]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
Overriding selection and hover highlights
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / editor / Plant3DEditor.java
index 21b99bfb74f109b5b910e5d86c19bdf8deda9531..273e1062d15ae6e805fbf1507007000df30a6673 100644 (file)
@@ -42,6 +42,7 @@ import org.simantics.objmap.graph.schema.IMappingSchema;
 import org.simantics.plant3d.actions.AddComponentAction;
 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.TranslateInlineAction;
 import org.simantics.plant3d.scenegraph.EndComponent;
@@ -50,12 +51,10 @@ import org.simantics.plant3d.scenegraph.IP3DNode;
 import org.simantics.plant3d.scenegraph.InlineComponent;
 import org.simantics.plant3d.scenegraph.Nozzle;
 import org.simantics.plant3d.scenegraph.P3DRootNode;
-import org.simantics.plant3d.scenegraph.PipeRun;
 import org.simantics.plant3d.scenegraph.PipelineComponent;
 import org.simantics.plant3d.scenegraph.SchemaBuilder;
 import org.simantics.plant3d.scenegraph.TurnComponent;
 import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory;
-import org.simantics.plant3d.scenegraph.controlpoint.PipeControlPoint;
 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
 import org.simantics.plant3d.utils.ComponentUtils;
 import org.simantics.plant3d.utils.Item;
