From 5f04782f56682abc1e56b84cff4da2e2770f9cf2 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Wed, 7 Nov 2018 21:58:36 -0800 Subject: [PATCH] improve ObjectExplorer to show adjacent faces for an edge --- web/app/cad/craft/ui/ObjectExplorer.jsx | 47 +++++++++++++++++-------- web/app/cad/model/medge.js | 13 +++++++ web/app/cad/model/mface.js | 15 ++++++++ web/app/cad/model/mshell.js | 4 +++ 4 files changed, 65 insertions(+), 14 deletions(-) diff --git a/web/app/cad/craft/ui/ObjectExplorer.jsx b/web/app/cad/craft/ui/ObjectExplorer.jsx index 117bd363..e9ddf31a 100644 --- a/web/app/cad/craft/ui/ObjectExplorer.jsx +++ b/web/app/cad/craft/ui/ObjectExplorer.jsx @@ -1,44 +1,63 @@ import React from 'react'; import connect from 'ui/connect'; import {Section} from 'ui/components/Section'; -import Fa from '../../../../../modules/ui/components/Fa'; -import {constant} from '../../../../../modules/lstream'; +import Fa from 'ui/components/Fa'; +import {constant} from 'lstream'; import ls from './ObjectExplorer.less'; import cx from 'classnames'; import {MShell} from '../../model/mshell'; import {MDatum} from '../../model/mdatum'; +import mapContext from 'ui/mapContext'; +import decoratorChain from 'ui/decoratorChain'; export default connect(streams => streams.craft.models.map(models => ({models}))) (function ObjectExplorer({models}) { - return models.map(m => (m instanceof MShell) ? + return models.map(m => (m instanceof MShell) ?
{ - m.faces.map(f => -
{''}}> - {f.sketchObjects.map(o =>
{o.id + ':' + o.sketchPrimitive.constructor.name}
)} -
-
) + m.faces.map(f => ) }
- {m.edges.map(e => )} + {m.edges.map(e => )}
: (m instanceof MDatum) ? : null); }); -const ModelSection = connect((streams, props) => (streams.selection[props.type]||constant([])).map(selection => ({selection}))) +function EdgeSection({edge}) { + return + {edge.adjacentFaces.map(f => )} + +} + +function FaceSection({face}) { + return +
{''}}> + {face.sketchObjects.map(o =>
{o.id + ':' + o.sketchPrimitive.constructor.name}
)} +
+
+ {face.edges.map(e => )} +
+
; +} + +const ModelSection = decoratorChain( + mapContext((ctx, props) => ({ + select: () => ctx.services.selection[props.type].select([props.model.id]) + })), + connect((streams, props) => (streams.selection[props.type] || constant([])).map(selection => ({selection})))) ( - function ModelSection({model, type, selection, ...props}) { + function ModelSection({model, type, selection, select, ...props}) { let labelClasses = cx(ls.modelLabel, { [ls.selected]: selection.indexOf(model.id) !== -1 }); - let label = - {type} {model.id} + let label = + {type} {model.id} ; - return
+ return
; } ); diff --git a/web/app/cad/model/medge.js b/web/app/cad/model/medge.js index bf942824..914eccdf 100644 --- a/web/app/cad/model/medge.js +++ b/web/app/cad/model/medge.js @@ -11,4 +11,17 @@ export class MEdge extends MObject { this.brepEdge = brepEdge; } + get adjacentFaces() { + let out = []; + let face = this.shell.brepRegistry.get(this.brepEdge.halfEdge1 && this.brepEdge.halfEdge1.loop.face); + if (face) { + out.push(face); + } + face = this.shell.brepRegistry.get(this.brepEdge.halfEdge2 && this.brepEdge.halfEdge2.loop.face); + if (face) { + out.push(face); + } + return out; + } + } \ No newline at end of file diff --git a/web/app/cad/model/mface.js b/web/app/cad/model/mface.js index 595f68fc..2a35dd54 100644 --- a/web/app/cad/model/mface.js +++ b/web/app/cad/model/mface.js @@ -75,6 +75,10 @@ export class MFace extends MObject { this.sketch = sketch; this.sketchObjects = []; + if (!sketch) { + return; + } + const addSketchObjects = sketchObjects => { let isConstruction = sketchObjects === sketch.constructionSegments; for (let sketchObject of sketchObjects) { @@ -131,6 +135,17 @@ export class MBrepFace extends MFace { this.brepFace = brepFace; } + get edges() { + let out = []; + for (let he of this.brepFace.edges) { + let edge = this.shell.brepRegistry.get(he.edge); + if (edge) { + out.push(edge); + } + } + return out; + } + getBounds() { const bounds = []; for (let loop of this.brepFace.loops) { diff --git a/web/app/cad/model/mshell.js b/web/app/cad/model/mshell.js index 021283c4..e2d76de5 100644 --- a/web/app/cad/model/mshell.js +++ b/web/app/cad/model/mshell.js @@ -23,6 +23,7 @@ export class MBrepShell extends MShell { super(); this.brepShell = shell; this.csys = csys || CSys.ORIGIN; + this.brepRegistry = new Map(); let faceCounter = 0; let edgeCounter = 0; @@ -31,16 +32,19 @@ export class MBrepShell extends MShell { for (let brepFace of this.brepShell.faces) { const mFace = new MBrepFace(brepFace.data.id || (this.id + '/F:' + faceCounter++), this, brepFace); this.faces.push(mFace); + this.brepRegistry.set(brepFace, mFace); } for (let brepEdge of this.brepShell.edges) { const mEdge = new MEdge(this.id + '/E:' + edgeCounter++, this, brepEdge); this.edges.push(mEdge); + this.brepRegistry.set(brepEdge, mEdge); } for (let brepVertex of this.brepShell.vertices) { const mVertex = new MVertex(this.id + '/V:' + vertexCounter++, this, brepVertex); this.vertices.push(mVertex); + this.brepRegistry.set(brepVertex, mVertex); } } }