Fixed nozzles are not added to equipment automatically.
gitlab #27
Change-Id: I675bee1132131fd9033f9054ea654c33ab60ffc6
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
_ :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
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;
@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);
}
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;
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);
}
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);
--- /dev/null
+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);
+
+}
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);
}
}
+
+ @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;
+ }
+ }
}
import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
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;
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;
public class Equipment extends P3DParentGeometryNode<Nozzle> {
private String type;
+ private FixedNozzleProvider fnp;
@GetType(Plant3D.URIs.Equipment)
public String getType() {
newId++;
addNode(Plant3D.URIs.HasNozzle,node);
node.setNozzleId(newId);
+ if (fnp != null)
+ syncNozzles();
}
@RelatedElementsGet(Plant3D.URIs.HasNozzle)
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};
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;
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;
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);
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;
+ }
}