X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Futils%2FP3DUtil.java;h=c125f105c84d0dfa5eb3686303609456bf283ab5;hb=6893513f254ffe9e35c2fda3371bd296cc22905c;hp=e5d1768a2c85da2cf2cdcb9bdcfbea36e6216c1e;hpb=53d55c24c779745f188bdb18d32f71d20acb61b2;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java index e5d1768a..c125f105 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java @@ -1,9 +1,13 @@ 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; @@ -44,12 +48,12 @@ public class P3DUtil { }); } - public static List getNozzles() throws DatabaseException { + public static List getNozzles(String libUri) throws DatabaseException { return Simantics.getSession().syncRequest(new Read>() { @Override public List 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); } }); @@ -65,9 +69,10 @@ public class P3DUtil { @Override public List perform(ReadGraph graph) throws DatabaseException { - Resource project = Simantics.getProject().get(); +// Resource project = Simantics.getProject().get(); Resource builtins = graph.getResource(libUri); - List actions = getItems(graph, project,type); + List actions = new ArrayList<>(); +// actions.addAll(getItems(graph, project,type)); actions.addAll(getItems(graph, builtins,type)); return actions; } @@ -88,34 +93,34 @@ public class P3DUtil { } } - public static List getEnds() throws DatabaseException { + public static List getEnds(String libUri) throws DatabaseException { return Simantics.getSession().syncRequest(new Read>() { @Override public List 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 getTurns() throws DatabaseException { + public static List getTurns(String libUri) throws DatabaseException { return Simantics.getSession().syncRequest(new Read>() { @Override public List 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 getInlines() throws DatabaseException { + public static List getInlines(String libUri) throws DatabaseException { return Simantics.getSession().syncRequest(new Read>() { @Override public List 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); } }); @@ -134,12 +139,21 @@ public class P3DUtil { Plant3D p3d = Plant3D.getInstance(graph); Layer0 l0 = Layer0.getInstance(graph); List result = new ArrayList(); - for (Resource r : graph.getObjects(lib, l0.ConsistsOf)) { + Set processed = new HashSet<>(); + Deque stack = new ArrayDeque(); + 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)) { @@ -152,8 +166,13 @@ public class P3DUtil { } 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() { @Override @@ -169,7 +188,8 @@ public class P3DUtil { Plant3D p3d = Plant3D.getInstance(graph); String name = graph.getRelatedValue(r, l0.HasName); String uri = graph.getURI(r); - Item item = new Item(uri, name); + String label = graph.getPossibleRelatedValue(r, l0.HasLabel); + Item item = new Item(uri, name, label); if (graph.isInstanceOf(r, p3d.Equipment)) item.setType(Type.EQUIPMENT); else if (graph.isInstanceOf(r, p3d.InlineComponent)) @@ -188,8 +208,12 @@ public class P3DUtil { if (graph.hasStatement(r, p3d.VariableAngleTurnComponent) || graph.hasStatement(r, p3d.VariableLengthInlineComponent)) item.setVariable(true); + if (graph.hasStatement(r, p3d.AdjustableLengthInlineComponent)) + item.setModifiable(true); if (graph.hasStatement(r, p3d.SizeChangeComponent)) item.setSizeChange(true); + if (graph.hasStatement(r, p3d.RotateComponent)) + item.setRotated(true); return item; } @@ -206,11 +230,15 @@ public class P3DUtil { public static void finalizeDBLoad(P3DRootNode rootNode) throws Exception{ for (INode node : rootNode.getChild()) { if (node instanceof PipeRun) { - for (PipelineComponent pc : ((PipeRun) node).getChild()) + for (PipelineComponent pc : ((PipeRun) node).getChild()) { pc.sync(); + pc.updateParameters(); + } } else if (node instanceof Equipment) { - for (PipelineComponent pc : ((Equipment) node).getChild()) + for (PipelineComponent pc : ((Equipment) node).getChild()) { pc.sync(); + pc.updateParameters(); + } } } @@ -228,14 +256,19 @@ public class P3DUtil { PipingRules.validate((PipeRun)node); } } - PipingRules.setEnabled(true); - for (INode node : rootNode.getChild()) { - if (node instanceof PipeRun) { - PipeRun run = (PipeRun)node; - for (PipeControlPoint pcp : run.getControlPoints()) - PipingRules.positionUpdate(pcp); - } - } } + + 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()) + if (pcp.asPathLegEnd()) + PipingRules.requestUpdate(pcp); + } + } + PipingRules.update(); + } }