package org.simantics.g3d.vtk.swt; import java.util.ArrayList; import java.util.List; import javax.vecmath.Point3d; import org.simantics.g3d.shape.Color4d; import org.simantics.g3d.vtk.common.VtkView; import org.simantics.g3d.vtk.shape.vtkShape; import vtk.vtkActor; import vtk.vtkProp; public class ConstraintDetector extends org.simantics.g3d.tools.ConstraintDetector { VtkView renderingPart; private List parts = new ArrayList(); public ConstraintDetector(VtkView renderingPart) { this.renderingPart = renderingPart; } @Override protected void addConstrainLineHighlight(Point3d p1, Point3d p2, Color4d color) { double w = 3; vtkActor lineActorX = vtkShape.createLineActor(p1, p2); lineActorX.GetProperty().SetColor(color.x, color.y, color.z); lineActorX.GetProperty().SetLineWidth(w); lineActorX.GetProperty().Delete(); parts.add(lineActorX); renderingPart.lock(); renderingPart.getRenderer().AddActor(lineActorX); renderingPart.unlock(); } @Override protected void addConstrainPlaneHighlight(Point3d p1, Point3d p2, int axis) { double w = 3; Point3d p12 = new Point3d(); Color4d color = xColor; switch (axis) { case ConstraintDetector.X: p12.x = p1.x; p12.y = p1.y; p12.z = p2.z; color = xColor; break; case ConstraintDetector.Y: p12.x = p1.x; p12.y = p1.y; p12.z = p2.z; color = yColor; break; case ConstraintDetector.Z: p12.x = p1.x; p12.y = p2.y; p12.z = p2.z; color = zColor; break; } vtkActor lineActorX = vtkShape.createLineActor(p1, p12, p2); lineActorX.GetProperty().SetColor(color.x, color.y, color.z); lineActorX.GetProperty().SetLineWidth(w); lineActorX.GetProperty().Delete(); parts.add(lineActorX); renderingPart.lock(); renderingPart.getRenderer().AddActor(lineActorX); renderingPart.unlock(); } @Override public void clearConstraintHighlights() { clearSnapString(); if (parts.size() == 0) return; renderingPart.lock(); for (vtkProp p : parts) { renderingPart.getRenderer().RemoveActor(p); p.Delete(); } parts.clear(); renderingPart.unlock(); } }