From a1e1faa6915445e786f482170576b9c9d0f5d982 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 4 Nov 2019 14:36:21 +0200 Subject: [PATCH] Fixed variable angle turns when they are not connected Now unconnected variable angle turns behave like fixed angle turns until they are connected from both sides. Additionally, added default parameter loading for geometry provides so that they get proper initial values. gitlab #46 Change-Id: Id7dede974fcfc69370930dba01d5a87091be671d --- .../graph/plant3d_builtins.pgraph | 6 +- .../plant3d/actions/AddComponentAction.java | 5 +- .../plant3d/actions/RoutePipeAction.java | 4 +- .../TranslateFreeVariableLengthAction.java | 2 +- .../actions/TranslateInlineAction.java | 4 +- .../plant3d/editor/Plant3DEditor.java | 30 +++++++++- .../plant3d/geometry/ParameterRead.java | 44 ++++++++++++++ .../plant3d/scenegraph/TurnComponent.java | 14 +++-- .../controlpoint/PipeControlPoint.java | 58 +++++++++++++++---- .../scenegraph/controlpoint/PipingRules.java | 36 ++++-------- .../plant3d/utils/ComponentUtils.java | 11 +++- 11 files changed, 159 insertions(+), 55 deletions(-) create mode 100644 org.simantics.plant3d/src/org/simantics/plant3d/geometry/ParameterRead.java diff --git a/org.simantics.plant3d.ontology/graph/plant3d_builtins.pgraph b/org.simantics.plant3d.ontology/graph/plant3d_builtins.pgraph index fc3c0083..4895630f 100644 --- a/org.simantics.plant3d.ontology/graph/plant3d_builtins.pgraph +++ b/org.simantics.plant3d.ontology/graph/plant3d_builtins.pgraph @@ -132,7 +132,8 @@ P3D.Builtin.Elbow90 0); } @@ -326,7 +326,7 @@ public class RoutePipeAction extends vtkSwtAction { start.getControlPointEnds(previousPosition,v); } } else if (startComponent instanceof TurnComponent) { - if (start.isFixed()) { + if (start.asFixedAngle()) { direction = startComponent.getControlPoint().getPathLegDirection(reversed ? Direction.PREVIOUS : Direction.NEXT); lock = LockType.CUSTOM; } else { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java index e693f1fb..16a38820 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateFreeVariableLengthAction.java @@ -108,7 +108,7 @@ public class TranslateFreeVariableLengthAction extends RoutePipeAction{ start.getControlPointEnds(previousPosition,v); } } else if (startComponent instanceof TurnComponent) { - if (start.isFixed()) { + if (start.asFixedAngle()) { direction = startComponent.getControlPoint().getPathLegDirection(reversed ? Direction.PREVIOUS : Direction.NEXT); lock = LockType.CUSTOM; } else { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java index 92a88b53..594c73d3 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/actions/TranslateInlineAction.java @@ -53,9 +53,9 @@ public class TranslateInlineAction extends TranslateAction{ setEnabled(false); return; } - if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixed() && prev.getPrevious() != null) + if (prev.getControlPoint().isInline() && !prev.getControlPoint().isFixedLength() && prev.getPrevious() != null) prev = prev.getPrevious(); - if (next.getControlPoint().isInline() && !next.getControlPoint().isFixed() && next.getNext() != null) { + if (next.getControlPoint().isInline() && !next.getControlPoint().isFixedLength() && next.getNext() != null) { next = next.getNext(); } Point3d ns = new Point3d(); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index 44e65292..e7db15d1 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -75,11 +75,15 @@ import org.simantics.utils.ui.ExceptionUtils; import vtk.vtkActor; import vtk.vtkCameraPass; import vtk.vtkDefaultPass; +import vtk.vtkGaussianBlurPass; import vtk.vtkLightsPass; import vtk.vtkProp; import vtk.vtkRenderPassCollection; import vtk.vtkRenderer; +import vtk.vtkSSAAPass; import vtk.vtkSequencePass; +import vtk.vtkSimpleMotionBlurPass; +import vtk.vtkSobelGradientMagnitudePass; public class Plant3DEditor extends ResourceEditorPart { @@ -308,6 +312,10 @@ public class Plant3DEditor extends ResourceEditorPart { vtkRenderer ren1 = panel.getRenderer(); boolean multiPass = false; + boolean blur = false; + boolean ssaa = false; + //boolean sobel = true; + boolean mblur = false; if (multiPass) { vtkLightsPass lightsPass = new vtkLightsPass(); @@ -324,8 +332,26 @@ public class Plant3DEditor extends ResourceEditorPart { vtkCameraPass cameraPass = new vtkCameraPass(); cameraPass.SetDelegatePass(seq); - ren1.SetPass(cameraPass); - + if (blur) { + vtkGaussianBlurPass blurPass = new vtkGaussianBlurPass(); + blurPass.SetDelegatePass(cameraPass); + ren1.SetPass(blurPass); + } else if (ssaa) { + vtkSSAAPass ssaaPass = new vtkSSAAPass(); + ssaaPass.SetDelegatePass(cameraPass); + ren1.SetPass(ssaaPass); + } else if (mblur) { + vtkSimpleMotionBlurPass mBlurPass = new vtkSimpleMotionBlurPass(); + mBlurPass.SetDelegatePass(cameraPass); + ren1.SetPass(mBlurPass); +// } else if (sobel) { +// vtkSobelGradientMagnitudePass sobelPass = new vtkSobelGradientMagnitudePass(); +// sobelPass.SetDelegatePass(sobelPass); +// ren1.SetPass(sobelPass); + } else { + ren1.SetPass(cameraPass); + } + } // ren1.GetRenderWindow().LineSmoothingOn(); // ren1.GetRenderWindow().PointSmoothingOn(); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ParameterRead.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ParameterRead.java new file mode 100644 index 00000000..e69b1b99 --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ParameterRead.java @@ -0,0 +1,44 @@ +package org.simantics.plant3d.geometry; + +import java.util.HashMap; +import java.util.Map; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.plant3d.ontology.Plant3D; + +public class ParameterRead extends ResourceRead> { + + public ParameterRead(Resource resource) { + super(resource); + } + + @Override + public Map perform(ReadGraph graph) throws DatabaseException { + Map parameters = new HashMap<>(); + Layer0 L0 = Layer0.getInstance(graph); + Plant3D P3D = Plant3D.getInstance(graph); + + for (Resource assertion : graph.getObjects(resource, L0.Asserts)) { + Resource rel = graph.getSingleObject(assertion, L0.HasPredicate); + if (!rel.equals(P3D.hasParameter)) + continue; + Resource param = graph.getSingleObject(assertion, L0.HasObject); + String name = graph.getRelatedValue(param, L0.HasName, Bindings.STRING); + Object value = graph.getRelatedValue(param, P3D.hasParameterValue); + parameters.put(name, value); + } + for (Resource param : graph.getObjects(resource, P3D.hasParameter)) { + String name = graph.getRelatedValue(param, L0.HasName, Bindings.STRING); + Object value = graph.getRelatedValue(param, P3D.hasParameterValue); + parameters.put(name, value); + } + + return parameters; + } + + } \ No newline at end of file diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java index 0e307a47..a1374def 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/TurnComponent.java @@ -70,7 +70,7 @@ public class TurnComponent extends PipelineComponent { @Override public void updateParameters() { super.updateParameters(); - if (!isVariableAngle()) { + if (controlPoint.asFixedAngle()) { Map calculated = getCalculatedParameters(); if (calculated.containsKey("length")) { controlPoint.setLength((Double)calculated.get("length")); @@ -81,12 +81,14 @@ public class TurnComponent extends PipelineComponent { @RelatedGetValue(Plant3D.URIs.HasTurnAngle) public Double getTurnAngle() { + if (!getControlPoint().asFixedAngle()) + return null; return getControlPoint().getTurnAngle(); } @RelatedSetValue(Plant3D.URIs.HasTurnAngle) public void setTurnAngle(Double a) { - if (!getControlPoint().isFixed()) + if (!getControlPoint().asFixedAngle()) return; getControlPoint().setTurnAngle(a); } @@ -140,7 +142,7 @@ public class TurnComponent extends PipelineComponent { @RelatedGetValue(Plant3D.URIs.HasRotationAngle) @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default") public Double getRotationAngle() { - if (!controlPoint.isFixed()) + if (!controlPoint.asFixedAngle()) return null; Double d = controlPoint.getRotationAngle(); if (d == null) @@ -150,7 +152,7 @@ public class TurnComponent extends PipelineComponent { @RelatedSetValue(Plant3D.URIs.HasRotationAngle) @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle) public void setRotationAngle(Double angle) { - if (!controlPoint.isFixed()) + if (!controlPoint.asFixedAngle()) return; if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) { @@ -166,14 +168,14 @@ public class TurnComponent extends PipelineComponent { @RelatedGetValue(Plant3D.URIs.IsReversed) @GetPropertyValue(name="Reverse", value=Plant3D.URIs.IsReversed, tabId = "Default") public Boolean isReversed() { - if (!controlPoint.isFixed()) + if (!controlPoint.asFixedAngle()) return null; Boolean d = controlPoint._getReversed(); return d; } @RelatedSetValue(Plant3D.URIs.IsReversed) public void setReversed(Boolean reverse) { - if (!controlPoint.isFixed()) + if (!controlPoint.asFixedAngle()) return; if (reverse == null) { diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java index cb76b74f..8219c1d6 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java @@ -35,12 +35,12 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { private PipelineComponent component; private PointType type; - private boolean isFixed = true; - private boolean isRotate = false; - private boolean isReverse = false; - private boolean isDeletable = true; - private boolean isSizeChange = false; - private boolean isSub = false; + private boolean isFixed = true; // In-line: fixed-length Turn: fixed-angle + private boolean isRotate = false; // rotates around path leg axis. + private boolean isReverse = false; // definition direction can be swapped + private boolean isDeletable = true; // can be removed by rules + private boolean isSizeChange = false; // changes size of the pipe. The next control point / component is on different PipeRun + private boolean isSub = false; // child point public PipeControlPoint(PipelineComponent component) { this.component = component; @@ -85,7 +85,6 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { return isFixed; } - public void setFixed(boolean fixed) { this.isFixed = fixed; } @@ -137,10 +136,20 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { return type == PointType.INLINE; } + /** + * True for end components, if control point defines absolute position direction, which rules cannot modify. + * This is typical for nozzles. + * @return + */ public boolean isDirected() { return isFixed && isEnd(); } + /** + * True for end components, if control is opposite to directed, and rules can modify position and orientation. + * This is typical for caps, and other end components. + * @return + */ public boolean isNonDirected() { return !isFixed && isEnd(); } @@ -148,10 +157,35 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { public boolean isVariableLength() { return !isFixed && isInline(); } + + /** + * Fixed length in-line component is such that piping rules cannot modify the length. + * @return + */ + public boolean isFixedLength() { + return isFixed && isInline(); + } public boolean isVariableAngle() { return !isFixed && isTurn(); } + + /** + * Fixed angle turn component is such that piping rules cannot modify the angle. + * @return + */ + public boolean isFixedAngle() { + return isFixed && isTurn(); + } + + /** + * Does the turn behave like fixed angle? + * For variable angle turns, the turn angle is defined by connected components, and without them, we must handle the component as fixed angle. + * @return + */ + public boolean asFixedAngle() { + return isTurn() && (isFixed || next == null || previous == null); + } public boolean isBranchEnd() { return isDeletable && isEnd(); @@ -628,7 +662,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { public Vector3d getDirection(Direction direction) { if (isDirected()) return getDirectedControlPointDirection(); - if (isTurn() && isFixed()) { + if (isTurn() && asFixedAngle()) { if (direction == Direction.NEXT) { if (previous != null) { PipeControlPoint pcp = this; @@ -687,7 +721,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { return getDirectedControlPointDirection(); } else { - if (isVariableAngle()) + if (isVariableAngle() && !asFixedAngle()) throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this); if (isInline()) { PipeControlPoint pcp = this; @@ -703,7 +737,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { Vector3d v = new Vector3d(); v.sub(getWorldPosition(),previous.getWorldPosition()); return v; - } else if (isTurn() && isFixed() && !_getReversed()) { + } else if (isTurn() && asFixedAngle() && !_getReversed()) { return getDirection(Direction.NEXT); } throw new RuntimeException("Missing implementation " + this); @@ -725,7 +759,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { v.negate(); return v; } else { - if (isVariableAngle()) + if (isVariableAngle() && !asFixedAngle()) throw new RuntimeException("Cannot calculate path leg direction for unconnected variable angle control point " + this); if (isInline()) { PipeControlPoint pcp = this; @@ -743,7 +777,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { Vector3d v = new Vector3d(); v.sub(getWorldPosition(),next.getWorldPosition()); return v; - } else if (isTurn() && isFixed() && _getReversed()) { + } else if (isTurn() && asFixedAngle() && _getReversed()) { return getDirection(Direction.PREVIOUS); } throw new RuntimeException("Missing implementation " + this); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java index 727cf1a8..393dc85e 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipingRules.java @@ -461,7 +461,7 @@ public class PipingRules { private static boolean asDirected(PipeControlPoint pcp, Direction direction) { if (pcp.isDirected()) return true; - if (pcp.isTurn() && pcp.isFixed()) { + if (pcp.asFixedAngle()) { if (!pcp._getReversed()) return direction == Direction.NEXT; else @@ -498,7 +498,7 @@ public class PipingRules { if (DEBUG) System.out.println("PipingRules.updateFreePipeRun " + u + " " + lengthChange); checkExpandPathLeg(u, lengthChange); - if (u.start.isInline() || u.end.isInline() || u.start.isFixed() || u.end.isFixed()) + if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle()|| u.end.asFixedAngle()) processPathLeg(u, true, false); } @@ -873,7 +873,7 @@ public class PipingRules { double distance = t.length(); boolean aligned = (distance < ALLOWED_OFFSET); if (aligned) { - if (u.start.isInline() || u.end.isInline() || u.start.isFixed() || u.end.isFixed()) + if (u.start.isInline() || u.end.isInline() || u.start.asFixedAngle() || u.end.asFixedAngle()) processPathLeg(u, true, false); checkExpandPathLeg(u, lengthChange, inlineEnd); @@ -1486,24 +1486,9 @@ public class PipingRules { private static void updateEndComponentControlPoint(PipeControlPoint ecp, Vector3d start, Vector3d end) throws Exception { if (DEBUG) System.out.println("PipingRules.updateEndComponentControlPoint() " + ecp); - // PipeControlPoint next = ecp.getNext(); - // PipeControlPoint prev = ecp.getPrevious(); - // if (next != null) { - // end = G3DTools.getPoint(next.getLocalPosition()); - // start = G3DTools.getPoint(ecp.getLocalPosition()); - // } else if (prev != null) { - // end = G3DTools.getPoint(ecp.getLocalPosition()); - // start = G3DTools.getPoint(prev.getLocalPosition()); - // } else { - // // TODO : warning? - // return; - // } - // Vector3d dir = new Vector3d (end); - // dir.sub(start); - // dir.normalize(); - // G3DTools.setTuple(ecp.getDirection(), dir); - if (!ecp.isFixed()) - updateControlPointOrientation(ecp); + //FIXME : end control point cannot be fixed! + //if (!ecp.isFixed()) + updateControlPointOrientation(ecp); for (PipeControlPoint pcp : ecp.getSubPoint()) { // TODO update position @@ -1564,7 +1549,7 @@ public class PipingRules { } } - if (!tcp.isFixed()) { + if (!tcp.asFixedAngle()) { if (next == null || prev == null) { @@ -1768,7 +1753,8 @@ public class PipingRules { } } - if (current.isTurn() && current.isFixed()) { + //if (current.isTurn() && current.isFixed()) { + if (current.asFixedAngle()) { current.setReversed(!current._getReversed()); } if (current.isInline() && current.isReverse()) { @@ -1856,8 +1842,8 @@ public class PipingRules { } public static void splitVariableLengthComponent(PipelineComponent newComponent, InlineComponent splittingComponent, boolean assignPos) throws Exception{ - assert(!splittingComponent.getControlPoint().isFixed()); - assert(!(newComponent instanceof InlineComponent && !newComponent.getControlPoint().isFixed())); + assert(!splittingComponent.getControlPoint().isFixedLength()); + assert(!(newComponent instanceof InlineComponent && !newComponent.getControlPoint().isFixedLength())); PipeControlPoint newCP = newComponent.getControlPoint(); PipeControlPoint splittingCP = splittingComponent.getControlPoint(); PipeControlPoint nextCP = splittingCP.getNext(); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java index 4bee16b6..fb065f11 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -16,7 +16,9 @@ import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.scenegraph.GeometryProvider; +import org.simantics.g3d.scenegraph.ParametricGeometryProvider; import org.simantics.layer0.Layer0; +import org.simantics.plant3d.geometry.ParameterRead; import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.EndComponent; import org.simantics.plant3d.scenegraph.Equipment; @@ -49,6 +51,8 @@ public class ComponentUtils { types.add(Plant3D.URIs.Builtin_ConcentricReducer); types.add(Plant3D.URIs.Builtin_BranchSplitComponent); types.add(Plant3D.URIs.Builtin_EccentricReducer); + types.add(Plant3D.URIs.Builtin_Elbow45); + types.add(Plant3D.URIs.Builtin_Elbow90); for (String typeURI : types) { load(graph, typeURI); @@ -72,6 +76,11 @@ public class ComponentUtils { } if (geom != null) { GeometryProvider provider = graph.adapt(geom, GeometryProvider.class); + if (provider instanceof ParametricGeometryProvider) { + Map params = graph.syncRequest(new ParameterRead(type)); + if (params.size() > 0) + ((ParametricGeometryProvider)provider).setProperties(params); + } return provider; } return null; @@ -368,7 +377,7 @@ public class ComponentUtils { } else if (toPcp.isDirected()) { dir = new Vector3d(toPcp.getDirection(Direction.NEXT)); pos = new Vector3d(toPcp.getWorldPosition()); - } else if (toPcp.isTurn() && toPcp.isFixed()) { + } else if (toPcp.isTurn() && toPcp.asFixedAngle()) { dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS)); pos = new Vector3d(toPcp.getWorldPosition()); if (!lengthAdjustable) { -- 2.47.1