Xcos GUI: handle XCOS / ZCOS import 90/17290/5
Clément DAVID [Fri, 2 Oct 2015 18:44:22 +0000 (20:44 +0200)]
Change-Id: I8c89984de76cf2f936529e14ba038634ab9168ee

33 files changed:
scilab/modules/xcos/etc/Xcos-style.xml
scilab/modules/xcos/src/java/org/scilab/modules/xcos/JavaControllerJNI.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/XcosDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/BlockInterFunction.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/ScicosObjectOwner.java [new file with mode: 0644]
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/graph/swing/handler/GraphHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/XcosFileType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicBlockCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicLinkCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicPortCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/XcosCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/XcosDiagramCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/XcosObjectCodec.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/BlockHandler.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/CustomHandler.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/HandledElement.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/HandledElementsCategory.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/JGraphXHandler.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/LinkHandler.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/PortHandler.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/RawDataHandler.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/SAXHandler.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/ScilabHandler.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/Stack.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/spec/ContentEntry.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/BasicPort.java

index 0d8da05..ba842fa 100644 (file)
         <add as="image" value="$SCILAB/modules/xcos/images/blocks/ASCOPE.svg"/>
     </add>
     <add as="AFFICH_m" extend="Affiche"/>
-    <add as="AFFICH_f" extend="Affiche"/>
     <add as="TRASH_f" extend="blockWithLabel">
         <add as="displayedLabel" value="Trash"/>
     </add>
index 87cad2e..e0ea1f6 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);
-  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 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 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 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 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 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 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 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 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 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);
+    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 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 String VectorOfInt_toString(long jarg1, VectorOfInt jarg1_);
+    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 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 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 String VectorOfDouble_toString(long jarg1, VectorOfDouble jarg1_);
+    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 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 String VectorOfString_toString(long jarg1, VectorOfString jarg1_);
+    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 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 String VectorOfScicosID_toString(long jarg1, VectorOfScicosID jarg1_);
+    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 f1f296a..6eb6834 100644 (file)
@@ -9,82 +9,86 @@
 package org.scilab.modules.xcos;
 
 public class VectorOfDouble {
-  private transient long swigCPtr;
-  protected transient boolean swigCMemOwn;
-
-  protected VectorOfDouble(long cPtr, boolean cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = cPtr;
-  }
-
-  protected static long getCPtr(VectorOfDouble obj) {
-    return (obj == null) ? 0 : obj.swigCPtr;
-  }
-
-  protected void finalize() {
-    delete();
-  }
-
-  public synchronized void delete() {
-    if (swigCPtr != 0) {
-      if (swigCMemOwn) {
-        swigCMemOwn = false;
-        JavaControllerJNI.delete_VectorOfDouble(swigCPtr);
-      }
-      swigCPtr = 0;
-    }
-  }
-
-  public VectorOfDouble() {
-    this(JavaControllerJNI.new_VectorOfDouble__SWIG_0(), true);
-  }
-
-  public VectorOfDouble(long n) {
-    this(JavaControllerJNI.new_VectorOfDouble__SWIG_1(n), true);
-  }
-
-  public void ensureCapacity(long n) {
-    JavaControllerJNI.VectorOfDouble_ensureCapacity(swigCPtr, this, n);
-  }
-
-  public int size() {
-    return JavaControllerJNI.VectorOfDouble_size(swigCPtr, this);
-  }
-
-  public boolean isEmpty() {
-    return JavaControllerJNI.VectorOfDouble_isEmpty(swigCPtr, this);
-  }
-
-  public void clear() {
-    JavaControllerJNI.VectorOfDouble_clear(swigCPtr, this);
-  }
-
-  public void add(double x) {
-    JavaControllerJNI.VectorOfDouble_add__SWIG_0(swigCPtr, this, x);
-  }
-
-  public boolean contains(double o) {
-    return JavaControllerJNI.VectorOfDouble_contains(swigCPtr, this, o);
-  }
-
-  public int indexOf(double o) {
-    return JavaControllerJNI.VectorOfDouble_indexOf(swigCPtr, this, o);
-  }
-
-  public double get(int i) {
-    return JavaControllerJNI.VectorOfDouble_get(swigCPtr, this, i);
-  }
-
-  public void set(int i, double val) {
-    JavaControllerJNI.VectorOfDouble_set(swigCPtr, this, i, val);
-  }
-
-  public void add(int i, double val) {
-    JavaControllerJNI.VectorOfDouble_add__SWIG_1(swigCPtr, this, i, val);
-  }
-
-  public boolean remove(double val) {
-    return JavaControllerJNI.VectorOfDouble_remove(swigCPtr, this, val);
-  }
+    private transient long swigCPtr;
+    protected transient boolean swigCMemOwn;
+
+    protected VectorOfDouble(long cPtr, boolean cMemoryOwn) {
+        swigCMemOwn = cMemoryOwn;
+        swigCPtr = cPtr;
+    }
+
+    protected static long getCPtr(VectorOfDouble obj) {
+        return (obj == null) ? 0 : obj.swigCPtr;
+    }
+
+    protected void finalize() {
+        delete();
+    }
+
+    public synchronized void delete() {
+        if (swigCPtr != 0) {
+            if (swigCMemOwn) {
+                swigCMemOwn = false;
+                JavaControllerJNI.delete_VectorOfDouble(swigCPtr);
+            }
+            swigCPtr = 0;
+        }
+    }
+
+    public VectorOfDouble() {
+        this(JavaControllerJNI.new_VectorOfDouble__SWIG_0(), true);
+    }
+
+    public VectorOfDouble(long n) {
+        this(JavaControllerJNI.new_VectorOfDouble__SWIG_1(n), true);
+    }
+
+    public void ensureCapacity(long n) {
+        JavaControllerJNI.VectorOfDouble_ensureCapacity(swigCPtr, this, n);
+    }
+
+    public int size() {
+        return JavaControllerJNI.VectorOfDouble_size(swigCPtr, this);
+    }
+
+    public boolean isEmpty() {
+        return JavaControllerJNI.VectorOfDouble_isEmpty(swigCPtr, this);
+    }
+
+    public void clear() {
+        JavaControllerJNI.VectorOfDouble_clear(swigCPtr, this);
+    }
+
+    public void add(double x) {
+        JavaControllerJNI.VectorOfDouble_add__SWIG_0(swigCPtr, this, x);
+    }
+
+    public boolean contains(double o) {
+        return JavaControllerJNI.VectorOfDouble_contains(swigCPtr, this, o);
+    }
+
+    public int indexOf(double o) {
+        return JavaControllerJNI.VectorOfDouble_indexOf(swigCPtr, this, o);
+    }
+
+    public double get(int i) {
+        return JavaControllerJNI.VectorOfDouble_get(swigCPtr, this, i);
+    }
+
+    public void set(int i, double val) {
+        JavaControllerJNI.VectorOfDouble_set(swigCPtr, this, i, val);
+    }
+
+    public void add(int i, double val) {
+        JavaControllerJNI.VectorOfDouble_add__SWIG_1(swigCPtr, this, i, val);
+    }
+
+    public boolean remove(double val) {
+        return JavaControllerJNI.VectorOfDouble_remove(swigCPtr, this, val);
+    }
+
+    public String toString() {
+        return JavaControllerJNI.VectorOfDouble_toString(swigCPtr, this);
+    }
 
 }
index 016d0f4..bd208c6 100644 (file)
@@ -9,82 +9,86 @@
 package org.scilab.modules.xcos;
 
 public class VectorOfInt {
-  private transient long swigCPtr;
-  protected transient boolean swigCMemOwn;
-
-  protected VectorOfInt(long cPtr, boolean cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = cPtr;
-  }
-
-  protected static long getCPtr(VectorOfInt obj) {
-    return (obj == null) ? 0 : obj.swigCPtr;
-  }
-
-  protected void finalize() {
-    delete();
-  }
-
-  public synchronized void delete() {
-    if (swigCPtr != 0) {
-      if (swigCMemOwn) {
-        swigCMemOwn = false;
-        JavaControllerJNI.delete_VectorOfInt(swigCPtr);
-      }
-      swigCPtr = 0;
-    }
-  }
-
-  public VectorOfInt() {
-    this(JavaControllerJNI.new_VectorOfInt__SWIG_0(), true);
-  }
-
-  public VectorOfInt(long n) {
-    this(JavaControllerJNI.new_VectorOfInt__SWIG_1(n), true);
-  }
-
-  public void ensureCapacity(long n) {
-    JavaControllerJNI.VectorOfInt_ensureCapacity(swigCPtr, this, n);
-  }
-
-  public int size() {
-    return JavaControllerJNI.VectorOfInt_size(swigCPtr, this);
-  }
-
-  public boolean isEmpty() {
-    return JavaControllerJNI.VectorOfInt_isEmpty(swigCPtr, this);
-  }
-
-  public void clear() {
-    JavaControllerJNI.VectorOfInt_clear(swigCPtr, this);
-  }
-
-  public void add(int x) {
-    JavaControllerJNI.VectorOfInt_add__SWIG_0(swigCPtr, this, x);
-  }
-
-  public boolean contains(int o) {
-    return JavaControllerJNI.VectorOfInt_contains(swigCPtr, this, o);
-  }
-
-  public int indexOf(int o) {
-    return JavaControllerJNI.VectorOfInt_indexOf(swigCPtr, this, o);
-  }
-
-  public int get(int i) {
-    return JavaControllerJNI.VectorOfInt_get(swigCPtr, this, i);
-  }
-
-  public void set(int i, int val) {
-    JavaControllerJNI.VectorOfInt_set(swigCPtr, this, i, val);
-  }
-
-  public void add(int i, int val) {
-    JavaControllerJNI.VectorOfInt_add__SWIG_1(swigCPtr, this, i, val);
-  }
-
-  public boolean remove(int val) {
-    return JavaControllerJNI.VectorOfInt_remove(swigCPtr, this, val);
-  }
+    private transient long swigCPtr;
+    protected transient boolean swigCMemOwn;
+
+    protected VectorOfInt(long cPtr, boolean cMemoryOwn) {
+        swigCMemOwn = cMemoryOwn;
+        swigCPtr = cPtr;
+    }
+
+    protected static long getCPtr(VectorOfInt obj) {
+        return (obj == null) ? 0 : obj.swigCPtr;
+    }
+
+    protected void finalize() {
+        delete();
+    }
+
+    public synchronized void delete() {
+        if (swigCPtr != 0) {
+            if (swigCMemOwn) {
+                swigCMemOwn = false;
+                JavaControllerJNI.delete_VectorOfInt(swigCPtr);
+            }
+            swigCPtr = 0;
+        }
+    }
+
+    public VectorOfInt() {
+        this(JavaControllerJNI.new_VectorOfInt__SWIG_0(), true);
+    }
+
+    public VectorOfInt(long n) {
+        this(JavaControllerJNI.new_VectorOfInt__SWIG_1(n), true);
+    }
+
+    public void ensureCapacity(long n) {
+        JavaControllerJNI.VectorOfInt_ensureCapacity(swigCPtr, this, n);
+    }
+
+    public int size() {
+        return JavaControllerJNI.VectorOfInt_size(swigCPtr, this);
+    }
+
+    public boolean isEmpty() {
+        return JavaControllerJNI.VectorOfInt_isEmpty(swigCPtr, this);
+    }
+
+    public void clear() {
+        JavaControllerJNI.VectorOfInt_clear(swigCPtr, this);
+    }
+
+    public void add(int x) {
+        JavaControllerJNI.VectorOfInt_add__SWIG_0(swigCPtr, this, x);
+    }
+
+    public boolean contains(int o) {
+        return JavaControllerJNI.VectorOfInt_contains(swigCPtr, this, o);
+    }
+
+    public int indexOf(int o) {
+        return JavaControllerJNI.VectorOfInt_indexOf(swigCPtr, this, o);
+    }
+
+    public int get(int i) {
+        return JavaControllerJNI.VectorOfInt_get(swigCPtr, this, i);
+    }
+
+    public void set(int i, int val) {
+        JavaControllerJNI.VectorOfInt_set(swigCPtr, this, i, val);
+    }
+
+    public void add(int i, int val) {
+        JavaControllerJNI.VectorOfInt_add__SWIG_1(swigCPtr, this, i, val);
+    }
+
+    public boolean remove(int val) {
+        return JavaControllerJNI.VectorOfInt_remove(swigCPtr, this, val);
+    }
+
+    public String toString() {
+        return JavaControllerJNI.VectorOfInt_toString(swigCPtr, this);
+    }
 
 }
