--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://web.resource.org/cc/"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="32"
+ height="32"
+ id="svg2"
+ sodipodi:version="0.32"
+ inkscape:version="0.44"
+ version="1.0"
+ inkscape:export-filename="C:\Documents and Settings\tuoxmao\Desktop\crosshair.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90"
+ sodipodi:docbase="C:\Documents and Settings\tuoxmao\Desktop"
+ sodipodi:docname="crosshair.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ gridtolerance="10000"
+ guidetolerance="10"
+ objecttolerance="10"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="10"
+ inkscape:cx="16"
+ inkscape:cy="16"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ width="32px"
+ height="32px"
+ inkscape:window-width="1280"
+ inkscape:window-height="968"
+ inkscape:window-x="-4"
+ inkscape:window-y="-4" />
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1">
+ <path
+ sodipodi:type="arc"
+ style="fill:none;fill-opacity:1;stroke:white;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:10;stroke-opacity:0.4973262"
+ id="path1872"
+ sodipodi:cx="16"
+ sodipodi:cy="16"
+ sodipodi:rx="12"
+ sodipodi:ry="12"
+ d="M 28 16 A 12 12 0 1 1 4,16 A 12 12 0 1 1 28 16 z" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:white;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:0.4973262;stroke-miterlimit:4;stroke-dasharray:none"
+ d="M 16,7.1054274e-015 L 16,32"
+ id="path2760" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:white;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:0.4973262;stroke-miterlimit:4;stroke-dasharray:none"
+ d="M 0,16 L 32,16"
+ id="path2762" />
+ </g>
+</svg>
import org.simantics.g3d.vtk.swt.vtkSwtAction;
import org.simantics.g3d.vtk.utils.vtkUtil;
import org.simantics.plant3d.Activator;
+import org.simantics.plant3d.gizmo.ConstraintPointGizmo;
import org.simantics.plant3d.gizmo.SplitPointSelectionGizmo;
import org.simantics.plant3d.gizmo.TerminalSelectionGizmo;
import org.simantics.plant3d.scenegraph.EndComponent;
private TranslateAxisGizmo translateAxisGizmo = new TranslateAxisGizmo();
private SplitPointSelectionGizmo splitPointSelectionGizmo;
+ private ConstraintPointGizmo constraintPointGizmo;
private TerminalSelectionGizmo terminalSelectionGizmo;
private NodeMap<vtkProp,INode> nodeMap;
nodeMap = root.getNodeMap();
splitPointSelectionGizmo = new SplitPointSelectionGizmo(panel);
terminalSelectionGizmo = new TerminalSelectionGizmo(panel);
+ constraintPointGizmo = new ConstraintPointGizmo(panel);
detector = new org.simantics.g3d.vtk.swt.ConstraintDetector(panel);
}
splitPointSelectionGizmo.deattach();
if (terminalSelectionGizmo.isAttached())
terminalSelectionGizmo.deattach();
+ if (constraintPointGizmo.isAttached())
+ constraintPointGizmo.deattach();
if (infoActor != null) {
panel.getRenderer().RemoveActor(infoActor);
infoActor.Delete();
private void updateConstraints() {
detector.clearConstraints();
+ constraintPointGizmo.clearPositions();
if (hoverObject == null) {
+ if (constraintPointGizmo.isAttached())
+ constraintPointGizmo.deattach();
return;
}
if (hoverObject instanceof Nozzle) {
c.getEnds(p1, p2);
detector.addContraintPoint(p1);
detector.addContraintPoint(p2);
+ detector.addContraintPoint(new Point3d(c.getWorldPosition()));
} else if (hoverObject instanceof TurnComponent) {
TurnComponent n = (TurnComponent)hoverObject;
detector.addContraintPoint(new Point3d(n.getWorldPosition()));
}
+ if (detector.getConstraintPoints().size() > 0) {
+ for (Point3d p : detector.getConstraintPoints()) {
+ constraintPointGizmo.addPosition(new Vector3d(p));
+ }
+ if (constraintPointGizmo.isAttached())
+ constraintPointGizmo.deattach();
+ constraintPointGizmo.attach(panel);
+ }
}
@Override
--- /dev/null
+package org.simantics.plant3d.gizmo;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.vecmath.Point2d;
+import javax.vecmath.Vector3d;
+
+import org.simantics.g3d.scenegraph.RenderListener;
+import org.simantics.g3d.tools.PluginTools;
+import org.simantics.g3d.vtk.common.VtkView;
+import org.simantics.g3d.vtk.gizmo.vtkGizmo;
+import org.simantics.g3d.vtk.utils.vtkUtil;
+import org.simantics.plant3d.Activator;
+
+import vtk.vtkCellArray;
+import vtk.vtkFloatArray;
+import vtk.vtkPNGReader;
+import vtk.vtkPoints;
+import vtk.vtkPolyData;
+import vtk.vtkPolyDataMapper2D;
+import vtk.vtkPolygon;
+import vtk.vtkProp;
+import vtk.vtkRenderer;
+import vtk.vtkTexture;
+import vtk.vtkTexturedActor2D;
+
+public class ConstraintPointGizmo extends vtkGizmo {
+
+ List<vtkTexturedActor2D> props;
+ List<Vector3d> positions;
+
+ VtkView panel;
+
+ private RenderListener listener;
+
+ public ConstraintPointGizmo(VtkView panel) {
+ this.panel = panel;
+ props = new ArrayList<>();
+ positions = new ArrayList<>();
+
+ this.listener = new RenderListener() {
+
+ @Override
+ public void preRender() {
+ for (int i = 0; i < positions.size(); i++) {
+ Vector3d pos = positions.get(i);
+ vtkTexturedActor2D prop = props.get(i);
+ Point2d p = vtkUtil.getScreenCoordinates(getRenderer(), pos);
+ prop.SetDisplayPosition((int)p.x, (int)p.y);
+ }
+ }
+
+ @Override
+ public void postRender() {
+
+
+ }
+ };
+
+ }
+
+ vtkRenderer getRenderer() {
+ return panel.getRenderer();
+ }
+
+
+ @Override
+ public void attach(VtkView renderingPart) {
+
+ panel.addListener(listener);
+
+ super.attach(renderingPart);
+
+ }
+
+ @Override
+ public Collection<vtkProp> getGizmo() {
+ List<vtkProp> list = new ArrayList<vtkProp>();
+ for (vtkTexturedActor2D p : props) {
+ list.add(p);
+ }
+ return list;
+ }
+
+ protected void attachActors() {
+ panel.lock();
+ vtkRenderer ren = getRenderer();
+ while (props.size() < positions.size())
+ props.add(createActor());
+ for (int i = 0; i < positions.size(); i++) {
+ vtkTexturedActor2D p = props.get(i);
+ ren.AddActor2D(p);
+ }
+ panel.unlock();
+ }
+
+ @Override
+ protected void deattachActors() {
+ panel.removeListener(listener);
+ panel.lock();
+ vtkRenderer ren = getRenderer();
+ for (vtkTexturedActor2D p : props) {
+ ren.RemoveActor2D(p);
+ }
+ panel.unlock();
+ }
+
+
+ public void addPosition(Vector3d position) {
+ positions.add(position);
+ }
+
+ public void clearPositions() {
+ positions.clear();
+ }
+
+ vtkPolyDataMapper2D mapper;
+ vtkTexture plusTex;
+
+ double pw = 8;
+
+ private vtkTexturedActor2D createActor() {
+ if (mapper == null) {
+ loadData();
+ }
+ vtkTexturedActor2D nextProp = new vtkTexturedActor2D();
+
+ nextProp.SetMapper(mapper);
+ nextProp.SetTexture(plusTex);
+ nextProp.SetPickable(0);
+ nextProp.SetWidth(pw);
+ nextProp.SetHeight(pw);
+ nextProp.GetProperty().SetColor(new double[] {255.0,0.0,255.0});
+ nextProp.GetProperty().Delete();
+
+ panel.addDeletable(nextProp);
+
+ return nextProp;
+ }
+
+ public void dispose() {
+
+ }
+
+
+ private void loadData() {
+ String plusTexFile = PluginTools.getAbsolutePath(Activator.getDefault().getBundle(), "icons/crosshair.png");
+ if (plusTexFile == null)
+ throw new RuntimeException("Cannot resolve required image files.");
+
+ vtkPoints points = new vtkPoints();
+ points.InsertNextPoint(-pw, -pw, 0.0);
+ points.InsertNextPoint( pw, -pw, 0.0);
+ points.InsertNextPoint( pw, pw, 0.0);
+ points.InsertNextPoint(-pw, pw, 0.0);
+
+
+ vtkCellArray cellArray = new vtkCellArray();
+ vtkPolygon polygon = new vtkPolygon();
+ polygon.GetPointIds().SetNumberOfIds(4);
+ polygon.GetPointIds().SetId(0, 0);
+ polygon.GetPointIds().SetId(1, 1);
+ polygon.GetPointIds().SetId(2, 2);
+ polygon.GetPointIds().SetId(3, 3);
+
+ cellArray.InsertNextCell(polygon);
+
+ vtkPolyData quad = new vtkPolyData();
+ quad.SetPoints(points);
+ quad.SetPolys(cellArray);
+
+ vtkFloatArray texCoords = new vtkFloatArray();
+
+ texCoords.SetNumberOfComponents(2);
+
+ texCoords.InsertNextTuple2(0.0, 0.0);
+ texCoords.InsertNextTuple2(1.0, 0.0);
+ texCoords.InsertNextTuple2(1.0, 1.0);
+ texCoords.InsertNextTuple2(0.0, 1.0);
+
+ quad.GetPointData().SetTCoords(texCoords);
+
+
+ vtkPNGReader plusReader = new vtkPNGReader();
+ plusReader.SetFileName(plusTexFile);
+
+ plusTex = new vtkTexture();
+ plusTex.SetInputConnection(plusReader.GetOutputPort());
+ plusTex.SetInterpolate(1);
+
+ mapper = new vtkPolyDataMapper2D();
+ mapper.SetInputData(quad);
+
+ panel.addDeletable(mapper);
+ panel.addDeletable(plusTex);
+
+
+ plusReader.GetOutputPort().Delete();
+ plusReader.Delete();
+ quad.GetPointData().Delete();
+ quad.Delete();
+ points.Delete();
+ polygon.GetPointIds().Delete();
+ polygon.Delete();
+ cellArray.Delete();
+ texCoords.Delete();
+
+ }
+
+
+
+
+}