X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Futils%2FP3DUtil.java;h=e5d1768a2c85da2cf2cdcb9bdcfbea36e6216c1e;hb=53d55c24c779745f188bdb18d32f71d20acb61b2;hp=7ba42b8f9d128d511973507595fee90d9a6d59fa;hpb=50d66f38dea493cbabe9ed6e04d37d6c408a1388;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 7ba42b8f..e5d1768a 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java @@ -25,12 +25,16 @@ import org.simantics.plant3d.utils.Item.Type; public class P3DUtil { public static List getEquipments() throws DatabaseException { + return getEquipments(Plant3D.URIs.Builtin); + } + + public static List getEquipments(final String libUri) throws DatabaseException { return Simantics.getSession().syncRequest(new Read>() { @Override public List 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 actions = getItems(graph, project,p3d.Equipment); actions.addAll(getItems(graph, builtins,p3d.Equipment)); return actions; @@ -45,26 +49,43 @@ public class P3DUtil { @Override public List perform(ReadGraph graph) throws DatabaseException { Plant3D p3d = Plant3D.getInstance(graph); - ItemQuery query = new ItemQuery(p3d.Nozzle); + ItemQuery query = new ItemQuery(p3d.Nozzle, Plant3D.URIs.Builtin); return graph.syncRequest(query); } }); } - private static class ItemQuery implements Read> { + public static class ItemQuery implements Read> { 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 perform(ReadGraph graph) throws DatabaseException { Resource project = Simantics.getProject().get(); - Resource builtins = graph.getResource(Plant3D.URIs.Builtin); + Resource builtins = graph.getResource(libUri); List actions = 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 getEnds() throws DatabaseException { @@ -72,7 +93,7 @@ public class P3DUtil { @Override public List perform(ReadGraph graph) throws DatabaseException { Plant3D p3d = Plant3D.getInstance(graph); - ItemQuery query = new ItemQuery(p3d.EndComponent); + ItemQuery query = new ItemQuery(p3d.EndComponent, Plant3D.URIs.Builtin); return graph.syncRequest(query); } }); @@ -83,7 +104,7 @@ public class P3DUtil { @Override public List perform(ReadGraph graph) throws DatabaseException { Plant3D p3d = Plant3D.getInstance(graph); - ItemQuery query = new ItemQuery(p3d.TurnComponent); + ItemQuery query = new ItemQuery(p3d.TurnComponent, Plant3D.URIs.Builtin); return graph.syncRequest(query); } }); @@ -94,19 +115,19 @@ public class P3DUtil { @Override public List perform(ReadGraph graph) throws DatabaseException { Plant3D p3d = Plant3D.getInstance(graph); - ItemQuery query = new ItemQuery(p3d.InlineComponent); + ItemQuery query = new ItemQuery(p3d.InlineComponent, Plant3D.URIs.Builtin); return graph.syncRequest(query); } }); } public static List filterUserComponents(List items) { - List result = new ArrayList(items.size()); - for (Item i : items) { - if (!i.isCode()) - result.add(i); - } - return result; + List result = new ArrayList(items.size()); + for (Item i : items) { + if (!i.isCode()) + result.add(i); + } + return result; } private static List getItems(ReadGraph graph, Resource lib, Resource type) throws DatabaseException{ @@ -135,11 +156,11 @@ public class P3DUtil { } } Collections.sort(result, new Comparator() { - @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; } @@ -165,7 +186,7 @@ public class P3DUtil { 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); @@ -183,38 +204,38 @@ 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()) - 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) { - PipeRun run = (PipeRun)node; - for (PipeControlPoint pcp : run.getControlPoints()) - PipingRules.positionUpdate(pcp); - } - } + 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) { + PipeRun run = (PipeRun)node; + for (PipeControlPoint pcp : run.getControlPoints()) + PipingRules.positionUpdate(pcp); + } + } } }