Merge pull request #2 from jmwright/kurt/update-cadhub-after-anaconda
Update CadHub after anaconda
This commit is contained in:
@@ -4,38 +4,45 @@ import { readFile } from 'fs/promises'
|
||||
|
||||
export const runCQ = async ({
|
||||
file,
|
||||
settings: { deflection = 0.3 } = {},
|
||||
settings: { deflection = 0.3, parameters } = {},
|
||||
} = {}) => {
|
||||
const tempFile = await writeFiles(
|
||||
[{ file, fileName: 'main.py' }],
|
||||
[
|
||||
{ file, fileName: 'main.py' },
|
||||
{
|
||||
file: JSON.stringify(parameters),
|
||||
fileName: 'params.json',
|
||||
}
|
||||
],
|
||||
'a' + nanoid() // 'a' ensure nothing funny happens if it start with a bad character like "-", maybe I should pick a safer id generator :shrug:
|
||||
)
|
||||
const fullPath = `/tmp/${tempFile}/output.gz`
|
||||
const stlPath = `/tmp/${tempFile}/output.stl`
|
||||
const customizerPath = `/tmp/${tempFile}/customizer.param`
|
||||
const command = [
|
||||
const customizerPath = `/tmp/${tempFile}/customizer.json`
|
||||
const mainCommand = [
|
||||
`./cq-cli/cq-cli.py`,
|
||||
`--codec stl`,
|
||||
`--infile /tmp/${tempFile}/main.py`,
|
||||
`--outfile ${stlPath}`,
|
||||
`--outputopts "deflection:${deflection};angularDeflection:${deflection};"`,
|
||||
`--params ${customizerPath}`,
|
||||
`--params /tmp/${tempFile}/params.json`,
|
||||
].join(' ')
|
||||
const command2 = [
|
||||
`cq-cli/cq-cli`,
|
||||
const customizerCommand = [
|
||||
`./cq-cli/cq-cli.py`,
|
||||
`--getparams true`,
|
||||
`--infile /tmp/${tempFile}/main.py`,
|
||||
`--outfile ${customizerPath}`,
|
||||
]
|
||||
console.log('command', command)
|
||||
].join(' ')
|
||||
console.log('command', mainCommand)
|
||||
let consoleMessage = ''
|
||||
try {
|
||||
consoleMessage = await runCommand(command, 30000)
|
||||
const consoleMessage2 = await runCommand(command2, 30000)
|
||||
;([consoleMessage] = await Promise.all([
|
||||
runCommand(mainCommand, 30000),
|
||||
runCommand(customizerCommand, 30000)
|
||||
]))
|
||||
const params = JSON.parse(
|
||||
await readFile(customizerPath, { encoding: 'ascii'})
|
||||
)
|
||||
console.log('params', params)
|
||||
await writeFiles(
|
||||
[
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
@@ -49,16 +51,15 @@ export const render: DefaultKernelExport['render'] = async ({
|
||||
data: await stlToGeometry(window.URL.createObjectURL(blob)),
|
||||
consoleMessage,
|
||||
date: new Date(),
|
||||
customizerParams: customizerParams,
|
||||
customizerParams: CadQueryToCadhubParams([customizerParams]), // TODO, should already be an array and not need to be wrapped in one.
|
||||
})
|
||||
} catch (e) {
|
||||
return createUnhealthyResponse(new Date())
|
||||
}
|
||||
}
|
||||
|
||||
const openscad: DefaultKernelExport = {
|
||||
const cadQuery: DefaultKernelExport = {
|
||||
render,
|
||||
// more functions to come
|
||||
}
|
||||
|
||||
export default openscad
|
||||
export default cadQuery
|
||||
49
app/web/src/helpers/cadPackages/cadQuery/cadQueryParams.ts
Normal file
49
app/web/src/helpers/cadPackages/cadQuery/cadQueryParams.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { CadhubParams } from 'src/components/Customizer/customizerConverter'
|
||||
|
||||
interface CadQueryParamsBase {
|
||||
name: string
|
||||
initial: number | string
|
||||
type?: 'number'
|
||||
}
|
||||
|
||||
interface CadQueryNumberParam extends CadQueryParamsBase {
|
||||
type: 'number'
|
||||
initial: number
|
||||
}
|
||||
|
||||
interface CadQueryStringParam extends CadQueryParamsBase {
|
||||
initial: string
|
||||
}
|
||||
|
||||
export type CadQueryStringParams =
|
||||
| CadQueryNumberParam
|
||||
| CadQueryStringParam
|
||||
|
||||
|
||||
export function CadQueryToCadhubParams(
|
||||
input: CadQueryStringParams[]
|
||||
): CadhubParams[] {
|
||||
return input
|
||||
.map((param): CadhubParams => {
|
||||
const common: { caption: string; name: string } = {
|
||||
caption: '',
|
||||
name: param.name,
|
||||
}
|
||||
if(param.type === 'number') {
|
||||
return {
|
||||
type: 'number',
|
||||
input: 'default-number',
|
||||
...common,
|
||||
initial: Number(param.initial),
|
||||
}
|
||||
}
|
||||
return {
|
||||
type: 'string',
|
||||
input: 'default-string',
|
||||
...common,
|
||||
initial: String(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