Xcos: fix user-defined external actions 23/18723/2
Clément DAVID [Tue, 29 Nov 2016 10:57:38 +0000 (11:57 +0100)]
Change-Id: Ie0dea58a12c6d7912bf1aa8240b5b3a15d86e46c

13 files changed:
scilab/modules/xcos/Makefile.am
scilab/modules/xcos/Makefile.in
scilab/modules/xcos/help/en_US/scilab_utilities_functions/xcosAddToolsMenu.xml
scilab/modules/xcos/includes/gw_xcos.hxx
scilab/modules/xcos/sci_gateway/cpp/sci_xcosUpdateBlock.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/actions/ExternalAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCellFactory.java
scilab/modules/xcos/src/jni/XcosCellFactory.cpp
scilab/modules/xcos/src/jni/XcosCellFactory.giws.xml
scilab/modules/xcos/src/jni/XcosCellFactory.hxx

index c87789e..e77ad43 100644 (file)
@@ -2,6 +2,7 @@
 # Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 # Copyright (C) DIGITEO - 2009-2010 - Allan CORNET <allan.cornet@scilab.org>
 # Copyright (C) DIGITEO - 2010-2010 - Clément DAVID <clement.david@scilab.org>
+# Copyright (C) 2012-2016 - Scilab Enterprises - Clément DAVID
 #
 # Copyright (C) 2012 - 2016 - Scilab Enterprises
 #
@@ -78,6 +79,7 @@ GATEWAY_CXX_SOURCES = \
        sci_gateway/cpp/sci_warnBlockByUID.cpp \
        sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
        sci_gateway/cpp/sci_xcosCellCreated.cpp \
+       sci_gateway/cpp/sci_xcosUpdateBlock.cpp \
        sci_gateway/cpp/sci_xcosDiagramToScilab.cpp \
        sci_gateway/cpp/sci_xcosPalLoad.cpp \
        sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
index 1628e57..c4099e1 100644 (file)
@@ -18,6 +18,7 @@
 # Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 # Copyright (C) DIGITEO - 2009-2010 - Allan CORNET <allan.cornet@scilab.org>
 # Copyright (C) DIGITEO - 2010-2010 - Clément DAVID <clement.david@scilab.org>
+# Copyright (C) 2012-2016 - Scilab Enterprises - Clément DAVID
 #
 # Copyright (C) 2012 - 2016 - Scilab Enterprises
 #
@@ -217,6 +218,7 @@ am__objects_4 = sci_gateway/cpp/libscixcos_la-sci_Xcos.lo \
        sci_gateway/cpp/libscixcos_la-sci_warnBlockByUID.lo \
        sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo \
+       sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo \
        sci_gateway/cpp/libscixcos_la-sci_xcosPalCategoryAdd.lo \
@@ -665,6 +667,7 @@ GATEWAY_CXX_SOURCES = \
        sci_gateway/cpp/sci_warnBlockByUID.cpp \
        sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
        sci_gateway/cpp/sci_xcosCellCreated.cpp \
+       sci_gateway/cpp/sci_xcosUpdateBlock.cpp \
        sci_gateway/cpp/sci_xcosDiagramToScilab.cpp \
        sci_gateway/cpp/sci_xcosPalLoad.cpp \
        sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
@@ -1263,6 +1266,9 @@ sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo:  \
 sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
