Fixed unexpected behavior for all editor move options 2d/3d view 24/12724/2
Caio SOUZA [Sat, 28 Sep 2013 02:55:42 +0000 (23:55 -0300)]
Change-Id: I13c3f2f9100ea3fb88976483be51dc040d4b17cb

scilab/modules/gui/etc/graphics_toolbar.xml
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/DataEditor.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/GEDPicker.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/PolylineHandler.java

index 1332818..625825c 100644 (file)
         <callback instruction="datatipManagerMode(get_figure_handle([SCILAB_FIGURE_ID]))" type="-2"/>
     </button>
     <!-- Scilab Graphic Editor -->
+    <!--
     <button icon="plot" tooltiptext="Open the graphics editor">
         <callback instruction="openged([SCILAB_FIGURE_ID])" type="-2"/>
     </button>
-    <!--
+    -->
     <button icon="data_modify" tooltiptext="Toggle curve data modification">
         <callback instruction="useeditor([SCILAB_FIGURE_ID])" type="-2"/>
     </button>
-    -->
     <separator/>
     <!-- Help -->
     <button icon="help-browser" tooltiptext="Help Browser">
index c0f1b09..ec0f5f6 100644 (file)
@@ -26,6 +26,7 @@ import org.scilab.modules.renderer.JoGLView.DrawerVisitor;
 import org.scilab.modules.renderer.JoGLView.axes.AxesDrawer;
 import org.scilab.modules.graphic_objects.PolylineData;
 import org.scilab.modules.localization.Messages;
