]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
First version of fixed nozzle positions 07/3107/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 15 Aug 2019 09:16:39 +0000 (12:16 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 15 Aug 2019 09:16:39 +0000 (12:16 +0300)
Fixed nozzles are not added to equipment automatically.

gitlab #27

Change-Id: I675bee1132131fd9033f9054ea654c33ab60ffc6

org.simantics.plant3d.ontology/graph/plant3d.pgraph
org.simantics.plant3d.ontology/graph/plant3d_builtins.pgraph
org.simantics.plant3d/src/org/simantics/plant3d/actions/AddEquipmentAction.java
org.simantics.plant3d/src/org/simantics/plant3d/actions/AddNozzleAction.java
org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
org.simantics.plant3d/src/org/simantics/plant3d/geometry/FixedNozzleProvider.java [new file with mode: 0644]
org.simantics.plant3d/src/org/simantics/plant3d/geometry/PumpGeometryProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Equipment.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/Nozzle.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java

index 040dd889321339f6d9134157546ca380224cd4ee..f589bf3728f427d9bd3558a69e0464bcda47a476 100644 (file)
@@ -127,21 +127,31 @@ P3D.IsReversed <R L0.HasProperty
 P3D.HasTurnAxis <R G3D.hasTransformation
     L0.HasRange G3D.Tuple3D
     
-P3D.HasNozzleDefinition <R L0.HasProperty
-    L0.HasDomain P3D.Equipment
-    L0.HasRange P3D.Nozzle
-    L0.HasDescription "This relation is used to connect nozzles to equipment in the template. For instantiated equipment nozzles must be connected with HasNozzle relation." : L0.String  
+//P3D.HasNozzleDefinition <R L0.HasProperty
+//    L0.HasDomain P3D.Equipment
+//    L0.HasRange P3D.Nozzle
+//    L0.HasDescription "This relation is used to connect nozzles to equipment in the template. For instantiated equipment nozzles must be connected with HasNozzle relation." : L0.String  
 P3D.HasNozzle <R G3D.children
     L0.InverseOf P3D.NozzleOf
     L0.HasDomain P3D.Equipment
     L0.HasRange P3D.Nozzle
     L0.HasDescription "Used to connect nozzles to equipment." : L0.String
-P3D.HasNozzleRestriction <R L0.HasProperty
-    L0.HasDescription "Used in template equipment to restrict amount of nozzles. If template has as many nozzleDefinitions that maximum count in this restriction, user cannot add new nozzles to the equipment instance." : L0.String
+//P3D.HasNozzleRestriction <R L0.HasProperty
+//    L0.HasDescription "Used in template equipment to restrict amount of nozzles. If template has as many nozzleDefinitions that maximum count in this restriction, user cannot add new nozzles to the equipment instance." : L0.String
+P3D.HasFixedNozzles <R L0.HasProperty
+    L0.HasDescription "Number of fixed nozzles" : L0.String
+    L0.HasDomain P3D.Equipment
+    L0.HasRange L0.Integer
+
 
 P3D.HasNozzleId <R L0.HasProperty
     L0.HasDomain P3D.Nozzle
     L0.HasRange L0.Integer
+    
+P3D.IsFixedNozzle <R L0.HasProperty
+    L0.HasDescription "Fixed nozzle" : L0.String
+    L0.HasDomain P3D.Nozzle
+    L0.HasRange L0.Boolean
 
 P3D.HasPipeRun <R L0.IsWeaklyRelatedTo
     L0.HasDomain P3D.Nozzle
index ed8cc0f16c4bc4bad81a6bdb3411a23f5c65d5ba..6eb90594ecda4a1d6c29f7932d4e824f0e650a5a 100644 (file)
@@ -99,7 +99,8 @@ P3D.Builtin.Pump <T P3D.Equipment : P3D.Equipment
          _ :P3D.Parameter
            L0.HasName "length" : L0.String
            P3D.hasParameterValue 0.5 : L0.Double
-           
+     @L0.assert P3D.HasFixedNozzles 2
+                
 P3D.Builtin.BallValve <T P3D.InlineComponent : P3D.InlineComponent
     @L0.tag P3D.DualConnectedComponent
     @L0.tag P3D.FixedLengthInlineComponent
index ae7603ca6ab3cda78c69d79384b56d4e22370fa3..ff87c4ea2da4acf894b118d85bb8225c5e7abf5f 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.plant3d.actions;
 import org.eclipse.jface.action.Action;
 import org.simantics.plant3d.scenegraph.Equipment;
 import org.simantics.plant3d.scenegraph.P3DRootNode;
+import org.simantics.plant3d.utils.ComponentUtils;
 import org.simantics.plant3d.utils.Item;
 import org.simantics.utils.ui.ExceptionUtils;
 
@@ -20,12 +21,8 @@ public class AddEquipmentAction extends Action {
        @Override
        public void run() {
                try {
-                       Equipment equipment = root.createEquipment();
-                       equipment.setType(item.getUri());
-                       String n = root.getUniqueName(item.getName());
-                       equipment.setName(n);
-                       root.addChild(equipment);
-                       root.getNodeMap().commit("Add equipment " + n);
+                       Equipment equipment = ComponentUtils.createEquipment(root, item);
+                       root.getNodeMap().commit("Add equipment " + equipment.getName());
                } catch (Exception e) {
                        ExceptionUtils.logAndShowError("Cannot create equipment",e);
                }
index 34069d95492c54f781ee3dfdd74bcfc27b89017a..e1def918b58a633525e84e8e179715a43fb1a60c 100644 (file)
@@ -5,7 +5,7 @@ import org.simantics.plant3d.Activator;
 import org.simantics.plant3d.scenegraph.Equipment;
 import org.simantics.plant3d.scenegraph.Nozzle;
 import org.simantics.plant3d.scenegraph.P3DRootNode;
-import org.simantics.plant3d.scenegraph.PipeRun;
+import org.simantics.plant3d.utils.ComponentUtils;
 import org.simantics.plant3d.utils.Item;
 import org.simantics.utils.ui.ExceptionUtils;
 
@@ -24,24 +24,20 @@ public class AddNozzleAction extends Action {
        
        public void setEquipment(Equipment equipment) {
                this.equipment = equipment;
+               int fixedNozzles = equipment.numberOfFixedNozzles();
+               if (fixedNozzles > 0) {
+                   int currentNozzles = equipment.getNodes().size();
+                   setEnabled(currentNozzles < fixedNozzles);
+               } else {
+                   setEnabled(true);
+               }
        }
        
        @Override
        public void run() {
                try {
-                       Nozzle nozzle = root.createNozzle();
-                       nozzle.setType(item.getUri());
-                       String n = root.getUniqueName(item.getName());
-                       nozzle.setName(n);
-                       PipeRun pipeRun = new PipeRun();
-                       n = root.getUniqueName("PipeRun");
-                       pipeRun.setName(n);
-                       nozzle.setPipeRun(pipeRun);
-                       
-                       equipment.addChild(nozzle);
-                       //root.addChild(nozzle);
-                       root.addChild(pipeRun);
-                       root.getNodeMap().commit("Add nozzle " + n);
+                       Nozzle nozzle = ComponentUtils.createNozzle(root, equipment, item);
+                       root.getNodeMap().commit("Add nozzle " + nozzle.getName());
                } catch (Exception e) {
                        ExceptionUtils.logAndShowError("Cannot create equipment",e);
                }
index b1bb5000995c394503504c3a3aa54a68bea3ab25..159a239d9ff649eb772517f2f2acaa220b16a23e 100644 (file)
@@ -353,9 +353,11 @@ public class Plant3DEditor extends ResourceEditorPart {
                                                m.add(add);
                                        }
                                } else if (node instanceof Nozzle) {
-                                       m.add(translateAction);
-                                       m.add(rotateAction);
-                                       Nozzle nozzle = (Nozzle)node;
+                                   Nozzle nozzle = (Nozzle)node;
+                                   if (!nozzle.isFixed()) {
+                                       m.add(translateAction);
+                           m.add(rotateAction);
+                                   }
                                        m.add(routePipeAction);
                                        routePipeAction.setComponent(nozzle);
                                        routePipeAction.setEnabled(nozzle.getNext() == null && nozzle.getPrevious() == null);
diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/FixedNozzleProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/FixedNozzleProvider.java
new file mode 100644 (file)
index 0000000..bf30437
--- /dev/null
@@ -0,0 +1,11 @@
+package org.simantics.plant3d.geometry;
+
+import org.simantics.plant3d.scenegraph.Nozzle;
+
+public interface FixedNozzleProvider {
+    
+    int numberOfNozzles();
+    void updateNozzlePosition(int index, Nozzle nozzle);
+    String getNozzleName(int index);
+
+}
index 451abe1e1da5251bb096caefca8a9efea5cc58c1..47b2d2d1b33620bd8fe60ef4867f114bb1db4724 100644 (file)
@@ -4,12 +4,16 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 
+import javax.vecmath.AxisAngle4d;
+import javax.vecmath.Vector3d;
+
 import org.jcae.opencascade.jni.TopoDS_Shape;
 import org.simantics.db.Resource;
 import org.simantics.g3d.math.MathTools;
 import org.simantics.opencascade.OccTriangulator;
+import org.simantics.plant3d.scenegraph.Nozzle;
 
-public class PumpGeometryProvider extends BuiltinGeometryProvider  {
+public class PumpGeometryProvider extends BuiltinGeometryProvider  implements FixedNozzleProvider{
        
        public PumpGeometryProvider(Resource resource) {
                super(resource);
@@ -62,5 +66,34 @@ public class PumpGeometryProvider extends BuiltinGeometryProvider  {
                }
                
        }
+       
+       @Override
+       public int numberOfNozzles() {
+           return 2;
+       }
+       
+       @Override
+       public void updateNozzlePosition(int index, Nozzle nozzle) {
+           Double fl = nozzle.getFlowLength();
+           if (fl == null)
+               fl = 0.1;
+           if (index == 0) {
+               nozzle.setPosition(new Vector3d(-length*0.5- fl,width*0.6,0.0));
+               nozzle.setOrientation(MathTools.getQuat(new AxisAngle4d(0,1,0,Math.PI)));
+           } else if (index == 1) {
+               nozzle.setPosition(new Vector3d(-length*0.4,width*1.1+ fl,0.0));
+            nozzle.setOrientation(MathTools.getQuat(new AxisAngle4d(0,0,1,Math.PI*0.5)));
+           }
+           
+       }
+       
+       @Override
+       public String getNozzleName(int index) {
+           switch (index) {
+           case 0 : return "Input";
+           case 1: return "Output";
+           default: return null;
+           }
+       }
 
 }
index 3bac765c4a88754a7add24df614db98d70965280..27a76067be46d08f8db412f5dc61f2ef2229f170 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.plant3d.scenegraph;
 
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -11,6 +12,7 @@ import javax.vecmath.Vector3d;
 import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.property.annotations.CompoundGetPropertyValue;
 import org.simantics.g3d.property.annotations.CompoundSetPropertyValue;
+import org.simantics.g3d.scenegraph.GeometryProvider;
 import org.simantics.objmap.graph.annotations.CompoundRelatedGetValue;
 import org.simantics.objmap.graph.annotations.CompoundRelatedSetValue;
 import org.simantics.objmap.graph.annotations.DynamicGraphType;
@@ -19,6 +21,7 @@ import org.simantics.objmap.graph.annotations.RelatedElementsAdd;
 import org.simantics.objmap.graph.annotations.RelatedElementsGet;
 import org.simantics.objmap.graph.annotations.RelatedElementsRem;
 import org.simantics.objmap.graph.annotations.SetType;
+import org.simantics.plant3d.geometry.FixedNozzleProvider;
 import org.simantics.plant3d.ontology.Plant3D;
 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 
@@ -27,6 +30,7 @@ import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 public class Equipment extends P3DParentGeometryNode<Nozzle> {
 
        private String type;
+       private FixedNozzleProvider fnp;
        
        @GetType(Plant3D.URIs.Equipment)
        public String getType() {
@@ -50,6 +54,8 @@ public class Equipment extends P3DParentGeometryNode<Nozzle> {
                        newId++;
                addNode(Plant3D.URIs.HasNozzle,node);
                node.setNozzleId(newId);
+               if (fnp != null)
+                   syncNozzles();
        }
        
        @RelatedElementsGet(Plant3D.URIs.HasNozzle)
@@ -76,6 +82,42 @@ public class Equipment extends P3DParentGeometryNode<Nozzle> {
                super.setParameterMap(parameters);
        }
        
+       @Override
+       public void setGeometry(GeometryProvider provider) {
+           super.setGeometry(provider);
+           if (provider instanceof FixedNozzleProvider) {
+               fnp = (FixedNozzleProvider)provider;
+               syncNozzles();
+           }
+       }
+       
+       public int numberOfFixedNozzles() {
+           if (fnp == null)
+               return 0;
+           return fnp.numberOfNozzles();
+       }
+       
+       /**
+        * Synchronizes fixed nozzles. 
+        * 
+        * Note: this method does not create nozzles, just sets their positions and names.
+        */
+       public void syncNozzles() {
+           if (fnp == null)
+               return;
+           
+        int count = fnp.numberOfNozzles();
+        List<Nozzle> currentNozzles = getNodes();
+        for (int i = 0; i < count; i++) {
+            if (i < currentNozzles.size()) {
+                Nozzle nozzle = currentNozzles.get(i);
+                nozzle.setName(fnp.getNozzleName(i));
+                fnp.updateNozzlePosition(i, nozzle);
+                nozzle.setFixed(true);
+            }
+        }
+       }
+       
        @Override
        protected double[] getColor() {
                return new double[]{1,0,0};
index 9c4ad6f6ce280d46df3ce31d0b1c383f31e39841..fec8c08447e539b5f9aa64449352508253aa2226 100644 (file)
@@ -53,6 +53,22 @@ public class Nozzle extends PipelineComponent {
                firePropertyChanged(Plant3D.URIs.HasNozzleId);
        }
        
+       private boolean fixed = false;
+    
+    @RelatedGetValue(Plant3D.URIs.IsFixedNozzle)
+    @GetPropertyValue(name="Fixed", value=Plant3D.URIs.IsFixedNozzle, tabId="Default")
+    public boolean isFixed() {
+        return fixed;
+    }
+    
+    @RelatedSetValue(Plant3D.URIs.IsFixedNozzle)
+    public void setFixed(boolean fixed) {
+        if (fixed == this.fixed)
+            return;
+        this.fixed = fixed;
+        firePropertyChanged(Plant3D.URIs.IsFixedNozzle);
+    }
+       
        private void _createCP() throws Exception{
                if (controlPoint != null)
                        return;
index 2644ab0f33003ba9580c6d1b26ad9b9cfb75734d..fdd5b5bbe8d89c3c4c8a3f4204ae6c618a36186d 100644 (file)
@@ -14,9 +14,11 @@ import org.simantics.g3d.scenegraph.GeometryProvider;
 import org.simantics.layer0.Layer0;
 import org.simantics.plant3d.ontology.Plant3D;
 import org.simantics.plant3d.scenegraph.EndComponent;
+import org.simantics.plant3d.scenegraph.Equipment;
 import org.simantics.plant3d.scenegraph.InlineComponent;
 import org.simantics.plant3d.scenegraph.Nozzle;
 import org.simantics.plant3d.scenegraph.P3DRootNode;
+import org.simantics.plant3d.scenegraph.PipeRun;
 import org.simantics.plant3d.scenegraph.PipelineComponent;
 import org.simantics.plant3d.scenegraph.TurnComponent;
 
@@ -85,7 +87,7 @@ public class ComponentUtils {
                GeometryProvider provider = getProvider(graph, type);
                if (provider != null || graph.hasStatement(type,p3d.NonVisibleComponent)) {
                        providers.put(typeURI, provider);
-                       ComponentUtils.clazzes.put(typeURI,getClazz(graph, type));
+                       clazzes.put(typeURI,getClazz(graph, type));
                        return;
                }
                throw new DatabaseException("Cannot find component for " + typeURI);
@@ -151,4 +153,33 @@ public class ComponentUtils {
                component.setType(Plant3D.URIs.Builtin_BranchSplitComponent);
                return component;
        }
+       
+       public static Equipment createEquipment(P3DRootNode root, Item equipmentType) throws Exception {
+           Equipment equipment = root.createEquipment();
+        equipment.setType(equipmentType.getUri());
+        String n = root.getUniqueName(equipmentType.getName());
+        equipment.setName(n);
+        root.addChild(equipment);
+        return equipment;
+       }
+       
+       public static Nozzle createDefaultNozzle(P3DRootNode root, Equipment equipment) throws Exception {
+           return createNozzle(root, equipment, new Item(Plant3D.URIs.Builtin_Nozzle, "Nozzle"));
+       }
+       
+       public static Nozzle createNozzle(P3DRootNode root, Equipment equipment, Item nozzleType) throws Exception {
+           Nozzle nozzle = root.createNozzle();
+        nozzle.setType(nozzleType.getUri());
+        String n = root.getUniqueName(nozzleType.getName());
+        nozzle.setName(n);
+        PipeRun pipeRun = new PipeRun();
+        n = root.getUniqueName("PipeRun");
+        pipeRun.setName(n);
+        nozzle.setPipeRun(pipeRun);
+        
+        equipment.addChild(nozzle);
+        root.addChild(pipeRun);
+        // root.getNodeMap().commit("Add nozzle " + n);
+        return nozzle;
+       }
 }