]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/gizmo/TranslateAxisGizmo.java
vtk 8.2.0 API changes
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / gizmo / TranslateAxisGizmo.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g3d.vtk.gizmo;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.List;\r
17 \r
18 import javax.vecmath.Point3d;\r
19 \r
20 import org.simantics.g3d.vtk.action.TranslateAction;\r
21 import org.simantics.g3d.vtk.shape.vtkShape;\r
22 \r
23 import vtk.vtkActor;\r
24 import vtk.vtkProp;\r
25 \r
26 public class TranslateAxisGizmo extends vtkGizmo{\r
27         \r
28         private List<vtkProp> parts = new ArrayList<vtkProp>();\r
29         int type = -1;\r
30 \r
31         \r
32         @Override\r
33         public Collection<vtkProp> getGizmo() {\r
34                 for (vtkProp p : parts)\r
35                         p.Delete();\r
36                 parts.clear();\r
37                 double l = 100;\r
38                 double w = 3;\r
39                 switch (type) {\r
40                 case TranslateAction.X:{\r
41                         vtkActor lineActorX = vtkShape.createLineActor(new Point3d(-l,0,0), new Point3d(l,0,0));\r
42                         lineActorX.GetProperty().SetColor(1, 0, 0);\r
43                         lineActorX.GetProperty().SetLineWidth(w);\r
44                         lineActorX.GetProperty().Delete();\r
45                         parts.add(lineActorX);\r
46                         break;\r
47                 }\r
48                 case TranslateAction.Y: {\r
49                         vtkActor lineActorY = vtkShape.createLineActor(new Point3d(0,-l,0), new Point3d(0,l,0));\r
50                         lineActorY.GetProperty().SetColor(0, 1, 0);\r
51                         lineActorY.GetProperty().SetLineWidth(w);\r
52                         lineActorY.GetProperty().Delete();\r
53                         parts.add(lineActorY);\r
54                         break;\r
55                 }\r
56                 case TranslateAction.Z: {\r
57                         vtkActor lineActorZ = vtkShape.createLineActor(new Point3d(0,0,-l), new Point3d(0,0,l));\r
58                         lineActorZ.GetProperty().SetColor(0, 0, 1);\r
59                         lineActorZ.GetProperty().SetLineWidth(w);\r
60                         lineActorZ.GetProperty().Delete();\r
61                         parts.add(lineActorZ);\r
62                         break;\r
63                 }\r
64                 case TranslateAction.XY: {\r
65                         vtkActor lineActorX = vtkShape.createLineActor(new Point3d(-l,0,0), new Point3d(l,0,0));\r
66                         lineActorX.GetProperty().SetColor(1, 0, 0);\r
67                         lineActorX.GetProperty().SetLineWidth(w);\r
68                         lineActorX.GetProperty().Delete();\r
69                         parts.add(lineActorX);\r
70                         vtkActor lineActorY = vtkShape.createLineActor(new Point3d(0,-l,0), new Point3d(0,l,0));\r
71                         lineActorY.GetProperty().SetColor(0, 1, 0);\r
72                         lineActorY.GetProperty().SetLineWidth(w);\r
73                         lineActorY.GetProperty().Delete();\r
74                         parts.add(lineActorY);\r
75                         break;\r
76                 }\r
77                 case TranslateAction.XZ: {\r
78                         vtkActor lineActorX = vtkShape.createLineActor(new Point3d(-l,0,0), new Point3d(l,0,0));\r
79                         lineActorX.GetProperty().SetColor(1, 0, 0);\r
80                         lineActorX.GetProperty().Delete();\r
81                         parts.add(lineActorX);\r
82                         vtkActor lineActorZ = vtkShape.createLineActor(new Point3d(0,0,-l), new Point3d(0,0,l));\r
83                         lineActorZ.GetProperty().SetColor(0, 0, 1);\r
84                         lineActorZ.GetProperty().Delete();\r
85                         parts.add(lineActorZ);\r
86                         break;\r
87                 }\r
88                 case TranslateAction.YZ: {\r
89                         vtkActor lineActorY = vtkShape.createLineActor(new Point3d(0,-l,0), new Point3d(0,l,0));\r
90                         lineActorY.GetProperty().SetColor(0, 1, 0);\r
91                         lineActorY.GetProperty().SetLineWidth(w);\r
92                         lineActorY.GetProperty().Delete();\r
93                         parts.add(lineActorY);\r
94                         vtkActor lineActorZ = vtkShape.createLineActor(new Point3d(0,0,-l), new Point3d(0,0,l));\r
95                         lineActorZ.GetProperty().SetColor(0, 0, 1);\r
96                         lineActorZ.GetProperty().SetLineWidth(w);\r
97                         lineActorZ.GetProperty().Delete();\r
98                         parts.add(lineActorZ);\r
99                         break;\r
100                 }\r
101                 default: {\r
102                         \r
103                 }\r
104                 }\r
105                 return parts;\r
106         }\r
107         \r
108         public void setType(int type) {\r
109                 if (this.type == type)\r
110                         return;\r
111                 this.type = type;\r
112                 if (getRenderer() != null) {\r
113                         deattachActors();\r
114                         attachActors();\r
115                 }\r
116         }\r
117         \r
118         \r
119 }\r