]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/ConstraintDetector.java
Only disable warning display when not in development mode
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / swt / ConstraintDetector.java
1 package org.simantics.g3d.vtk.swt;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.vecmath.Point3d;
7
8 import org.simantics.g3d.shape.Color4d;
9 import org.simantics.g3d.vtk.common.VtkView;
10 import org.simantics.g3d.vtk.shape.vtkShape;
11
12 import vtk.vtkActor;
13 import vtk.vtkProp;
14
15 public class ConstraintDetector extends org.simantics.g3d.tools.ConstraintDetector {
16
17     VtkView renderingPart;
18     
19     private List<vtkProp> parts = new ArrayList<vtkProp>();
20     
21     public ConstraintDetector(VtkView renderingPart) {
22         this.renderingPart = renderingPart;
23     }
24     
25     @Override
26     protected void addConstrainLineHighlight(Point3d p1, Point3d p2, Color4d color) {
27         double w = 3;
28         
29         vtkActor lineActorX = vtkShape.createLineActor(p1, p2);
30         lineActorX.GetProperty().SetColor(color.x, color.y, color.z);
31         lineActorX.GetProperty().SetLineWidth(w);
32         lineActorX.GetProperty().Delete();
33         parts.add(lineActorX);
34         renderingPart.lock();
35         renderingPart.getRenderer().AddActor(lineActorX);
36         renderingPart.unlock();
37     }
38     
39     @Override
40     protected void addConstrainPlaneHighlight(Point3d p1, Point3d p2, int axis) {
41         double w = 3;
42         Point3d p12 = new Point3d();
43         Color4d color = xColor;
44         switch (axis) {
45             case ConstraintDetector.X:
46                 p12.x = p1.x;
47                 p12.y = p1.y;
48                 p12.z = p2.z;
49                 color = xColor;
50                 break;
51             case ConstraintDetector.Y:
52                 p12.x = p1.x;
53                 p12.y = p1.y;
54                 p12.z = p2.z;
55                 color = yColor;
56                 break;
57             case ConstraintDetector.Z:
58                 p12.x = p1.x;
59                 p12.y = p2.y;
60                 p12.z = p2.z;
61                 color = zColor;
62                 break;
63         }
64         vtkActor lineActorX = vtkShape.createLineActor(p1, p12, p2);
65         lineActorX.GetProperty().SetColor(color.x, color.y, color.z);
66         lineActorX.GetProperty().SetLineWidth(w);
67         lineActorX.GetProperty().Delete();
68         parts.add(lineActorX);
69         renderingPart.lock();
70         renderingPart.getRenderer().AddActor(lineActorX);
71         renderingPart.unlock();
72     }
73     
74     @Override
75     public void clearConstraintHighlights() {
76         clearSnapString();
77         if (parts.size() == 0)
78             return;
79         renderingPart.lock();
80         for (vtkProp p : parts) {
81             renderingPart.getRenderer().RemoveActor(p);
82             p.Delete();
83         }
84         parts.clear();
85         renderingPart.unlock();
86     }
87 }