Xcos MVC: implement XCOS / ZCOS file saving 03/17403/11
Clément DAVID [Fri, 23 Oct 2015 11:58:11 +0000 (13:58 +0200)]
 * Add a DESCRIPTION property for blocks' value
 * Handle both binary and textual saving
 * testing is performed manually using xcosDiagramToScilab calls

Change-Id: If60686a54e87d6b127886d38592f93f9b0bd3ed3

65 files changed:
scilab/modules/commons/src/java/org/scilab/modules/commons/xml/ScilabXMLOutputFactory.java [new file with mode: 0644]
scilab/modules/scicos/includes/Controller.hxx
scilab/modules/scicos/includes/view_scilab/Adapters.hxx
scilab/modules/scicos/src/cpp/Controller.cpp
scilab/modules/scicos/src/cpp/Model_getObjectProperties.cpp
scilab/modules/scicos/src/cpp/Model_setObjectProperties.cpp
scilab/modules/scicos/src/cpp/model/Block.hxx
scilab/modules/scicos/src/cpp/model/Block.hxx.orig [deleted file]
scilab/modules/scicos/src/cpp/view_scilab/Adapters.cpp
scilab/modules/xcos/includes/gw_xcos.h
scilab/modules/xcos/includes/gw_xcos.hxx
scilab/modules/xcos/sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
scilab/modules/xcos/sci_gateway/xcos_gateway.xml
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Controller.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/JavaControllerJNI.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCell.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCellFactory.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/HandledElement.java [moved from scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/HandledElement.java with 93% similarity]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/HandledElementsCategory.java [moved from scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/HandledElementsCategory.java with 86% similarity]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/ScilabTypeCoder.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/XcosFileType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/package-info.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/BlockHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/CustomHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/JGraphXHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/LinkHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/PortHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/RawDataHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/ScilabHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/XcosSAXHandler.java [moved from scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/SAXHandler.java with 85% similarity]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/BlockModelElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/InputPortElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/LinkElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/OutputPortElement.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/spec/ContentEntry.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/spec/DictionaryEntry.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/spec/XcosPackage.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/BlockWriter.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/CustomWriter.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/JGraphXWriter.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/LinkWriter.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/PortWriter.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/RawDataWriter.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/ScilabWriter.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/XcosWriter.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/BasicLink.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/commandcontrol/CommandControlLink.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/explicit/ExplicitLink.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/link/implicit/ImplicitLink.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/BasicPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/command/CommandPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/control/ControlPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/input/ExplicitInputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/input/InputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/output/OutputPort.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/Stack.java [moved from scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/Stack.java with 95% similarity]
scilab/modules/xcos/src/jni/JavaController.i
scilab/modules/xcos/src/jni/JavaController_wrap.cxx
scilab/modules/xcos/src/jni/Xcos.cpp
scilab/modules/xcos/src/jni/Xcos.giws.xml
scilab/modules/xcos/src/jni/Xcos.hxx
scilab/modules/xcos/tests/unit_tests/empty.xcos [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/xcosDiagramToScilab.dia.ref [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/xcosDiagramToScilab.tst [new file with mode: 0644]

diff --git a/scilab/modules/commons/src/java/org/scilab/modules/commons/xml/ScilabXMLOutputFactory.java b/scilab/modules/commons/src/java/org/scilab/modules/commons/xml/ScilabXMLOutputFactory.java
new file mode 100644 (file)
index 0000000..a8bbc28
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+package org.scilab.modules.commons.xml;
+
+import javax.xml.stream.XMLOutputFactory;
+/**
+ * Class to provide a way to be sure that the default {@link XMLOutputFactory} provided by Java framework will be used.
+ */
+public class ScilabXMLOutputFactory {
+
+    private static final String DEFAULT_FACTORYID = "javax.xml.stream.XMLOutputFactory";
+    private static final String DEFAULT_IMPL = "com.sun.xml.internal.stream.XMLOutputFactoryImpl";
+
+    /**
+     * Use default internal XMLOutputFactoryImpl
+     * @return the key corresponding to the currently used implementation
+     */
+    public static String useDefaultTransformerFactoryImpl() {
+        String factory = System.getProperty(DEFAULT_FACTORYID);
+        System.setProperty(DEFAULT_FACTORYID, DEFAULT_IMPL);
+
+        return factory;
+    }
+
+    /**
+     * Restore the previous factory
+     * @param factory the key as returned by useDefaultXMLOutputFactoryImpl
+     */
+    public static void restoreTransformerFactoryImpl(String factory) {
+        if (factory == null) {
+            System.clearProperty(DEFAULT_FACTORYID);
+        } else {
+            System.setProperty(DEFAULT_FACTORYID, factory);
+        }
+    }
+
+    /**
+     * @return a new instance using the default XMLOutputFactory implementation
+     */
+    public static XMLOutputFactory newInstance() {
+        String factory = useDefaultTransformerFactoryImpl();
+        XMLOutputFactory xof = XMLOutputFactory.newInstance();
+        restoreTransformerFactoryImpl(factory);
+
+        return xof;
+    }
+
+}
index 9ab5e6b..53d35c6 100644 (file)
@@ -55,6 +55,7 @@ public:
 
     kind_t getKind(ScicosID uid) const;
     std::vector<ScicosID> getAll(kind_t k) const;
+    void sortAndFillKind(std::vector<ScicosID>& uids, std::vector<int>& kind);
     model::BaseObject* getObject(ScicosID uid) const;
     template<typename T>
     T* getObject(ScicosID uid) const
index 328f882..47411d9 100644 (file)
@@ -18,6 +18,7 @@
 #include <string>
 
 #include "internal.hxx"
+#include "utilities.hxx"
 #include "model/BaseObject.hxx"
 
 extern "C"
@@ -56,6 +57,7 @@ public:
     adapters_index_t lookup_by_typename(const std::wstring& name);
     std::wstring get_typename(adapters_index_t index);
     const model::BaseObject* descriptor(types::InternalType* v);
+    types::InternalType* allocate_view(ScicosID id, kind_t kind);
 
 private:
 
index d660849..bad20a5 100644 (file)
@@ -462,6 +462,40 @@ std::vector<ScicosID> Controller::getAll(kind_t k) const
     return m_instance.model.getAll(k);
 }
 
+void Controller::sortAndFillKind(std::vector<ScicosID>& uids, std::vector<int>& kinds)
+{
+    // create a container of pair
+    struct local_pair
+    {
+        ScicosID first;
+        int second;
+    };
+    std::vector<local_pair> container(uids.size());
+
+    // fill it
+    for (size_t i = 0; i < uids.size(); ++i)
+    {
+        container[i] = { uids[i], getKind(uids[i]) };
+    }
+
+    // sort according to the kinds
+    std::sort(container.begin(), container.end(), [] (const local_pair & a, const local_pair & b)
+    {
+        return a.second < b.second;
+    });
+
+    // move things back
+    uids.clear();
+    kinds.reserve(uids.capacity());
+    for (const auto& v : container)
+    {
+        uids.push_back(v.first);
+        kinds.push_back(v.second);
+    }
+}
+
+
+
 model::BaseObject* Controller::getObject(ScicosID uid) const
 {
     return m_instance.model.getObject(uid);
index e1bbacc..0053790 100644 (file)
@@ -251,6 +251,9 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
             case STYLE:
                 o->getStyle(v);
                 return true;
+            case DESCRIPTION:
+                o->getDescription(v);
+                return true;
             case LABEL:
                 o->getLabel(v);
                 return true;
index 062892a..1da9f55 100644 (file)
@@ -313,6 +313,8 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
                 return o->setSimBlocktype(v);
             case STYLE:
                 return o->setStyle(v);
+            case DESCRIPTION:
+                return o->setDescription(v);
             case LABEL:
                 return o->setLabel(v);
             case UID:
index f43ae89..57f4878 100644 (file)
@@ -126,7 +126,7 @@ class Block: public BaseObject
 {
 public:
     Block() : BaseObject(BLOCK), m_parentDiagram(ScicosID()), m_interfaceFunction(), m_geometry(), m_angle(),
-        m_label(), m_style(), m_uid(), m_sim(), m_in(), m_out(), m_ein(), m_eout(),
+        m_description(), m_label(), m_style(), m_uid(), m_sim(), m_in(), m_out(), m_ein(), m_eout(),
         m_parameter(), m_state(), m_parentBlock(ScicosID()), m_children(), m_childrenColor(), m_context(), m_portReference(ScicosID())
     {
         // m_exprs default value is an empty matrix encoded by var2vec()
@@ -138,7 +138,7 @@ public:
         m_childrenColor = { -1, 1};
     }
     Block(const Block& o) : BaseObject(BLOCK), m_parentDiagram(o.m_parentDiagram), m_interfaceFunction(o.m_interfaceFunction), m_geometry(o.m_geometry),
-        m_angle(o.m_angle), m_exprs(o.m_exprs), m_label(o.m_label), m_style(o.m_style), m_nzcross(o.m_nzcross), m_nmode(o.m_nmode), m_equations(o.m_equations), m_uid(o.m_uid),
+        m_angle(o.m_angle), m_exprs(o.m_exprs), m_description(o.m_description), m_label(o.m_label), m_style(o.m_style), m_nzcross(o.m_nzcross), m_nmode(o.m_nmode), m_equations(o.m_equations), m_uid(o.m_uid),
         m_sim(o.m_sim), m_in(o.m_in), m_out(o.m_out), m_ein(o.m_ein), m_eout(o.m_eout), m_parameter(o.m_parameter), m_state(o.m_state), m_parentBlock(o.m_parentBlock),
         m_children(o.m_children), m_childrenColor(o.m_childrenColor), m_context(o.m_context), m_portReference(o.m_portReference) {}
     ~Block() = default;
@@ -238,6 +238,22 @@ private:
         return SUCCESS;
     }
 
+    void getDescription(std::string& data) const
+    {
+        data = m_description;
+    }
+
+    update_status_t setDescription(const std::string& data)
+    {
+        if (data == m_description)
+        {
+            return NO_CHANGES;
+        }
+
+        m_description = data;
+        return SUCCESS;
+    }
+
     void getLabel(std::string& data) const
     {
         data = m_label;
@@ -723,6 +739,7 @@ private:
     Geometry m_geometry;
     Angle m_angle;
     std::vector<double> m_exprs;
+    std::string m_description;
     std::string m_label;
     std::string m_style;
     std::vector<int> m_nzcross;
diff --git a/scilab/modules/scicos/src/cpp/model/Block.hxx.orig b/scilab/modules/scicos/src/cpp/model/Block.hxx.orig
deleted file mode 100644 (file)
index 893bd00..0000000
+++ /dev/null
@@ -1,776 +0,0 @@
-/*
- *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2014-2014 - Scilab Enterprises - Clement DAVID
- *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
- *
- */
-
-#ifndef BLOCK_HXX_
-#define BLOCK_HXX_
-
-#include <string>
-#include <vector>
-
-#include "utilities.hxx"
-#include "Model.hxx"
-#include "model/BaseObject.hxx"
-
-namespace org_scilab_modules_scicos
-{
-namespace model
-{
-
-struct Parameter
-{
-    std::vector<double> rpar;
-    std::vector<int> ipar;
-    std::vector<double> opar;
-
-    // opar default value is an empty list encoded by var2vec()
-    Parameter() : rpar(), ipar()
-    {
-        opar = {15, 0};
-    }
-};
-
-struct State
-{
-    std::vector<double> state;
-    std::vector<double> dstate;
-    std::vector<double> odstate;
-
-    // odstate default value is an empty list encoded by var2vec()
-    State() : state(), dstate()
-    {
-        odstate = {15, 0};
-    }
-};
-
-/**
- * Mask list for all possible block scheduling descriptor from the simulator point of view.
- *
- * Examples:
- *  * CONST_m == 0
- *  * SUMMATION == DEP_U
- *  * CLR == DEP_T
- *  * SWITCH_f == DEP_U | DEP_T
- */
-enum dep_ut_t
-{
-    DEP_U       = 1 << 0, //!< y=f(u)
-    DEP_T       = 1 << 1, //!< y=f(x)
-};
-
-enum blocktype_t
-{
-    BLOCKTYPE_C = 'c', //!< N/A ; dummy value used to represent a 'c' blocktype (eg. not 'd')
-    BLOCKTYPE_D = 'd', //!< N/A ; dummy value used to represent a 'd' blocktype (eg. not 'c')
-    BLOCKTYPE_H = 'h', //!< N/A ; used to represent blocks composed by blocks
-    BLOCKTYPE_L = 'l', //!< synchronization block ; ifthenelse and eselect
-    BLOCKTYPE_M = 'm', //!< memorization block ; see the Scicos original paper
-    BLOCKTYPE_X = 'x', //!< derivable block without state ; these blocks will be treated as if they contain a state.
-    BLOCKTYPE_Z = 'z', //!< zero-crossing block ; see the Scicos original paper.
-};
-
-struct Descriptor
-{
-    std::string functionName;
-    int functionApi;
-
-    char dep_ut;            //!< dep_ut_t masked value
-    char blocktype;         //!< one of blocktype_t value
-
-    Descriptor() : functionName(), functionApi(0), dep_ut(0), blocktype(BLOCKTYPE_C) {}
-};
-
-/*
- * Flip and theta
- */
-struct Angle
-{
-    bool flip;
-    bool mirror;
-    double theta;
-
-    Angle() : flip(false), mirror(false), theta(0) {};
-    Angle(const Angle& a) : flip(a.flip), mirror(a.mirror), theta(a.theta) {};
-    Angle(const std::vector<double>& a) :
-        flip(  ((static_cast<int>(a[0]) & 0x0001) == 0) ? false : true),
-        mirror(((static_cast<int>(a[0]) & 0x0002) == 0) ? false : true),
-        theta(a[1])
-    {};
-
-    void fill(std::vector<double>& a) const
-    {
-        a.resize(2);
-
-        int mirrorAndFlip = static_cast<int>(a[0]);
-        (flip == false) ?   mirrorAndFlip &= ~(1 << 0) : mirrorAndFlip |= 1 << 0;
-        (mirror == false) ? mirrorAndFlip &= ~(1 << 1) : mirrorAndFlip |= 1 << 1;
-
-        a[0] = mirrorAndFlip;
-        a[1] = theta;
-    }
-    bool operator==(const Angle& a) const
-    {
-        return flip == a.flip && mirror == a.mirror && theta == a.theta;
-    }
-};
-
-class Block: public BaseObject
-{
-public:
-<<<<<<< HEAD
-    Block() : BaseObject(BLOCK), m_parentDiagram(ScicosID()), m_interfaceFunction(), m_geometry(), m_angle(),
-        m_label(), m_style(), m_equations(), m_uid(), m_sim(), m_in(), m_out(), m_ein(), m_eout(),
-        m_parameter(), m_state(), m_parentBlock(ScicosID()), m_children(), m_portReference(ScicosID())
-    {
-        // m_exprs default value is an empty matrix encoded by var2vec()
-        m_exprs = {1, 2, 0, 0, 0};
-        m_nmode = {0};
-        m_nzcross = {0};
-        m_childrenColor = { -1, 1};
-    }
-    Block(const Block& o) : BaseObject(BLOCK), m_parentDiagram(o.m_parentDiagram), m_interfaceFunction(o.m_interfaceFunction), m_geometry(o.m_geometry),
-        m_angle(o.m_angle), m_exprs(o.m_exprs), m_label(o.m_label), m_style(o.m_style), m_nzcross(o.m_nzcross), m_nmode(o.m_nmode), m_equations(o.m_equations), m_uid(o.m_uid),
-        m_sim(o.m_sim), m_in(o.m_in), m_out(o.m_out), m_ein(o.m_ein), m_eout(o.m_eout), m_parameter(o.m_parameter), m_state(o.m_state), m_parentBlock(o.m_parentBlock),
-        m_children(o.m_children), m_childrenColor(o.m_childrenColor), m_portReference(o.m_portReference) {}
-=======
-    Block() : BaseObject(BLOCK), m_parentDiagram(0), m_interfaceFunction(), m_geometry(), m_angle(),
-        m_exprs(std::vector<double> (5, 0)), m_label(), m_style(), m_nzcross(std::vector<int> (1, 0)), m_nmode(std::vector<int> (1, 0)), m_equations(), m_uid(), m_sim(), m_in(), m_out(), m_ein(), m_eout(),
-        m_parameter(), m_state(), m_parentBlock(0), m_children(), m_context(), m_portReference(0)
-    {
-        // By default, 'm_exprs' takes the value of vec2var([]), which is {12, 2, 0, 0, 0}
-        m_exprs[0] = 12;
-        m_exprs[1] = 2;
-    };
-    Block(const Block& o) : BaseObject(BLOCK), m_parentDiagram(o.m_parentDiagram), m_interfaceFunction(o.m_interfaceFunction), m_geometry(o.m_geometry),
-        m_angle(o.m_angle), m_exprs(o.m_exprs), m_label(o.m_label), m_style(o.m_style), m_nzcross(o.m_nzcross), m_nmode(o.m_nmode), m_equations(o.m_equations), m_uid(o.m_uid),
-        m_sim(o.m_sim), m_in(o.m_in), m_out(o.m_out), m_ein(o.m_ein), m_eout(o.m_eout), m_parameter(o.m_parameter), m_state(o.m_state), m_parentBlock(o.m_parentBlock),
-        m_children(o.m_children), m_context(o.m_context), m_portReference(o.m_portReference) {};
->>>>>>> f7b3897... Xcos MVC: Fixed objects content for compatibility between Scicos and Xcos
-    ~Block() = default;
-
-private:
-    friend class ::org_scilab_modules_scicos::Model;
-
-    void getChildren(std::vector<ScicosID>& v) const
-    {
-        v = this->m_children;
-    }
-
-    update_status_t setChildren(const std::vector<ScicosID>& children)
-    {
-        if (children == this->m_children)
-        {
-            return NO_CHANGES;
-        }
-
-        this->m_children = children;
-        return SUCCESS;
-    }
-
-    void getChildrenColor(std::vector<int>& data) const
-    {
-        data = this->m_childrenColor;
-    }
-
-    update_status_t setChildrenColor(const std::vector<int>& data)
-    {
-        if (data == this->m_childrenColor)
-        {
-            return NO_CHANGES;
-        }
-
-        this->m_childrenColor = data;
-        return SUCCESS;
-    }
-
-    void getGeometry(std::vector<double>& v) const
-    {
-        m_geometry.fill(v);
-    }
-
-    update_status_t setGeometry(const std::vector<double>& v)
-    {
-        if (v.size() != 4)
-        {
-            return FAIL;
-        }
-
-        Geometry g = Geometry(v);
-        if (g == m_geometry)
-        {
-            return NO_CHANGES;
-        }
-
-        m_geometry = g;
-        return SUCCESS;
-    }
-
-    void getAngle(std::vector<double>& data) const
-    {
-        m_angle.fill(data);
-    }
-
-    update_status_t setAngle(const std::vector<double>& data)
-    {
-        if (data.size() != 2)
-        {
-            return FAIL;
-        }
-
-        Angle a = Angle(data);
-        if (a == m_angle)
-        {
-            return NO_CHANGES;
-        }
-
-        m_angle = a;
-        return SUCCESS;
-    }
-
-    void getExprs(std::vector<double>& data) const
-    {
-        data = m_exprs;
-    }
-
-    update_status_t setExprs(const std::vector<double>& data)
-    {
-        if (data == m_exprs)
-        {
-            return NO_CHANGES;
-        }
-
-        m_exprs = data;
-        return SUCCESS;
-    }
-
-    void getLabel(std::string& data) const
-    {
-        data = m_label;
-    }
-
-    update_status_t setLabel(const std::string& data)
-    {
-        if (data == m_label)
-        {
-            return NO_CHANGES;
-        }
-
-        m_label = data;
-        return SUCCESS;
-    }
-
-    void getIn(std::vector<ScicosID>& v) const
-    {
-        v = m_in;
-    }
-
-    update_status_t setIn(const std::vector<ScicosID>& in)
-    {
-        if (in == this->m_in)
-        {
-            return NO_CHANGES;
-        }
-
-        this->m_in = in;
-        return SUCCESS;
-    }
-
-    void getInterfaceFunction(std::string& fun) const
-    {
-        fun = m_interfaceFunction;
-    }
-
-    update_status_t setInterfaceFunction(const std::string& fun)
-    {
-        if (fun == m_interfaceFunction)
-        {
-            return NO_CHANGES;
-        }
-
-        m_interfaceFunction = fun;
-        return SUCCESS;
-    }
-
-    void getOut(std::vector<ScicosID>& v) const
-    {
-        v = m_out;
-    }
-
-    update_status_t setOut(const std::vector<ScicosID>& out)
-    {
-        if (out == this->m_out)
-        {
-            return NO_CHANGES;
-        }
-
-        this->m_out = out;
-        return SUCCESS;
-    }
-
-    void getEin(std::vector<ScicosID>& v) const
-    {
-        v = m_ein;
-    }
-
-    update_status_t setEin(const std::vector<ScicosID>& ein)
-    {
-        if (ein == this->m_ein)
-        {
-            return NO_CHANGES;
-        }
-
-        this->m_ein = ein;
-        return SUCCESS;
-    }
-
-    void getEout(std::vector<ScicosID>& v) const
-    {
-        v = m_eout;
-    }
-
-    update_status_t setEout(const std::vector<ScicosID>& eout)
-    {
-        if (eout == this->m_eout)
-        {
-            return NO_CHANGES;
-        }
-
-        this->m_eout = eout;
-        return SUCCESS;
-    }
-
-    const Parameter& getParameter() const
-    {
-        return m_parameter;
-    }
-
-    void setParameter(const Parameter& parameter)
-    {
-        this->m_parameter = parameter;
-    }
-
-    void getParentBlock(ScicosID& v) const
-    {
-        v = m_parentBlock;
-    }
-
-    update_status_t setParentBlock(ScicosID parentBlock)
-    {
-        if (parentBlock == this->m_parentBlock)
-        {
-            return NO_CHANGES;
-        }
-
-        this->m_parentBlock = parentBlock;
-        return SUCCESS;
-    }
-
-    void getParentDiagram(ScicosID& v) const
-    {
-        v = m_parentDiagram;
-    }
-
-    update_status_t setParentDiagram(const ScicosID v)
-    {
-        if (v == m_parentDiagram)
-        {
-            return NO_CHANGES;
-        }
-
-        m_parentDiagram = v;
-        return SUCCESS;
-    }
-
-    void getPortReference(ScicosID& v) const
-    {
-        v = m_portReference;
-    }
-
-    update_status_t setPortReference(const ScicosID v)
-    {
-        if (v == m_portReference)
-        {
-            return NO_CHANGES;
-        }
-
-        m_portReference = v;
-        return SUCCESS;
-    }
-
-    const Descriptor& getSim() const
-    {
-        return m_sim;
-    }
-
-    void setSim(const Descriptor& sim)
-    {
-        this->m_sim = sim;
-    }
-
-    void getStyle(std::string& data) const
-    {
-        data = m_style;
-    }
-
-    update_status_t setStyle(const std::string& data)
-    {
-        if (data == m_style)
-        {
-            return NO_CHANGES;
-        }
-
-        m_style = data;
-        return SUCCESS;
-    }
-
-    void getNZcross(std::vector<int>& data) const
-    {
-        data = m_nzcross;
-    }
-
-    update_status_t setNZcross(const std::vector<int>& data)
-    {
-        if (data == m_nzcross)
-        {
-            return NO_CHANGES;
-        }
-
-        m_nzcross = data;
-        return SUCCESS;
-    }
-
-    void getNMode(std::vector<int>& data) const
-    {
-        data = m_nmode;
-    }
-
-    update_status_t setNMode(const std::vector<int>& data)
-    {
-        if (data == m_nmode)
-        {
-            return NO_CHANGES;
-        }
-
-        m_nmode = data;
-        return SUCCESS;
-    }
-
-    void getEquations(std::vector<std::string>& data) const
-    {
-        data = m_equations;
-    }
-
-    update_status_t setEquations(const std::vector<std::string>& data)
-    {
-        if (data == m_equations)
-        {
-            return NO_CHANGES;
-        }
-
-        m_equations = data;
-        return SUCCESS;
-    }
-
-    void getUID(std::string& data) const
-    {
-        data = m_uid;
-    }
-
-    update_status_t setUID(const std::string& data)
-    {
-        if (data == m_uid)
-        {
-            return NO_CHANGES;
-        }
-
-        m_uid = data;
-        return SUCCESS;
-    }
-
-    void getRpar(std::vector<double>& data) const
-    {
-        data = m_parameter.rpar;
-    }
-
-    update_status_t setRpar(const std::vector<double>& data)
-    {
-        if (data == m_parameter.rpar)
-        {
-            return NO_CHANGES;
-        }
-
-        m_parameter.rpar = data;
-        return SUCCESS;
-    }
-
-    void getIpar(std::vector<int>& data) const
-    {
-        data = m_parameter.ipar;
-    }
-
-    update_status_t setIpar(const std::vector<int>& data)
-    {
-        if (data == m_parameter.ipar)
-        {
-            return NO_CHANGES;
-        }
-
-        m_parameter.ipar = data;
-        return SUCCESS;
-    }
-
-    void getOpar(std::vector<double>& data) const
-    {
-        data = m_parameter.opar;
-    }
-
-    update_status_t setOpar(const std::vector<double>& data)
-    {
-        if (data == m_parameter.opar)
-        {
-            return NO_CHANGES;
-        }
-
-        m_parameter.opar = data;
-        return SUCCESS;
-    }
-
-    void getSimFunctionName(std::string& data) const
-    {
-        data = m_sim.functionName;
-    }
-
-    update_status_t setSimFunctionName(const std::string& data)
-    {
-        if (data == m_sim.functionName)
-        {
-            return NO_CHANGES;
-        }
-
-        m_sim.functionName = data;
-        return SUCCESS;
-    }
-
-    void getSimFunctionApi(int& data) const
-    {
-        data = m_sim.functionApi;
-    }
-
-    update_status_t setSimFunctionApi(const int data)
-    {
-        if (data == m_sim.functionApi)
-        {
-            return NO_CHANGES;
-        }
-
-        m_sim.functionApi = data;
-        return SUCCESS;
-    }
-
-    void getSimBlocktype(std::string& data) const
-    {
-        data = std::string(1, m_sim.blocktype);
-    }
-
-    update_status_t setSimBlocktype(const std::string data)
-    {
-        if (data.size() != 1)
-        {
-            return FAIL;
-        }
-
-        char c = *(data.c_str());
-
-        if (c == m_sim.blocktype)
-        {
-            return NO_CHANGES;
-        }
-
-        switch (c)
-        {
-            case BLOCKTYPE_C:
-            case BLOCKTYPE_D:
-            case BLOCKTYPE_H:
-            case BLOCKTYPE_L:
-            case BLOCKTYPE_M:
-            case BLOCKTYPE_X:
-            case BLOCKTYPE_Z:
-                m_sim.blocktype = c;
-                return SUCCESS;
-            default:
-                return FAIL;
-        }
-    }
-
-    void getSimDepUT(std::vector<int>& data) const
-    {
-        data.resize(2, 0);
-        switch (m_sim.dep_ut)
-        {
-            case DEP_U & DEP_T:
-                // data is already set to [0 0] here.
-                break;
-            case DEP_U:
-                data[0] = 1;
-                break;
-            case DEP_T:
-                data[1] = 1;
-                break;
-            case DEP_U | DEP_T:
-                data[0] = 1;
-                data[1] = 1;
-                break;
-            default:
-                break;
-        }
-    }
-
-    update_status_t setSimDepUT(const std::vector<int>& data)
-    {
-        if (data.size() != 2)
-        {
-            return FAIL;
-        }
-
-        int dep = DEP_U & DEP_T;
-        if (data[0])
-        {
-            if (data[1])
-            {
-                dep = DEP_U | DEP_T;
-            }
-            else
-            {
-                dep = DEP_U;
-            }
-        }
-        else if (data[1])
-        {
-            dep = DEP_T;
-        }
-
-        if (dep == m_sim.dep_ut)
-        {
-            return NO_CHANGES;
-        }
-
-        m_sim.dep_ut = dep;
-        return SUCCESS;
-    }
-
-    void getState(std::vector<double>& data) const
-    {
-        data = m_state.state;
-    }
-
-    update_status_t setState(const std::vector<double>& data)
-    {
-        if (data == m_state.state)
-        {
-            return NO_CHANGES;
-        }
-
-        m_state.state = data;
-        return SUCCESS;
-    }
-
-    void getDState(std::vector<double>& data) const
-    {
-        data = m_state.dstate;
-    }
-
-    update_status_t setDState(const std::vector<double>& data)
-    {
-        if (data == m_state.dstate)
-        {
-            return NO_CHANGES;
-        }
-
-        m_state.dstate = data;
-        return SUCCESS;
-    }
-
-    void getODState(std::vector<double>& data) const
-    {
-        data = m_state.odstate;
-    }
-
-    update_status_t setODState(const std::vector<double>& data)
-    {
-        if (data == m_state.odstate)
-        {
-            return NO_CHANGES;
-        }
-
-        m_state.odstate = data;
-        return SUCCESS;
-    }
-
-    void getContext(std::vector<std::string>& data) const
-    {
-        data = m_context;
-    }
-
-    update_status_t setContext(const std::vector<std::string>& data)
-    {
-        if (data == m_context)
-        {
-            return NO_CHANGES;
-        }
-
-        m_context = data;
-        return SUCCESS;
-    }
-
-private:
-    ScicosID m_parentDiagram;
-    std::string m_interfaceFunction;
-    Geometry m_geometry;
-    Angle m_angle;
-    std::vector<double> m_exprs;
-    std::string m_label;
-    std::string m_style;
-    std::vector<int> m_nzcross;
-    std::vector<int> m_nmode;
-    std::vector<std::string> m_equations;
-    std::string m_uid;
-
-    Descriptor m_sim;
-
-    std::vector<ScicosID> m_in;
-    std::vector<ScicosID> m_out;
-    std::vector<ScicosID> m_ein;
-    std::vector<ScicosID> m_eout;
-
-    Parameter m_parameter;
-    State m_state;
-
-    /**
-     * SuperBlock: the blocks, links and so on contained into this block
-     */
-    ScicosID m_parentBlock;
-    std::vector<ScicosID> m_children;
-<<<<<<< HEAD
-    std::vector<int> m_childrenColor;
-=======
-    std::vector<std::string> m_context;
->>>>>>> f7b3897... Xcos MVC: Fixed objects content for compatibility between Scicos and Xcos
-
-    /**
-     * I/O Blocks: the corresponding parent port
-     */
-    ScicosID m_portReference;
-};
-
-} /* namespace model */
-} /* namespace org_scilab_modules_scicos */
-
-#endif /* BLOCK_HXX_ */
index f644ce3..8167aea 100644 (file)
@@ -127,5 +127,22 @@ const model::BaseObject* Adapters::descriptor(types::InternalType* v)
     return nullptr;
 }
 
+types::InternalType* Adapters::allocate_view(ScicosID id, kind_t kind)
+{
+    Controller controller;
+
+    switch (kind)
+    {
+        case BLOCK:
+            return new view_scilab::BlockAdapter(controller, static_cast<model::Block*>(controller.getObject(id)));
+        case LINK:
+            return new view_scilab::LinkAdapter(controller, static_cast<model::Link*>(controller.getObject(id)));
+        case DIAGRAM:
+            return new view_scilab::DiagramAdapter(controller, static_cast<model::Diagram*>(controller.getObject(id)));
+        default:
+            return nullptr;
+    }
+}
+
 } /* namespace view_scilab */
 } /* namespace org_scilab_modules_scicos */