+import org.scilab.forge.scirenderer.tranformations.Vector3d;
 
 /**
  * Polyline data editor.
@@ -229,15 +230,41 @@ public class DataEditor {
 
             if (!picked.isSegment) {
 
-                double[] pos = {1.0 * lastClick[0], 1.0 * lastClick[1], 1.0};
+                double[] datax = (double[])PolylineData.getDataX(curPolyline);
+                double[] datay = (double[])PolylineData.getDataY(curPolyline);
+                double[] dataz = (double[])PolylineData.getDataZ(curPolyline);
+
+                //Current point
+                Vector3d planePoint = new Vector3d(datax[picked.point], datay[picked.point], dataz[picked.point]);
+                Vector3d planeNorm = new Vector3d(0.0, 0.0, 1.0);
+                //2d coords for current click
+                double[] pos = {1.0 * newClick[0], 1.0 * newClick[1], 1.0};
                 double[] c2d = CallRenderer.get2dViewFromPixelCoordinates(axes, pos);
-                double[] pos2 = {1.0 * newClick[0], 1.0 * newClick[1], 1.0};
-                double[] c2d2 = CallRenderer.get2dViewFromPixelCoordinates(axes, pos2);
+
+                Axes axesObj = AxesHandler.getAxesFromUid(axes);
+                //3d ray for the current click
+                double[] c3d1 = AxesDrawer.compute3dViewCoordinates(axesObj, c2d);
+                c2d[2] += 1.0;
+                double[] c3d2 = AxesDrawer.compute3dViewCoordinates(axesObj, c2d);
+
+                Vector3d v0 = new Vector3d(c3d1);
+                Vector3d v1 = new Vector3d(c3d2);
+                Vector3d dir = v1.minus(v0);
+                //if the dir is parallel to the plane there isn't intersection
+                if (dir.getZ() == 0) {
+                    return;
+                }
+                //General plane intersection
+                //double u = planePoint.minus(v0).scalar(planeNorm) /  dir.scalar(planeNorm);
+                double u = (planePoint.getZ() - v0.getZ()) / dir.getZ();
+                Vector3d pointNew = dir.times(u);
+                pointNew = pointNew.plus(v0);
+
                 boolean[] logFlags = new boolean[] {(Boolean)GraphicController.getController().getProperty(axes, GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__),
                                                     (Boolean)GraphicController.getController().getProperty(axes, GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__),
                                                     (Boolean)GraphicController.getController().getProperty(axes, GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__)
                                                    };
-                PolylineData.translatePoint(curPolyline, picked.point, c2d2[0] - c2d[0], c2d2[1] - c2d[1], 0.0, logFlags[0] ? 1 : 0, logFlags[1] ? 1 : 0, logFlags[2] ? 1 : 0);
+                PolylineData.translatePoint(curPolyline, picked.point, pointNew.getX() - planePoint.getX(), pointNew.getY() - planePoint.getY(), 0.0 , logFlags[0] ? 1 : 0, logFlags[1] ? 1 : 0, logFlags[2] ? 1 : 0);
 
             } else {
                 PolylineHandler.getInstance().dragPolyline(curPolyline, lastClick, newClick);
index d047aa7..ca2af37 100644 (file)
@@ -370,7 +370,7 @@ public class GEDPicker {
             return false;
         }
 
-        double u = upperLeft[2] - (v0.getZ() / dir.getZ());
+        double u = (upperLeft[2] - v0.getZ()) / dir.getZ();
         Vector3d point = v0.plus(dir.times(u));
 
         double xr = data[1] / 2.;
@@ -586,7 +586,7 @@ public class GEDPicker {
             return false;
         }
 
-        double u = upperLeft[2] - (v0.getZ() / c.getZ());
+        double u = (upperLeft[2] - v0.getZ()) / c.getZ();
         Vector3d point = v0.plus(c.times(u));
 
         if (point.getX() >= upperLeft[0] && point.getX() <= (upperLeft[0] + width)
index 26c59b0..0233f02 100644 (file)
@@ -21,6 +21,11 @@ import org.scilab.modules.renderer.CallRenderer;
 
 import org.scilab.modules.gui.editor.ObjectSearcher;
 import org.scilab.modules.graphic_objects.PolylineData;
+import org.scilab.forge.scirenderer.tranformations.Vector3d;
+import org.scilab.modules.renderer.JoGLView.axes.AxesDrawer;
+import org.scilab.modules.renderer.CallRenderer;
+import org.scilab.modules.graphic_objects.axes.Axes;
+
 
 
 /**
@@ -92,16 +97,58 @@ public class PolylineHandler {
 
         String axes = (String) GraphicController.getController().getProperty(polyline, GraphicObjectProperties.__GO_PARENT_AXES__);
         if (polyline != null && axes != null) {
-            double[] pos0 = { position[0] * 1.0, position[1] * 1.0};
-            double[] pos1 = { nextPosition[0] * 1.0, nextPosition[1] * 1.0 };
-            double[] coord0 = CallRenderer.get2dViewFromPixelCoordinates(axes, pos0);
-            double[] coord1 = CallRenderer.get2dViewFromPixelCoordinates(axes, pos1);
-            double[] coordDiff = {coord1[0] - coord0[0], coord1[1] - coord0[1]};
+
+            double[] datax = (double[])PolylineData.getDataX(polyline);
+            double[] datay = (double[])PolylineData.getDataY(polyline);
+            double[] dataz = (double[])PolylineData.getDataZ(polyline);
+
+            //Current point
+            Vector3d planePoint = new Vector3d(datax[0], datay[0], dataz[0]);
+            Vector3d planeNorm = new Vector3d(0.0, 0.0, 1.0);
+            //2d coords for current click
+            double[] pos = {1.0 * nextPosition[0], 1.0 * nextPosition[1], 1.0};
+            double[] c2d = CallRenderer.get2dViewFromPixelCoordinates(axes, pos);
+            //2d position for last click
+            double[] pos2 = {1.0 * position[0], 1.0 * position[1], 1.0};
+            double[] c2d2 = CallRenderer.get2dViewFromPixelCoordinates(axes, pos2);
+
+            Axes axesObj = AxesHandler.getAxesFromUid(axes);
+            //3d ray for the current click
+            double[] c3d1 = AxesDrawer.compute3dViewCoordinates(axesObj, c2d);
+            c2d[2] += 1.0;
+            double[] c3d2 = AxesDrawer.compute3dViewCoordinates(axesObj, c2d);
+            //3d ray for last click
+            double[] c3d3 = AxesDrawer.compute3dViewCoordinates(axesObj, c2d2);
+            c2d2[2] += 1.0;
+            double[] c3d4 = AxesDrawer.compute3dViewCoordinates(axesObj, c2d2);
+
+            //3d current click point and dir
+            Vector3d v0 = new Vector3d(c3d1);
+            Vector3d v1 = new Vector3d(c3d2);
+            Vector3d vdir = v1.minus(v0);
+            //3d old click point and dir
+            Vector3d w0 = new Vector3d(c3d3);
+            Vector3d w1 = new Vector3d(c3d4);
+            Vector3d wdir = v1.minus(v0);
+
+            //if the dir is parallel to the plane there isn't intersection
+            if (wdir.getZ() == 0 || vdir.getZ() == 0) {
+                return;
+            }
+            //General plane intersection
+            double v = (planePoint.getZ() - v0.getZ()) / vdir.getZ();
+            Vector3d pointNew = vdir.times(v);
+            pointNew = pointNew.plus(v0);
+
+            double w = (planePoint.getZ() - w0.getZ()) / wdir.getZ();
+            Vector3d pointOld = wdir.times(w);
+            pointOld = pointOld.plus(w0);
+
             boolean[] logFlags = new boolean[] {(Boolean)GraphicController.getController().getProperty(axes, GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__),
                                                 (Boolean)GraphicController.getController().getProperty(axes, GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__),
                                                 (Boolean)GraphicController.getController().getProperty(axes, GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__)
                                                };
-            PolylineData.translatePolyline(polyline, coordDiff[0], coordDiff[1], 0.0, logFlags[0] ? 1 : 0, logFlags[1] ? 1 : 0, logFlags[2] ? 1 : 0);
+            PolylineData.translatePolyline(polyline, pointNew.getX() - pointOld.getX(), pointNew.getY() - pointOld.getY(), 0.0, logFlags[0] ? 1 : 0, logFlags[1] ? 1 : 0, logFlags[2] ? 1 : 0);
             GraphicController.getController().setProperty(polyline, GraphicObjectProperties.__GO_DATA_MODEL__, polyline);
         }
     }