]> 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 5775035a1e48cb5cb6368d02ad20fdde686c1c4f..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;
@@ -73,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;
@@ -91,7 +95,9 @@ public class Plant3DEditor extends ResourceEditorPart {
        
        protected NodeSelectionProvider2<Resource,Object> selectionProvider;
        
+       
        protected vtkCameraAndSelectorAction cameraAction;
+       protected FocusAction focusAction;
        protected TranslateAction translateAction;
        protected TranslateInlineAction translateInlineAction;
        protected TranslateFreeVariableLengthAction translateFreeVariableLengthAction;
@@ -235,6 +241,7 @@ 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());
@@ -358,6 +365,19 @@ public class Plant3DEditor extends ResourceEditorPart {
        
        protected void createContextMenu(IMenuManager m) {
                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())) {