index 4b1ebdb..6ec4ddb 100644 (file)
@@ -9,82 +9,86 @@
 package org.scilab.modules.xcos;
 
 public class VectorOfScicosID {
-  private transient long swigCPtr;
-  protected transient boolean swigCMemOwn;
-
-  protected VectorOfScicosID(long cPtr, boolean cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = cPtr;
-  }
-
-  protected static long getCPtr(VectorOfScicosID obj) {
-    return (obj == null) ? 0 : obj.swigCPtr;
-  }
-
-  protected void finalize() {
-    delete();
-  }
-
-  public synchronized void delete() {
-    if (swigCPtr != 0) {
-      if (swigCMemOwn) {
-        swigCMemOwn = false;
-        JavaControllerJNI.delete_VectorOfScicosID(swigCPtr);
-      }
-      swigCPtr = 0;
-    }
-  }
-
-  public VectorOfScicosID() {
-    this(JavaControllerJNI.new_VectorOfScicosID__SWIG_0(), true);
-  }
-
-  public VectorOfScicosID(long n) {
-    this(JavaControllerJNI.new_VectorOfScicosID__SWIG_1(n), true);
-  }
-
-  public void ensureCapacity(long n) {
-    JavaControllerJNI.VectorOfScicosID_ensureCapacity(swigCPtr, this, n);
-  }
-
-  public int size() {
-    return JavaControllerJNI.VectorOfScicosID_size(swigCPtr, this);
-  }
-
-  public boolean isEmpty() {
-    return JavaControllerJNI.VectorOfScicosID_isEmpty(swigCPtr, this);
-  }
-
-  public void clear() {
-    JavaControllerJNI.VectorOfScicosID_clear(swigCPtr, this);
-  }
-
-  public void add(long x) {
-    JavaControllerJNI.VectorOfScicosID_add__SWIG_0(swigCPtr, this, x);
-  }
-
-  public boolean contains(long o) {
-    return JavaControllerJNI.VectorOfScicosID_contains(swigCPtr, this, o);
-  }
-
-  public int indexOf(long o) {
-    return JavaControllerJNI.VectorOfScicosID_indexOf(swigCPtr, this, o);
-  }
-
-  public long get(int i) {
-    return JavaControllerJNI.VectorOfScicosID_get(swigCPtr, this, i);
-  }
-
-  public void set(int i, long val) {
-    JavaControllerJNI.VectorOfScicosID_set(swigCPtr, this, i, val);
-  }
-
-  public void add(int i, long val) {
-    JavaControllerJNI.VectorOfScicosID_add__SWIG_1(swigCPtr, this, i, val);
-  }
-
-  public boolean remove(long val) {
-    return JavaControllerJNI.VectorOfScicosID_remove(swigCPtr, this, val);
-  }
+    private transient long swigCPtr;
+    protected transient boolean swigCMemOwn;
+
+    protected VectorOfScicosID(long cPtr, boolean cMemoryOwn) {
+        swigCMemOwn = cMemoryOwn;
+        swigCPtr = cPtr;
+    }
+
+    protected static long getCPtr(VectorOfScicosID obj) {
+        return (obj == null) ? 0 : obj.swigCPtr;
+    }
+
+    protected void finalize() {
+        delete();
+    }
+
+    public synchronized void delete() {
+        if (swigCPtr != 0) {
+            if (swigCMemOwn) {
+                swigCMemOwn = false;
+                JavaControllerJNI.delete_VectorOfScicosID(swigCPtr);
+            }
+            swigCPtr = 0;
+        }
+    }
+
+    public VectorOfScicosID() {
+        this(JavaControllerJNI.new_VectorOfScicosID__SWIG_0(), true);
+    }
+
+    public VectorOfScicosID(long n) {
+        this(JavaControllerJNI.new_VectorOfScicosID__SWIG_1(n), true);
+    }
+
+    public void ensureCapacity(long n) {
+        JavaControllerJNI.VectorOfScicosID_ensureCapacity(swigCPtr, this, n);
+    }
+
+    public int size() {
+        return JavaControllerJNI.VectorOfScicosID_size(swigCPtr, this);
+    }
+
+    public boolean isEmpty() {
+        return JavaControllerJNI.VectorOfScicosID_isEmpty(swigCPtr, this);
+    }
+
+    public void clear() {
+        JavaControllerJNI.VectorOfScicosID_clear(swigCPtr, this);
+    }
+
+    public void add(long x) {
+        JavaControllerJNI.VectorOfScicosID_add__SWIG_0(swigCPtr, this, x);
+    }
+
+    public boolean contains(long o) {
+        return JavaControllerJNI.VectorOfScicosID_contains(swigCPtr, this, o);
+    }
+
+    public int indexOf(long o) {
+        return JavaControllerJNI.VectorOfScicosID_indexOf(swigCPtr, this, o);
+    }
+
+    public long get(int i) {
+        return JavaControllerJNI.VectorOfScicosID_get(swigCPtr, this, i);
+    }
+
+    public void set(int i, long val) {
+        JavaControllerJNI.VectorOfScicosID_set(swigCPtr, this, i, val);
+    }
+
+    public void add(int i, long val) {
+        JavaControllerJNI.VectorOfScicosID_add__SWIG_1(swigCPtr, this, i, val);
+    }
+
+    public boolean remove(long val) {
+        return JavaControllerJNI.VectorOfScicosID_remove(swigCPtr, this, val);
+    }
+
+    public String toString() {
+        return JavaControllerJNI.VectorOfScicosID_toString(swigCPtr, this);
+    }
 
 }
index 6ba24a0..ff966af 100644 (file)
@@ -9,82 +9,86 @@
 package org.scilab.modules.xcos;
 
 public class VectorOfString {
-  private transient long swigCPtr;
-  protected transient boolean swigCMemOwn;
-
-  protected VectorOfString(long cPtr, boolean cMemoryOwn) {
-    swigCMemOwn = cMemoryOwn;
-    swigCPtr = cPtr;
-  }
-
-  protected static long getCPtr(VectorOfString obj) {
-    return (obj == null) ? 0 : obj.swigCPtr;
-  }
-
-  protected void finalize() {
-    delete();
-  }
-
-  public synchronized void delete() {
-    if (swigCPtr != 0) {
-      if (swigCMemOwn) {
-        swigCMemOwn = false;
-        JavaControllerJNI.delete_VectorOfString(swigCPtr);
-      }
-      swigCPtr = 0;
-    }
-  }
-
-  public VectorOfString() {
-    this(JavaControllerJNI.new_VectorOfString__SWIG_0(), true);
-  }
-
-  public VectorOfString(long n) {
-    this(JavaControllerJNI.new_VectorOfString__SWIG_1(n), true);
-  }
-
-  public void ensureCapacity(long n) {
-    JavaControllerJNI.VectorOfString_ensureCapacity(swigCPtr, this, n);
-  }
-
-  public int size() {
-    return JavaControllerJNI.VectorOfString_size(swigCPtr, this);
-  }
-
-  public boolean isEmpty() {
-    return JavaControllerJNI.VectorOfString_isEmpty(swigCPtr, this);
-  }
-
-  public void clear() {
-    JavaControllerJNI.VectorOfString_clear(swigCPtr, this);
-  }
-
-  public void add(String x) {
-    JavaControllerJNI.VectorOfString_add__SWIG_0(swigCPtr, this, x);
-  }
-
-  public boolean contains(String o) {
-    return JavaControllerJNI.VectorOfString_contains(swigCPtr, this, o);
-  }
-
-  public int indexOf(String o) {
-    return JavaControllerJNI.VectorOfString_indexOf(swigCPtr, this, o);
-  }
-
-  public String get(int i) {
-    return JavaControllerJNI.VectorOfString_get(swigCPtr, this, i);
-  }
-
-  public void set(int i, String val) {
-    JavaControllerJNI.VectorOfString_set(swigCPtr, this, i, val);
-  }
-
-  public void add(int i, String val) {
-    JavaControllerJNI.VectorOfString_add__SWIG_1(swigCPtr, this, i, val);
-  }
-
-  public boolean remove(String val) {
-    return JavaControllerJNI.VectorOfString_remove(swigCPtr, this, val);
-  }
+    private transient long swigCPtr;
+    protected transient boolean swigCMemOwn;
+
+    protected VectorOfString(long cPtr, boolean cMemoryOwn) {
+        swigCMemOwn = cMemoryOwn;
+        swigCPtr = cPtr;
+    }
+
+    protected static long getCPtr(VectorOfString obj) {
+        return (obj == null) ? 0 : obj.swigCPtr;
+    }
+
+    protected void finalize() {
+        delete();
+    }
+
+    public synchronized void delete() {
+        if (swigCPtr != 0) {
+            if (swigCMemOwn) {
+                swigCMemOwn = false;
+                JavaControllerJNI.delete_VectorOfString(swigCPtr);
+            }
+            swigCPtr = 0;
+        }
+    }
+
+    public VectorOfString() {
+        this(JavaControllerJNI.new_VectorOfString__SWIG_0(), true);
+    }
+
+    public VectorOfString(long n) {
+        this(JavaControllerJNI.new_VectorOfString__SWIG_1(n), true);
+    }
+
+    public void ensureCapacity(long n) {
+        JavaControllerJNI.VectorOfString_ensureCapacity(swigCPtr, this, n);
+    }
+
+    public int size() {
+        return JavaControllerJNI.VectorOfString_size(swigCPtr, this);
+    }
+
+    public boolean isEmpty() {
+        return JavaControllerJNI.VectorOfString_isEmpty(swigCPtr, this);
+    }
+
+    public void clear() {
+        JavaControllerJNI.VectorOfString_clear(swigCPtr, this);
+    }
+
+    public void add(String x) {
+        JavaControllerJNI.VectorOfString_add__SWIG_0(swigCPtr, this, x);
+    }
+
+    public boolean contains(String o) {
+        return JavaControllerJNI.VectorOfString_contains(swigCPtr, this, o);
+    }
+
+    public int indexOf(String o) {
+        return JavaControllerJNI.VectorOfString_indexOf(swigCPtr, this, o);
+    }
+
+    public String get(int i) {
+        return JavaControllerJNI.VectorOfString_get(swigCPtr, this, i);
+    }
+
+    public void set(int i, String val) {
+        JavaControllerJNI.VectorOfString_set(swigCPtr, this, i, val);
+    }
+
+    public void add(int i, String val) {
+        JavaControllerJNI.VectorOfString_add__SWIG_1(swigCPtr, this, i, val);
+    }
+
+    public boolean remove(String val) {
+        return JavaControllerJNI.VectorOfString_remove(swigCPtr, this, val);
+    }
+
+    public String toString() {
+        return JavaControllerJNI.VectorOfString_toString(swigCPtr, this);
+    }
 
 }
