]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
Focus action
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / editor / Plant3DEditor.java
index d3f3c5e47e11d199b838225ee16f7afa6a0fd4e0..44e6529287bfb3ba9fd875098b8af6a2ca121668 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.plant3d.editor;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -29,9 +30,11 @@ import org.simantics.g3d.vtk.action.RemoveAction;
 import org.simantics.g3d.vtk.common.HoverHighlighter;
 import org.simantics.g3d.vtk.common.NodeSelectionProvider2;
 import org.simantics.g3d.vtk.common.SelectionHighlighter;
+import org.simantics.g3d.vtk.common.VTKSelectionItem;
 import org.simantics.g3d.vtk.common.VtkView;
 import org.simantics.g3d.vtk.shape.vtkShape;
 import org.simantics.g3d.vtk.swt.ContextMenuListener;
+import org.simantics.g3d.vtk.swt.FocusAction;
 import org.simantics.g3d.vtk.swt.InteractiveVtkComposite;
 import org.simantics.g3d.vtk.swt.RotateAction;
 import org.simantics.g3d.vtk.swt.TranslateAction;
@@ -45,6 +48,7 @@ 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;
@@ -72,6 +76,7 @@ import vtk.vtkActor;
 import vtk.vtkCameraPass;
 import vtk.vtkDefaultPass;
 import vtk.vtkLightsPass;
+import vtk.vtkProp;
 import vtk.vtkRenderPassCollection;
 import vtk.vtkRenderer;
 import vtk.vtkSequencePass;
@@ -88,16 +93,19 @@ public class Plant3DEditor extends ResourceEditorPart {
        private P3DRootNode rootNode;
        private IMapping<Resource,Object> mapping;
        
-       private NodeSelectionProvider2<Resource,Object> selectionProvider;
+       protected 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 FocusAction focusAction;
+       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;
        
@@ -129,8 +137,6 @@ public class Plant3DEditor extends ResourceEditorPart {
                hookContextMenu();
                
                createScene();
-
-               //component.syncPopulate();
                
                new ContextMenuListener(panel, contextMenu);
                
@@ -160,9 +166,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);
@@ -237,8 +241,10 @@ public class Plant3DEditor extends ResourceEditorPart {
        }
        
        protected void createActions() {
+           focusAction = new FocusAction(panel, cameraAction);
                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) {
@@ -358,7 +364,20 @@ public class Plant3DEditor extends ResourceEditorPart {
        }
        
        protected void createContextMenu(IMenuManager m) {
-               List<IG3DNode> selected = selectionProvider.getSelectedNodes();
+               List<INode> selected = selectionProvider.getSelectedNodes();
+               List<VTKSelectionItem<Resource>> selectedItems = selectionProvider.getSelectedItems();
+               if (selectedItems.size() > 0) {
+                   List<vtkProp> props = new ArrayList<>();
+                   for (VTKSelectionItem<Resource> i : selectedItems) {
+                       vtkProp p = (vtkProp)i.getAdapter(vtkProp.class);
+                       if (p != null)
+                           props.add(p);
+                   }
+                   if (props.size() > 0) {
+                       focusAction.setProps(props);
+                       m.add(focusAction);
+                   }
+               }
                try {
                        if (selected.size() == 0) {
                                for (Item eq : P3DUtil.getEquipments(getLibraryUri())) {
@@ -406,7 +425,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);
@@ -421,6 +443,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                                
                                translateAction.setNode(node);
                                translateInlineAction.setNode(node);
+                               translateFreeVariableLengthAction.setNode(node);
                                rotateAction.setNode(node);
                                removeAction.setNode(node);