diff --git a/web/app/cad/craft/boolean/booleanOpSchema.js b/web/app/cad/craft/boolean/booleanOpSchema.js index fb309ac1..b2ae15b6 100644 --- a/web/app/cad/craft/boolean/booleanOpSchema.js +++ b/web/app/cad/craft/boolean/booleanOpSchema.js @@ -2,11 +2,11 @@ export default { operandA: { type: 'shell', markColor: 0xC9FFBC, - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, operandB: { type: 'shell', markColor: 0xFFBEB4, - defaultValue: {type: 'selection'} + initializeBySelection: 1 } }; diff --git a/web/app/cad/craft/cutExtrude/schema.js b/web/app/cad/craft/cutExtrude/schema.js index 5d680392..a1d77fd3 100644 --- a/web/app/cad/craft/cutExtrude/schema.js +++ b/web/app/cad/craft/cutExtrude/schema.js @@ -18,7 +18,7 @@ export default { }, face: { type: 'face', - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, datumAxisVector: { type: 'datumAxis', diff --git a/web/app/cad/craft/datum/create/createDatumOpSchema.js b/web/app/cad/craft/datum/create/createDatumOpSchema.js index fc740e09..2675626e 100644 --- a/web/app/cad/craft/datum/create/createDatumOpSchema.js +++ b/web/app/cad/craft/datum/create/createDatumOpSchema.js @@ -1,7 +1,7 @@ export default { originatingFace: { type: 'face', - defaultValue: {type: 'selection'}, + initializeBySelection: 0, optional: true }, x: { diff --git a/web/app/cad/craft/datum/move/moveDatumOpSchema.js b/web/app/cad/craft/datum/move/moveDatumOpSchema.js index 87205ddd..2761e632 100644 --- a/web/app/cad/craft/datum/move/moveDatumOpSchema.js +++ b/web/app/cad/craft/datum/move/moveDatumOpSchema.js @@ -1,7 +1,7 @@ export default { datum: { type: 'datum', - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, x: { type: 'number', diff --git a/web/app/cad/craft/datum/rotate/rotateDatumOpSchema.js b/web/app/cad/craft/datum/rotate/rotateDatumOpSchema.js index ed531811..a0ccdc16 100644 --- a/web/app/cad/craft/datum/rotate/rotateDatumOpSchema.js +++ b/web/app/cad/craft/datum/rotate/rotateDatumOpSchema.js @@ -1,7 +1,7 @@ export default { datum: { type: 'datum', - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, axis: { type: 'enum', diff --git a/web/app/cad/craft/fillet/schema.js b/web/app/cad/craft/fillet/schema.js index bac6f420..026517ef 100644 --- a/web/app/cad/craft/fillet/schema.js +++ b/web/app/cad/craft/fillet/schema.js @@ -2,9 +2,7 @@ export default { edges: { type: 'array', itemType: 'edge', - defaultValue: { - type: 'selection', - } + initializeBySelection: true }, thickness: { type: 'number', diff --git a/web/app/cad/craft/intializeBySchema.js b/web/app/cad/craft/intializeBySchema.js index c00eb9cd..f6610d83 100644 --- a/web/app/cad/craft/intializeBySchema.js +++ b/web/app/cad/craft/intializeBySchema.js @@ -9,21 +9,19 @@ export default function initializeBySchema(schema, context) { if (md.type === 'array') { if (md.itemType === 'object') { if (md.defaultValue) { - if (md.defaultValue.type === 'selection') { - let {itemField, entity} = md.defaultValue; - val = context.streams.selection[entity].value.map(s => { - let item = initializeBySchema(md.schema, context); - item[itemField] = s; - return item; - }); - } else { - val = md.defaultValue; - } + val = md.defaultValue; + } else if (md.initializeBySelection === true) { + let {itemField, entity} = md.defaultValue; + val = context.streams.selection[entity].value.map(s => { + let item = initializeBySchema(md.schema, context); + item[itemField] = s; + return item; + }); } else { val = []; } } else if (isEntityType(md.itemType)) { - if (md.defaultValue && md.defaultValue.type === 'selection') { + if (md.initializeBySelection === true) { let entityContext = context.streams.selection[md.itemType]; if (entityContext) { val = [...entityContext.value]; @@ -32,17 +30,15 @@ export default function initializeBySchema(schema, context) { val = [] } } else { - throw 'unsupport'; + throw 'unsupported'; } - } else if (isEntityType(md.type) && md.defaultValue && md.defaultValue.type === 'selection') { + } else if (isEntityType(md.type) && md.initializeBySelection !== undefined) { const entityContext = context.streams.selection[md.type]; if (entityContext) { - val = entityContext.value[0]; + val = entityContext.value[md.initializeBySelection]; } } else if (md.type === 'object') { val = initializeBySchema(md.schema, context); - } else if (md.type === 'number') { - val = md.defaultValue; } else { val = md.defaultValue; } diff --git a/web/app/cad/craft/loft/schema.js b/web/app/cad/craft/loft/schema.js index b90e170b..e963272a 100644 --- a/web/app/cad/craft/loft/schema.js +++ b/web/app/cad/craft/loft/schema.js @@ -2,9 +2,7 @@ export default { sections: { type: 'array', itemType: 'loop', - defaultValue: { - type: 'selection', - } + initializeBySelection: true }, boolean: { type: 'enum', diff --git a/web/app/cad/craft/materializeParams.js b/web/app/cad/craft/materializeParams.js index 7a78960f..064cdfdd 100644 --- a/web/app/cad/craft/materializeParams.js +++ b/web/app/cad/craft/materializeParams.js @@ -11,7 +11,7 @@ export default function materializeParams(services, params, schema, result, erro } let value = params[field]; if (value === undefined || value === null || value === '') { - if (!md.optional && !md.hasOwnProperty('defaultValue')) { + if (!md.optional) { errors.push({path: [...parentPath, field], message: 'required'}); } } else { diff --git a/web/app/cad/craft/primitives/box/boxOpSchema.js b/web/app/cad/craft/primitives/box/boxOpSchema.js index 4803e3da..c2813878 100644 --- a/web/app/cad/craft/primitives/box/boxOpSchema.js +++ b/web/app/cad/craft/primitives/box/boxOpSchema.js @@ -4,7 +4,7 @@ export default { datum: { type: 'datum', optional: true, - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, width: { type: 'number', diff --git a/web/app/cad/craft/primitives/cone/coneOpSchema.js b/web/app/cad/craft/primitives/cone/coneOpSchema.js index cedade85..4c0da17f 100644 --- a/web/app/cad/craft/primitives/cone/coneOpSchema.js +++ b/web/app/cad/craft/primitives/cone/coneOpSchema.js @@ -4,7 +4,7 @@ export default { datum: { type: 'datum', optional: true, - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, radius: { type: 'number', diff --git a/web/app/cad/craft/primitives/cylinder/cylinderOpSchema.js b/web/app/cad/craft/primitives/cylinder/cylinderOpSchema.js index 552d7649..47ad5a65 100644 --- a/web/app/cad/craft/primitives/cylinder/cylinderOpSchema.js +++ b/web/app/cad/craft/primitives/cylinder/cylinderOpSchema.js @@ -4,7 +4,7 @@ export default { datum: { type: 'datum', optional: true, - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, radius: { type: 'number', diff --git a/web/app/cad/craft/primitives/plane/planeOpSchema.js b/web/app/cad/craft/primitives/plane/planeOpSchema.js index 1ea295c3..93df2548 100644 --- a/web/app/cad/craft/primitives/plane/planeOpSchema.js +++ b/web/app/cad/craft/primitives/plane/planeOpSchema.js @@ -1,6 +1,6 @@ export default { datum: { type: 'datum', - defaultValue: {type: 'selection'} + initializeBySelection: 0 } } \ No newline at end of file diff --git a/web/app/cad/craft/primitives/sphere/sphereOpSchema.js b/web/app/cad/craft/primitives/sphere/sphereOpSchema.js index e32b8d52..91ed1114 100644 --- a/web/app/cad/craft/primitives/sphere/sphereOpSchema.js +++ b/web/app/cad/craft/primitives/sphere/sphereOpSchema.js @@ -4,7 +4,7 @@ export default { datum: { type: 'datum', optional: true, - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, radius: { type: 'number', diff --git a/web/app/cad/craft/primitives/torus/torusOpSchema.js b/web/app/cad/craft/primitives/torus/torusOpSchema.js index 25f4463f..dcfe6f14 100644 --- a/web/app/cad/craft/primitives/torus/torusOpSchema.js +++ b/web/app/cad/craft/primitives/torus/torusOpSchema.js @@ -4,7 +4,7 @@ export default { datum: { type: 'datum', optional: true, - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, radius: { type: 'number', diff --git a/web/app/cad/craft/revolve/schema.js b/web/app/cad/craft/revolve/schema.js index dbfe9bfd..33721394 100644 --- a/web/app/cad/craft/revolve/schema.js +++ b/web/app/cad/craft/revolve/schema.js @@ -5,11 +5,11 @@ export default { }, face: { type: 'face', - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, axis: { type: 'sketchObject', - defaultValue: {type: 'selection'} + initializeBySelection: 0 }, boolean: { type: 'enum',