index 56ac5cf..87f4d8d 100644 (file)
@@ -20,7 +20,6 @@
 XCOS_IMPEXP int sci_xcosNotify(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_warnBlockByUID(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_closeXcosFromScilab(char *fname, void *pvApiCtx);
-XCOS_IMPEXP int sci_xcosDiagramToScilab(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosDiagramOpen(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosDiagramClose(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosPalLoad(char *fname, void *pvApiCtx);
index 836e4fb..d87904a 100644 (file)
@@ -18,6 +18,7 @@
 
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_Xcos, XCOS_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosCellCreated, XCOS_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosDiagramToScilab, XCOS_IMPEXP);
 
 #endif /* GW_XCOS_HXX_ */
 
index 7cb01f3..dc21a57 100644 (file)
 #include "GiwsException.hxx"
 #include "loadStatus.hxx"
 #include "Controller.hxx"
+#include "view_scilab/Adapters.hxx"
+
+#include "types.hxx"
+#include "function.hxx"
+#include "string.hxx"
+#include "user.hxx"
+#include "int.hxx"
+
+#include "gw_xcos.hxx"
 
 extern "C"
 {
-#include "gw_xcos.h"
-#include "api_scilab.h"
+#include "sci_malloc.h"
 #include "localization.h"
 #include "Scierror.h"
-#include "sci_malloc.h"
-#include "freeArrayOfString.h"
 #include "getScilabJavaVM.h"
 }
 /*--------------------------------------------------------------------------*/
 using namespace org_scilab_modules_xcos;
-
+using namespace org_scilab_modules_scicos;
+/*--------------------------------------------------------------------------*/
+static char funname[] = "xcosDiagramToScilab";
+types::InternalType* importFile(char const* file);
+bool exportFile(int index, char const* file, types::InternalType* uid);
 /*--------------------------------------------------------------------------*/
-int sci_xcosDiagramToScilab(char *fname, void *pvApiCtx)
+types::Function::ReturnValue sci_xcosDiagramToScilab(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    CheckRhs(1, 1);
-    CheckLhs(0, 1);
-
-    SciErr sciErr;
-
-    int iRows1 = 0;
-    int iCols1 = 0;
-    int iLen1 = 0;
-    int *piAddr1 = NULL;
-    char *pstXcosFile = NULL;
+    /*
+     * to import some files
+     * scs_m = xcosDiagramToScilab("/path/to/a/file")
+     * [scs_m1, scs_m2] = xcosDiagramToScilab(["/path/to/a/file", "/path/to/files"])
+     *
+     * to export a file
+     * xcosDiagramToScilab("/path/to/a/file", scs_m)
+     * xcosDiagramToScilab(["/path/to/a/file", "/path/to/files"], scs_m1, scs_m2)
+     */
 
-    //get xcos filename
-    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
-    if (sciErr.iErr)
+    if (in.size() < 1)
     {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-        return 0;
+        Scierror(77, _("%s: Wrong number of input arguments: at least %d expected.\n"), funname, 1);
+        return types::Function::Error;
     }
 
-    //get xcos filename matrix dimension
-    sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows1, &iCols1, NULL, NULL);
-    if (sciErr.iErr)
+    if (!in[0]->isString())
     {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-        return 0;
+        Scierror(77, _("%s: Wrong type for input argument #%d: string expected.\n"), funname, 1);
     }
 
-    if (iRows1 != 1 || iCols1 != 1)
+    types::String* files = in[0]->getAs<types::String>();
+    if (in.size() == 1 && files->getSize() == _iRetCount)
     {
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+        // the user asked to import
+        out.resize(_iRetCount);
+        for (int i = 0; i < _iRetCount; i++)
+        {
+            char* f = wide_string_to_UTF8(files->get(i));
+            out[i] = importFile(f);
+            FREE(f);
+            if (out[i] == nullptr)
+            {
+                return types::Function::Error;
+            }
+        }
     }
-
-    //get xcos filename length
-    sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows1, &iCols1, &iLen1, NULL);
-    if (sciErr.iErr)
+    else if (in.size() == 1 + files->getSize() && _iRetCount <= 1)
     {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-        return 0;
+        // the user asked to export
+        for (int i = 0; i < _iRetCount; i++)
+        {
+            if (!in[1 + i]->isUserType())
+            {
+                Scierror(77, _("%s: Wrong type for input argument #%d: ""%s"" expected.\n"), funname, "diagram");
+            }
+        }
+        for (int i = 0; i < _iRetCount; i++)
+        {
+            char* f = wide_string_to_UTF8(files->get(i));
+            bool success = exportFile(1 + i, f, in[1 + i]);
+            FREE(f);
+            if (!success)
+            {
+                return types::Function::Error;
+            }
+        }
     }
-
-    pstXcosFile = (char*) MALLOC(sizeof(char) * (iLen1 + 1)); //+ 1 for null termination
-    //get xcos filename
-    sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows1, &iCols1, &iLen1, &pstXcosFile);
-    if (sciErr.iErr)
+    else
     {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-        return 0;
+        // report a comprehensible error message
+        if (in.size() == 1)
+        {
+            Scierror(77, _("%s: Wrong number of output arguments: %d expected.\n"), funname, files->getSize());
+        }
+        else if (in.size() == 1 + files->getSize())
+        {
+            Scierror(77, _("%s: Wrong number of output arguments: %d expected.\n"), funname, 0);
+        }
+        else
+        {
+            Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), funname, 1);
+        }
+        return types::Function::Error;
     }
 
-    /*
-     * Call the Java implementation on an existing diagram UID
-     */
+    return types::Function::OK;
+}
+/*--------------------------------------------------------------------------*/
+types::InternalType* importFile(char const* file)
+{
+    // create a diagram
     org_scilab_modules_scicos::Controller controller;
     ScicosID uid = controller.createObject(DIAGRAM);
 
+    // load it
     set_loaded_status(XCOS_CALLED);
     try
     {
-        Xcos::xcosDiagramToScilab(getScilabJavaVM(), pstXcosFile, uid);
+        Xcos::xcosDiagramToScilab(getScilabJavaVM(), file, uid, false);
     }
     catch (GiwsException::JniCallMethodException &exception)
     {
-        Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
+        Scierror(999, "%s: %s\n", funname, exception.getJavaDescription().c_str());
         controller.deleteObject(uid);
-        return 0;
+        return nullptr;
     }
     catch (GiwsException::JniException &exception)
     {
-        Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
+        Scierror(999, "%s: %s\n", funname, exception.whatStr().c_str());
         controller.deleteObject(uid);
-        return 0;
+        return nullptr;
     }
 
-    sciErr = createMatrixOfInteger64(pvApiCtx, Rhs + 1, 1, 1, &uid);
-    if (sciErr.iErr)
+    return view_scilab::Adapters::instance().allocate_view(uid, DIAGRAM);
+}
+/*--------------------------------------------------------------------------*/
+bool exportFile(int index, char const* file, types::InternalType* type)
+{
+    // check that the passed argument is a diagram
+    const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(type);
+    if (o == nullptr || o->kind() != DIAGRAM)
     {
-        printError(&sciErr, 0);
-        Scierror(999, _("%s: Memory allocation error.\n"), fname);
-        return 0;
+        Scierror(77, _("%s: Wrong type for input argument #%d: ""%s"" expected.\n"), funname, index, "diagram");
+        return false;
     }
 
-    LhsVar(1) = Rhs + 1;
-    PutLhsVar();
-    return 0;
-}
+    // export it
+    set_loaded_status(XCOS_CALLED);
+    try
+    {
+        Xcos::xcosDiagramToScilab(getScilabJavaVM(), file, o->id(), true);
+    }
+    catch (GiwsException::JniCallMethodException &exception)
+    {
+        Scierror(999, "%s: %s\n", funname, exception.getJavaDescription().c_str());
+        return false;
+    }
+    catch (GiwsException::JniException &exception)
+    {
+        Scierror(999, "%s: %s\n", funname, exception.whatStr().c_str());
+        return false;
+    }
 
+    return true;
+}
 /*--------------------------------------------------------------------------*/
index 31b766b..31eccbd 100644 (file)
@@ -33,9 +33,9 @@
     <gateway name="sci_loadXcos"                function="loadXcos"                 type="0" />
     <gateway name="sci_xcosSimulationStarted"   function="xcosSimulationStarted"    type="0" />
     <gateway name="sci_xcosPalGet"              function="xcosPalGet"               type="0" />
-    <gateway name="sci_xcosDiagramToScilab"     function="xcosDiagramToScilab"      type="0" />
     <!-- Scilab 6 Gateways (C++) -->
     <gateway name="sci_Xcos"                    function="xcos"                     type="1" />
     <gateway name="sci_xcosCellCreated"         function="xcosCellCreated"          type="1" />
+    <gateway name="sci_xcosDiagramToScilab"     function="xcosDiagramToScilab"      type="1" />
 </module>
 