@@ -1337,6 +1343,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalMove.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosSimulationStarted.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosUpdateBlock.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscixcos_algo_la-loadStatus.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscixcos_algo_la-xcosUtilities.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libscixcos_algo_la-JavaController_wrap.Plo@am__quote@
@@ -1486,6 +1493,13 @@ sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo: sci_gateway/cpp/sci_xcosCe
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_xcosCellCreated.lo `test -f 'sci_gateway/cpp/sci_xcosCellCreated.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosCellCreated.cpp
 
+sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo: sci_gateway/cpp/sci_xcosUpdateBlock.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_xcosUpdateBlock.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosUpdateBlock.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo `test -f 'sci_gateway/cpp/sci_xcosUpdateBlock.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosUpdateBlock.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosUpdateBlock.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosUpdateBlock.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_xcosUpdateBlock.cpp' object='sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.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_xcosUpdateBlock.lo `test -f 'sci_gateway/cpp/sci_xcosUpdateBlock.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosUpdateBlock.cpp
+
 sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo: sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo `test -f 'sci_gateway/cpp/sci_xcosDiagramToScilab.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Plo
index a550559..cfb29dd 100644 (file)
@@ -56,8 +56,8 @@ xcosAddToolsMenu("print diagram", "disp(scs_m)");
 
 // define a custom update function
 function myUpdateFunction(blk, scs_m)
-    execstr(''[ok, blk] = '' + blk.gui + ''(''''set'''', blk)'') ;
-    xcosUpdateBlock(blk) ;
+    execstr("[ok, blk] = " + blk.gui + "(''set'', blk);");
+    xcosUpdateBlock(blk);
 endfunction
 xcosAddToolsMenu("update block", "myUpdateFunction(blk, scs_m)");
 ]]></programlisting>
index b897c50..4da642b 100644 (file)
@@ -21,6 +21,7 @@
 
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_Xcos, XCOS_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosCellCreated, XCOS_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosUpdateBlock, XCOS_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosDiagramToScilab, XCOS_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosPalGenerateIcon, XCOS_IMPEXP);
 
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosUpdateBlock.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosUpdateBlock.cpp
new file mode 100644 (file)
index 0000000..3b196cf
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID
+ *
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ *
+ */
+
+/*--------------------------------------------------------------------------*/
+#include "XcosCellFactory.hxx"
+#include "view_scilab/Adapters.hxx"
+
+#include "types.hxx"
+#include "int.hxx"
+#include "function.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_xcosUpdateBlock(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() != BLOCK && o->kind() != ANNOTATION))
+        {
+            Scierror(77, _("%s: Wrong type for input argument #%d: ""%s"" expected.\n"), "xcosUpdateBlock", 1, "block");
+            return types::Function::Error;
+        }
+
+        XcosCellFactory::update(getScilabJavaVM(), o->id(), static_cast<int>(o->kind()));
+    }
+    return types::Function::OK;
+}
+/*--------------------------------------------------------------------------*/
+
index caf358e..f32b1e1 100644 (file)
@@ -38,7 +38,9 @@
     <!-- Scilab 6 Gateways (C++) -->
     <gateway name="sci_Xcos"                    function="xcos"                     type="1" />
     <gateway name="sci_xcosCellCreated"         function="xcosCellCreated"          type="1" />
+    <gateway name="sci_xcosUpdateBlock"         function="xcosUpdateBlock"          type="1" />
     <gateway name="sci_xcosDiagramToScilab"     function="xcosDiagramToScilab"      type="1" />
     <gateway name="sci_xcosPalGenerateIcon"     function="xcosPalGenerateIcon"      type="1" />
+    <gateway name="sci_xcosCellCreated"         function="xcosCellCreated"          type="1" />
 </module>
 
index 455786a..f5cca0a 100644 (file)
     <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_xcosUpdateBlock.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 558bcc7..422d6c2 100644 (file)
@@ -41,6 +41,9 @@
     <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosCellCreated.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosUpdateBlock.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosConfigureXmlFile.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
index dca7448..b0a43fb 100644 (file)
  */
 package org.scilab.modules.xcos.actions;
 
+import java.awt.Cursor;
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.util.logging.Logger;
 
 import javax.swing.Action;
 
+import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
+import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
 import org.scilab.modules.graph.ScilabGraph;
 import org.scilab.modules.graph.actions.base.DefaultAction;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.graph.model.ScicosObjectOwner;
+import org.scilab.modules.xcos.graph.model.XcosCellFactory;
+import org.scilab.modules.xcos.utils.BlockPositioning;
 
 /**
  * External action
@@ -37,8 +46,6 @@ public final class ExternalAction extends DefaultAction {
     /** Accelerator key for the action */
     public static final int ACCELERATOR_KEY = 0;
 
-    private static final Logger LOG = Logger.getLogger(ExternalAction.class.getName());
-
     final String localCommand;
 
     /**
@@ -68,69 +75,89 @@ public final class ExternalAction extends DefaultAction {
         localCommand = action.localCommand;
     }
 
+    static private void reset_view(final XcosDiagram graph, final BasicBlock block, boolean start) {
+        if (block != null) {
+            block.setLocked(start);
+        }
+
+        int cursor;
+        if (start) {
+            cursor = Cursor.WAIT_CURSOR;
+        } else {
+            cursor = Cursor.DEFAULT_CURSOR;
+        }
+
+        graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(cursor));
+        graph.setCellsLocked(start);
+
+        graph.getView().clear(graph.getCurrentRoot(), true, true);
+    }
+
     @Override
     public void actionPerformed(ActionEvent e) {
+        final XcosDiagram graph = (XcosDiagram) getGraph(e);
+        final StringBuilder command = new StringBuilder();
+
+        final BasicBlock block;
+        final ActionListener callback;
+
+        /*
+         * Export the whole graph, to update all the sub-graphs on demand.
+         */
+        command.append("scs_m = scicos_new(\"0x").append(Long.toHexString(graph.getUID())).append("\"); \n");
+
+        /*
+         * Then export the selected block
+         */
+        Object cell = graph.getSelectionCell();
+        if (cell instanceof BasicBlock) {
+            block = (BasicBlock) cell;
+            command.append("blk = scicos_new(\"0x").append(Long.toHexString(block.getUID())).append("\"); \n");
+            command.append(localCommand).append('\n');
+            command.append("if exists('blk') then xcosCellCreated(blk); end\n");
+        } else {
+            block = null;
+        }
+
+
+
+        /*
+         * Import the updated block
+         */
+        if (block != null) {
+            callback = new ActionListener() {
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    // Now update the Block
+                    graph.getModel().beginUpdate();
+                    try {
+                        ScicosObjectOwner last = XcosCellFactory.getLastCreated();
+                        if (last != null && last.getUID() != 0l) {
+                            JavaController controller = new JavaController();
+
+                            BasicBlock modified = XcosCellFactory.createBlock(controller, last);
+                            if (modified != null) {
+                                block.updateBlockSettings(controller, graph, modified);
+                            }
+                        }
+                        BlockPositioning.updateBlockView(graph, block);
+                    } finally {
+                        graph.getModel().endUpdate();
+                        reset_view(graph, block, false);
+                    }
+                }
+            };
+        } else {
+            callback = (ActionEvent ev) -> {
+                reset_view(graph, block, false);
+            };
+        }
 
-        // FIXME: implement the external action
-        //        final XcosDiagram graph = (XcosDiagram) getGraph(e);
-        //        final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
-        //        if (handler == null) {
-        //            return;
-        //        }
-        //
-        //        final BasicBlock block;
-        //        final ActionListener callback;
-        //        try {
-        //            /*
-        //             * Export the whole diagram, to update all the sub-diagrams on demand.
-        //             */
-        //            handler.writeDiagram(graph.getRootDiagram());
-        //
-        //            /*
-        //             * Then export the selected block
-        //             */
-        //            Object cell = graph.getSelectionCell();
-        //            if (cell instanceof BasicBlock) {
-        //                block = (BasicBlock) cell;
-        //                handler.writeBlock(block);
-        //            } else {
-        //                block = null;
-        //            }
-        //
-        //            /*
-        //             * Import the updated block
-        //             */
-        //            if (block != null) {
-        //                callback = new ActionListener() {
-        //                    @Override
-        //                    public void actionPerformed(ActionEvent e) {
-        //                        try {
-        //
-        //                            final BasicBlock modifiedBlock = handler.readBlock();
-        //                            block.updateBlockSettings(modifiedBlock);
-        //
-        //                            graph.fireEvent(new mxEventObject(XcosEvent.ADD_PORTS, XcosConstants.EVENT_BLOCK_UPDATED, block));
-        //                        } catch (ScicosFormatException e1) {
-        //                            LOG.severe(e1.getMessage());
-        //                        } finally {
-        //                            handler.release();
-        //                        }
-        //                    }
-        //                };
-        //            } else {
-        //                callback = new ActionListener() {
-        //                    @Override
-        //                    public void actionPerformed(ActionEvent e) {
-        //                        handler.release();
-        //                    }
-        //                };
-        //            }
-        //
-        //            ScilabInterpreterManagement.asynchronousScilabExec(callback, localCommand);
-        //        } catch (InterpreterException e2) {
-        //            LOG.warning(e2.toString());
-        //
-        //            handler.release();
-        //        }
+        try {
+            reset_view(graph, block, true);
+            ScilabInterpreterManagement.asynchronousScilabExec(callback, command.toString());
+        } catch (InterpreterException e1) {
+            reset_view(graph, block, false);
+        }
     }
 }
index 00a3d9b..950a1ed 100644 (file)
@@ -26,6 +26,8 @@ import java.util.HashMap;
 import java.util.Optional;
 import java.util.logging.Logger;
 
+import javax.swing.SwingUtilities;
+
 import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
 import org.scilab.modules.graph.utils.ScilabExported;
 import org.scilab.modules.xcos.JavaController;
@@ -87,7 +89,42 @@ public final class XcosCellFactory {
 
     }
 
+    /**
+     * This is a notify method mapped as a Scilab gateway used to update an 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 synchronized void update(long uid, int kind) {
+        lastCreated = new ScicosObjectOwner(uid, Kind.values()[kind]);
+
+        try {
+            SwingUtilities.invokeAndWait(() -> {
+                if (kind == Kind.BLOCK.ordinal()) {
+                    JavaController controller = new JavaController();
+
+                    XcosDiagram graph = previousDiagram;
+                    graph.getModel().beginUpdate();
+                    try {
+                        BasicBlock block = createBlock(controller, lastCreated);
+                        previousBlock.updateBlockSettings(controller, graph, block);
+                        BlockPositioning.updateBlockView(graph, block);
+                    } finally {
+                        graph.getModel().beginUpdate();
+                    }
+                }
+            });
+        } catch (InvocationTargetException | InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
     private static ScicosObjectOwner lastCreated = null;
+    private static BasicBlock previousBlock = null;
+    private static XcosDiagram previousDiagram = null;
 
     /**
      * Retrieve and clear the last created object (<pre>xcosCellCreated</pre> call)
@@ -99,6 +136,15 @@ public final class XcosCellFactory {
         return last;
     }
 
+    /**
+     * Set an object available for update (<pre>xcosUpdateBlock</pre> call)
+     * @param previous the object to track for update
+     */
+    public static synchronized void setPrevious(BasicBlock block, XcosDiagram diagram) {
+        previousBlock = block;
+        previousDiagram = diagram;
+    }
+
     /*
      * Diagram management
      */
index 91cec47..8c03926 100644 (file)
@@ -9,14 +9,31 @@ 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.
 
-Copyright (C) 2012 - 2016 - Scilab Enterprises
-
-This file is hereby licensed under the terms of the GNU GPL v2.0,
-pursuant to article 5.3.4 of the CeCILL v.2.1.
-This file was originally licensed under the terms of the CeCILL v2.1,
-and continues to be available under such terms.
-For more information, see the COPYING file which you should have received
-along with this program.
+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 {
@@ -87,6 +104,7 @@ curEnv->DeleteLocalRef(localInstance);
 
                 /* Methods ID set to NULL */
 voidcreatedjlonglongjintintID=NULL;
+voidupdatejlonglongjintintID=NULL;
 
 
 }
@@ -110,6 +128,7 @@ throw GiwsException::JniObjectCreationException(curEnv, this->className());
         }
         /* Methods ID set to NULL */
         voidcreatedjlonglongjintintID=NULL;
+voidupdatejlonglongjintintID=NULL;
 
 
 }
@@ -149,4 +168,24 @@ throw GiwsException::JniCallMethodException(curEnv);
 }
 }
 
+void XcosCellFactory::update (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 voidupdatejlonglongjintintID = curEnv->GetStaticMethodID(cls, "update", "(JI)V" ) ;
+if (voidupdatejlonglongjintintID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "update");
+}
+
+                         curEnv->CallStaticVoidMethod(cls, voidupdatejlonglongjintintID ,uid, kind);
+                        if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
 }
index 1cf39be..81f9874 100644 (file)
@@ -5,6 +5,10 @@
             <parameter name="uid" type="long"/>
             <parameter name="kind" type="int"/>
         </method>
+        <method name="update" returnType="void" modifier="static">
+            <parameter name="uid" type="long"/>
+            <parameter name="kind" type="int"/>
+        </method>
     </object>
 </package>
 
index 474d566..5ca43fd 100644 (file)
@@ -8,14 +8,31 @@ 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.
 
-Copyright (C) 2012 - 2016 - Scilab Enterprises
-
-This file is hereby licensed under the terms of the GNU GPL v2.0,
-pursuant to article 5.3.4 of the CeCILL v.2.1.
-This file was originally licensed under the terms of the CeCILL v2.1,
-and continues to be available under such terms.
-For more information, see the COPYING file which you should have received
-along with this program.
+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.
 */
 
 
@@ -60,6 +77,7 @@ JavaVM * jvm;
 
 protected:
 jmethodID voidcreatedjlonglongjintintID; // cache method id
+jmethodID voidupdatejlonglongjintintID; // cache method id
 
 
 
@@ -121,6 +139,8 @@ void endSynchronize();
 // Methods
 static void created(JavaVM * jvm_, long long uid, int kind);
 
+static void update(JavaVM * jvm_, long long uid, int kind);
+
 
                         /**
                         * Get class name to use for static methods