diff --git a/web/app/cad/craft/primitives/simplePlane/simplePlaneOpSchema.js b/web/app/cad/craft/primitives/simplePlane/simplePlaneOpSchema.js index 56c99000..5f6a4588 100644 --- a/web/app/cad/craft/primitives/simplePlane/simplePlaneOpSchema.js +++ b/web/app/cad/craft/primitives/simplePlane/simplePlaneOpSchema.js @@ -1,3 +1,5 @@ +import {entityKindCapture} from "cad/craft/schema/types/entityType"; + export default { orientation: { type: 'string', @@ -6,7 +8,7 @@ export default { }, datum: { type: 'entity', - allowedKinds: ['face', 'datum'], + allowedKinds: entityKindCapture('face', 'datum'), optional: true, defaultValue: { usePreselection: true, diff --git a/web/app/cad/craft/schema/initializeBySchema.ts b/web/app/cad/craft/schema/initializeBySchema.ts index fbb5bd20..00884403 100644 --- a/web/app/cad/craft/schema/initializeBySchema.ts +++ b/web/app/cad/craft/schema/initializeBySchema.ts @@ -15,7 +15,7 @@ export default function initializeBySchema(schema: OperationSchema, context: Cor if (defaultValue.usePreselection === true) { const entitySchema = md.items; const currentSelection = - context.entityContextService.selectedEntities.value.filter(e => entitySchema.allowedKinds.includes(e.TYPE)); + context.entityContextService.selectedEntities.value.filter(entitySchema.entityCapture); val = currentSelection.map(e => e.id); } } else { @@ -23,11 +23,9 @@ export default function initializeBySchema(schema: OperationSchema, context: Cor } } else if (md.type === Types.entity && md.defaultValue !== undefined) { const defaultValue = md.defaultValue; - console.log(defaultValue) if (defaultValue.usePreselection === true && defaultValue.preselectionIndex !== undefined) { - const allowedKinds = md.allowedKinds; const currentSelection = - context.entityContextService.selectedEntities.value.filter(e => allowedKinds.includes(e.TYPE)); + context.entityContextService.selectedEntities.value.filter(md.entityCapture); let mObject = currentSelection[defaultValue.preselectionIndex as number]; if (mObject) { diff --git a/web/app/cad/craft/schema/types/entityType.ts b/web/app/cad/craft/schema/types/entityType.ts index effbf7b0..55e36826 100644 --- a/web/app/cad/craft/schema/types/entityType.ts +++ b/web/app/cad/craft/schema/types/entityType.ts @@ -8,7 +8,7 @@ export interface EntityTypeSchema extends BaseSchemaField { type: Types.entity, - allowedKinds: EntityKind[]; + entityCapture: EntityCapture, defaultValue?: { usePreselection: boolean; @@ -16,6 +16,8 @@ export interface EntityTypeSchema extends BaseSchemaField { } } +export type EntityCapture = (entity: MObject) => boolean; + export const EntityType: Type = { resolve(ctx: CoreContext, @@ -38,3 +40,10 @@ export const EntityType: Type = { } } + +export function entityKindCapture(...allowedKinds: EntityKind[]) { + + return e => allowedKinds.includes(e.TYPE); + +} + diff --git a/web/app/cad/craft/wizard/wizardSelectionPlugin.ts b/web/app/cad/craft/wizard/wizardSelectionPlugin.ts index c98afa35..06f4c15d 100644 --- a/web/app/cad/craft/wizard/wizardSelectionPlugin.ts +++ b/web/app/cad/craft/wizard/wizardSelectionPlugin.ts @@ -8,6 +8,7 @@ import {MarkerPluginContext} from "cad/scene/selectionMarker/markerPlugin"; import {WizardPluginContext} from "cad/craft/wizard/wizardPlugin"; import {PickControlPluginContext} from "cad/scene/controls/pickControlPlugin"; import _ from "lodash"; +import {MObject} from "cad/model/mobject"; export type WizardSelectionPluginInputContext = MarkerPluginContext & WizardPluginContext & PickControlPluginContext; @@ -94,13 +95,13 @@ function createPickHandlerFromSchema(wizardService: WizardService) { } - function activeCanTakeIt(kind) { + function activeCanTakeIt(model: MObject) { let activeRef: EntityReference = activeEntityRef(); if (!activeRef) { return false; } const activeMd = activeRef?.metadata; - return activeMd && activeMd.allowedKinds.includes(kind); + return activeMd && activeMd.entityCapture(model); } function select(entityRef: EntityReference, id: string) { @@ -129,10 +130,10 @@ function createPickHandlerFromSchema(wizardService: WizardService) { select(activeEntityRef(), id); } - function selectToFirst(entity, id) { + function selectToFirst(entity) { for (let eRef of schemaIndex.entities) { - if (eRef.metadata.allowedKinds.includes(entity)) { - select(eRef, id); + if (eRef.metadata.entityCapture(entity)) { + select(eRef, entity.id); return true; } } @@ -175,20 +176,20 @@ function createPickHandlerFromSchema(wizardService: WizardService) { } if (modelType === FACE) { - if (activeCanTakeIt(SHELL)) { + if (activeCanTakeIt(model.shell)) { selectActive(model.shell.id); - } else if (activeCanTakeIt(FACE)) { + } else if (activeCanTakeIt(model)) { selectActive(model.id); } else { - if (!selectToFirst(FACE, model.id)) { - selectToFirst(SHELL, model.shell.id) - } + // if (!selectToFirst(model)) { + // selectToFirst(model.shell) + // } } } else{ - if (activeCanTakeIt(modelType)) { + if (activeCanTakeIt(model)) { selectActive(model.id); } else { - selectToFirst(modelType, model.id); + // selectToFirst(model); } } return false; diff --git a/web/app/cad/mdf/ui/SelectionWidget.tsx b/web/app/cad/mdf/ui/SelectionWidget.tsx index c2721398..27b25058 100644 --- a/web/app/cad/mdf/ui/SelectionWidget.tsx +++ b/web/app/cad/mdf/ui/SelectionWidget.tsx @@ -6,6 +6,8 @@ import {FieldBasicProps, fieldToSchemaGeneric} from "cad/mdf/ui/field"; import {EntityKind} from "cad/model/entities"; import {ArrayTypeSchema} from "cad/craft/schema/types/arrayType"; import {Types} from "cad/craft/schema/types"; +import {MObject} from "cad/model/mobject"; +import {EntityCapture, entityKindCapture} from "cad/craft/schema/types/entityType"; export interface SelectionWidgetProps extends FieldBasicProps { @@ -14,7 +16,7 @@ export interface SelectionWidgetProps extends FieldBasicProps { multi?: boolean; - capture: EntityKind[]; + capture: EntityKind[] | EntityCapture; min?: number; @@ -29,7 +31,7 @@ SelectionWidget.propsToSchema = (props: SelectionWidgetProps) => { let value = { type: Types.entity, - allowedKinds: props.capture, + entityCapture: Array.isArray(props.capture) ? entityKindCapture(...props.capture) : props.capture, } as SchemaField; if (props.multi) {