index f3a7b8b..7a9e998 100644 (file)
 package org.scilab.modules.xcos;
 
 public class Controller {
-  private transient long swigCPtr;
-  protected transient boolean swigCMemOwn;
+    private transient long swigCPtr;
+    protected transient boolean swigCMemOwn;
 
-  protected Controller(long cPtr, boolean cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = cPtr;
-  }
-
-  protected static long getCPtr(Controller obj) {
-    return (obj == null) ? 0 : obj.swigCPtr;
-  }
-
-  protected void finalize() {
-    delete();
-  }
-
-  public synchronized void delete() {
-    if (swigCPtr != 0) {
-      if (swigCMemOwn) {
-        swigCMemOwn = false;
-        JavaControllerJNI.delete_Controller(swigCPtr);
-      }
-      swigCPtr = 0;
-    }
-  }
-
-  public static View look_for_view(String name) {
-    long cPtr = JavaControllerJNI.Controller_look_for_view(name);
-    return (cPtr == 0) ? null : new View(cPtr, false);
-  }
+    protected Controller(long cPtr, boolean cMemoryOwn) {
+        swigCMemOwn = cMemoryOwn;
+        swigCPtr = cPtr;
+    }
+
+    protected static long getCPtr(Controller obj) {
+        return (obj == null) ? 0 : obj.swigCPtr;
+    }
+
+    protected void finalize() {
+        delete();
+    }
+
+    public synchronized void delete() {
+        if (swigCPtr != 0) {
+            if (swigCMemOwn) {
+                swigCMemOwn = false;
+                JavaControllerJNI.delete_Controller(swigCPtr);
+            }
+            swigCPtr = 0;
+        }
+    }
+
+    public static View look_for_view(String name) {
+        long cPtr = JavaControllerJNI.Controller_look_for_view(name);
+        return (cPtr == 0) ? null : new View(cPtr, false);
+    }
+
+    public Controller() {
+        this(JavaControllerJNI.new_Controller(), true);
+    }
+
+    public long createObject(Kind k) {
+        return JavaControllerJNI.Controller_createObject(swigCPtr, this, k.ordinal());
+    }
+
+    public long referenceObject(long uid) {
+        return JavaControllerJNI.Controller_referenceObject(swigCPtr, this, uid);
+    }
+
+    public void deleteObject(long uid) {
+        JavaControllerJNI.Controller_deleteObject(swigCPtr, this, uid);
+    }
+
+    public long cloneObject(long uid, boolean cloneChildren, boolean clonePorts) {
+        return JavaControllerJNI.Controller_cloneObject(swigCPtr, this, uid, cloneChildren, clonePorts);
+    }
+
+    public Kind getKind(long uid) {
+        return Kind.class.getEnumConstants()[JavaControllerJNI.Controller_getKind(swigCPtr, this, uid)];
+    }
+
+    public VectorOfScicosID getAll(Kind k) {
+        return new VectorOfScicosID(JavaControllerJNI.Controller_getAll(swigCPtr, this, k.ordinal()), true);
+    }
+
+    public void sortAndFillKind(VectorOfScicosID uids, VectorOfInt kind) {
+        JavaControllerJNI.Controller_sortAndFillKind(swigCPtr, this, VectorOfScicosID.getCPtr(uids), uids, VectorOfInt.getCPtr(kind), kind);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, int[] v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_1(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, boolean[] v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_2(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, double[] v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_3(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, String[] v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_4(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, long[] v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_5(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfInt v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_6(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfInt.getCPtr(v), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfBool v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_7(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfBool.getCPtr(v), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfDouble v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_8(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfDouble.getCPtr(v), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfString v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_9(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfString.getCPtr(v), v);
+    }
+
+    public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfScicosID v) {
+        return JavaControllerJNI.Controller_getObjectProperty__SWIG_10(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfScicosID.getCPtr(v), v);
+    }
 
-  public Controller() {
-    this(JavaControllerJNI.new_Controller(), true);
-  }
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, int v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_1(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
+    }
+
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, boolean v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_2(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
+    }
+
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, double v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_3(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
+    }
 
-  public long createObject(Kind k) {
-    return JavaControllerJNI.Controller_createObject(swigCPtr, this, k.ordinal());
-  }
-
-  public long referenceObject(long uid) {
-    return JavaControllerJNI.Controller_referenceObject(swigCPtr, this, uid);
-  }
-
-  public void deleteObject(long uid) {
-    JavaControllerJNI.Controller_deleteObject(swigCPtr, this, uid);
-  }
-
-  public long cloneObject(long uid, boolean cloneChildren, boolean clonePorts) {
-    return JavaControllerJNI.Controller_cloneObject(swigCPtr, this, uid, cloneChildren, clonePorts);
-  }
-
-  public Kind getKind(long uid) {
-    return Kind.class.getEnumConstants()[JavaControllerJNI.Controller_getKind(swigCPtr, this, uid)];
-  }
-
-  public VectorOfScicosID getAll(Kind k) {
-    return new VectorOfScicosID(JavaControllerJNI.Controller_getAll(swigCPtr, this, k.ordinal()), true);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, int[] v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_1(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, boolean[] v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_2(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, double[] v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_3(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, String[] v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_4(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, long[] v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_5(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfInt v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_6(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfInt.getCPtr(v), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfBool v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_7(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfBool.getCPtr(v), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfDouble v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_8(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfDouble.getCPtr(v), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfString v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_9(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfString.getCPtr(v), v);
-  }
-
-  public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfScicosID v) {
-    return JavaControllerJNI.Controller_getObjectProperty__SWIG_10(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfScicosID.getCPtr(v), v);
-  }
-
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, int v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_1(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
-  }
-
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, boolean v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_2(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
-  }
-
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, double v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_3(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
-  }
-
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, String v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_4(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
-  }
-
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, long v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_5(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
-  }
-
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfInt v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_6(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfInt.getCPtr(v), v)];
-  }
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, String v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_4(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
+    }
 
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfBool v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_7(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfBool.getCPtr(v), v)];
-  }
-
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfDouble v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_8(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfDouble.getCPtr(v), v)];
-  }
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, long v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_5(swigCPtr, this, uid, k.ordinal(), p.ordinal(), v)];
+    }
 
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfString v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_9(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfString.getCPtr(v), v)];
-  }
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfInt v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_6(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfInt.getCPtr(v), v)];
+    }
 
-  public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfScicosID v) {
-    return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_10(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfScicosID.getCPtr(v), v)];
-  }
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfBool v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_7(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfBool.getCPtr(v), v)];
+    }
+
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfDouble v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_8(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfDouble.getCPtr(v), v)];
+    }
+
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfString v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_9(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfString.getCPtr(v), v)];
+    }
+
+    public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfScicosID v) {
+        return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_10(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfScicosID.getCPtr(v), v)];
+    }
 
 }