index 68f190e..2d01013 100644 (file)
@@ -79,7 +79,7 @@ public final class Xcos {
     /**
      * The current Xcos version
      */
-    public static final String VERSION = "1.0";
+    public static final String VERSION = "2.0";
     /**
      * The current Xcos tradename
      */
index 2cf038c..df70067 100644 (file)
@@ -68,9 +68,9 @@ import org.scilab.modules.xcos.block.io.ExplicitOutBlock;
 import org.scilab.modules.xcos.block.io.ImplicitInBlock;
 import org.scilab.modules.xcos.block.io.ImplicitOutBlock;
 import org.scilab.modules.xcos.configuration.ConfigurationManager;
+import org.scilab.modules.xcos.graph.model.BlockInterFunction;
 import org.scilab.modules.xcos.graph.model.XcosCell;
 import org.scilab.modules.xcos.graph.model.XcosCellFactory;
-import org.scilab.modules.xcos.graph.model.XcosCellFactory.BlockInterFunction;
 import org.scilab.modules.xcos.graph.swing.GraphComponent;
 import org.scilab.modules.xcos.io.XcosFileType;
 import org.scilab.modules.xcos.link.BasicLink;
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/BlockInterFunction.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/BlockInterFunction.java
new file mode 100644 (file)
index 0000000..6e522ef
--- /dev/null
@@ -0,0 +1,95 @@
+package org.scilab.modules.xcos.graph.model;
+
+import org.scilab.modules.xcos.block.AfficheBlock;
+import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.block.SplitBlock;
+import org.scilab.modules.xcos.block.SuperBlock;
+import org.scilab.modules.xcos.block.TextBlock;
+import org.scilab.modules.xcos.block.io.EventInBlock;
+import org.scilab.modules.xcos.block.io.EventOutBlock;
+import org.scilab.modules.xcos.block.io.ExplicitInBlock;
+import org.scilab.modules.xcos.block.io.ExplicitOutBlock;
+import org.scilab.modules.xcos.block.io.ImplicitInBlock;
+import org.scilab.modules.xcos.block.io.ImplicitOutBlock;
+import org.scilab.modules.xcos.block.positionning.BigSom;
+import org.scilab.modules.xcos.block.positionning.GroundBlock;
+import org.scilab.modules.xcos.block.positionning.Product;
+import org.scilab.modules.xcos.block.positionning.RoundBlock;
+import org.scilab.modules.xcos.block.positionning.Summation;
+import org.scilab.modules.xcos.block.positionning.VoltageSensorBlock;
+
+/**
+ * List the specific block interface function name. <BR>
+ * <BR>
+ * <EM>Specific instance must be registered before generic ones in order
+ * to serialized all the non-default values.</EM>
+ */
+public enum BlockInterFunction {
+    /** @see TextBlock */
+    TEXT_f(TextBlock.class),
+    /** @see SuperBlock */
+    DSUPER(SuperBlock.class),
+    /** @see SuperBlock */
+    SUPER_f(SuperBlock.class),
+    /** @see AfficheBlock */
+    AFFICH_m(AfficheBlock.class),
+    /** @see ExplicitInBlock */
+    IN_f(ExplicitInBlock.class),
+    /** @see ExplicitOutBlock */
+    OUT_f(ExplicitOutBlock.class),
+    /** @see ImplicitInBlock */
+    INIMPL_f(ImplicitInBlock.class),
+    /** @see ImplicitOutBlock */
+    OUTIMPL_f(ImplicitOutBlock.class),
+    /** @see EventInBlock */
+    CLKINV_f(EventInBlock.class),
+    /** @see EventOutBlock */
+    CLKOUTV_f(EventOutBlock.class),
+    /** @see EventOutBlock */
+    CLKOUT_f(EventOutBlock.class),
+    /** @see SplitBlock */
+    SPLIT_f(SplitBlock.class),
+    /** @see SplitBlock */
+    IMPSPLIT_f(SplitBlock.class),
+    /** @see SplitBlock */
+    CLKSPLIT_f(SplitBlock.class),
+    /** @see GroundBlock */
+    Ground(GroundBlock.class),
+    /** @see VoltageSensorBlock */
+    VoltageSensor(VoltageSensorBlock.class),
+    /** @see RoundBlock */
+    SUM_f(RoundBlock.class),
+    /** @see RoundBlock */
+    PROD_f(RoundBlock.class),
+    /** @see RoundBlock */
+    CLKSOM_f(RoundBlock.class),
+    /** @see RoundBlock */
+    CLKSOMV_f(RoundBlock.class),
+    /** @see BigSom */
+    BIGSOM_f(BigSom.class),
+    /** @see Summation */
+    SUMMATION(Summation.class),
+    /** @see Product */
+    PRODUCT(Product.class),
+    /** @see BasicBlock */
+    BASIC_BLOCK(BasicBlock.class);
+
+    private final Class<? extends BasicBlock> klass;
+
+    /**
+     * Default constructor
+     *
+     * @param block
+     *            The reference instance
+     */
+    private BlockInterFunction(Class<? extends BasicBlock> klass) {
+        this.klass = klass;
+    }
+
+    /**
+     * @return the class to instantiate
+     */
+    public Class<? extends BasicBlock> getKlass() {
+        return klass;
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/ScicosObjectOwner.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/ScicosObjectOwner.java
new file mode 100644 (file)
index 0000000..aa2df8b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.graph.model;
+
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+
+public class ScicosObjectOwner {
+    final long uid;
+    final Kind kind;
+
+    public ScicosObjectOwner(long uid, Kind kind) {
+        this.uid = uid;
+        this.kind = kind;
+
+        // defensive programming
+        if (uid == 0) {
+            throw new IllegalStateException();
+        }
+
+        JavaController controller = new JavaController();
+        controller.referenceObject(uid);
+    }
+
+    public long getUID() {
+        return uid;
+    }
+
+    public Kind getKind() {
+        return kind;
+    }
+
+    @Override
+    public String toString() {
+        return "[ " + uid + " , " + kind.name() + " ]";
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        JavaController controller = new JavaController();
+        controller.deleteObject(uid);
+    }
+}
\ No newline at end of file
index 3d1ef3f..29b69a0 100644 (file)
@@ -1,5 +1,20 @@
+/*
+ * 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.graph.model;
 
+import java.util.Collections;
+import java.util.List;
+
 import org.scilab.modules.graph.ScilabGraphUniqueObject;
 import org.scilab.modules.xcos.JavaController;
 import org.scilab.modules.xcos.Kind;
@@ -10,13 +25,13 @@ import org.scilab.modules.xcos.VectorOfScicosID;
 
 import com.mxgraph.model.mxGeometry;
 import com.mxgraph.model.mxICell;
+import com.mxgraph.util.mxPoint;
 
 
 public class XcosCell extends ScilabGraphUniqueObject {
     private static final long serialVersionUID = 1L;
 
-    private long uid;
-    private Kind kind;
+    private transient ScicosObjectOwner owner;
 
     /**
      * Construct an Xcos graphical object.
@@ -27,8 +42,12 @@ public class XcosCell extends ScilabGraphUniqueObject {
      * @param kind the associated MVC kind
      */
     public XcosCell(long uid, Kind kind) {
-        this.uid = uid;
-        this.kind = kind;
+        owner = new ScicosObjectOwner(uid, kind);
+
+        // defensive programming
+        if (uid == 0l) {
+            throw new IllegalArgumentException();
+        }
 
         JavaController controller = new JavaController();
         controller.referenceObject(uid);
@@ -38,14 +57,14 @@ public class XcosCell extends ScilabGraphUniqueObject {
      * @return the MVC unique identifier
      */
     public long getUID() {
-        return uid;
+        return owner.getUID();
     }
 
     /**
      * @return the MVC kind of object
      */
     public Kind getKind() {
-        return kind;
+        return owner.getKind();
     }
 
     /*
@@ -58,7 +77,7 @@ public class XcosCell extends ScilabGraphUniqueObject {
     @Override
     public void setValue(Object value) {
         super.setValue(value);
-        if (getKind() == null) {
+        if (owner == null) {
             return;
         }
 
@@ -86,9 +105,18 @@ public class XcosCell extends ScilabGraphUniqueObject {
 
         JavaController controller = new JavaController();
         switch (getKind()) {
+            case ANNOTATION:
+                controller.setObjectProperty(getUID(), getKind(), ObjectProperties.UID, id);
+                break;
             case BLOCK:
                 controller.setObjectProperty(getUID(), getKind(), ObjectProperties.UID, id);
                 break;
+            case LINK:
+                controller.setObjectProperty(getUID(), getKind(), ObjectProperties.UID, id);
+                break;
+            case PORT:
+                controller.setObjectProperty(getUID(), getKind(), ObjectProperties.UID, id);
+                break;
             default:
                 break;
         }
@@ -100,7 +128,7 @@ public class XcosCell extends ScilabGraphUniqueObject {
     @Override
     public void setGeometry(mxGeometry geometry) {
         super.setGeometry(geometry);
-        if (getKind() == null) {
+        if (owner == null) {
             return;
         }
 
@@ -117,12 +145,68 @@ public class XcosCell extends ScilabGraphUniqueObject {
                 break;
             }
             case LINK: {
-                VectorOfDouble v = new VectorOfDouble(4);
-                v.set(0, geometry.getX());
-                v.set(1, geometry.getY());
-                v.set(2, geometry.getWidth());
-                v.set(3, geometry.getHeight());
-                controller.setObjectProperty(getUID(), getKind(), ObjectProperties.GEOMETRY, v);
+                /*
+                 * try to find the origin of the source and target accordingly to the JGraphX implementation
+                 */
+                mxPoint sourcePoint = null;
+                mxPoint targetPoint = null;
+
+                mxICell sourceCell = getSource();
+                mxICell targetCell = getTarget();
+                if (sourceCell != null && sourceCell.getGeometry() != null) {
+                    sourcePoint = new mxPoint(sourceCell.getGeometry().getCenterX(), sourceCell.getGeometry().getCenterY());
+                }
+                if (targetCell != null && targetCell.getGeometry() != null) {
+                    targetPoint = new mxPoint(targetCell.getGeometry().getCenterX(), targetCell.getGeometry().getCenterY());
+                }
+
+                if (sourcePoint == null) {
+                    sourcePoint = geometry.getSourcePoint();
+                }
+                if (targetPoint == null) {
+                    targetPoint = geometry.getTargetPoint();
+                }
+
+                if (sourcePoint == null) {
+                    sourcePoint = new mxPoint();
+                }
+                if (targetPoint == null) {
+                    targetPoint = new mxPoint();
+                }
+
+                List<mxPoint> points = geometry.getPoints();
+                if (points == null) {
+                    points = Collections.emptyList();
+                }
+
+                /*
+                 * At that point, the sourcePoint, targetPoint and points are valid values (but may be unknown)
+                 * encode them to the the CONTROL_POINTS
+                 */
+
+                // Allocate some space to contains them all
+                int nbOfPoints = 2 + points.size();
+                VectorOfDouble v = new VectorOfDouble(2 * nbOfPoints);
+                int i = 0;
+
+                // then fill the allocation space
+                v.set(2 * i, sourcePoint.getX());
+                v.set(2 * i + 1, sourcePoint.getY());
+                i++;
+
+                for (; i < nbOfPoints - 1 ; i++) {
+                    v.set(2 * i, points.get(i - 1).getX());
+                    v.set(2 * i + 1, points.get(i - 1).getY());
+                }
+
+                v.set(2 * i, targetPoint.getX());
+                v.set(2 * i + 1, targetPoint.getY());
+                i++;
+
+                /*
+                 * Finally push the values to the model
+                 */
+                controller.setObjectProperty(getUID(), getKind(), ObjectProperties.CONTROL_POINTS, v);
                 break;
             }
             default:
@@ -136,7 +220,7 @@ public class XcosCell extends ScilabGraphUniqueObject {
     @Override
     public void setStyle(String style) {
         super.setStyle(style);
-        if (getKind() == null) {
+        if (owner == null) {
             return;
         }
 
@@ -365,8 +449,7 @@ public class XcosCell extends ScilabGraphUniqueObject {
     public Object clone() throws CloneNotSupportedException {
         JavaController controller = new JavaController();
         XcosCell c = (XcosCell) super.clone();
-        c.uid = controller.cloneObject(getUID(), false);
-        c.kind = getKind();
+        c.owner = new ScicosObjectOwner(controller.cloneObject(getUID(), false), getKind());
         return c;
     }
 
index 6835c03..90ec52a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2009 - DIGITEO - Clement DAVID
+ * 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
@@ -32,23 +32,7 @@ import org.scilab.modules.xcos.VectorOfDouble;
 import org.scilab.modules.xcos.VectorOfScicosID;
 import org.scilab.modules.xcos.Xcos;
 import org.scilab.modules.xcos.XcosView;
-import org.scilab.modules.xcos.block.AfficheBlock;
 import org.scilab.modules.xcos.block.BasicBlock;
-import org.scilab.modules.xcos.block.SplitBlock;
-import org.scilab.modules.xcos.block.SuperBlock;
-import org.scilab.modules.xcos.block.TextBlock;
-import org.scilab.modules.xcos.block.io.EventInBlock;
-import org.scilab.modules.xcos.block.io.EventOutBlock;
-import org.scilab.modules.xcos.block.io.ExplicitInBlock;
-import org.scilab.modules.xcos.block.io.ExplicitOutBlock;
-import org.scilab.modules.xcos.block.io.ImplicitInBlock;
-import org.scilab.modules.xcos.block.io.ImplicitOutBlock;
-import org.scilab.modules.xcos.block.positionning.BigSom;
-import org.scilab.modules.xcos.block.positionning.GroundBlock;
-import org.scilab.modules.xcos.block.positionning.Product;
-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.XcosDiagram;
 import org.scilab.modules.xcos.link.BasicLink;
 import org.scilab.modules.xcos.link.commandcontrol.CommandControlLink;
@@ -73,116 +57,6 @@ import com.mxgraph.util.mxPoint;
  */
 public final class XcosCellFactory {
 
-    // DAC: As this is the constructor for all the block classes, this class is
-    // very coupled with *Block classes
-    // CSOFF: ClassDataAbstractionCoupling
-    /**
-     * List the specific block interface function name. <BR>
-     * <BR>
-     * <EM>Specific instance must be registered before generic ones in order
-     * to serialized all the non-default values.</EM>
-     */
-    public static enum BlockInterFunction {
-        /** @see TextBlock */
-        TEXT_f(TextBlock.class),
-        /** @see SuperBlock */
-        DSUPER(SuperBlock.class),
-        /** @see SuperBlock */
-        SUPER_f(SuperBlock.class),
-        /** @see AfficheBlock */
-        AFFICH_m(AfficheBlock.class),
-        /** @see AfficheBlock */
-        AFFICH_f(AfficheBlock.class),
-        /** @see ExplicitInBlock */
-        IN_f(ExplicitInBlock.class),
-        /** @see ExplicitOutBlock */
-        OUT_f(ExplicitOutBlock.class),
-        /** @see ImplicitInBlock */
-        INIMPL_f(ImplicitInBlock.class),
-        /** @see ImplicitOutBlock */
-        OUTIMPL_f(ImplicitOutBlock.class),
-        /** @see EventInBlock */
-        CLKINV_f(EventInBlock.class),
-        /** @see EventOutBlock */
-        CLKOUTV_f(EventOutBlock.class),
-        /** @see EventOutBlock */
-        CLKOUT_f(EventOutBlock.class),
-        /** @see SplitBlock */
-        SPLIT_f(SplitBlock.class),
-        /** @see SplitBlock */
-        IMPSPLIT_f(SplitBlock.class),
-        /** @see SplitBlock */
-        CLKSPLIT_f(SplitBlock.class),
-        /** @see GroundBlock */
-        Ground(GroundBlock.class),
-        /** @see VoltageSensorBlock */
-        VoltageSensor(VoltageSensorBlock.class),
-        /** @see RoundBlock */
-        SUM_f(RoundBlock.class),
-        /** @see RoundBlock */
-        PROD_f(RoundBlock.class),
-        /** @see RoundBlock */
-        CLKSOM_f(RoundBlock.class),
-        /** @see RoundBlock */
-        CLKSOMV_f(RoundBlock.class),
-        /** @see BigSom */
-        BIGSOM_f(BigSom.class),
-        /** @see Summation */
-        SUMMATION(Summation.class),
-        /** @see Product */
-        PRODUCT(Product.class),
-        /** @see BasicBlock */
-        BASIC_BLOCK(BasicBlock.class);
-
-        private final Class<? extends BasicBlock> klass;
-
-        /**
-         * Default constructor
-         *
-         * @param block
-         *            The reference instance
-         */
-        private BlockInterFunction(Class<? extends BasicBlock> klass) {
-            this.klass = klass;
-        }
-
-        /**
-         * @return the class to instantiate
-         */
-        public Class<? extends BasicBlock> getKlass() {
-            return klass;
-        }
-    }
-
-    private static class ScicosObjectOwner {
-        final long uid;
-        final Kind kind;
-
-        public ScicosObjectOwner(long uid, Kind kind) {
-            this.uid = uid;
-            this.kind = kind;
-
-            JavaController controller = new JavaController();
-            controller.referenceObject(uid);
-        }
-
-        public long getUID() {
-            return uid;
-        }
-
-        public Kind getKind() {
-            return kind;
-        }
-
-        @Override
-        protected void finalize() throws Throwable {
-            JavaController controller = new JavaController();
-            controller.deleteObject(uid);
-        }
-    }
-
-    // CSON: ClassDataAbstractionCoupling
-
     /** Default singleton constructor */
     private XcosCellFactory() {
         // This class is a static singleton
@@ -299,13 +173,17 @@ public final class XcosCellFactory {
             controller.getObjectProperty(l.getUID(), l.getKind(), ObjectProperties.DESTINATION_PORT, dest);
 
             int srcIndex = Collections.binarySearch(ports, new XcosCell(src[0], Kind.PORT), compare);
-            if (srcIndex > 0) {
+            if (srcIndex >= 0) {
                 l.setSource(ports.get(srcIndex));
+            } else {
+                throw new IllegalStateException();
             }
 
             int destIndex = Collections.binarySearch(ports, new XcosCell(dest[0], Kind.PORT), compare);
             if (destIndex > 0) {
                 l.setTarget(ports.get(destIndex));
+            } else {
+                throw new IllegalStateException();
             }
         }
 
@@ -360,7 +238,19 @@ public final class XcosCellFactory {
     private static BasicBlock createBlock(final JavaController controller, BlockInterFunction func, String interfaceFunction) {
         BasicBlock block;
         try {
-            synchronousScilabExec("xcosCellCreated(" + interfaceFunction + "(\"define\")); ");
+            if (BlockInterFunction.BASIC_BLOCK.name().equals(interfaceFunction)) {
+                // deliver all the MVC speed for the casual case
+                lastCreated = new ScicosObjectOwner(controller.createObject(Kind.BLOCK), Kind.BLOCK);
+            } else {
+                // allocate an empty block that will be filled later
+                synchronousScilabExec("xcosCellCreated(" + interfaceFunction + "(\"define\")); ");
+            }
+
+            // defensive programming
+            if (lastCreated == null) {
+                System.err.println("XcosCellFactory#createBlock : unable to allocate " + interfaceFunction);
+                return null;
+            }
 
             if (EnumSet.of(Kind.BLOCK, Kind.ANNOTATION).contains(lastCreated.getKind())) {
                 block = createBlock(controller, func, interfaceFunction, lastCreated.getUID());
@@ -421,7 +311,13 @@ public final class XcosCellFactory {
          */
         insertPortChildren(controller, block);
 
-        block.setStyle(interfaceFunction);
+        String[] style = new String[1];
+        controller.getObjectProperty(block.getUID(), block.getKind(), ObjectProperties.STYLE, style);
+        if (style[0].isEmpty()) {
+            block.setStyle(interfaceFunction);
+        } else {
+            block.setStyle(style[0]);
+        }
 
         VectorOfDouble geom = new VectorOfDouble(4);
         controller.getObjectProperty(block.getUID(), block.getKind(), ObjectProperties.GEOMETRY, geom);
@@ -429,6 +325,9 @@ public final class XcosCellFactory {
 
         // FIXME find a way to reuse the Scicos compat handler from org.scilab.modules.xcos.io.scicos
 
+
+
+
         return block;
     }
 
@@ -566,14 +465,21 @@ public final class XcosCellFactory {
         controller.getObjectProperty(uid, kind, ObjectProperties.CONTROL_POINTS, controlPoints);
         final int pointsLen = controlPoints.size() / 2;
 
-        ArrayList<mxPoint> points = new ArrayList<>(pointsLen);
-        for (int i = 0 ; i < pointsLen; i++) {
+        mxGeometry geom = new mxGeometry();
+
+        // as the link is supposed to be connected and accordingly to the JGraphX rules : do not add the origin and destination point
+        ArrayList<mxPoint> points = new ArrayList<>();
+        int i = 0;
+        // ignore origin
+        i++;
+        // loop for points
+        for (; i < pointsLen - 1; i++) {
             points.add(new mxPoint(controlPoints.get(2 * i), controlPoints.get(2 * i + 1)));
         }
+        // ignore destination
+        i++;
 
-        mxGeometry geom = new mxGeometry();
         geom.setPoints(points);
-
         link.setGeometry(geom);
         return link;
     }
index 6e9bd5e..f34b491 100644 (file)
@@ -23,8 +23,8 @@ import javax.swing.SwingUtilities;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.block.TextBlock;
+import org.scilab.modules.xcos.graph.model.BlockInterFunction;
 import org.scilab.modules.xcos.graph.model.XcosCellFactory;
-import org.scilab.modules.xcos.graph.model.XcosCellFactory.BlockInterFunction;
 import org.scilab.modules.xcos.graph.swing.GraphComponent;
 import org.scilab.modules.xcos.link.BasicLink;
 import org.scilab.modules.xcos.port.BasicPort;
index c01fb28..8e92a93 100644 (file)
@@ -28,18 +28,23 @@ import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.xml.parsers.ParserConfigurationException;
 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.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.xcos.JavaController;
 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.spec.ContentEntry;
 import org.scilab.modules.xcos.io.spec.XcosPackage;
 import org.scilab.modules.xcos.utils.XcosMessages;
 import org.w3c.dom.Node;
@@ -84,26 +89,24 @@ public enum XcosFileType {
         @Override
         public void load(String file, XcosDiagram into)
         throws TransformerException {
-            final XcosCodec codec = new XcosCodec();
-            final TransformerFactory tranFactory = ScilabTransformerFactory
-                                                   .newInstance();
-            final Transformer aTransformer = tranFactory.newTransformer();
 
-            StreamSource src;
             try {
-                src = new StreamSource(new File(file).toURI().toURL()
-                                       .toString());
-                final DOMResult result = new DOMResult(codec.getDocument());
+                final TransformerFactory tranFactory = ScilabTransformerFactory.newInstance();
+                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()));
 
                 LOG.entering("Transformer", "transform");
                 aTransformer.transform(src, result);
                 LOG.exiting("Transformer", "transform");
 
-                LOG.entering("XcosCodec", "decode");
-                codec.setElementIdAttributes();
-                codec.decode(result.getNode().getFirstChild(), into);
-                LOG.exiting("XcosCodec", "decode");
-            } catch (MalformedURLException e) {
+            } catch (TransformerConfigurationException e) {
+                Logger.getLogger(ContentEntry.class.getName()).severe(e.getMessageAndLocation());
+            } catch (TransformerException e) {
+                e.printStackTrace();
+                Logger.getLogger(ContentEntry.class.getName()).severe(e.getMessageAndLocation());
+            } catch (Exception e) {
                 e.printStackTrace();
             }
         }
index af5b2f9..5598ed8 100644 (file)
 
 package org.scilab.modules.xcos.io.codec;
 
+import java.util.EnumSet;
+import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
+import java.util.stream.Collectors;
 
 import org.scilab.modules.graph.utils.StyleMap;
 import org.scilab.modules.types.ScilabType;
@@ -22,8 +25,8 @@ import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.ObjectProperties;
 import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.block.TextBlock;
+import org.scilab.modules.xcos.graph.model.BlockInterFunction;
 import org.scilab.modules.xcos.graph.model.XcosCellFactory;
-import org.scilab.modules.xcos.graph.model.XcosCellFactory.BlockInterFunction;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -41,8 +44,7 @@ import com.mxgraph.util.mxUtils;
 public class BasicBlockCodec extends XcosObjectCodec {
 
     private static final String BASIC_BLOCK = BasicBlock.class.getSimpleName();
-    private static final String SIMULATION_FUNCTION_TYPE = "simulationFunctionType";
-    private static final String[] IGNORED_FIELDS = new String[] { SIMULATION_FUNCTION_TYPE, "locked", "parametersPCS" };
+    private static final String[] IGNORED_FIELDS = new String[] { };
     private static final Logger LOG = Logger.getLogger(BasicBlockCodec.class.getName());
 
     /**
@@ -66,36 +68,44 @@ public class BasicBlockCodec extends XcosObjectCodec {
      * Register all known codecs on the {@link mxCodecRegistry}.
      */
     public static void register() {
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.block");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.block.io");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.block.positionning");
+        try {
 
-        for (BlockInterFunction function : XcosCellFactory.BlockInterFunction.values()) {
-            XcosObjectCodec codec = new BasicBlockCodec(XcosCellFactory.createBlock(function), IGNORED_FIELDS, REFS, null);
-            mxCodecRegistry.register(codec);
-        }
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.block");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.block.io");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.block.positionning");
 
-        XcosObjectCodec basicBlockCodec = new BasicBlockCodec(new BasicBlock(0l), IGNORED_FIELDS, REFS, null);
-        mxCodecRegistry.register(basicBlockCodec);
 
-        mxCellCodec cellCodec = new mxCellCodec(new mxCell(), null, REFS, null);
-        mxCodecRegistry.register(cellCodec);
+            Map<Class <? extends BasicBlock>, List<BlockInterFunction>> customBlocks = EnumSet.allOf(BlockInterFunction.class).stream()
+                    .collect(Collectors.groupingBy(BlockInterFunction::getKlass));
 
-        /*
-         * per block specific codec setup
-         */
-        BasicBlockCodec codec = (BasicBlockCodec) mxCodecRegistry.getCodec("AfficheBlock");
-        codec.exclude.add("printTimer");
-        codec.exclude.add("updateAction");
+            for (Class<? extends BasicBlock> blockKlass : customBlocks.keySet()) {
+                final String interfaceFunction = customBlocks.get(blockKlass).get(0).name();
+                XcosObjectCodec codec = new BasicBlockCodec(XcosCellFactory.createBlock(interfaceFunction), IGNORED_FIELDS, REFS, null);
+                mxCodecRegistry.register(codec);
+            }
 
-        /*
-         * Compat. to remove old specific implementations
-         *
-         * These implementation was available from Scilab-5.2.0 to Scilab-5.3.3.
-         */
-        mxCodecRegistry.addAlias("ConstBlock", BASIC_BLOCK);
-        mxCodecRegistry.addAlias("GainBlock", BASIC_BLOCK);
-        mxCodecRegistry.addAlias("PrintBlock", BASIC_BLOCK);
+            mxCellCodec cellCodec = new mxCellCodec(new mxCell(), null, REFS, null);
+            mxCodecRegistry.register(cellCodec);
+
+            /*
+             * per block specific codec setup
+             */
+            BasicBlockCodec codec = (BasicBlockCodec) mxCodecRegistry.getCodec("AfficheBlock");
+            codec.exclude.add("printTimer");
+            codec.exclude.add("updateAction");
+
+            /*
+             * Compat. to remove old specific implementations
+             *
+             * These implementation was available from Scilab-5.2.0 to Scilab-5.3.3.
+             */
+            mxCodecRegistry.addAlias("ConstBlock", BASIC_BLOCK);
+            mxCodecRegistry.addAlias("GainBlock", BASIC_BLOCK);
+            mxCodecRegistry.addAlias("PrintBlock", BASIC_BLOCK);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     /**
index 74b1746..f577f10 100644 (file)
@@ -16,7 +16,10 @@ import static org.scilab.modules.xcos.io.codec.XcosCodec.LOG;
 
 import java.util.Map;
 
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.graph.model.XcosCellFactory;
 import org.scilab.modules.xcos.link.BasicLink;
 import org.scilab.modules.xcos.link.commandcontrol.CommandControlLink;
 import org.scilab.modules.xcos.link.explicit.ExplicitLink;
@@ -30,14 +33,13 @@ import com.mxgraph.io.mxCodecRegistry;
 public class BasicLinkCodec extends XcosObjectCodec {
 
     public static void register() {
-        BasicLinkCodec explicitlinkCodec = new BasicLinkCodec(
-            new ExplicitLink(0l), null, REFS, null);
+        JavaController controller = new JavaController();
+
+        BasicLinkCodec explicitlinkCodec = new BasicLinkCodec(new ExplicitLink(controller.createObject(Kind.LINK)), null, REFS, null);
         mxCodecRegistry.register(explicitlinkCodec);
-        BasicLinkCodec implicitlinkCodec = new BasicLinkCodec(
-            new ImplicitLink(0l), null, REFS, null);
+        BasicLinkCodec implicitlinkCodec = new BasicLinkCodec(new ImplicitLink(controller.createObject(Kind.LINK)), null, REFS, null);
         mxCodecRegistry.register(implicitlinkCodec);
-        BasicLinkCodec commandControllinkCodec = new BasicLinkCodec(
-            new CommandControlLink(0l), null, REFS, null);
+        BasicLinkCodec commandControllinkCodec = new BasicLinkCodec(new CommandControlLink(controller.createObject(Kind.LINK)), null, REFS, null);
         mxCodecRegistry.register(commandControllinkCodec);
     }
 
index 9ad3e6e..c76c509 100644 (file)
@@ -17,6 +17,8 @@ import java.util.logging.Logger;
 
 import org.scilab.modules.graph.utils.ScilabGraphConstants;
 import org.scilab.modules.graph.utils.StyleMap;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.Orientation;
@@ -70,17 +72,19 @@ public class BasicPortCodec extends XcosObjectCodec {
      * Register all the know codecs on the {@link mxCodecRegistry}
      */
     public static void register() {
-        XcosObjectCodec explicitOutputPortCodec = new BasicPortCodec(new ExplicitOutputPort(0l), IGNORED_FIELDS, REFS, null);
+        JavaController controller = new JavaController();
+
+        XcosObjectCodec explicitOutputPortCodec = new BasicPortCodec(new ExplicitOutputPort(controller.createObject(Kind.PORT)), IGNORED_FIELDS, REFS, null);
         mxCodecRegistry.register(explicitOutputPortCodec);
-        XcosObjectCodec explicitInputPortCodec = new BasicPortCodec(new ExplicitInputPort(0l), IGNORED_FIELDS, REFS, null);
+        XcosObjectCodec explicitInputPortCodec = new BasicPortCodec(new ExplicitInputPort(controller.createObject(Kind.PORT)), IGNORED_FIELDS, REFS, null);
         mxCodecRegistry.register(explicitInputPortCodec);
-        XcosObjectCodec implicitOutputPortCodec = new BasicPortCodec(new ImplicitOutputPort(0l), IGNORED_FIELDS, REFS, null);
+        XcosObjectCodec implicitOutputPortCodec = new BasicPortCodec(new ImplicitOutputPort(controller.createObject(Kind.PORT)), IGNORED_FIELDS, REFS, null);
         mxCodecRegistry.register(implicitOutputPortCodec);
-        XcosObjectCodec implicitInputPortCodec = new BasicPortCodec(new ImplicitInputPort(0l), IGNORED_FIELDS, REFS, null);
+        XcosObjectCodec implicitInputPortCodec = new BasicPortCodec(new ImplicitInputPort(controller.createObject(Kind.PORT)), IGNORED_FIELDS, REFS, null);
         mxCodecRegistry.register(implicitInputPortCodec);
-        XcosObjectCodec commandPortCodec = new BasicPortCodec(new CommandPort(0l), IGNORED_FIELDS, REFS, null);
+        XcosObjectCodec commandPortCodec = new BasicPortCodec(new CommandPort(controller.createObject(Kind.PORT)), IGNORED_FIELDS, REFS, null);
         mxCodecRegistry.register(commandPortCodec);
-        XcosObjectCodec controlPortCodec = new BasicPortCodec(new ControlPort(0l), IGNORED_FIELDS, REFS, null);
+        XcosObjectCodec controlPortCodec = new BasicPortCodec(new ControlPort(controller.createObject(Kind.PORT)), IGNORED_FIELDS, REFS, null);
         mxCodecRegistry.register(controlPortCodec);
         mxCodecRegistry.register(new mxObjectCodec(Orientation.EAST));
     }
index a7e4eda..5f5f165 100644 (file)
@@ -37,49 +37,60 @@ public class XcosCodec extends mxCodec {
      * Register packages for encoding/decoding diagrams
      */
     static {
-        // Add all xcos packages
-        mxCodecRegistry.addPackage("org.scilab.modules.graph");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.graph");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.block");
-        mxCodecRegistry
-        .addPackage("org.scilab.modules.xcos.block.positionning");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.link");
-        mxCodecRegistry
-        .addPackage("org.scilab.modules.xcos.link.commandcontrol");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.link.explicit");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.link.implicit");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.port");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.port.command");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.port.control");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.port.input");
-        mxCodecRegistry.addPackage("org.scilab.modules.xcos.port.output");
-        // Add 'types' package to have all scilab types known
-        mxCodecRegistry.addPackage("org.scilab.modules.types");
+        try {
+
+            // Add all xcos packages
+            mxCodecRegistry.addPackage("org.scilab.modules.graph");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.graph");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.block");
+            mxCodecRegistry
+            .addPackage("org.scilab.modules.xcos.block.positionning");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.link");
+            mxCodecRegistry
+            .addPackage("org.scilab.modules.xcos.link.commandcontrol");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.link.explicit");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.link.implicit");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.port");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.port.command");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.port.control");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.port.input");
+            mxCodecRegistry.addPackage("org.scilab.modules.xcos.port.output");
+            // Add 'types' package to have all scilab types known
+            mxCodecRegistry.addPackage("org.scilab.modules.types");
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     /**
      * Install codecs for serializable instance
      */
     static {
+        try {
+
+            // Types
+            ScilabObjectCodec.register();
 
-        // Types
-        ScilabObjectCodec.register();
+            // Diagram
+            XcosDiagramCodec.register();
 
-        // Diagram
-        XcosDiagramCodec.register();
+            // Blocks
+            BasicBlockCodec.register();
 
-        // Blocks
-        BasicBlockCodec.register();
+            // Link
+            BasicLinkCodec.register();
 
-        // Link
-        BasicLinkCodec.register();
+            // Ports
+            BasicPortCodec.register();
 
-        // Ports
-        BasicPortCodec.register();
+            // Orientation
+            OrientationCodec.register();
 
-        // Orientation
-        OrientationCodec.register();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     public static final Logger LOG = Logger.getLogger(XcosCodec.class.getSimpleName());
index 29e5192..5a6a4e8 100644 (file)
@@ -29,6 +29,7 @@ import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.Xcos;
 import org.scilab.modules.xcos.graph.ScicosParameters;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.graph.model.XcosCell;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -36,7 +37,9 @@ import org.w3c.dom.NodeList;
 
 import com.mxgraph.io.mxCodec;
 import com.mxgraph.io.mxCodecRegistry;
+import com.mxgraph.model.mxCell;
 import com.mxgraph.model.mxGraphModel;
+import com.mxgraph.model.mxICell;
 
 /**
  * Codec for an {@link org.scilab.modules.xcos.graph.XcosDiagram} instance.
@@ -191,6 +194,30 @@ public class XcosDiagramCodec extends ScilabGraphCodec {
             field = null;
         }
 
+        // pre 6.0.0 Xcos have an mxCell defaultParent whereas it should be an XcosCell
+        if (field == null && "defaultParent".equals(fieldname) && !(value instanceof XcosCell)) {
+            XcosDiagram diag = (XcosDiagram) obj;
+            XcosCell defaultParent = (XcosCell) diag.getDefaultParent();
+            mxICell root = (mxICell) diag.getModel().getRoot();
+
+            /*
+             * Restore the initial hierarchy
+             *  mxCell -> root
+             *   XcosCell -> default parent with diagram uid / kind
+             *    BasicBlock
+             *    BasicLink
+             *    .
+             *    .
+             *    .
+             */
+
+            Object[] cells = diag.getChildCells(value);
+            root.remove(0);
+            diag.addCells(cells, defaultParent);
+
+            return;
+        }
+
         if (field == null) {
             super.setFieldValue(obj, fieldname, value);
         }
@@ -306,28 +333,6 @@ public class XcosDiagramCodec extends ScilabGraphCodec {
         final mxGraphModel model = (mxGraphModel) diag.getModel();
         final Object parent = diag.getDefaultParent();
 
-        // FIXME is it really needed now ?
-        // main update loop
-        //        final mxGraphModel.Filter filter = new mxGraphModel.Filter() {
-        //            @Override
-        //            public boolean filter(Object cell) {
-        //                if (cell instanceof BasicBlock) {
-        //                    final BasicBlock block = (BasicBlock) cell;
-        //
-        //                    // update parent diagram
-        //                    block.setParentDiagram(diag);
-        //
-        //                    // restore default root in case of a wrong hierarchy.
-        //                    return block.getParent() != parent;
-        //                }
-        //                return false;
-        //            }
-        //        };
-        //        final Collection<Object> blocks = mxGraphModel.filterDescendants(model, filter);
-        //        if (!blocks.isEmpty()) {
-        //            diag.addCells(blocks.toArray());
-        //        }
-
         // pre-5.3 diagram may be saved in a locked state
         // unlock it
         diag.setReadOnly(false);
index 89c3a83..35c10d7 100644 (file)
 
 package org.scilab.modules.xcos.io.codec;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Hashtable;
 import java.util.Map;
 import java.util.WeakHashMap;
 
 import org.scilab.modules.graph.utils.ScilabGraphConstants;
 import org.scilab.modules.graph.utils.StyleMap;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.graph.model.XcosCell;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
 import com.mxgraph.io.mxCellCodec;
@@ -38,9 +45,9 @@ public class XcosObjectCodec extends mxCellCodec {
     /*
      * Cache fields and accessors
      */
-    protected Map<Class, Map<String, Field>> fields = new WeakHashMap<Class, Map<String, Field>>();
-    protected Map<Class, Map<Field, Method>> getters = new WeakHashMap<Class, Map<Field, Method>>();
-    protected Map<Class, Map<Field, Method>> setters = new WeakHashMap<Class, Map<Field, Method>>();
+    protected Map<Class<?>, Map<String, Field>> fields = new WeakHashMap<>();
+    protected Map<Class<?>, Map<Field, Method>> getters = new WeakHashMap<>();
+    protected Map<Class<?>, Map<Field, Method>> setters = new WeakHashMap<>();
 
     /**
      * Attribute name containing {@link com.mxgraph.model.mxCell} style.
@@ -150,6 +157,43 @@ public class XcosObjectCodec extends mxCellCodec {
     }
 
     /**
+     * {@inheritDoc}
+     *
+     * Clone the object while preserving UID / Kind allocation
+     *
+     */
+    @Override
+    protected Object cloneTemplate(Node node) {
+        Object obj = null;
+
+        try {
+            if (template.getClass().isEnum()) {
+                obj = template.getClass().getEnumConstants()[0];
+            } else {
+                if (XcosCell.class.isAssignableFrom(template.getClass())) {
+                    JavaController controller = new JavaController();
+                    Kind kind = ((XcosCell) template).getKind();
+
+                    Constructor<? extends Object> cstrs = template.getClass().getConstructor(Long.TYPE);
+                    obj = cstrs.newInstance(controller.createObject(kind));
+                } else {
+                    obj = template.getClass().newInstance();
+                }
+            }
+
+        } catch (ReflectiveOperationException e) {
+            // ignore
+            e.printStackTrace();
+        } catch (SecurityException e) {
+            // ignore
+            e.printStackTrace();
+        }
+
+        return obj;
+
+    }
+
+    /**
      * Apply compatibility pattern to the decoded object
      *
      * @param dec
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/BlockHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/BlockHandler.java
new file mode 100644 (file)
index 0000000..d9fae8a
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * 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.sax;
+
+import java.util.Arrays;
+
+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.SplitBlock;
+import org.scilab.modules.xcos.block.SuperBlock;
+import org.scilab.modules.xcos.block.TextBlock;
+import org.scilab.modules.xcos.block.io.EventInBlock;
+import org.scilab.modules.xcos.block.io.EventOutBlock;
+import org.scilab.modules.xcos.block.io.ExplicitInBlock;
+import org.scilab.modules.xcos.block.io.ExplicitOutBlock;
+import org.scilab.modules.xcos.block.io.ImplicitInBlock;
+import org.scilab.modules.xcos.block.io.ImplicitOutBlock;
+import org.scilab.modules.xcos.block.positionning.BigSom;
+import org.scilab.modules.xcos.block.positionning.GroundBlock;
+import org.scilab.modules.xcos.block.positionning.Product;
+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.xml.sax.Attributes;
+
+class BlockHandler implements ScilabHandler {
+
+    private final SAXHandler saxHandler;
+
+    /**
+     * Default constructor
+     * @param saxHandler the shared sax handler
+     */
+    BlockHandler(SAXHandler saxHandler) {
+        this.saxHandler = saxHandler;
+    }
+
+    public BasicBlock startElement(HandledElement found, Attributes atts) {
+        String v;
+        BasicBlock block;
+        final long uid = saxHandler.controller.createObject(Kind.BLOCK);
+
+        switch (found) {
+            case AfficheBlock:
+                block = new AfficheBlock(uid);
+                break;
+            case BasicBlock:
+                block = new BasicBlock(uid);
+                break;
+            case BigSom:
+                block = new BigSom(uid);
+                break;
+            case ConstBlock:
+                // FIXME: why not needed anymore
+                block = new BasicBlock(uid);
+                break;
+            case EventInBlock:
+                block = new EventInBlock(uid);
+                break;
+            case EventOutBlock:
+                block = new EventOutBlock(uid);
+                break;
+            case ExplicitInBlock:
+                block = new ExplicitInBlock(uid);
+                break;
+            case ExplicitOutBlock:
+                block = new ExplicitOutBlock(uid);
+                break;
+            case GainBlock:
+                // FIXME: why not needed anymore
+                block = new BasicBlock(uid);
+                break;
+            case GroundBlock:
+                block = new GroundBlock(uid);
+                break;
+            case ImplicitInBlock:
+                block = new ImplicitInBlock(uid);
+                break;
+            case ImplicitOutBlock:
+                block = new ImplicitOutBlock(uid);
+                break;
+            case PrintBlock:
+                // FIXME: why not needed anymore
+                block = new BasicBlock(uid);
+                break;
+            case Product:
+                block = new Product(uid);
+                break;
+            case RoundBlock:
+                block = new RoundBlock(uid);
+                break;
+            case SplitBlock:
+                block = new SplitBlock(uid);
+                break;
+            case Summation:
+                block = new Summation(uid);
+                break;
+            case SuperBlock:
+                block = new SuperBlock(uid);
+                break;
+            case TextBlock:
+                block = new TextBlock(uid);
+                break;
+            case VoltageSensorBlock:
+                block = new VoltageSensorBlock(uid);
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+
+        /*
+         * Set the attributes
+         */
+        v = atts.getValue("id");
+        if (v != null) {
+            saxHandler.allChildren.peek().put(v, uid);
+            saxHandler.controller.setObjectProperty(uid, Kind.BLOCK, ObjectProperties.UID, v);
+        }
+
+        v = atts.getValue("interfaceFunctionName");
+        if (v != null) {
+            saxHandler.controller.setObjectProperty(uid, Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, v);
+        } else {
+            // Setup the interface function accordingly to the mapping table
+            // by default it is empty and might not be serialized (depending on
+            // the class)
+            String defaultInterfaceFunction = Arrays.stream(BlockInterFunction.values()).filter(n -> n.getKlass().equals(block.getClass())).map(e -> e.name())
+                                              .findFirst().get();
+            saxHandler.controller.setObjectProperty(uid, Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, defaultInterfaceFunction);
+        }
+        v = atts.getValue("simulationFunctionName");
+        if (v != null) {
+            saxHandler.controller.setObjectProperty(uid, Kind.BLOCK, ObjectProperties.SIM_FUNCTION_NAME, v);
+        }
+        v = atts.getValue("blockType");
+        if (v != null) {
+            saxHandler.controller.setObjectProperty(uid, Kind.BLOCK, ObjectProperties.SIM_BLOCKTYPE, v);
+        }
+        v = atts.getValue("style");
+        if (v != null) {
+            saxHandler.controller.setObjectProperty(uid, Kind.BLOCK, ObjectProperties.STYLE, v);
+        }
+
+        saxHandler.insertChild(block);
+        return block;
+    }
+
+    public void endElement(HandledElement found) {
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/CustomHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/CustomHandler.java
new file mode 100644 (file)
index 0000000..07a02f3
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * 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.sax;
+
+import java.util.HashMap;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+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.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.port.BasicPort;
+import org.scilab.modules.xcos.port.Orientation;
+import org.xml.sax.Attributes;
+
+class CustomHandler implements ScilabHandler {
+
+    private final SAXHandler saxHandler;
+
+    /**
+     * Default constructor
+     * @param saxHandler the shared sax handler
+     */
+    CustomHandler(SAXHandler saxHandler) {
+        this.saxHandler = saxHandler;
+    }
+
+    public Object startElement(HandledElement found, final Attributes atts) {
+        long uid = 0l;
+        String v;
+
+        switch (found) {
+            case Orientation: {
+                // defensive programming
+                if (!(saxHandler.parents.peek() instanceof BasicPort)) {
+                    return null;
+                }
+                BasicPort parent = (BasicPort) saxHandler.parents.peek();
+
+                v = atts.getValue("value");
+                if (v != null) {
+                    final String orientationString = v;
+                    Optional<Orientation> orientation = Stream.of(Orientation.values()).filter(o -> o.name().equals(orientationString)).findFirst();
+                    if (orientation.isPresent()) {
+                        parent.setOrientation(orientation.get());
+                    }
+                }
+
+                return null;
+            }
+            case XcosDiagram:
+                // do not allocate this is already allocated as #root
+                uid = saxHandler.root.getUID();
+
+                /*
+                 * Decode some graph properties
+                 */
+                v = atts.getValue("savedFile");
+                if (v != null) {
+                    saxHandler.controller.setObjectProperty(uid, Kind.DIAGRAM, ObjectProperties.PATH, v);
+                }
+
+                /*
+                 * Decode simulation properties
+                 */
+                VectorOfDouble properties = new VectorOfDouble();
+                saxHandler.controller.getObjectProperty(uid, Kind.DIAGRAM, ObjectProperties.PROPERTIES, properties);
+
+                v = atts.getValue("finalIntegrationTime");
+                if (v != null) {
+                    properties.set(ScicosParameters.FINAL_INTEGRATION_TIME, Double.valueOf(v));
+                }
+                v = atts.getValue("integratorAbsoluteTolerance");
+                if (v != null) {
+                    properties.set(ScicosParameters.INTEGRATOR_ABSOLUTE_TOLERANCE, Double.valueOf(v));
+                }
+                v = atts.getValue("integratorRelativeTolerance");
+                if (v != null) {
+                    properties.set(ScicosParameters.INTEGRATOR_RELATIVE_TOLERANCE, Double.valueOf(v));
+                }
+                v = atts.getValue("toleranceOnTime");
+                if (v != null) {
+                    properties.set(ScicosParameters.TOLERANCE_ON_TIME, Double.valueOf(v));
+                }
+                v = atts.getValue("maxIntegrationTimeinterval");
+                if (v != null) {
+                    properties.set(ScicosParameters.MAX_INTEGRATION_TIME_INTERVAL, Double.valueOf(v));
+                }
+                v = atts.getValue("maximumStepSize");
+                if (v != null) {
+                    properties.set(ScicosParameters.MAXIMUM_STEP_SIZE, Double.valueOf(v));
+                }
+                v = atts.getValue("realTimeScaling");
+                if (v != null) {
+                    properties.set(ScicosParameters.REAL_TIME_SCALING, Double.valueOf(v));
+                }
+                v = atts.getValue("solver");
+                if (v != null) {
+                    properties.set(ScicosParameters.SOLVER, Double.valueOf(v));
+                }
+
+                saxHandler.controller.setObjectProperty(uid, Kind.DIAGRAM, ObjectProperties.PROPERTIES, properties);
+
+            // no break on purpose, we decode non-root specific properties later
+            case SuperBlockDiagram:
+                final Kind kind;
+                if (uid == 0l) {
+                    XcosCell parent = saxHandler.lookupForParentXcosCellElement();
+                    uid = parent.getUID();
+                    kind = parent.getKind();
+                } else {
+                    kind = Kind.DIAGRAM;
+                }
+
+                /*
+                 * Decode the properties shared between a DIAGRAM and a BLOCK
+                 */
+                VectorOfInt colors = new VectorOfInt();
+                saxHandler.controller.getObjectProperty(uid, kind, ObjectProperties.COLOR, colors);
+                v = atts.getValue("background");
+                if (v != null) {
+                    colors.set(0, Integer.valueOf(v));
+                }
+                v = atts.getValue("gridEnabled");
+                if (v != null) {
+                    colors.set(1, Integer.valueOf(v));
+                }
+                saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.COLOR, colors);
+
+                v = atts.getValue("title");
+                if (v != null) {
+                    saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.TITLE, v);
+                }
+
+                /*
+                 * Update some states
+                 */
+                saxHandler.allChildren.push(new HashMap<>());
+                return new ScicosObjectOwner(uid, kind);
+            default:
+                throw new IllegalArgumentException();
+        }
+    }
+
+    public void endElement(HandledElement found) {
+        switch (found) {
+            case Orientation:
+                break;
+            case XcosDiagram:
+                XcosCellFactory.insertChildren(saxHandler.controller, saxHandler.root);
+                break;
+            case SuperBlockDiagram:
+                saxHandler.allChildren.pop();
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+
+        // FIXME manage unresolved link source
+        // FIXME manage unresolved link target
+
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/HandledElement.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/HandledElement.java
new file mode 100644 (file)
index 0000000..0a5b6e3
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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.sax;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Stream;
+
+/**
+ * Contains all the handled elements to Xcos by category to ease dispatch.
+ *
+ * <p>
+ * Note: the names correspond to each Element localName.
+ */
+enum HandledElement {
+    add(HandledElementsCategory.RAW_DATA),
+    AfficheBlock(HandledElementsCategory.BLOCK),
+    Array(HandledElementsCategory.RAW_DATA),
+    BasicBlock(HandledElementsCategory.BLOCK),
+    BigSom(HandledElementsCategory.BLOCK),
+    CommandControlLink(HandledElementsCategory.LINK),
+    CommandPort(HandledElementsCategory.PORT),
+    ConstBlock(HandledElementsCategory.BLOCK),
+    ControlPort(HandledElementsCategory.PORT),
+    data(HandledElementsCategory.RAW_DATA),
+    EventInBlock(HandledElementsCategory.BLOCK),
+    EventOutBlock(HandledElementsCategory.BLOCK),
+    ExplicitInBlock(HandledElementsCategory.BLOCK),
+    ExplicitInputPort(HandledElementsCategory.PORT),
+    ExplicitLink(HandledElementsCategory.LINK),
+    ExplicitOutBlock(HandledElementsCategory.BLOCK),
+    ExplicitOutputPort(HandledElementsCategory.PORT),
+    GainBlock(HandledElementsCategory.BLOCK),
+    GroundBlock(HandledElementsCategory.BLOCK),
+    ImplicitInBlock(HandledElementsCategory.BLOCK),
+    ImplicitInputPort(HandledElementsCategory.PORT),
+    ImplicitLink(HandledElementsCategory.LINK),
+    ImplicitOutBlock(HandledElementsCategory.BLOCK),
+    ImplicitOutputPort(HandledElementsCategory.PORT),
+    mxCell(HandledElementsCategory.JGRAPHX),
+    mxGeometry(HandledElementsCategory.JGRAPHX),
+    mxPoint(HandledElementsCategory.JGRAPHX),
+    Orientation(HandledElementsCategory.CUSTOM),
+    PrintBlock(HandledElementsCategory.BLOCK),
+    Product(HandledElementsCategory.BLOCK),
+    RoundBlock(HandledElementsCategory.BLOCK),
+    ScilabBoolean(HandledElementsCategory.RAW_DATA),
+    ScilabDouble(HandledElementsCategory.RAW_DATA),
+    ScilabInteger(HandledElementsCategory.RAW_DATA),
+    ScilabString(HandledElementsCategory.RAW_DATA),
+    SplitBlock(HandledElementsCategory.BLOCK),
+    Summation(HandledElementsCategory.BLOCK),
+    SuperBlock(HandledElementsCategory.BLOCK),
+    SuperBlockDiagram(HandledElementsCategory.CUSTOM),
+    TextBlock(HandledElementsCategory.BLOCK),
+    VoltageSensorBlock(HandledElementsCategory.BLOCK),
+    XcosDiagram(HandledElementsCategory.CUSTOM),;
+
+    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));
+
+        return Collections.unmodifiableMap(map);
+    }
+
+    final HandledElementsCategory category;
+
+    private HandledElement(final HandledElementsCategory category) {
+        this.category = category;
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/HandledElementsCategory.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/HandledElementsCategory.java
new file mode 100644 (file)
index 0000000..16a3125
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * 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.sax;
+
+enum HandledElementsCategory {
+    JGRAPHX, BLOCK, LINK, PORT, RAW_DATA, CUSTOM
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/JGraphXHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/JGraphXHandler.java
new file mode 100644 (file)
index 0000000..3dc14d7
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * 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.sax;
+
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.graph.model.XcosCell;
+import org.xml.sax.Attributes;
+
+import com.mxgraph.model.mxGeometry;
+import com.mxgraph.util.mxPoint;
+
+class JGraphXHandler implements ScilabHandler {
+
+    private final SAXHandler saxHandler;
+
+    JGraphXHandler(SAXHandler saxHandler) {
+        this.saxHandler = saxHandler;
+    }
+
+    public Object startElement(HandledElement found, Attributes atts) {
+        String v;
+
+        switch (found) {
+            case mxCell: {
+                v = atts.getValue("parent");
+                if (v != null) {
+                    long parentUID = saxHandler.allChildren.peek().getOrDefault(v, 0l);
+                    if (parentUID != 0) {
+                        v = atts.getValue("value");
+                        if (v != null) {
+                            Kind kind = saxHandler.controller.getKind(parentUID);
+                            saxHandler.controller.setObjectProperty(parentUID, kind, ObjectProperties.LABEL, v);
+                        }
+                    }
+                }
+
+                return null;
+            }
+            case mxGeometry: {
+                mxGeometry g = new mxGeometry();
+
+                v = atts.getValue("height");
+                if (v != null) {
+                    g.setHeight(Double.valueOf(v));
+                }
+                v = atts.getValue("width");
+                if (v != null) {
+                    g.setWidth(Double.valueOf(v));
+                }
+                v = atts.getValue("x");
+                if (v != null) {
+                    g.setX(Double.valueOf(v));
+                }
+                v = atts.getValue("y");
+                if (v != null) {
+                    g.setY(Double.valueOf(v));
+                }
+
+                return g;
+            }
+            case mxPoint: {
+                // defensive programming
+                if (!(saxHandler.parents.peek() instanceof mxGeometry)) {
+                    return null;
+                }
+                mxGeometry parent = (mxGeometry) saxHandler.parents.peek();
+
+                mxPoint p = new mxPoint();
+
+                v = atts.getValue("x");
+                if (v != null) {
+                    p.setX(Double.valueOf(v));
+                }
+                v = atts.getValue("y");
+                if (v != null) {
+                    p.setY(Double.valueOf(v));
+                }
+                v = atts.getValue("as");
+                if ("sourcePoint".equals(v)) {
+                    parent.setSourcePoint(p);
+                } else if ("targetPoint".equals(v)) {
+                    parent.setTargetPoint(p);
+                }
+                return p;
+            }
+            default:
+                throw new IllegalArgumentException();
+        }
+    }
+
+    public void endElement(HandledElement found) {
+        switch (found) {
+            case mxCell:
+                break;
+            case mxGeometry: {
+                // defensive programming
+                if (!(saxHandler.parents.peek() instanceof mxGeometry)) {
+                    return;
+                }
+                mxGeometry g = (mxGeometry) saxHandler.parents.peek();
+                if (!(saxHandler.parents.peek(1) instanceof XcosCell)) {
+                    return;
+                }
+                XcosCell cell = (XcosCell) saxHandler.parents.peek(1);
+
+                cell.setGeometry(g);
+            }
+            case mxPoint:
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/LinkHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/LinkHandler.java
new file mode 100644 (file)
index 0000000..12d7478
--- /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.sax;
+
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+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;
+
+class LinkHandler implements ScilabHandler {
+
+    private final SAXHandler saxHandler;
+
+    /**
+     * Default constructor
+     * @param saxHandler the shared sax handler
+     */
+    LinkHandler(SAXHandler saxHandler) {
+        this.saxHandler = saxHandler;
+    }
+
+    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();
+        }
+
+        /*
+         * Set the attributes
+         */
+        v = atts.getValue("id");
+        if (v != null) {
+            saxHandler.allChildren.peek().put(v, uid);
+            saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.UID, v);
+        }
+
+        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);
+        }
+
+        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);
+        }
+
+        v = atts.getValue("style");
+        if (v != null) {
+            saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.STYLE, v);
+        }
+
+        v = atts.getValue("value");
+        if (v != null) {
+            saxHandler.controller.setObjectProperty(uid, Kind.LINK, ObjectProperties.LABEL, v);
+        }
+
+        saxHandler.insertChild(link);
+        return link;
+    }
+
+    public void endElement(HandledElement found) {
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/PortHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/PortHandler.java
new file mode 100644 (file)
index 0000000..b15fe49
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * 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.sax;
+
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfInt;
+import org.scilab.modules.xcos.VectorOfScicosID;
+import org.scilab.modules.xcos.port.BasicPort;
+import org.scilab.modules.xcos.port.command.CommandPort;
+import org.scilab.modules.xcos.port.control.ControlPort;
+import org.scilab.modules.xcos.port.input.ExplicitInputPort;
+import org.scilab.modules.xcos.port.input.ImplicitInputPort;
+import org.scilab.modules.xcos.port.output.ExplicitOutputPort;
+import org.scilab.modules.xcos.port.output.ImplicitOutputPort;
+import org.xml.sax.Attributes;
+
+class PortHandler implements ScilabHandler {
+
+    private final SAXHandler saxHandler;
+
+    /**
+     * Default constructor
+     * @param saxHandler the shared sax handler
+     */
+    PortHandler(SAXHandler saxHandler) {
+        this.saxHandler = saxHandler;
+    }
+
+    public BasicPort startElement(HandledElement found, Attributes atts) {
+        BasicPort port;
+        ObjectProperties relatedProperty;
+        final long uid = saxHandler.controller.createObject(Kind.PORT);
+
+        /*
+         * Allocate the port with the right class to set default properties
+         */
+
+        switch (found) {
+            case CommandPort:
+                port = new CommandPort(uid);
+                relatedProperty = ObjectProperties.EVENT_OUTPUTS;
+                break;
+            case ControlPort:
+                port = new ControlPort(uid);
+                relatedProperty = ObjectProperties.EVENT_INPUTS;
+                break;
+            case ExplicitInputPort:
+                port = new ExplicitInputPort(uid);
+                relatedProperty = ObjectProperties.INPUTS;
+                break;
+            case ExplicitOutputPort:
+                port = new ExplicitOutputPort(uid);
+                relatedProperty = ObjectProperties.OUTPUTS;
+                break;
+            case ImplicitInputPort:
+                port = new ImplicitInputPort(uid);
+                relatedProperty = ObjectProperties.INPUTS;
+                break;
+            case ImplicitOutputPort:
+                port = new ImplicitOutputPort(uid);
+                relatedProperty = ObjectProperties.OUTPUTS;
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+
+        /*
+         * Setup the properties
+         */
+        String v;
+
+        v = atts.getValue("id");
+        if (v != null) {
+            saxHandler.allChildren.peek().put(v, uid);
+        }
+
+        v = atts.getValue("style");
+        if (v != null) {
+            saxHandler.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.STYLE, v);
+        }
+
+        VectorOfInt datatype = new VectorOfInt();
+        saxHandler.controller.getObjectProperty(uid, Kind.PORT, ObjectProperties.DATATYPE, datatype);
+
+        v = atts.getValue("dataType");
+        if (v != null) {
+            datatype.set(0, BasicPort.DataType.valueOf(v).ordinal());
+        }
+        v = atts.getValue("dataColumns");
+        if (v != null) {
+            datatype.set(1, Integer.valueOf(v));
+        }
+        v = atts.getValue("dataLines");
+        if (v != null) {
+            datatype.set(2, Integer.valueOf(v));
+        }
+
+        saxHandler.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));
+        }
+
+        /*
+         * Associate to the parent block
+         */
+
+        int ordering = 0;
+        long parent = 0l;
+
+        v = atts.getValue("ordering");
+        if (v != null) {
+            ordering = Integer.valueOf(v) - 1;
+        }
+
+        v = atts.getValue("parent");
+        if (v != null) {
+            parent = saxHandler.allChildren.peek().get(v);
+        }
+
+        VectorOfScicosID associatedPorts = new VectorOfScicosID();
+        saxHandler.controller.getObjectProperty(parent, Kind.BLOCK, relatedProperty, associatedPorts);
+
+        associatedPorts.add(ordering, uid);
+        saxHandler.controller.referenceObject(uid);
+
+        saxHandler.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.SOURCE_BLOCK, parent);
+        saxHandler.controller.setObjectProperty(parent, Kind.BLOCK, relatedProperty, associatedPorts);
+
+        return port;
+    }
+
+    public void endElement(HandledElement found) {
+    }
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/RawDataHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/RawDataHandler.java
new file mode 100644 (file)
index 0000000..154f216
--- /dev/null
@@ -0,0 +1,388 @@
+/*
+ * 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.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;
+import java.util.Map;
+
+import org.scilab.modules.types.ScilabBoolean;
+import org.scilab.modules.types.ScilabDouble;
+import org.scilab.modules.types.ScilabInteger;
+import org.scilab.modules.types.ScilabIntegerTypeEnum;
+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.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfString;
+import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
+import org.xml.sax.Attributes;
+
+import com.mxgraph.model.mxGeometry;
+import com.mxgraph.util.mxPoint;
+
+class RawDataHandler implements ScilabHandler {
+
+    static class RawDataDescriptor {
+        final ObjectProperties as;
+        final HandledElement found;
+        final String scilabClass;
+        final Object value;
+
+        public RawDataDescriptor(ObjectProperties as, HandledElement found, String scilabClass, Object container) {
+            // defensive programming
+            if (as == null) {
+                throw new IllegalAccessError();
+            }
+
+            this.as = as;
+            this.found = found;
+            this.scilabClass = scilabClass;
+            this.value = container;
+        }
+    }
+
+    private final SAXHandler saxHandler;
+    private final Map<String, ObjectProperties> propertyMap;
+
+    /**
+     * Default constructor
+     * @param saxHandler the shared sax handler
+     */
+    RawDataHandler(SAXHandler saxHandler) {
+        this.saxHandler = saxHandler;
+
+        Map<String, ObjectProperties> localPropertyMap = new HashMap<>();
+        localPropertyMap.put("context", ObjectProperties.DIAGRAM_CONTEXT);
+        localPropertyMap.put("equations", ObjectProperties.EQUATIONS);
+        localPropertyMap.put("exprs", ObjectProperties.EXPRS);
+        localPropertyMap.put("integerParameters", ObjectProperties.IPAR);
+        localPropertyMap.put("nbZerosCrossing", ObjectProperties.NZCROSS);
+        localPropertyMap.put("nmode", ObjectProperties.NMODE);
+        localPropertyMap.put("objectsParameters", ObjectProperties.OPAR);
+        localPropertyMap.put("oDState", ObjectProperties.ODSTATE);
+        localPropertyMap.put("points", ObjectProperties.CONTROL_POINTS);
+        localPropertyMap.put("realParameters", ObjectProperties.RPAR);
+        // TODO might be incomplete
+        propertyMap = Collections.unmodifiableMap(localPropertyMap);
+    }
+
+    public Object startElement(HandledElement found, Attributes atts) {
+        String v;
+
+        switch (found) {
+            case ScilabBoolean:
+            // no break on purpose
+            case ScilabDouble:
+            // no break on purpose
+            case ScilabInteger:
+            // no break on purpose
+            case ScilabString:
+            // no break on purpose
+            case Array: {
+                String as = atts.getValue("as");
+
+                /*
+                 * first : try to retrieve the already decoded binary data
+                 */
+                boolean binary = false;
+                int position = -1;
+
+                v = atts.getValue("binary");
+                if (v != null) {
+                    binary = Boolean.valueOf(v);
+                }
+                v = atts.getValue("position");
+                if (v != null) {
+                    position = Integer.valueOf(v);
+                }
+
+                if (binary && (0 <= position && position < saxHandler.dictionary.size())) {
+                    return new RawDataDescriptor(propertyMap.get(as), found, null, saxHandler.dictionary.get(position));
+                }
+
+                /*
+                 * otherwise : this is not a binary, decode it
+                 */
+                int height = 0;
+                int width = 0;
+                String scilabClass = "ScilabDouble";
+
+                v = atts.getValue("height");
+                if (v != null) {
+                    height = Integer.valueOf(v);
+                }
+                v = atts.getValue("width");
+                if (v != null) {
+                    width = Integer.valueOf(v);
+                }
+                v = atts.getValue("scilabClass");
+                if (v != null) {
+                    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;
+                }
+
+                return new RawDataDescriptor(propertyMap.get(as), found, scilabClass, container);
+            }
+            case add: {
+                // defensive programming
+                if (!(saxHandler.parents.peek() instanceof RawDataDescriptor)) {
+                    return null;
+                }
+                RawDataDescriptor fieldValue = (RawDataDescriptor) saxHandler.parents.peek();
+
+                switch (fieldValue.as) {
+                    case DIAGRAM_CONTEXT: {
+                        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: {
+                // defensive programming
+                if (!(saxHandler.parents.peek() instanceof RawDataDescriptor)) {
+                    return null;
+                }
+                RawDataDescriptor fieldValue = (RawDataDescriptor) saxHandler.parents.peek();
+
+                /*
+                 * Decode the position and then switch per container klass
+                 */
+
+                int column = 0;
+                int line = 0;
+
+                v = atts.getValue("column");
+                if (v != null) {
+                    column = Integer.valueOf(v);
+                }
+                v = atts.getValue("line");
+                if (v != null) {
+                    line = Integer.valueOf(v);
+                }
+
+                switch (fieldValue.found) {
+                    case ScilabBoolean: {
+                        ScilabBoolean localScilabValue = ((ScilabBoolean) fieldValue.value);
+                        boolean[][] data = localScilabValue.getData();
+
+                        v = atts.getValue("value");
+                        if (v != null) {
+                            data[line][column] = Boolean.valueOf(v);
+                        }
+                        break;
+                    }
+                    case ScilabDouble: {
+                        ScilabDouble localScilabValue = ((ScilabDouble) fieldValue.value);
+                        double[][] realPartData = localScilabValue.getRealPart();
+                        double[][] imaginaryPartData = localScilabValue.getImaginaryPart();
+
+                        v = atts.getValue("realPart");
+                        if (v != null) {
+                            realPartData[line][column] = Double.valueOf(v);
+                        }
+
+                        v = atts.getValue("imaginaryPart");
+                        if (v != null) {
+                            // allocate the imaginary part on demand
+                            if (imaginaryPartData == null) {
+                                imaginaryPartData = new double[localScilabValue.getHeight()][localScilabValue.getWidth()];
+                                localScilabValue.setImaginaryPart(imaginaryPartData);
+                            }
+
+                            imaginaryPartData[line][column] = Double.valueOf(v);
+                        }
+                        break;
+                    }
+                    case ScilabInteger: {
+                        ScilabInteger localScilabValue = ((ScilabInteger) fieldValue.value);
+                        ScilabIntegerTypeEnum precision = localScilabValue.getPrec();
+
+                        v = atts.getValue("value");
+                        if (v != null) {
+                            switch (precision) {
+                                case sci_int8:
+                                case sci_uint8:
+                                    localScilabValue.getDataAsByte()[line][column] = Byte.valueOf(v);
+                                    break;
+                                case sci_int16:
+                                case sci_uint16:
+                                    localScilabValue.getDataAsShort()[line][column] = Short.valueOf(v);
+                                    break;
+                                case sci_int32:
+                                case sci_uint32:
+                                    localScilabValue.getDataAsInt()[line][column] = Integer.valueOf(v);
+                                    break;
+                                case sci_int64:
+                                case sci_uint64:
+                                    localScilabValue.getDataAsLong()[line][column] = Long.valueOf(v);
+                                    break;
+                            }
+                        }
+                        break;
+                    }
+                    case ScilabString: {
+                        ScilabString localScilabValue = ((ScilabString) fieldValue.value);
+                        String[][] data = localScilabValue.getData();
+                        data[line][column] = atts.getValue("value");
+                        break;
+                    }
+                    default:
+                        break;
+                }
+            }
+            default:
+                throw new IllegalArgumentException();
+        }
+
+        return null;
+    }
+
+    public void endElement(HandledElement found) {
+        switch (found) {
+            case Array:
+            // no break on purpose
+            case ScilabBoolean:
+            // no break on purpose
+            case ScilabDouble:
+            // no break on purpose
+            case ScilabInteger:
+            // no break on purpose
+            case ScilabString: {
+                // defensive programming
+                if (!(saxHandler.parents.peek() instanceof RawDataDescriptor)) {
+                    return;
+                }
+                RawDataDescriptor fieldValue = (RawDataDescriptor) saxHandler.parents.peek();
+                Object parent = saxHandler.parents.peek(1);
+
+                switch (fieldValue.as) {
+                    case CONTROL_POINTS: {
+                        // defensive programming
+                        if (!(parent instanceof mxGeometry)) {
+                            return;
+                        }
+                        mxGeometry geom = (mxGeometry) parent;
+                        ArrayList<mxPoint> value = (ArrayList<mxPoint>) fieldValue.value;
+                        geom.setPoints(value);
+                        break;
+                    }
+                    case DIAGRAM_CONTEXT: {
+                        // defensive programming
+                        if (!(parent instanceof ScicosObjectOwner)) {
+                            return;
+                        }
+                        ScicosObjectOwner diagram = (ScicosObjectOwner) parent;
+
+                        ArrayList<String> value = (ArrayList<String>) fieldValue.value;
+                        VectorOfString ctx = new VectorOfString(value.size());
+                        for (int i = 0; i < value.size(); i++) {
+                            ctx.set(i, value.get(i));
+                        }
+                        saxHandler.controller.setObjectProperty(diagram.getUID(), diagram.getKind(), ObjectProperties.DIAGRAM_CONTEXT, ctx);
+                        break;
+                    }
+                    default:
+                        System.err.println("RawDataHandler not handled: " + fieldValue.as);
+                        break;
+
+                }
+                break;
+            }
+            case add:
+                break;
+            case data:
+                break;
+            default:
+                throw new IllegalArgumentException();
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/SAXHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/SAXHandler.java
new file mode 100644 (file)
index 0000000..48aa98b
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * 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.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 org.scilab.modules.types.ScilabList;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+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.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Implement a diagram SAX handler to decode the document as a stream.
+ */
+public class SAXHandler extends DefaultHandler {
+
+    /*
+     * Utilities classes and methods
+     */
+    private static class UnresolvedReference {
+        private ScicosObjectOwner owner;
+        private ObjectProperties property;
+        private ObjectProperties associatedProperty;
+        private int associatedPropertyIndex;
+
+        public UnresolvedReference(ScicosObjectOwner owner, ObjectProperties property, ObjectProperties associatedProperty, int associatedPropertyIndex) {
+            this.owner = owner;
+            this.property = property;
+            this.associatedProperty = associatedProperty;
+            this.associatedPropertyIndex = associatedPropertyIndex;
+        }
+
+        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);
+        }
+    }
+
+    XcosCell lookupForParentXcosCellElement() {
+        // TODO in fact we can use the depth (eg. size) of the stack to retrieve
+        // this value
+        // is it necessary to improve performance (over safety) there ?
+        Optional<XcosCell> parentBlock = parents.stream()
+                                         .filter(o -> o instanceof XcosCell)
+                                         .map(o -> (XcosCell) o)
+                                         .findFirst();
+
+        return parentBlock.orElse(null);
+    }
+
+    /*
+     * Instance data, raw shared with the sub-handlers
+     */
+    protected final XcosDiagram root;
+    protected final ScilabList dictionary;
+    protected final JavaController controller;
+    protected final Map<String, HandledElement> elementMap;
+    protected final Map<HandledElementsCategory, ScilabHandler> handlers;
+
+    /*
+     * Current state of the parser, also raw shared with the sub-handlers
+     */
+
+    /** Contains the decoded parent' node (as an in-depth view of decoded elements) */
+    Stack<Object> parents = new Stack<>();
+    /** Mapping of UUID JGraphX strings to an MVC decoded object */
+    Stack<HashMap<String, Long>> allChildren = new Stack<>();
+    /** 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) {
+        this.root = content;
+        this.dictionary = dictionary;
+
+        this.controller = new JavaController();
+        this.elementMap = HandledElement.getMap();
+
+        // add all the known handler to the map
+        EnumMap<HandledElementsCategory, ScilabHandler> localHandlers = new EnumMap<>(HandledElementsCategory.class);
+        localHandlers.put(HandledElementsCategory.JGRAPHX, new JGraphXHandler(this));
+        localHandlers.put(HandledElementsCategory.BLOCK, new BlockHandler(this));
+        localHandlers.put(HandledElementsCategory.LINK, new LinkHandler(this));
+        localHandlers.put(HandledElementsCategory.PORT, new PortHandler(this));
+        localHandlers.put(HandledElementsCategory.RAW_DATA, new RawDataHandler(this));
+        localHandlers.put(HandledElementsCategory.CUSTOM, new CustomHandler(this));
+
+        this.handlers = Collections.unmodifiableMap(localHandlers);
+    }
+
+    /*
+     * Implemented method
+     */
+
+    @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
+
+        HandledElement found = elementMap.get(localName);
+        Object localParent = null;
+
+        if (found != null) {
+            localParent = handlers.get(found.category).startElement(found, atts);
+        }
+
+        parents.push(localParent);
+    }
+
+    @Override
+    public void endElement(String uri, String localName, String qName) throws SAXException {
+        HandledElement found = elementMap.get(localName);
+
+        if (found != null) {
+            handlers.get(found.category).endElement(found);
+        }
+
+        parents.pop();
+    }
+
+    /**
+     * Insert a child into the current sub-diagram
+     *
+     * Manage hierarchy association :
+     * <UL>
+     *   <LI>{@link ObjectProperties#PARENT_BLOCK}
+     *   <LI>{@link ObjectProperties#PARENT_DIAGRAM}
+     *   <LI>{@link ObjectProperties#CHILDREN}
+     */
+    protected void insertChild(final XcosCell cell) {
+        long parentUID;
+        Kind parentKind;
+
+        final XcosCell parentBlock = lookupForParentXcosCellElement();
+        if (parentBlock != null) {
+            parentUID = parentBlock.getUID();
+            parentKind = parentBlock.getKind();
+
+            controller.setObjectProperty(cell.getUID(), cell.getKind(), ObjectProperties.PARENT_BLOCK, parentUID);
+        } else {
+            parentUID = ((XcosCell) root.getDefaultParent()).getUID();
+            parentKind = Kind.DIAGRAM;
+        }
+        controller.setObjectProperty(cell.getUID(), cell.getKind(), ObjectProperties.PARENT_DIAGRAM, ((XcosCell) root.getDefaultParent()).getUID());
+
+        VectorOfScicosID children = new VectorOfScicosID();
+        controller.getObjectProperty(parentUID, parentKind, ObjectProperties.CHILDREN, children);
+
+        children.add(cell.getUID());
+        controller.referenceObject(cell.getUID());
+
+        controller.setObjectProperty(parentUID, parentKind, ObjectProperties.CHILDREN, children);
+    }
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/ScilabHandler.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/ScilabHandler.java
new file mode 100644 (file)
index 0000000..91bf552
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.sax;
+
+import org.xml.sax.Attributes;
+
+/**
+ * Common interface to decode specific content
+ */
+interface ScilabHandler {
+    Object startElement(HandledElement found, Attributes atts);
+    void endElement(HandledElement found);
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/Stack.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/Stack.java
new file mode 100644 (file)
index 0000000..0717cfe
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.sax;
+
+import java.util.ArrayList;
+import java.util.Vector;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+/**
+ * Local implementation of a Stack as the java default one inherit from
+ * {@link Vector}.
+ *
+ * @param <E>
+ *            the contained item klass
+ */
+class Stack<E> {
+    private ArrayList<E> stack = new ArrayList<>();
+
+    public void pop() {
+        stack.remove(stack.size() - 1);
+    }
+
+    public void push(E e) {
+        stack.add(e);
+    }
+
+    public E peek() {
+        return peek(0);
+    }
+
+    public E peek(int depth) {
+        return stack.get(stack.size() - 1 - depth);
+    }
+
+    public int size() {
+        return stack.size();
+    }
+
+    public Stream<E> stream() {
+        // stream in a reversed order (traditional stack usage)
+        return IntStream.range(0, stack.size()).mapToObj(i -> stack.get(stack.size() - 1 - i));
+    }
+
+    @Override
+    public String toString() {
+        return stack.toString();
+    }
+}
\ No newline at end of file
index 89dfd86..457d44f 100644 (file)
@@ -22,8 +22,8 @@ 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.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
@@ -31,6 +31,7 @@ import org.scilab.modules.commons.xml.ScilabTransformerFactory;
 import org.scilab.modules.types.ScilabList;
 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.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -67,28 +68,16 @@ public class ContentEntry implements Entry {
     @Override
     public void load(ZipEntry entry, InputStream stream) throws IOException {
         try {
-            final XcosCodec codec = new XcosCodec();
             final TransformerFactory tranFactory = ScilabTransformerFactory.newInstance();
             final Transformer aTransformer = tranFactory.newTransformer();
 
             final StreamSource src = new StreamSource(stream);
-            final DOMResult result = new DOMResult(codec.getDocument());
+            final SAXResult result = new SAXResult(new SAXHandler(content, dictionary));
 
             LOG.entering("Transformer", "transform");
             aTransformer.transform(src, result);
             LOG.exiting("Transformer", "transform");
 
-            LOG.entering("XcosCodec", "decode");
-            codec.setElementIdAttributes();
-            if (dictionary == null) {
-                codec.decode(result.getNode().getFirstChild(), content);
-            } else {
-                XcosCodec.enableBinarySerialization(dictionary);
-                codec.decode(result.getNode().getFirstChild(), content);
-                XcosCodec.disableBinarySerialization();
-            }
-            LOG.exiting("XcosCodec", "decode");
-
         } catch (TransformerConfigurationException e) {
             Logger.getLogger(ContentEntry.class.getName()).severe(e.getMessageAndLocation());
         } catch (TransformerException e) {
index 37e7ceb..5136e14 100644 (file)
@@ -124,6 +124,10 @@ public abstract class BasicPort extends XcosCell {
         setStyle(style);
         setGeometry(new mxGeometry(0, 0, DEFAULT_PORTSIZE, DEFAULT_PORTSIZE));
         setOrientation(orientation);
+
+        boolean isImplicit = getType() == Type.IMPLICIT;
+        JavaController controller = new JavaController();
+        controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.IMPLICIT, isImplicit);
     }
 
     /**