From: Marko Luukkainen Date: Tue, 16 Jul 2019 16:25:00 +0000 (+0300) Subject: Support for inline component rotations X-Git-Tag: v1.43.0~249 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F22%2F3022%2F1;p=simantics%2F3d.git Support for inline component rotations * P3D.RotateComponent tag * P3D.HasRotationAngle property relation * PipeControlPoint rotate flag * InlineComponent get/set RotationAngle methods * Gate Valve inline component for testing the feature gitlab #13 Change-Id: I2a1fb87a5de312d2870189b0e81791feeec1f652 --- diff --git a/org.simantics.plant3d.ontology/graph/plant3d.pgraph b/org.simantics.plant3d.ontology/graph/plant3d.pgraph index 8edc9f61..d7dce09e 100644 --- a/org.simantics.plant3d.ontology/graph/plant3d.pgraph +++ b/org.simantics.plant3d.ontology/graph/plant3d.pgraph @@ -67,9 +67,11 @@ P3D.VariableAngleTurnComponent + + + diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/GateValveGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/GateValveGeometryProvider.java new file mode 100644 index 00000000..90c39363 --- /dev/null +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/GateValveGeometryProvider.java @@ -0,0 +1,58 @@ +package org.simantics.plant3d.geometry; + +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +import org.jcae.opencascade.jni.TopoDS_Shape; +import org.simantics.db.Resource; +import org.simantics.g3d.math.MathTools; +import org.simantics.opencascade.OccTriangulator; + +public class GateValveGeometryProvider extends BuiltinGeometryProvider { + + public GateValveGeometryProvider(Resource resource) { + super(resource); + } + + private double radius = 0.01; + + @Override + public Collection getModel() throws Exception { + + TopoDS_Shape con = OccTriangulator.makeCone(new double[] {-radius, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, radius*0.1,radius); + TopoDS_Shape con2 = OccTriangulator.makeCone(new double[] {radius, 0.0, 0.0}, new double[] { -1.0, 0.0, 0.0 }, radius, radius*0.1,radius); + //TopoDS_Shape sph = OccTriangulator.makeSphere(0, 0, 0, radius*0.75); + //TopoDS_Shape cyl = OccTriangulator.makeCylinder(new double[] {0.0, 0.0, 0.0}, new double[] { 0.0, 1.0, 0.0 }, radius*0.75, radius*2); + TopoDS_Shape cyl = OccTriangulator.makeFillet(OccTriangulator.makeBox(-radius*0.5, -radius*0.5, -radius*0.75, radius*0.5, radius*1.25, radius*0.75), radius*0.25); + //TopoDS_Shape cyl = OccTriangulator.makeChamfer(OccTriangulator.makeBox(-radius*0.5, -radius*0.5, -radius*0.75, radius*0.5, radius*1.25, radius*0.75), radius*0.25); + TopoDS_Shape cyl2 = OccTriangulator.makeCylinder(new double[] {0.0, 0.0, 0.0}, new double[] { 0.0, 1.0, 0.0 }, radius*0.125, radius*2); + TopoDS_Shape tor = OccTriangulator.makeTorus(new double[] { 0.0, radius*2, 0.0}, new double[] { 0.0, 1.0, 0.0 }, radius*0.5, radius*0.125); + + TopoDS_Shape shape = OccTriangulator.makeCompound(new TopoDS_Shape[] {con,con2,cyl,cyl2,tor}); + cyl.delete(); + con.delete(); + con2.delete(); + //sph.delete(); + tor.delete(); + return Collections.singletonList(shape); + } + + @Override + public void setProperties(Map props) { + if (props.containsKey("radius")) { + radius = (Double)props.get("radius"); + } + if (radius < MathTools.NEAR_ZERO) + radius = MathTools.NEAR_ZERO; + + } + + @Override + public void updateCalculatedProperties(Map returnProps) { + returnProps.put("length", radius*2); + + } + + +} diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java index a7c32a66..29a6869f 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java @@ -4,16 +4,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; -import org.jcae.opencascade.jni.BRepBuilderAPI_MakeEdge; -import org.jcae.opencascade.jni.BRepBuilderAPI_MakeFace; -import org.jcae.opencascade.jni.BRepBuilderAPI_MakeWire; -import org.jcae.opencascade.jni.BRepPrimAPI_MakeRevol; -import org.jcae.opencascade.jni.GC_MakeArcOfCircle; -import org.jcae.opencascade.jni.GC_MakeSegment; -import org.jcae.opencascade.jni.TopoDS_Edge; -import org.jcae.opencascade.jni.TopoDS_Face; import org.jcae.opencascade.jni.TopoDS_Shape; -import org.jcae.opencascade.jni.TopoDS_Wire; import org.simantics.db.Resource; import org.simantics.opencascade.OccTriangulator; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java index a1558c86..e098de63 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java @@ -3,13 +3,19 @@ package org.simantics.plant3d.scenegraph; import java.util.HashMap; import java.util.Map; +import org.simantics.g3d.math.MathTools; +import org.simantics.g3d.property.annotations.GetPropertyValue; +import org.simantics.g3d.property.annotations.SetPropertyValue; import org.simantics.g3d.scenegraph.base.ParentNode; import org.simantics.objmap.graph.annotations.DynamicGraphType; import org.simantics.objmap.graph.annotations.GetType; +import org.simantics.objmap.graph.annotations.RelatedGetValue; +import org.simantics.objmap.graph.annotations.RelatedSetValue; import org.simantics.objmap.graph.annotations.SetType; import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory; import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint; +import org.simantics.plant3d.scenegraph.controlpoint.PipingRules; @DynamicGraphType(Plant3D.URIs.InlineComponent) public class InlineComponent extends PipelineComponent { @@ -45,6 +51,37 @@ public class InlineComponent extends PipelineComponent { return !controlPoint.isFixed(); } + @RelatedGetValue(Plant3D.URIs.HasRotationAngle) + @GetPropertyValue(name="Rotation Angle", value=Plant3D.URIs.HasRotationAngle, tabId = "Default") + public Double getRotationAngle() { + if (!controlPoint.isRotate()) + return null; + Double d = controlPoint.getRotationAngle(); + if (d == null) + return 0.0; + return MathTools.radToDeg(d); + } + @RelatedSetValue(Plant3D.URIs.HasRotationAngle) + @SetPropertyValue(value=Plant3D.URIs.HasRotationAngle) + public void setRotationAngle(Double angle) { + if (!controlPoint.isRotate()) + return; + + if (angle == null || Double.isInfinite(angle) || Double.isNaN(angle)) { + return; + } + angle = MathTools.degToRad(angle); + if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO) + return; + controlPoint.setRotationAngle(angle); + try { + PipingRules.requestUpdate(getControlPoint()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Override public void updateParameters() { super.updateParameters(); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java index a6d1eb26..824f74d6 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java @@ -45,6 +45,7 @@ public class ControlPointFactory { PipeControlPoint pcp = new PipeControlPoint(component); pcp.setType(inst.type); pcp.setFixed(inst.fixed); + pcp.setRotate(inst.isRotate); switch(inst.type) { case END: @@ -77,7 +78,7 @@ public class ControlPointFactory { boolean fixed; boolean isOffset; boolean isSizeChange; - + boolean isRotate; } @@ -91,6 +92,7 @@ public class ControlPointFactory { i.fixed = false; i.isOffset = false; i.isSizeChange = false; + i.isRotate = false; i.type = Type.INLINE; if (graph.isInheritedFrom(res, p3d.Nozzle)) { i.fixed = true; @@ -113,6 +115,9 @@ public class ControlPointFactory { if (graph.hasStatement(res,p3d.OffsetComponent)) { i.isOffset = true; } + if (graph.hasStatement(res,p3d.RotateComponent)) { + i.isRotate = true; + } } else if (graph.isInheritedFrom(res, p3d.TurnComponent)) { i.type = Type.TURN; 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 21f2564d..b822b2f3 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 @@ -30,6 +30,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { private Type type; private boolean fixed = true; + private boolean rotate = false; private boolean deletable = true; private boolean sub = false; @@ -81,6 +82,16 @@ public class PipeControlPoint extends G3DNode implements IP3DNode { this.fixed = fixed; } + @GetPropertyValue(name="Rotate",tabId="Debug",value="rotate") + public boolean isRotate() { + return rotate; + } + + + public void setRotate(boolean rotate) { + this.rotate = rotate; + } + public void setSub(boolean sub) { this.sub = sub; } 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 b08c04cb..2644ab0f 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java @@ -36,7 +36,7 @@ public class ComponentUtils { types.add(Plant3D.URIs.Builtin_Elbow); types.add(Plant3D.URIs.Builtin_ConcentricReducer); types.add(Plant3D.URIs.Builtin_BranchSplitComponent); -// types.add(Plant3D.URIs.Builtin_EccentricReducer); + types.add(Plant3D.URIs.Builtin_EccentricReducer); for (String typeURI : types) { load(graph, typeURI);