Datatip: fix datatip creation by program for 3 coordinates. 06/12606/1
Gustavo LIBOTTE [Thu, 19 Sep 2013 19:47:07 +0000 (16:47 -0300)]
Change-Id: I3d4da0acce578ae79731591ade15d123f799ac64

scilab/modules/gui/sci_gateway/cpp/sci_datatipcreate.cpp
scilab/modules/gui/src/java/org/scilab/modules/gui/datatip/DatatipCommon.java
scilab/modules/gui/src/java/org/scilab/modules/gui/datatip/DatatipCreate.java

index 9a860db..8ac6b64 100755 (executable)
@@ -86,9 +86,13 @@ int sci_datatipcreate(char *fname, unsigned long fname_len)
                     {
                         datatip_handler = DatatipCreate::createDatatipProgramCoord(getScilabJavaVM(), (char*)polylineUID, pdblReal, 2);
                     }
+                    else if (nbRow * nbCol == 3)
+                    {
+                        datatip_handler = DatatipCreate::createDatatipProgramCoord(getScilabJavaVM(), (char*)polylineUID, pdblReal, 3);
+                    }
                     else
                     {
-                        Scierror(999, _("%s: Wrong size for input argument #%d: matrix 1x2 expected.\n"), fname, 2);
+                        Scierror(999, _("%s: Wrong size for input argument #%d: array of %d or %d elements expected.\n"), fname, 2, 2, 3);
                         return FALSE;
                     }
                 }
index a8c5d5b..8232b03 100644 (file)
@@ -213,7 +213,6 @@ public class DatatipCommon {
     public static Double[] Interpolate3dView(double x, double y, Segment seg, String polyline) {
 
         double[][] polylineData = getPolylineDataMatrix (polyline);
-
         Double[][] polylineDataBackup = backupPolylineData(polylineData);
 
         String axesUid = (String)GraphicController.getController().getProperty(polyline, __GO_PARENT_AXES__);
@@ -221,16 +220,29 @@ public class DatatipCommon {
         polylineData = geom3dCoords;
 
         double[] coefProj = OrthogonalProjection.orthogonalProj(polylineData, new double[] {x, y});
-
         int ind = (int) coefProj[0];
         double coef = coefProj[1];
 
-        Double[] datatipNewPos = new Double[3];
+        Double[] datatipNewPos = datatipInterpolatedPosition (ind, coef, polylineDataBackup);
+        return datatipNewPos;
+
+    }
+
+    /*
+     * Return the interpolated position (x, y, z)
+     * that the segment (x, y) belongs in the polyline
+     * to create de datatip by program
+     */
+    public static Double[] Interpolate3dViewProgCoord(double x, double y, Segment seg, String polyline) {
+
+        double[][] polylineData = getPolylineDataMatrix (polyline);
+        Double[][] polylineDataBackup = backupPolylineData(polylineData);
 
-        datatipNewPos[0] = polylineDataBackup[ind][0] + ((polylineDataBackup[ind + 1][0] - polylineDataBackup[ind][0]) * coef);
-        datatipNewPos[1] = polylineDataBackup[ind][1] + ((polylineDataBackup[ind + 1][1] - polylineDataBackup[ind][1]) * coef);
-        datatipNewPos[2] = polylineDataBackup[ind][2] + ((polylineDataBackup[ind + 1][2] - polylineDataBackup[ind][2]) * coef);
+        double[] coefProj = OrthogonalProjection.orthogonalProj(polylineData, new double[] {x, y});
+        int ind = (int) coefProj[0];
+        double coef = coefProj[1];
 
+        Double[] datatipNewPos = datatipInterpolatedPosition (ind, coef, polylineDataBackup);
         return datatipNewPos;
 
     }
@@ -327,4 +339,15 @@ public class DatatipCommon {
 
         return geom3d;
     }
+
+    private static Double[] datatipInterpolatedPosition (int index, double coefficient, Double[][] polylineData) {
+
+        Double[] datatipNewPos = new Double[3];
+
+        datatipNewPos[0] = polylineData[index][0] + ((polylineData[index + 1][0] - polylineData[index][0]) * coefficient);
+        datatipNewPos[1] = polylineData[index][1] + ((polylineData[index + 1][1] - polylineData[index][1]) * coefficient);
+        datatipNewPos[2] = polylineData[index][2] + ((polylineData[index + 1][2] - polylineData[index][2]) * coefficient);
+
+        return datatipNewPos;
+    }
 }
index 0a60b4e..25471a5 100755 (executable)
@@ -83,7 +83,7 @@ public class DatatipCreate {
 
                 DatatipCommon.Segment seg3d = DatatipCommon.getSegment3dView(coordDoubleXY[0], coordDoubleXY[1], polylineUid);
 
-                Double[] pos = DatatipCommon.Interpolate3dView(coordDoubleXY[0], coordDoubleXY[1], seg3d, polylineUid);
+                Double[] pos = DatatipCommon.Interpolate3dViewProgCoord(coordDoubleXY[0], coordDoubleXY[1], seg3d, polylineUid);
                 double[] position = new double[] {pos[0], pos[1], pos[2]};
 
                 String newDatatip = datatipProperties(position, polylineUid);