index 6f9315e..229340d 100644 (file)
 package org.scilab.modules.xcos;
 
 public class JavaControllerJNI {
-  public final static native long new_View();
-  public final static native void delete_View(long jarg1);
-  public final static native void View_objectCreated(long jarg1, View jarg1_, long jarg2, int jarg3);
-  public final static native void View_objectReferenced(long jarg1, View jarg1_, long jarg2, int jarg3, long jarg4);
-  public final static native void View_objectUnreferenced(long jarg1, View jarg1_, long jarg2, int jarg3, long jarg4);
-  public final static native void View_objectDeleted(long jarg1, View jarg1_, long jarg2, int jarg3);
-  public final static native void View_propertyUpdated(long jarg1, View jarg1_, long jarg2, int jarg3, int jarg4, int jarg5);
-  public final static native void View_director_connect(View obj, long cptr, boolean mem_own, boolean weak_global);
-  public final static native void View_change_ownership(View obj, long cptr, boolean take_or_release);
-  public final static native long Controller_look_for_view(String jarg1);
-  public final static native long new_Controller();
-  public final static native void delete_Controller(long jarg1);
-  public final static native long Controller_createObject(long jarg1, Controller jarg1_, int jarg2);
-  public final static native long Controller_referenceObject(long jarg1, Controller jarg1_, long jarg2);
-  public final static native void Controller_deleteObject(long jarg1, Controller jarg1_, long jarg2);
-  public final static native long Controller_cloneObject(long jarg1, Controller jarg1_, long jarg2, boolean jarg3, boolean jarg4);
-  public final static native int Controller_getKind(long jarg1, Controller jarg1_, long jarg2);
-  public final static native long Controller_getAll(long jarg1, Controller jarg1_, int jarg2);
-  public final static native boolean Controller_getObjectProperty__SWIG_1(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, int[] jarg5);
-  public final static native boolean Controller_getObjectProperty__SWIG_2(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, boolean[] jarg5);
-  public final static native boolean Controller_getObjectProperty__SWIG_3(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, double[] jarg5);
-  public final static native boolean Controller_getObjectProperty__SWIG_4(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, String[] jarg5);
-  public final static native boolean Controller_getObjectProperty__SWIG_5(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long[] jarg5);
-  public final static native boolean Controller_getObjectProperty__SWIG_6(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfInt jarg5_);
-  public final static native boolean Controller_getObjectProperty__SWIG_7(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfBool jarg5_);
-  public final static native boolean Controller_getObjectProperty__SWIG_8(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfDouble jarg5_);
-  public final static native boolean Controller_getObjectProperty__SWIG_9(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfString jarg5_);
-  public final static native boolean Controller_getObjectProperty__SWIG_10(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfScicosID jarg5_);
-  public final static native int Controller_setObjectProperty__SWIG_1(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, int jarg5);
-  public final static native int Controller_setObjectProperty__SWIG_2(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, boolean jarg5);
-  public final static native int Controller_setObjectProperty__SWIG_3(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, double jarg5);
-  public final static native int Controller_setObjectProperty__SWIG_4(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, String jarg5);
-  public final static native int Controller_setObjectProperty__SWIG_5(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5);
-  public final static native int Controller_setObjectProperty__SWIG_6(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfInt jarg5_);
-  public final static native int Controller_setObjectProperty__SWIG_7(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfBool jarg5_);
-  public final static native int Controller_setObjectProperty__SWIG_8(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfDouble jarg5_);
-  public final static native int Controller_setObjectProperty__SWIG_9(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfString jarg5_);
-  public final static native int Controller_setObjectProperty__SWIG_10(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfScicosID jarg5_);
-  public final static native long new_VectorOfInt__SWIG_0();
-  public final static native long new_VectorOfInt__SWIG_1(long jarg1);
-  public final static native void VectorOfInt_ensureCapacity(long jarg1, VectorOfInt jarg1_, long jarg2);
-  public final static native void VectorOfInt_resize(long jarg1, VectorOfInt jarg1_, long jarg2);
-  public final static native int VectorOfInt_size(long jarg1, VectorOfInt jarg1_);
-  public final static native boolean VectorOfInt_isEmpty(long jarg1, VectorOfInt jarg1_);
-  public final static native void VectorOfInt_clear(long jarg1, VectorOfInt jarg1_);
-  public final static native void VectorOfInt_add__SWIG_0(long jarg1, VectorOfInt jarg1_, int jarg2);
-  public final static native boolean VectorOfInt_contains(long jarg1, VectorOfInt jarg1_, int jarg2);
-  public final static native int VectorOfInt_indexOf(long jarg1, VectorOfInt jarg1_, int jarg2);
-  public final static native int VectorOfInt_get(long jarg1, VectorOfInt jarg1_, int jarg2);
-  public final static native void VectorOfInt_set(long jarg1, VectorOfInt jarg1_, int jarg2, int jarg3);
-  public final static native void VectorOfInt_add__SWIG_1(long jarg1, VectorOfInt jarg1_, int jarg2, int jarg3);
-  public final static native boolean VectorOfInt_remove(long jarg1, VectorOfInt jarg1_, int jarg2);
-  public final static native java.nio.ByteBuffer VectorOfInt_asByteBuffer(long jarg1, VectorOfInt jarg1_, int jarg2, int jarg3);
-  public final static native void delete_VectorOfInt(long jarg1);
-  public final static native long new_VectorOfBool__SWIG_0();
-  public final static native long new_VectorOfBool__SWIG_1(long jarg1);
-  public final static native void VectorOfBool_ensureCapacity(long jarg1, VectorOfBool jarg1_, long jarg2);
-  public final static native void VectorOfBool_resize(long jarg1, VectorOfBool jarg1_, long jarg2);
-  public final static native int VectorOfBool_size(long jarg1, VectorOfBool jarg1_);
-  public final static native boolean VectorOfBool_isEmpty(long jarg1, VectorOfBool jarg1_);
-  public final static native void VectorOfBool_clear(long jarg1, VectorOfBool jarg1_);
-  public final static native void VectorOfBool_add__SWIG_0(long jarg1, VectorOfBool jarg1_, boolean jarg2);
-  public final static native boolean VectorOfBool_get(long jarg1, VectorOfBool jarg1_, int jarg2);
-  public final static native void VectorOfBool_set(long jarg1, VectorOfBool jarg1_, int jarg2, boolean jarg3);
-  public final static native void VectorOfBool_add__SWIG_1(long jarg1, VectorOfBool jarg1_, int jarg2, boolean jarg3);
-  public final static native boolean VectorOfBool_remove(long jarg1, VectorOfBool jarg1_, boolean jarg2);
-  public final static native void delete_VectorOfBool(long jarg1);
-  public final static native long new_VectorOfDouble__SWIG_0();
-  public final static native long new_VectorOfDouble__SWIG_1(long jarg1);
-  public final static native void VectorOfDouble_ensureCapacity(long jarg1, VectorOfDouble jarg1_, long jarg2);
-  public final static native void VectorOfDouble_resize(long jarg1, VectorOfDouble jarg1_, long jarg2);
-  public final static native int VectorOfDouble_size(long jarg1, VectorOfDouble jarg1_);
-  public final static native boolean VectorOfDouble_isEmpty(long jarg1, VectorOfDouble jarg1_);
-  public final static native void VectorOfDouble_clear(long jarg1, VectorOfDouble jarg1_);
-  public final static native void VectorOfDouble_add__SWIG_0(long jarg1, VectorOfDouble jarg1_, double jarg2);
-  public final static native boolean VectorOfDouble_contains(long jarg1, VectorOfDouble jarg1_, double jarg2);
-  public final static native int VectorOfDouble_indexOf(long jarg1, VectorOfDouble jarg1_, double jarg2);
-  public final static native double VectorOfDouble_get(long jarg1, VectorOfDouble jarg1_, int jarg2);
-  public final static native void VectorOfDouble_set(long jarg1, VectorOfDouble jarg1_, int jarg2, double jarg3);
-  public final static native void VectorOfDouble_add__SWIG_1(long jarg1, VectorOfDouble jarg1_, int jarg2, double jarg3);
-  public final static native boolean VectorOfDouble_remove(long jarg1, VectorOfDouble jarg1_, double jarg2);
-  public final static native java.nio.ByteBuffer VectorOfDouble_asByteBuffer(long jarg1, VectorOfDouble jarg1_, int jarg2, int jarg3);
-  public final static native void delete_VectorOfDouble(long jarg1);
-  public final static native long new_VectorOfString__SWIG_0();
-  public final static native long new_VectorOfString__SWIG_1(long jarg1);
-  public final static native void VectorOfString_ensureCapacity(long jarg1, VectorOfString jarg1_, long jarg2);
-  public final static native void VectorOfString_resize(long jarg1, VectorOfString jarg1_, long jarg2);
-  public final static native int VectorOfString_size(long jarg1, VectorOfString jarg1_);
-  public final static native boolean VectorOfString_isEmpty(long jarg1, VectorOfString jarg1_);
-  public final static native void VectorOfString_clear(long jarg1, VectorOfString jarg1_);
-  public final static native void VectorOfString_add__SWIG_0(long jarg1, VectorOfString jarg1_, String jarg2);
-  public final static native boolean VectorOfString_contains(long jarg1, VectorOfString jarg1_, String jarg2);
-  public final static native int VectorOfString_indexOf(long jarg1, VectorOfString jarg1_, String jarg2);
-  public final static native String VectorOfString_get(long jarg1, VectorOfString jarg1_, int jarg2);
-  public final static native void VectorOfString_set(long jarg1, VectorOfString jarg1_, int jarg2, String jarg3);
-  public final static native void VectorOfString_add__SWIG_1(long jarg1, VectorOfString jarg1_, int jarg2, String jarg3);
-  public final static native boolean VectorOfString_remove(long jarg1, VectorOfString jarg1_, String jarg2);
-  public final static native java.nio.ByteBuffer VectorOfString_asByteBuffer(long jarg1, VectorOfString jarg1_, int jarg2, int jarg3);
-  public final static native void delete_VectorOfString(long jarg1);
-  public final static native long new_VectorOfScicosID__SWIG_0();
-  public final static native long new_VectorOfScicosID__SWIG_1(long jarg1);
-  public final static native void VectorOfScicosID_ensureCapacity(long jarg1, VectorOfScicosID jarg1_, long jarg2);
-  public final static native void VectorOfScicosID_resize(long jarg1, VectorOfScicosID jarg1_, long jarg2);
-  public final static native int VectorOfScicosID_size(long jarg1, VectorOfScicosID jarg1_);
-  public final static native boolean VectorOfScicosID_isEmpty(long jarg1, VectorOfScicosID jarg1_);
-  public final static native void VectorOfScicosID_clear(long jarg1, VectorOfScicosID jarg1_);
-  public final static native void VectorOfScicosID_add__SWIG_0(long jarg1, VectorOfScicosID jarg1_, long jarg2);
-  public final static native boolean VectorOfScicosID_contains(long jarg1, VectorOfScicosID jarg1_, long jarg2);
-  public final static native int VectorOfScicosID_indexOf(long jarg1, VectorOfScicosID jarg1_, long jarg2);
-  public final static native long VectorOfScicosID_get(long jarg1, VectorOfScicosID jarg1_, int jarg2);
-  public final static native void VectorOfScicosID_set(long jarg1, VectorOfScicosID jarg1_, int jarg2, long jarg3);
-  public final static native void VectorOfScicosID_add__SWIG_1(long jarg1, VectorOfScicosID jarg1_, int jarg2, long jarg3);
-  public final static native boolean VectorOfScicosID_remove(long jarg1, VectorOfScicosID jarg1_, long jarg2);
-  public final static native java.nio.ByteBuffer VectorOfScicosID_asByteBuffer(long jarg1, VectorOfScicosID jarg1_, int jarg2, int jarg3);
-  public final static native void delete_VectorOfScicosID(long jarg1);
-  public final static native void register_view(String jarg1, long jarg2, View jarg2_);
-  public final static native void unregister_view(long jarg1, View jarg1_);
+    public final static native long new_View();
+    public final static native void delete_View(long jarg1);
+    public final static native void View_objectCreated(long jarg1, View jarg1_, long jarg2, int jarg3);
+    public final static native void View_objectReferenced(long jarg1, View jarg1_, long jarg2, int jarg3, long jarg4);
+    public final static native void View_objectUnreferenced(long jarg1, View jarg1_, long jarg2, int jarg3, long jarg4);
+    public final static native void View_objectDeleted(long jarg1, View jarg1_, long jarg2, int jarg3);
+    public final static native void View_propertyUpdated(long jarg1, View jarg1_, long jarg2, int jarg3, int jarg4, int jarg5);
+    public final static native void View_director_connect(View obj, long cptr, boolean mem_own, boolean weak_global);
+    public final static native void View_change_ownership(View obj, long cptr, boolean take_or_release);
+    public final static native long Controller_look_for_view(String jarg1);
+    public final static native long new_Controller();
+    public final static native void delete_Controller(long jarg1);
+    public final static native long Controller_createObject(long jarg1, Controller jarg1_, int jarg2);
+    public final static native long Controller_referenceObject(long jarg1, Controller jarg1_, long jarg2);
+    public final static native void Controller_deleteObject(long jarg1, Controller jarg1_, long jarg2);
+    public final static native long Controller_cloneObject(long jarg1, Controller jarg1_, long jarg2, boolean jarg3, boolean jarg4);
+    public final static native int Controller_getKind(long jarg1, Controller jarg1_, long jarg2);
+    public final static native long Controller_getAll(long jarg1, Controller jarg1_, int jarg2);
+    public final static native void Controller_sortAndFillKind(long jarg1, Controller jarg1_, long jarg2, VectorOfScicosID jarg2_, long jarg3, VectorOfInt jarg3_);
+    public final static native boolean Controller_getObjectProperty__SWIG_1(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, int[] jarg5);
+    public final static native boolean Controller_getObjectProperty__SWIG_2(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, boolean[] jarg5);
+    public final static native boolean Controller_getObjectProperty__SWIG_3(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, double[] jarg5);
+    public final static native boolean Controller_getObjectProperty__SWIG_4(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, String[] jarg5);
+    public final static native boolean Controller_getObjectProperty__SWIG_5(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long[] jarg5);
+    public final static native boolean Controller_getObjectProperty__SWIG_6(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfInt jarg5_);
+    public final static native boolean Controller_getObjectProperty__SWIG_7(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfBool jarg5_);
+    public final static native boolean Controller_getObjectProperty__SWIG_8(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfDouble jarg5_);
+    public final static native boolean Controller_getObjectProperty__SWIG_9(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfString jarg5_);
+    public final static native boolean Controller_getObjectProperty__SWIG_10(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfScicosID jarg5_);
+    public final static native int Controller_setObjectProperty__SWIG_1(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, int jarg5);
+    public final static native int Controller_setObjectProperty__SWIG_2(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, boolean jarg5);
+    public final static native int Controller_setObjectProperty__SWIG_3(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, double jarg5);
+    public final static native int Controller_setObjectProperty__SWIG_4(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, String jarg5);
+    public final static native int Controller_setObjectProperty__SWIG_5(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5);
+    public final static native int Controller_setObjectProperty__SWIG_6(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfInt jarg5_);
+    public final static native int Controller_setObjectProperty__SWIG_7(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfBool jarg5_);
+    public final static native int Controller_setObjectProperty__SWIG_8(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfDouble jarg5_);
+    public final static native int Controller_setObjectProperty__SWIG_9(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfString jarg5_);
+    public final static native int Controller_setObjectProperty__SWIG_10(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfScicosID jarg5_);
+    public final static native long new_VectorOfInt__SWIG_0();
+    public final static native long new_VectorOfInt__SWIG_1(long jarg1);
+    public final static native void VectorOfInt_ensureCapacity(long jarg1, VectorOfInt jarg1_, long jarg2);
+    public final static native void VectorOfInt_resize(long jarg1, VectorOfInt jarg1_, long jarg2);
+    public final static native int VectorOfInt_size(long jarg1, VectorOfInt jarg1_);
+    public final static native boolean VectorOfInt_isEmpty(long jarg1, VectorOfInt jarg1_);
+    public final static native void VectorOfInt_clear(long jarg1, VectorOfInt jarg1_);
+    public final static native void VectorOfInt_add__SWIG_0(long jarg1, VectorOfInt jarg1_, int jarg2);
+    public final static native boolean VectorOfInt_contains(long jarg1, VectorOfInt jarg1_, int jarg2);
+    public final static native int VectorOfInt_indexOf(long jarg1, VectorOfInt jarg1_, int jarg2);
+    public final static native int VectorOfInt_get(long jarg1, VectorOfInt jarg1_, int jarg2);
+    public final static native void VectorOfInt_set(long jarg1, VectorOfInt jarg1_, int jarg2, int jarg3);
+    public final static native void VectorOfInt_add__SWIG_1(long jarg1, VectorOfInt jarg1_, int jarg2, int jarg3);
+    public final static native boolean VectorOfInt_remove(long jarg1, VectorOfInt jarg1_, int jarg2);
+    public final static native java.nio.ByteBuffer VectorOfInt_asByteBuffer(long jarg1, VectorOfInt jarg1_, int jarg2, int jarg3);
+    public final static native void delete_VectorOfInt(long jarg1);
+    public final static native long new_VectorOfBool__SWIG_0();
+    public final static native long new_VectorOfBool__SWIG_1(long jarg1);
+    public final static native void VectorOfBool_ensureCapacity(long jarg1, VectorOfBool jarg1_, long jarg2);
+    public final static native void VectorOfBool_resize(long jarg1, VectorOfBool jarg1_, long jarg2);
+    public final static native int VectorOfBool_size(long jarg1, VectorOfBool jarg1_);
+    public final static native boolean VectorOfBool_isEmpty(long jarg1, VectorOfBool jarg1_);
+    public final static native void VectorOfBool_clear(long jarg1, VectorOfBool jarg1_);
+    public final static native void VectorOfBool_add__SWIG_0(long jarg1, VectorOfBool jarg1_, boolean jarg2);
+    public final static native boolean VectorOfBool_get(long jarg1, VectorOfBool jarg1_, int jarg2);
+    public final static native void VectorOfBool_set(long jarg1, VectorOfBool jarg1_, int jarg2, boolean jarg3);
+    public final static native void VectorOfBool_add__SWIG_1(long jarg1, VectorOfBool jarg1_, int jarg2, boolean jarg3);
+    public final static native boolean VectorOfBool_remove(long jarg1, VectorOfBool jarg1_, boolean jarg2);
+    public final static native void delete_VectorOfBool(long jarg1);
+    public final static native long new_VectorOfDouble__SWIG_0();
+    public final static native long new_VectorOfDouble__SWIG_1(long jarg1);
+    public final static native void VectorOfDouble_ensureCapacity(long jarg1, VectorOfDouble jarg1_, long jarg2);
+    public final static native void VectorOfDouble_resize(long jarg1, VectorOfDouble jarg1_, long jarg2);
+    public final static native int VectorOfDouble_size(long jarg1, VectorOfDouble jarg1_);
+    public final static native boolean VectorOfDouble_isEmpty(long jarg1, VectorOfDouble jarg1_);
+    public final static native void VectorOfDouble_clear(long jarg1, VectorOfDouble jarg1_);
+    public final static native void VectorOfDouble_add__SWIG_0(long jarg1, VectorOfDouble jarg1_, double jarg2);
+    public final static native boolean VectorOfDouble_contains(long jarg1, VectorOfDouble jarg1_, double jarg2);
+    public final static native int VectorOfDouble_indexOf(long jarg1, VectorOfDouble jarg1_, double jarg2);
+    public final static native double VectorOfDouble_get(long jarg1, VectorOfDouble jarg1_, int jarg2);
+    public final static native void VectorOfDouble_set(long jarg1, VectorOfDouble jarg1_, int jarg2, double jarg3);
+    public final static native void VectorOfDouble_add__SWIG_1(long jarg1, VectorOfDouble jarg1_, int jarg2, double jarg3);
+    public final static native boolean VectorOfDouble_remove(long jarg1, VectorOfDouble jarg1_, double jarg2);
+    public final static native java.nio.ByteBuffer VectorOfDouble_asByteBuffer(long jarg1, VectorOfDouble jarg1_, int jarg2, int jarg3);
+    public final static native void delete_VectorOfDouble(long jarg1);
+    public final static native long new_VectorOfString__SWIG_0();
+    public final static native long new_VectorOfString__SWIG_1(long jarg1);
+    public final static native void VectorOfString_ensureCapacity(long jarg1, VectorOfString jarg1_, long jarg2);
+    public final static native void VectorOfString_resize(long jarg1, VectorOfString jarg1_, long jarg2);
+    public final static native int VectorOfString_size(long jarg1, VectorOfString jarg1_);
+    public final static native boolean VectorOfString_isEmpty(long jarg1, VectorOfString jarg1_);
+    public final static native void VectorOfString_clear(long jarg1, VectorOfString jarg1_);
+    public final static native void VectorOfString_add__SWIG_0(long jarg1, VectorOfString jarg1_, String jarg2);
+    public final static native boolean VectorOfString_contains(long jarg1, VectorOfString jarg1_, String jarg2);
+    public final static native int VectorOfString_indexOf(long jarg1, VectorOfString jarg1_, String jarg2);
+    public final static native String VectorOfString_get(long jarg1, VectorOfString jarg1_, int jarg2);
+    public final static native void VectorOfString_set(long jarg1, VectorOfString jarg1_, int jarg2, String jarg3);
+    public final static native void VectorOfString_add__SWIG_1(long jarg1, VectorOfString jarg1_, int jarg2, String jarg3);
+    public final static native boolean VectorOfString_remove(long jarg1, VectorOfString jarg1_, String jarg2);
+    public final static native java.nio.ByteBuffer VectorOfString_asByteBuffer(long jarg1, VectorOfString jarg1_, int jarg2, int jarg3);
+    public final static native void delete_VectorOfString(long jarg1);
+    public final static native long new_VectorOfScicosID__SWIG_0();
+    public final static native long new_VectorOfScicosID__SWIG_1(long jarg1);
+    public final static native void VectorOfScicosID_ensureCapacity(long jarg1, VectorOfScicosID jarg1_, long jarg2);
+    public final static native void VectorOfScicosID_resize(long jarg1, VectorOfScicosID jarg1_, long jarg2);
+    public final static native int VectorOfScicosID_size(long jarg1, VectorOfScicosID jarg1_);
+    public final static native boolean VectorOfScicosID_isEmpty(long jarg1, VectorOfScicosID jarg1_);
+    public final static native void VectorOfScicosID_clear(long jarg1, VectorOfScicosID jarg1_);
+    public final static native void VectorOfScicosID_add__SWIG_0(long jarg1, VectorOfScicosID jarg1_, long jarg2);
+    public final static native boolean VectorOfScicosID_contains(long jarg1, VectorOfScicosID jarg1_, long jarg2);
+    public final static native int VectorOfScicosID_indexOf(long jarg1, VectorOfScicosID jarg1_, long jarg2);
+    public final static native long VectorOfScicosID_get(long jarg1, VectorOfScicosID jarg1_, int jarg2);
+    public final static native void VectorOfScicosID_set(long jarg1, VectorOfScicosID jarg1_, int jarg2, long jarg3);
+    public final static native void VectorOfScicosID_add__SWIG_1(long jarg1, VectorOfScicosID jarg1_, int jarg2, long jarg3);
+    public final static native boolean VectorOfScicosID_remove(long jarg1, VectorOfScicosID jarg1_, long jarg2);
+    public final static native java.nio.ByteBuffer VectorOfScicosID_asByteBuffer(long jarg1, VectorOfScicosID jarg1_, int jarg2, int jarg3);
+    public final static native void delete_VectorOfScicosID(long jarg1);
+    public final static native void register_view(String jarg1, long jarg2, View jarg2_);
+    public final static native void unregister_view(long jarg1, View jarg1_);
 
-  static {
-    try {
-        System.loadLibrary("scixcos");
-    } catch (SecurityException e) {
-        System.err.println("A security manager exists and does not allow the loading of the specified dynamic library.");
-        System.err.println(e.getLocalizedMessage());
-        System.exit(-1);
-    } catch (UnsatisfiedLinkError e)    {
-           System.err.println("The native library scicommons does not exist or cannot be found.");
-        if (System.getenv("CONTINUE_ON_JNI_ERROR") == null) {
-           System.err.println(e.getLocalizedMessage());
-           System.err.println("Current java.library.path is : "+System.getProperty("java.library.path"));
-           System.exit(-1);
-        }else{
-           System.err.println("Continuing anyway because of CONTINUE_ON_JNI_ERROR");
+    static {
+        try {
+            System.loadLibrary("scixcos");
+        } catch (SecurityException e) {
+            System.err.println("A security manager exists and does not allow the loading of the specified dynamic library.");
+            System.err.println(e.getLocalizedMessage());
+            System.exit(-1);
+        } catch (UnsatisfiedLinkError e)    {
+            System.err.println("The native library scicommons does not exist or cannot be found.");
+            if (System.getenv("CONTINUE_ON_JNI_ERROR") == null) {
+                System.err.println(e.getLocalizedMessage());
+                System.err.println("Current java.library.path is : " + System.getProperty("java.library.path"));
+                System.exit(-1);
+            } else {
+                System.err.println("Continuing anyway because of CONTINUE_ON_JNI_ERROR");
+            }
         }
     }
-  }
 
 
-  public static void SwigDirector_View_objectCreated(View jself, long uid, int kind) {
-    jself.objectCreated(uid, Kind.class.getEnumConstants()[kind]);
-  }
-  public static void SwigDirector_View_objectReferenced(View jself, long uid, int kind, long refCount) {
-    jself.objectReferenced(uid, Kind.class.getEnumConstants()[kind], refCount);
-  }
-  public static void SwigDirector_View_objectUnreferenced(View jself, long uid, int kind, long refCount) {
-    jself.objectUnreferenced(uid, Kind.class.getEnumConstants()[kind], refCount);
-  }
-  public static void SwigDirector_View_objectDeleted(View jself, long uid, int kind) {
-    jself.objectDeleted(uid, Kind.class.getEnumConstants()[kind]);
-  }
-  public static void SwigDirector_View_propertyUpdated(View jself, long uid, int kind, int property, int status) {
-    jself.propertyUpdated(uid, Kind.class.getEnumConstants()[kind], ObjectProperties.class.getEnumConstants()[property], UpdateStatus.class.getEnumConstants()[status]);
-  }
+    public static void SwigDirector_View_objectCreated(View jself, long uid, int kind) {
+        jself.objectCreated(uid, Kind.class.getEnumConstants()[kind]);
+    }
+    public static void SwigDirector_View_objectReferenced(View jself, long uid, int kind, long refCount) {
+        jself.objectReferenced(uid, Kind.class.getEnumConstants()[kind], refCount);
+    }
+    public static void SwigDirector_View_objectUnreferenced(View jself, long uid, int kind, long refCount) {
+        jself.objectUnreferenced(uid, Kind.class.getEnumConstants()[kind], refCount);
+    }
+    public static void SwigDirector_View_objectDeleted(View jself, long uid, int kind) {
+        jself.objectDeleted(uid, Kind.class.getEnumConstants()[kind]);
+    }
+    public static void SwigDirector_View_propertyUpdated(View jself, long uid, int kind, int property, int status) {
+        jself.propertyUpdated(uid, Kind.class.getEnumConstants()[kind], ObjectProperties.class.getEnumConstants()[property], UpdateStatus.class.getEnumConstants()[status]);
+    }
 
-  private final static native void swig_module_init();
-  static {
-    swig_module_init();
-  }
+    private final static native void swig_module_init();
+    static {
+        swig_module_init();
+    }
 }
index fa9444e..ae4f9fa 100644 (file)
@@ -842,20 +842,22 @@ public final class Xcos {
     }
 
     /**
-     * Load an xcos diagram without using Scilab at all.
+     * Load or Save an xcos diagram without using Scilab at all.
      *
      * <P>
-     * This support a reduced number of format and should be mainly used to test the decoder
+     * This support a reduced number of format and should be mainly used to test
      *
      * @param file
      *            the file
      * @param diagramId
      *            the diagram to load into
+     * @param export
+     *            flag used to indicate an export (true == export ; false == import)
      * @throws Exception
      *             on loading error
      */
     @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
-    public static void xcosDiagramToScilab(String file, long diagramId) throws Exception {
+    public static void xcosDiagramToScilab(String file, long diagramId, boolean export) throws Exception {
         XcosFileType filetype = XcosFileType.findFileType(file);
         if (filetype == null) {
             throw new IllegalArgumentException("not handled filetype");
@@ -863,7 +865,11 @@ public final class Xcos {
         switch (filetype) {
             case XCOS:
             case ZCOS:
-                filetype.load(file, new XcosDiagram(diagramId, Kind.DIAGRAM));
+                if (export) {
+                    filetype.save(file, new XcosDiagram(diagramId, Kind.DIAGRAM));
+                } else {
+                    filetype.load(file, new XcosDiagram(diagramId, Kind.DIAGRAM));
+                }
                 break;
             case COSF:
                 throw new IllegalArgumentException("not handled filetype");
index fe55796..39cd52d 100644 (file)
@@ -49,9 +49,6 @@ public class XcosCell extends ScilabGraphUniqueObject {
         if (uid == 0l) {
             throw new IllegalArgumentException();
         }
-
-        JavaController controller = new JavaController();
-        controller.referenceObject(uid);
     }
 
     /**
@@ -231,7 +228,7 @@ public class XcosCell extends ScilabGraphUniqueObject {
             case ANNOTATION:
             case BLOCK:
             case PORT:
-                controller.setObjectProperty(getUID(), getKind(), ObjectProperties.STYLE, String.valueOf(style));
+                controller.setObjectProperty(getUID(), getKind(), ObjectProperties.STYLE, style);
                 break;
             default:
                 break;
@@ -278,19 +275,21 @@ public class XcosCell extends ScilabGraphUniqueObject {
     public mxICell setTerminal(mxICell terminal, boolean isSource) {
         mxICell cell = super.setTerminal(terminal, isSource);
 
+        final long uid;
         if (cell == null) {
-            return cell;
+            uid = 0l;
+        } else {
+            // a terminal of an XcosCell is always another XcosCell
+            uid = ((XcosCell) cell).getUID();
         }
 
-        // a terminal of an XcosCell is always another XcosCell
-        XcosCell t = (XcosCell) cell;
         JavaController controller = new JavaController();
         switch (getKind()) {
             case LINK:
                 if (isSource) {
-                    controller.setObjectProperty(getUID(), getKind(), ObjectProperties.SOURCE_PORT, t.getUID());
+                    controller.setObjectProperty(getUID(), getKind(), ObjectProperties.SOURCE_PORT, uid);
                 } else {
-                    controller.setObjectProperty(getUID(), getKind(), ObjectProperties.DESTINATION_PORT, t.getUID());
+                    controller.setObjectProperty(getUID(), getKind(), ObjectProperties.DESTINATION_PORT, uid);
                 }
                 break;
             default:
@@ -460,10 +459,4 @@ public class XcosCell extends ScilabGraphUniqueObject {
         c.owner = new ScicosObjectOwner(controller.cloneObject(getUID(), false, false), getKind());
         return c;
     }
-
-    @Override
-    protected void finalize() throws Throwable {
-        JavaController controller = new JavaController();
-        controller.deleteObject(getUID());
-    }
 }
index 8a10c8e..61f0753 100644 (file)
@@ -128,8 +128,12 @@ public final class XcosCellFactory {
      *            the current diagram instance
      */
     public static void insertChildren(JavaController controller, XcosDiagram diagram) {
+        /*
+         * Retrieve then clear the children to avoid inserting the UIDs twice
+         */
         VectorOfScicosID children = new VectorOfScicosID();
         controller.getObjectProperty(diagram.getUID(), diagram.getKind(), ObjectProperties.CHILDREN, children);
+        controller.setObjectProperty(diagram.getUID(), diagram.getKind(), ObjectProperties.CHILDREN, new VectorOfScicosID());
         final int childrenLen = children.size();
 
         /*
@@ -183,7 +187,7 @@ public final class XcosCellFactory {
                 l.setSource(srcPort);
             } else {
                 //               FIXME Commented for the alpha release
-                throw new IllegalStateException();
+                //                throw new IllegalStateException();
             }
 
             BasicPort destPort = ports.get(dest[0]);;
@@ -191,7 +195,7 @@ public final class XcosCellFactory {
                 l.setTarget(destPort);
             } else {
                 //               FIXME Commented for the alpha release
-                throw new IllegalStateException();
+                //                throw new IllegalStateException();
             }
         }
 
@@ -10,7 +10,7 @@
  *
  */
 
-package org.scilab.modules.xcos.io.sax;
+package org.scilab.modules.xcos.io;
 
 import java.util.Collections;
 import java.util.HashMap;
@@ -23,7 +23,7 @@ import java.util.stream.Stream;
  * <p>
  * Note: the names correspond to each Element localName.
  */
-enum HandledElement {
+public enum HandledElement {
     add(HandledElementsCategory.RAW_DATA),
     AfficheBlock(HandledElementsCategory.BLOCK),
     Array(HandledElementsCategory.RAW_DATA),
@@ -67,7 +67,7 @@ enum HandledElement {
     VoltageSensorBlock(HandledElementsCategory.BLOCK),
     XcosDiagram(HandledElementsCategory.CUSTOM);
 
-    static Map<String, HandledElement> getMap() {
+    public static Map<String, HandledElement> getMap() {
         Map<String, HandledElement> map = new HashMap<>(HandledElement.values().length);
         Stream.of(HandledElement.values())
         .forEach(e -> map.put(e.name(), e));
@@ -80,4 +80,8 @@ enum HandledElement {
     private HandledElement(final HandledElementsCategory category) {
         this.category = category;
     }
+
+    public HandledElementsCategory getCategory() {
+        return category;
+    }
 }
\ No newline at end of file
@@ -10,8 +10,8 @@
  *
  */
 
-package org.scilab.modules.xcos.io.sax;
+package org.scilab.modules.xcos.io;
 
-enum HandledElementsCategory {
+public enum HandledElementsCategory {
     JGRAPHX, BLOCK, LINK, PORT, RAW_DATA, CUSTOM
 }
\ No newline at end of file
index b1f1e60..604eba1 100644 (file)
 package org.scilab.modules.xcos.io;
 
 import java.io.UnsupportedEncodingException;
-import java.lang.ref.WeakReference;
 import java.nio.ByteBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.scilab.modules.types.ScilabBoolean;
 import org.scilab.modules.types.ScilabDouble;
 import org.scilab.modules.types.ScilabInteger;
@@ -32,6 +32,11 @@ import org.scilab.modules.types.ScilabTList;
 import org.scilab.modules.types.ScilabType;
 import org.scilab.modules.types.ScilabTypeEnum;
 import org.scilab.modules.xcos.VectorOfDouble;
+import org.scilab.modules.xcos.VectorOfInt;
+import org.scilab.modules.xcos.VectorOfScicosID;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Encode and decode using a var2vec / vec2var compatible encoding.
@@ -42,6 +47,8 @@ import org.scilab.modules.xcos.VectorOfDouble;
  */
 public class ScilabTypeCoder {
 
+    private static final Logger LOG = Logger.getLogger("org.scilab.modules.xcos.io");
+
     class JavaScilabType {
         final ScilabTypeEnum type;
         final ScilabIntegerTypeEnum intType;
@@ -77,7 +84,22 @@ public class ScilabTypeCoder {
             value = var;
         }
 
-        return encode(value, new VectorOfDouble());
+        if (LOG.isLoggable(Level.FINER)) {
+            LOG.entering(ScilabTypeCoder.class.getCanonicalName(), "var2vec");
+        }
+
+        VectorOfDouble vec = new VectorOfDouble();
+        encode(value, vec);
+
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine("var2vec:" + var.toString() + ":" + toString(vec));
+        }
+
+        if (LOG.isLoggable(Level.FINER)) {
+            LOG.exiting(ScilabTypeCoder.class.getCanonicalName(), "var2vec");
+        }
+
+        return vec;
     }
 
     @SuppressWarnings("unchecked")
@@ -125,9 +147,9 @@ public class ScilabTypeCoder {
 
         // specific flag for managing the complex case
         if (var.isReal()) {
-            vec.add(0);
+            vec.add(0f);
         } else {
-            vec.add(1);
+            vec.add(1f);
         }
 
         // push the data
@@ -307,8 +329,8 @@ public class ScilabTypeCoder {
         }
         if (matrix != null) {
             vec.add(2);
-            vec.add(matrix.getWidth());
             vec.add(matrix.getHeight());
+            vec.add(matrix.getWidth());
         } else if (list != null) {
             vec.add(list.size());
         } else {
@@ -330,8 +352,22 @@ public class ScilabTypeCoder {
     public ScilabType vec2var(VectorOfDouble vec) {
         position = 0;
 
+        if (LOG.isLoggable(Level.FINER)) {
+            LOG.entering(ScilabTypeCoder.class.getName(), "vec2var");
+        }
+
         ScilabType var = decodeHeader(vec);
-        return decode(vec, var);
+        decode(vec, var);
+
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine("vec2var:" + toString(vec) + ":" + var.toString());
+        }
+
+        if (LOG.isLoggable(Level.FINER)) {
+            LOG.exiting(ScilabTypeCoder.class.getName(), "vec2var");
+        }
+
+        return var;
     }
 
     @SuppressWarnings("unchecked")
@@ -518,6 +554,7 @@ public class ScilabTypeCoder {
             case sci_matrix:
             case sci_boolean:
             case sci_strings:
+                position++; // n-Dims not managed
                 height = (int) vec.get(position++);
                 width = (int) vec.get(position++);
                 break;
@@ -543,31 +580,46 @@ public class ScilabTypeCoder {
         // allocate the right type with the decoded properties
         switch (type) {
             case sci_matrix:
-                return new ScilabDouble(new double[height][width], imagData);
+                if (height * width == 0) {
+                    return new ScilabDouble();
+                } else {
+                    return new ScilabDouble(new double[height][width], imagData);
+                }
             case sci_boolean:
-                return new ScilabBoolean(new boolean[height][width]);
-            case sci_ints:
-                switch (ScilabIntegerTypeEnum.swigToEnum(precision)) {
-                    case sci_int8:
-                        return new ScilabInteger(new byte[height][width], false);
-                    case sci_int16:
-                        return new ScilabInteger(new short[height][width], false);
-                    case sci_int32:
-                        return new ScilabInteger(new int[height][width], false);
-                    case sci_int64:
-                        return new ScilabInteger(new long[height][width], false);
-                    case sci_uint8:
-                        return new ScilabInteger(new byte[height][width], true);
-                    case sci_uint16:
-                        return new ScilabInteger(new short[height][width], true);
-                    case sci_uint32:
-                        return new ScilabInteger(new int[height][width], true);
-                    case sci_uint64:
-                        return new ScilabInteger(new long[height][width], true);
-
+                if (height * width == 0) {
+                    return new ScilabBoolean();
+                } else {
+                    return new ScilabBoolean(new boolean[height][width]);
                 }
+            case sci_ints:
+                if (height * width == 0) {
+                    return new ScilabInteger();
+                } else
+                    switch (ScilabIntegerTypeEnum.swigToEnum(precision)) {
+                        case sci_int8:
+                            return new ScilabInteger(new byte[height][width], false);
+                        case sci_int16:
+                            return new ScilabInteger(new short[height][width], false);
+                        case sci_int32:
+                            return new ScilabInteger(new int[height][width], false);
+                        case sci_int64:
+                            return new ScilabInteger(new long[height][width], false);
+                        case sci_uint8:
+                            return new ScilabInteger(new byte[height][width], true);
+                        case sci_uint16:
+                            return new ScilabInteger(new short[height][width], true);
+                        case sci_uint32:
+                            return new ScilabInteger(new int[height][width], true);
+                        case sci_uint64:
+                            return new ScilabInteger(new long[height][width], true);
+
+                    }
             case sci_strings:
-                return new ScilabString(new String[height][width]);
+                if (height * width == 0) {
+                    return new ScilabString();
+                } else {
+                    return new ScilabString(new String[height][width]);
+                }
             case sci_list:
                 return new ScilabList(Collections.nCopies(listLen, null));
             case sci_mlist:
@@ -579,4 +631,43 @@ public class ScilabTypeCoder {
 
         }
     }
+
+    /**
+     * Utility to display a vec on debug
+     *
+     * @param vec the vector to convert
+     * @return a representative string
+     */
+    private static String toString(VectorOfDouble vec) {
+        int len = vec.size();
+        double[] copy = new double[len];
+        DoubleBuffer.wrap(copy).put(vec.asByteBuffer(0, len).asDoubleBuffer());
+        return Arrays.toString(copy);
+    }
+
+    /**
+     * Utility to display a vec on debug
+     *
+     * @param vec the vector to convert
+     * @return a representative string
+     */
+    private static String toString(VectorOfScicosID vec) {
+        int len = vec.size();
+        long[] copy = new long[len];
+        LongBuffer.wrap(copy).put(vec.asByteBuffer(0, len).asLongBuffer());
+        return Arrays.toString(copy);
+    }
+
+    /**
+     * Utility to display a vec on debug
+     *
+     * @param vec the vector to convert
+     * @return a representative string
+     */
+    private static String toString(VectorOfInt vec) {
+        int len = vec.size();
+        int[] copy = new int[len];
+        IntBuffer.wrap(copy).put(vec.asByteBuffer(0, len).asIntBuffer());
+        return Arrays.toString(copy);
+    }
 }
index 93dff59..07a1900 100644 (file)
@@ -27,28 +27,31 @@ import java.util.logging.Logger;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stax.StAXSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.scilab.modules.commons.xml.ScilabTransformerFactory;
+import org.scilab.modules.commons.xml.ScilabXMLOutputFactory;
 import org.scilab.modules.types.ScilabList;
 import org.scilab.modules.xcos.JavaController;
 import org.scilab.modules.xcos.View;
 import org.scilab.modules.xcos.Xcos;
-import org.scilab.modules.xcos.XcosView;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.graph.model.XcosCellFactory;
-import org.scilab.modules.xcos.io.codec.XcosCodec;
-import org.scilab.modules.xcos.io.sax.SAXHandler;
+import org.scilab.modules.xcos.io.sax.XcosSAXHandler;
 import org.scilab.modules.xcos.io.spec.ContentEntry;
 import org.scilab.modules.xcos.io.spec.XcosPackage;
+import org.scilab.modules.xcos.io.writer.XcosWriter;
 import org.scilab.modules.xcos.utils.XcosMessages;
 import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
@@ -107,7 +110,7 @@ public enum XcosFileType {
                 final Transformer aTransformer = tranFactory.newTransformer();
 
                 final StreamSource src = new StreamSource(new File(file).toURI().toURL().toString());
-                final SAXResult result = new SAXResult(new SAXHandler(into, new ScilabList()));
+                final SAXResult result = new SAXResult(new XcosSAXHandler(into, null));
 
                 LOG.entering("Transformer", "transform");
                 aTransformer.transform(src, result);
@@ -127,21 +130,14 @@ public enum XcosFileType {
 
         @Override
         public void save(String file, XcosDiagram from) throws Exception {
-            final XcosCodec codec = new XcosCodec();
-            final TransformerFactory tranFactory = ScilabTransformerFactory
-                                                   .newInstance();
-            final Transformer aTransformer = tranFactory.newTransformer();
-
-            LOG.entering("XcosCodec", "encode");
-            final Node doc = codec.encode(from);
-            LOG.exiting("XcosCodec", "encode");
-
-            final DOMSource src = new DOMSource(doc);
             final StreamResult result = new StreamResult(file);
 
-            LOG.entering("Transformer", "transform");
-            aTransformer.transform(src, result);
-            LOG.exiting("Transformer", "transform");
+            final XMLOutputFactory factory = ScilabXMLOutputFactory.newInstance();
+            final XMLStreamWriter writer = factory.createXMLStreamWriter(result);
+
+            LOG.entering("XMLStreamWriter", "write");
+            new XcosWriter(null, writer).write(from.getUID(), from.getKind());
+            LOG.exiting("XMLStreamWriter", "write");
         }
     },
     /**
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/package-info.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/package-info.java
new file mode 100644 (file)
index 0000000..90d9b21
--- /dev/null
@@ -0,0 +1,7 @@
+/**
+ * This is the old JGraphX based serializer that has been used on Xcos for Scilab 5.
+ *
+ * <p>This package is now deprecated and should not be used at all as it does not handle large Xcos files.
+ */
+@Deprecated
+package org.scilab.modules.xcos.io.codec;
index af689c8..7e2cc62 100644 (file)
@@ -18,6 +18,7 @@ import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.ObjectProperties;
 import org.scilab.modules.xcos.block.AfficheBlock;
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.block.BasicBlock.SimulationFunctionType;
 import org.scilab.modules.xcos.block.SplitBlock;
 import org.scilab.modules.xcos.block.SuperBlock;
 import org.scilab.modules.xcos.block.TextBlock;
@@ -34,17 +35,18 @@ import org.scilab.modules.xcos.block.positionning.RoundBlock;
 import org.scilab.modules.xcos.block.positionning.Summation;
 import org.scilab.modules.xcos.block.positionning.VoltageSensorBlock;
 import org.scilab.modules.xcos.graph.model.BlockInterFunction;
+import org.scilab.modules.xcos.io.HandledElement;
 import org.xml.sax.Attributes;
 
 class BlockHandler implements ScilabHandler {
 
-    private final SAXHandler saxHandler;
+    private final XcosSAXHandler saxHandler;
 
     /**
      * Default constructor
      * @param saxHandler the shared sax handler
      */
-    BlockHandler(SAXHandler saxHandler) {
+    BlockHandler(XcosSAXHandler saxHandler) {
         this.saxHandler = saxHandler;
     }
 
@@ -156,11 +158,22 @@ class BlockHandler implements ScilabHandler {
         if (v != null) {
             saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.SIM_BLOCKTYPE, v);
         }
+        v = atts.getValue("simulationFunctionType");
+        if (v != null) {
+            SimulationFunctionType type = SimulationFunctionType.valueOf(v);
+            saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.SIM_FUNCTION_API, type.getValue());
+        }
+
         v = atts.getValue("style");
         if (v != null) {
             saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.STYLE, v);
         }
 
+        v = atts.getValue("value");
+        if (v != null) {
+            saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.DESCRIPTION, v);
+        }
+
         saxHandler.insertChild(block);
         return block;
     }
index 2c1ac33..9b5bae4 100644 (file)
@@ -16,8 +16,11 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map.Entry;
 import java.util.Optional;
+import java.util.logging.Level;
 import java.util.stream.Stream;
 
+import javax.naming.LimitExceededException;
+
 import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.ObjectProperties;
 import org.scilab.modules.xcos.VectorOfDouble;
@@ -26,14 +29,15 @@ import org.scilab.modules.xcos.graph.ScicosParameters;
 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
 import org.scilab.modules.xcos.graph.model.XcosCell;
 import org.scilab.modules.xcos.graph.model.XcosCellFactory;
-import org.scilab.modules.xcos.io.sax.SAXHandler.UnresolvedReference;
+import org.scilab.modules.xcos.io.HandledElement;
+import org.scilab.modules.xcos.io.sax.XcosSAXHandler.UnresolvedReference;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
 import org.xml.sax.Attributes;
 
 class CustomHandler implements ScilabHandler {
 
-    private final SAXHandler saxHandler;
+    private final XcosSAXHandler saxHandler;
 
     /**
      * Default constructor
@@ -41,7 +45,7 @@ class CustomHandler implements ScilabHandler {
      * @param saxHandler
      *            the shared sax handler
      */
-    CustomHandler(SAXHandler saxHandler) {
+    CustomHandler(XcosSAXHandler saxHandler) {
         this.saxHandler = saxHandler;
     }
 
@@ -71,6 +75,10 @@ class CustomHandler implements ScilabHandler {
                 return null;
             }
             case XcosDiagram:
+                if (XcosSAXHandler.LOG.isLoggable(Level.FINER)) {
+                    XcosSAXHandler.LOG.entering(CustomHandler.class.getName(), "startElement(\"XcosDiagram\", ...)");
+                }
+
                 // do not allocate this is already allocated as #root
                 uid = saxHandler.root.getUID();
 
@@ -123,7 +131,7 @@ class CustomHandler implements ScilabHandler {
 
                 saxHandler.controller.setObjectProperty(uid, Kind.DIAGRAM, ObjectProperties.PROPERTIES, properties);
 
-                // no break on purpose, we decode non-root specific properties later
+            // no break on purpose, we decode non-root specific properties later
             case SuperBlockDiagram:
                 final Kind kind;
                 if (uid == 0l) {
@@ -173,6 +181,10 @@ class CustomHandler implements ScilabHandler {
                 resolve();
                 saxHandler.allChildren.pop();
                 XcosCellFactory.insertChildren(saxHandler.controller, saxHandler.root);
+
+                if (XcosSAXHandler.LOG.isLoggable(Level.FINER)) {
+                    XcosSAXHandler.LOG.exiting(CustomHandler.class.getName(), "endElement(\"XcosDiagram\")");
+                }
                 break;
             case SuperBlockDiagram:
                 resolve();
index 675ea4d..a8e6a92 100644 (file)
@@ -15,6 +15,7 @@ package org.scilab.modules.xcos.io.sax;
 import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.ObjectProperties;
 import org.scilab.modules.xcos.graph.model.XcosCell;
+import org.scilab.modules.xcos.io.HandledElement;
 import org.xml.sax.Attributes;
 
 import com.mxgraph.model.mxGeometry;
@@ -22,9 +23,9 @@ import com.mxgraph.util.mxPoint;
 
 class JGraphXHandler implements ScilabHandler {
 
-    private final SAXHandler saxHandler;
+    private final XcosSAXHandler saxHandler;
 
-    JGraphXHandler(SAXHandler saxHandler) {
+    JGraphXHandler(XcosSAXHandler saxHandler) {
         this.saxHandler = saxHandler;
     }
 
index a9a10fd..ec7065c 100644 (file)
@@ -17,16 +17,18 @@ import java.util.ArrayList;
 import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.ObjectProperties;
 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
-import org.scilab.modules.xcos.io.sax.SAXHandler.UnresolvedReference;
+import org.scilab.modules.xcos.io.HandledElement;
+import org.scilab.modules.xcos.io.sax.XcosSAXHandler.UnresolvedReference;
 import org.scilab.modules.xcos.link.BasicLink;
 import org.scilab.modules.xcos.link.commandcontrol.CommandControlLink;
 import org.scilab.modules.xcos.link.explicit.ExplicitLink;
 import org.scilab.modules.xcos.link.implicit.ImplicitLink;
 import org.xml.sax.Attributes;
+import org.xml.sax.SAXParseException;
 
 class LinkHandler implements ScilabHandler {
 
-    private final SAXHandler saxHandler;
+    private final XcosSAXHandler saxHandler;
 
     /**
      * Default constructor
@@ -34,7 +36,7 @@ class LinkHandler implements ScilabHandler {
      * @param saxHandler
      *            the shared sax handler
      */
-    LinkHandler(SAXHandler saxHandler) {
+    LinkHandler(XcosSAXHandler saxHandler) {
         this.saxHandler = saxHandler;
     }
 
@@ -42,20 +44,21 @@ class LinkHandler implements ScilabHandler {
     public BasicLink startElement(HandledElement found, Attributes atts) {
         String v;
         BasicLink link;
+        int linkKind;
         final long uid = saxHandler.controller.createObject(Kind.LINK);
 
         switch (found) {
             case CommandControlLink:
                 link = new CommandControlLink(uid);
-                saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, -1);
+                linkKind = -1;
                 break;
             case ExplicitLink:
                 link = new ExplicitLink(uid);
-                saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, 1);
+                linkKind = 1;
                 break;
             case ImplicitLink:
                 link = new ImplicitLink(uid);
-                saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, 2);
+                linkKind = 2;
                 break;
             default:
                 throw new IllegalArgumentException();
@@ -70,6 +73,8 @@ class LinkHandler implements ScilabHandler {
             saxHandler.allChildren.peek().put(v, uid);
         }
 
+        saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, linkKind);
+
         v = atts.getValue("source");
         if (v != null) {
             Long src = saxHandler.allChildren.peek().get(v);
index a581c0e..4f282e6 100644 (file)
@@ -20,7 +20,8 @@ import org.scilab.modules.xcos.VectorOfInt;
 import org.scilab.modules.xcos.VectorOfScicosID;
 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
 import org.scilab.modules.xcos.graph.model.XcosCell;
-import org.scilab.modules.xcos.io.sax.SAXHandler.UnresolvedReference;
+import org.scilab.modules.xcos.io.HandledElement;
+import org.scilab.modules.xcos.io.sax.XcosSAXHandler.UnresolvedReference;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.command.CommandPort;
 import org.scilab.modules.xcos.port.control.ControlPort;
@@ -32,14 +33,14 @@ import org.xml.sax.Attributes;
 
 class PortHandler implements ScilabHandler {
 
-    private final SAXHandler saxHandler;
+    private final XcosSAXHandler shared;
 
     /**
      * Default constructor
      * @param saxHandler the shared sax handler
      */
-    PortHandler(SAXHandler saxHandler) {
-        this.saxHandler = saxHandler;
+    PortHandler(XcosSAXHandler saxHandler) {
+        this.shared = saxHandler;
     }
 
     @Override
@@ -47,6 +48,7 @@ class PortHandler implements ScilabHandler {
         String v;
         BasicPort port;
         ObjectProperties relatedProperty;
+        boolean isImplicit;
 
         /*
          * First, check if the port has already been defined. Otherwise, create the object in the model
@@ -54,11 +56,11 @@ class PortHandler implements ScilabHandler {
         v = atts.getValue("id");
         long uid = 0;
         if (v != null) {
-            if (saxHandler.allChildren.peek().containsKey(v)) {
-                uid = saxHandler.allChildren.peek().get(v);
+            if (shared.allChildren.peek().containsKey(v)) {
+                uid = shared.allChildren.peek().get(v);
             } else {
-                uid = saxHandler.controller.createObject(Kind.PORT);
-                saxHandler.allChildren.peek().put(v, uid);
+                uid = shared.controller.createObject(Kind.PORT);
+                shared.allChildren.peek().put(v, uid);
             }
         }
 
@@ -70,42 +72,53 @@ class PortHandler implements ScilabHandler {
             case CommandPort:
                 port = new CommandPort(uid);
                 relatedProperty = ObjectProperties.EVENT_OUTPUTS;
+                isImplicit = false;
                 break;
             case ControlPort:
                 port = new ControlPort(uid);
                 relatedProperty = ObjectProperties.EVENT_INPUTS;
+                isImplicit = false;
                 break;
             case ExplicitInputPort:
                 port = new ExplicitInputPort(uid);
                 relatedProperty = ObjectProperties.INPUTS;
+                isImplicit = false;
                 break;
             case ExplicitOutputPort:
                 port = new ExplicitOutputPort(uid);
                 relatedProperty = ObjectProperties.OUTPUTS;
+                isImplicit = false;
                 break;
             case ImplicitInputPort:
                 port = new ImplicitInputPort(uid);
                 relatedProperty = ObjectProperties.INPUTS;
+                isImplicit = true;
                 break;
             case ImplicitOutputPort:
                 port = new ImplicitOutputPort(uid);
                 relatedProperty = ObjectProperties.OUTPUTS;
+                isImplicit = true;
                 break;
             default:
                 throw new IllegalArgumentException();
         }
+
+        // set the decoded XML ID
         port.setId(v);
 
+        // set the implicit
+        shared.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.IMPLICIT, isImplicit);
+
         /*
          * Setup the properties
          */
         v = atts.getValue("style");
         if (v != null) {
-            saxHandler.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.STYLE, v);
+            shared.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.STYLE, v);
         }
 
         VectorOfInt datatype = new VectorOfInt();
-        saxHandler.controller.getObjectProperty(uid, Kind.PORT, ObjectProperties.DATATYPE, datatype);
+        shared.controller.getObjectProperty(uid, Kind.PORT, ObjectProperties.DATATYPE, datatype);
 
         v = atts.getValue("dataType");
         if (v != null) {
@@ -120,11 +133,11 @@ class PortHandler implements ScilabHandler {
             datatype.set(2, Integer.valueOf(v));
         }
 
-        saxHandler.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.DATATYPE, datatype);
+        shared.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.DATATYPE, datatype);
 
         v = atts.getValue("initialState");
         if (v != null) {
-            saxHandler.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.FIRING, Double.valueOf(v));
+            shared.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.FIRING, Double.valueOf(v));
         }
 
         /*
@@ -141,27 +154,27 @@ class PortHandler implements ScilabHandler {
 
         v = atts.getValue("parent");
         if (v != null) {
-            parent = saxHandler.allChildren.peek().get(v);
+            parent = shared.allChildren.peek().get(v);
 
             // if we can resolve the parent, then connect it directly
             if (parent != null) {
                 VectorOfScicosID associatedPorts = new VectorOfScicosID();
-                saxHandler.controller.getObjectProperty(parent, Kind.BLOCK, relatedProperty, associatedPorts);
+                shared.controller.getObjectProperty(parent, Kind.BLOCK, relatedProperty, associatedPorts);
 
-                associatedPorts.resize(ordering + 1);
+                associatedPorts.resize(Math.max(associatedPorts.size(), ordering + 1));
                 associatedPorts.set(ordering, uid);
-                saxHandler.controller.referenceObject(uid);
+                shared.controller.referenceObject(uid);
 
-                saxHandler.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.SOURCE_BLOCK, parent);
-                saxHandler.controller.setObjectProperty(parent, Kind.BLOCK, relatedProperty, associatedPorts);
+                shared.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.SOURCE_BLOCK, parent);
+                shared.controller.setObjectProperty(parent, Kind.BLOCK, relatedProperty, associatedPorts);
             } else {
                 // resolve the parent later
-                ArrayList<UnresolvedReference> refList = saxHandler.unresolvedReferences.get(v);
+                ArrayList<UnresolvedReference> refList = shared.unresolvedReferences.get(v);
                 if (refList == null) {
                     refList = new ArrayList<>();
-                    saxHandler.unresolvedReferences.put(v, refList);
+                    shared.unresolvedReferences.put(v, refList);
                 }
-                refList.add(new UnresolvedReference(new ScicosObjectOwner(uid, Kind.PORT), ObjectProperties.SOURCE_BLOCK, ObjectProperties.CHILDREN, ordering));
+                refList.add(new UnresolvedReference(new ScicosObjectOwner(uid, Kind.PORT), ObjectProperties.SOURCE_BLOCK, relatedProperty, ordering));
             }
         }
 
@@ -177,10 +190,10 @@ class PortHandler implements ScilabHandler {
                 opposite = ObjectProperties.DESTINATION_PORT;
             }
 
-            XcosCell cell = saxHandler.lookupForParentXcosCellElement();
+            XcosCell cell = shared.lookupForParentXcosCellElement();
             if (cell.getKind() == Kind.LINK) {
-                saxHandler.controller.setObjectProperty(cell.getUID(), cell.getKind(), opposite, port.getUID());
-                saxHandler.controller.setObjectProperty(port.getUID(), port.getKind(), ObjectProperties.CONNECTED_SIGNALS, cell.getUID());
+                shared.controller.setObjectProperty(cell.getUID(), cell.getKind(), opposite, port.getUID());
+                shared.controller.setObjectProperty(port.getUID(), port.getKind(), ObjectProperties.CONNECTED_SIGNALS, cell.getUID());
             }
         }
 
index da73b02..daf7b72 100644 (file)
@@ -32,9 +32,11 @@ import org.scilab.modules.xcos.VectorOfString;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
 import org.scilab.modules.xcos.graph.model.XcosCell;
+import org.scilab.modules.xcos.io.HandledElement;
 import org.scilab.modules.xcos.io.ScilabTypeCoder;
 import org.scilab.modules.xcos.io.scicos.DiagramElement;
 import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
+import org.scilab.modules.xcos.io.writer.XcosWriter;
 import org.xml.sax.Attributes;
 
 import com.mxgraph.model.mxGeometry;
@@ -61,7 +63,7 @@ class RawDataHandler implements ScilabHandler {
         }
     }
 
-    private final SAXHandler saxHandler;
+    private final XcosSAXHandler saxHandler;
     private final Map<String, ObjectProperties> propertyMap;
 
     /**
@@ -70,7 +72,7 @@ class RawDataHandler implements ScilabHandler {
      * @param saxHandler
      *            the shared sax handler
      */
-    RawDataHandler(SAXHandler saxHandler) {
+    RawDataHandler(XcosSAXHandler saxHandler) {
         this.saxHandler = saxHandler;
 
         Map<String, ObjectProperties> localPropertyMap = new HashMap<>();
@@ -124,7 +126,9 @@ class RawDataHandler implements ScilabHandler {
                     position = Integer.valueOf(v);
                 }
 
-                if (binary && (0 <= position && position < saxHandler.dictionary.size())) {
+                if (binary &&
+                        saxHandler.dictionary != null &&
+                        (0 <= position && position < saxHandler.dictionary.size())) {
                     return new RawDataDescriptor(propertyMap.get(as), found, null, saxHandler.dictionary.get(position));
                 }
 
@@ -451,7 +455,7 @@ class RawDataHandler implements ScilabHandler {
                         break;
                     }
                     default:
-                        System.err.println("RawDataHandler not handled: " + fieldValue.as);
+                        XcosSAXHandler.LOG.warning("RawDataHandler not handled: " + fieldValue.as);
                         break;
                 }
                 break;
 package org.scilab.modules.xcos.io.sax;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.scilab.modules.types.ScilabList;
 import org.scilab.modules.xcos.JavaController;
@@ -27,6 +30,9 @@ import org.scilab.modules.xcos.VectorOfScicosID;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
 import org.scilab.modules.xcos.graph.model.XcosCell;
+import org.scilab.modules.xcos.io.HandledElement;
+import org.scilab.modules.xcos.io.HandledElementsCategory;
+import org.scilab.modules.xcos.utils.Stack;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
@@ -34,7 +40,8 @@ import org.xml.sax.helpers.DefaultHandler;
 /**
  * Implement a diagram SAX handler to decode the document as a stream.
  */
-public class SAXHandler extends DefaultHandler {
+public class XcosSAXHandler extends DefaultHandler {
+    protected static final Logger LOG = Logger.getLogger("org.scilab.modules.xcos.io.sax");
 
     /*
      * Utilities classes and methods
@@ -59,8 +66,8 @@ public class SAXHandler extends DefaultHandler {
                 VectorOfScicosID associated = new VectorOfScicosID();
                 controller.getObjectProperty(v, kind, associatedProperty, associated);
 
-                associated.resize(associatedPropertyIndex + 1);
-                associated.set(associatedPropertyIndex, v);
+                associated.resize(Math.max(associated.size(), associatedPropertyIndex + 1));
+                associated.set(associatedPropertyIndex, owner.getUID());
 
                 controller.setObjectProperty(v, kind, associatedProperty, associated);
             }
@@ -86,7 +93,8 @@ public class SAXHandler extends DefaultHandler {
     protected final ScilabList dictionary;
     protected final JavaController controller;
     protected final Map<String, HandledElement> elementMap;
-    protected final Map<HandledElementsCategory, ScilabHandler> handlers;
+
+    private final Map<HandledElementsCategory, ScilabHandler> handlers;
 
     /*
      * Current state of the parser, also raw shared with the sub-handlers
@@ -99,7 +107,7 @@ public class SAXHandler extends DefaultHandler {
     /** List of unresolved references that will be resolved at {@link HandledElement#XcosDiagram} or {@link HandledElement#SuperBlockDiagram} ending */
     HashMap<String, ArrayList<UnresolvedReference>> unresolvedReferences = new HashMap<>();
 
-    public SAXHandler(final XcosDiagram content, final ScilabList dictionary) {
+    public XcosSAXHandler(final XcosDiagram content, final ScilabList dictionary) {
         this.root = content;
         this.dictionary = dictionary;
 
@@ -124,18 +132,18 @@ public class SAXHandler extends DefaultHandler {
 
     @Override
     public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
-        // DO NOT COMMIT
         // FOR DEBUG only : printout an XML tree
-        //                char[] indent = new char[parents.size()];
-        //                Arrays.fill(indent, ' ');
-        //                System.err.println(new String(indent) + localName + " id=\"" + atts.getValue("id") + "\"");
-        // DO NOT COMMIT
+        if (LOG.isLoggable(Level.FINEST)) {
+            char[] indent = new char[parents.size()];
+            Arrays.fill(indent, ' ');
+            LOG.finest(new String(indent) + localName + " id=\"" + atts.getValue("id") + "\"");
+        }
 
         HandledElement found = elementMap.get(localName);
         Object localParent = null;
 
         if (found != null) {
-            localParent = handlers.get(found.category).startElement(found, atts);
+            localParent = handlers.get(found.getCategory()).startElement(found, atts);
         }
 
         parents.push(localParent);
@@ -146,7 +154,7 @@ public class SAXHandler extends DefaultHandler {
         HandledElement found = elementMap.get(localName);
 
         if (found != null) {
-            handlers.get(found.category).endElement(found);
+            handlers.get(found.getCategory()).endElement(found);
         }
 
         parents.pop();
index 0aa905f..3728d5b 100644 (file)
@@ -16,6 +16,7 @@ import static java.util.Arrays.asList;
 
 import java.util.List;
 
+import org.flexdock.util.UUID;
 import org.scilab.modules.types.ScilabBoolean;
 import org.scilab.modules.types.ScilabDouble;
 import org.scilab.modules.types.ScilabList;
@@ -156,6 +157,7 @@ final class BlockModelElement extends BlockPartsElement {
             int nbControlPort = dataNbControlPort.getHeight();
             for (int i = 0; i < nbControlPort; i++) {
                 final BasicPort port = new ControlPort(controller.createObject(Kind.PORT));
+                port.setId(UUID.randomUUID().toString());
 
                 // do not use BasicPort#addPort() to avoid the view update
                 into.insert(port, baseIndex + i);
@@ -168,6 +170,7 @@ final class BlockModelElement extends BlockPartsElement {
             int nbCommandPort = dataNbCommandPort.getHeight();
             for (int i = 0; i < nbCommandPort; i++) {
                 final BasicPort port = new CommandPort(controller.createObject(Kind.PORT));
+                port.setId(UUID.randomUUID().toString());
 
                 // do not use BasicPort#addPort() to avoid the view update
                 into.insert(port, baseIndex + i);
index 267b829..a11d87f 100644 (file)
@@ -14,6 +14,7 @@ package org.scilab.modules.xcos.io.scicos;
 
 import java.util.List;
 
+import org.flexdock.util.UUID;
 import org.scilab.modules.graph.utils.StyleMap;
 import org.scilab.modules.types.ScilabDouble;
 import org.scilab.modules.types.ScilabMList;
@@ -101,6 +102,7 @@ public final class InputPortElement extends AbstractElement<InputPort> {
         data = (ScilabMList) element;
 
         port = allocatePort();
+        port.setId(UUID.randomUUID().toString());
 
         port = beforeDecode(element, port);
 
index dee8ad8..c712450 100644 (file)
@@ -18,6 +18,7 @@ import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -106,8 +107,8 @@ public final class LinkElement extends AbstractElement<BasicLink> {
         /*
          * Fill the data
          */
-        link.setSource(start);
-        link.setTarget(end);
+        link.setTerminal(start, true);
+        link.setTerminal(end, false);
 
         mxGeometry geom = link.getGeometry();
         if (geom == null) {
@@ -136,6 +137,7 @@ public final class LinkElement extends AbstractElement<BasicLink> {
             LOG.severe(e.toString());
         }
 
+        link.setId(UUID.randomUUID().toString());
         return link;
     }
 
index 1105520..dedfdf0 100644 (file)
@@ -14,6 +14,7 @@ package org.scilab.modules.xcos.io.scicos;
 
 import java.util.List;
 
+import org.flexdock.util.UUID;
 import org.scilab.modules.graph.utils.StyleMap;
 import org.scilab.modules.types.ScilabDouble;
 import org.scilab.modules.types.ScilabMList;
@@ -103,6 +104,7 @@ public final class OutputPortElement extends AbstractElement<OutputPort> {
         data = (ScilabMList) element;
 
         port = allocatePort();
+        port.setId(UUID.randomUUID().toString());
 
         port = beforeDecode(element, port);
 
index 457d44f..67a5ba0 100644 (file)
@@ -18,35 +18,29 @@ import java.util.logging.Logger;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXResult;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.scilab.modules.commons.xml.ScilabTransformerFactory;
-import org.scilab.modules.types.ScilabList;
+import org.scilab.modules.commons.xml.ScilabXMLOutputFactory;
 import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.codec.XcosCodec;
-import org.scilab.modules.xcos.io.sax.SAXHandler;
-import org.w3c.dom.Document;
+import org.scilab.modules.xcos.io.sax.XcosSAXHandler;
+import org.scilab.modules.xcos.io.writer.XcosWriter;
 import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 
 public class ContentEntry implements Entry {
     private static final Logger LOG = Logger.getLogger(ContentEntry.class.getName());
 
-    private Document manifest;
     private XcosDiagram content;
     private XcosPackage pack;
-    private ScilabList dictionary;
-
-    public void setDictionary(ScilabList dictionary) {
-        this.dictionary = dictionary;
-    }
 
     @Override
     public String getMediaType() {
@@ -61,7 +55,6 @@ public class ContentEntry implements Entry {
     @Override
     public void setup(XcosPackage p) {
         pack = p;
-        manifest = p.getManifest();
         content = p.getContent();
     }
 
@@ -72,7 +65,7 @@ public class ContentEntry implements Entry {
             final Transformer aTransformer = tranFactory.newTransformer();
 
             final StreamSource src = new StreamSource(stream);
-            final SAXResult result = new SAXResult(new SAXHandler(content, dictionary));
+            final SAXResult result = new SAXResult(new XcosSAXHandler(content, pack.getDictionary()));
 
             LOG.entering("Transformer", "transform");
             aTransformer.transform(src, result);
@@ -100,42 +93,23 @@ public class ContentEntry implements Entry {
          * Store content
          */
         try {
-            final XcosCodec codec = new XcosCodec();
-            final TransformerFactory tranFactory = ScilabTransformerFactory.newInstance();
-            final Transformer aTransformer = tranFactory.newTransformer();
-
-            LOG.entering("XcosCodec", "encode");
-            Object lock = XcosCodec.enableBinarySerialization(null);
-            final Node doc;
-            final ScilabList dictionary;
-            synchronized (lock) {
-                doc = codec.encode(content);
-                dictionary = XcosCodec.disableBinarySerialization();
-            }
-            LOG.exiting("XcosCodec", "encode");
-
-            final DOMSource src = new DOMSource(doc);
+            final XMLOutputFactory factory = ScilabXMLOutputFactory.newInstance();
             final StreamResult result = new StreamResult(stream);
+            final XMLStreamWriter writer = factory.createXMLStreamWriter(result);
 
-            LOG.entering("Transformer", "transform");
-            aTransformer.transform(src, result);
-            LOG.exiting("Transformer", "transform");
-
-            DictionaryEntry dictEntry = new DictionaryEntry(dictionary);
-            dictEntry.setup(pack);
-            dictEntry.store(stream);
+            LOG.entering("XMLStreamWriter", "write");
+            new XcosWriter(pack.getDictionary(), writer).write(content.getUID(), content.getKind());
+            LOG.exiting("XMLStreamWriter", "write");
 
             /*
              * Add an entry to the manifest file
              */
-            final Element e = manifest.createElement("manifest:file-entry");
+            final Element e = pack.getManifest().createElement("manifest:file-entry");
             e.setAttribute("manifest:media-type", getMediaType());
             e.setAttribute("manifest:full-path", getFullPath());
-            manifest.getFirstChild().appendChild(e);
-        } catch (TransformerConfigurationException e) {
-            Logger.getLogger(ContentEntry.class.getName()).severe(e.getMessageAndLocation());
-        } catch (TransformerException e) {
-            Logger.getLogger(ContentEntry.class.getName()).severe(e.getMessageAndLocation());
+            pack.getManifest().getFirstChild().appendChild(e);
+        } catch (XMLStreamException e) {
+            Logger.getLogger(ContentEntry.class.getName()).severe(e.getMessage());
         }
     }
 }
\ No newline at end of file
index 2fb02d1..f0bab23 100644 (file)
@@ -12,7 +12,6 @@
 
 package org.scilab.modules.xcos.io.spec;
 
-import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -23,26 +22,16 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
 import org.scilab.modules.types.ScilabList;
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 public class DictionaryEntry implements Entry {
     private static final Logger LOG = Logger.getLogger(DictionaryEntry.class.getName());
 
-    private Document manifest;
-    private ScilabList dict;
+    private XcosPackage pack;
 
     public DictionaryEntry() {
     }
 
-    public DictionaryEntry(ScilabList dict) {
-        this.dict = dict;
-    }
-
-    public ScilabList getDictionary() {
-        return dict;
-    }
-
     @Override
     public String getMediaType() {
         return "bin/ser";
@@ -55,15 +44,17 @@ public class DictionaryEntry implements Entry {
 
     @Override
     public void setup(XcosPackage p) {
-        manifest = p.getManifest();
+        this.pack = p;
     }
 
     @Override
     public void load(ZipEntry entry, InputStream stream) throws IOException {
         ObjectInputStream ois = null;
         try {
-            ois = new ObjectInputStream(new BufferedInputStream(stream));
-            dict = (ScilabList) ois.readObject();
+            ois = new ObjectInputStream(stream);
+
+            pack.getDictionary().clear();
+            pack.getDictionary().addAll((ScilabList) ois.readObject());
         } catch (IOException e) {
             Logger.getLogger(DictionaryEntry.class.getName()).severe(e.getMessage());
         } catch (ClassNotFoundException e) {
@@ -86,16 +77,16 @@ public class DictionaryEntry implements Entry {
          */
         LOG.entering("ObjectOutputStream", "writeObject");
         ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(stream));
-        oos.writeObject(dict);
+        oos.writeObject(pack.getDictionary());
         oos.flush();
         LOG.exiting("ObjectOutputStream", "writeObject");
 
         /*
          * Add an entry to the manifest file
          */
-        final Element e = manifest.createElement("manifest:file-entry");
+        final Element e = pack.getManifest().createElement("manifest:file-entry");
         e.setAttribute("manifest:media-type", getMediaType());
         e.setAttribute("manifest:full-path", getFullPath());
-        manifest.getFirstChild().appendChild(e);
+        pack.getManifest().getFirstChild().appendChild(e);
     }
 }
index 14b54e7..0706798 100644 (file)
 
 package org.scilab.modules.xcos.io.spec;
 
-import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
-import java.util.logging.Logger;
 import java.util.zip.CRC32;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
@@ -48,7 +46,6 @@ import org.scilab.modules.types.ScilabList;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
 
 /**
@@ -57,7 +54,6 @@ import org.xml.sax.SAXException;
  * You can load/save from/to a file a specific package without storing any data.
  */
 public class XcosPackage {
-    private static final Logger LOG = Logger.getLogger(XcosPackage.class.getName());
     private static final String MIMETYPE = "mimetype";
     private static final String META_INF_MANIFEST_XML = "META-INF/manifest.xml";
 
@@ -67,8 +63,6 @@ public class XcosPackage {
 
     private static final String INVALID_MIMETYPE = "Invalid mimetype";
 
-    private static final String DICTIONARY_PATH = "dictionary/dictionary.ser";
-
     /**
      * Specific InputStream implementation to use entry closing instead of
      * stream closing.
@@ -119,14 +113,19 @@ public class XcosPackage {
 
     /**
      * Entries encoder/decoder stored in the encoding order
+     * <p>
+     * take care:
+     * <ul>
+     * <li>the order is the encoding order (from start to end)
+     * <li>decoding will be performed from the end to the start
      */
-    private Entry[] availableEntries;
+    private Entry[] availableEntries = new Entry[] { new ContentEntry(), new DictionaryEntry() };
 
     /*
      * Data to store or load into
      */
     private XcosDiagram content;
-    private ScilabList dictionary;
+    private final ScilabList dictionary;
 
     /*
      * External methods, to save/load a file
@@ -143,13 +142,11 @@ public class XcosPackage {
      */
     public XcosPackage(final File file) throws ParserConfigurationException {
         this.file = file;
+        this.dictionary = new ScilabList();
 
         manifest = ScilabDocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
         final Element root = manifest.createElementNS("urn:scilab:xcos:xmlns:manifest:0.1", "manifest:manifest");
         manifest.appendChild(root);
-
-        // take care: the order is the encoding order
-        availableEntries = new Entry[] { new ContentEntry() };
     }
 
     private boolean hasInvalidManifest() {
@@ -172,79 +169,36 @@ public class XcosPackage {
             checkHeader();
         }
 
-        final ScilabList dictionary = getDictionary();
-
-        final FileInputStream fis = new FileInputStream(file);
-        final ZipInputStream zin = new ZipInputStream(fis);
-        // input stream without close operation
-        final EntryInputStream ein = new EntryInputStream(zin);
-
-        ZipEntry entry;
-        try {
-            while ((entry = zin.getNextEntry()) != null) {
-                final Node root = manifest.getFirstChild();
-                for (Node n = root.getFirstChild(); n != null; n = n.getNextSibling()) {
-                    // node precondition
-                    if (n.getNodeType() != Node.ELEMENT_NODE) {
-                        continue;
-                    }
-                    if (!n.hasAttributes()) {
-                        continue;
-                    }
-
-                    final String media = n.getAttributes().getNamedItem("manifest:media-type").getNodeValue();
-                    final String path = n.getAttributes().getNamedItem("manifest:full-path").getNodeValue();
+        // Decode using the specified order (from end to start)
+        for (int i = availableEntries.length - 1; 0 <= i;) {
+            Entry e = availableEntries[i];
 
-                    // path should be the entry one, if not continue
-                    if (!path.equals(entry.getName()) || path.equals(DICTIONARY_PATH)) {
-                        continue;
-                    }
+            // open the file on each entry to manage non well ordered (but still
+            // valid) zip files
+            final FileInputStream fis = new FileInputStream(file);
+            final ZipInputStream zin = new ZipInputStream(fis);
 
-                    // select the right entry decoder
-                    for (final Entry e : availableEntries) {
-                        if (media.equals(e.getMediaType()) && path.matches(e.getFullPath())) {
-                            if (dictionary != null) {
-                                ((ContentEntry) e).setDictionary(dictionary);
-                            }
-                            e.setup(this);
-                            e.load(entry, ein);
-                            break;
+            try {
+                ZipEntry entry;
+                while ((entry = zin.getNextEntry()) != null) {
+                    final String path = entry.getName();
+                    if (path.equals(e.getFullPath())) {
+                        // decode the current entry
+                        e.setup(this);
+                        e.load(entry, new EntryInputStream(zin));
+
+                        // try to decode the next entry (for well ordered zip,
+                        // the more common case)
+                        i--;
+                        if (0 <= i) {
+                            e = availableEntries[i];
                         }
                     }
                 }
+            } finally {
+                zin.close();
             }
-
-        } finally {
-            zin.close();
-        }
-    }
-
-    public ScilabList getDictionary() throws IOException {
-        LOG.entering("XcosPackage", "getDictionary");
-        final FileInputStream fis = new FileInputStream(file);
-        final ZipInputStream zin = new ZipInputStream(fis);
-
-        ZipEntry entry;
-        BufferedInputStream bis = new BufferedInputStream(zin);
-
-        try {
-            while ((entry = zin.getNextEntry()) != null) {
-                final String name = entry.getName();
-                if (name.equals(DICTIONARY_PATH)) {
-                    DictionaryEntry e = new DictionaryEntry();
-                    e.setup(this);
-                    e.load(entry, bis);
-                    return e.getDictionary();
-                }
-            }
-        } finally {
-            bis.close();
-            zin.close();
-
-            LOG.exiting("XcosPackage", "getDictionary");
         }
-
-        return null;
     }
 
     /**
@@ -316,6 +270,8 @@ public class XcosPackage {
 
             // store the manifest file
             storeTrailer(zout);
+        } catch (Exception e) {
+            e.printStackTrace();
         } finally {
             zout.close();
         }
@@ -385,6 +341,10 @@ public class XcosPackage {
         return content;
     }
 
+    public ScilabList getDictionary() {
+        return dictionary;
+    }
+
     /*
      * Utilities
      */
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/BlockWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/BlockWriter.java
new file mode 100644 (file)
index 0000000..2fdf4c4
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos.io.writer;
+
+import java.util.EnumSet;
+import java.util.UUID;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfScicosID;
+import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.block.BasicBlock.SimulationFunctionType;
+import org.scilab.modules.xcos.graph.model.BlockInterFunction;
+import org.scilab.modules.xcos.graph.model.XcosCellFactory;
+
+public class BlockWriter extends ScilabWriter {
+
+    public BlockWriter(XcosWriter writer) {
+        super(writer);
+    }
+
+    @Override
+    public void write(long uid, Kind kind) throws XMLStreamException {
+        // Lookup for the element name
+        String[] interfaceFunction = new String[1];
+        BlockInterFunction interFunction;
+        if (kind == Kind.BLOCK) {
+            shared.controller.getObjectProperty(uid, kind, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
+            interFunction = XcosCellFactory.lookForInterfunction(interfaceFunction[0]);
+        } else {
+            interfaceFunction[0] = BlockInterFunction.TEXT_f.name();
+            interFunction = BlockInterFunction.TEXT_f;
+        }
+
+        shared.stream.writeStartElement(interFunction.getKlass().getSimpleName());
+
+        String[] v = new String[1];
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.UID, v);
+        if (v[0].isEmpty()) {
+            v[0] = UUID.randomUUID().toString();
+            shared.controller.setObjectProperty(uid, kind, ObjectProperties.UID, v[0]);
+        }
+        shared.stream.writeAttribute("id", v[0]);
+        shared.stream.writeAttribute("parent", shared.layers.peek());
+        shared.layers.push(v[0]);
+
+        shared.stream.writeAttribute("interfaceFunctionName", interfaceFunction[0]);
+
+        if (kind == Kind.BLOCK) {
+            shared.controller.getObjectProperty(uid, kind, ObjectProperties.SIM_BLOCKTYPE, v);
+            shared.stream.writeAttribute("blockType", v[0]);
+
+            shared.controller.getObjectProperty(uid, kind, ObjectProperties.SIM_FUNCTION_NAME, v);
+            shared.stream.writeAttribute("simulationFunctionName", v[0]);
+
+            int[] functionAPI = new int[1];
+            shared.controller.getObjectProperty(uid, kind, ObjectProperties.SIM_FUNCTION_API, functionAPI);
+            SimulationFunctionType type = BasicBlock.SimulationFunctionType.convertScilabValue(functionAPI[0]);
+            shared.stream.writeAttribute("simulationFunctionType", type.name());
+        }
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.STYLE, v);
+        shared.stream.writeAttribute("style", v[0]);
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.DESCRIPTION, v);
+        if (!v[0].isEmpty()) {
+            shared.stream.writeAttribute("value", v[0]);
+        }
+
+        // delegate the sub-elements to their writers
+        shared.rawDataWriter.write(uid, kind);
+        new JGraphXWriter(shared).write(uid, kind);
+        new CustomWriter(shared).write(uid, kind);
+
+        shared.stream.writeEndElement(); // Block name
+
+        /*
+         * We serialize the ports on the inner layer but close it before to
+         * have a flat object view per diagram, this is Scilab 5 compatible.
+         */
+
+        // serialize the ports after the block
+        VectorOfScicosID ports = new VectorOfScicosID();
+        final EnumSet<ObjectProperties> portKind = EnumSet.of(ObjectProperties.INPUTS, ObjectProperties.OUTPUTS,
+                ObjectProperties.EVENT_INPUTS, ObjectProperties.EVENT_OUTPUTS);
+        for (ObjectProperties p : portKind) {
+            shared.controller.getObjectProperty(uid, kind, p, ports);
+            PortWriter portWriter = new PortWriter(shared, p);
+
+            final int length = ports.size();
+            for (int i = 0; i < length; i++) {
+                portWriter.write(ports.get(i), Kind.PORT);
+            }
+        }
+
+        shared.layers.pop();
+    }
+
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/CustomWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/CustomWriter.java
new file mode 100644 (file)
index 0000000..54923d4
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos.io.writer;
+
+import java.util.UUID;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfDouble;
+import org.scilab.modules.xcos.VectorOfInt;
+import org.scilab.modules.xcos.VectorOfScicosID;
+import org.scilab.modules.xcos.Xcos;
+import org.scilab.modules.xcos.graph.ScicosParameters;
+import org.scilab.modules.xcos.io.HandledElement;
+
+public class CustomWriter extends ScilabWriter {
+    private static final String SEP = " - ";
+
+    public CustomWriter(XcosWriter writer) {
+        super(writer);
+    }
+
+    @Override
+    public void write(long uid, Kind kind) throws XMLStreamException {
+        String[] str = new String[1];
+        VectorOfDouble vDouble = new VectorOfDouble();
+        VectorOfScicosID children = new VectorOfScicosID();
+
+        switch (kind) {
+            case DIAGRAM:
+                shared.stream.writeStartDocument();
+                shared.stream.writeStartElement(HandledElement.XcosDiagram.name());
+
+                /*
+                 * Write diagram content
+                 */
+
+                shared.controller.getObjectProperty(uid, kind, ObjectProperties.PATH, str);
+                shared.stream.writeAttribute("savedFile", str[0]);
+
+                // write simulation properties
+                shared.controller.getObjectProperty(uid, kind, ObjectProperties.PROPERTIES, vDouble);
+                String prop;
+
+                prop = Double.toString(vDouble.get(ScicosParameters.FINAL_INTEGRATION_TIME));
+                shared.stream.writeAttribute("finalIntegrationTime", prop);
+                prop = Double.toString(vDouble.get(ScicosParameters.INTEGRATOR_ABSOLUTE_TOLERANCE));
+                shared.stream.writeAttribute("integratorAbsoluteTolerance", prop);
+                prop = Double.toString(vDouble.get(ScicosParameters.INTEGRATOR_RELATIVE_TOLERANCE));
+                shared.stream.writeAttribute("integratorRelativeTolerance", prop);
+                prop = Double.toString(vDouble.get(ScicosParameters.TOLERANCE_ON_TIME));
+                shared.stream.writeAttribute("toleranceOnTime", prop);
+                prop = Double.toString(vDouble.get(ScicosParameters.MAX_INTEGRATION_TIME_INTERVAL));
+                shared.stream.writeAttribute("maxIntegrationTimeInterval", prop);
+                prop = Double.toString(vDouble.get(ScicosParameters.MAXIMUM_STEP_SIZE));
+                shared.stream.writeAttribute("maximumStepSize", prop);
+                prop = Double.toString(vDouble.get(ScicosParameters.REAL_TIME_SCALING));
+                shared.stream.writeAttribute("realTimeScaling", prop);
+                prop = Double.toString(vDouble.get(ScicosParameters.SOLVER));
+                shared.stream.writeAttribute("solver", prop);
+
+                // write the graphical part and children
+                shared.controller.getObjectProperty(uid, kind, ObjectProperties.CHILDREN, children);
+                writeDiagramAndSuperDiagramContent(uid, kind, children);
+
+                shared.stream.writeEndElement();
+                shared.stream.writeEndDocument();
+
+                // post processing for binary data handling
+                shared.rawDataWriter.fillSharedDictionary();
+                break;
+            case BLOCK:
+                shared.controller.getObjectProperty(uid, kind, ObjectProperties.CHILDREN, children);
+                if (children.size() > 0) {
+                    shared.stream.writeStartElement(HandledElement.SuperBlockDiagram.name());
+                    writeDiagramAndSuperDiagramContent(uid, kind, children);
+                    shared.stream.writeEndElement(); // SuperBlockDiagram
+                }
+                break;
+            case PORT:
+                // FIXME encode orientation from the model or not?
+                break;
+            default:
+                break;
+        }
+    }
+
+    private void writeDiagramAndSuperDiagramContent(long uid, Kind kind, VectorOfScicosID children) throws XMLStreamException {
+
+        VectorOfInt colors = new VectorOfInt();
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.COLOR, colors);
+        shared.stream.writeAttribute("background", Integer.toString(colors.get(0)));
+        shared.stream.writeAttribute("gridEnabled", Integer.toString(colors.get(1)));
+
+        String[] str = new String[1];
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.TITLE, str);
+        shared.stream.writeAttribute("title", str[0]);
+
+        /*
+         * Add the legacy version comment
+         */
+        final Package p = Package.getPackage("org.scilab.modules.xcos");
+        StringBuilder comment = new StringBuilder().append(Xcos.TRADENAME).append(SEP).append(Xcos.VERSION).append(SEP)
+        .append(p.getSpecificationVersion()).append(SEP).append(p.getImplementationVersion());
+        shared.stream.writeComment(comment.toString());
+
+        /*
+         * encode some content then the children
+         */
+        shared.rawDataWriter.write(uid, kind);
+
+        UUID root = UUID.randomUUID();
+        UUID layer = UUID.randomUUID();
+        shared.layers.push(layer.toString());
+
+        // children header
+        shared.stream.writeStartElement("mxGraphModel");
+        shared.stream.writeAttribute("as", "model");
+        shared.stream.writeStartElement("root");
+        shared.stream.writeEmptyElement("mxCell");
+        shared.stream.writeAttribute("id", root.toString());
+        shared.stream.writeEmptyElement("mxCell");
+        shared.stream.writeAttribute("id", shared.layers.peek());
+        shared.stream.writeAttribute("parent", root.toString());
+
+        // loop on all children, encode the blocks and ports then the links
+        VectorOfInt kinds = new VectorOfInt();
+        shared.controller.sortAndFillKind(children, kinds);
+
+        final int len = children.size();
+        for (int i = 0; i < len; i++) {
+            long child = children.get(i);
+            Kind childKind = Kind.values()[kinds.get(i)];
+            shared.write(child, childKind);
+        }
+
+        shared.layers.pop();
+        shared.stream.writeEndElement(); // root
+        shared.stream.writeEndElement(); // mxGraphModel
+    }
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/JGraphXWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/JGraphXWriter.java
new file mode 100644 (file)
index 0000000..01406d5
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos.io.writer;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfDouble;
+
+public class JGraphXWriter extends ScilabWriter {
+
+    public JGraphXWriter(XcosWriter writer) {
+        super(writer);
+    }
+
+    @Override
+    public void write(long uid, Kind kind) throws XMLStreamException {
+        VectorOfDouble vDouble = new VectorOfDouble();
+
+        switch (kind) {
+            case ANNOTATION:
+            case BLOCK:
+                shared.controller.getObjectProperty(uid, kind, ObjectProperties.GEOMETRY, vDouble);
+
+                shared.stream.writeEmptyElement("mxGeometry");
+                shared.stream.writeAttribute("as", "geometry");
+                shared.stream.writeAttribute("x", Double.toString(vDouble.get(0)));
+                shared.stream.writeAttribute("y", Double.toString(vDouble.get(1)));
+                shared.stream.writeAttribute("width", Double.toString(vDouble.get(2)));
+                shared.stream.writeAttribute("height", Double.toString(vDouble.get(3)));
+                break;
+            case LINK:
+                shared.controller.getObjectProperty(uid, kind, ObjectProperties.CONTROL_POINTS, vDouble);
+                int i = 0;
+                final int nbOfPoints = vDouble.size() / 2;
+
+                shared.stream.writeStartElement("mxGeometry");
+                shared.stream.writeAttribute("as", "geometry");
+
+                if (i < nbOfPoints) {
+                    shared.stream.writeEmptyElement("mxPoint");
+                    shared.stream.writeAttribute("as", "sourcePoint");
+                    shared.stream.writeAttribute("x", Double.toString(vDouble.get(2 * i)));
+                    shared.stream.writeAttribute("y", Double.toString(vDouble.get(2 * i + 1)));
+                }
+
+                shared.stream.writeStartElement("Array");
+                shared.stream.writeAttribute("as", "points");
+                for (; i < nbOfPoints - 1; i++) {
+                    shared.stream.writeEmptyElement("mxPoint");
+                    shared.stream.writeAttribute("x", Double.toString(vDouble.get(2 * i)));
+                    shared.stream.writeAttribute("y", Double.toString(vDouble.get(2 * i + 1)));
+                }
+                shared.stream.writeEndElement(); // Array
+
+                if (i < nbOfPoints) {
+                    shared.stream.writeEmptyElement("mxPoint");
+                    shared.stream.writeAttribute("as", "targetPoint");
+                    shared.stream.writeAttribute("x", Double.toString(vDouble.get(2 * i)));
+                    shared.stream.writeAttribute("y", Double.toString(vDouble.get(2 * i + 1)));
+                }
+
+                shared.stream.writeEndElement(); // mxGeometry
+                break;
+            case PORT: // no break on purpose
+            case DIAGRAM:
+                break;
+        }
+    }
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/LinkWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/LinkWriter.java
new file mode 100644 (file)
index 0000000..0289892
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos.io.writer;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+
+public class LinkWriter extends ScilabWriter {
+
+    public LinkWriter(XcosWriter writer) {
+        super(writer);
+    }
+
+    @Override
+    public void write(long uid, Kind kind) throws XMLStreamException {
+        assert kind == Kind.LINK;
+
+        int[] linkKind = new int[1];
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.KIND, linkKind);
+
+        String localName;
+        switch (linkKind[0]) {
+            case -1:
+                localName = "CommandControlLink";
+                break;
+            case 1:
+                localName = "ExplicitLink";
+                break;
+            case 2:
+                localName = "ImplicitLink";
+                break;
+            default:
+                return;
+        }
+
+        String[] id = new String[1];
+        long[] scicosId = new long[1];
+
+        String[] src = new String[1];
+        String[] dst = new String[1];
+        String[] style = new String[1];
+        String[] value = new String[1];
+
+        /*
+         * Retrieve all the serialized info
+         */
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.UID, id);
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.SOURCE_PORT, scicosId);
+        shared.controller.getObjectProperty(scicosId[0], Kind.PORT, ObjectProperties.UID, src);
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.DESTINATION_PORT, scicosId);
+        shared.controller.getObjectProperty(scicosId[0], Kind.PORT, ObjectProperties.UID, dst);
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.STYLE, style);
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.LABEL, value);
+
+        /*
+         * Only serialized a fully connected link
+         */
+        if (!src[0].isEmpty() && !dst[0].isEmpty()) {
+            shared.stream.writeStartElement(localName);
+
+            shared.stream.writeAttribute("id", id[0]);
+            shared.stream.writeAttribute("parent", shared.layers.peek());
+
+            shared.stream.writeAttribute("source", src[0]);
+            shared.stream.writeAttribute("target", dst[0]);
+            shared.stream.writeAttribute("style", style[0]);
+            shared.stream.writeAttribute("value", value[0]);
+
+            shared.stream.writeEndElement(); // localName
+        }
+    }
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/PortWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/PortWriter.java
new file mode 100644 (file)
index 0000000..8c46530
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos.io.writer;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfInt;
+import org.scilab.modules.xcos.port.BasicPort;
+
+public class PortWriter extends ScilabWriter {
+
+    private final ObjectProperties portKind;
+
+    public PortWriter(XcosWriter writer, ObjectProperties portKind) {
+        super(writer);
+
+        this.portKind = portKind;
+    }
+
+    @Override
+    public void write(long uid, Kind kind) throws XMLStreamException {
+        assert kind == Kind.PORT;
+
+        String localName;
+        boolean[] isImplicit = new boolean[1];
+
+        // retrieve some properties before emiting the element
+        shared.controller.getObjectProperty(uid, Kind.PORT, ObjectProperties.IMPLICIT, isImplicit);
+
+        switch (portKind) {
+            case INPUTS:
+                if (isImplicit[0]) {
+                    localName = "ImplicitInputPort";
+                } else {
+                    localName = "ExplicitInputPort";
+                }
+                break;
+            case OUTPUTS:
+                if (isImplicit[0]) {
+                    localName = "ImplicitOutputPort";
+                } else {
+                    localName = "ExplicitOutputPort";
+                }
+                break;
+            case EVENT_INPUTS:
+                localName = "ControlPort";
+                break;
+            case EVENT_OUTPUTS:
+                localName = "CommandPort";
+                break;
+
+            default:
+                return;
+        }
+
+        /*
+         * Emit the XML
+         */
+        String[] str = new String[1];
+
+        // the Geometry does not need to be saved, serialize only attributes there
+        shared.stream.writeEmptyElement(localName);
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.UID, str);
+        shared.stream.writeAttribute("id", str[0]);
+        shared.stream.writeAttribute("parent", shared.layers.peek());
+
+        VectorOfInt datatype = new VectorOfInt();
+        shared.controller.getObjectProperty(uid, Kind.PORT, ObjectProperties.DATATYPE, datatype);
+
+        int dataDescriptor = datatype.get(0);
+        if (0 <= dataDescriptor && dataDescriptor < BasicPort.DataType.values().length) {
+            shared.stream.writeAttribute("dataType", BasicPort.DataType.values()[dataDescriptor].name());
+            shared.stream.writeAttribute("dataColumns", Integer.toString(datatype.get(1)));
+            shared.stream.writeAttribute("dataLines", Integer.toString(datatype.get(2)));
+        }
+
+        double[] firing = new double[1];
+        shared.controller.getObjectProperty(uid, Kind.PORT, ObjectProperties.FIRING, firing);
+        shared.stream.writeAttribute("initialState", Double.toString(firing[0]));
+
+        String[] style = new String[1];
+        shared.controller.getObjectProperty(uid, Kind.PORT, ObjectProperties.STYLE, style);
+        shared.stream.writeAttribute("style", style[0]);
+    }
+
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/RawDataWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/RawDataWriter.java
new file mode 100644 (file)
index 0000000..bb66957
--- /dev/null
@@ -0,0 +1,345 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos.io.writer;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.scilab.modules.types.ScilabBoolean;
+import org.scilab.modules.types.ScilabDouble;
+import org.scilab.modules.types.ScilabInteger;
+import org.scilab.modules.types.ScilabString;
+import org.scilab.modules.types.ScilabType;
+import org.scilab.modules.types.ScilabTypeEnum;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfDouble;
+import org.scilab.modules.xcos.VectorOfInt;
+import org.scilab.modules.xcos.VectorOfString;
+import org.scilab.modules.xcos.io.ScilabTypeCoder;
+
+public class RawDataWriter extends ScilabWriter {
+
+    /*
+     * Shared map information used to avoid duplicated entry on the dictionary
+     */
+    private final HashMap<ScilabType, Integer> dictionaryMap;
+
+    public RawDataWriter(XcosWriter writer) {
+        super(writer);
+
+        dictionaryMap = new HashMap<>();
+    }
+
+    /**
+     * Fill the shared dictinary with the encoded mapping
+     */
+    public void fillSharedDictionary() {
+        if (shared.dictionary == null) {
+            return;
+        }
+
+        // reserve the size with null values
+        shared.dictionary.addAll(Collections.nCopies(dictionaryMap.size(), new ScilabDouble()));
+
+        // push all the values
+        for (Entry<ScilabType, Integer> entry : dictionaryMap.entrySet()) {
+            shared.dictionary.set(entry.getValue(), entry.getKey());
+        }
+    }
+
+    @Override
+    public void write(long uid, Kind kind) throws XMLStreamException {
+
+        switch (kind) {
+            case BLOCK:
+                writeBlock(uid, kind);
+                break;
+            case DIAGRAM:
+                writeContext(uid, kind);
+                break;
+            case LINK: // no break on purpose
+            case ANNOTATION:  // no break on purpose
+            default:
+                break;
+        }
+    }
+
+    private void writeContext(long uid, Kind kind) throws XMLStreamException {
+        VectorOfString context = new VectorOfString();
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.DIAGRAM_CONTEXT, context);
+
+        String[] value = new String[context.size()];
+        for (int i = 0; i < value.length; i++) {
+            value[i] = context.get(i);
+        }
+        write(value, "context");
+    }
+
+    private void writeBlock(long uid, Kind kind) throws XMLStreamException {
+        VectorOfDouble vDouble = new VectorOfDouble();
+        VectorOfInt vInt = new VectorOfInt();
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.EXPRS, vDouble);
+        write(new ScilabTypeCoder().vec2var(vDouble), "exprs");
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.RPAR, vDouble);
+        write(vDouble, "realParameters");
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.IPAR, vInt);
+        write(vInt, "integerParameters");
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.OPAR, vDouble);
+        write(new ScilabTypeCoder().vec2var(vDouble), "objectsParameters");
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.NZCROSS, vInt);
+        write(vInt, "nbZerosCrossing");
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.NMODE, vInt);
+        write(vInt, "nmode");
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.DSTATE, vDouble);
+        write(vDouble, "dState");
+
+        shared.controller.getObjectProperty(uid, kind, ObjectProperties.EQUATIONS, vDouble);
+        write(new ScilabTypeCoder().vec2var(vDouble), "equations");
+    }
+
+    /*
+     * Low-level serialization methods
+     */
+
+    private void write(String[] value, String as) throws XMLStreamException {
+        shared.stream.writeStartElement("Array");
+        shared.stream.writeAttribute("as", as);
+        shared.stream.writeAttribute("scilabClass", "String[]");
+
+        for (String v : value) {
+            shared.stream.writeEmptyElement("add");
+            shared.stream.writeAttribute("value", v);
+        }
+
+        shared.stream.writeEndElement(); // Array
+    }
+
+    private void write(ScilabType value, String as) throws XMLStreamException {
+        if (shared.dictionary == null) {
+            writeAsXml(value, as);
+        } else {
+            writeAsBinary(value, as);
+        }
+    }
+
+    private void writeAsXml(ScilabType value, String as) throws XMLStreamException {
+        ScilabTypeEnum type = value.getType();
+        final String localName;
+        final String scilabClass;
+        final String intPrecision;
+
+        /*
+         * Get the right descriptor
+         */
+        switch (type) {
+            case sci_boolean:
+                localName = "ScilabBoolean";
+                scilabClass = null;
+                intPrecision = null;
+                break;
+            case sci_ints:
+                localName = "ScilabInteger";
+                scilabClass = null;
+                intPrecision = ((ScilabInteger) value).getPrec().name();
+                break;
+            case sci_matrix:
+                localName = "ScilabDouble";
+                scilabClass = null;
+                intPrecision = null;
+                break;
+            case sci_strings:
+                localName = "ScilabString";
+                scilabClass = null;
+                intPrecision = null;
+                break;
+            case sci_list:
+                localName = "Array";
+                scilabClass = "ScilabList";
+                intPrecision = null;
+                break;
+            case sci_mlist:
+                localName = "Array";
+                scilabClass = "ScilabMList";
+                intPrecision = null;
+                break;
+            case sci_tlist:
+                localName = "Array";
+                scilabClass = "ScilabTList";
+                intPrecision = null;
+                break;
+            default:
+                throw new XMLStreamException("Not handled ScilabType : " + type.name());
+        }
+
+        /*
+         * Emit the elements
+         */
+        final int len = value.getHeight() * value.getWidth();
+        if (len > 0) {
+            shared.stream.writeStartElement(localName);
+        } else {
+            shared.stream.writeEmptyElement(localName);
+        }
+        if (as != null) {
+            shared.stream.writeAttribute("as", as);
+        }
+
+        if (value instanceof ArrayList) {
+            writeList(value, scilabClass);
+        } else {
+            writeMatrix(value, type, intPrecision);
+        }
+
+        if (len > 0) {
+            shared.stream.writeEndElement();
+        }
+    }
+
+    private void writeList(ScilabType value, final String scilabClass) throws XMLStreamException {
+        shared.stream.writeAttribute("scilabClass", scilabClass);
+
+        @SuppressWarnings("unchecked")
+        ArrayList<ScilabType> values = (ArrayList<ScilabType>) value;
+        for (ScilabType subValue : values) {
+            write(subValue, null);
+        }
+    }
+
+    @SuppressWarnings("incomplete-switch")
+    private void writeMatrix(ScilabType value, ScilabTypeEnum type, final String intPrecision) throws XMLStreamException {
+        shared.stream.writeAttribute("height", Integer.toString(value.getHeight()));
+        shared.stream.writeAttribute("width", Integer.toString(value.getWidth()));
+        if (intPrecision != null) {
+            shared.stream.writeAttribute("intPrecision", value.getType().name());
+        }
+
+        for (int i = 0; i < value.getHeight(); i++) {
+            for (int j = 0; j < value.getWidth(); j++) {
+                shared.stream.writeEmptyElement("data");
+                shared.stream.writeAttribute("column", Integer.toString(i));
+                shared.stream.writeAttribute("line", Integer.toString(j));
+
+                switch (type) {
+                    case sci_boolean:
+                        boolean bValue = ((ScilabBoolean)value).getElement(i, j);
+                        shared.stream.writeAttribute("value", Boolean.toString(bValue));
+                        break;
+                    case sci_ints:
+                        long lValue = ((ScilabInteger) value).getElement(i, j);
+                        shared.stream.writeAttribute("value", Long.toString(lValue));
+                        break;
+                    case sci_matrix:
+                        double dValue = ((ScilabDouble) value).getRealElement(i, j);
+                        shared.stream.writeAttribute("realPart", Double.toString(dValue));
+                        if (!((ScilabDouble) value).isReal()) {
+                            dValue  = ((ScilabDouble) value).getImaginaryElement(i, j);
+                            shared.stream.writeAttribute("imaginaryPart", Double.toString(dValue));
+                        }
+                        break;
+                    case sci_strings:
+                        String strValue = ((ScilabString) value).getData()[i][j];
+                        shared.stream.writeAttribute("value", strValue);
+                        break;
+                }
+            }
+        }
+    }
+
+    private void writeAsBinary(ScilabType value, String as) throws XMLStreamException {
+        ScilabTypeEnum type = value.getType();
+        final String localName;
+
+        /*
+         * Get the right descriptor
+         */
+        switch (type) {
+            case sci_boolean:
+                localName = "ScilabBoolean";
+                break;
+            case sci_ints:
+                localName = "ScilabInteger";
+                break;
+            case sci_matrix:
+                localName = "ScilabDouble";
+                break;
+            case sci_strings:
+                localName = "ScilabString";
+                break;
+            case sci_list: // no break on purpose
+            case sci_mlist: // no break on purpose
+            case sci_tlist:
+                localName = "Array";
+                break;
+            default:
+                throw new XMLStreamException("Not handled ScilabType : " + type.name());
+        }
+
+        /*
+         * Emit the elements
+         */
+
+        // if the value has not been mapped, then use the next position (map.size())
+        // else re-use the same position
+        Integer expectedPosition = dictionaryMap.size();
+        Integer position = dictionaryMap.putIfAbsent(value, expectedPosition);
+        if (position == null) {
+            position = expectedPosition;
+        }
+
+        if (XcosWriter.LOG.isLoggable(Level.FINE)) {
+            XcosWriter.LOG.fine("put:" + value.toString() + ":" + position.toString());
+        }
+
+        shared.stream.writeEmptyElement(localName);
+        shared.stream.writeAttribute("as", as);
+        shared.stream.writeAttribute("binary", "true");
+        shared.stream.writeAttribute("position", position.toString());
+    }
+
+    private void write(VectorOfDouble value, String as) throws XMLStreamException {
+        // recreate a ScilabDouble for the encoding
+        final int length = value.size();
+        if (length > 0) {
+            double[][] data = new double[1][length];
+            value.asByteBuffer(0, length).asDoubleBuffer().get(data[0]);
+            write(new ScilabDouble(data), as);
+        } else {
+            write(new ScilabDouble(), as);
+        }
+    }
+
+    private void write(VectorOfInt value, String as) throws XMLStreamException {
+        // recreate a ScilabInteger for the encoding
+        final int length = value.size();
+        if (length > 0) {
+            int[][] data = new int[1][length];
+            value.asByteBuffer(0, length).asIntBuffer().get(data[0]);
+            write(new ScilabInteger(data, false), as);
+        } else {
+            write(new ScilabDouble(), as);
+        }
+    }
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/ScilabWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/ScilabWriter.java
new file mode 100644 (file)
index 0000000..74e61b0
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+package org.scilab.modules.xcos.io.writer;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.scilab.modules.xcos.Kind;
+
+abstract class ScilabWriter {
+    protected final XcosWriter shared;
+
+    public ScilabWriter(XcosWriter writer) {
+        this.shared = writer;
+    }
+
+    /**
+     * Write the uid object to the stream
+     *
+     * @param uid the uid to serialize
+     * @param kind the kind of uid
+     * @throws XMLStreamException on write error
+     */
+    public abstract void write(long uid, Kind kind) throws XMLStreamException;
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/XcosWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/XcosWriter.java
new file mode 100644 (file)
index 0000000..c210e8e
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos.io.writer;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.scilab.modules.types.ScilabList;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.utils.Stack;
+
+/**
+ * Implement an XML writer for any kind of model object
+ */
+public class XcosWriter {
+
+    protected static final Logger LOG = Logger.getLogger("org.scilab.modules.xcos.io.writer");
+
+    /*
+     * Shared data
+     */
+    protected final JavaController controller;
+    protected final ScilabList dictionary;
+    protected final RawDataWriter rawDataWriter;
+    protected final XMLStreamWriter stream;
+    protected final Stack<String> layers;
+
+    public XcosWriter(ScilabList dictionary, XMLStreamWriter writer) {
+        this.controller = new JavaController();
+        this.dictionary = dictionary;
+        this.rawDataWriter = new RawDataWriter(this);
+        this.stream = writer;
+
+        this.layers = new Stack<>();
+    }
+
+    public void write(long uid, Kind kind) throws XMLStreamException {
+
+        if (LOG.isLoggable(Level.FINER)) {
+            LOG.entering(XcosWriter.class.getName(), "write");
+        }
+
+        switch (kind) {
+            case ANNOTATION:
+            case BLOCK:
+                new BlockWriter(this).write(uid, kind);
+                break;
+            case DIAGRAM:
+                new CustomWriter(this).write(uid, kind);
+                break;
+            case LINK:
+                new LinkWriter(this).write(uid, kind);
+                break;
+            case PORT:
+                // this will be managed by the BlockWriter
+                break;
+        }
+
+        if (LOG.isLoggable(Level.FINER)) {
+            LOG.exiting(XcosWriter.class.getName(), "write");
+        }
+    }
+}
index 6d9d4c8..7a4cd23 100644 (file)
@@ -25,7 +25,9 @@ import org.scilab.modules.gui.contextmenu.ContextMenu;
 import org.scilab.modules.gui.contextmenu.ScilabContextMenu;
 import org.scilab.modules.gui.menu.Menu;
 import org.scilab.modules.gui.menu.ScilabMenu;
+import org.scilab.modules.xcos.JavaController;
 import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
 import org.scilab.modules.xcos.actions.EditFormatAction;
 import org.scilab.modules.xcos.block.actions.BorderColorAction;
 import org.scilab.modules.xcos.graph.model.XcosCell;
@@ -62,6 +64,9 @@ public abstract class BasicLink extends XcosCell {
         setVertex(false);
         setEdge(true);
         setStyle(style + XcosOptions.getEdition().getEdgeStyle());
+
+        JavaController controller = new JavaController();
+        controller.setObjectProperty(getUID(), getKind(), ObjectProperties.KIND, getLinkKind());
     }
 
     /**
@@ -257,6 +262,9 @@ public abstract class BasicLink extends XcosCell {
     /** @return The scicos color and type values */
     public abstract double[][] getColorAndType();
 
+    /** the scicos kind */
+    public abstract int getLinkKind();
+
     /**
      * Open the contextual menu of the link
      *
index 1a39eda..cae4bc8 100644 (file)
@@ -37,4 +37,11 @@ public class CommandControlLink extends BasicLink {
         return COLOR_AND_TYPE;
     }
 
+    @Override
+    public int getLinkKind() {
+        return -1;
+    }
+
+
+
 }
index b969ffb..915d3d2 100644 (file)
@@ -36,4 +36,9 @@ public class ExplicitLink extends BasicLink {
     public double[][] getColorAndType() {
         return COLOR_AND_TYPE;
     }
+
+    @Override
+    public int getLinkKind() {
+        return 1;
+    }
 }
index b200430..f02c04a 100644 (file)
@@ -36,4 +36,9 @@ public class ImplicitLink extends BasicLink {
     public double[][] getColorAndType() {
         return COLOR_AND_TYPE;
     }
+
+    @Override
+    public int getLinkKind() {
+        return 2;
+    }
 }
index 5136e14..54e48d1 100644 (file)
@@ -17,6 +17,7 @@ import org.scilab.modules.types.ScilabType;
 import org.scilab.modules.xcos.JavaController;
 import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.PortKind;
 import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.graph.model.XcosCell;
 
@@ -128,6 +129,7 @@ public abstract class BasicPort extends XcosCell {
         boolean isImplicit = getType() == Type.IMPLICIT;
         JavaController controller = new JavaController();
         controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.IMPLICIT, isImplicit);
+        controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.PORT_KIND, getPortKind().ordinal());
     }
 
     /**
@@ -135,6 +137,8 @@ public abstract class BasicPort extends XcosCell {
      */
     public abstract Type getType();
 
+    public abstract PortKind getPortKind();
+
     /** @return The default orientation of this port */
     public final Orientation getOrientation() {
         return orientation;
index ad2ab87..d3da4f2 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.scilab.modules.xcos.port.command;
 
+import org.scilab.modules.xcos.PortKind;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
 
@@ -36,4 +37,9 @@ public class CommandPort extends BasicPort {
     public Type getType() {
         return null;
     }
+
+    @Override
+    public PortKind getPortKind() {
+        return PortKind.PORT_EOUT;
+    }
 }
index 0141025..070707a 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.scilab.modules.xcos.port.control;
 
+import org.scilab.modules.xcos.PortKind;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
 
@@ -42,4 +43,9 @@ public class ControlPort extends BasicPort {
         return null;
     }
 
+    @Override
+    public PortKind getPortKind() {
+        return PortKind.PORT_EIN;
+    }
+
 }
index 6e87c58..fc4a624 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.scilab.modules.xcos.port.input;
 
+import org.scilab.modules.xcos.PortKind;
+
 /**
  * An explicit output port is a port where the transfer of information has a
  * 'IN' direction.
@@ -30,5 +32,4 @@ public class ExplicitInputPort extends InputPort {
     public Type getType() {
         return Type.EXPLICIT;
     }
-
 }
index ef2fb64..4235498 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.scilab.modules.xcos.port.input;
 
+import org.scilab.modules.xcos.PortKind;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
 
@@ -35,4 +36,9 @@ public abstract class InputPort extends BasicPort {
     protected InputPort(long uid, String style) {
         super(uid, style, Orientation.WEST);
     }
+
+    @Override
+    public PortKind getPortKind() {
+        return PortKind.PORT_IN;
+    }
 }
index 89960b4..b0e2ee0 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.scilab.modules.xcos.port.output;
 
+import org.scilab.modules.xcos.PortKind;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
 
@@ -35,4 +36,9 @@ public abstract class OutputPort extends BasicPort {
     public OutputPort(long uid, String style) {
         super(uid, style, Orientation.EAST);
     }
+
+    @Override
+    public PortKind getPortKind() {
+        return PortKind.PORT_OUT;
+    }
 }
@@ -10,7 +10,7 @@
  *
  */
 
-package org.scilab.modules.xcos.io.sax;
+package org.scilab.modules.xcos.utils;
 
 import java.util.ArrayList;
 import java.util.Vector;
@@ -24,7 +24,7 @@ import java.util.stream.Stream;
  * @param <E>
  *            the contained item klass
  */
-class Stack<E> {
+public class Stack<E> {
     private ArrayList<E> stack = new ArrayList<>();
 
     public void pop() {
index ee12a8e..601426f 100644 (file)
@@ -99,7 +99,9 @@ namespace std {
                 void* buffer = nullptr;
                 int size = int(self->size()) ;
                 if (i>=0 && i<size) {
-                    buffer = ((char*) self->data()) + i;
+                    buffer = self->data() + i;
+                } else if (i==0 && size == 0) {
+                    buffer = self->data();
                 } else {
                     throw std::out_of_range("vector index out of range");
                 }
index efff679..4e1f566 100644 (file)
@@ -718,7 +718,9 @@ SWIGINTERN void *std_vector_Sl_int_Sg__asByteBuffer(std::vector< int > *self,int
                 void* buffer = nullptr;
                 int size = int(self->size()) ;
                 if (i>=0 && i<size) {
-                    buffer = ((char*) self->data()) + i;
+                    buffer = self->data() + i;
+                } else if (i==0 && size == 0) {
+                    buffer = self->data();
                 } else {
                     throw std::out_of_range("vector index out of range");
                 }
@@ -797,7 +799,9 @@ SWIGINTERN void *std_vector_Sl_double_Sg__asByteBuffer(std::vector< double > *se
                 void* buffer = nullptr;
                 int size = int(self->size()) ;
                 if (i>=0 && i<size) {
-                    buffer = ((char*) self->data()) + i;
+                    buffer = self->data() + i;
+                } else if (i==0 && size == 0) {
+                    buffer = self->data();
                 } else {
                     throw std::out_of_range("vector index out of range");
                 }
@@ -847,7 +851,9 @@ SWIGINTERN void *std_vector_Sl_std_string_Sg__asByteBuffer(std::vector< std::str
                 void* buffer = nullptr;
                 int size = int(self->size()) ;
                 if (i>=0 && i<size) {
-                    buffer = ((char*) self->data()) + i;
+                    buffer = self->data() + i;
+                } else if (i==0 && size == 0) {
+                    buffer = self->data();
                 } else {
                     throw std::out_of_range("vector index out of range");
                 }
@@ -897,7 +903,9 @@ SWIGINTERN void *std_vector_Sl_ScicosID_Sg__asByteBuffer(std::vector< ScicosID >
                 void* buffer = nullptr;
                 int size = int(self->size()) ;
                 if (i>=0 && i<size) {
-                    buffer = ((char*) self->data()) + i;
+                    buffer = self->data() + i;
+                } else if (i==0 && size == 0) {
+                    buffer = self->data();
                 } else {
                     throw std::out_of_range("vector index out of range");
                 }
@@ -1409,6 +1417,31 @@ SWIGEXPORT jlong JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_Controll
 }
 
 
+SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_Controller_1sortAndFillKind(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jlong jarg3, jobject jarg3_) {
+  org_scilab_modules_scicos::Controller *arg1 = (org_scilab_modules_scicos::Controller *) 0 ;
+  std::vector< ScicosID > *arg2 = 0 ;
+  std::vector< int > *arg3 = 0 ;
+  
+  (void)jenv;
+  (void)jcls;
+  (void)jarg1_;
+  (void)jarg2_;
+  (void)jarg3_;
+  arg1 = *(org_scilab_modules_scicos::Controller **)&jarg1; 
+  arg2 = *(std::vector< ScicosID > **)&jarg2;
+  if (!arg2) {
+    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "std::vector< ScicosID > & reference is null");
+    return ;
+  } 
+  arg3 = *(std::vector< int > **)&jarg3;
+  if (!arg3) {
+    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "std::vector< int > & reference is null");
+    return ;
+  } 
+  (arg1)->sortAndFillKind(*arg2,*arg3);
+}
+
+
 SWIGEXPORT jboolean JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_Controller_1getObjectProperty_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jint jarg3, jint jarg4, jintArray jarg5) {
   jboolean jresult = 0 ;
   org_scilab_modules_scicos::Controller *arg1 = (org_scilab_modules_scicos::Controller *) 0 ;
index 70c416d..da5c1db 100644 (file)
@@ -104,7 +104,7 @@ curEnv->DeleteLocalRef(localInstance);
 
                 /* Methods ID set to NULL */
 voidxcosjstringjava_lang_StringjlonglongID=NULL;
-voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID=NULL;
+voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID=NULL;
 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
 voidcloseXcosFromScilabID=NULL;
 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
@@ -132,7 +132,7 @@ throw GiwsException::JniObjectCreationException(curEnv, this->className());
         }
         /* Methods ID set to NULL */
         voidxcosjstringjava_lang_StringjlonglongID=NULL;
-voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID=NULL;
+voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID=NULL;
 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
 voidcloseXcosFromScilabID=NULL;
 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
@@ -184,7 +184,7 @@ throw GiwsException::JniCallMethodException(curEnv);
 }
 }
 
-void Xcos::xcosDiagramToScilab (JavaVM * jvm_, char const* file, long long diagramId){
+void Xcos::xcosDiagramToScilab (JavaVM * jvm_, char const* file, long long diagramId, bool exported){
 
 JNIEnv * curEnv = NULL;
 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
@@ -193,8 +193,8 @@ if ( cls == NULL) {
 throw GiwsException::JniCallMethodException(curEnv);
 }
 
-static jmethodID voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID = curEnv->GetStaticMethodID(cls, "xcosDiagramToScilab", "(Ljava/lang/String;J)V" ) ;
-if (voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID == NULL) {
+static jmethodID voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID = curEnv->GetStaticMethodID(cls, "xcosDiagramToScilab", "(Ljava/lang/String;JZ)V" ) ;
+if (voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID == NULL) {
 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramToScilab");
 }
 
@@ -205,7 +205,9 @@ throw GiwsException::JniBadAllocException(curEnv);
 }
 
 
-                         curEnv->CallStaticVoidMethod(cls, voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID ,file_, diagramId);
+jboolean exported_ = (static_cast<bool>(exported) ? JNI_TRUE : JNI_FALSE);
+
+                         curEnv->CallStaticVoidMethod(cls, voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID ,file_, diagramId, exported_);
                         curEnv->DeleteLocalRef(file_);
 if (curEnv->ExceptionCheck()) {
 throw GiwsException::JniCallMethodException(curEnv);
index b0ad5ac..2e52825 100644 (file)
@@ -8,6 +8,7 @@
         <method name="xcosDiagramToScilab" returnType="void" modifier="static">
             <parameter name="file" type="String"/>
             <parameter name="diagramId" type="long"/>
+            <parameter name="exported" type="boolean"/>
         </method>
         <method name="warnCellByUID" returnType="void" modifier="static">
             <parameter name="uids" type="String[]"/>
index ccac809..effbd6e 100644 (file)
@@ -77,7 +77,7 @@ JavaVM * jvm;
 
 protected:
 jmethodID voidxcosjstringjava_lang_StringjlonglongID; // cache method id
-jmethodID voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID; // cache method id
+jmethodID voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID; // cache method id
 jmethodID voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID; // cache method id
 jclass stringArrayClass;
 jmethodID voidcloseXcosFromScilabID; // cache method id
@@ -144,7 +144,7 @@ void endSynchronize();
 // Methods
 static void xcos(JavaVM * jvm_, char const* file, long long diagramId);
 
-static void xcosDiagramToScilab(JavaVM * jvm_, char const* file, long long diagramId);
+static void xcosDiagramToScilab(JavaVM * jvm_, char const* file, long long diagramId, bool exported);
 
 static void warnCellByUID(JavaVM * jvm_, char const* const* uids, int uidsSize, char const* message);
 
diff --git a/scilab/modules/xcos/tests/unit_tests/empty.xcos b/scilab/modules/xcos/tests/unit_tests/empty.xcos
new file mode 100644 (file)
index 0000000..449b716
Binary files /dev/null and b/scilab/modules/xcos/tests/unit_tests/empty.xcos differ
diff --git a/scilab/modules/xcos/tests/unit_tests/xcosDiagramToScilab.dia.ref b/scilab/modules/xcos/tests/unit_tests/xcosDiagramToScilab.dia.ref
new file mode 100644 (file)
index 0000000..a71c6f8
--- /dev/null
@@ -0,0 +1,32 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) DIGITEO - 2015-2015 - Clément DAVID
+//
+// This file is distributed under the same license as the Scilab package.
+// <-- XCOS TEST -->
+//
+// <-- Short Description -->
+// Internal test to check that xcos files and zcos files can be loaded and saved
+function check_file(path, file)
+    // load the empty file and save it
+    mprintf("IMPORT %s\n", SCI+"/"+path+"/"+file);
+    scs_m = xcosDiagramToScilab(SCI+"/"+path+"/"+file)
+    mprintf("EXPORT %s\n", TMPDIR+"/"+file);
+    xcosDiagramToScilab(TMPDIR+"/"+file, scs_m)
+    // then reload it and check that the two diagrams are equals
+    old_scs_m = scs_m;
+    mprintf("REIMPORT %s\n", TMPDIR+"/"+file);
+    scs_m = xcosDiagramToScilab(TMPDIR+"/"+file);
+    //    assert_checktrue(old_scs_m == scs_m);
+endfunction
+check_file("modules/xcos/tests/unit_tests", "empty.xcos");
+IMPORT SCI/modules/xcos/tests/unit_tests/empty.xcos
+EXPORT TMPDIR/empty.xcos
+REIMPORT TMPDIR/empty.xcos
+check_file("modules/xcos/tests/unit_tests", "empty.zcos");
+IMPORT SCI/modules/xcos/tests/unit_tests/empty.zcos
+EXPORT TMPDIR/empty.zcos
+REIMPORT TMPDIR/empty.zcos
+check_file("modules/xcos/demos", "Simple_Demo.zcos");
+IMPORT SCI/modules/xcos/demos/Simple_Demo.zcos
+EXPORT TMPDIR/Simple_Demo.zcos
+REIMPORT TMPDIR/Simple_Demo.zcos
diff --git a/scilab/modules/xcos/tests/unit_tests/xcosDiagramToScilab.tst b/scilab/modules/xcos/tests/unit_tests/xcosDiagramToScilab.tst
new file mode 100644 (file)
index 0000000..f7db8b7
--- /dev/null
@@ -0,0 +1,30 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) DIGITEO - 2015-2015 - Clément DAVID
+//
+// This file is distributed under the same license as the Scilab package.
+
+// <-- XCOS TEST -->
+//
+// <-- Short Description -->
+// Internal test to check that xcos files and zcos files can be loaded and saved
+
+function check_file(path, file)
+
+    // load the empty file and save it
+    mprintf("IMPORT %s\n", SCI+"/"+path+"/"+file);
+    scs_m = xcosDiagramToScilab(SCI+"/"+path+"/"+file)
+    mprintf("EXPORT %s\n", TMPDIR+"/"+file);
+    xcosDiagramToScilab(TMPDIR+"/"+file, scs_m)
+
+    // then reload it and check that the two diagrams are equals
+    old_scs_m = scs_m;
+    mprintf("REIMPORT %s\n", TMPDIR+"/"+file);
+    scs_m = xcosDiagramToScilab(TMPDIR+"/"+file);
+    //    assert_checktrue(old_scs_m == scs_m);
+endfunction
+
+check_file("modules/xcos/tests/unit_tests", "empty.xcos");
+check_file("modules/xcos/tests/unit_tests", "empty.zcos");
+
+check_file("modules/xcos/demos", "Simple_Demo.zcos");
+