]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
Merge changes Ic491c642,Ibd66115e
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / editor / Plant3DEditor.java
index 2c94b5daea3fa4d191f7dda53dbc7960f350063d..2dc90bdd57466abf8f3bd2c4f4bc8d9002799fe4 100644 (file)
@@ -45,7 +45,9 @@ import org.simantics.plant3d.actions.AddEquipmentAction;
 import org.simantics.plant3d.actions.AddNozzleAction;
 import org.simantics.plant3d.actions.RemoveAndSplitAction;
 import org.simantics.plant3d.actions.RoutePipeAction;
+import org.simantics.plant3d.actions.TranslateFreeVariableLengthAction;
 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;
@@ -89,14 +91,15 @@ public class Plant3DEditor extends ResourceEditorPart {
        
        private NodeSelectionProvider2<Resource,Object> selectionProvider;
        
-       private vtkCameraAndSelectorAction cameraAction;
-       private TranslateAction translateAction;
-       private TranslateInlineAction translateInlineAction;
-       private RotateAction rotateAction;
-       private RemoveAction removeAction;
-       private RemoveAndSplitAction removeSplitAction;
-       private RoutePipeAction routePipeAction;
-       private AddComponentAction addComponentAction;
+       protected vtkCameraAndSelectorAction cameraAction;
+       protected TranslateAction translateAction;
+       protected TranslateInlineAction translateInlineAction;
+       protected TranslateFreeVariableLengthAction translateFreeVariableLengthAction;
+       protected RotateAction rotateAction;
+       protected RemoveAction removeAction;
+       protected RemoveAndSplitAction removeSplitAction;
+       protected RoutePipeAction routePipeAction;
+       protected AddComponentAction addComponentAction;
        
        private P3DNodeMap nodeMap;
        
@@ -128,8 +131,6 @@ public class Plant3DEditor extends ResourceEditorPart {
                hookContextMenu();
                
                createScene();
-
-               //component.syncPopulate();
                
                new ContextMenuListener(panel, contextMenu);
                
@@ -139,7 +140,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                panel.setPickType(4);
                
                try {
-                       ControlPointFactory.preloadCache();
+                       ControlPointFactory.preloadCache(getLibraryUri());
                        ComponentUtils.preloadCache();
                } catch (Exception e) {
                        ExceptionUtils.logAndShowError("Cannot open Plant3D editor",e);
@@ -159,9 +160,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                                        rootNode = (P3DRootNode)mapping.map(graph, input);
                                        // update control points.
                                        // TODO : this should be optimized.
-                                       
-                                       
-                                       
+
                                        try {
                                            P3DUtil.finalizeDBLoad(rootNode);
                                            nodeMap = createNodeMap(getSession(), mapping, panel,rootNode);
@@ -227,13 +226,18 @@ public class Plant3DEditor extends ResourceEditorPart {
            return new HoverHighlighter(panel,nodeMap);
        }
        
-       protected SelectionHighlighter<INode> createSelectionHighlighter() {
-           return new SelectionHighlighter<INode>(panel,nodeMap);
+       protected SelectionHighlighter<Resource,INode> createSelectionHighlighter() {
+           return new SelectionHighlighter<Resource,INode>(panel,nodeMap);
+       }
+       
+       protected String getLibraryUri() {
+           return Plant3D.URIs.Builtin;
        }
        
        protected void createActions() {
                translateAction = new TranslateAction(panel,nodeMap);
                translateInlineAction = new TranslateInlineAction(panel, nodeMap);
+               translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode());
                rotateAction = new RotateAction(panel,nodeMap);
                removeAction = new RemoveAction(nodeMap) {
                        public void setNode(IG3DNode node) {
@@ -243,7 +247,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 +360,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 +368,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);
@@ -401,7 +405,10 @@ public class Plant3DEditor extends ResourceEditorPart {
                                } else if (node instanceof InlineComponent) {
                                        //m.add(translateInlineAction);
                                        InlineComponent component = (InlineComponent)node;
-                                       m.add(translateInlineAction);
+                                       if (component.isVariableLength())
+                                           m.add(translateFreeVariableLengthAction);
+                                       else
+                                           m.add(translateInlineAction);
                                        m.add(routePipeAction);
                                        routePipeAction.setComponent(component);
                                        m.add(addComponentAction);
@@ -416,6 +423,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                                
                                translateAction.setNode(node);
                                translateInlineAction.setNode(node);
+                               translateFreeVariableLengthAction.setNode(node);
                                rotateAction.setNode(node);
                                removeAction.setNode(node);