From e97a7ba206150d7e2176ec444d0f8fd2fc7e5987 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Tue, 3 Nov 2015 23:59:10 -0800 Subject: [PATCH] grouping to curved surface --- web/app/3d/viewer.js | 18 ++++++++++++++---- web/app/engine.js | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/web/app/3d/viewer.js b/web/app/3d/viewer.js index b5b30ad4..68bac148 100644 --- a/web/app/3d/viewer.js +++ b/web/app/3d/viewer.js @@ -117,7 +117,7 @@ TCAD.Viewer = function(bus) { **/ - this.selectionMgr = new TCAD.FaceSelectionManager( 0xFAFAD2, null); + this.selectionMgr = new TCAD.FaceSelectionManager( 0xFAFAD2, 0xFF0000, null); var raycaster = new THREE.Raycaster(); @@ -198,16 +198,26 @@ TCAD.Viewer.prototype.select = function(polyFace) { this.bus.notify('selection', polyFace); }; -TCAD.FaceSelectionManager = function(selectionColor, defaultColor) { +TCAD.FaceSelectionManager = function(selectionColor, readOnlyColor, defaultColor) { this.selectionColor = selectionColor; + this.readOnlyColor = readOnlyColor; this.defaultColor = defaultColor; this.selection = []; }; TCAD.FaceSelectionManager.prototype.select = function(polyFace) { this.clear(); - this.selection.push(polyFace); - TCAD.view.setFaceColor(polyFace, this.selectionColor); + if (polyFace.curvedSurfaces !== null) { + for (var i = 0; i < polyFace.curvedSurfaces.length; i++) { + var face = polyFace.curvedSurfaces[i]; + this.selection.push(face); + TCAD.view.setFaceColor(face, this.readOnlyColor); + } + } else { + this.selection.push(polyFace); + TCAD.view.setFaceColor(polyFace, this.selectionColor); + } + }; TCAD.FaceSelectionManager.prototype.contains = function(polyFace) { diff --git a/web/app/engine.js b/web/app/engine.js index e869d716..1ffdb860 100644 --- a/web/app/engine.js +++ b/web/app/engine.js @@ -502,6 +502,10 @@ TCAD.utils.getDerivedID = function(shared) { return shared.__tcad && !!shared.__tcad.csgInfo && !!shared.__tcad.csgInfo.derivedFrom ? shared.__tcad.csgInfo.derivedFrom.id : null; }; +TCAD.utils.getDerivedFrom = function(shared) { + return shared.__tcad && !!shared.__tcad.csgInfo && !!shared.__tcad.csgInfo.derivedFrom ? shared.__tcad.csgInfo.derivedFrom : null; +}; + /** @constructor */ TCAD.Solid = function(csg, material) { THREE.Geometry.call( this ); @@ -518,6 +522,7 @@ TCAD.Solid = function(csg, material) { this.polyFaces = []; this.wires = TCAD.struct.hashTable.forEdge(); + this.curvedSurfaces = {}; var scope = this; function threeV(v) {return new THREE.Vector3( v.x, v.y, v.z )} @@ -553,6 +558,7 @@ TCAD.Solid = function(csg, material) { //TCAD.view.setFaceColor(polyFace, TCAD.utils.isSmoothPiece(group.shared) ? 0xFF0000 : null); off = this.vertices.length; } + this.collectCurvedSurface(polyFace); this.collectWires(polyFace); } @@ -565,6 +571,18 @@ if (typeof THREE !== "undefined") { TCAD.Solid.prototype = Object.create( THREE.Geometry.prototype ); } +TCAD.Solid.prototype.collectCurvedSurface = function(face) { + var derivedFrom = TCAD.utils.getDerivedFrom(face.csgGroup.shared); + if (derivedFrom === null || derivedFrom._class !== "TCAD.TWO.Arc" && derivedFrom._class !== "TCAD.TWO.Circle" ) return; + var surfaces = this.curvedSurfaces[derivedFrom.id]; + if (surfaces === undefined) { + surfaces = []; + this.curvedSurfaces[derivedFrom.id] = surfaces; + } + surfaces.push(face); + face.curvedSurfaces = surfaces; +}; + TCAD.Solid.prototype.collectWires = function(face) { function contains(planes, plane) { @@ -649,6 +667,7 @@ TCAD.SketchFace = function(solid, csgGroup) { this.csgGroup = csgGroup; this.faces = []; this.sketch3DGroup = null; + this.curvedSurfaces = null; }; if (typeof THREE !== "undefined") {