--- /dev/null
+package org.simantics.g3d.vtk.swt;
+
+import java.util.Collection;
+
+import org.eclipse.jface.action.Action;
+import org.simantics.g3d.vtk.Activator;
+import org.simantics.g3d.vtk.common.VtkView;
+import org.simantics.utils.threads.AWTThread;
+
+import vtk.vtkProp;
+import vtk.vtkProp3D;
+
+public class FocusAction extends Action {
+
+ VtkView view;
+ vtkCameraAndSelectorAction cameraAndSelectorAction;
+ Collection<vtkProp> props;
+
+ public FocusAction(VtkView view, vtkCameraAndSelectorAction cameraAndSelectorAction) {
+ super("Focus");
+ setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/eye.png"));
+ this.view = view;
+ this.cameraAndSelectorAction = cameraAndSelectorAction;
+ }
+
+ public void setProps(Collection<vtkProp> props) {
+ this.props = props;
+ }
+
+ @Override
+ public void run() {
+ view.getThreadQueue().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ int count = 0;
+ double loc[] = new double[] {0,0,0};
+ for (vtkProp prop : props) {
+ if (prop instanceof vtkProp3D) {
+ vtkProp3D prop3d = (vtkProp3D)prop;
+ double l[] = prop3d.GetCenter();
+ for (int i = 0; i < 3; i++)
+ loc[i] = loc[i] + l[i];
+ count++;
+ }
+ }
+ if (count > 0) {
+ for (int i = 0; i < 3; i++)
+ loc[i] = loc[i] / count;
+ cameraAndSelectorAction.focus(loc[0],loc[1],loc[2]);
+ view.refresh();
+ }
+
+ }
+ });
+ }
+}
\ No newline at end of file
package org.simantics.plant3d.editor;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
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;
import vtk.vtkCameraPass;
import vtk.vtkDefaultPass;
import vtk.vtkLightsPass;
+import vtk.vtkProp;
import vtk.vtkRenderPassCollection;
import vtk.vtkRenderer;
import vtk.vtkSequencePass;
protected NodeSelectionProvider2<Resource,Object> selectionProvider;
+
protected vtkCameraAndSelectorAction cameraAction;
+ protected FocusAction focusAction;
protected TranslateAction translateAction;
protected TranslateInlineAction translateInlineAction;
protected TranslateFreeVariableLengthAction translateFreeVariableLengthAction;
}
protected void createActions() {
+ focusAction = new FocusAction(panel, cameraAction);
translateAction = new TranslateAction(panel,nodeMap);
translateInlineAction = new TranslateInlineAction(panel, nodeMap);
translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode());
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())) {