@@ -94,6 +93,7 @@ public class Plant3DEditor extends ResourceEditorPart {
        private TranslateInlineAction translateInlineAction;
        private RotateAction rotateAction;
        private RemoveAction removeAction;
+       private RemoveAndSplitAction removeSplitAction;
        private RoutePipeAction routePipeAction;
        private AddComponentAction addComponentAction;
        
@@ -132,7 +132,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                
                new ContextMenuListener(panel, contextMenu);
                
-               cameraAction = new vtkCameraAndSelectorAction(panel);   
+               cameraAction = createCameraAction();
                panel.setDefaultAction(cameraAction);
                panel.useDefaultAction();
                panel.setPickType(4);
@@ -158,8 +158,8 @@ public class Plant3DEditor extends ResourceEditorPart {
                                        // update control points.
                                        // TODO : this should be optimized.
                                        try {
-                                           P3DUtil.finalizeDBLoad(rootNode);
-                                           
+                                               P3DUtil.finalizeDBLoad(rootNode);
+                                               
                                        } catch (Exception e) {
                                                throw new DatabaseException(e);
                                        }
@@ -171,12 +171,12 @@ public class Plant3DEditor extends ResourceEditorPart {
                                throw new RuntimeException("Scenegraph loading failed.");
                        populate();
                        
-                       selectionProvider = new NodeSelectionProvider2<Resource,Object>(this,mapping,nodeMap);
+                       selectionProvider = createSelectionProvider();
 
                        cameraAction.addSelectionChangedListener(selectionProvider);
 
-                       cameraAction.addHoverChangedListener(new HoverHighlighter(panel,nodeMap));
-                       selectionProvider.addSelectionChangedListener(new SelectionHighlighter(panel,nodeMap));
+                       cameraAction.addHoverChangedListener(createHoverHighlhighter());
+                       selectionProvider.addSelectionChangedListener(createSelectionHighlighter());
                        
                        getSite().setSelectionProvider(selectionProvider);
                        getSite().getPage().addPostSelectionListener(selectionProvider);
@@ -204,19 +204,39 @@ public class Plant3DEditor extends ResourceEditorPart {
                        return;
                }
                
+               createActions();
+               
+       }
+       
+       protected vtkCameraAndSelectorAction createCameraAction() {
+           return new vtkCameraAndSelectorAction(panel); 
+       }
+       
+       protected NodeSelectionProvider2<Resource,Object> createSelectionProvider() {
+           return new NodeSelectionProvider2<Resource,Object>(this,mapping,nodeMap);
+       }
+       
+       protected HoverHighlighter createHoverHighlhighter() {
+           return new HoverHighlighter(panel,nodeMap);
+       }
+       
+       protected SelectionHighlighter<INode> createSelectionHighlighter() {
+           return new SelectionHighlighter<INode>(panel,nodeMap);
+       }
+       
+       protected void createActions() {
                translateAction = new TranslateAction(panel,nodeMap);
                translateInlineAction = new TranslateInlineAction(panel, nodeMap);
                rotateAction = new RotateAction(panel,nodeMap);
                removeAction = new RemoveAction(nodeMap) {
                        public void setNode(IG3DNode node) {
                                super.setNode(node);
-                               
-                               
                        }
                };
+               
+               removeSplitAction = new RemoveAndSplitAction(nodeMap);
                routePipeAction = new RoutePipeAction(panel,rootNode);
                addComponentAction = new AddComponentAction(panel, rootNode);
-               
        }
        
        public void populate() {
@@ -236,7 +256,7 @@ public class Plant3DEditor extends ResourceEditorPart {
        }
        
        protected P3DNodeMap createNodeMap(Session session, IMapping<Resource, Object> mapping, VtkView panel, P3DRootNode rootNode) {
-                return new P3DNodeMap(session, mapping, panel,rootNode);
+               return new P3DNodeMap(session, mapping, panel,rootNode);
        }
        
        @Override
@@ -279,30 +299,30 @@ public class Plant3DEditor extends ResourceEditorPart {
                ren1.SetBackground(0.9,0.9,0.9);
                ren1.SetGradientBackground(true);
 
-          // vtkActor grid = vtkShape.createGridActor(8,1.0,1|2|4);
-           vtkActor grid = vtkShape.createGridActor(8,1.0, 2 );
-           grid.SetPickable(0);
-           ren1.AddActor(grid);
-           panel.addDeletable(grid);
-           
-           AxesDisplay axesDisplay = new AxesDisplay(panel);
-           axesDisplay.show();
+               // vtkActor grid = vtkShape.createGridActor(8,1.0,1|2|4);
+               vtkActor grid = vtkShape.createGridActor(8,1.0, 2 );
+               grid.SetPickable(0);
+               ren1.AddActor(grid);
+               panel.addDeletable(grid);
+               
+               AxesDisplay axesDisplay = new AxesDisplay(panel);
+               axesDisplay.show();
                
        }
        
        protected Menu contextMenu;
        
        protected void hookContextMenu() {
-        MenuManager menuMgr = new MenuManager("#PopupMenu");
-        menuMgr.setRemoveAllWhenShown(true);
-        menuMgr.addMenuListener(new IMenuListener() {
-            public void menuAboutToShow(IMenuManager manager) {                
-               createContextMenu(manager);
-            }
-        });
+               MenuManager menuMgr = new MenuManager("#PopupMenu");
+               menuMgr.setRemoveAllWhenShown(true);
+               menuMgr.addMenuListener(new IMenuListener() {
+                       public void menuAboutToShow(IMenuManager manager) {             
+                               createContextMenu(manager);
+                       }
+               });
 
-        contextMenu = menuMgr.createContextMenu(parent);
-    }
+               contextMenu = menuMgr.createContextMenu(parent);
+       }
        
        protected void createContextMenu(IMenuManager m) {
                List<IG3DNode> selected = selectionProvider.getSelectedNodes();
@@ -321,17 +341,19 @@ public class Plant3DEditor extends ResourceEditorPart {
                                                add.setEquipment((Equipment)node);
                                                m.add(add);
                                        }
+                                       m.add(removeAction);
                                } else if (node instanceof Nozzle) {
-                                   Nozzle nozzle = (Nozzle)node;
-                                   if (!nozzle.isFixed()) {
-                                       m.add(translateAction);
-                           m.add(rotateAction);
-                                   }
+                                       Nozzle nozzle = (Nozzle)node;
+                                       if (!nozzle.isFixed()) {
+                                               m.add(translateAction);
+                                               m.add(rotateAction);
+                                       }
                                        m.add(routePipeAction);
                                        routePipeAction.setComponent(nozzle);
                                        routePipeAction.setEnabled(nozzle.getNext() == null && nozzle.getPrevious() == null);
                                        m.add(addComponentAction);
                                        addComponentAction.setComponent(nozzle);
+                                       m.add(removeAction);
                                } else if (node instanceof TurnComponent) {
                                        m.add(translateAction);
                                        TurnComponent component = (TurnComponent)node;
@@ -340,10 +362,14 @@ public class Plant3DEditor extends ResourceEditorPart {
                                        routePipeAction.setEnabled(component.getNext() == null || component.getPrevious() == null);
                                        m.add(addComponentAction);
                                        addComponentAction.setComponent(component);
+                                       m.add(removeAction);
+                                       m.add(removeSplitAction);
+                                       removeSplitAction.setNode(node);
                                } else if (node instanceof EndComponent) {
                                        m.add(translateAction);
                                        m.add(addComponentAction);
                                        addComponentAction.setComponent((PipelineComponent)node);
+                                       m.add(removeAction);
                                } else if (node instanceof InlineComponent) {
                                        //m.add(translateInlineAction);
                                        InlineComponent component = (InlineComponent)node;
@@ -352,9 +378,14 @@ public class Plant3DEditor extends ResourceEditorPart {
                                        routePipeAction.setComponent(component);
                                        m.add(addComponentAction);
                                        addComponentAction.setComponent(component);
+                                       m.add(removeAction);
+                                       m.add(removeSplitAction);
+                                       removeSplitAction.setNode(node);
+                               } else {
+                                   m.add(removeAction);
                                }
                                
-                               m.add(removeAction);
+                               
                                translateAction.setNode(node);
                                translateInlineAction.setNode(node);
                                rotateAction.setNode(node);
@@ -362,8 +393,8 @@ public class Plant3DEditor extends ResourceEditorPart {
                                
                        } 
                } catch (DatabaseException e) {
-               ExceptionUtils.logAndShowError(e);
-       }
+                       ExceptionUtils.logAndShowError(e);
+               }
        }
        
        private IContentOutlinePage createOutline() {
@@ -418,6 +449,10 @@ public class Plant3DEditor extends ResourceEditorPart {
                return result;
        }
        
+       public InteractiveVtkComposite getPanel() {
+        return panel;
+    }
+       
        public P3DRootNode getRootNode() {
                return rootNode;
        }
@@ -425,4 +460,8 @@ public class Plant3DEditor extends ResourceEditorPart {
        public IMapping<Resource, Object> getMapping() {
                return mapping;
        }
+       
+       public P3DNodeMap getNodeMap() {
+        return nodeMap;
+    }
 }