Add CadQuery customizer (#547)
* Rough changes to make the CadQuery integration work with the customizer * Tweak runCQ * Switched to Anaconda * Cleaned up code * Update CadHub after anaconda Related to #547 * Add final tweaks to CQ customizer * Separated out customizer.json from params.json * Changes after discussing CadHub integration * linting runCQ Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit was merged in pull request #547.
This commit is contained in:
@@ -7,15 +7,17 @@ import {
|
||||
RenderArgs,
|
||||
DefaultKernelExport,
|
||||
splitGziped,
|
||||
} from './common'
|
||||
} from '../common'
|
||||
import { CadQueryToCadhubParams } from './cadQueryParams'
|
||||
|
||||
export const render: DefaultKernelExport['render'] = async ({
|
||||
code,
|
||||
settings: { quality = 'low' },
|
||||
settings: { quality = 'low', parameters },
|
||||
}: RenderArgs) => {
|
||||
const body = JSON.stringify({
|
||||
settings: {
|
||||
deflection: quality === 'low' ? 0.35 : 0.11,
|
||||
parameters,
|
||||
},
|
||||
file: code,
|
||||
})
|
||||
@@ -43,21 +45,21 @@ export const render: DefaultKernelExport['render'] = async ({
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const text = await new Response(blob).text()
|
||||
const { consoleMessage } = splitGziped(text)
|
||||
const { consoleMessage, customizerParams, type } = splitGziped(text)
|
||||
return createHealthyResponse({
|
||||
type: 'geometry',
|
||||
data: await stlToGeometry(window.URL.createObjectURL(blob)),
|
||||
consoleMessage,
|
||||
date: new Date(),
|
||||
customizerParams: CadQueryToCadhubParams(customizerParams),
|
||||
})
|
||||
} catch (e) {
|
||||
return createUnhealthyResponse(new Date())
|
||||
}
|
||||
}
|
||||
|
||||
const openscad: DefaultKernelExport = {
|
||||
const cadQuery: DefaultKernelExport = {
|
||||
render,
|
||||
// more functions to come
|
||||
}
|
||||
|
||||
export default openscad
|
||||
export default cadQuery
|
||||
63
app/web/src/helpers/cadPackages/cadQuery/cadQueryParams.ts
Normal file
63
app/web/src/helpers/cadPackages/cadQuery/cadQueryParams.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { CadhubParams } from 'src/components/Customizer/customizerConverter'
|
||||
|
||||
interface CadQueryParamsBase {
|
||||
name: string
|
||||
initial: number | string | boolean
|
||||
type?: 'number' | 'string' | 'boolean'
|
||||
}
|
||||
|
||||
interface CadQueryNumberParam extends CadQueryParamsBase {
|
||||
type: 'number'
|
||||
initial: number
|
||||
}
|
||||
|
||||
interface CadQueryStringParam extends CadQueryParamsBase {
|
||||
type: 'string'
|
||||
initial: string
|
||||
}
|
||||
|
||||
interface CadQueryBooleanParam extends CadQueryParamsBase {
|
||||
type: 'boolean'
|
||||
initial: boolean
|
||||
}
|
||||
|
||||
export type CadQueryStringParams =
|
||||
| CadQueryNumberParam
|
||||
| CadQueryStringParam
|
||||
| CadQueryBooleanParam
|
||||
|
||||
export function CadQueryToCadhubParams(
|
||||
input: CadQueryStringParams[]
|
||||
): CadhubParams[] {
|
||||
return input
|
||||
.map((param): CadhubParams => {
|
||||
const common: { caption: string; name: string } = {
|
||||
caption: '',
|
||||
name: param.name,
|
||||
}
|
||||
switch (param.type) {
|
||||
case 'number':
|
||||
return {
|
||||
type: 'number',
|
||||
input: 'default-number',
|
||||
...common,
|
||||
initial: param.initial,
|
||||
}
|
||||
case 'string':
|
||||
return {
|
||||
type: 'string',
|
||||
input: 'default-string',
|
||||
...common,
|
||||
initial: param.initial,
|
||||
}
|
||||
case 'boolean':
|
||||
return {
|
||||
type: 'boolean',
|
||||
input: 'default-boolean',
|
||||
...common,
|
||||
initial: param.initial,
|
||||
}
|
||||
}
|
||||
})
|
||||
.filter((a) => a)
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import openscad from './openScad/openScadController'
|
||||
import openScadGuide from 'src/helpers/cadPackages/openScad/userGuide.md'
|
||||
import openScadInitialCode from 'src/helpers/cadPackages/openScad/initialCode.scad'
|
||||
|
||||
import cadquery from './cadQueryController'
|
||||
import cadquery from './cadQuery/cadQueryController'
|
||||
import cadQueryGuide from 'src/helpers/cadPackages/cadQuery/userGuide.md'
|
||||
import cadQueryInitialCode from 'src/helpers/cadPackages/cadQuery/initialCode.py'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user