diff --git a/modules/bus/index.js b/modules/bus/index.js index 79324440..50294b6b 100644 --- a/modules/bus/index.js +++ b/modules/bus/index.js @@ -3,7 +3,7 @@ export default class Bus { constructor() { this.listeners = {}; this.state = {}; - this.recordFor = new Set(); + this.keepStateFor = new Set(); this.lock = new Set(); } @@ -15,7 +15,7 @@ export default class Bus { } listenerList.push(callback); - if (this.recordFor.has(key)) { + if (this.keepStateFor.has(key)) { callback(this.state[key]); } return callback; @@ -36,6 +36,9 @@ export default class Bus { console.warn('recursive dispatch'); return } + if (this.keepStateFor.has(key)) { + this.state[key] = data; + } this.lock.add(key); try { let listenerList = this.listeners[key]; @@ -51,19 +54,16 @@ export default class Bus { } } finally { this.lock.delete(key); - if (this.recordFor.has(key)) { - this.state[key] = data; - } } }; enableState(forEvent, initValue) { - this.recordFor.add(forEvent); + this.keepStateFor.add(forEvent); this.state[forEvent] = initValue; } disableState(forEvent) { - this.recordFor.delete(forEvent); + this.keepStateFor.delete(forEvent); } } diff --git a/web/app/3d/actions/core-actions.js b/web/app/3d/actions/core-actions.js index 6ca79073..a5c8c811 100644 --- a/web/app/3d/actions/core-actions.js +++ b/web/app/3d/actions/core-actions.js @@ -5,7 +5,7 @@ export const EditFace = { label: 'sketch', icon96: 'img/3d/face-edit96.png', info: 'open sketcher for a face/plane', - listens: ['selection'], + listens: ['selection:face'], update: ActionHelpers.checkForSelectedFaces(1), invoke: (app) => app.editFace() }; diff --git a/web/app/3d/actions/operation-actions.js b/web/app/3d/actions/operation-actions.js index 432727fa..b1bcccaf 100644 --- a/web/app/3d/actions/operation-actions.js +++ b/web/app/3d/actions/operation-actions.js @@ -63,11 +63,11 @@ requiresSolidSelection(DIFFERENCE, 2); requiresSolidSelection(UNION, 2); function requiresFaceSelection(action, amount) { - action.listens = ['selection']; + action.listens = ['selection:face']; action.update = ActionHelpers.checkForSelectedFaces(amount) } function requiresSolidSelection(action, amount) { - action.listens = ['selection']; + action.listens = ['selection:face']; action.update = ActionHelpers.checkForSelectedSolids(amount) } diff --git a/web/app/3d/craft/mesh/wizards/revolve.js b/web/app/3d/craft/mesh/wizards/revolve.js index 89f81e8b..36860c58 100644 --- a/web/app/3d/craft/mesh/wizards/revolve.js +++ b/web/app/3d/craft/mesh/wizards/revolve.js @@ -16,7 +16,7 @@ export function RevolveWizard(app, face, initParams) { this.synch(); this.autoResoltion = true; this.selectionListener = () => { - const object = this.app.viewer.sketchSelectionMgr.selection[0]; + const object = this.app.getFirstSelectedFace(); if (canBePivot(object, this.face)) { this.ui.pivotSketchObjectId.input.val(object.__TCAD_SketchObject.id); this.synch(); @@ -31,7 +31,7 @@ function canBePivot(sketchObject, face) { function findDefaultAxis(app, face) { let line; - const preSelected = app.viewer.sketchSelectionMgr.selection[0]; + const preSelected = app.getFirstSelectedFace(); if (canBePivot(preSelected, face)) { line = preSelected; } else { diff --git a/web/app/3d/debug.js b/web/app/3d/debug.js index cc12948c..d2490f08 100644 --- a/web/app/3d/debug.js +++ b/web/app/3d/debug.js @@ -239,7 +239,7 @@ const DebugActions = { cssIcons: ['cutlery'], label: 'print face', info: 'print a face out as JSON', - listens: ['selection'], + listens: ['selection:face'], update: checkForSelectedFaces(1), invoke: (app) => { var s = app.getFirstSelectedFace(); @@ -254,7 +254,7 @@ const DebugActions = { cssIcons: ['cutlery'], label: 'print face id', info: 'print a face id', - listens: ['selection'], + listens: ['selection:face'], update: checkForSelectedFaces(1), invoke: (app) => { console.log(app.getFirstSelectedFace().id); @@ -265,7 +265,7 @@ const DebugActions = { cssIcons: ['cutlery'], label: 'print face sketch', info: 'print face sketch stripping constraints and boundary', - listens: ['selection'], + listens: ['selection:face'], update: checkForSelectedFaces(1), invoke: (app) => { const faceId = app.getFirstSelectedFace().id; diff --git a/web/app/3d/modeler-app.js b/web/app/3d/modeler-app.js index e3a79c34..51b53a1d 100644 --- a/web/app/3d/modeler-app.js +++ b/web/app/3d/modeler-app.js @@ -81,7 +81,7 @@ function App() { this.bus.subscribe("craft", function() { var historyEditMode = app.craft.historyPointer != app.craft.history.length; if (!historyEditMode) { - app.viewer.selectionMgr.clear(); + //app.viewer.selectionMgr.clear(); } app._refreshSketches(); }); @@ -423,11 +423,10 @@ App.prototype.projectStorageKey = function(polyFaceId) { App.prototype.editFace = function() { - if (this.viewer.selectionMgr.selection.length == 0) { - return; + const polyFace = this.getFirstSelectedFace(); + if (polyFace) { + this.sketchFace(polyFace); } - const polyFace = this.viewer.selectionMgr.selection[0]; - this.sketchFace(polyFace); }; App.prototype.sketchFace = function(sceneFace) { diff --git a/web/app/3d/ui/ctrl.js b/web/app/3d/ui/ctrl.js index 04da9d6b..590f3e88 100644 --- a/web/app/3d/ui/ctrl.js +++ b/web/app/3d/ui/ctrl.js @@ -161,7 +161,7 @@ UI.prototype.createWizardForOperation = function(op) { var initParams = op.params; var face = op.face !== undefined ? this.app.findFace(op.face) : null; if (face != null) { - this.app.context.bus.dispatch('selection:face', face); + this.app.context.bus.dispatch('selection:face', [face]); } return this.createWizard(op.type, true, initParams, face); }; diff --git a/web/test/cases/brep-bool-wizard-based.js b/web/test/cases/brep-bool-wizard-based.js index 15485f67..fbfdc204 100644 --- a/web/test/cases/brep-bool-wizard-based.js +++ b/web/test/cases/brep-bool-wizard-based.js @@ -154,7 +154,7 @@ function setSketch(win, app, faceId, data) { } function selectFace(app, faceId) { - app.viewer.selectionMgr.select(app.findFace(faceId)); + app.bus.dispatch('selection:face', [app.findFace(faceId)]); } function assertScene(app, env, expected) {