Xcos file format: fix some issues on read-write 78/17578/2
Clément DAVID [Tue, 15 Dec 2015 05:36:03 +0000 (06:36 +0100)]
 * a typo on Port labels
 * Store matrices as vectors on the MVC in a scilab way
 * Store the Scilab timestamp as the default time
 * Only set PARENT_BLOCK if needed

Change-Id: Ifa909881466445c2d473d55872f254a1e7623cf7

scilab/modules/scicos/src/cpp/model/Port.hxx
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/RawDataHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/XcosSAXHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/BlockGraphicElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/spec/XcosPackage.java

index 209d472..b6bc064 100644 (file)
@@ -178,7 +178,7 @@ private:
 
     void getLabel(std::string& l) const
     {
-        l = m_style;
+        l = m_label;
     }
 
     update_status_t setLabel(const std::string& label)
index c7fe04e..5ebafe8 100644 (file)
@@ -442,11 +442,12 @@ class RawDataHandler implements ScilabHandler {
                             // defensive programming against old schema
                             ScilabDouble value = (ScilabDouble) fieldValue.value;
 
-                            vec = new VectorOfDouble(value.getHeight());
-                            for (int i = 0; i < value.getHeight(); i++) {
-                                vec.set(i, value.getRealElement(i, 0));
+                            vec = new VectorOfDouble(value.getHeight() * value.getWidth());
+                            for (int i = 0; i < value.getWidth(); i++) {
+                                for (int j = 0; j < value.getHeight(); j++) {
+                                    vec.set(value.getHeight() * i + j, value.getRealElement(j, i));
+                                }
                             }
-
                             saxHandler.controller.setObjectProperty(cell.getUID(), cell.getKind(), fieldValue.as, vec);
                         }
                         break;
@@ -465,33 +466,38 @@ class RawDataHandler implements ScilabHandler {
                             // defensive programming against old schema
                             ScilabDouble value = (ScilabDouble) fieldValue.value;
 
-                            vec = new VectorOfInt(value.getHeight());
-                            for (int i = 0; i < value.getHeight(); i++) {
-                                vec.set(i, (int) value.getRealElement(i, 0));
+                            vec = new VectorOfInt(value.getHeight() * value.getWidth());
+                            for (int i = 0; i < value.getWidth(); i++) {
+                                for (int j = 0; j < value.getHeight(); j++) {
+                                    vec.set(value.getHeight() * i + j, (int) value.getRealElement(j, i));
+                                }
                             }
                         } else if (fieldValue.value instanceof ScilabInteger) {
                             // defensive programming against old schema
                             ScilabInteger value = (ScilabInteger) fieldValue.value;
 
-                            vec = new VectorOfInt(value.getHeight());
-                            for (int i = 0; i < value.getHeight(); i++) {
-                                switch (value.getPrec()) {
-                                    case sci_int8:
-                                    case sci_uint8:
-                                        vec.set(i, value.getByteElement(i, 0));
-                                        break;
-                                    case sci_int16:
-                                    case sci_uint16:
-                                        vec.set(i, value.getShortElement(i, 0));
-                                        break;
-                                    case sci_int32:
-                                    case sci_uint32:
-                                        vec.set(i, value.getIntElement(i, 0));
-                                        break;
-                                    case sci_int64:
-                                    case sci_uint64:
-                                        vec.set(i, (int) value.getLongElement(i, 0));
-                                        break;
+                            vec = new VectorOfInt(value.getHeight() * value.getWidth());
+                            for (int i = 0; i < value.getWidth(); i++) {
+                                for (int j = 0; j < value.getHeight(); j++) {
+                                    int index = value.getHeight() * i + j;
+                                    switch (value.getPrec()) {
+                                        case sci_int8:
+                                        case sci_uint8:
+                                            vec.set(index, value.getByteElement(j, i));
+                                            break;
+                                        case sci_int16:
+                                        case sci_uint16:
+                                            vec.set(index, value.getShortElement(j, i));
+                                            break;
+                                        case sci_int32:
+                                        case sci_uint32:
+                                            vec.set(index, value.getIntElement(j, i));
+                                            break;
+                                        case sci_int64:
+                                        case sci_uint64:
+                                            vec.set(index, (int) value.getLongElement(j, i));
+                                            break;
+                                    }
                                 }
                             }
                         }
index aedf7ed..85ed32f 100644 (file)
@@ -184,10 +184,10 @@ public class XcosSAXHandler extends DefaultHandler {
         long parentUID;
         Kind parentKind;
 
-        final XcosCell parentBlock = lookupForParentXcosCellElement();
-        if (parentBlock != null) {
-            parentUID = parentBlock.getUID();
-            parentKind = parentBlock.getKind();
+        final XcosCell parentCell = lookupForParentXcosCellElement();
+        if (Kind.BLOCK.equals(parentCell.getKind())) {
+            parentUID = parentCell.getUID();
+            parentKind = parentCell.getKind();
 
             controller.setObjectProperty(cell.getUID(), cell.getKind(), ObjectProperties.PARENT_BLOCK, parentUID);
         } else {
index 74a2685..4d6b3d2 100644 (file)
@@ -37,6 +37,7 @@ import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongTypeExceptio
 import org.scilab.modules.xcos.utils.BlockPositioning;
 
 import com.mxgraph.model.mxCell;
+import com.mxgraph.model.mxGeometry;
 import com.mxgraph.util.mxConstants;
 
 /**
index ffc6645..2b06c8b 100644 (file)
@@ -151,7 +151,7 @@ public class XcosPackage {
         final Element root = manifest.createElementNS("urn:scilab:xcos:xmlns:manifest:0.1", "manifest:manifest");
         manifest.appendChild(root);
 
-        time = 0l;
+        time = ScilabCommons.getScilabVersionTimestamp();
     }
 
     private boolean hasInvalidManifest() {