X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Feditor%2FPlant3DEditor.java;h=53a0ed2c78ed1298bca72e551986d2fe2f3cd8fc;hb=4a656971025eea4b563933179d6120d0e87e7549;hp=51e03ad36530828b74ebad223bd29af5e1f41e94;hpb=dad2672f12421f28805df9d97acf20d0a8efe71f;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 51e03ad3..53a0ed2c 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -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; @@ -21,7 +22,6 @@ import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; -import org.simantics.g3d.scenegraph.IG3DNode; import org.simantics.g3d.scenegraph.NodeMap; import org.simantics.g3d.scenegraph.RenderListener; import org.simantics.g3d.scenegraph.base.INode; @@ -29,9 +29,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; @@ -45,6 +47,7 @@ import org.simantics.plant3d.actions.AddEquipmentAction; import org.simantics.plant3d.actions.AddNozzleAction; import org.simantics.plant3d.actions.RemoveAndSplitAction; import org.simantics.plant3d.actions.RoutePipeAction; +import org.simantics.plant3d.actions.TranslateFreeVariableLengthAction; import org.simantics.plant3d.actions.TranslateInlineAction; import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.EndComponent; @@ -71,10 +74,15 @@ import org.simantics.utils.ui.ExceptionUtils; import vtk.vtkActor; import vtk.vtkCameraPass; import vtk.vtkDefaultPass; +import vtk.vtkGaussianBlurPass; import vtk.vtkLightsPass; +import vtk.vtkProp; import vtk.vtkRenderPassCollection; import vtk.vtkRenderer; +import vtk.vtkSSAAPass; import vtk.vtkSequencePass; +import vtk.vtkSimpleMotionBlurPass; +import vtk.vtkSobelGradientMagnitudePass; public class Plant3DEditor extends ResourceEditorPart { @@ -86,18 +94,21 @@ public class Plant3DEditor extends ResourceEditorPart { private InteractiveVtkComposite panel; private P3DRootNode rootNode; - private IMapping mapping; + private IMapping mapping; - private NodeSelectionProvider2 selectionProvider; + protected NodeSelectionProvider2 selectionProvider; - private vtkCameraAndSelectorAction cameraAction; - private TranslateAction translateAction; - private TranslateInlineAction translateInlineAction; - private RotateAction rotateAction; - private RemoveAction removeAction; - private RemoveAndSplitAction removeSplitAction; - private RoutePipeAction routePipeAction; - private AddComponentAction addComponentAction; + + protected vtkCameraAndSelectorAction cameraAction; + protected FocusAction focusAction; + protected TranslateAction translateAction; + protected TranslateInlineAction translateInlineAction; + protected TranslateFreeVariableLengthAction translateFreeVariableLengthAction; + protected RotateAction rotateAction; + protected RemoveAction removeAction; + protected RemoveAndSplitAction removeSplitAction; + protected RoutePipeAction routePipeAction; + protected AddComponentAction addComponentAction; private P3DNodeMap nodeMap; @@ -129,8 +140,6 @@ public class Plant3DEditor extends ResourceEditorPart { hookContextMenu(); createScene(); - - //component.syncPopulate(); new ContextMenuListener(panel, contextMenu); @@ -140,7 +149,7 @@ public class Plant3DEditor extends ResourceEditorPart { panel.setPickType(4); try { - ControlPointFactory.preloadCache(); + ControlPointFactory.preloadCache(getLibraryUri()); ComponentUtils.preloadCache(); } catch (Exception e) { ExceptionUtils.logAndShowError("Cannot open Plant3D editor",e); @@ -150,19 +159,16 @@ public class Plant3DEditor extends ResourceEditorPart { try { getSession().syncRequest(new ReadRequest() { - @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void run(ReadGraph graph) throws DatabaseException { System.out.println("START PLANT3D LOAD"); PipingRules.setEnabled(false); - IMappingSchema schema = getSchema(graph); + IMappingSchema schema = getSchema(graph); mapping = Mappings.createWithListening(schema); rootNode = (P3DRootNode)mapping.map(graph, input); // update control points. // TODO : this should be optimized. - - - + try { P3DUtil.finalizeDBLoad(rootNode); nodeMap = createNodeMap(getSession(), mapping, panel,rootNode); @@ -220,16 +226,16 @@ public class Plant3DEditor extends ResourceEditorPart { return new vtkCameraAndSelectorAction(panel); } - protected NodeSelectionProvider2 createSelectionProvider() { - return new NodeSelectionProvider2(this,mapping,nodeMap); + protected NodeSelectionProvider2 createSelectionProvider() { + return new NodeSelectionProvider2(this,mapping,nodeMap); } protected HoverHighlighter createHoverHighlhighter() { return new HoverHighlighter(panel,nodeMap); } - protected SelectionHighlighter createSelectionHighlighter() { - return new SelectionHighlighter(panel,nodeMap); + protected SelectionHighlighter createSelectionHighlighter() { + return new SelectionHighlighter(panel,nodeMap); } protected String getLibraryUri() { @@ -237,15 +243,12 @@ 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()); rotateAction = new RotateAction(panel,nodeMap); - removeAction = new RemoveAction(nodeMap) { - public void setNode(IG3DNode node) { - super.setNode(node); - } - }; - + removeAction = new RemoveAction(nodeMap); removeSplitAction = new RemoveAndSplitAction(nodeMap); routePipeAction = new RoutePipeAction(panel,rootNode); addComponentAction = new AddComponentAction(panel, rootNode, getLibraryUri()); @@ -283,12 +286,12 @@ public class Plant3DEditor extends ResourceEditorPart { } - protected IMappingSchema getSchema(ReadGraph graph) throws DatabaseException { - IMappingSchema schema = SchemaBuilder.getSchema(graph); + protected IMappingSchema getSchema(ReadGraph graph) throws DatabaseException { + IMappingSchema schema = SchemaBuilder.getSchema(graph); return schema; } - protected P3DNodeMap createNodeMap(Session session, IMapping mapping, VtkView panel, P3DRootNode rootNode) { + protected P3DNodeMap createNodeMap(Session session, IMapping mapping, VtkView panel, P3DRootNode rootNode) { return new P3DNodeMap(session, mapping, panel,rootNode); } @@ -302,6 +305,10 @@ public class Plant3DEditor extends ResourceEditorPart { vtkRenderer ren1 = panel.getRenderer(); boolean multiPass = false; + boolean blur = false; + boolean ssaa = false; + //boolean sobel = true; + boolean mblur = false; if (multiPass) { vtkLightsPass lightsPass = new vtkLightsPass(); @@ -318,8 +325,26 @@ public class Plant3DEditor extends ResourceEditorPart { vtkCameraPass cameraPass = new vtkCameraPass(); cameraPass.SetDelegatePass(seq); - ren1.SetPass(cameraPass); - + if (blur) { + vtkGaussianBlurPass blurPass = new vtkGaussianBlurPass(); + blurPass.SetDelegatePass(cameraPass); + ren1.SetPass(blurPass); + } else if (ssaa) { + vtkSSAAPass ssaaPass = new vtkSSAAPass(); + ssaaPass.SetDelegatePass(cameraPass); + ren1.SetPass(ssaaPass); + } else if (mblur) { + vtkSimpleMotionBlurPass mBlurPass = new vtkSimpleMotionBlurPass(); + mBlurPass.SetDelegatePass(cameraPass); + ren1.SetPass(mBlurPass); +// } else if (sobel) { +// vtkSobelGradientMagnitudePass sobelPass = new vtkSobelGradientMagnitudePass(); +// sobelPass.SetDelegatePass(sobelPass); +// ren1.SetPass(sobelPass); + } else { + ren1.SetPass(cameraPass); + } + } // ren1.GetRenderWindow().LineSmoothingOn(); // ren1.GetRenderWindow().PointSmoothingOn(); @@ -358,7 +383,20 @@ public class Plant3DEditor extends ResourceEditorPart { } protected void createContextMenu(IMenuManager m) { - List selected = selectionProvider.getSelectedNodes(); + 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); + } + } try { if (selected.size() == 0) { for (Item eq : P3DUtil.getEquipments(getLibraryUri())) { @@ -406,7 +444,10 @@ public class Plant3DEditor extends ResourceEditorPart { } else if (node instanceof InlineComponent) { //m.add(translateInlineAction); InlineComponent component = (InlineComponent)node; - m.add(translateInlineAction); + if (component.isVariableLength()) + m.add(translateFreeVariableLengthAction); + else + m.add(translateInlineAction); m.add(routePipeAction); routePipeAction.setComponent(component); m.add(addComponentAction); @@ -421,6 +462,7 @@ public class Plant3DEditor extends ResourceEditorPart { translateAction.setNode(node); translateInlineAction.setNode(node); + translateFreeVariableLengthAction.setNode(node); rotateAction.setNode(node); removeAction.setNode(node); @@ -490,7 +532,7 @@ public class Plant3DEditor extends ResourceEditorPart { return rootNode; } - public IMapping getMapping() { + public IMapping getMapping() { return mapping; }