Xcos ecore: fix implicit, states and solvers
[scilab.git] / scilab / modules / scicos / src / cpp / XMIResource_save.cpp
index 8412bed..ebd1058 100644 (file)
@@ -85,6 +85,18 @@ static std::string to_string(int v)
     return std::to_string(v);
 }
 
+static std::string to_string(bool v)
+{
+    if (v)
+    {
+        return "true";
+    }
+    else
+    {
+        return "false";
+    }
+}
+
 static std::string to_string(double v)
 {
     if (std::trunc(v) == v)
@@ -165,12 +177,47 @@ static int writeBase64(xmlTextWriterPtr writer, const char* name, const std::vec
     return status;
 }
 
+int XMIResource::writeDatatype(xmlTextWriterPtr writer, const std::vector<int>& datatype)
+{
+    int status;
+
+    status = xmlTextWriterStartElement(writer, BAD_CAST("datatype"));
+    if (status == -1)
+    {
+        return status;
+    }
+
+    status = xmlTextWriterWriteAttribute(writer, BAD_CAST("type"), BAD_CAST(to_string(datatype[2]).c_str()));
+    if (status == -1)
+    {
+        return status;
+    }
+
+    status = xmlTextWriterWriteAttribute(writer, BAD_CAST("rows"), BAD_CAST(to_string(datatype[0]).c_str()));
+    if (status == -1)
+    {
+        return status;
+    }
+
+    status = xmlTextWriterWriteAttribute(writer, BAD_CAST("columns"), BAD_CAST(to_string(datatype[1]).c_str()));
+    if (status == -1)
+    {
+        return status;
+    }
+
+    status = xmlTextWriterEndElement(writer);
+    if (status == -1)
+    {
+        return status;
+    }
+
+    return status;
+}
 
 int XMIResource::writePoint(xmlTextWriterPtr writer, double x, double y)
 {
     int status;
 
-
     status = xmlTextWriterStartElement(writer, BAD_CAST("controlPoint"));
     if (status == -1)
     {
@@ -359,7 +406,7 @@ int XMIResource::writeDiagram(xmlTextWriterPtr writer)
     {
         return status;
     }
-    status = xmlTextWriterWriteAttributeNS(writer, BAD_CAST("xsi"), BAD_CAST("schemaLocation"), BAD_CAST("http://www.w3.org/2001/XMLSchema-instance"), BAD_CAST("org.scilab.modules.xcos Xcos.xcore#/EPackage"));
+    status = xmlTextWriterWriteAttributeNS(writer, BAD_CAST("xsi"), BAD_CAST("schemaLocation"), BAD_CAST("http://www.w3.org/2001/XMLSchema-instance"), BAD_CAST("org.scilab.modules.xcos xcos.ecore"));
     if (status == -1)
     {
         return status;
@@ -446,7 +493,7 @@ int XMIResource::writeSimulationConfig(xmlTextWriterPtr writer, ScicosID id)
     {
         return -1;
     }
-    status = xmlTextWriterWriteAttribute(writer, BAD_CAST("absoluteTime"), BAD_CAST(to_string(doubleArrayValue[i]).c_str()));
+    status = xmlTextWriterWriteAttribute(writer, BAD_CAST("absoluteTolerance"), BAD_CAST(to_string(doubleArrayValue[i]).c_str()));
     if (status == -1)
     {
         return status;
@@ -468,7 +515,7 @@ int XMIResource::writeSimulationConfig(xmlTextWriterPtr writer, ScicosID id)
     {
         return -1;
     }
-    status = xmlTextWriterWriteAttribute(writer, BAD_CAST("absoluteTolerance"), BAD_CAST(to_string(doubleArrayValue[i]).c_str()));
+    status = xmlTextWriterWriteAttribute(writer, BAD_CAST("timeTolerance"), BAD_CAST(to_string(doubleArrayValue[i]).c_str()));
     if (status == -1)
     {
         return status;
@@ -888,6 +935,14 @@ int XMIResource::writePort(xmlTextWriterPtr writer, enum object_properties_t con
         return status;
     }
 
+    bool implicit;
+    controller.getObjectProperty(id, PORT, IMPLICIT, implicit);
+    status = xmlTextWriterWriteAttribute(writer, BAD_CAST("implicit"), BAD_CAST(to_string(implicit).c_str()));
+    if (status == -1)
+    {
+        return status;
+    }
+
     controller.getObjectProperty(id, PORT, CONNECTED_SIGNALS, idValue);
     if (idValue != 0)
     {
@@ -917,16 +972,9 @@ int XMIResource::writePort(xmlTextWriterPtr writer, enum object_properties_t con
         return status;
     }
 
-    std::vector<double> doubleArrayValue;
-    controller.getObjectProperty(id, BLOCK, DATATYPE, doubleArrayValue);
-    for (double d : doubleArrayValue)
-    {
-        status = xmlTextWriterWriteElement(writer, BAD_CAST("datatype"), BAD_CAST(to_string(d).c_str()));
-        if (status == -1)
-        {
-            return status;
-        }
-    }
+    std::vector<int> intArrayValue;
+    controller.getObjectProperty(id, PORT, DATATYPE, intArrayValue);
+    status = writeDatatype(writer, intArrayValue);
 
     status = xmlTextWriterEndElement(writer);
     if (status == -1)