]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Equipment/Component library customization 10/3410/2
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 25 Oct 2019 12:49:06 +0000 (15:49 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 25 Oct 2019 12:50:04 +0000 (15:50 +0300)
gitlab #29

Change-Id: If023250f7762fcd7bc113fec462f285184bf9608

org.simantics.plant3d.ontology/graph/plant3d.pgraph
org.simantics.plant3d.ontology/graph/plant3d_builtins.pgraph
org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java
org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java
org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/ControlPointFactory.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java

index 591a34cabb401fa9ea5a2900860cb991cab47275..7d0e4976891f8d807d24af669a6e56e704494ea8 100644 (file)
@@ -171,4 +171,7 @@ P3D.hasParameter <R L0.IsRelatedTo
 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
index 84e0b67414dd39f54c1dc1cd773d84054fc82558..fc3c0083423ace76db3bddd2dd12c42c4d50fcee 100644 (file)
@@ -2,7 +2,7 @@ L0 = <http://www.simantics.org/Layer0-1.1>
 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
@@ -23,9 +23,7 @@ P3D.Builtin.ConcentricReducer <T P3D.InlineComponent : P3D.InlineComponent
     @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
@@ -33,38 +31,21 @@ P3D.Builtin.EccentricReducer <T P3D.InlineComponent : P3D.InlineComponent
     @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
index a39d84c8ebd31d7706d2848472c38464ce3293a6..ba6721043d20f7e38c8f63d227e310ddc7591621 100644 (file)
@@ -50,13 +50,16 @@ public class AddComponentAction extends vtkSwtAction {
        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) {
@@ -89,7 +92,7 @@ public class AddComponentAction extends vtkSwtAction {
        @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();
@@ -182,162 +185,6 @@ public class AddComponentAction extends vtkSwtAction {
                } 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) {
index 30f2540d5ccee1be1953ff0db181d2247c24a2ae..93a305bb9d74ea67fddb1ed35c088c09044d12e4 100644 (file)
@@ -33,6 +33,7 @@ import org.eclipse.swt.widgets.Shell;
 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;
@@ -48,6 +49,8 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
 
        private ResourceManager resourceManager;
        
+       private String libUri;
+       
        private Item selected;
        private Set<PositionType> allowed;
        private Set<PositionType> filterAllowed;
@@ -81,14 +84,19 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
        
        
        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);
@@ -115,9 +123,9 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                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());
index 2c94b5daea3fa4d191f7dda53dbc7960f350063d..51e03ad36530828b74ebad223bd29af5e1f41e94 100644 (file)
@@ -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<INode>(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<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) {
@@ -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);
index 1b982f07ce6ac3cd84ca14fac483fe89e98a8ef5..ae71b7afa9e5da1734a382e93903e40a8fc31938 100644 (file)
@@ -21,10 +21,10 @@ public class ControlPointFactory {
        
        
        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());
index 71f844d866329fe2dac458d7e9c468c6eb28ce33..65b93cffd2688102500fb30a0b67dce44949c87f 100644 (file)
@@ -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<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);
                        }
                });
@@ -67,7 +71,8 @@ public class P3DUtil {
                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;
                }
@@ -88,34 +93,34 @@ public class P3DUtil {
                }
        }
        
-       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);
                        }
                });
@@ -134,12 +139,21 @@ public class P3DUtil {
                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)) {
@@ -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<Item>() {
                        @Override