1 package org.simantics.g3d.vtk.swt;
3 import java.util.Collection;
5 import org.eclipse.jface.action.Action;
6 import org.simantics.g3d.vtk.Activator;
7 import org.simantics.g3d.vtk.common.VtkView;
12 public class FocusAction extends Action {
15 vtkCameraAndSelectorAction cameraAndSelectorAction;
16 Collection<vtkProp> props;
18 public FocusAction(VtkView view, vtkCameraAndSelectorAction cameraAndSelectorAction) {
20 setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/eye.png"));
22 this.cameraAndSelectorAction = cameraAndSelectorAction;
25 public void setProps(Collection<vtkProp> props) {
31 view.getThreadQueue().asyncExec(new Runnable() {
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];
47 for (int i = 0; i < 3; i++)
48 loc[i] = loc[i] / count;
49 cameraAndSelectorAction.focus(loc[0],loc[1],loc[2]);