Xcos: reintroduce a private xcosDiagramToScilab 27/17327/5
Clément DAVID [Tue, 13 Oct 2015 14:25:57 +0000 (16:25 +0200)]
importXcosDiagram use this helper to decode files using the Java
implementation. The rationale behind : `importXcosDiagram` is a public
function that manage all supported file types whereas `xcosDiagramToScilab`
is an helper used to call the Java implemented decoders.

NOTE: This commit also slightly improve the decoding of XCOS and ZCOS
diagrams.

Change-Id: I3f7329194e728e60bce8b47033b28b77969a9002

27 files changed:
scilab/modules/xcos/Makefile.am
scilab/modules/xcos/Makefile.in
scilab/modules/xcos/macros/importXcosDiagram.sci
scilab/modules/xcos/sci_gateway/cpp/sci_xcosDiagramToScilab.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/xcos_gateway.xml
scilab/modules/xcos/src/c/xcos.vcxproj
scilab/modules/xcos/src/c/xcos.vcxproj.filters
scilab/modules/xcos/src/java/org/scilab/modules/xcos/JavaControllerJNI.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfBool.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfDouble.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfInt.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfScicosID.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/VectorOfString.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCellFactory.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/HandledElement.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/SAXHandler.java
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/nonreg_tests/bug_7537.tst

index aca72b9..1e7f0bc 100644 (file)
@@ -73,6 +73,7 @@ GATEWAY_CXX_SOURCES = \
        sci_gateway/cpp/sci_warnBlockByUID.cpp \
        sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
        sci_gateway/cpp/sci_xcosCellCreated.cpp \
+       sci_gateway/cpp/sci_xcosDiagramToScilab.cpp \
        sci_gateway/cpp/sci_xcosPalLoad.cpp \
        sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
        sci_gateway/cpp/sci_xcosPalDelete.cpp \
index b61abff..92ba502 100644 (file)
@@ -210,6 +210,7 @@ am__objects_4 = sci_gateway/cpp/libscixcos_la-sci_Xcos.lo \
        sci_gateway/cpp/libscixcos_la-sci_warnBlockByUID.lo \
        sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo \
+       sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosPalCategoryAdd.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosPalDelete.lo \
@@ -652,6 +653,7 @@ GATEWAY_CXX_SOURCES = \
        sci_gateway/cpp/sci_warnBlockByUID.cpp \
        sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
        sci_gateway/cpp/sci_xcosCellCreated.cpp \
+       sci_gateway/cpp/sci_xcosDiagramToScilab.cpp \
        sci_gateway/cpp/sci_xcosPalLoad.cpp \
        sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
        sci_gateway/cpp/sci_xcosPalDelete.cpp \
@@ -1246,6 +1248,9 @@ sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo:  \
 sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
