]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/FocusAction.java
Only disable warning display when not in development mode
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / swt / FocusAction.java
1 package org.simantics.g3d.vtk.swt;
2
3 import java.util.Collection;
4
5 import org.eclipse.jface.action.Action;
6 import org.simantics.g3d.vtk.Activator;
7 import org.simantics.g3d.vtk.common.VtkView;
8
9 import vtk.vtkProp;
10 import vtk.vtkProp3D;
11
12 public class FocusAction extends Action {
13         
14     VtkView view;
15     vtkCameraAndSelectorAction cameraAndSelectorAction;
16         Collection<vtkProp> props;
17         
18         public FocusAction(VtkView view, vtkCameraAndSelectorAction cameraAndSelectorAction) {
19                 super("Focus");
20                 setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/eye.png"));
21                 this.view = view;
22                 this.cameraAndSelectorAction = cameraAndSelectorAction;
23         }
24         
25         public void setProps(Collection<vtkProp> props) {
26                 this.props = props;
27         }
28         
29         @Override
30         public void run() {
31                 view.getThreadQueue().asyncExec(new Runnable() {
32                         
33                         @Override
34                         public void run() {
35                                 int count = 0;
36                                 double loc[] = new double[] {0,0,0};
37                                 for (vtkProp prop : props) {
38                                         if (prop instanceof vtkProp3D) {
39                                                 vtkProp3D prop3d = (vtkProp3D)prop;
40                                                 double l[] = prop3d.GetCenter();
41                                                 for (int i = 0; i < 3; i++)
42                                                         loc[i] = loc[i] + l[i]; 
43                                                 count++;
44                                         }
45                                 }
46                                 if (count > 0) {
47                                         for (int i = 0; i < 3; i++)
48                                                 loc[i] = loc[i] / count;
49                                         cameraAndSelectorAction.focus(loc[0],loc[1],loc[2]);
50                                         view.refresh();
51                                 }
52                                 
53                         }
54                 });
55         }
56 }