Xcos MVC: modify Link's 'xx' and 'yy' properties storage 80/17280/3
Paul Bignier [Fri, 2 Oct 2015 14:26:38 +0000 (16:26 +0200)]
 * When dragging a Link, the Xcos GUI will try to ADD control points to that Link,
so this commit stores them in a [x1 y1 x2 y2 x3 y3] pattern instead of previous [x1 x2 x3 y1 y2 y3],
which made point insertion tedious

Change-Id: I778449078a8c9f99e24b569fe7f206d05aefa3d0

scilab/modules/scicos/src/cpp/view_scilab/LinkAdapter.cpp
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCellFactory.java

index 40d7206..ad825ca 100644 (file)
@@ -60,11 +60,10 @@ struct xx
         int size = (int)controlPoints.size() / 2;
         types::Double* o = new types::Double(size, 1, &data);
 
-#ifdef _MSC_VER
-        std::copy(controlPoints.begin(), controlPoints.begin() + size, stdext::checked_array_iterator<double*>(data, size));
-#else
-        std::copy(controlPoints.begin(), controlPoints.begin() + size, data);
-#endif
+        for (int i = 0; i < size; ++i)
+        {
+            data[i] = controlPoints[2 * i];
+        }
         return o;
     }
 
@@ -89,14 +88,19 @@ struct xx
 
         if (newXSize == oldXSize)
         {
-            std::copy(current->getReal(), current->getReal() + newXSize, newControlPoints.begin());
+            for (int i = 0; i < newXSize; ++i)
+            {
+                newControlPoints[2 * i] = current->getReal()[i];
+            }
         }
         else
         {
             newControlPoints.resize(2 * current->getSize(), 0);
 
-            std::copy(current->getReal(), current->getReal() + newXSize, newControlPoints.begin());
-            std::copy(controlPoints.begin() + oldXSize, controlPoints.begin() + oldXSize + std::min(newXSize, oldXSize), newControlPoints.begin() + newXSize);
+            for (int i = 0; i < newXSize; ++i)
+            {
+                newControlPoints[2 * i] = current->getReal()[i];
+            }
         }
 
         controller.setObjectProperty(adaptee, LINK, CONTROL_POINTS, newControlPoints);
@@ -118,11 +122,10 @@ struct yy
         int size = (int)controlPoints.size() / 2;
         types::Double* o = new types::Double(size, 1, &data);
 
-#ifdef _MSC_VER
-        std::copy(controlPoints.begin() + size, controlPoints.end(), stdext::checked_array_iterator<double*>(data, size));
-#else
-        std::copy(controlPoints.begin() + size, controlPoints.end(), data);
-#endif
+        for (int i = 0; i < size; ++i)
+        {
+            data[i] = controlPoints[2 * i + 1];
+        }
         return o;
     }
 
@@ -147,16 +150,18 @@ struct yy
 
         if (newYSize == oldYSize)
         {
-            std::copy(current->getReal(), current->getReal() + newYSize, newControlPoints.begin() + newYSize);
+            for (int i = 0; i < newYSize; ++i)
+            {
+                newControlPoints[2 * i + 1] = current->getReal()[i];
+            }
         }
         else
         {
             newControlPoints.resize(2 * current->getSize());
 
-            std::copy(current->getReal(), current->getReal() + newYSize, newControlPoints.begin() + newYSize);
-            if (newYSize > oldYSize)
+            for (int i = 0; i < newYSize; ++i)
             {
-                std::fill(newControlPoints.begin() + oldYSize, newControlPoints.begin() + oldYSize + newYSize, 0);
+                newControlPoints[2 * i + 1] = current->getReal()[i];
             }
         }
 
index 35ab5e9..6835c03 100644 (file)
@@ -564,11 +564,11 @@ public final class XcosCellFactory {
          */
         VectorOfDouble controlPoints = new VectorOfDouble();
         controller.getObjectProperty(uid, kind, ObjectProperties.CONTROL_POINTS, controlPoints);
-        final int controlPointsLen = controlPoints.size() / 2;
+        final int pointsLen = controlPoints.size() / 2;
 
-        ArrayList<mxPoint> points = new ArrayList<>(controlPointsLen);
-        for (int i = 0 ; i < controlPointsLen; i++) {
-            points.add(new mxPoint(controlPoints.get(i), controlPoints.get(i + controlPointsLen)));
+        ArrayList<mxPoint> points = new ArrayList<>(pointsLen);
+        for (int i = 0 ; i < pointsLen; i++) {
+            points.add(new mxPoint(controlPoints.get(2 * i), controlPoints.get(2 * i + 1)));
         }
 
         mxGeometry geom = new mxGeometry();