diff --git a/web/app/cad/craft/craftHistoryUtils.js b/web/app/cad/craft/craftHistoryUtils.js index c3b46a8d..b1f273f5 100644 --- a/web/app/cad/craft/craftHistoryUtils.js +++ b/web/app/cad/craft/craftHistoryUtils.js @@ -37,4 +37,12 @@ export function removeAndDropDependants({history}, indexToRemove) { history, pointer: history.length - 1 } +} + +export function removeFeature({history}, indexToRemove) { + history = history.slice(0, indexToRemove); + return { + history, + pointer: history.length - 1 + } } \ No newline at end of file diff --git a/web/app/cad/craft/wizard/wizardPlugin.ts b/web/app/cad/craft/wizard/wizardPlugin.ts index c3ef610a..b6ebce17 100644 --- a/web/app/cad/craft/wizard/wizardPlugin.ts +++ b/web/app/cad/craft/wizard/wizardPlugin.ts @@ -4,7 +4,14 @@ import {clone} from 'gems/objects'; import materializeParams from '../schema/materializeParams'; import {createFunctionList} from 'gems/func'; import {CraftHistory, OperationRequest} from "cad/craft/craftPlugin"; -import {NewOperationCall, ParamsPath, WizardService, WizardState, WorkingRequest} from "cad/craft/wizard/wizardTypes"; +import { + NewOperationCall, + ParamsPath, + ValueUpdater, + WizardService, + WizardState, + WorkingRequest +} from "cad/craft/wizard/wizardTypes"; import _ from "lodash"; import {OperationParamValue} from "cad/craft/schema/schema"; import {ApplicationContext} from "context"; @@ -96,6 +103,7 @@ export function activate(ctx: ApplicationContext) { if (!Array.isArray(path)) { path = [path] } + _.set(params, path, value); }); }; @@ -157,7 +165,7 @@ export function activate(ctx: ApplicationContext) { workingRequest$, materializedWorkingRequest$, state$, updateParams, updateParam, readParam, updateState, - addDisposer: disposerList.add + addDisposer: (disposer) => disposerList.add(disposer) }; ctx.wizardService = services.wizard = wizardService; diff --git a/web/app/cad/craft/wizard/wizardSelectionPlugin.ts b/web/app/cad/craft/wizard/wizardSelectionPlugin.ts index 380b2459..90e20131 100644 --- a/web/app/cad/craft/wizard/wizardSelectionPlugin.ts +++ b/web/app/cad/craft/wizard/wizardSelectionPlugin.ts @@ -1,12 +1,14 @@ import {FACE, SHELL} from 'cad/model/entities'; import {OperationRequest} from "cad/craft/craftPlugin"; -import {FlattenPath, ParamsPath, WizardService} from "cad/craft/wizard/wizardTypes"; -import {OperationParamValue} from "cad/craft/schema/schema"; +import {ParamsPath, WizardService} from "cad/craft/wizard/wizardTypes"; +import {OperationParamPrimitive, OperationParamValue} from "cad/craft/schema/schema"; import {EntityReference} from "cad/craft/operationPlugin"; -import {ContextSpec, Plugin, Spec} from "plugable/pluginSystem"; +import {Plugin} from "plugable/pluginSystem"; 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 {param} from "cypress/types/jquery"; export type WizardSelectionPluginInputContext = MarkerPluginContext & WizardPluginContext & PickControlPluginContext; @@ -28,11 +30,20 @@ export const WizardSelectionPlugin: Plugin { ctx.markerService.clear(); if (opRequest) { - const wizardPickHandler = createPickHandlerFromSchema(wizardService); - ctx.pickControlService.setPickHandler(wizardPickHandler); + if (wizardPickHandler === null) { + wizardPickHandler = createPickHandlerFromSchema(wizardService); + ctx.pickControlService.setPickHandler(wizardPickHandler); + ctx.wizardService.addDisposer(() => { + console.log("DISPOSE!!!!"); + wizardPickHandler = null; + ctx.pickControlService.setPickHandler(null); + }); + } + const marker = ctx.markerService; marker.startSession(); let {schemaIndex} = wizardService.operation; @@ -51,33 +62,28 @@ export const WizardSelectionPlugin: Plugin id; -const arrayValue = (id, arr) => { - if (!arr) { - return [id]; - } - if (arr.indexOf(id) === -1) { - arr.push(id); - } - return arr; -}; - function createPickHandlerFromSchema(wizardService: WizardService) { - - function update(param: ParamsPath, value: OperationParamValue, paramToMakeActive: FlattenPath) { + function updateSingle(param: ParamsPath, value: OperationParamPrimitive) { wizardService.updateParam(param, value); - wizardService.updateState(state => { - state.activeParam = paramToMakeActive; + } + + function updateMulti(param: ParamsPath, value: OperationParamPrimitive) { + wizardService.updateParams(params => { + const currVal = _.get(params, param); + if (!currVal) { + _.set(params, param, [value]); + } else { + const arr: OperationParamPrimitive[] = Array.isArray(currVal) ? currVal : [currVal]; + if (arr.indexOf(value) === -1) { + arr.push(value); + } + } }); } return model => { @@ -101,10 +107,15 @@ function createPickHandlerFromSchema(wizardService: WizardService) { function select(entityRef: EntityReference, id: string) { const param = entityRef.field; - const valueGetter = entityRef.isArray ? arrayValue : singleValue; let paramToMakeActive = getNextActiveParam(entityRef); - const currentValue = wizardService.readParam(param.path); - update(param.path, valueGetter(id, currentValue), paramToMakeActive.field.flattenedPath); + if (entityRef.isArray) { + updateMulti(param.path, id); + } else { + updateSingle(param.path, id); + } + wizardService.updateState(state => { + state.activeParam = paramToMakeActive.field.flattenedPath + }); } function getNextActiveParam(entityRef: EntityReference): EntityReference { @@ -132,14 +143,24 @@ function createPickHandlerFromSchema(wizardService: WizardService) { function deselectIfNeeded(id) { for (let entityRef of schemaIndex.entities) { let val = wizardService.readParam(entityRef.field.path); + if (val === id) { - update(entityRef.field.path, undefined, entityRef.field.flattenedPath); + updateSingle(entityRef.field.path, undefined); + wizardService.updateState(state => { + state.activeParam = entityRef.field.flattenedPath + }); return true; } else if (Array.isArray(val)) { let index = val.indexOf(id); if (index !== -1) { - val = val.slice(index, 1); - update(entityRef.field.path, val, entityRef.field.flattenedPath); + wizardService.updateParams(params => { + const val = _.get(params, entityRef.field.path); + let index = val.indexOf(id); + val.splice(index, 1); + }); + wizardService.updateState(state => { + state.activeParam = entityRef.field.flattenedPath + }); return true; } } diff --git a/web/app/cad/craft/wizard/wizardTypes.ts b/web/app/cad/craft/wizard/wizardTypes.ts index 108b064c..141bdfd9 100644 --- a/web/app/cad/craft/wizard/wizardTypes.ts +++ b/web/app/cad/craft/wizard/wizardTypes.ts @@ -56,4 +56,6 @@ export interface WizardService { export interface NewOperationCall { type: string; initialOverrides: OperationParams; -} \ No newline at end of file +} + +export type ValueUpdater = (value: OperationParamValue) => OperationParamValue; diff --git a/web/app/cad/scene/controls/pickControlPlugin.ts b/web/app/cad/scene/controls/pickControlPlugin.ts index 3536ca85..ae205241 100644 --- a/web/app/cad/scene/controls/pickControlPlugin.ts +++ b/web/app/cad/scene/controls/pickControlPlugin.ts @@ -166,7 +166,7 @@ export function activate(context) { setPickHandler, deselectAll, pick, pickFromRay, simulatePickFromRay }; - services.pickControlService = services.pickControl; + context.pickControlService = services.pickControl; if (LOG_FLAGS.PICK) { initRayCastDebug();