]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/property/VTKPropertyTabContributor.java
Perform view direction switching via vtkCameraAndSelectorAction
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / property / VTKPropertyTabContributor.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g3d.vtk.property;
13
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.ISelectionProvider;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.FillLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Display;
21 import org.eclipse.swt.widgets.Text;
22 import org.eclipse.ui.IWorkbenchSite;
23 import org.simantics.db.management.ISessionContext;
24 import org.simantics.selectionview.IPropertyTab;
25 import org.simantics.selectionview.PropertyTabContributor;
26 import org.simantics.utils.threads.IThreadWorkQueue;
27 import org.simantics.utils.threads.ThreadUtils;
28
29 import vtk.vtkActor;
30 import vtk.vtkAlgorithm;
31 import vtk.vtkAlgorithmOutput;
32 import vtk.vtkMapper;
33 import vtk.vtkProp;
34
35 public class VTKPropertyTabContributor implements PropertyTabContributor{
36         
37         private IThreadWorkQueue tq;
38         public VTKPropertyTabContributor(IThreadWorkQueue tq) {
39                 this.tq = tq;
40         }
41         
42         public org.simantics.selectionview.IPropertyTab create(Composite parent, IWorkbenchSite site, ISessionContext context, Object input) {
43                 IPropertyTab tab = new VTKPropertyTab((vtkProp)input);
44                 tab.createControl(parent, context);
45                 return tab;
46         };
47         
48         
49         public class VTKPropertyTab implements IPropertyTab {
50                 private Composite composite;
51                 private Text text;
52                 private vtkProp prop;
53                 
54                 public VTKPropertyTab(vtkProp prop) {
55                         this.prop = prop;
56                 }
57                 
58                 @Override
59                 public void createControl(Composite parent, ISessionContext context) {
60                         
61                         composite = new Composite(parent, SWT.NONE);
62                         composite.setLayout(new FillLayout());
63                         text = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
64                         ThreadUtils.asyncExec(tq, new Runnable() {
65                                 
66                                 @Override
67                                 public void run() {
68                                         String string = "";
69                                         if (prop instanceof vtkActor) {
70                                                 vtkActor act = (vtkActor)prop;
71                                                 vtkMapper mapper = act.GetMapper();
72                                                 vtkAlgorithmOutput out = mapper.GetInputConnection(0, 0);
73                                                 vtkAlgorithm producer = out.GetProducer();
74                                                 string += producer.GetClassName() +"\n";
75                                                 out.Delete();
76                                                 mapper.Delete();
77                                                 producer.Delete();
78                                         }
79                                         string += prop.Print();
80                                         final String s = string;
81                                         Display.getDefault().asyncExec(new Runnable() {
82                                                 @Override
83                                                 public void run() {
84                                                         if (!text.isDisposed())
85                                                                 text.setText(s);
86                                                 }
87                                         });
88                                 }
89                         });;
90                         
91                         
92                 }
93                 
94                 @Override
95                 public void requestFocus() {
96                         composite.setFocus();
97                 }
98                 
99                 @Override
100                 public void dispose() {
101                         composite.dispose();
102                 }
103                 
104                 @Override
105                 public boolean isDisposed() {
106                         return composite.isDisposed();
107                 }
108                 
109                 @Override
110                 public Control getControl() {
111                         return composite;
112                 }
113                 
114                 @Override
115                 public void setInput(ISessionContext context, ISelection selection,
116                                 boolean force) {
117                         
118                 }
119                 
120                 @Override
121                 public ISelectionProvider getSelectionProvider() {
122                         return null;
123                 }
124         }
125
126 }