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 class P3DUtil {
public static List<Item> getEquipments() throws DatabaseException {
+ return getEquipments(Plant3D.URIs.Builtin);
+ }
+
+ public static List<Item> getEquipments(final 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);
Resource project = Simantics.getProject().get();
- Resource builtins = graph.getResource(Plant3D.URIs.Builtin);
+ Resource builtins = graph.getResource(libUri);
List<Item> actions = getItems(graph, project,p3d.Equipment);
actions.addAll(getItems(graph, builtins,p3d.Equipment));
return actions;
});
}
- 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);
+ ItemQuery query = new ItemQuery(p3d.Nozzle, libUri);
return graph.syncRequest(query);
}
});
}
- private static class ItemQuery implements Read<List<Item>> {
+ public static class ItemQuery implements Read<List<Item>> {
private Resource type;
- public ItemQuery(Resource type) {
+ private String libUri;
+ public ItemQuery(Resource type, String libUri) {
this.type = type;
+ this.libUri = libUri;
}
@Override
public List<Item> perform(ReadGraph graph) throws DatabaseException {
Resource project = Simantics.getProject().get();
- Resource builtins = graph.getResource(Plant3D.URIs.Builtin);
- List<Item> actions = getItems(graph, project,type);
+ Resource builtins = graph.getResource(libUri);
+ List<Item> actions = new ArrayList<>();
+// actions.addAll(getItems(graph, project,type));
actions.addAll(getItems(graph, builtins,type));
return actions;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj.getClass() != this.getClass())
+ return false;
+ ItemQuery other = (ItemQuery)obj;
+ if (!type.equals(other.type))
+ return false;
+ return libUri.equals(other.libUri);
+ }
+
+ @Override
+ public int hashCode() {
+ return type.hashCode() + libUri.hashCode();
+ }
}
- 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);
+ 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);
+ 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);
+ ItemQuery query = new ItemQuery(p3d.InlineComponent, libUri);
return graph.syncRequest(query);
}
});
}
public static List<Item> filterUserComponents(List<Item> items) {
- List<Item> result = new ArrayList<Item>(items.size());
- for (Item i : items) {
- if (!i.isCode())
- result.add(i);
- }
- return result;
+ List<Item> result = new ArrayList<Item>(items.size());
+ for (Item i : items) {
+ if (!i.isCode())
+ result.add(i);
+ }
+ return result;
}
private static List<Item> getItems(ReadGraph graph, Resource lib, Resource type) throws DatabaseException{
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
- public int compare(Item o1, Item o2) {
- return o1.getName().compareTo(o2.getName());
- }
- });
+ @Override
+ public int compare(Item o1, Item o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
return result;
}
if (graph.hasStatement(r, p3d.CodeComponent))
item.setCode(true);
if (graph.hasStatement(r, p3d.VariableAngleTurnComponent) ||
- graph.hasStatement(r, p3d.VariableLengthInlineComponent))
+ graph.hasStatement(r, p3d.VariableLengthInlineComponent))
item.setVariable(true);
if (graph.hasStatement(r, p3d.SizeChangeComponent))
item.setSizeChange(true);
}
public static void finalizeDBLoad(P3DRootNode rootNode) throws Exception{
- for (INode node : rootNode.getChild()) {
- if (node instanceof PipeRun) {
- for (PipelineComponent pc : ((PipeRun) node).getChild())
- pc.sync();
- } else if (node instanceof Equipment) {
- for (PipelineComponent pc : ((Equipment) node).getChild())
- pc.sync();
- }
- }
-
- for (INode node : rootNode.getChild()) {
- if (node instanceof PipeRun) {
- for (PipelineComponent pc : ((PipeRun) node).getChild())
- pc.sync2();
- } else if (node instanceof Equipment) {
- for (PipelineComponent pc : ((Equipment) node).getChild())
- pc.sync2();
- }
- }
- for (INode node : rootNode.getChild()) {
- if (node instanceof PipeRun) {
- PipingRules.validate((PipeRun)node);
- }
- }
- PipingRules.setEnabled(true);
+ for (INode node : rootNode.getChild()) {
+ if (node instanceof PipeRun) {
+ for (PipelineComponent pc : ((PipeRun) node).getChild())
+ pc.sync();
+ } else if (node instanceof Equipment) {
+ for (PipelineComponent pc : ((Equipment) node).getChild())
+ pc.sync();
+ }
+ }
+
+ for (INode node : rootNode.getChild()) {
+ if (node instanceof PipeRun) {
+ for (PipelineComponent pc : ((PipeRun) node).getChild())
+ pc.sync2();
+ } else if (node instanceof Equipment) {
+ for (PipelineComponent pc : ((Equipment) node).getChild())
+ pc.sync2();
+ }
+ }
+ for (INode node : rootNode.getChild()) {
+ if (node instanceof PipeRun) {
+ PipingRules.validate((PipeRun)node);
+ }
+ }
+ }
+
+ public static void finalizeDBLoad2(P3DRootNode rootNode) throws Exception{
+ PipingRules.setEnabled(true);
for (INode node : rootNode.getChild()) {
if (node instanceof PipeRun) {
PipeRun run = (PipeRun)node;
for (PipeControlPoint pcp : run.getControlPoints())
- PipingRules.positionUpdate(pcp);
+ PipingRules.positionUpdate(pcp);
+ //PipingRules.requestUpdate(pcp);
}
}
- }
+ }
}