From 16028b60f4ce460c1918fea7c1b9fa89ac3ad9b7 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Fri, 9 Sep 2016 20:47:09 -0700 Subject: [PATCH] solid transformation controls --- web/app/3d/ctrl.js | 6 ++++- web/app/3d/viewer.js | 46 ++++++++++++++++++++++++--------- web/app/3d/wizards/transform.js | 35 +++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 web/app/3d/wizards/transform.js diff --git a/web/app/3d/ctrl.js b/web/app/3d/ctrl.js index 3deef3a8..450a3fa7 100644 --- a/web/app/3d/ctrl.js +++ b/web/app/3d/ctrl.js @@ -3,6 +3,7 @@ import * as cad_utils from './cad-utils' import * as math from '../math/math' import * as workbench from './workbench' import {ExtrudeWizard, PlaneWizard} from './wizards/wizards' +import {TransformWizard} from './wizards/transform' import {IO} from '../sketcher/io' function UI(app) { @@ -149,7 +150,10 @@ function UI(app) { })); var stl = CSG.fromPolygons(allPolygons).toStlString(); IO.exportTextData(stl.data[0], app.id + ".stl"); - }) + }); + app.bus.subscribe("solid-pick", function(solid) { + new TransformWizard(app.viewer, solid).createUI(mainBox); + }); } UI.prototype.getInfoForOp = function(op) { diff --git a/web/app/3d/viewer.js b/web/app/3d/viewer.js index 6b6c1b44..6490c535 100644 --- a/web/app/3d/viewer.js +++ b/web/app/3d/viewer.js @@ -109,7 +109,11 @@ function Viewer(bus) { }; function onClick(e) { - viewer.selectionMgr.handlePick(e); + if (e.button != 0) { + viewer.handleSolidPick(e); + } else { + viewer.selectionMgr.handlePick(e); + } } var mouseState = { @@ -143,6 +147,29 @@ function Viewer(bus) { animate(); } +Viewer.prototype.handleSolidPick = function(e) { + this.raycastFaces(event, this, function(sketchFace) { + this.selectionMgr.clear(); + this.bus.notify("solid-pick", sketchFace.solid); + this.render(); + return false; + }); +}; + + +Viewer.prototype.raycastFaces = function(event, scope, visitor) { + var pickResults = this.raycast(event); + for (var i = 0; i < pickResults.length; i++) { + var pickResult = pickResults[i]; + if (!!pickResult.face && pickResult.face.__TCAD_polyFace !== undefined) { + var sketchFace = pickResult.face.__TCAD_polyFace; + if (!visitor.call(scope, sketchFace)) { + break; + } + } + } +}; + Viewer.setFacesColor = function(faces, color) { for (var i = 0; i < faces.length; ++i) { var face = faces[i]; @@ -200,18 +227,13 @@ SelectionManager.prototype.updateBasis = function(basis, depth) { }; SelectionManager.prototype.handlePick = function(event) { - - var pickResults = this.viewer.raycast(event); - for (var i = 0; i < pickResults.length; i++) { - var pickResult = pickResults[i]; - if (!!pickResult.face && pickResult.face.__TCAD_polyFace !== undefined) { - var sketchFace = pickResult.face.__TCAD_polyFace; - if (!this.contains(sketchFace)) { - this.select(sketchFace); - break; - } + this.viewer.raycastFaces(event, this, function(sketchFace) { + if (!this.contains(sketchFace)) { + this.select(sketchFace); + return false; } - } + return true; + }); }; SelectionManager.prototype.select = function(sketchFace) { diff --git a/web/app/3d/wizards/transform.js b/web/app/3d/wizards/transform.js new file mode 100644 index 00000000..ab4d6e07 --- /dev/null +++ b/web/app/3d/wizards/transform.js @@ -0,0 +1,35 @@ +import * as tk from '../../ui/toolkit' + +export function TransformWizard(viewer, solid) { + this.viewer = viewer; + this.solid = solid; +} + +TransformWizard.prototype.createUI = function(alignComponent) { + this.viewer.transformControls.attach(this.solid.cadGroup); + this.viewer.render(); + var box = new tk.Box(); + box.root.css({left : (alignComponent.root.width() + 10) + 'px', top : 0}); + var folder = new tk.Folder("Transformation"); + tk.add(box, folder); + var wizard = this; + function close() { + box.close(); + wizard.dispose(); + } + function apply() { + //app.craft.modify({ + // type: 'PLANE', + // solids : [], + // params : wizard.operationParams, + // protoParams : protoParams() + //}, overiding); + close(); + } + tk.add(folder, new tk.ButtonRow(["Cancel", "Apply"], [close, apply])); +}; + +TransformWizard.prototype.dispose = function() { + this.viewer.transformControls.detach(this.solid.cadGroup); + this.viewer.render(); +};