Xcos GUI: handle COSF import 72/17272/5
Clément DAVID [Wed, 30 Sep 2015 13:32:49 +0000 (15:32 +0200)]
Rendering is *NOT* translated from Scicos to Xcos yet.

Change-Id: I4c1dd67c5dd76967bb2a23bd4af9c808fc5f9312

27 files changed:
scilab/modules/scicos/sci_gateway/cpp/sci_scicos_new.cpp
scilab/modules/scicos/src/cpp/view_scilab/Adapters.cpp
scilab/modules/scicos/src/cpp/view_scilab/BaseAdapter.hxx
scilab/modules/scicos_blocks/macros/Misc/DSUPER.sci
scilab/modules/xcos/Makefile.am
scilab/modules/xcos/Makefile.in
scilab/modules/xcos/includes/gw_xcos.hxx
scilab/modules/xcos/macros/importScicosDiagram.sci [deleted file]
scilab/modules/xcos/sci_gateway/cpp/sci_xcosCellCreated.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/xcos_gateway.xml
scilab/modules/xcos/src/c/xcos.vcxproj
scilab/modules/xcos/src/c/xcos.vcxproj.filters
scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosTab.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/ShowParentAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/io/ContextUpdate.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCell.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCellFactory.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/XcosFileType.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/spec/ContentEntry.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosDelegates.java
scilab/modules/xcos/src/jni/XcosCellFactory.cpp [new file with mode: 0644]
scilab/modules/xcos/src/jni/XcosCellFactory.giws.xml [new file with mode: 0644]
scilab/modules/xcos/src/jni/XcosCellFactory.hxx [new file with mode: 0644]

index 6b17219..705bfa7 100644 (file)
@@ -16,6 +16,7 @@
 #include "gw_scicos.hxx"
 
 #include "types.hxx"
+#include "int.hxx"
 #include "string.hxx"
 #include "tlist.hxx"
 #include "mlist.hxx"
@@ -243,7 +244,7 @@ types::Function::ReturnValue allocate(types::typed_list &in, int _iRetCount, typ
     return types::Function::OK;
 }
 
