]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
Add units to ComponentSelectionDialog
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / editor / Plant3DEditor.java
1 package org.simantics.plant3d.editor;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.HashSet;
6 import java.util.List;
7 import java.util.Set;
8
9 import org.eclipse.jface.action.Action;
10 import org.eclipse.jface.action.IAction;
11 import org.eclipse.jface.action.IMenuListener;
12 import org.eclipse.jface.action.IMenuManager;
13 import org.eclipse.jface.action.MenuManager;
14 import org.eclipse.jface.action.Separator;
15 import org.eclipse.jface.layout.GridDataFactory;
16 import org.eclipse.jface.layout.GridLayoutFactory;
17 import org.eclipse.jface.viewers.ISelectionChangedListener;
18 import org.eclipse.jface.viewers.ISelectionProvider;
19 import org.eclipse.jface.viewers.SelectionChangedEvent;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.DisposeEvent;
22 import org.eclipse.swt.events.DisposeListener;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Menu;
25 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
26 import org.simantics.Simantics;
27 import org.simantics.db.ReadGraph;
28 import org.simantics.db.Resource;
29 import org.simantics.db.Session;
30 import org.simantics.db.common.request.ParametrizedRead;
31 import org.simantics.db.common.request.ReadRequest;
32 import org.simantics.db.exception.DatabaseException;
33 import org.simantics.db.layer0.request.combinations.Combinators;
34 import org.simantics.g3d.scenegraph.NodeMap;
35 import org.simantics.g3d.scenegraph.RenderListener;
36 import org.simantics.g3d.scenegraph.base.INode;
37 import org.simantics.g3d.scenegraph.base.ParentNode;
38 import org.simantics.g3d.toolbar.ToolComposite;
39 import org.simantics.g3d.vtk.action.RemoveAction;
40 import org.simantics.g3d.vtk.common.HoverHighlighter;
41 import org.simantics.g3d.vtk.common.NodeSelectionProvider2;
42 import org.simantics.g3d.vtk.common.SelectionHighlighter;
43 import org.simantics.g3d.vtk.common.VtkView;
44 import org.simantics.g3d.vtk.shape.vtkShape;
45 import org.simantics.g3d.vtk.swt.ContextMenuListener;
46 import org.simantics.g3d.vtk.swt.FocusAction;
47 import org.simantics.g3d.vtk.swt.InteractiveVtkComposite;
48 import org.simantics.g3d.vtk.swt.RotateAction;
49 import org.simantics.g3d.vtk.swt.TranslateAction;
50 import org.simantics.g3d.vtk.swt.vtkCameraAndSelectorAction;
51 import org.simantics.g3d.vtk.utils.AxesDisplay;
52 import org.simantics.objmap.graph.IMapping;
53 import org.simantics.objmap.graph.Mappings;
54 import org.simantics.objmap.graph.schema.IMappingSchema;
55 import org.simantics.plant3d.actions.AddComponentAction;
56 import org.simantics.plant3d.actions.AddEquipmentAction;
57 import org.simantics.plant3d.actions.AddNozzleAction;
58 import org.simantics.plant3d.actions.RemoveAndSplitAction;
59 import org.simantics.plant3d.actions.ReversePipeRunAction;
60 import org.simantics.plant3d.actions.RoutePipeAction;
61 import org.simantics.plant3d.actions.TranslateFreeVariableLengthAction;
62 import org.simantics.plant3d.actions.TranslateInlineAction;
63 import org.simantics.plant3d.ontology.Plant3D;
64 import org.simantics.plant3d.scenegraph.EndComponent;
65 import org.simantics.plant3d.scenegraph.Equipment;
66 import org.simantics.plant3d.scenegraph.IP3DNode;
67 import org.simantics.plant3d.scenegraph.IP3DVisualNode;
68 import org.simantics.plant3d.scenegraph.InlineComponent;
69 import org.simantics.plant3d.scenegraph.Nozzle;
70 import org.simantics.plant3d.scenegraph.P3DRootNode;
71 import org.simantics.plant3d.scenegraph.PipeRun;
72 import org.simantics.plant3d.scenegraph.PipelineComponent;
73 import org.simantics.plant3d.scenegraph.SchemaBuilder;
74 import org.simantics.plant3d.scenegraph.TurnComponent;
75 import org.simantics.plant3d.scenegraph.controlpoint.ControlPointFactory;
76 import org.simantics.plant3d.scenegraph.controlpoint.PipingRules;
77 import org.simantics.plant3d.utils.ComponentUtils;
78 import org.simantics.plant3d.utils.Item;
79 import org.simantics.plant3d.utils.P3DUtil;
80 import org.simantics.selectionview.StandardPropertyPage;
81 import org.simantics.ui.workbench.IPropertyPage;
82 import org.simantics.ui.workbench.IResourceEditorInput;
83 import org.simantics.ui.workbench.ResourceEditorPart;
84 import org.simantics.ui.workbench.editor.input.InputValidationCombinators;
85 import org.simantics.utils.threads.ThreadUtils;
86 import org.simantics.utils.ui.ExceptionUtils;
87
88 import vtk.vtkActor;
89 import vtk.vtkCameraPass;
90 import vtk.vtkDefaultPass;
91 import vtk.vtkGaussianBlurPass;
92 import vtk.vtkLightsPass;
93 import vtk.vtkProp3D;
94 import vtk.vtkRenderPassCollection;
95 import vtk.vtkRenderer;
96 import vtk.vtkSSAAPass;
97 import vtk.vtkSequencePass;
98 import vtk.vtkSimpleMotionBlurPass;
99
100
101 public class Plant3DEditor extends ResourceEditorPart {
102
103         private Composite parent;
104         protected ToolComposite toolComposite;
105         private Resource input;
106 //      private InteractiveVtkPanel panel;
107 //      private SWTAWTComponent component;
108         private InteractiveVtkComposite panel;
109
110         
111         private P3DRootNode rootNode;
112         private IMapping<Resource,INode> mapping;
113         
114         protected NodeSelectionProvider2<Resource, INode> selectionProvider;
115         
116         
117         protected vtkCameraAndSelectorAction cameraAction;
118         protected FocusAction focusAction;
119         protected TranslateAction translateAction;
120         protected TranslateInlineAction translateInlineAction;
121         protected TranslateFreeVariableLengthAction translateFreeVariableLengthAction;
122         protected RotateAction rotateAction;
123         protected RemoveAction removeAction;
124         protected RemoveAndSplitAction removeSplitAction;
125         protected RoutePipeAction routePipeAction;
126         protected AddComponentAction addComponentAction;
127         protected ReversePipeRunAction reversePipeRunAction;
128         
129         private P3DNodeMap nodeMap;
130         
131         /** Constants for selecting the up-direction */
132         public static final int X = 0, Y = 1, Z = 2;
133         
134         protected int upDirection = 1;
135
136         ParametrizedRead<IResourceEditorInput, Boolean> INPUT_VALIDATOR =
137                         Combinators.compose(
138                                         InputValidationCombinators.hasURI(),
139                                         InputValidationCombinators.extractInputResource()
140                                         );
141
142         @Override
143         protected ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
144                 return INPUT_VALIDATOR;
145         }
146
147         @Override
148         public void createPartControl(Composite parent) {
149                 this.parent = parent;
150
151                 activateValidation();
152
153                 IResourceEditorInput rei = (IResourceEditorInput)getEditorInput();
154                 input = rei.getResource();
155                 
156                 toolComposite = new ToolComposite(parent, SWT.BORDER);
157             toolComposite.setVisible(true);
158                 
159                 panel = new InteractiveVtkComposite(parent);
160                 
161                 GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(parent);
162         GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(getPanel().getComponent());
163                 
164       
165         GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(toolComposite);
166         
167                 //IActionBars actionBars = getEditorSite().getActionBars();
168
169                 hookContextMenu();
170                 
171                 createScene();
172                 
173                 new ContextMenuListener(panel, contextMenu);
174                 
175                 cameraAction = createCameraAction();
176                 switch (upDirection) {
177                 case 0:
178                         cameraAction.setUpDirection(new double[] { 1, 0, 0 });
179                         break;
180                 case 1:
181                         cameraAction.setUpDirection(new double[] { 0, 1, 0 });
182                         break;
183                 case 2:
184                         cameraAction.setUpDirection(new double[] { 0, 0, 1 });
185                         break;
186                 }
187                 
188                 panel.setDefaultAction(cameraAction);
189                 panel.useDefaultAction();
190                 panel.setPickType(4);
191                 
192                 try {
193                         ControlPointFactory.preloadCache(Simantics.getSession(), getLibraryUri());
194                         ComponentUtils.preloadCache(Simantics.getSession());
195                 } catch (Exception e) {
196                         ExceptionUtils.logAndShowError("Cannot open Plant3D editor",e);
197                         return;
198                 }
199                 
200                 try {
201                         getSession().syncRequest(new ReadRequest() {
202                                 
203                                 @Override
204                                 public void run(ReadGraph graph) throws DatabaseException {
205                                     //System.out.println("START PLANT3D LOAD");
206                                         PipingRules.setEnabled(false);
207                                         IMappingSchema<Resource,INode> schema = getSchema(graph);
208                                         mapping = Mappings.createWithListening(schema);
209                                         rootNode = (P3DRootNode)mapping.map(graph, input);
210                                         // update control points.
211                                         // TODO : this should be optimized.
212
213                                         try {
214                                             P3DUtil.finalizeDBLoad(rootNode);
215                                             nodeMap = createNodeMap(getSession(), mapping, panel,rootNode);
216                                            
217                     } catch (Exception e) {
218                         throw new DatabaseException(e);
219                     }
220                                         
221                                         //System.out.println("END PLANT3D LOAD");
222                                 }
223                         });
224                         
225                         if (rootNode == null)
226                                 throw new RuntimeException("Scenegraph loading failed.");
227                         populate();
228                         
229                         selectionProvider = createSelectionProvider();
230
231                         cameraAction.addSelectionChangedListener(selectionProvider);
232
233                         cameraAction.addHoverChangedListener(createHoverHighlhighter());
234                         selectionProvider.addSelectionChangedListener(createSelectionHighlighter());
235                         
236                         getSite().setSelectionProvider(selectionProvider);
237                         getSite().getPage().addPostSelectionListener(selectionProvider);
238                         
239                         //outlinePage = new ScenegraphOutlinePage(rootNode);
240                         
241                         
242                         parent.addDisposeListener(new DisposeListener() {
243                                 
244                                 @Override
245                                 public void widgetDisposed(DisposeEvent e) {
246                                         getSite().getPage().removePostSelectionListener(selectionProvider);
247                                         
248                                         PipingRules.setEnabled(false);
249                                         nodeMap.delete();
250                                         PipingRules.setEnabled(true);
251                                         mapping.dispose();
252 //                                      component.dispose();
253                                         //panel.getComponent().dispose();
254                                         
255                                 }
256                         });
257                 } catch (DatabaseException e1) {
258                         ExceptionUtils.logAndShowError("Cannot open Plant3D editor",e1);
259                         return;
260                 }
261                 
262                 createActions();
263         }
264         
265         public void setUpDirection(int upDirection) {
266                 this.upDirection = upDirection;
267         }
268
269         protected vtkCameraAndSelectorAction createCameraAction() {
270             return new vtkCameraAndSelectorAction(panel); 
271         }
272         
273         protected NodeSelectionProvider2<Resource,INode> createSelectionProvider() {
274             return new NodeSelectionProvider2<Resource,INode>(this,mapping,nodeMap);
275         }
276         
277         protected HoverHighlighter<Resource> createHoverHighlhighter() {
278             return new HoverHighlighter<>(panel,nodeMap);
279         }
280         
281         protected SelectionHighlighter<Resource> createSelectionHighlighter() {
282             return new SelectionHighlighter<Resource>(panel,nodeMap);
283         }
284         
285         protected String getLibraryUri() {
286             return Plant3D.URIs.Builtin;
287         }
288         
289         protected void createActions() {
290             focusAction = new FocusAction(panel, cameraAction);
291                 translateAction = new TranslateAction(panel,nodeMap,toolComposite);
292                 translateInlineAction = new TranslateInlineAction(panel, nodeMap,toolComposite);
293                 translateFreeVariableLengthAction = new TranslateFreeVariableLengthAction(panel, getRootNode(), toolComposite);
294                 rotateAction = new RotateAction(panel,nodeMap,toolComposite);
295                 removeAction = new RemoveAction(nodeMap);
296                 removeSplitAction = new RemoveAndSplitAction(nodeMap);
297                 routePipeAction = new RoutePipeAction(panel,rootNode, toolComposite);
298                 addComponentAction = new AddComponentAction(panel, rootNode, getLibraryUri());
299                 reversePipeRunAction = new ReversePipeRunAction(nodeMap);
300         }
301         
302         public void populate() {
303                 ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() {
304                         
305                         @Override
306                         public void run() {
307                                 nodeMap.setChangeTracking(false);
308                                 nodeMap.populate();
309                                 nodeMap.setChangeTracking(true);
310                                 panel.addListener(new RenderListener() {
311
312                                         @Override
313                                         public void preRender() {
314
315                                         }
316
317                                         @Override
318                                         public void postRender() {
319                                                 panel.removeListener(this);
320
321                                                 try {
322                                                         P3DUtil.finalizeDBLoad2(rootNode);
323                                                         if (nodeMap.getMapping().isRangeModified())
324                                                                 nodeMap.commit("Load sync");
325                                                 } catch (Exception e) {
326                                                         ExceptionUtils.logAndShowError("Failed to load model correctly", e);
327                                                 }
328                                                 
329                                                 onEditorInitializationComplete();
330                                                 
331                                                 List<vtkProp3D> props = new ArrayList<>();
332                                                 collectProps(rootNode, props);
333                                                 fitToWindow(props);
334                                         }
335                                 });
336                         }
337                 });
338
339         }
340
341         /**
342          * This can be overridden by clients to perform extra initialization tasks
343          */
344         protected void onEditorInitializationComplete() {
345         }
346         
347         protected IMappingSchema<Resource, INode> getSchema(ReadGraph graph) throws DatabaseException {
348                 IMappingSchema<Resource,INode> schema = SchemaBuilder.getSchema(graph);
349                 return schema;
350         }
351         
352         protected P3DNodeMap createNodeMap(Session session, IMapping<Resource, INode> mapping, VtkView panel, P3DRootNode rootNode) {
353                 return new P3DNodeMap(session, mapping, panel,rootNode);
354         }
355         
356         @Override
357         public void setFocus() {
358                 //component.setFocus();
359                 panel.getComponent().setFocus();
360         }
361         
362         protected void createScene() {
363                 vtkRenderer ren1 = panel.getRenderer();
364                 
365                 boolean multiPass = false;
366                 boolean blur = false;
367                 boolean ssaa = false;
368                 //boolean sobel = true;
369                 boolean mblur = false;
370                 if (multiPass) {
371                         
372                         vtkLightsPass lightsPass = new vtkLightsPass();
373                         vtkDefaultPass defaultPass = new vtkDefaultPass();
374                         
375                         
376                         vtkRenderPassCollection passes = new vtkRenderPassCollection();
377                         passes.AddItem(lightsPass);
378                         passes.AddItem(defaultPass);
379                         
380                         vtkSequencePass seq = new vtkSequencePass();
381                         seq.SetPasses(passes);
382                         
383                         vtkCameraPass cameraPass = new vtkCameraPass();
384                         cameraPass.SetDelegatePass(seq);
385                         
386                         if (blur) {
387                             vtkGaussianBlurPass blurPass = new vtkGaussianBlurPass();
388                             blurPass.SetDelegatePass(cameraPass);
389                             ren1.SetPass(blurPass);
390                         } else if (ssaa) {
391                             vtkSSAAPass ssaaPass = new vtkSSAAPass();
392                             ssaaPass.SetDelegatePass(cameraPass);
393                             ren1.SetPass(ssaaPass);
394                         } else if (mblur) {
395                             vtkSimpleMotionBlurPass mBlurPass = new vtkSimpleMotionBlurPass();
396                             mBlurPass.SetDelegatePass(cameraPass);
397                 ren1.SetPass(mBlurPass);
398 //                      } else if (sobel) {
399 //                          vtkSobelGradientMagnitudePass sobelPass = new vtkSobelGradientMagnitudePass();
400 //                          sobelPass.SetDelegatePass(sobelPass);
401 //                          ren1.SetPass(sobelPass);
402                 } else {
403                     ren1.SetPass(cameraPass);
404                 }
405                          
406                 }
407 //              ren1.GetRenderWindow().LineSmoothingOn();
408 //              ren1.GetRenderWindow().PointSmoothingOn();
409 //              ren1.GetRenderWindow().PolygonSmoothingOn();
410 //              ren1.GetRenderWindow().SetMultiSamples(2);
411
412                 
413
414                 ren1.SetBackground2(1,1,1); // background color white
415                 ren1.SetBackground(0.9,0.9,0.9);
416                 ren1.SetGradientBackground(true);
417
418                 // vtkActor grid = vtkShape.createGridActor(8,1.0,1|2|4);
419                 int dir = 1 << upDirection;
420                 vtkActor grid = vtkShape.createGridActor(8, 1.0, dir);
421                 grid.SetPickable(0);
422                 ren1.AddActor(grid);
423                 panel.addDeletable(grid);
424                 
425                 AxesDisplay axesDisplay = new AxesDisplay(panel);
426                 axesDisplay.show();
427         }
428         
429         protected Menu contextMenu;
430         
431         protected void hookContextMenu() {
432                 MenuManager menuMgr = new MenuManager("#PopupMenu");
433                 menuMgr.setRemoveAllWhenShown(true);
434                 menuMgr.addMenuListener(new IMenuListener() {
435                         public void menuAboutToShow(IMenuManager manager) {             
436                                 createContextMenu(manager);
437                         }
438                 });
439
440                 contextMenu = menuMgr.createContextMenu(parent);
441         }
442         
443         protected void createContextMenu(IMenuManager m) {
444                 List<INode> selected = selectionProvider.getSelectedNodes();
445                 
446                 createFocusMenu(m, selected);
447
448                 m.add(new Separator());
449                 
450                 try {
451                         if (selected.size() == 0) {
452                             m.add(new AddEquipmentAction(rootNode, getLibraryUri()));
453 //                              for (Item eq : P3DUtil.getEquipments(getLibraryUri())) {
454 //                                      m.add(new AddEquipmentAction(rootNode, eq));
455 //                              }
456                         } else if (selected.size() == 1) {
457                                 IP3DNode node = (IP3DNode)selected.get(0);
458                                 if (node instanceof Equipment) {
459                                         m.add(translateAction);
460                                         m.add(rotateAction);
461                                         for (Item eq : P3DUtil.getNozzles(Simantics.getSession(), getLibraryUri())) {
462                                                 AddNozzleAction add = new AddNozzleAction(rootNode, eq);
463                                                 add.setEquipment((Equipment)node);
464                                                 m.add(add);
465                                         }
466                                         m.add(removeAction);
467                                 } else if (node instanceof Nozzle) {
468                                         Nozzle nozzle = (Nozzle)node;
469                                         if (!nozzle.isFixed()) {
470                                                 m.add(translateAction);
471                                                 m.add(rotateAction);
472                                         }
473                                         m.add(routePipeAction);
474                                         routePipeAction.setComponent(nozzle);
475                                         routePipeAction.setEnabled(nozzle.getNext() == null && nozzle.getPrevious() == null);
476                                         m.add(addComponentAction);
477                                         addComponentAction.setComponent(nozzle);
478                                         m.add(removeAction);
479                                 } else if (node instanceof TurnComponent) {
480                                         m.add(translateAction);
481                                         TurnComponent component = (TurnComponent)node;
482                                         m.add(routePipeAction);
483                                         routePipeAction.setComponent(component);
484                                         routePipeAction.setEnabled(component.getNext() == null || component.getPrevious() == null);
485                                         m.add(addComponentAction);
486                                         addComponentAction.setComponent(component);
487                                         m.add(removeAction);
488                                         m.add(removeSplitAction);
489                                         removeSplitAction.setNode(node);
490                                 } else if (node instanceof EndComponent) {
491                                         m.add(translateAction);
492                                         m.add(addComponentAction);
493                                         addComponentAction.setComponent((PipelineComponent)node);
494                                         m.add(removeAction);
495                                 } else if (node instanceof InlineComponent) {
496                                         //m.add(translateInlineAction);
497                                         InlineComponent component = (InlineComponent)node;
498                                         if (component.isVariableLength())
499                                             m.add(translateFreeVariableLengthAction);
500                                         else
501                                             m.add(translateInlineAction);
502                                         m.add(routePipeAction);
503                                         routePipeAction.setComponent(component);
504                                         m.add(addComponentAction);
505                                         addComponentAction.setComponent(component);
506                                         m.add(removeAction);
507                                         m.add(removeSplitAction);
508                                         removeSplitAction.setNode(node);
509                                 } else if (node instanceof PipeRun) {
510                                     m.add(reversePipeRunAction);
511                                     m.add(removeAction);
512                                     reversePipeRunAction.setNode(node);
513                                 } else {
514                                     m.add(removeAction);
515                                 }
516                                 
517                                 
518                                 translateAction.setNode(node);
519                                 translateInlineAction.setNode(node);
520                                 translateFreeVariableLengthAction.setNode(node);
521                                 rotateAction.setNode(node);
522                                 removeAction.setNode(node);
523                                 
524                         } 
525                 } catch (DatabaseException e) {
526                         ExceptionUtils.logAndShowError(e);
527                 }
528         }
529
530         protected class FitToWindow extends Action {
531                 private List<INode> selected;
532                 public FitToWindow(List<INode> selected) {
533                         super("Fit to Window");
534                         this.selected = selected;
535                         //setAccelerator('1');
536                 }
537                 @Override
538                 public void run() {
539                         List<vtkProp3D> props = new ArrayList<>();
540                         final Collection<INode> collection = !selected.isEmpty() ? selected : getRootNode().getChild();
541                         for (INode n : collection)
542                                 collectProps(n, props);
543
544                         fitToWindow(props);
545                         getPanel().refresh();
546                 }
547         }
548
549         protected void createFocusMenu(IMenuManager m, List<INode> selected) {
550                 m.add(createFitToWindowAction(selected));
551
552                 if (!selected.isEmpty()) {
553                         List<vtkProp3D> actors = new ArrayList<>();
554                         for (INode n : selected)
555                                 collectProps(n, actors);
556                         if (actors.size() > 0) {
557                                 focusAction.setProps(new ArrayList<>(actors));
558                                 m.add(focusAction);
559                         }
560                 }
561         }
562
563         protected IAction createFitToWindowAction(List<INode> selected) {
564                 return new FitToWindow(selected);
565         }
566
567         private IContentOutlinePage createOutline() {
568                 if (rootNode == null || selectionProvider == null)
569                         return null;
570                 //IContentOutlinePage outlinePage = new VTKContentOutlinePage<Resource,Object>(rootNode, selectionProvider);
571                 IContentOutlinePage outlinePage = new P3DContentOutlinePage(rootNode, selectionProvider) {
572                         protected void createContextMenu(IMenuManager manager) {
573                                 Plant3DEditor.this.createContextMenu(manager);
574                         };
575                 };
576                 outlinePage.addSelectionChangedListener(new ISelectionChangedListener() {
577                         
578                         @Override
579                         public void selectionChanged(SelectionChangedEvent event) {
580                                 selectionProvider.selectionChanged(event);
581                         }
582                 });
583                 return outlinePage;
584         }
585
586         @Override
587         public <T> T getAdapter(Class<T> adapter) {
588                 if (adapter.isAssignableFrom(IPropertyPage.class))
589                         return adapter.cast(new StandardPropertyPage(getSite(),getPropertyContexts()));
590                 if (adapter.isAssignableFrom(ISelectionProvider.class))
591                         return adapter.cast(selectionProvider);
592                 if (adapter.isAssignableFrom(IContentOutlinePage.class)) {
593                         return adapter.cast(createOutline());
594                 }
595                 if (adapter.isAssignableFrom(NodeMap.class)) {
596                         return adapter.cast(nodeMap);
597                 }
598                 if (adapter.isAssignableFrom(INode.class)) {
599                         return adapter.cast(rootNode);
600                 }
601                 if (adapter.isAssignableFrom(IMapping.class)) {
602                         return adapter.cast(mapping);
603                 }
604 //              if (adapter.isAssignableFrom(InteractiveVtkPanel.class)) {
605 //                      return adapter.cast(panel);
606 //              }
607                 if (adapter.isAssignableFrom(VtkView.class))
608                         return adapter.cast(panel);
609                 return super.getAdapter(adapter);
610         }
611         
612         public Set<String> getPropertyContexts() {
613                 Set<String> result = new HashSet<String>();
614                 result.add("http://www.simantics.org/Project-1.0/ProjectBrowseContext");
615                 return result;
616         }
617         
618         public InteractiveVtkComposite getPanel() {
619         return panel;
620     }
621         
622         public P3DRootNode getRootNode() {
623                 return rootNode;
624         }
625         
626         public IMapping<Resource, INode> getMapping() {
627                 return mapping;
628         }
629         
630         public P3DNodeMap getNodeMap() {
631         return nodeMap;
632     }
633
634         public void fitToWindow(Collection<vtkProp3D> props) {
635                 cameraAction.fitToView(props);
636         }
637
638         protected static void collectProps(INode node, List<vtkProp3D> props) {
639                 if (node instanceof IP3DVisualNode)
640                         props.addAll(((IP3DVisualNode) node).getActors());
641                 
642                 if (node instanceof ParentNode)
643                 for (INode n : ((ParentNode<?>) node).getNodes()) {
644                                 collectProps(n, props);
645                 }
646         }
647 }