X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Feditor%2FPlant3DEditor.java;h=b4448e670749caef8e30b8685d33422eb922cb55;hb=refs%2Fchanges%2F76%2F4176%2F1;hp=a7559f8009b35a599469a6d7d45cc7845b698a43;hpb=d207cfa3235339e7d7b894494be400160b121bd5;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index a7559f80..b4448e67 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -1,13 +1,17 @@ package org.simantics.plant3d.editor; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -23,17 +27,19 @@ import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; +import org.simantics.db.common.request.ParametrizedRead; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.combinations.Combinators; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.RenderListener; import org.simantics.g3d.scenegraph.base.INode; +import org.simantics.g3d.scenegraph.base.ParentNode; import org.simantics.g3d.toolbar.ToolComposite; 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; @@ -58,6 +64,7 @@ import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.EndComponent; import org.simantics.plant3d.scenegraph.Equipment; import org.simantics.plant3d.scenegraph.IP3DNode; +import org.simantics.plant3d.scenegraph.IP3DVisualNode; import org.simantics.plant3d.scenegraph.InlineComponent; import org.simantics.plant3d.scenegraph.Nozzle; import org.simantics.plant3d.scenegraph.P3DRootNode; @@ -74,6 +81,7 @@ import org.simantics.selectionview.StandardPropertyPage; import org.simantics.ui.workbench.IPropertyPage; import org.simantics.ui.workbench.IResourceEditorInput; import org.simantics.ui.workbench.ResourceEditorPart; +import org.simantics.ui.workbench.editor.input.InputValidationCombinators; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.ExceptionUtils; @@ -82,7 +90,7 @@ import vtk.vtkCameraPass; import vtk.vtkDefaultPass; import vtk.vtkGaussianBlurPass; import vtk.vtkLightsPass; -import vtk.vtkProp; +import vtk.vtkProp3D; import vtk.vtkRenderPassCollection; import vtk.vtkRenderer; import vtk.vtkSSAAPass; @@ -124,25 +132,23 @@ public class Plant3DEditor extends ResourceEditorPart { public static final int X = 0, Y = 1, Z = 2; protected int upDirection = 1; - + + ParametrizedRead INPUT_VALIDATOR = + Combinators.compose( + InputValidationCombinators.hasURI(), + InputValidationCombinators.extractInputResource() + ); + + @Override + protected ParametrizedRead getInputValidator() { + return INPUT_VALIDATOR; + } + @Override public void createPartControl(Composite parent) { this.parent = parent; - //parent.setLayout (new FillLayout ()); - - -// component = new SWTAWTComponent(parent,SWT.NONE) { -// -// @Override -// protected Component createSwingComponent() { -// if (panel == null) { -// panel = new InteractiveVtkPanel(); -// vtkPanelUtil.registerPanel(panel); -// createScene(); -// } -// return panel; -// } -// }; + + activateValidation(); IResourceEditorInput rei = (IResourceEditorInput)getEditorInput(); input = rei.getResource(); @@ -254,7 +260,6 @@ public class Plant3DEditor extends ResourceEditorPart { } createActions(); - } public void setUpDirection(int upDirection) { @@ -299,32 +304,44 @@ public class Plant3DEditor extends ResourceEditorPart { @Override public void run() { + nodeMap.setChangeTracking(false); nodeMap.populate(); + nodeMap.setChangeTracking(true); panel.addListener(new RenderListener() { - - @Override - public void preRender() { - - } - - @Override - public void postRender() { - try { - P3DUtil.finalizeDBLoad2(rootNode); - if (nodeMap.isRangeModified()); - nodeMap.commit("Load sync"); - } catch (Exception e) { - ExceptionUtils.logAndShowError("Failed to load model correctly", e); - //throw new DatabaseException(e); - } - panel.removeListener(this); - - } - }); - + + @Override + public void preRender() { + + } + + @Override + public void postRender() { + panel.removeListener(this); + + try { + P3DUtil.finalizeDBLoad2(rootNode); + if (nodeMap.getMapping().isRangeModified()) + nodeMap.commit("Load sync"); + } catch (Exception e) { + ExceptionUtils.logAndShowError("Failed to load model correctly", e); + } + + onEditorInitializationComplete(); + + List props = new ArrayList<>(); + collectProps(rootNode, props); + fitToWindow(props); + } + }); } }); - + + } + + /** + * This can be overridden by clients to perform extra initialization tasks + */ + protected void onEditorInitializationComplete() { } protected IMappingSchema getSchema(ReadGraph graph) throws DatabaseException { @@ -342,7 +359,7 @@ public class Plant3DEditor extends ResourceEditorPart { panel.getComponent().setFocus(); } - private void createScene() { + protected void createScene() { vtkRenderer ren1 = panel.getRenderer(); boolean multiPass = false; @@ -407,7 +424,6 @@ public class Plant3DEditor extends ResourceEditorPart { AxesDisplay axesDisplay = new AxesDisplay(panel); axesDisplay.show(); - } protected Menu contextMenu; @@ -426,19 +442,11 @@ public class Plant3DEditor extends ResourceEditorPart { protected void createContextMenu(IMenuManager m) { List selected = selectionProvider.getSelectedNodes(); - List> selectedItems = selectionProvider.getSelectedItems(); - if (selectedItems.size() > 0) { - List props = new ArrayList<>(); - for (VTKSelectionItem 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); - } - } + + createFocusMenu(m, selected); + + m.add(new Separator()); + try { if (selected.size() == 0) { m.add(new AddEquipmentAction(rootNode, getLibraryUri())); @@ -518,7 +526,44 @@ public class Plant3DEditor extends ResourceEditorPart { ExceptionUtils.logAndShowError(e); } } - + + protected class FitToWindow extends Action { + private List selected; + public FitToWindow(List selected) { + super("Fit to Window"); + this.selected = selected; + //setAccelerator('1'); + } + @Override + public void run() { + List props = new ArrayList<>(); + final Collection collection = !selected.isEmpty() ? selected : getRootNode().getChild(); + for (INode n : collection) + collectProps(n, props); + + fitToWindow(props); + getPanel().refresh(); + } + } + + protected void createFocusMenu(IMenuManager m, List selected) { + m.add(createFitToWindowAction(selected)); + + if (!selected.isEmpty()) { + List actors = new ArrayList<>(); + for (INode n : selected) + collectProps(n, actors); + if (actors.size() > 0) { + focusAction.setProps(new ArrayList<>(actors)); + m.add(focusAction); + } + } + } + + protected IAction createFitToWindowAction(List selected) { + return new FitToWindow(selected); + } + private IContentOutlinePage createOutline() { if (rootNode == null || selectionProvider == null) return null; @@ -585,4 +630,18 @@ public class Plant3DEditor extends ResourceEditorPart { public P3DNodeMap getNodeMap() { return nodeMap; } + + public void fitToWindow(Collection props) { + cameraAction.fitToView(props); + } + + protected static void collectProps(INode node, List props) { + if (node instanceof IP3DVisualNode) + props.addAll(((IP3DVisualNode) node).getActors()); + + if (node instanceof ParentNode) + for (INode n : ((ParentNode) node).getNodes()) { + collectProps(n, props); + } + } }