@@ -1307,6 +1312,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosAddToolsMenu.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosCellCreated.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosConfigureXmlFile.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalCategoryAdd.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalDelete.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalDisable.Plo@am__quote@
@@ -1457,6 +1463,13 @@ sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo: sci_gateway/cpp/sci_xcosCe
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo `test -f 'sci_gateway/cpp/sci_xcosCellCreated.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosCellCreated.cpp
 
+sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo: sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo `test -f 'sci_gateway/cpp/sci_xcosDiagramToScilab.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_xcosDiagramToScilab.cpp' object='sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo `test -f 'sci_gateway/cpp/sci_xcosDiagramToScilab.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
+
 sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo: sci_gateway/cpp/sci_xcosPalLoad.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo `test -f 'sci_gateway/cpp/sci_xcosPalLoad.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalLoad.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Plo
index 1d1ab9f..09d97a3 100644 (file)
@@ -1,6 +1,7 @@
 //
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2009 - DIGITEO - Antoine ELIAS
+// 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
@@ -29,16 +30,28 @@ function result = importXcosDiagram(xcosFile)
             return;
         end
         // construct a full path string
-        fullPathName = get_absolute_file_path(fname + extension) + fname + extension;
+        fullPathName = get_absolute_file_path(fname + extension) + fname + convstr(extension, "l");
         mclose(a);
     else
         error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected." + "\n"), "importXcosDiagram", 1));
         return;
     end
 
-    // import the real file
-    scs_m = scicos_diagram();
-    convertStatus = xcos(fullPathName, scs_m);
+    // decode scilab managed file format
+    [path,fname,extension] = fileparts(fullPathName);
+    select extension
+    case "sod"  then
+        load(fullPathName, "scs_m");
+    case "h5"   then
+        load(fullPathName, "scs_m");
+    case "cosf" then
+        exec(fullPathName);
+    case "cos"  then
+        error(msprintf(gettext("%s: Not supported format %s.\n"), "importXcosDiagram", extension));
+    else
+        // on the Java side
+        scs_m = xcosDiagramToScilab(fullPathName);
+    end
 
     //return scs_m in Scilab environment
     result = %t;
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosDiagramToScilab.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
new file mode 100644 (file)
index 0000000..7cb01f3
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) DIGITEO - 2009-2009 - Antoine ELIAS <antoine.elias@scilab.org>
+ * Copyright (C) DIGITEO - 2009-2010 - Clément DAVID <clement.david@scilab.org>
+ *
+ * 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
+ *
+ */
+/*--------------------------------------------------------------------------*/
+#include "Xcos.hxx"
+#include "GiwsException.hxx"
+#include "loadStatus.hxx"
+#include "Controller.hxx"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "sci_malloc.h"
+#include "freeArrayOfString.h"
+#include "getScilabJavaVM.h"
+}
+/*--------------------------------------------------------------------------*/
+using namespace org_scilab_modules_xcos;
+
+/*--------------------------------------------------------------------------*/
+int sci_xcosDiagramToScilab(char *fname, void *pvApiCtx)
+{
+    CheckRhs(1, 1);
+    CheckLhs(0, 1);
+
+    SciErr sciErr;
+
+    int iRows1 = 0;
+    int iCols1 = 0;
+    int iLen1 = 0;
+    int *piAddr1 = NULL;
+    char *pstXcosFile = NULL;
+
+    //get xcos filename
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+        return 0;
+    }
+
+    //get xcos filename matrix dimension
+    sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows1, &iCols1, NULL, NULL);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+        return 0;
+    }
+
+    if (iRows1 != 1 || iCols1 != 1)
+    {
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+    }
+
+    //get xcos filename length
+    sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows1, &iCols1, &iLen1, NULL);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+        return 0;
+    }
+
+    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)
+    {
+        printError(&sciErr, 0);
+        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
+        return 0;
+    }
+
+    /*
+     * Call the Java implementation on an existing diagram UID
+     */
+    org_scilab_modules_scicos::Controller controller;
+    ScicosID uid = controller.createObject(DIAGRAM);
+
+    set_loaded_status(XCOS_CALLED);
+    try
+    {
+        Xcos::xcosDiagramToScilab(getScilabJavaVM(), pstXcosFile, uid);
+    }
+    catch (GiwsException::JniCallMethodException &exception)
+    {
+        Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
+        controller.deleteObject(uid);
+        return 0;
+    }
+    catch (GiwsException::JniException &exception)
+    {
+        Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
+        controller.deleteObject(uid);
+        return 0;
+    }
+
+    sciErr = createMatrixOfInteger64(pvApiCtx, Rhs + 1, 1, 1, &uid);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        Scierror(999, _("%s: Memory allocation error.\n"), fname);
+        return 0;
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+    return 0;
+}
+
+/*--------------------------------------------------------------------------*/
index c711e49..31b766b 100644 (file)
@@ -33,6 +33,7 @@
     <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" />
index 6cbd426..0fecdf2 100644 (file)
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosDiagramToScilab.cpp" />
     <ClCompile Include="..\cpp\loadStatus.cpp" />
     <ClCompile Include="..\jni\JavaController_wrap.cxx" />
     <ClCompile Include="..\jni\XcosCellFactory.cpp" />
index abce708..26a2cd7 100644 (file)
@@ -95,6 +95,9 @@
     <ClCompile Include="..\jni\XcosCellFactory.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosDiagramToScilab.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_xcos.h">
index f8bf538..b661fa0 100644 (file)
@@ -50,6 +50,7 @@ public class JavaControllerJNI {
   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_);
@@ -63,10 +64,9 @@ public class JavaControllerJNI {
   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 long VectorOfBool_size(long jarg1, VectorOfBool jarg1_);
-  public final static native long VectorOfBool_capacity(long jarg1, VectorOfBool 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);
@@ -78,6 +78,7 @@ public class JavaControllerJNI {
   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_);
@@ -92,6 +93,7 @@ public class JavaControllerJNI {
   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_);
@@ -106,6 +108,7 @@ public class JavaControllerJNI {
   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_);
index 8a67bb0..bbb2ea0 100644 (file)
@@ -43,14 +43,6 @@ public class VectorOfBool {
     this(JavaControllerJNI.new_VectorOfBool__SWIG_1(n), true);
   }
 
-  public long size() {
-    return JavaControllerJNI.VectorOfBool_size(swigCPtr, this);
-  }
-
-  public long capacity() {
-    return JavaControllerJNI.VectorOfBool_capacity(swigCPtr, this);
-  }
-
   public void ensureCapacity(long n) {
     JavaControllerJNI.VectorOfBool_ensureCapacity(swigCPtr, this, n);
   }
@@ -59,6 +51,10 @@ public class VectorOfBool {
     JavaControllerJNI.VectorOfBool_resize(swigCPtr, this, n);
   }
 
+  public int size() {
+    return JavaControllerJNI.VectorOfBool_size(swigCPtr, this);
+  }
+
   public boolean isEmpty() {
     return JavaControllerJNI.VectorOfBool_isEmpty(swigCPtr, this);
   }
index f1f296a..ed2d7a3 100644 (file)
@@ -47,6 +47,10 @@ public class VectorOfDouble {
     JavaControllerJNI.VectorOfDouble_ensureCapacity(swigCPtr, this, n);
   }
 
+  public void resize(long n) {
+    JavaControllerJNI.VectorOfDouble_resize(swigCPtr, this, n);
+  }
+
   public int size() {
     return JavaControllerJNI.VectorOfDouble_size(swigCPtr, this);
   }
index 016d0f4..a245c31 100644 (file)
@@ -47,6 +47,10 @@ public class VectorOfInt {
     JavaControllerJNI.VectorOfInt_ensureCapacity(swigCPtr, this, n);
   }
 
+  public void resize(long n) {
+    JavaControllerJNI.VectorOfInt_resize(swigCPtr, this, n);
+  }
+
   public int size() {
     return JavaControllerJNI.VectorOfInt_size(swigCPtr, this);
   }
index 4b1ebdb..7249e7f 100644 (file)
@@ -47,6 +47,10 @@ public class VectorOfScicosID {
     JavaControllerJNI.VectorOfScicosID_ensureCapacity(swigCPtr, this, n);
   }
 
+  public void resize(long n) {
+    JavaControllerJNI.VectorOfScicosID_resize(swigCPtr, this, n);
+  }
+
   public int size() {
     return JavaControllerJNI.VectorOfScicosID_size(swigCPtr, this);
   }
index 6ba24a0..8c372ff 100644 (file)
@@ -47,6 +47,10 @@ public class VectorOfString {
     JavaControllerJNI.VectorOfString_ensureCapacity(swigCPtr, this, n);
   }
 
+  public void resize(long n) {
+    JavaControllerJNI.VectorOfString_resize(swigCPtr, this, n);
+  }
+
   public int size() {
     return JavaControllerJNI.VectorOfString_size(swigCPtr, this);
   }
index 2d01013..e65b7be 100644 (file)
@@ -57,6 +57,7 @@ import org.scilab.modules.xcos.configuration.ConfigurationManager;
 import org.scilab.modules.xcos.configuration.model.DocumentType;
 import org.scilab.modules.xcos.graph.DiagramComparator;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.io.XcosFileType;
 import org.scilab.modules.xcos.palette.PaletteManager;
 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
 import org.scilab.modules.xcos.preferences.XcosConfiguration;
@@ -849,6 +850,31 @@ public final class Xcos {
     }
 
     /**
+     * Load 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
+     *
+     * @param file the file
+     * @param diagramId the diagram to load into
+     * @throws Exception on loading error
+     */
+    @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
+    public static void xcosDiagramToScilab(String file, long diagramId) throws Exception {
+        XcosFileType filetype = XcosFileType.findFileType(file);
+        if (filetype == null) {
+            throw new IllegalArgumentException("not handled filetype");
+        }
+        switch (filetype) {
+            case XCOS:
+            case ZCOS:
+                filetype.load(file, new XcosDiagram(diagramId, Kind.DIAGRAM));
+                break;
+            case COSF:
+                throw new IllegalArgumentException("not handled filetype");
+        }
+    }
+
+    /**
      * Close the current xcos session from any thread.
      *
      * This method invoke Xcos operation on the EDT thread. Please prefer using
index 90ec52a..20f653d 100644 (file)
@@ -180,7 +180,7 @@ public final class XcosCellFactory {
             }
 
             int destIndex = Collections.binarySearch(ports, new XcosCell(dest[0], Kind.PORT), compare);
-            if (destIndex > 0) {
+            if (destIndex >= 0) {
                 l.setTarget(ports.get(destIndex));
             } else {
                 throw new IllegalStateException();
index 07a02f3..13acb9f 100644 (file)
@@ -12,7 +12,9 @@
 
 package org.scilab.modules.xcos.io.sax;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.stream.Stream;
 
@@ -24,6 +26,7 @@ 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.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
 import org.xml.sax.Attributes;
@@ -162,17 +165,31 @@ class CustomHandler implements ScilabHandler {
             case Orientation:
                 break;
             case XcosDiagram:
+                resolve();
+                saxHandler.allChildren.pop();
                 XcosCellFactory.insertChildren(saxHandler.controller, saxHandler.root);
                 break;
             case SuperBlockDiagram:
+                resolve();
                 saxHandler.allChildren.pop();
                 break;
             default:
                 throw new IllegalArgumentException();
         }
+    }
+
+    private void resolve() {
+        HashMap<String, Long> allLocalChildren = saxHandler.allChildren.peek();
 
-        // FIXME manage unresolved link source
-        // FIXME manage unresolved link target
+        for (Entry<String, ArrayList<UnresolvedReference>> entry : saxHandler.unresolvedReferences.entrySet()) {
+            Long uidObject = allLocalChildren.get(entry.getKey());
+            if (uidObject != null) {
+                long uid = uidObject.longValue();
 
+                for (UnresolvedReference unresolvedReference : entry.getValue()) {
+                    unresolvedReference.resolve(saxHandler.controller, uid);
+                }
+            }
+        }
     }
 }
\ No newline at end of file
index 0a5b6e3..afd0b48 100644 (file)
@@ -65,7 +65,7 @@ enum HandledElement {
     SuperBlockDiagram(HandledElementsCategory.CUSTOM),
     TextBlock(HandledElementsCategory.BLOCK),
     VoltageSensorBlock(HandledElementsCategory.BLOCK),
-    XcosDiagram(HandledElementsCategory.CUSTOM),;
+    XcosDiagram(HandledElementsCategory.CUSTOM);
 
     static Map<String, HandledElement> getMap() {
         Map<String, HandledElement> map = new HashMap<>(HandledElement.values().length);
index 12d7478..9d144ae 100644 (file)
 
 package org.scilab.modules.xcos.io.sax;
 
+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.link.BasicLink;
 import org.scilab.modules.xcos.link.commandcontrol.CommandControlLink;
 import org.scilab.modules.xcos.link.explicit.ExplicitLink;
@@ -26,32 +30,35 @@ class LinkHandler implements ScilabHandler {
 
     /**
      * Default constructor
-     * @param saxHandler the shared sax handler
+     * 
+     * @param saxHandler
+     *            the shared sax handler
      */
     LinkHandler(SAXHandler saxHandler) {
         this.saxHandler = saxHandler;
     }
 
+    @Override
     public BasicLink startElement(HandledElement found, Attributes atts) {
         String v;
         BasicLink link;
         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);
-                break;
-            case ExplicitLink:
-                link = new ExplicitLink(uid);
-                saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, 1);
-                break;
-            case ImplicitLink:
-                link = new ImplicitLink(uid);
-                saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, 2);
-                break;
-            default:
-                throw new IllegalArgumentException();
+        case CommandControlLink:
+            link = new CommandControlLink(uid);
+            saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, -1);
+            break;
+        case ExplicitLink:
+            link = new ExplicitLink(uid);
+            saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, 1);
+            break;
+        case ImplicitLink:
+            link = new ImplicitLink(uid);
+            saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.KIND, 2);
+            break;
+        default:
+            throw new IllegalArgumentException();
         }
 
         /*
@@ -65,18 +72,38 @@ class LinkHandler implements ScilabHandler {
 
         v = atts.getValue("source");
         if (v != null) {
-            // if the attribute is present then the connected port is already
-            // decoded and present in the map
-            long src = saxHandler.allChildren.peek().get(v);
-            saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.SOURCE_PORT, src);
+            Long src = saxHandler.allChildren.peek().get(v);
+            if (src != null) {
+                // if the attribute is present then the connected port is already
+                // decoded and present in the map
+                saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.SOURCE_PORT, src.longValue());
+            } else {
+                // if not present then it will be resolved later
+                ArrayList<UnresolvedReference> refList = saxHandler.unresolvedReferences.get(v);
+                if (refList == null) {
+                    refList = new ArrayList<>();
+                    saxHandler.unresolvedReferences.put(v, refList);
+                }
+                refList.add(new UnresolvedReference(new ScicosObjectOwner(uid, Kind.LINK), ObjectProperties.SOURCE_PORT, null, 0));
+            }
         }
 
         v = atts.getValue("target");
         if (v != null) {
-            // if the attribute is present then the connected port is already
-            // decoded and present in the map
-            long dst = saxHandler.allChildren.peek().get(v);
-            saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.DESTINATION_PORT, dst);
+            Long dst = saxHandler.allChildren.peek().get(v);
+            if (dst != null) {
+                // if the attribute is present then the connected port is already
+                // decoded and present in the map
+                saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.DESTINATION_PORT, dst.longValue());
+            } else {
+                // if not present then it will be resolved later
+                ArrayList<UnresolvedReference> refList = saxHandler.unresolvedReferences.get(v);
+                if (refList == null) {
+                    refList = new ArrayList<>();
+                    saxHandler.unresolvedReferences.put(v, refList);
+                }
+                refList.add(new UnresolvedReference(new ScicosObjectOwner(uid, Kind.LINK), ObjectProperties.DESTINATION_PORT, null, 0));
+            }
         }
 
         v = atts.getValue("style");
@@ -93,6 +120,7 @@ class LinkHandler implements ScilabHandler {
         return link;
     }
 
+    @Override
     public void endElement(HandledElement found) {
     }
 }
\ No newline at end of file
index b15fe49..9c7c0e1 100644 (file)
@@ -133,7 +133,8 @@ class PortHandler implements ScilabHandler {
         VectorOfScicosID associatedPorts = new VectorOfScicosID();
         saxHandler.controller.getObjectProperty(parent, Kind.BLOCK, relatedProperty, associatedPorts);
 
-        associatedPorts.add(ordering, uid);
+        associatedPorts.resize(ordering + 1);
+        associatedPorts.set(ordering, uid);
         saxHandler.controller.referenceObject(uid);
 
         saxHandler.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.SOURCE_BLOCK, parent);
index 154f216..6fa67a0 100644 (file)
 
 package org.scilab.modules.xcos.io.sax;
 
-import java.beans.BeanDescriptor;
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.beans.SimpleBeanInfo;
-import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -30,9 +25,12 @@ import org.scilab.modules.types.ScilabList;
 import org.scilab.modules.types.ScilabMList;
 import org.scilab.modules.types.ScilabString;
 import org.scilab.modules.types.ScilabTList;
+import org.scilab.modules.types.ScilabType;
 import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfDouble;
 import org.scilab.modules.xcos.VectorOfString;
 import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
+import org.scilab.modules.xcos.graph.model.XcosCell;
 import org.xml.sax.Attributes;
 
 import com.mxgraph.model.mxGeometry;
@@ -49,7 +47,7 @@ class RawDataHandler implements ScilabHandler {
         public RawDataDescriptor(ObjectProperties as, HandledElement found, String scilabClass, Object container) {
             // defensive programming
             if (as == null) {
-                throw new IllegalAccessError();
+                throw new IllegalArgumentException();
             }
 
             this.as = as;
@@ -71,6 +69,7 @@ class RawDataHandler implements ScilabHandler {
 
         Map<String, ObjectProperties> localPropertyMap = new HashMap<>();
         localPropertyMap.put("context", ObjectProperties.DIAGRAM_CONTEXT);
+        localPropertyMap.put("dState", ObjectProperties.DSTATE);
         localPropertyMap.put("equations", ObjectProperties.EQUATIONS);
         localPropertyMap.put("exprs", ObjectProperties.EXPRS);
         localPropertyMap.put("integerParameters", ObjectProperties.IPAR);
@@ -80,10 +79,14 @@ class RawDataHandler implements ScilabHandler {
         localPropertyMap.put("oDState", ObjectProperties.ODSTATE);
         localPropertyMap.put("points", ObjectProperties.CONTROL_POINTS);
         localPropertyMap.put("realParameters", ObjectProperties.RPAR);
-        // TODO might be incomplete
+        localPropertyMap.put("state", ObjectProperties.STATE);
         propertyMap = Collections.unmodifiableMap(localPropertyMap);
     }
 
+    /*
+     * Implement the ScilabHandler interface to decode the data
+     */
+
     public Object startElement(HandledElement found, Attributes atts) {
         String v;
 
@@ -138,68 +141,8 @@ class RawDataHandler implements ScilabHandler {
                     scilabClass = v;
                 }
 
-                // allocate the right class
-                final Object container;
-                switch (found) {
-                    case ScilabBoolean:
-                        container = new ScilabBoolean(new boolean[height][width]);
-                        break;
-                    case ScilabDouble:
-                        container = new ScilabDouble(new double[height][width]);
-                        break;
-                    case ScilabInteger:
-                        v = atts.getValue("intPrecision");
-                        if (v != null) {
-                            boolean unsigned = true;
-                            switch (ScilabIntegerTypeEnum.valueOf(v)) {
-                                case sci_int8:
-                                    unsigned = false;
-                                // no break on purpose
-                                case sci_uint8:
-                                    container = new ScilabInteger(new byte[height][width], unsigned);
-                                    break;
-                                case sci_int16:
-                                    unsigned = false;
-                                // no break on purpose
-                                case sci_uint16:
-                                    container = new ScilabInteger(new short[height][width], unsigned);
-                                    break;
-                                case sci_int32:
-                                    unsigned = false;
-                                // no break on purpose
-                                case sci_uint32:
-                                    container = new ScilabInteger(new int[height][width], unsigned);
-                                    break;
-                                case sci_int64:
-                                    unsigned = false;
-                                // no break on purpose
-                                case sci_uint64:
-                                    container = new ScilabInteger(new long[height][width], unsigned);
-                                    break;
-                                default:
-                                    container = new ScilabInteger(new long[height][width], false);
-                                    break;
-                            }
-                        } else {
-                            container = new ScilabInteger(new long[height][width], false);
-                        }
-                        break;
-                    case ScilabString:
-                        container = new ScilabString(new String[height][width]);
-                        break;
-                    default: // case Array
-                        if (scilabClass.equalsIgnoreCase("ScilabMList")) {
-                            container = new ScilabMList();
-                        } else if (scilabClass.equalsIgnoreCase("ScilabTList")) {
-                            container = new ScilabTList();
-                        } else if (scilabClass.equalsIgnoreCase("ScilabList")) {
-                            container = new ScilabList();
-                        } else {
-                            container = new ArrayList<>();
-                        }
-                        break;
-                }
-
+                // allocate the right class and push it to a descriptor
+                final Object container = allocateDataType(found, atts, height, width, scilabClass);
                 return new RawDataDescriptor(propertyMap.get(as), found, scilabClass, container);
             }
             case add: {
@@ -211,18 +154,14 @@ class RawDataHandler implements ScilabHandler {
 
                 switch (fieldValue.as) {
                     case DIAGRAM_CONTEXT: {
+                        @SuppressWarnings("unchecked")
                         ArrayList<String> container = ((ArrayList<String>) fieldValue.value);
                         container.add(atts.getValue("value"));
                         break;
                     }
-                    case CONTROL_POINTS: {
-                        // FIXME not implemented yet
-                        break;
-                    }
                     default:
                         break;
                 }
-
                 break;
             }
             case data: {
@@ -325,6 +264,80 @@ class RawDataHandler implements ScilabHandler {
         return null;
     }
 
+    /**
+     * Allocate a {@link ScilabType} datatype accordingly to the decoded descriptors
+     * @param found the decoded element
+     * @param atts the attributes of the element
+     * @param height decoded height
+     * @param width decoded width
+     * @param scilabClass decoded scilabClass
+     * @return the container
+     */
+    private Object allocateDataType(HandledElement found, Attributes atts, int height, int width, String scilabClass) {
+        String v;
+        final Object container;
+        switch (found) {
+            case ScilabBoolean:
+                container = new ScilabBoolean(new boolean[height][width]);
+                break;
+            case ScilabDouble:
+                container = new ScilabDouble(new double[height][width]);
+                break;
+            case ScilabInteger:
+                v = atts.getValue("intPrecision");
+                if (v != null) {
+                    boolean unsigned = true;
+                    switch (ScilabIntegerTypeEnum.valueOf(v)) {
+                        case sci_int8:
+                            unsigned = false;
+                        // no break on purpose
+                        case sci_uint8:
+                            container = new ScilabInteger(new byte[height][width], unsigned);
+                            break;
+                        case sci_int16:
+                            unsigned = false;
+                        // no break on purpose
+                        case sci_uint16:
+                            container = new ScilabInteger(new short[height][width], unsigned);
+                            break;
+                        case sci_int32:
+                            unsigned = false;
+                        // no break on purpose
+                        case sci_uint32:
+                            container = new ScilabInteger(new int[height][width], unsigned);
+                            break;
+                        case sci_int64:
+                            unsigned = false;
+                        // no break on purpose
+                        case sci_uint64:
+                            container = new ScilabInteger(new long[height][width], unsigned);
+                            break;
+                        default:
+                            container = new ScilabInteger(new long[height][width], false);
+                            break;
+                    }
+                } else {
+                    container = new ScilabInteger(new long[height][width], false);
+                }
+                break;
+            case ScilabString:
+                container = new ScilabString(new String[height][width]);
+                break;
+            default: // case Array
+                if ("ScilabMList".equals(scilabClass)) {
+                    container = new ScilabMList();
+                } else if ("ScilabTList".equals(scilabClass)) {
+                    container = new ScilabTList();
+                } else if ("ScilabList".equals(scilabClass)) {
+                    container = new ScilabList();
+                } else {
+                    container = new ArrayList<>();
+                }
+                break;
+        }
+        return container;
+    }
+
     public void endElement(HandledElement found) {
         switch (found) {
             case Array:
@@ -350,6 +363,8 @@ class RawDataHandler implements ScilabHandler {
                             return;
                         }
                         mxGeometry geom = (mxGeometry) parent;
+
+                        @SuppressWarnings("unchecked")
                         ArrayList<mxPoint> value = (ArrayList<mxPoint>) fieldValue.value;
                         geom.setPoints(value);
                         break;
@@ -361,6 +376,7 @@ class RawDataHandler implements ScilabHandler {
                         }
                         ScicosObjectOwner diagram = (ScicosObjectOwner) parent;
 
+                        @SuppressWarnings("unchecked")
                         ArrayList<String> value = (ArrayList<String>) fieldValue.value;
                         VectorOfString ctx = new VectorOfString(value.size());
                         for (int i = 0; i < value.size(); i++) {
@@ -369,10 +385,47 @@ class RawDataHandler implements ScilabHandler {
                         saxHandler.controller.setObjectProperty(diagram.getUID(), diagram.getKind(), ObjectProperties.DIAGRAM_CONTEXT, ctx);
                         break;
                     }
+                    case DSTATE:
+                    case NZCROSS:
+                    case NMODE:
+                    case IPAR:
+                    case RPAR: {
+                        // defensive programming
+                        if (!(parent instanceof XcosCell)) {
+                            return;
+                        }
+                        XcosCell cell = (XcosCell) parent;
+                        if (!(fieldValue.value instanceof ScilabDouble)) {
+                            // FIXME decode the rpar as a subdiagram using the legacy decoders
+                            return;
+                        }
+                        ScilabDouble value = (ScilabDouble) fieldValue.value;
+
+                        VectorOfDouble vec = new VectorOfDouble(value.getHeight());
+                        for (int i = 0; i < value.getHeight(); i++) {
+                            vec.set(i, value.getRealElement(i, 0));
+                        }
+
+                        saxHandler.controller.setObjectProperty(cell.getUID(), cell.getKind(), ObjectProperties.RPAR, vec);
+                        break;
+                    }
+                    case EQUATIONS:
+                    case ODSTATE: {
+                        // defensive programming
+                        if (!(parent instanceof XcosCell)) {
+                            return;
+                        }
+                        XcosCell cell = (XcosCell) parent;
+                        ScilabList value = (ScilabList) fieldValue.value;
+
+                        if (value.size() > 0) {
+                            System.err.println("RawDataHandler value not decoded: " + fieldValue.as);
+                        }
+                        break;
+                    }
                     default:
                         System.err.println("RawDataHandler not handled: " + fieldValue.as);
                         break;
-
                 }
                 break;
             }
@@ -385,4 +438,69 @@ class RawDataHandler implements ScilabHandler {
         }
     }
 
+    /*
+     * Convert the decoded data to a var2vec encoded value
+     */
+
+    private static void addMatrixHeader(VectorOfDouble vec, ScilabType var) {
+        vec.add(var.getType().swigValue());
+        vec.add(2); // we do not manage hypermatrices yet
+        vec.add(var.getHeight());
+        vec.add(var.getWidth());
+    }
+
+    public static VectorOfDouble var2vec(VectorOfDouble vec, ScilabBoolean var) {
+        addMatrixHeader(vec, var);
+
+
+        return vec;
+    }
+
+    public static VectorOfDouble var2vec(VectorOfDouble vec, ScilabDouble var) {
+        addMatrixHeader(vec, var);
+
+        // FIXME encode the values
+
+        return vec;
+    }
+
+    public static VectorOfDouble var2vec(VectorOfDouble vec, ScilabInteger var) {
+        addMatrixHeader(vec, var);
+
+        // FIXME encode the values
+
+        return vec;
+    }
+
+    public static VectorOfDouble var2vec(VectorOfDouble vec, ScilabString var) {
+        addMatrixHeader(vec, var);
+
+        // FIXME encode the values
+
+        return vec;
+    }
+
+    public static VectorOfDouble var2vec(VectorOfDouble vec, ScilabList var) {
+
+
+        // FIXME encode the values
+
+        return vec;
+    }
+
+    public static VectorOfDouble var2vec(VectorOfDouble vec, ScilabTList var) {
+
+
+        // FIXME encode the values
+
+        return vec;
+    }
+
+    public static VectorOfDouble var2vec(VectorOfDouble vec, ScilabMList var) {
+
+
+        // FIXME encode the values
+
+        return vec;
+    }
 }
\ No newline at end of file
index 48aa98b..a183595 100644 (file)
@@ -40,7 +40,7 @@ public class SAXHandler extends DefaultHandler {
     /*
      * Utilities classes and methods
      */
-    private static class UnresolvedReference {
+    protected static class UnresolvedReference {
         private ScicosObjectOwner owner;
         private ObjectProperties property;
         private ObjectProperties associatedProperty;
@@ -56,11 +56,15 @@ public class SAXHandler extends DefaultHandler {
         public void resolve(JavaController controller, long v) {
             controller.setObjectProperty(owner.getUID(), owner.getKind(), property, v);
 
-            VectorOfScicosID associated = new VectorOfScicosID();
-            controller.getObjectProperty(owner.getUID(), owner.getKind(), property, associated);
-            associated.ensureCapacity(associatedPropertyIndex + 1);
-            associated.set(associatedPropertyIndex, v);
-            controller.setObjectProperty(owner.getUID(), owner.getKind(), property, associated);
+            if (associatedProperty != null) {
+                VectorOfScicosID associated = new VectorOfScicosID();
+                controller.getObjectProperty(owner.getUID(), owner.getKind(), associatedProperty, associated);
+
+                associated.resize(associatedPropertyIndex + 1);
+                associated.set(associatedPropertyIndex, v);
+
+                controller.setObjectProperty(owner.getUID(), owner.getKind(), associatedProperty, associated);
+            }
         }
     }
 
@@ -123,9 +127,9 @@ public class SAXHandler extends DefaultHandler {
     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") + "\"");
+        //                char[] indent = new char[parents.size()];
+        //                Arrays.fill(indent, ' ');
+        //                System.err.println(new String(indent) + localName + " id=\"" + atts.getValue("id") + "\"");
         // DO NOT COMMIT
 
         HandledElement found = elementMap.get(localName);
index d8e96a0..98436eb 100644 (file)
@@ -47,6 +47,7 @@ namespace std {
         vector(size_type n);
         %rename(ensureCapacity) reserve;
         void reserve(size_type n);
+        void resize(size_type n);
         int size() const;
         %rename(isEmpty) empty;
         bool empty() const;
@@ -104,10 +105,10 @@ namespace std {
         typedef bool const_reference;
         vector();
         vector(size_type n);
-        size_type size() const;
-        size_type capacity() const;
+        %rename(ensureCapacity) reserve;
         void reserve(size_type n);
         void resize(size_type n);
+        int size() const;
         %rename(isEmpty) empty;
         bool empty() const;
         void clear();
index c06506f..c951759 100644 (file)
@@ -2038,6 +2038,19 @@ SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfI
 }
 
 
+SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfInt_1resize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
+  std::vector< int > *arg1 = (std::vector< int > *) 0 ;
+  std::vector< int >::size_type arg2 ;
+  
+  (void)jenv;
+  (void)jcls;
+  (void)jarg1_;
+  arg1 = *(std::vector< int > **)&jarg1; 
+  arg2 = (std::vector< int >::size_type)jarg2; 
+  (arg1)->resize(arg2);
+}
+
+
 SWIGEXPORT jint JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfInt_1size(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
   jint jresult = 0 ;
   std::vector< int > *arg1 = (std::vector< int > *) 0 ;
@@ -2259,37 +2272,20 @@ SWIGEXPORT jlong JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_new_1Vec
 }
 
 
-SWIGEXPORT jlong JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfBool_1size(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
-  jlong jresult = 0 ;
-  std::vector< bool > *arg1 = (std::vector< bool > *) 0 ;
-  std::vector< bool >::size_type result;
-  
-  (void)jenv;
-  (void)jcls;
-  (void)jarg1_;
-  arg1 = *(std::vector< bool > **)&jarg1; 
-  result = ((std::vector< bool > const *)arg1)->size();
-  jresult = (jlong)result; 
-  return jresult;
-}
-
-
-SWIGEXPORT jlong JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfBool_1capacity(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
-  jlong jresult = 0 ;
+SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfBool_1ensureCapacity(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
   std::vector< bool > *arg1 = (std::vector< bool > *) 0 ;
-  std::vector< bool >::size_type result;
+  std::vector< bool >::size_type arg2 ;
   
   (void)jenv;
   (void)jcls;
   (void)jarg1_;
   arg1 = *(std::vector< bool > **)&jarg1; 
-  result = ((std::vector< bool > const *)arg1)->capacity();
-  jresult = (jlong)result; 
-  return jresult;
+  arg2 = (std::vector< bool >::size_type)jarg2; 
+  (arg1)->reserve(arg2);
 }
 
 
-SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfBool_1ensureCapacity(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
+SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfBool_1resize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
   std::vector< bool > *arg1 = (std::vector< bool > *) 0 ;
   std::vector< bool >::size_type arg2 ;
   
@@ -2298,20 +2294,22 @@ SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfB
   (void)jarg1_;
   arg1 = *(std::vector< bool > **)&jarg1; 
   arg2 = (std::vector< bool >::size_type)jarg2; 
-  (arg1)->reserve(arg2);
+  (arg1)->resize(arg2);
 }
 
 
-SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfBool_1resize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
+SWIGEXPORT jint JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfBool_1size(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
+  jint jresult = 0 ;
   std::vector< bool > *arg1 = (std::vector< bool > *) 0 ;
-  std::vector< bool >::size_type arg2 ;
+  int result;
   
   (void)jenv;
   (void)jcls;
   (void)jarg1_;
   arg1 = *(std::vector< bool > **)&jarg1; 
-  arg2 = (std::vector< bool >::size_type)jarg2; 
-  (arg1)->resize(arg2);
+  result = (int)((std::vector< bool > const *)arg1)->size();
+  jresult = (jint)result; 
+  return jresult;
 }
 
 
@@ -2496,6 +2494,19 @@ SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfD
 }
 
 
+SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfDouble_1resize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
+  std::vector< double > *arg1 = (std::vector< double > *) 0 ;
+  std::vector< double >::size_type arg2 ;
+  
+  (void)jenv;
+  (void)jcls;
+  (void)jarg1_;
+  arg1 = *(std::vector< double > **)&jarg1; 
+  arg2 = (std::vector< double >::size_type)jarg2; 
+  (arg1)->resize(arg2);
+}
+
+
 SWIGEXPORT jint JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfDouble_1size(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
   jint jresult = 0 ;
   std::vector< double > *arg1 = (std::vector< double > *) 0 ;
@@ -2730,6 +2741,19 @@ SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfS
 }
 
 
+SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfString_1resize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
+  std::vector< std::string > *arg1 = (std::vector< std::string > *) 0 ;
+  std::vector< std::string >::size_type arg2 ;
+  
+  (void)jenv;
+  (void)jcls;
+  (void)jarg1_;
+  arg1 = *(std::vector< std::string > **)&jarg1; 
+  arg2 = (std::vector< std::string >::size_type)jarg2; 
+  (arg1)->resize(arg2);
+}
+
+
 SWIGEXPORT jint JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfString_1size(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
   jint jresult = 0 ;
   std::vector< std::string > *arg1 = (std::vector< std::string > *) 0 ;
@@ -3000,6 +3024,19 @@ SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfS
 }
 
 
+SWIGEXPORT void JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfScicosID_1resize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
+  std::vector< ScicosID > *arg1 = (std::vector< ScicosID > *) 0 ;
+  std::vector< long long >::size_type arg2 ;
+  
+  (void)jenv;
+  (void)jcls;
+  (void)jarg1_;
+  arg1 = *(std::vector< ScicosID > **)&jarg1; 
+  arg2 = (std::vector< long long >::size_type)jarg2; 
+  (arg1)->resize(arg2);
+}
+
+
 SWIGEXPORT jint JNICALL Java_org_scilab_modules_xcos_JavaControllerJNI_VectorOfScicosID_1size(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
   jint jresult = 0 ;
   std::vector< ScicosID > *arg1 = (std::vector< ScicosID > *) 0 ;
index b965f12..70c416d 100644 (file)
@@ -104,6 +104,7 @@ curEnv->DeleteLocalRef(localInstance);
 
                 /* Methods ID set to NULL */
 voidxcosjstringjava_lang_StringjlonglongID=NULL;
+voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID=NULL;
 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
 voidcloseXcosFromScilabID=NULL;
 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
@@ -131,6 +132,7 @@ throw GiwsException::JniObjectCreationException(curEnv, this->className());
         }
         /* Methods ID set to NULL */
         voidxcosjstringjava_lang_StringjlonglongID=NULL;
+voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID=NULL;
 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
 voidcloseXcosFromScilabID=NULL;
 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
@@ -182,6 +184,34 @@ throw GiwsException::JniCallMethodException(curEnv);
 }
 }
 
+void Xcos::xcosDiagramToScilab (JavaVM * jvm_, char const* file, long long diagramId){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = initClass(curEnv);
+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) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramToScilab");
+}
+
+jstring file_ = curEnv->NewStringUTF( file );
+if (file != NULL && file_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+
+                         curEnv->CallStaticVoidMethod(cls, voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID ,file_, diagramId);
+                        curEnv->DeleteLocalRef(file_);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
 void Xcos::warnCellByUID (JavaVM * jvm_, char const* const* uids, int uidsSize, char const* message){
 
 JNIEnv * curEnv = NULL;
index 9cb6566..b0ad5ac 100644 (file)
@@ -5,6 +5,10 @@
             <parameter name="file" type="String"/>
             <parameter name="diagramId" type="long"/>
         </method>
+        <method name="xcosDiagramToScilab" returnType="void" modifier="static">
+            <parameter name="file" type="String"/>
+            <parameter name="diagramId" type="long"/>
+        </method>
         <method name="warnCellByUID" returnType="void" modifier="static">
             <parameter name="uids" type="String[]"/>
             <parameter name="message" type="String"/>
index f3a1772..ccac809 100644 (file)
@@ -77,6 +77,7 @@ JavaVM * jvm;
 
 protected:
 jmethodID voidxcosjstringjava_lang_StringjlonglongID; // cache method id
+jmethodID voidxcosDiagramToScilabjstringjava_lang_StringjlonglongID; // cache method id
 jmethodID voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID; // cache method id
 jclass stringArrayClass;
 jmethodID voidcloseXcosFromScilabID; // cache method id
@@ -143,6 +144,8 @@ 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 warnCellByUID(JavaVM * jvm_, char const* const* uids, int uidsSize, char const* message);
 
 static void closeXcosFromScilab(JavaVM * jvm_);
index 26d9dd4..aff1e41 100644 (file)
@@ -1,12 +1,12 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2010 - DIGITEO - Clément DAVID
+// Copyright (C) 2015 - Scilab Enterprises - Clément DAVID
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
 // <-- XCOS TEST -->
-// <-- LONG TIME EXECUTION -->
 //
 // <-- Non-regression test for bug 7537 -->
 //
@@ -43,6 +43,6 @@ err = execstr("save(h5name, ""scs_m"")", "errcatch");
 if err <> 0 then pause, end
 
 // import to xcos (decode/encode synchronous version)
-status = xcosDiagramToScilab(h5name);
+status = importXcosDiagram(h5name);
 if status <> 0 then pause, end