]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Highlight constrain points 96/3396/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 23 Oct 2019 15:52:06 +0000 (18:52 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 23 Oct 2019 15:52:06 +0000 (18:52 +0300)
gitlab #32

Change-Id: I6e2d36c9ac08040da8a46a67a85bc5a216a1cb08

org.simantics.g3d/src/org/simantics/g3d/tools/ConstraintDetector.java
org.simantics.plant3d/icons/crosshair.png [new file with mode: 0644]
org.simantics.plant3d/icons/crosshair.svg [new file with mode: 0644]
org.simantics.plant3d/src/org/simantics/plant3d/actions/RoutePipeAction.java
org.simantics.plant3d/src/org/simantics/plant3d/gizmo/ConstraintPointGizmo.java [new file with mode: 0644]

index 51e1a7c3345f38353b32b5cbe7f92b016343d608..f1ed4ac422edd098b4c6b10be0220b3212315580 100644 (file)
@@ -39,14 +39,6 @@ public abstract class ConstraintDetector {
        protected Color4d yColor = new Color4d(0.f,1.f,0.f,1.f);
        protected Color4d zColor = new Color4d(0.f,0.f,1.f,1.f);
        
-       
-//    public ConstraintDetector(ThreeDimensionalEditorBase editor) {
-//        this.editor = editor;
-//        ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();
-//        ms.setEmissive(new ColorRGBA(1.f,1.f,1.f,1.f));
-//        ms.setColorMaterial(MaterialState.CM_EMISSIVE);
-//    }
-       
 
        public void clearConstraints() {
                //System.out.println("ConstraintDetector.clearConstraints()");
diff --git a/org.simantics.plant3d/icons/crosshair.png b/org.simantics.plant3d/icons/crosshair.png
new file mode 100644 (file)
index 0000000..379424e
Binary files /dev/null and b/org.simantics.plant3d/icons/crosshair.png differ
diff --git a/org.simantics.plant3d/icons/crosshair.svg b/org.simantics.plant3d/icons/crosshair.svg
new file mode 100644 (file)
index 0000000..8c73e69
--- /dev/null
@@ -0,0 +1,78 @@
+<?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>
index 64d2d8c6e6c84d7c7f70ae7bd1ab2a90313ea536..5c787037daed939790c0d8030942b9e1e5ea3aa9 100644 (file)
@@ -23,6 +23,7 @@ import org.simantics.g3d.vtk.swt.InteractiveVtkComposite;
 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;
@@ -61,6 +62,7 @@ public class RoutePipeAction extends vtkSwtAction {
 
        private TranslateAxisGizmo translateAxisGizmo = new TranslateAxisGizmo();
        private SplitPointSelectionGizmo splitPointSelectionGizmo;
+       private ConstraintPointGizmo constraintPointGizmo;
        private TerminalSelectionGizmo terminalSelectionGizmo;
        private NodeMap<vtkProp,INode> nodeMap;
        
@@ -93,6 +95,7 @@ public class RoutePipeAction extends vtkSwtAction {
                nodeMap = root.getNodeMap();
                splitPointSelectionGizmo = new SplitPointSelectionGizmo(panel);
                terminalSelectionGizmo = new TerminalSelectionGizmo(panel);
+               constraintPointGizmo = new ConstraintPointGizmo(panel);
                detector = new org.simantics.g3d.vtk.swt.ConstraintDetector(panel);
        }
        
@@ -151,6 +154,8 @@ public class RoutePipeAction extends vtkSwtAction {
                        splitPointSelectionGizmo.deattach();
                if (terminalSelectionGizmo.isAttached())
                        terminalSelectionGizmo.deattach();
+               if (constraintPointGizmo.isAttached())
+                   constraintPointGizmo.deattach();
                if (infoActor != null) {
                        panel.getRenderer().RemoveActor(infoActor);
                        infoActor.Delete();
@@ -595,7 +600,10 @@ public class RoutePipeAction extends vtkSwtAction {
        
        private void updateConstraints() {
            detector.clearConstraints();
+           constraintPointGizmo.clearPositions();
            if (hoverObject == null) {
+               if (constraintPointGizmo.isAttached())
+                   constraintPointGizmo.deattach();
                return;
            }
            if (hoverObject instanceof Nozzle) {
@@ -608,10 +616,19 @@ public class RoutePipeAction extends vtkSwtAction {
                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
diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/gizmo/ConstraintPointGizmo.java b/org.simantics.plant3d/src/org/simantics/plant3d/gizmo/ConstraintPointGizmo.java
new file mode 100644 (file)
index 0000000..44d158f
--- /dev/null
@@ -0,0 +1,215 @@
+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();
+        
+    }
+    
+    
+  
+
+}