From: Marko Luukkainen Date: Fri, 25 Oct 2019 12:49:06 +0000 (+0300) Subject: Equipment/Component library customization X-Git-Tag: v1.43.0~167^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=dad2672f12421f28805df9d97acf20d0a8efe71f;p=simantics%2F3d.git Equipment/Component library customization gitlab #29 Change-Id: If023250f7762fcd7bc113fec462f285184bf9608 --- diff --git a/org.simantics.plant3d.ontology/graph/plant3d.pgraph b/org.simantics.plant3d.ontology/graph/plant3d.pgraph index 591a34ca..7d0e4976 100644 --- a/org.simantics.plant3d.ontology/graph/plant3d.pgraph +++ b/org.simantics.plant3d.ontology/graph/plant3d.pgraph @@ -171,4 +171,7 @@ P3D.hasParameter P3D = -P3D.Builtin : L0.Library +P3D.Builtin : P3D.ComponentLibrary P3D.Builtin.NozzleGeometryProvider : P3D.GeometryProvider P3D.Builtin.FlatNozzleGeometryProvider : P3D.GeometryProvider @@ -23,9 +23,7 @@ P3D.Builtin.ConcentricReducer allowed; private Set filterAllowed; @@ -81,14 +84,19 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange public ComponentSelectionDialog(Shell parentShell, Set allowed, PipelineComponent component){ - super(parentShell); - this.allowed = allowed; - this.component = component; - filterAllowed = new HashSet(); - insertAdjustable = component instanceof InlineComponent ? ((InlineComponent)component).isVariableLength() : false; - lenghtAdjustable = false; + this(parentShell, allowed, component, Plant3D.URIs.Builtin); } + public ComponentSelectionDialog(Shell parentShell, Set allowed, PipelineComponent component, String libUri){ + super(parentShell); + this.allowed = allowed; + this.component = component; + filterAllowed = new HashSet(); + 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); @@ -115,9 +123,9 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange List turns = null; List 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()); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index 2c94b5da..51e03ad3 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -46,6 +46,7 @@ import org.simantics.plant3d.actions.AddNozzleAction; 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; @@ -231,6 +232,10 @@ public class Plant3DEditor extends ResourceEditorPart { return new SelectionHighlighter(panel,nodeMap); } + protected String getLibraryUri() { + return Plant3D.URIs.Builtin; + } + protected void createActions() { translateAction = new TranslateAction(panel,nodeMap); translateInlineAction = new TranslateInlineAction(panel, nodeMap); @@ -243,7 +248,7 @@ public class Plant3DEditor extends ResourceEditorPart { removeSplitAction = new RemoveAndSplitAction(nodeMap); routePipeAction = new RoutePipeAction(panel,rootNode); - addComponentAction = new AddComponentAction(panel, rootNode); + addComponentAction = new AddComponentAction(panel, rootNode, getLibraryUri()); } public void populate() { @@ -356,7 +361,7 @@ public class Plant3DEditor extends ResourceEditorPart { List 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) { @@ -364,7 +369,7 @@ public class Plant3DEditor extends ResourceEditorPart { 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); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java index 1b982f07..ae71b7af 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java @@ -21,10 +21,10 @@ public class ControlPointFactory { public static void preloadCache() throws Exception { - List items = P3DUtil.getEnds(); - items.addAll(P3DUtil.getInlines()); - items.addAll(P3DUtil.getNozzles()); - items.addAll(P3DUtil.getTurns()); + List 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()); 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 71f844d8..65b93cff 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); } }); @@ -67,7 +71,8 @@ public class P3DUtil { public List perform(ReadGraph graph) throws DatabaseException { 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