-types::Function::ReturnValue get(types::Double* UIDs, int _iRetCount, types::typed_list &out)
+types::Function::ReturnValue get(types::Int64* UIDs, int _iRetCount, types::typed_list &out)
 {
     if (UIDs->getSize() != _iRetCount)
     {
@@ -315,8 +316,8 @@ types::Function::ReturnValue sci_scicos_new(types::typed_list &in, int _iRetCoun
     {
         case types::InternalType::ScilabString:
             return allocate(in, _iRetCount, out);
-        case types::InternalType::ScilabDouble:
-            return get(type->getAs<types::Double>(), _iRetCount, out);
+        case types::InternalType::ScilabInt64:
+            return get(type->getAs<types::Int64>(), _iRetCount, out);
         default:
             Scierror(999, _("%s: Wrong type for input argument #%d: String or ID expected.\n"), funame.data(), 1);
             return types::Function::Error;
index c2bebc8..f644ce3 100644 (file)
@@ -119,6 +119,8 @@ const model::BaseObject* Adapters::descriptor(types::InternalType* v)
                 return v->getAs<view_scilab::StateAdapter>()->getAdaptee();
             case TEXT_ADAPTER:
                 return v->getAs<view_scilab::TextAdapter>()->getAdaptee();
+            default:
+                return nullptr;
         }
     }
 
index 41c58eb..7be90dd 100644 (file)
@@ -23,6 +23,7 @@
 #include "bool.hxx"
 #include "double.hxx"
 #include "user.hxx"
+#include "int.hxx"
 #include "internal.hxx"
 #include "tlist.hxx"
 #include "mlist.hxx"
@@ -325,7 +326,7 @@ private:
         // specific case : to ease debugging let the user retrieve the model ID
         if (name == L"modelID")
         {
-            out = new types::Double(m_adaptee->id());
+            out = new types::Int64(m_adaptee->id());
             return true;
         }
 
index c0a522b..faa46f2 100644 (file)
@@ -76,6 +76,9 @@ function [x,y,typ] = DSUPER(job,arg1,arg2)
         end
 
     case "define" then
-        // never used
+        // used only on save / load
+        x=SUPER_f("define");
+        x.gui="DSUPER";
+        x.graphics.exprs=list("", list([], []));
     end
 endfunction
index 254be2f..aca72b9 100644 (file)
@@ -37,6 +37,8 @@ libscixcos_la_etc_DATA = \
 XCOS_CXX_SOURCES =     \
     src/jni/Xcos.cpp \
     src/jni/Xcos.hxx \
+    src/jni/XcosCellFactory.cpp \
+    src/jni/XcosCellFactory.hxx \
     src/jni/Palette.cpp \
     src/jni/Palette.hxx \
     src/jni/Modelica.cpp \
@@ -48,6 +50,7 @@ XCOS_CXX_SOURCES =    \
 
 GIWS_WRAPPERS = \
     src/jni/Xcos.giws.xml \
+    src/jni/XcosCellFactory.giws.xml \
     src/jni/Palette.giws.xml \
     src/jni/Modelica.giws.xml
 SWIG_WRAPPERS = \
@@ -69,6 +72,7 @@ GATEWAY_CXX_SOURCES = \
        sci_gateway/cpp/sci_Xcos.cpp \
        sci_gateway/cpp/sci_warnBlockByUID.cpp \
        sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
+       sci_gateway/cpp/sci_xcosCellCreated.cpp \
        sci_gateway/cpp/sci_xcosPalLoad.cpp \
        sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
        sci_gateway/cpp/sci_xcosPalDelete.cpp \
index 97ef2c7..b61abff 100644 (file)
@@ -184,6 +184,7 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkglib_LTLIBRARIES)
 libscixcos_algo_la_LIBADD =
 am__dirstamp = $(am__leading_dot)dirstamp
 am__objects_1 = src/jni/libscixcos_algo_la-Xcos.lo \
+       src/jni/libscixcos_algo_la-XcosCellFactory.lo \
        src/jni/libscixcos_algo_la-Palette.lo \
        src/jni/libscixcos_algo_la-Modelica.lo \
        src/jni/libscixcos_algo_la-JavaController_wrap.lo \
@@ -208,6 +209,7 @@ am__objects_3 =
 am__objects_4 = sci_gateway/cpp/libscixcos_la-sci_Xcos.lo \
        sci_gateway/cpp/libscixcos_la-sci_warnBlockByUID.lo \
        sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo \
+       sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosPalCategoryAdd.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosPalDelete.lo \
@@ -622,6 +624,8 @@ libscixcos_la_etc_DATA = \
 XCOS_CXX_SOURCES = \
     src/jni/Xcos.cpp \
     src/jni/Xcos.hxx \
+    src/jni/XcosCellFactory.cpp \
+    src/jni/XcosCellFactory.hxx \
     src/jni/Palette.cpp \
     src/jni/Palette.hxx \
     src/jni/Modelica.cpp \
@@ -632,6 +636,7 @@ XCOS_CXX_SOURCES = \
 
 GIWS_WRAPPERS = \
     src/jni/Xcos.giws.xml \
+    src/jni/XcosCellFactory.giws.xml \
     src/jni/Palette.giws.xml \
     src/jni/Modelica.giws.xml
 
@@ -646,6 +651,7 @@ GATEWAY_CXX_SOURCES = \
        sci_gateway/cpp/sci_Xcos.cpp \
        sci_gateway/cpp/sci_warnBlockByUID.cpp \
        sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
+       sci_gateway/cpp/sci_xcosCellCreated.cpp \
        sci_gateway/cpp/sci_xcosPalLoad.cpp \
        sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
        sci_gateway/cpp/sci_xcosPalDelete.cpp \
@@ -1189,6 +1195,8 @@ src/jni/$(DEPDIR)/$(am__dirstamp):
        @: > src/jni/$(DEPDIR)/$(am__dirstamp)
 src/jni/libscixcos_algo_la-Xcos.lo: src/jni/$(am__dirstamp) \
        src/jni/$(DEPDIR)/$(am__dirstamp)
+src/jni/libscixcos_algo_la-XcosCellFactory.lo:  \
+       src/jni/$(am__dirstamp) src/jni/$(DEPDIR)/$(am__dirstamp)
 src/jni/libscixcos_algo_la-Palette.lo: src/jni/$(am__dirstamp) \
        src/jni/$(DEPDIR)/$(am__dirstamp)
 src/jni/libscixcos_algo_la-Modelica.lo: src/jni/$(am__dirstamp) \
@@ -1235,6 +1243,9 @@ sci_gateway/cpp/libscixcos_la-sci_warnBlockByUID.lo:  \
 sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
@@ -1294,6 +1305,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_loadXcos.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_warnBlockByUID.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosAddToolsMenu.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosCellCreated.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosConfigureXmlFile.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalCategoryAdd.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalDelete.Plo@am__quote@
@@ -1310,6 +1322,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libscixcos_algo_la-Modelica.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libscixcos_algo_la-Palette.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libscixcos_algo_la-Xcos.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libscixcos_algo_la-XcosCellFactory.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/noxcos/$(DEPDIR)/libscixcos_disable_la-noxcos.Plo@am__quote@
 
 .c.o:
@@ -1374,6 +1387,13 @@ src/jni/libscixcos_algo_la-Xcos.lo: src/jni/Xcos.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/jni/libscixcos_algo_la-Xcos.lo `test -f 'src/jni/Xcos.cpp' || echo '$(srcdir)/'`src/jni/Xcos.cpp
 
+src/jni/libscixcos_algo_la-XcosCellFactory.lo: src/jni/XcosCellFactory.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/jni/libscixcos_algo_la-XcosCellFactory.lo -MD -MP -MF src/jni/$(DEPDIR)/libscixcos_algo_la-XcosCellFactory.Tpo -c -o src/jni/libscixcos_algo_la-XcosCellFactory.lo `test -f 'src/jni/XcosCellFactory.cpp' || echo '$(srcdir)/'`src/jni/XcosCellFactory.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/jni/$(DEPDIR)/libscixcos_algo_la-XcosCellFactory.Tpo src/jni/$(DEPDIR)/libscixcos_algo_la-XcosCellFactory.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/jni/XcosCellFactory.cpp' object='src/jni/libscixcos_algo_la-XcosCellFactory.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/jni/libscixcos_algo_la-XcosCellFactory.lo `test -f 'src/jni/XcosCellFactory.cpp' || echo '$(srcdir)/'`src/jni/XcosCellFactory.cpp
+
 src/jni/libscixcos_algo_la-Palette.lo: src/jni/Palette.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/jni/libscixcos_algo_la-Palette.lo -MD -MP -MF src/jni/$(DEPDIR)/libscixcos_algo_la-Palette.Tpo -c -o src/jni/libscixcos_algo_la-Palette.lo `test -f 'src/jni/Palette.cpp' || echo '$(srcdir)/'`src/jni/Palette.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/jni/$(DEPDIR)/libscixcos_algo_la-Palette.Tpo src/jni/$(DEPDIR)/libscixcos_algo_la-Palette.Plo
@@ -1430,6 +1450,13 @@ sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo: sci_gateway/cpp/sci_cl
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo `test -f 'sci_gateway/cpp/sci_closeXcosFromScilab.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_closeXcosFromScilab.cpp
 
+sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo: sci_gateway/cpp/sci_xcosCellCreated.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosCellCreated.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo `test -f 'sci_gateway/cpp/sci_xcosCellCreated.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosCellCreated.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosCellCreated.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosCellCreated.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_xcosCellCreated.cpp' object='sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo `test -f 'sci_gateway/cpp/sci_xcosCellCreated.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosCellCreated.cpp
+
 sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo: sci_gateway/cpp/sci_xcosPalLoad.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo `test -f 'sci_gateway/cpp/sci_xcosPalLoad.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalLoad.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Plo
index 2b8b0d0..836e4fb 100644 (file)
@@ -17,6 +17,7 @@
 #include "dynlib_xcos.h"
 
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_Xcos, XCOS_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosCellCreated, XCOS_IMPEXP);
 
 #endif /* GW_XCOS_HXX_ */
 
diff --git a/scilab/modules/xcos/macros/importScicosDiagram.sci b/scilab/modules/xcos/macros/importScicosDiagram.sci
deleted file mode 100644 (file)
index 156acec..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2010 - DIGITEO - Clément 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
-//
-
-//
-// Import a scicos diagram.
-//
-// This method wrap all the scicos entry points (load, version, etc...).
-//
-// @source the filename or a diagram instance
-// @out the scicos diagram structure (scs_m)
-function out = importScicosDiagram(source)
-    out = [];
-
-    [lhs,rhs] = argn(0);
-    if rhs <> 1 then
-        error(999,  msprintf(_("%s: Wrong number of input argument(s): %d expected.\n"), "importScicosDiagram", 1));
-        return;
-    end
-
-    if typeof(source) == "diagram" then //import scs_m structure
-        out = source;
-    elseif typeof(source) == "string" then //import cos or cosf file
-        [path,name,ext] = fileparts(source);
-        ext2 = convstr(ext, "u");
-        if ext2 == ".COS" then
-            load(source);
-            out = scs_m;
-            clear scs_m;
-        elseif ext2 == ".COSF" then
-            exec(source, -1);
-            out = scs_m;
-            clear scs_m;
-        else
-            error(999 ,msprintf(_("%s: Wrong type for argument #%d: String or diagram structure expected"), "importScicosDiagram", 1));
-            return;
-        end
-    else
-        error(999, msprintf(_("%s: Wrong type for argument #%d: String or diagram structure expected"), "importScicosDiagram", 1));
-        return;
-    end
-
-    version = getDiagramVersion(out);
-    out = do_version(out, version);
-endfunction
-
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosCellCreated.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosCellCreated.cpp
new file mode 100644 (file)
index 0000000..8ce996e
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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
+ *
+ */
+
+/*--------------------------------------------------------------------------*/
+#include "XcosCellFactory.hxx"
+#include "view_scilab/Adapters.hxx"
+
+#include "types.hxx"
+#include "int.hxx"
+
+#include "gw_xcos.hxx"
+
+extern "C" {
+#include "getScilabJavaVM.h"
+#include "Scierror.h"
+#include "localization.h"
+}
+/*--------------------------------------------------------------------------*/
+using namespace org_scilab_modules_scicos;
+using namespace org_scilab_modules_xcos_graph_model;
+/*--------------------------------------------------------------------------*/
+types::Function::ReturnValue sci_xcosCellCreated(types::typed_list &in, int /*_iRetCount*/, types::typed_list &/*out*/)
+{
+    if (in.size() == 1 && in[0]->isUserType())
+    {
+        const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(in[0]);
+        if (o == nullptr || (o->kind() != DIAGRAM && o->kind() != BLOCK && o->kind() != ANNOTATION))
+        {
+            Scierror(77, _("%s: Wrong type for input argument #%d: ""%s"" expected.\n"), "xcosCellCreated", 1, "diagram or block");
+            return types::Function::Error;
+        }
+
+        XcosCellFactory::created(getScilabJavaVM(), o->id(), static_cast<int>(o->kind()));
+    }
+    return types::Function::OK;
+}
+/*--------------------------------------------------------------------------*/
+
index e4ac7c0..c711e49 100644 (file)
@@ -35,5 +35,6 @@
     <gateway name="sci_xcosPalGet"              function="xcosPalGet"               type="0" />
     <!-- Scilab 6 Gateways (C++) -->
     <gateway name="sci_Xcos"                    function="xcos"                     type="1" />
+    <gateway name="sci_xcosCellCreated"         function="xcosCellCreated"          type="1" />
 </module>
 
index 496d592..fbcba59 100644 (file)
     <ClCompile Include="..\..\sci_gateway\cpp\sci_closeXcosFromScilab.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_warnBlockByUID.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_Xcos.cpp" />
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosCellCreated.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosConfigureXmlFile.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalCategoryAdd.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalDelete.cpp" />
index 4992425..6be39f3 100644 (file)
@@ -41,6 +41,9 @@
     <ClCompile Include="..\..\sci_gateway\cpp\sci_Xcos.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosCellCreated.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosConfigureXmlFile.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
index e4983c1..928a322 100644 (file)
@@ -98,7 +98,7 @@ public final class Xcos {
     private static final String UNABLE_TO_LOAD_BATIK = Messages.gettext("Unable to load the Batik library. \nExpecting version %s ; Getting version %s .");
 
     private static final String CALLED_OUTSIDE_THE_EDT_THREAD = "Called outside the EDT thread.";
-    private static final Logger LOG = Logger.getLogger(Xcos.class.getSimpleName());
+    private static final Logger LOG = Logger.getLogger(Xcos.class.getName());
 
     /** common shared instance */
     private static volatile Xcos sharedInstance;
@@ -161,7 +161,7 @@ public final class Xcos {
         diagrams = new HashMap<>();
 
         view = new XcosView();
-        JavaController.register_view(Xcos.class.getSimpleName(), view);
+        JavaController.register_view(Xcos.class.getName(), view);
         // allocate and install the browser view on demand to avoid any cost
         browser = null;
 
@@ -943,7 +943,7 @@ public final class Xcos {
 
     public mxCell[] lookupForCells(final String[] uid) {
         mxCell[] found = new mxCell[uid.length];
-        XcosView view = (XcosView) JavaController.lookup_view(Xcos.class.getSimpleName());
+        XcosView view = (XcosView) JavaController.lookup_view(Xcos.class.getName());
 
         final String[] sortedUIDs = Arrays.copyOf(uid,  uid.length);
         Arrays.sort(sortedUIDs);
index d545089..55d356d 100644 (file)
@@ -311,6 +311,8 @@ public class XcosTab extends SwingScilabDockablePanel implements SimpleTab {
             uuid = UUID.randomUUID().toString();
         }
 
+        // FIXME: fix a crash on DnD and Tab restore
+
         final XcosTab tab = new XcosTab(graph, uuid);
         ScilabTabFactory.getInstance().addToCache(tab);
 
index d5f69b2..f515cf1 100644 (file)
@@ -27,7 +27,6 @@ import org.scilab.modules.graph.actions.CopyAction;
 import org.scilab.modules.graph.actions.CutAction;
 import org.scilab.modules.graph.actions.DeleteAction;
 import org.scilab.modules.graph.actions.base.DefaultAction;
-import org.scilab.modules.graph.utils.ScilabGraphConstants;
 import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
 import org.scilab.modules.gui.contextmenu.ContextMenu;
 import org.scilab.modules.gui.contextmenu.ScilabContextMenu;
index 7634fdb..db7b54c 100644 (file)
@@ -83,7 +83,7 @@ public class ShowParentAction extends DefaultAction {
                 controller.getObjectProperty(graph.getUID(), kind, ObjectProperties.PARENT_DIAGRAM, parent);
             }
 
-            XcosView view = (XcosView) JavaController.lookup_view(Xcos.class.getSimpleName());
+            XcosView view = (XcosView) JavaController.lookup_view(Xcos.class.getName());
 
             XcosDiagram diagram = (XcosDiagram) view.getVisibleObjects().get(parent[0]);
             if (diagram == null) {
index 71230ec..46c58f6 100644 (file)
@@ -290,7 +290,7 @@ public abstract class ContextUpdate extends BasicBlock {
         public static ContextUpdate createBlock(BasicPort port) {
             for (IOBlocks io : IOBlocks.values()) {
                 if (io.getReferencedPortClass().isInstance(port)) {
-                    final XcosView disabledView = (XcosView) JavaController.look_for_view(Xcos.class.getSimpleName());
+                    final XcosView disabledView = (XcosView) JavaController.look_for_view(Xcos.class.getName());
                     try {
                         JavaController controller = new JavaController();
 
@@ -322,7 +322,7 @@ public abstract class ContextUpdate extends BasicBlock {
                     } catch (InvocationTargetException e) {
                         e.printStackTrace();
                     } finally {
-                        JavaController.register_view(Xcos.class.getSimpleName(), disabledView);
+                        JavaController.register_view(Xcos.class.getName(), disabledView);
                     }
                 }
             }
index deffa5b..2cf038c 100644 (file)
@@ -137,11 +137,6 @@ public class XcosDiagram extends ScilabGraph {
     // the associated parameters
     private final ScicosParameters scicosParameters;
 
-    // the associated object uid
-    private final long uid;
-    // the kind of the diagram : can be either a DIAGRAM or a BLOCK (eg. for superblocks)
-    private final Kind kind;
-
     /**
      * Constructor
      *
@@ -150,10 +145,6 @@ public class XcosDiagram extends ScilabGraph {
     public XcosDiagram(final long diagramId, final Kind kind) {
         super(new mxGraphModel(), Xcos.getInstance().getStyleSheet());
 
-        this.uid = diagramId;
-        this.kind = kind;
-        new JavaController().referenceObject(uid);
-
         // Scicos related setup
         if (kind == Kind.DIAGRAM) {
             scicosParameters = new ScicosParameters(diagramId);
@@ -162,7 +153,8 @@ public class XcosDiagram extends ScilabGraph {
         }
 
         // add the default parent (the JGraphX layer)
-        XcosCell parent = new XcosCell(this.uid, this.kind);
+        XcosCell parent = new XcosCell(diagramId, kind);
+        new JavaController().referenceObject(diagramId);
         ((mxICell) getModel().getRoot()).insert(parent);
         setDefaultParent(parent);
 
@@ -332,7 +324,7 @@ public class XcosDiagram extends ScilabGraph {
 
     @Override
     public String validateCell(final Object cell, final Hashtable<Object, Object> context) {
-        if (kind == Kind.BLOCK) {
+        if (getKind() == Kind.BLOCK) {
             return validateChildDiagram(cell, context);
         } else {
             // does not perform any validation on a root diagram
@@ -1639,14 +1631,14 @@ public class XcosDiagram extends ScilabGraph {
      * @return the model ID
      */
     public long getUID() {
-        return uid;
+        return ((XcosCell) getDefaultParent()).getUID();
     }
 
     /**
      * @return Kind.DIAGRAM or Kind.BLOCK
      */
     public Kind getKind() {
-        return kind;
+        return ((XcosCell) getDefaultParent()).getKind();
     }
 
     /**
@@ -1908,12 +1900,13 @@ public class XcosDiagram extends ScilabGraph {
                         if (f != null && filetype != null) {
                             filetype.load(file, XcosDiagram.this);
                         } else {
-                            //                         FIXME: implement the model decoding
-                            //                         controller.getObjectProperty(uid, k, p, v)
+                            XcosCellFactory.insertChildren(controller, XcosDiagram.this);
                         }
 
                         instance.setLastError("");
                     } catch (Exception e) {
+                        e.printStackTrace();
+
                         Throwable ex = e;
                         while (ex instanceof RuntimeException) {
                             ex = ex.getCause();
@@ -1953,7 +1946,7 @@ public class XcosDiagram extends ScilabGraph {
     public XcosDiagram getRootDiagram() {
         JavaController controller = new JavaController();
         long[] parent = new long[1];
-        controller.getObjectProperty(uid, kind, ObjectProperties.PARENT_DIAGRAM, parent);
+        controller.getObjectProperty(getUID(), getKind(), ObjectProperties.PARENT_DIAGRAM, parent);
 
         Collection<XcosDiagram> diagrams = Xcos.getInstance().getDiagrams(parent[0]);
         return diagrams.stream().filter(d -> d.getUID() == parent[0])
@@ -2033,7 +2026,7 @@ public class XcosDiagram extends ScilabGraph {
 
     @Override
     public File getSavedFile() {
-        if (kind == Kind.DIAGRAM) {
+        if (getKind() == Kind.DIAGRAM) {
             return super.getSavedFile();
         } else {
             return getRootDiagram().getSavedFile();
@@ -2131,10 +2124,4 @@ public class XcosDiagram extends ScilabGraph {
             }
         };
     }
-
-    @Override
-    protected void finalize() throws Throwable {
-        JavaController controller = new JavaController();
-        controller.deleteObject(uid);
-    }
 }
index d6b4ab8..aa8f84e 100644 (file)
@@ -29,6 +29,9 @@ public class XcosCell extends ScilabGraphUniqueObject {
     public XcosCell(long uid, Kind kind) {
         this.uid = uid;
         this.kind = kind;
+
+        JavaController controller = new JavaController();
+        controller.referenceObject(uid);
     }
 
     /**
@@ -236,7 +239,6 @@ public class XcosCell extends ScilabGraphUniqueObject {
 
             JavaController controller = new JavaController();
             controller.referenceObject(c.getUID());
-
         }
 
         return inserted;
index adcf43a..35ab5e9 100644 (file)
@@ -16,19 +16,22 @@ import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManag
 import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.synchronousScilabExec;
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.EnumSet;
 import java.util.Optional;
 
 import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
+import org.scilab.modules.graph.utils.ScilabExported;
 import org.scilab.modules.xcos.JavaController;
 import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.ObjectProperties;
-import org.scilab.modules.xcos.UpdateStatus;
+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.XcosViewListener;
 import org.scilab.modules.xcos.block.AfficheBlock;
 import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.block.SplitBlock;
@@ -47,7 +50,10 @@ 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.io.scicos.ScilabDirectHandler;
+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.scilab.modules.xcos.port.BasicPort;
 import org.scilab.modules.xcos.port.command.CommandPort;
 import org.scilab.modules.xcos.port.control.ControlPort;
@@ -55,8 +61,12 @@ 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.scilab.modules.xcos.utils.BlockPositioning;
+
 import com.mxgraph.model.mxCell;
+import com.mxgraph.model.mxGeometry;
 import com.mxgraph.model.mxICell;
+import com.mxgraph.util.mxPoint;
 
 /**
  * Ease the creation of any {@link Kind} of graphical object
@@ -144,6 +154,33 @@ public final class XcosCellFactory {
         }
     }
 
+    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 */
@@ -151,77 +188,136 @@ public final class XcosCellFactory {
         // This class is a static singleton
     }
 
-    /*
-     * Block and Annotation management
+    /**
+     * This is a notify method mapped as a Scilab gateway used to alert with the loaded UID
+     * @param uid the loaded UID
+     * @param kind the kind of the created object (as an int)
      */
+    @ScilabExported(module = "xcos", filename = "XcosCellFactory.giws.xml")
+    public static void created(long uid, int kind) {
+        lastCreated = new ScicosObjectOwner(uid, Kind.values()[kind]);
 
+    }
+    private static ScicosObjectOwner lastCreated = null;
 
+    /*
+     * Diagram management
+     */
 
     /**
-     * Instantiate a new block with the specified UID value and interface function
+     * Allocate a Java XcosDiagram from a COSF file.
      *
-     * @param uid
-     *            The associated UID value
-     * @param interfaceFunction the interface function
-     * @return A new instance of a block.
+     * This method execute the file and register a
+     *
+     * @param controller the controller
+     * @param filename the file to execute
+     * @return an allocated XcosDiagram
      */
-    public static BasicBlock createBlock(String interfaceFunction) {
-        Optional<BlockInterFunction> func = EnumSet.allOf(BlockInterFunction.class).stream()
-                                            .filter(f -> f.name().equals(interfaceFunction))
-                                            .findFirst();
+    public static XcosDiagram createDiagramFromCOSF(final JavaController controller, String filename) {
+        XcosView view = (XcosView) JavaController.lookup_view(Xcos.class.getName());
+        JavaController.unregister_view(view);
 
-        final BasicBlock block;
-        if (func.isPresent()) {
-            block = createBlock(func.get());
-        } else {
-            block = createBlock(BlockInterFunction.BASIC_BLOCK);
+        XcosDiagram diagram;
+        try {
+            synchronousScilabExec(
+                "function f(), " +
+                buildCall("exec", filename, -1) +
+                buildCall("xcosCellCreated", "scs_m".toCharArray()) +
+                "endfunction; f();");
+
+            if (lastCreated.getKind() == Kind.DIAGRAM) {
+                diagram = new XcosDiagram(lastCreated.getUID(), lastCreated.getKind());
+                insertChildren(controller, diagram);
+                lastCreated = null;
+            } else {
+                diagram = null;
+            }
+        } catch (InterpreterException e) {
+            diagram = null;
+        } finally {
+            JavaController.register_view(Xcos.class.getName(), view);
         }
-        block.setStyle(interfaceFunction);
 
-        return block;
+        return diagram;
     }
 
+    /**
+     * Insert the diagram MVC children into the JGraphX model
+     * @param controller the shared controller
+     * @param diagram the current diagram instance
+     */
+    public static void insertChildren(JavaController controller, XcosDiagram diagram) {
+        VectorOfScicosID children = new VectorOfScicosID();
+        controller.getObjectProperty(diagram.getUID(), diagram.getKind(), ObjectProperties.CHILDREN, children);
+        final int childrenLen = children.size();
 
+        /*
+         * Allocation some pre-sized stash data
+         */
+        final ArrayList<BasicLink> links = new ArrayList<>(childrenLen / 2);
+        final ArrayList<BasicPort> ports = new ArrayList<>(childrenLen);
 
-    private static class BlockLoadedListener extends XcosViewListener {
-        private long uid;
-
-        public BlockLoadedListener() {
-            uid = 0;
-        }
-
-        public long getUID() {
-            return uid;
-        }
-
-        /**
-         * When a unique block is created then store it for later use.
+        /*
+         * Create the XcosCell objects and store some of them for later use
          */
-        @Override
-        public void objectCreated(long uid, Kind kind) {
-            if (!EnumSet.of(Kind.BLOCK, Kind.ANNOTATION).contains(kind)) {
-                return;
+        XcosCell[] cells = new XcosCell[childrenLen];
+        for (int i = 0; i < childrenLen; i++) {
+            final long uid = children.get(i);
+            final Kind kind = controller.getKind(uid);
+
+            switch (kind) {
+                case ANNOTATION:
+                case BLOCK:
+                    BasicBlock b = createBlock(controller, uid, kind);
+                    cells[i] = b;
+                    BlockPositioning.updatePortsPosition(diagram, b);
+                    b.getTypedChildrenIndexes(BasicPort.class).stream()
+                    .map(index -> b.getChildAt(index))
+                    .filter(c -> c instanceof BasicPort)
+                    .forEach( c -> ports.add((BasicPort) c));
+                    break;
+                case LINK:
+                    BasicLink l = createLink(controller, uid, kind);
+                    cells[i] = l;
+                    links.add(l);
+                    break;
+                default:
+                    break;
             }
-
-            this.uid = uid;
         }
 
-        /**
-         * When a composite block is created we track the PARENT_BLOCK / CHILDREN association to store the parent.
+        /*
+         * Relink the links on the XcosCell part
          */
-        @Override
-        public void propertyUpdated(long uid, Kind kind, ObjectProperties property, UpdateStatus status) {
-            if (status != UpdateStatus.SUCCESS || property != ObjectProperties.CHILDREN) {
-                return;
-            }
-            if (!EnumSet.of(Kind.BLOCK, Kind.ANNOTATION).contains(kind)) {
-                return;
+        Comparator<XcosCell> compare = (c1, c2) -> (int) (c1.getUID() - c2.getUID());
+        Collections.sort(ports, compare);
+        for (BasicLink l : links) {
+            long[] src = new long[1];
+            controller.getObjectProperty(l.getUID(), l.getKind(), ObjectProperties.SOURCE_PORT, src);
+
+            long[] dest = new long[1];
+            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) {
+                l.setSource(ports.get(srcIndex));
             }
 
-            this.uid = uid;
+            int destIndex = Collections.binarySearch(ports, new XcosCell(dest[0], Kind.PORT), compare);
+            if (destIndex > 0) {
+                l.setTarget(ports.get(destIndex));
+            }
         }
+
+        diagram.addCells(cells);
     }
 
+
+
+    /*
+     * Block and Annotation management
+     */
+
     /**
      * Instantiate a new block with the specified interface function.
      *
@@ -230,44 +326,87 @@ public final class XcosCellFactory {
      * @return A new instance of a block.
      */
     public static BasicBlock createBlock(BlockInterFunction func) {
-        return createBlock(new JavaController(), func);
+        return createBlock(func, func.name());
     }
 
     /**
-     * Instantiate a new block with the specified interface function.
+     * Instantiate a new block with the specified UID value and interface function
      *
-     * @param func
-     *            the interface function
+     * @param uid
+     *            The associated UID value
+     * @param interfaceFunction the interface function
      * @return A new instance of a block.
      */
-    public static BasicBlock createBlock(final JavaController controller, BlockInterFunction func) {
-        XcosView view = (XcosView) JavaController.lookup_view(Xcos.class.getSimpleName());
+    public static BasicBlock createBlock(String interfaceFunction) {
+        Optional<BlockInterFunction> func = EnumSet.allOf(BlockInterFunction.class).stream()
+                                            .filter(f -> f.name().equals(interfaceFunction))
+                                            .findFirst();
 
-        BlockLoadedListener blockLoaded = new BlockLoadedListener();
-        view.addXcosViewListener(blockLoaded, EnumSet.allOf(Kind.class), true, EnumSet.of(ObjectProperties.CHILDREN));
+        final BasicBlock block;
+        if (func.isPresent()) {
+            block = createBlock(func.get());
+        } else {
+            block = createBlock(BlockInterFunction.BASIC_BLOCK, interfaceFunction);
+        }
+        block.setStyle(interfaceFunction);
 
+        return block;
+    }
+
+    private static BasicBlock createBlock(BlockInterFunction func, String interfaceFunction) {
+        return createBlock(new JavaController(), func, interfaceFunction);
+    }
+
+    private static BasicBlock createBlock(final JavaController controller, BlockInterFunction func, String interfaceFunction) {
         BasicBlock block;
         try {
-            synchronousScilabExec(ScilabDirectHandler.BLK + " = " + buildCall(func.name(), "define"));
-            block = XcosCellFactory.createBlock(controller, func, blockLoaded.getUID());
-        } catch (InterpreterException e1) {
+            synchronousScilabExec("xcosCellCreated(" + interfaceFunction + "(\"define\")); ");
+
+            if (EnumSet.of(Kind.BLOCK, Kind.ANNOTATION).contains(lastCreated.getKind())) {
+                block = createBlock(controller, func, interfaceFunction, lastCreated.getUID());
+                lastCreated = null;
+            } else {
+                block = null;
+            }
+        } catch (InterpreterException e) {
             block = null;
-        } finally {
-            view.removeXcosViewListener(blockLoaded);
         }
 
         return block;
     }
 
+    private static BasicBlock createBlock(final JavaController controller, long uid, Kind kind) {
+        String[] interfaceFunction = new String[1];
+        controller.getObjectProperty(uid, kind, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
+
+        return createBlock(controller, interfaceFunction[0], uid);
+    }
+
+    private static BasicBlock createBlock(final JavaController controller, String interfaceFunction, long uid) {
+        Optional<BlockInterFunction> optFunc = EnumSet.allOf(BlockInterFunction.class).stream()
+                                               .filter(f -> f.name().equals(interfaceFunction))
+                                               .findFirst();
+
+        final BlockInterFunction func;
+        if (optFunc.isPresent()) {
+            func = optFunc.get();
+        } else {
+            func = BlockInterFunction.BASIC_BLOCK;
+        }
+
+        return createBlock(controller, func, interfaceFunction, uid);
+    }
+
     /**
      * Instantiate a new block with the specified interface function and uid.
      *
      * @param controller the Java controller to use
-     * @param func the interface function
+     * @param func the interface function as an enum
+     * @param interfaceFunction the interface function name
      * @param uid the allocated uid
      * @return A new instance of a block.
      */
-    private static BasicBlock createBlock(final JavaController controller, BlockInterFunction func, long uid) {
+    private static BasicBlock createBlock(final JavaController controller, BlockInterFunction func, String interfaceFunction, long uid) {
         BasicBlock block = null;
         try {
             block = func.getKlass().getConstructor(Long.TYPE).newInstance(uid);
@@ -277,7 +416,19 @@ public final class XcosCellFactory {
             return block;
         }
 
+        /*
+         * Synchronize model information back to the JGraphX data
+         */
         insertPortChildren(controller, block);
+
+        block.setStyle(interfaceFunction);
+
+        VectorOfDouble geom = new VectorOfDouble(4);
+        controller.getObjectProperty(block.getUID(), block.getKind(), ObjectProperties.GEOMETRY, geom);
+        block.setGeometry(new mxGeometry(geom.get(0), geom.get(1), geom.get(2), geom.get(3)));
+
+        // FIXME find a way to reuse the Scicos compat handler from org.scilab.modules.xcos.io.scicos
+
         return block;
     }
 
@@ -285,7 +436,6 @@ public final class XcosCellFactory {
      * Port management
      */
 
-
     /**
      * Helper used to create port children on a parent block.
      *
@@ -294,7 +444,7 @@ public final class XcosCellFactory {
      * @param controller is the shared controller instance
      * @param parent is the parent {@link mxCell} to modify
      */
-    public static void insertPortChildren(final JavaController controller, final XcosCell parent) {
+    private static void insertPortChildren(final JavaController controller, final XcosCell parent) {
         final EnumSet<ObjectProperties> properties = EnumSet.of(ObjectProperties.INPUTS, ObjectProperties.OUTPUTS, ObjectProperties.EVENT_INPUTS, ObjectProperties.EVENT_OUTPUTS);
         insertPortChildren(controller, properties, parent);
     }
@@ -313,7 +463,7 @@ public final class XcosCellFactory {
      *        <LI>{@link ObjectProperties#EVENT_OUTPUTS}
      * @param parent is the parent {@link mxCell} to modify
      */
-    public static void insertPortChildren(final JavaController controller, final EnumSet<ObjectProperties> properties, final XcosCell parent) {
+    private static void insertPortChildren(final JavaController controller, final EnumSet<ObjectProperties> properties, final XcosCell parent) {
         for (ObjectProperties property : properties) {
             insertPortChildren(controller, property, parent);
         }
@@ -332,7 +482,7 @@ public final class XcosCellFactory {
      *        <LI>{@link ObjectProperties#EVENT_OUTPUTS}
      * @param parent is the parent {@link mxCell} to modify
      */
-    public static void insertPortChildren(final JavaController controller, final ObjectProperties property, final XcosCell parent) {
+    private static void insertPortChildren(final JavaController controller, final ObjectProperties property, final XcosCell parent) {
         if (parent.getKind() != Kind.BLOCK) {
             return;
         }
@@ -385,4 +535,47 @@ public final class XcosCellFactory {
                 return null;
         }
     }
+
+    /*
+     * Link management
+     */
+
+    private static BasicLink createLink(JavaController controller, long uid, Kind kind) {
+        int[] type = new int[1];
+        controller.getObjectProperty(uid, kind, ObjectProperties.KIND, type);
+
+        BasicLink link;
+        switch (type[0]) {
+            case -1:
+                link = new CommandControlLink(uid);
+                break;
+            case 1:
+                link = new ExplicitLink(uid);
+                break;
+            case 2:
+                link = new ImplicitLink(uid);
+                break;
+            default:
+                return null;
+        }
+
+        /*
+         * Synchronize model information back to the JGraphX data
+         */
+        VectorOfDouble controlPoints = new VectorOfDouble();
+        controller.getObjectProperty(uid, kind, ObjectProperties.CONTROL_POINTS, controlPoints);
+        final int controlPointsLen = controlPoints.size() / 2;
+
+        ArrayList<mxPoint> points = new ArrayList<>(controlPointsLen);
+        for (int i = 0 ; i < controlPointsLen; i++) {
+            points.add(new mxPoint(controlPoints.get(i), controlPoints.get(i + controlPointsLen)));
+        }
+
+        mxGeometry geom = new mxGeometry();
+        geom.setPoints(points);
+
+        link.setGeometry(geom);
+        return link;
+    }
+
 }
index 8c35a47..c01fb28 100644 (file)
@@ -36,9 +36,10 @@ import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.scilab.modules.commons.xml.ScilabTransformerFactory;
+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.scicos.ScilabDirectHandler;
 import org.scilab.modules.xcos.io.spec.XcosPackage;
 import org.scilab.modules.xcos.utils.XcosMessages;
 import org.w3c.dom.Node;
@@ -132,22 +133,8 @@ public enum XcosFileType {
     COSF("cosf", XcosMessages.FILE_COSF) {
         @Override
         public void load(String file, XcosDiagram into) throws Exception {
-            loadScicosDiagram(file, into);
-        }
-
-        @Override
-        public void save(String file, XcosDiagram from) throws Exception {
-            throw new UnsupportedOperationException();
-        }
-    },
-    /**
-     * Represent the old Scicos binary format.
-     */
-    COS("cos", XcosMessages.FILE_COS) {
-
-        @Override
-        public void load(String file, XcosDiagram into) throws Exception {
-            loadScicosDiagram(file, into);
+            XcosDiagram diagram = XcosCellFactory.createDiagramFromCOSF(new JavaController(), file);
+            into.addCell(diagram.getDefaultParent(), into.getDefaultParent());
         }
 
         @Override
@@ -434,41 +421,4 @@ public enum XcosFileType {
         values.add(XcosFileType.ZCOS);
         return values;
     }
-
-    /**
-     * Load a Scicos diagram file int a diagram
-     */
-    private static void loadScicosDiagram(final String filename,
-                                          final XcosDiagram into) {
-        final StringBuilder cmd = new StringBuilder();
-        cmd.append(ScilabDirectHandler.SCS_M);
-        cmd.append(" = importScicosDiagram(\"");
-        cmd.append(filename);
-        cmd.append("\");");
-
-        // FIXME manage that
-        //        final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
-        //        if (handler == null) {
-        //            return;
-        //        }
-        //
-        //        ActionListener callback = new ActionListener() {
-        //            @Override
-        //            public void actionPerformed(ActionEvent e) {
-        //                try {
-        //                    handler.readDiagram(into);
-        //                } finally {
-        //                    handler.release();
-        //                }
-        //            }
-        //        };
-        //
-        //        try {
-        //            ScilabInterpreterManagement.asynchronousScilabExec(callback,
-        //                    cmd.toString());
-        //        } catch (InterpreterException e) {
-        //            e.printStackTrace();
-        //            handler.release();
-        //        }
-    }
 }
index 8432339..89dfd86 100644 (file)
@@ -94,6 +94,8 @@ public class ContentEntry implements Entry {
         } catch (TransformerException e) {
             e.printStackTrace();
             Logger.getLogger(ContentEntry.class.getName()).severe(e.getMessageAndLocation());
+        } catch (Exception e) {
+            e.printStackTrace();
         }
     }
 
index 22b41c8..3f49b9f 100644 (file)
@@ -261,9 +261,11 @@ public final class BlockPositioning {
         VectorOfDouble mvcAngle = new VectorOfDouble();
         controller.getObjectProperty(block.getUID(), Kind.BLOCK, ObjectProperties.ANGLE, mvcAngle);
 
-        final boolean mirrored = mvcAngle.get(0) == 4d;
-        final boolean flipped = mvcAngle.get(0) == 8d;
-        final int angle = (int) Math.round(mvcAngle.get(1));
+        double flags = mvcAngle.get(0);
+        final boolean mirrored = flags == 4d;
+        final boolean flipped = flags == 8d;
+        final int angle = ( ((int) Math.round(mvcAngle.get(1))) % 360 + 360) % 360;
+
         List<BasicPort> working = ports;
 
         /* List order modification with the flip flag */
index 0399d28..ec427ce 100644 (file)
@@ -23,6 +23,9 @@ import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.io.XcosFileType;
 
+import com.mxgraph.swing.mxGraphComponent;
+import com.mxgraph.util.mxCellRenderer;
+
 /**
  * Class which contains all Xcos dependant function used by other modules.
  */
@@ -50,13 +53,11 @@ public class XcosDelegates {
         diag.installListeners();
 
         final XcosFileType filetype = XcosFileType.findFileType(xcosFile);
-        // FIXME load file
-        //        filetype.load(xcosFile, diag);
-        //
-        //        final mxGraphComponent graphComponent = diag.getAsComponent();
-        //
-        //        final BufferedImage image = mxCellRenderer.createBufferedImage(diag, null, 1, null, graphComponent.isAntiAlias(), null, graphComponent.getCanvas());
-        final BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
+        filetype.load(xcosFile, diag);
+
+        final mxGraphComponent graphComponent = diag.getAsComponent();
+
+        final BufferedImage image = mxCellRenderer.createBufferedImage(diag, null, 1, null, graphComponent.isAntiAlias(), null, graphComponent.getCanvas());
         ImageIO.write(image, "png", imageFile);
 
         controller.deleteObject(diag.getUID());
diff --git a/scilab/modules/xcos/src/jni/XcosCellFactory.cpp b/scilab/modules/xcos/src/jni/XcosCellFactory.cpp
new file mode 100644 (file)
index 0000000..326188d
--- /dev/null
@@ -0,0 +1,169 @@
+#include "XcosCellFactory.hxx"
+/* Generated by GIWS (version 2.0.2) with command:
+giws --disable-return-size-array --output-dir src/jni/ --throws-exception-on-error --description-file src/jni/XcosCellFactory.giws.xml
+*/
+/*
+
+This is generated code.
+
+This software is a computer program whose purpose is to hide the complexity
+of accessing Java objects/methods from C++ code.
+
+This software is governed by the CeCILL-B license under French law and
+abiding by the rules of distribution of free software.  You can  use,
+modify and/ or redistribute the software under the terms of the CeCILL-B
+license as circulated by CEA, CNRS and INRIA at the following URL
+"http://www.cecill.info".
+
+As a counterpart to the access to the source code and  rights to copy,
+modify and redistribute granted by the license, users are provided only
+with a limited warranty  and the software's author,  the holder of the
+economic rights,  and the successive licensors  have only  limited
+liability.
+
+In this respect, the user's attention is drawn to the risks associated
+with loading,  using,  modifying and/or developing or reproducing the
+software by the user in light of its specific status of free software,
+that may mean  that it is complicated to manipulate,  and  that  also
+therefore means  that it is reserved for developers  and  experienced
+professionals having in-depth computer knowledge. Users are therefore
+encouraged to load and test the software's suitability as regards their
+requirements in conditions enabling the security of their systems and/or
+data to be ensured and,  more generally, to use and operate it in the
+same conditions as regards security.
+
+The fact that you are presently reading this means that you have had
+knowledge of the CeCILL-B license and that you accept its terms.
+*/
+
+namespace org_scilab_modules_xcos_graph_model {
+
+                // Static declarations (if any)
+                
+// Returns the current env
+
+JNIEnv * XcosCellFactory::getCurrentEnv() {
+JNIEnv * curEnv = NULL;
+jint res=this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+if (res != JNI_OK) {
+throw GiwsException::JniException(getCurrentEnv());
+}
+return curEnv;
+}
+// Destructor
+
+XcosCellFactory::~XcosCellFactory() {
+JNIEnv * curEnv = NULL;
+this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+curEnv->DeleteGlobalRef(this->instance);
+curEnv->DeleteGlobalRef(this->instanceClass);
+}
+// Constructors
+XcosCellFactory::XcosCellFactory(JavaVM * jvm_) {
+jmethodID constructObject = NULL ;
+jobject localInstance ;
+jclass localClass ;
+
+const std::string construct="<init>";
+const std::string param="()V";
+jvm=jvm_;
+
+JNIEnv * curEnv = getCurrentEnv();
+
+localClass = curEnv->FindClass( this->className().c_str() ) ;
+if (localClass == NULL) {
+  throw GiwsException::JniClassNotFoundException(curEnv, this->className());
+}
+
+this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
+
+/* localClass is not needed anymore */
+curEnv->DeleteLocalRef(localClass);
+
+if (this->instanceClass == NULL) {
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+}
+
+
+constructObject = curEnv->GetMethodID( this->instanceClass, construct.c_str() , param.c_str() ) ;
+if(constructObject == NULL){
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+}
+
+localInstance = curEnv->NewObject( this->instanceClass, constructObject ) ;
+if(localInstance == NULL){
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+}
+this->instance = curEnv->NewGlobalRef(localInstance) ;
+if(this->instance == NULL){
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+}
+/* localInstance not needed anymore */
+curEnv->DeleteLocalRef(localInstance);
+
+                /* Methods ID set to NULL */
+voidcreatedjlonglongjintintID=NULL;
+
+
+}
+
+XcosCellFactory::XcosCellFactory(JavaVM * jvm_, jobject JObj) {
+        jvm=jvm_;
+
+        JNIEnv * curEnv = getCurrentEnv();
+
+jclass localClass = curEnv->GetObjectClass(JObj);
+        this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
+        curEnv->DeleteLocalRef(localClass);
+
+        if (this->instanceClass == NULL) {
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+        }
+
+        this->instance = curEnv->NewGlobalRef(JObj) ;
+        if(this->instance == NULL){
+throw GiwsException::JniObjectCreationException(curEnv, this->className());
+        }
+        /* Methods ID set to NULL */
+        voidcreatedjlonglongjintintID=NULL;
+
+
+}
+
+// Generic methods
+
+void XcosCellFactory::synchronize() {
+if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
+throw GiwsException::JniMonitorException(getCurrentEnv(), "XcosCellFactory");
+}
+}
+
+void XcosCellFactory::endSynchronize() {
+if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
+throw GiwsException::JniMonitorException(getCurrentEnv(), "XcosCellFactory");
+}
+}
+// Method(s)
+
+void XcosCellFactory::created (JavaVM * jvm_, long long uid, int kind){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = initClass(curEnv);
+if ( cls == NULL) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+
+static jmethodID voidcreatedjlonglongjintintID = curEnv->GetStaticMethodID(cls, "created", "(JI)V" ) ;
+if (voidcreatedjlonglongjintintID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "created");
+}
+
+                         curEnv->CallStaticVoidMethod(cls, voidcreatedjlonglongjintintID ,uid, kind);
+                        if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+}
diff --git a/scilab/modules/xcos/src/jni/XcosCellFactory.giws.xml b/scilab/modules/xcos/src/jni/XcosCellFactory.giws.xml
new file mode 100644 (file)
index 0000000..1cf39be
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<package name="org.scilab.modules.xcos.graph.model">
+    <object name="XcosCellFactory">
+        <method name="created" returnType="void" modifier="static">
+            <parameter name="uid" type="long"/>
+            <parameter name="kind" type="int"/>
+        </method>
+    </object>
+</package>
+
diff --git a/scilab/modules/xcos/src/jni/XcosCellFactory.hxx b/scilab/modules/xcos/src/jni/XcosCellFactory.hxx
new file mode 100644 (file)
index 0000000..09d213e
--- /dev/null
@@ -0,0 +1,178 @@
+/* Generated by GIWS (version 2.0.2) with command:
+giws --disable-return-size-array --output-dir src/jni/ --throws-exception-on-error --description-file src/jni/XcosCellFactory.giws.xml
+*/
+/*
+
+This is generated code.
+
+This software is a computer program whose purpose is to hide the complexity
+of accessing Java objects/methods from C++ code.
+
+This software is governed by the CeCILL-B license under French law and
+abiding by the rules of distribution of free software.  You can  use,
+modify and/ or redistribute the software under the terms of the CeCILL-B
+license as circulated by CEA, CNRS and INRIA at the following URL
+"http://www.cecill.info".
+
+As a counterpart to the access to the source code and  rights to copy,
+modify and redistribute granted by the license, users are provided only
+with a limited warranty  and the software's author,  the holder of the
+economic rights,  and the successive licensors  have only  limited
+liability.
+
+In this respect, the user's attention is drawn to the risks associated
+with loading,  using,  modifying and/or developing or reproducing the
+software by the user in light of its specific status of free software,
+that may mean  that it is complicated to manipulate,  and  that  also
+therefore means  that it is reserved for developers  and  experienced
+professionals having in-depth computer knowledge. Users are therefore
+encouraged to load and test the software's suitability as regards their
+requirements in conditions enabling the security of their systems and/or
+data to be ensured and,  more generally, to use and operate it in the
+same conditions as regards security.
+
+The fact that you are presently reading this means that you have had
+knowledge of the CeCILL-B license and that you accept its terms.
+*/
+
+
+#ifndef __ORG_SCILAB_MODULES_XCOS_GRAPH_MODEL_XCOSCELLFACTORY__
+#define __ORG_SCILAB_MODULES_XCOS_GRAPH_MODEL_XCOSCELLFACTORY__
+#include <iostream>
+#include <string>
+#include <string.h>
+#include <stdlib.h>
+#include <jni.h>
+
+#include "GiwsException.hxx"
+
+        #if defined(_MSC_VER) /* Defined anyway with Visual */
+            #include <Windows.h>
+        #else
+            typedef signed char byte;
+        #endif
+
+
+#ifndef GIWSEXPORT
+# if defined(_MSC_VER) || defined(__WIN32__) || defined(__CYGWIN__)
+#   if defined(STATIC_LINKED)
+#     define GIWSEXPORT
+#   else
+#     define GIWSEXPORT __declspec(dllexport)
+#   endif
+# else
+#   if __GNUC__ >= 4
+#     define GIWSEXPORT __attribute__ ((visibility ("default")))
+#   else
+#     define GIWSEXPORT
+#   endif
+# endif
+#endif
+
+namespace org_scilab_modules_xcos_graph_model {
+class GIWSEXPORT XcosCellFactory {
+
+private:
+JavaVM * jvm;
+
+protected:
+jmethodID voidcreatedjlonglongjintintID; // cache method id
+
+
+
+jobject instance;
+jclass instanceClass; // cache class
+
+                       
+// Caching (if any)
+
+
+/**
+* Get the environment matching to the current thread.
+*/
+virtual JNIEnv * getCurrentEnv();
+
+public:
+// Constructor
+/**
+* Create a wrapping of the object from a JNIEnv.
+* It will call the default constructor
+* @param JEnv_ the Java Env
+*/
+XcosCellFactory(JavaVM * jvm_);
+
+/**
+* Create a wrapping of an already existing object from a JNIEnv.
+* The object must have already been instantiated
+* @param JEnv_ the Java Env
+* @param JObj the object
+*/
+XcosCellFactory(JavaVM * jvm_, jobject JObj);
+
+
+/** 
+* This is a fake constructor to avoid the constructor
+* chaining when dealing with extended giws classes 
+*/
+#ifdef FAKEGIWSDATATYPE
+XcosCellFactory(fakeGiwsDataType::fakeGiwsDataType /* unused */) {}
+#endif
+
+// Destructor
+~XcosCellFactory();
+
+// Generic method
+// Synchronization methods
+/**
+* Enter monitor associated with the object.
+* Equivalent of creating a "synchronized(obj)" scope in Java.
+*/
+void synchronize();
+
+/**
+* Exit monitor associated with the object.
+* Equivalent of ending a "synchronized(obj)" scope.
+*/
+void endSynchronize();
+
+// Methods
+static void created(JavaVM * jvm_, long long uid, int kind);
+
+
+                        /**
+                        * Get class name to use for static methods
+                        * @return class name to use for static methods
+                        */
+                        
+                static const std::string className()
+                {
+                return "org/scilab/modules/xcos/graph/model/XcosCellFactory";
+                }
+                
+
+                        /**
+                        * Get class to use for static methods
+                        * @return class to use for static methods
+                        */
+                        
+                static jclass initClass(JNIEnv * curEnv)
+                {
+                    static jclass cls = 0;
+
+                    if (cls == 0)
+                    {
+                        jclass _cls = curEnv->FindClass(className().c_str());
+                        if (_cls)
+                        {
+                            cls = static_cast<jclass>(curEnv->NewGlobalRef(_cls));
+                        }
+                    }
+
+                    return cls;
+                 }
+                
+};
+
+
+}
+#endif