From 3bb0e518025af0a93adb3e05f3e8329adb642f8d Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Mon, 4 Apr 2022 01:14:44 -0700 Subject: [PATCH] enter sketch mode on sketch object double click --- .../scene/controls/mouseEventSystemPlugin.js | 26 ++++++++++++++++++- .../cad/scene/controls/pickControlPlugin.ts | 4 +-- web/app/cad/scene/views/curveBasedView.js | 8 ++++-- web/app/cad/scene/views/sketchLoopView.js | 11 ++++++-- web/app/cad/scene/views/sketchObjectView.js | 3 +++ web/app/cad/scene/views/view.js | 4 +++ web/app/cad/sketch/sketcherPlugin.ts | 1 + 7 files changed, 50 insertions(+), 7 deletions(-) diff --git a/web/app/cad/scene/controls/mouseEventSystemPlugin.js b/web/app/cad/scene/controls/mouseEventSystemPlugin.js index b5af877c..374bccaf 100644 --- a/web/app/cad/scene/controls/mouseEventSystemPlugin.js +++ b/web/app/cad/scene/controls/mouseEventSystemPlugin.js @@ -11,6 +11,7 @@ export function activate(ctx) { domElement.addEventListener('mousedown', mousedown, false); domElement.addEventListener('mouseup', mouseup, false); domElement.addEventListener('mousemove', mousemove, false); + domElement.addEventListener('dblclick', dblclick, false); let performRaycast = e => { @@ -149,8 +150,31 @@ export function activate(ctx) { valid.clear(); } + function dblclick(e) { + let hits = performRaycast(e); + dispatchDblclick(e, hits); + } + + function dispatchDblclick(e, hits) { + event.mouseEvent = e; + event.hits = hits; + for (let hit of hits) { + if (LOG_FLAGS.PICK) { + printRaycastDebugInfo('dblclick', hit); + } + let obj = hit.object; + if (obj && obj.onDblclick) { + obj.onDblclick(event); + } + if (!hit.object.passMouseEvent || !hit.object.passMouseEvent(event)) { + break; + } + } + } + + ctx.services.modelMouseEventSystem = { - dispatchMousedown, dispatchMouseup, dispatchMousemove + dispatchMousedown, dispatchMouseup, dispatchMousemove, dispatchDblclick } } diff --git a/web/app/cad/scene/controls/pickControlPlugin.ts b/web/app/cad/scene/controls/pickControlPlugin.ts index 94607658..68b08cc9 100644 --- a/web/app/cad/scene/controls/pickControlPlugin.ts +++ b/web/app/cad/scene/controls/pickControlPlugin.ts @@ -131,7 +131,7 @@ export function activate(context) { let TOL = 1; if (dx < TOL && dy < TOL) { if (e.button !== 0) { - handleSolidPick(e); + // handleSolidPick(e); } else { handlePick(e); } @@ -139,7 +139,7 @@ export function activate(context) { } function mousedblclick(e) { - handleSolidPick(e); + // handleSolidPick(e); } function clickaway() { diff --git a/web/app/cad/scene/views/curveBasedView.js b/web/app/cad/scene/views/curveBasedView.js index 3b647aae..9411f290 100644 --- a/web/app/cad/scene/views/curveBasedView.js +++ b/web/app/cad/scene/views/curveBasedView.js @@ -20,10 +20,14 @@ export class CurveBasedView extends View { this.rootGroup.add(this.marker); this.rootGroup.add(this.picker); this.picker.onMouseEnter = () => { - this.ctx.highlightService.highlight(this.model.id); + if (!this.isDisposed) { + this.ctx.highlightService.highlight(this.model.id); + } } this.picker.onMouseLeave = () => { - this.ctx.highlightService.unHighlight(this.model.id); + if (!this.isDisposed) { + this.ctx.highlightService.unHighlight(this.model.id); + } } } diff --git a/web/app/cad/scene/views/sketchLoopView.js b/web/app/cad/scene/views/sketchLoopView.js index be96e15a..880280d7 100644 --- a/web/app/cad/scene/views/sketchLoopView.js +++ b/web/app/cad/scene/views/sketchLoopView.js @@ -65,12 +65,19 @@ export class SketchLoopView extends View { this.rootGroup.add(this.mesh); this.mesh.onMouseEnter = () => { - this.ctx.highlightService.highlight(this.model.id); + if (!this.isDisposed) { + this.ctx.highlightService.highlight(this.model.id); + } } this.mesh.onMouseLeave = () => { - this.ctx.highlightService.unHighlight(this.model.id); + if (!this.isDisposed) { + this.ctx.highlightService.unHighlight(this.model.id); + } } this.mesh.raycastPriority = 10; + this.mesh.onDblclick = () => { + ctx.sketcherService.sketchFace(this.model.face); + } } updateVisuals() { diff --git a/web/app/cad/scene/views/sketchObjectView.js b/web/app/cad/scene/views/sketchObjectView.js index 807c942d..28ad6633 100644 --- a/web/app/cad/scene/views/sketchObjectView.js +++ b/web/app/cad/scene/views/sketchObjectView.js @@ -6,5 +6,8 @@ export class SketchObjectView extends CurveBasedView { const color = mSketchObject.construction ? 0x777777 : 0x0000FF; const tess = mSketchObject.sketchPrimitive.tessellate(10).map(sketchToWorldTransformation.apply).map(v => v.data()); super(ctx, mSketchObject, tess, 3, 4, color, 0x49FFA5, true); + this.picker.onDblclick = () => { + ctx.sketcherService.sketchFace(this.model.face); + } } } diff --git a/web/app/cad/scene/views/view.js b/web/app/cad/scene/views/view.js index d5238e7c..a50b6691 100644 --- a/web/app/cad/scene/views/view.js +++ b/web/app/cad/scene/views/view.js @@ -95,6 +95,10 @@ export class View { this.model.ext.view = null; this.model = null; }; + + get isDisposed() { + return this.model === null; + } } diff --git a/web/app/cad/sketch/sketcherPlugin.ts b/web/app/cad/sketch/sketcherPlugin.ts index d9a612b1..e4530809 100644 --- a/web/app/cad/sketch/sketcherPlugin.ts +++ b/web/app/cad/sketch/sketcherPlugin.ts @@ -151,6 +151,7 @@ export function activate(ctx) { if (inPlaceEditor.inEditMode) { inPlaceEditor.exit(); } + ctx.pickControlService.deselectAll(); inPlaceEditor.enter(face); }