Demo branch adding JSCAD type, without implementing the render
Related to #411
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -2,6 +2,7 @@
|
|||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"Hutten",
|
"Hutten",
|
||||||
"cadquery",
|
"cadquery",
|
||||||
|
"jscad",
|
||||||
"openscad",
|
"openscad",
|
||||||
"sendmail"
|
"sendmail"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ model User {
|
|||||||
enum CadPackage {
|
enum CadPackage {
|
||||||
openscad
|
openscad
|
||||||
cadquery
|
cadquery
|
||||||
|
// jscad // TODO #422, add jscad to db schema when were ready to enable saving of jscad projects
|
||||||
}
|
}
|
||||||
|
|
||||||
model Project {
|
model Project {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { makeCodeStoreKey, requestRender } from 'src/helpers/hooks/useIdeState'
|
|||||||
import Editor, { useMonaco } from '@monaco-editor/react'
|
import Editor, { useMonaco } from '@monaco-editor/react'
|
||||||
import { theme } from 'src/../tailwind.config'
|
import { theme } from 'src/../tailwind.config'
|
||||||
import { useSaveCode } from 'src/components/IdeWrapper/useSaveCode'
|
import { useSaveCode } from 'src/components/IdeWrapper/useSaveCode'
|
||||||
|
import type { CadPackage as CadPackageType } from 'src/helpers/hooks/useIdeState'
|
||||||
|
import CadPackage from '../CadPackage/CadPackage'
|
||||||
|
|
||||||
const colors = theme.extend.colors
|
const colors = theme.extend.colors
|
||||||
|
|
||||||
@@ -12,9 +14,10 @@ const IdeEditor = ({ Loading }) => {
|
|||||||
const [theme, setTheme] = useState('vs-dark')
|
const [theme, setTheme] = useState('vs-dark')
|
||||||
const saveCode = useSaveCode()
|
const saveCode = useSaveCode()
|
||||||
|
|
||||||
const ideTypeToLanguageMap = {
|
const ideTypeToLanguageMap: {[key in CadPackageType]: string} = {
|
||||||
cadquery: 'python',
|
cadquery: 'python',
|
||||||
openscad: 'cpp',
|
openscad: 'cpp',
|
||||||
|
jscad: 'javascript',
|
||||||
}
|
}
|
||||||
const monaco = useMonaco()
|
const monaco = useMonaco()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
import { Link, routes } from '@redwoodjs/router'
|
import { Link, routes } from '@redwoodjs/router'
|
||||||
import Svg from 'src/components/Svg/Svg'
|
import Svg from 'src/components/Svg/Svg'
|
||||||
import { Popover } from '@headlessui/react'
|
import { Popover } from '@headlessui/react'
|
||||||
|
import type { CadPackage } from 'src/helpers/hooks/useIdeState'
|
||||||
|
|
||||||
|
|
||||||
|
const menuOptions: {
|
||||||
|
name: string
|
||||||
|
sub: string
|
||||||
|
ideType: CadPackage
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
name: 'OpenSCAD',
|
||||||
|
sub: 'beta',
|
||||||
|
ideType: 'openscad',
|
||||||
|
},
|
||||||
|
{ name: 'CadQuery', sub: 'beta', ideType: 'cadquery' },
|
||||||
|
// { name: 'JSCAD', sub: 'alpha', ideType: 'jscad' }, // TODO #422, add jscad to db schema when were ready to enable saving of jscad projects
|
||||||
|
]
|
||||||
|
|
||||||
const NavPlusButton: React.FC = () => {
|
const NavPlusButton: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
@@ -11,14 +27,7 @@ const NavPlusButton: React.FC = () => {
|
|||||||
|
|
||||||
<Popover.Panel className="absolute z-10 right-0">
|
<Popover.Panel className="absolute z-10 right-0">
|
||||||
<ul className="bg-gray-200 mt-4 rounded shadow-md overflow-hidden">
|
<ul className="bg-gray-200 mt-4 rounded shadow-md overflow-hidden">
|
||||||
{[
|
{menuOptions.map(({ name, sub, ideType }) => (
|
||||||
{
|
|
||||||
name: 'OpenSCAD',
|
|
||||||
sub: 'beta',
|
|
||||||
ideType: 'openscad',
|
|
||||||
},
|
|
||||||
{ name: 'CadQuery', sub: 'beta', ideType: 'cadquery' },
|
|
||||||
].map(({ name, sub, ideType }) => (
|
|
||||||
<li
|
<li
|
||||||
key={name}
|
key={name}
|
||||||
className="px-4 py-2 hover:bg-gray-400 text-gray-800"
|
className="px-4 py-2 hover:bg-gray-400 text-gray-800"
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
|
import { DefaultKernelExport } from './common'
|
||||||
|
import type { CadPackage } from 'src/helpers/hooks/useIdeState'
|
||||||
|
|
||||||
import openscad from './openScadController'
|
import openscad from './openScadController'
|
||||||
import cadquery from './cadQueryController'
|
import cadquery from './cadQueryController'
|
||||||
|
import jscad from './jsCadController'
|
||||||
|
|
||||||
export const cadPackages = {
|
export const cadPackages: {[key in CadPackage]: DefaultKernelExport} = {
|
||||||
openscad,
|
openscad,
|
||||||
cadquery,
|
cadquery,
|
||||||
|
jscad,
|
||||||
}
|
}
|
||||||
|
|||||||
15
app/web/src/helpers/cadPackages/jsCadController.ts
Normal file
15
app/web/src/helpers/cadPackages/jsCadController.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { RenderArgs, DefaultKernelExport, createUnhealthyResponse } from './common'
|
||||||
|
|
||||||
|
export const render: DefaultKernelExport['render'] = async ({
|
||||||
|
code,
|
||||||
|
settings,
|
||||||
|
}: RenderArgs) => {
|
||||||
|
// do your magic
|
||||||
|
return createUnhealthyResponse( new Date(), 'JSCAD controller not implemented yet')
|
||||||
|
}
|
||||||
|
|
||||||
|
const jsCadController: DefaultKernelExport = {
|
||||||
|
render,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default jsCadController
|
||||||
@@ -9,7 +9,9 @@ function withThunk(dispatch, getState) {
|
|||||||
: dispatch(actionOrThunk)
|
: dispatch(actionOrThunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
const initCodeMap = {
|
export type CadPackage = 'openscad' | 'cadquery' | 'jscad'
|
||||||
|
|
||||||
|
const initCodeMap: {[key in CadPackage]: string} = {
|
||||||
openscad: `// involute donut
|
openscad: `// involute donut
|
||||||
|
|
||||||
// ^ first comment is used for download title (i.e "involute-donut.stl")
|
// ^ first comment is used for download title (i.e "involute-donut.stl")
|
||||||
@@ -40,6 +42,9 @@ result = (cq.Workplane().circle(diam).extrude(20.0)
|
|||||||
|
|
||||||
show_object(result)
|
show_object(result)
|
||||||
`,
|
`,
|
||||||
|
jscad: `
|
||||||
|
// TODO implement example JSCAD code.
|
||||||
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
const codeStorageKey = 'Last-editor-code'
|
const codeStorageKey = 'Last-editor-code'
|
||||||
@@ -53,7 +58,7 @@ interface XYZ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
ideType: 'INIT' | 'openscad' | 'cadquery'
|
ideType: 'INIT' | CadPackage
|
||||||
consoleMessages: { type: 'message' | 'error'; message: string; time: Date }[]
|
consoleMessages: { type: 'message' | 'error'; message: string; time: Date }[]
|
||||||
code: string
|
code: string
|
||||||
objectData: {
|
objectData: {
|
||||||
|
|||||||
Reference in New Issue
Block a user