]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/gizmo/TranslateAxisGizmo.java
Using SWT thread with Plant3d
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / gizmo / TranslateAxisGizmo.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.gizmo;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
17
18 import javax.vecmath.Point3d;
19
20 import org.simantics.g3d.vtk.awt.TranslateAction;
21 import org.simantics.g3d.vtk.shape.vtkShape;
22
23 import vtk.vtkActor;
24 import vtk.vtkProp;
25
26 public class TranslateAxisGizmo extends vtkGizmo{
27         
28         private List<vtkProp> parts = new ArrayList<vtkProp>();
29         int type = -1;
30
31         
32         @Override
33         public Collection<vtkProp> getGizmo() {
34                 for (vtkProp p : parts)
35                         p.Delete();
36                 parts.clear();
37                 double l = 100;
38                 double w = 3;
39                 switch (type) {
40                 case TranslateAction.X:{
41                         vtkActor lineActorX = vtkShape.createLineActor(new Point3d(-l,0,0), new Point3d(l,0,0));
42                         lineActorX.GetProperty().SetColor(1, 0, 0);
43                         lineActorX.GetProperty().SetLineWidth(w);
44                         lineActorX.GetProperty().Delete();
45                         parts.add(lineActorX);
46                         break;
47                 }
48                 case TranslateAction.Y: {
49                         vtkActor lineActorY = vtkShape.createLineActor(new Point3d(0,-l,0), new Point3d(0,l,0));
50                         lineActorY.GetProperty().SetColor(0, 1, 0);
51                         lineActorY.GetProperty().SetLineWidth(w);
52                         lineActorY.GetProperty().Delete();
53                         parts.add(lineActorY);
54                         break;
55                 }
56                 case TranslateAction.Z: {
57                         vtkActor lineActorZ = vtkShape.createLineActor(new Point3d(0,0,-l), new Point3d(0,0,l));
58                         lineActorZ.GetProperty().SetColor(0, 0, 1);
59                         lineActorZ.GetProperty().SetLineWidth(w);
60                         lineActorZ.GetProperty().Delete();
61                         parts.add(lineActorZ);
62                         break;
63                 }
64                 case TranslateAction.XY: {
65                         vtkActor lineActorX = vtkShape.createLineActor(new Point3d(-l,0,0), new Point3d(l,0,0));
66                         lineActorX.GetProperty().SetColor(1, 0, 0);
67                         lineActorX.GetProperty().SetLineWidth(w);
68                         lineActorX.GetProperty().Delete();
69                         parts.add(lineActorX);
70                         vtkActor lineActorY = vtkShape.createLineActor(new Point3d(0,-l,0), new Point3d(0,l,0));
71                         lineActorY.GetProperty().SetColor(0, 1, 0);
72                         lineActorY.GetProperty().SetLineWidth(w);
73                         lineActorY.GetProperty().Delete();
74                         parts.add(lineActorY);
75                         break;
76                 }
77                 case TranslateAction.XZ: {
78                         vtkActor lineActorX = vtkShape.createLineActor(new Point3d(-l,0,0), new Point3d(l,0,0));
79                         lineActorX.GetProperty().SetColor(1, 0, 0);
80                         lineActorX.GetProperty().Delete();
81                         parts.add(lineActorX);
82                         vtkActor lineActorZ = vtkShape.createLineActor(new Point3d(0,0,-l), new Point3d(0,0,l));
83                         lineActorZ.GetProperty().SetColor(0, 0, 1);
84                         lineActorZ.GetProperty().Delete();
85                         parts.add(lineActorZ);
86                         break;
87                 }
88                 case TranslateAction.YZ: {
89                         vtkActor lineActorY = vtkShape.createLineActor(new Point3d(0,-l,0), new Point3d(0,l,0));
90                         lineActorY.GetProperty().SetColor(0, 1, 0);
91                         lineActorY.GetProperty().SetLineWidth(w);
92                         lineActorY.GetProperty().Delete();
93                         parts.add(lineActorY);
94                         vtkActor lineActorZ = vtkShape.createLineActor(new Point3d(0,0,-l), new Point3d(0,0,l));
95                         lineActorZ.GetProperty().SetColor(0, 0, 1);
96                         lineActorZ.GetProperty().SetLineWidth(w);
97                         lineActorZ.GetProperty().Delete();
98                         parts.add(lineActorZ);
99                         break;
100                 }
101                 default: {
102                         
103                 }
104                 }
105                 return parts;
106         }
107         
108         public void setType(int type) {
109                 if (this.type == type)
110                         return;
111                 this.type = type;
112                 if (getView() != null) {
113                         deattachActors();
114                         attachActors();
115                 }
116         }
117         
118         
119 }