]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
Using SWT thread with Plant3d
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / editor / Plant3DEditor.java
index 033f8544cf6f71103130d6b7db37a986609959f0..b1bb5000995c394503504c3a3aa54a68bea3ab25 100644 (file)
@@ -1,6 +1,5 @@
 package org.simantics.plant3d.editor;
 
-import java.awt.Component;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -11,12 +10,10 @@ import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.DisposeEvent;
 import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 import org.simantics.db.ReadGraph;
@@ -28,17 +25,17 @@ import org.simantics.g3d.scenegraph.IG3DNode;
 import org.simantics.g3d.scenegraph.NodeMap;
 import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.g3d.vtk.action.RemoveAction;
-import org.simantics.g3d.vtk.action.RotateAction;
-import org.simantics.g3d.vtk.action.TranslateAction;
-import org.simantics.g3d.vtk.action.vtkCameraAndSelectorAction;
-import org.simantics.g3d.vtk.common.ContextMenuListener;
 import org.simantics.g3d.vtk.common.HoverHighlighter;
-import org.simantics.g3d.vtk.common.InteractiveVtkPanel;
 import org.simantics.g3d.vtk.common.NodeSelectionProvider2;
 import org.simantics.g3d.vtk.common.SelectionHighlighter;
+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.InteractiveVtkComposite;
+import org.simantics.g3d.vtk.swt.RotateAction;
+import org.simantics.g3d.vtk.swt.TranslateAction;
+import org.simantics.g3d.vtk.swt.vtkCameraAndSelectorAction;
 import org.simantics.g3d.vtk.utils.AxesDisplay;
-import org.simantics.g3d.vtk.utils.vtkPanelUtil;
 import org.simantics.objmap.graph.IMapping;
 import org.simantics.objmap.graph.Mappings;
 import org.simantics.objmap.graph.schema.IMappingSchema;
@@ -67,17 +64,13 @@ 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.utils.threads.AWTThread;
 import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.ExceptionUtils;
-import org.simantics.utils.ui.SWTAWTComponent;
 
 import vtk.vtkActor;
-import vtk.vtkAxesActor;
 import vtk.vtkCameraPass;
 import vtk.vtkDefaultPass;
 import vtk.vtkLightsPass;
-import vtk.vtkOrientationMarkerWidget;
 import vtk.vtkRenderPassCollection;
 import vtk.vtkRenderer;
 import vtk.vtkSequencePass;
@@ -87,8 +80,9 @@ public class Plant3DEditor extends ResourceEditorPart {
 
        private Composite parent;
        private Resource input;
-       private InteractiveVtkPanel panel;
-       private SWTAWTComponent component;
+//     private InteractiveVtkPanel panel;
+//     private SWTAWTComponent component;
+       private InteractiveVtkComposite panel;
        
        private P3DRootNode rootNode;
        private IMapping<Resource,Object> mapping;
@@ -109,28 +103,32 @@ public class Plant3DEditor extends ResourceEditorPart {
        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;
-                       }
-               };
+//             component = new SWTAWTComponent(parent,SWT.NONE) {
+//                     
+//                     @Override
+//                     protected Component createSwingComponent() {
+//                             if (panel == null) {
+//                                     panel = new InteractiveVtkPanel();
+//                                     vtkPanelUtil.registerPanel(panel);
+//                                     createScene();
+//                             }
+//                             return panel;
+//                     }
+//             };
 
                IResourceEditorInput rei = (IResourceEditorInput)getEditorInput();
                input = rei.getResource();
                
+               panel = new InteractiveVtkComposite(parent);
+               
                
                //IActionBars actionBars = getEditorSite().getActionBars();
 
                hookContextMenu();
                
-               component.syncPopulate();
+               createScene();
+
+               //component.syncPopulate();
                
                new ContextMenuListener(panel, contextMenu);
                
@@ -223,20 +221,12 @@ public class Plant3DEditor extends ResourceEditorPart {
                                public void widgetDisposed(DisposeEvent e) {
                                        getSite().getPage().removePostSelectionListener(selectionProvider);
                                        
-                                       ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
-                                               
-                                               @Override
-                                               public void run() {
-                                                       PipingRules.setEnabled(false);
-                                                       nodeMap.delete();
-                                                       PipingRules.setEnabled(true);
-                                                       vtkPanelUtil.unregisterPanel(panel);
-
-                                               }
-                                       });
+                                       PipingRules.setEnabled(false);
+                                       nodeMap.delete();
+                                       PipingRules.setEnabled(true);
                                        mapping.dispose();
-                                       component.dispose();
-                                       
+//                                     component.dispose();
+                                       //panel.getComponent().dispose();
                                        
                                }
                        });
@@ -261,7 +251,7 @@ public class Plant3DEditor extends ResourceEditorPart {
        }
        
        public void populate() {
-               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+               ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() {
                        
                        @Override
                        public void run() {
@@ -276,17 +266,18 @@ public class Plant3DEditor extends ResourceEditorPart {
                return schema;
        }
        
-       protected P3DNodeMap createNodeMap(Session session, IMapping<Resource, Object> mapping, InteractiveVtkPanel panel, P3DRootNode rootNode) {
+       protected P3DNodeMap createNodeMap(Session session, IMapping<Resource, Object> mapping, VtkView panel, P3DRootNode rootNode) {
                 return new P3DNodeMap(session, mapping, panel,rootNode);
        }
        
        @Override
        public void setFocus() {
-               component.setFocus();
+               //component.setFocus();
+               panel.getComponent().setFocus();
        }
        
        private void createScene() {
-               vtkRenderer ren1 = panel.GetRenderer();
+               vtkRenderer ren1 = panel.getRenderer();
                
                boolean multiPass = false;
                if (multiPass) {
@@ -440,9 +431,11 @@ public class Plant3DEditor extends ResourceEditorPart {
                if (IMapping.class.equals(adapter)) {
                        return mapping;
                }
-               if (InteractiveVtkPanel.class.equals(adapter)) {
+//             if (InteractiveVtkPanel.class.equals(adapter)) {
+//                     return panel;
+//             }
+               if (VtkView.class.equals(adapter))
                        return panel;
-               }
                if (ISelectionProvider.class.equals(adapter))
                        return selectionProvider;
                return super.getAdapter(adapter);