P3D.hasParameterValue <R L0.IsRelatedTo : L0.FunctionalRelation
L0.HasDomain P3D.Parameter
L0.HasRange L0.Literal
+
+P3D.ComponentLibrary <T L0.Library
+P3D.ComponentLibrary.contains <R L0.IsWeaklyRelatedTo
\ No newline at end of file
P3D = <http://www.simantics.org/Plant3D-0.1>
-P3D.Builtin : L0.Library
+P3D.Builtin : P3D.ComponentLibrary
P3D.Builtin.NozzleGeometryProvider : P3D.GeometryProvider
P3D.Builtin.FlatNozzleGeometryProvider : P3D.GeometryProvider
@L0.tag P3D.SizeChangeComponent
@L0.tag P3D.FixedLengthInlineComponent
@L0.tag P3D.DualConnectedComponent
-// HasRotationAngle "0.0" : Double
-// HasControlPoint
-// _ : SizeChangeControlPoint
+
P3D.Builtin.EccentricReducer <T P3D.InlineComponent : P3D.InlineComponent
@L0.assert P3D.hasGeometry P3D.Builtin.ReducerGeometryProvider
@L0.tag P3D.OffsetComponent
@L0.tag P3D.FixedLengthInlineComponent
@L0.tag P3D.DualConnectedComponent
@L0.tag P3D.RotateComponent
-// HasRotationAngle "0.0" : Double
-// HasControlPoint
-// _ : SizeChangeControlPoint : OffsettingPoint
+
P3D.Builtin.Elbow <T P3D.TurnComponent : P3D.TurnComponent
@L0.tag P3D.VariableAngleTurnComponent
@L0.tag P3D.DualConnectedComponent
@L0.assert P3D.hasGeometry P3D.Builtin.ElbowGeometryProvider
-// HasLength "0.0" : Double
-// HasTurnRadius "0.0" : Double
-// HasTurnAngle "0.0" : Double
-// HasControlPoint
-// _ : VariableAngleTurnControlPoint
+
P3D.Builtin.Straight <T P3D.InlineComponent : P3D.InlineComponent
@L0.tag P3D.DualConnectedComponent
@L0.tag P3D.VariableLengthInlineComponent
@L0.assert P3D.hasGeometry P3D.Builtin.StraightGeometryProvider
-// HasLength "0.0" : Double
-// HasControlPoint
-// _ : VariableLengthControlPoint
+
P3D.Builtin.BranchSplitComponent <T P3D.InlineComponent : P3D.InlineComponent
@L0.tag P3D.CodeComponent
@L0.tag P3D.FixedLengthInlineComponent
@L0.tag P3D.NonVisibleComponent
-// HasLength "0.0" : Double
-// HasControlPoint
-// _ : BranchControlPoint
-//P3D.Builtin.Vessel : P3D.Equipment
-// @L0.tag L0.Abstract
-//P3D.Builtin.VerticalVessel <T P3D.Builtin.Vessel
- //[HasHeight card "1"]
-//P3D.Builtin.HorizontalVessel <T P3D.Builtin.Vessel
- //[HasLength card "1"]
P3D.Builtin.Nozzle <T P3D.Nozzle : P3D.Nozzle
private boolean insertAdjustable;
private boolean lengthAdjustable;
- public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root) {
+ private String libUri;
+
+ public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root, String libUri) {
super(panel);
this.root = root;
setText("Add Component");
setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/Component.png"));
nodeMap = root.getNodeMap();
gizmo = new TerminalSelectionGizmo(panel);
+ this.libUri = libUri;
}
public void setComponent(PipelineComponent component) {
@Override
public void run() {
- ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed, component);
+ ComponentSelectionDialog dialog = new ComponentSelectionDialog(Display.getCurrent().getActiveShell(), allowed, component, libUri);
if (dialog.open() == ComponentSelectionDialog.CANCEL)
return;
toAdd = dialog.getSelected();
} catch (Exception e) {
ExceptionUtils.logAndShowError("Cannot add component", e);
}
-// try {
-// PipelineComponent newComponent = ComponentUtils.createComponent(root,toAdd.getUri());
-// PipeControlPoint newPcp = newComponent.getControlPoint();
-//
-// PipeControlPoint toPcp = component.getControlPoint();
-// PipeRun pipeRun = toPcp.getPipeRun();
-//
-// Vector3d dir = null;
-// Vector3d pos = null;
-//
-//
-// if (toPcp.isInline()) {
-// switch (position) {
-// case NEXT:
-// if (toPcp.isDualInline())
-// toPcp = toPcp.getSubPoint().get(0);
-//
-// break;
-// case PREVIOUS:
-// if (toPcp.isDualSub())
-// toPcp = toPcp.parent;
-// }
-// Vector3d start = new Vector3d();
-// Vector3d end = new Vector3d();
-// dir = new Vector3d();
-// toPcp.getInlineControlPointEnds(start, end, dir);
-// dir.normalize();
-// switch (position) {
-// case NEXT:
-// pos = new Vector3d(end);
-// break;
-// case PREVIOUS:
-// pos = new Vector3d(start);
-// break;
-// case SPLIT:
-// pos = new Vector3d(toPcp.getWorldPosition());
-// break;
-// }
-//
-// } else if (toPcp.isDirected()) {
-// dir = new Vector3d(toPcp.getDirection(Direction.NEXT));
-// pos = new Vector3d(toPcp.getWorldPosition());
-// } else if (toPcp.isTurn() && toPcp.isFixed()) {
-// dir = new Vector3d(toPcp.getDirection(position == PositionType.NEXT ? Direction.NEXT : Direction.PREVIOUS));
-// pos = new Vector3d(toPcp.getWorldPosition());
-// if (!lengthAdjustable) {
-// Vector3d v = new Vector3d(dir);
-// v.scale(toPcp.getInlineLength());
-// pos.add(v);
-// } else {
-// if (insertPosition == PositionType.NEXT) {
-// Vector3d v = new Vector3d(dir);
-// v.scale(toPcp.getInlineLength());
-// pos.add(v);
-// } else if (insertPosition == PositionType.SPLIT) {
-// // scale 0.5*length so that we don't remove the length twice from the new component
-// Vector3d v = new Vector3d(dir);
-// v.scale(toPcp.getInlineLength()*0.5);
-// pos.add(v);
-// }
-// }
-// }
-//
-//
-// if (!toAdd.isSizeChange()) {
-// String name = component.getPipeRun().getUniqueName(toAdd.getName());
-// newComponent.setName(name);
-//
-// pipeRun.addChild(newComponent);
-// if (toAdd.isVariable()) {
-// // TODO: these options are not stored into DB. Should they?!
-// if (toAdd.getType() == Type.INLINE) {
-// newPcp.setLength(length);
-//// newPcp.setFixed(true);
-// } else if (toAdd.getType() == Type.TURN) {
-// newPcp.setTurnAngle(angle);
-//// newPcp.setFixed(true);
-// }
-// }
-// newComponent.updateParameters();
-//
-// Vector3d v = new Vector3d(dir);
-// if (insertAdjustable) {
-// if (insertPosition == PositionType.NEXT)
-// v.scale(newComponent.getControlPoint().getInlineLength());
-// else if (insertPosition == PositionType.SPLIT)
-// v.set(0, 0, 0);
-// else if (insertPosition == PositionType.PREVIOUS)
-// v.scale(-newComponent.getControlPoint().getInlineLength());
-// } else {
-// v.scale(newComponent.getControlPoint().getInlineLength());
-// }
-// switch (position) {
-// case NEXT:
-// pos.add(v);
-// break;
-// case PREVIOUS:
-// pos.sub(v);
-// break;
-// case SPLIT:
-// break;
-// }
-//
-// switch (position) {
-// case NEXT:
-// if (toPcp.isDualInline())
-// toPcp = toPcp.getSubPoint().get(0);
-// newPcp.insert(toPcp, Direction.NEXT);
-// newPcp.setWorldPosition(pos);
-// break;
-// case PREVIOUS:
-// if (toPcp.isDualSub())
-// toPcp = toPcp.parent;
-// newPcp.insert(toPcp, Direction.PREVIOUS);
-// newPcp.setWorldPosition(pos);
-// break;
-// case SPLIT:
-// PipingRules.splitVariableLengthComponent(newComponent, (InlineComponent)component, true);
-// }
-// } else {
-// PipeRun other = new PipeRun();
-// String n = root.getUniqueName("PipeRun");
-// other.setName(n);
-// other.setPipeDiameter(diameter);
-// other.setTurnRadius(turnRadius);
-// root.addChild(other);
-//
-//
-// if (position == PositionType.NEXT) {
-// PipingRules.addSizeChange(false, pipeRun, other, (InlineComponent)newComponent, toPcp, null);
-// } else if (position == PositionType.PREVIOUS){
-// PipingRules.addSizeChange(true, pipeRun, other, (InlineComponent)newComponent, toPcp, null);
-// }
-// newPcp.setWorldPosition(pos);
-// // TODO : chicken-egg problem
-// newComponent.updateParameters();
-// Vector3d v = new Vector3d(dir);
-// v.scale(newComponent.getControlPoint().getLength()*0.5);
-// switch (position) {
-// case NEXT:
-// pos.add(v);
-// break;
-// case PREVIOUS:
-// pos.sub(v);
-// break;
-// case SPLIT:
-// break;
-// }
-// newPcp.setWorldPosition(pos);
-//
-// }
-//
-//
-// } catch (Exception e) {
-// ExceptionUtils.logAndShowError("Cannot add component", e);
-// }
}
public boolean mouseClicked(MouseEvent e) {
import org.eclipse.swt.widgets.Text;
import org.simantics.db.exception.DatabaseException;
import org.simantics.plant3d.Activator;
+import org.simantics.plant3d.ontology.Plant3D;
import org.simantics.plant3d.scenegraph.EndComponent;
import org.simantics.plant3d.scenegraph.InlineComponent;
import org.simantics.plant3d.scenegraph.Nozzle;
private ResourceManager resourceManager;
+ private String libUri;
+
private Item selected;
private Set<PositionType> allowed;
private Set<PositionType> filterAllowed;
public ComponentSelectionDialog(Shell parentShell, Set<PositionType> allowed, PipelineComponent component){
- super(parentShell);
- this.allowed = allowed;
- this.component = component;
- filterAllowed = new HashSet<PositionType>();
- insertAdjustable = component instanceof InlineComponent ? ((InlineComponent)component).isVariableLength() : false;
- lenghtAdjustable = false;
+ this(parentShell, allowed, component, Plant3D.URIs.Builtin);
}
+ public ComponentSelectionDialog(Shell parentShell, Set<PositionType> allowed, PipelineComponent component, String libUri){
+ super(parentShell);
+ this.allowed = allowed;
+ this.component = component;
+ filterAllowed = new HashSet<PositionType>();
+ insertAdjustable = component instanceof InlineComponent ? ((InlineComponent)component).isVariableLength() : false;
+ lenghtAdjustable = false;
+ this.libUri = libUri;
+ }
+
@Override
protected Control createDialogArea(Composite parent) {
resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);
List<Item> turns = null;
List<Item> inlines = null;
try {
- ends = P3DUtil.getEnds();
- turns= P3DUtil.getTurns();
- inlines = P3DUtil.getInlines();
+ ends = P3DUtil.getEnds(libUri);
+ turns= P3DUtil.getTurns(libUri);
+ inlines = P3DUtil.getInlines(libUri);
} catch (DatabaseException e) {
Label label = new Label(composite, SWT.NONE);
label.setText("Cannot load pipeline components: " + e.getMessage());
import org.simantics.plant3d.actions.RemoveAndSplitAction;
import org.simantics.plant3d.actions.RoutePipeAction;
import org.simantics.plant3d.actions.TranslateInlineAction;
+import org.simantics.plant3d.ontology.Plant3D;
import org.simantics.plant3d.scenegraph.EndComponent;
import org.simantics.plant3d.scenegraph.Equipment;
import org.simantics.plant3d.scenegraph.IP3DNode;
return new SelectionHighlighter<INode>(panel,nodeMap);
}
+ protected String getLibraryUri() {
+ return Plant3D.URIs.Builtin;
+ }
+
protected void createActions() {
translateAction = new TranslateAction(panel,nodeMap);
translateInlineAction = new TranslateInlineAction(panel, nodeMap);
removeSplitAction = new RemoveAndSplitAction(nodeMap);
routePipeAction = new RoutePipeAction(panel,rootNode);
- addComponentAction = new AddComponentAction(panel, rootNode);
+ addComponentAction = new AddComponentAction(panel, rootNode, getLibraryUri());
}
public void populate() {
List<IG3DNode> selected = selectionProvider.getSelectedNodes();
try {
if (selected.size() == 0) {
- for (Item eq : P3DUtil.getEquipments()) {
+ for (Item eq : P3DUtil.getEquipments(getLibraryUri())) {
m.add(new AddEquipmentAction(rootNode, eq));
}
} else if (selected.size() == 1) {
if (node instanceof Equipment) {
m.add(translateAction);
m.add(rotateAction);
- for (Item eq : P3DUtil.getNozzles()) {
+ for (Item eq : P3DUtil.getNozzles(getLibraryUri())) {
AddNozzleAction add = new AddNozzleAction(rootNode, eq);
add.setEquipment((Equipment)node);
m.add(add);
public static void preloadCache() throws Exception {
- List<Item> items = P3DUtil.getEnds();
- items.addAll(P3DUtil.getInlines());
- items.addAll(P3DUtil.getNozzles());
- items.addAll(P3DUtil.getTurns());
+ List<Item> items = P3DUtil.getEnds(Plant3D.URIs.Builtin);
+ items.addAll(P3DUtil.getInlines(Plant3D.URIs.Builtin));
+ items.addAll(P3DUtil.getNozzles(Plant3D.URIs.Builtin));
+ items.addAll(P3DUtil.getTurns(Plant3D.URIs.Builtin));
for (Item item : items) {
Instruction inst = createInstruction(item.getUri());
package org.simantics.plant3d.utils;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Deque;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
});
}
- public static List<Item> getNozzles() throws DatabaseException {
+ public static List<Item> getNozzles(String libUri) throws DatabaseException {
return Simantics.getSession().syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);
- ItemQuery query = new ItemQuery(p3d.Nozzle, Plant3D.URIs.Builtin);
+ ItemQuery query = new ItemQuery(p3d.Nozzle, libUri);
return graph.syncRequest(query);
}
});
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Resource project = Simantics.getProject().get();
Resource builtins = graph.getResource(libUri);
- List<Item> actions = getItems(graph, project,type);
+ List<Item> actions = new ArrayList<>();
+// actions.addAll(getItems(graph, project,type));
actions.addAll(getItems(graph, builtins,type));
return actions;
}
}
}
- public static List<Item> getEnds() throws DatabaseException {
+ public static List<Item> getEnds(String libUri) throws DatabaseException {
return Simantics.getSession().syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);
- ItemQuery query = new ItemQuery(p3d.EndComponent, Plant3D.URIs.Builtin);
+ ItemQuery query = new ItemQuery(p3d.EndComponent, libUri);
return graph.syncRequest(query);
}
});
}
- public static List<Item> getTurns() throws DatabaseException {
+ public static List<Item> getTurns(String libUri) throws DatabaseException {
return Simantics.getSession().syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);
- ItemQuery query = new ItemQuery(p3d.TurnComponent, Plant3D.URIs.Builtin);
+ ItemQuery query = new ItemQuery(p3d.TurnComponent, libUri);
return graph.syncRequest(query);
}
});
}
- public static List<Item> getInlines() throws DatabaseException {
+ public static List<Item> getInlines(String libUri) throws DatabaseException {
return Simantics.getSession().syncRequest(new Read<List<Item>>() {
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Plant3D p3d = Plant3D.getInstance(graph);
- ItemQuery query = new ItemQuery(p3d.InlineComponent, Plant3D.URIs.Builtin);
+ ItemQuery query = new ItemQuery(p3d.InlineComponent, libUri);
return graph.syncRequest(query);
}
});
Plant3D p3d = Plant3D.getInstance(graph);
Layer0 l0 = Layer0.getInstance(graph);
List<Item> result = new ArrayList<Item>();
- for (Resource r : graph.getObjects(lib, l0.ConsistsOf)) {
+ Set<Resource> processed = new HashSet<>();
+ Deque<Resource> stack = new ArrayDeque<Resource>();
+ stack.addAll(graph.getObjects(lib, l0.ConsistsOf));
+ stack.addAll(graph.getObjects(lib, p3d.ComponentLibrary_contains));
+ while (!stack.isEmpty()) {
+ Resource r = stack.pop();
+ if (processed.contains(r))
+ continue;
+ processed.add(r);
if (graph.isInstanceOf(r, type) ) {
Resource geom = graph.getPossibleObject(r,p3d.hasGeometry);
if (geom != null || graph.hasStatement(r,p3d.NonVisibleComponent)) {
result.add(createItem(graph, r));
+ continue;
}
}
if (graph.isInheritedFrom(r, type)) {
}
if (asserts) {
result.add(createItem(graph, r));
+ continue;
}
}
+ if (graph.isInstanceOf(r, p3d.ComponentLibrary)) {
+ stack.addAll(graph.getObjects(r, l0.ConsistsOf));
+ stack.addAll(graph.getObjects(r, p3d.ComponentLibrary_contains));
+ }
}
Collections.sort(result, new Comparator<Item>() {
@Override