Xcos: fix xcosPalGenerateAllIcon thanks to the MVC 02/18102/4
Clément DAVID [Wed, 20 Apr 2016 07:27:09 +0000 (09:27 +0200)]
The same execution path than on Drag n' Drop is used to render blocks the
same way. The images palettes will be updated on another commit.

Change-Id: I1ac0519fba980fd52c67154171ab920a28b49896

scilab/modules/modules_manager/macros/tbx_build_blocks.sci
scilab/modules/xcos/includes/gw_xcos.h
scilab/modules/xcos/includes/gw_xcos.hxx
scilab/modules/xcos/macros/xcosPalGenerateAllIcons.sci
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp
scilab/modules/xcos/sci_gateway/xcos_gateway.xml
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCellFactory.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/Palette.java
scilab/modules/xcos/src/jni/Palette.giws.xml

index 9c883a9..9055cd1 100644 (file)
@@ -111,7 +111,7 @@ function tbx_build_blocks(module, names, macros_path)
         files = files(isfile(files));
         if files == [] then
             filename = gif_tlbx + "/" + names(i) + ".gif";
-            xcosPalGenerateIcon(filename);
+            xcosPalGenerateIcon(blk, filename);
         end
     end
 endfunction
index 55744fa..1a3fb87 100644 (file)
@@ -31,7 +31,6 @@ XCOS_IMPEXP int sci_xcosPalDelete(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosPalMove(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosPalEnable(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosPalDisable(char *fname, void *pvApiCtx);
-XCOS_IMPEXP int sci_xcosPalGenerateIcon(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosConfigureXmlFile(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosAddToolsMenu(char *fname, void *pvApiCtx);
 XCOS_IMPEXP int sci_xcosUpdateBlock(char *fname, void *pvApiCtx);
index 1d16670..b897c50 100644 (file)
@@ -22,6 +22,7 @@
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_Xcos, XCOS_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosCellCreated, XCOS_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosDiagramToScilab, XCOS_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_xcosPalGenerateIcon, XCOS_IMPEXP);
 
 #endif /* GW_XCOS_HXX_ */
 
index df758ff..1b85834 100644 (file)
@@ -49,7 +49,7 @@ function blocks = xcosPalGenerateAllIcons(path)
         end
 
         // generate the icon
-        xcosPalGenerateIcon(iconPath);
+        xcosPalGenerateIcon(blk, iconPath);
 
         blocks($+1) = name;
     end
index 61edec6..ef9aaa4 100644 (file)
  *
  */
 
+#include <string>
+
+#include "gw_xcos.hxx"
 #include "Palette.hxx"
-#include "Controller.hxx"
+#include "model/BaseObject.hxx"
+#include "view_scilab/Adapters.hxx"
+
+#include "types.hxx"
+#include "function.hxx"
+#include "string.hxx"
+#include "UTF8.hxx"
+
 #include "GiwsException.hxx"
 #include "xcosUtilities.hxx"
 #include "loadStatus.hxx"
 
 extern "C"
 {
-#include "gw_xcos.h"
-#include "api_scilab.h"
 #include "localization.h"
 #include "Scierror.h"
-#include "sci_malloc.h"
 #include "getScilabJavaVM.h"
 }
 
 using namespace org_scilab_modules_xcos_palette;
 using namespace org_scilab_modules_scicos;
 
-int sci_xcosPalGenerateIcon(char *fname, void* pvApiCtx)
+static char funname[] = "xcosPalGenerateIcon";
+
+types::Function::ReturnValue sci_xcosPalGenerateIcon(types::typed_list &in, int _iRetCount, types::typed_list &/*out*/)
 {
-    CheckRhs(1, 1);
-    CheckLhs(0, 1);
+    if (in.size() != 2)
+    {
+        Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), funname, 2);
+        return types::Function::Error;
+    }
 
-    char *iconPath = NULL;
+    if (_iRetCount > 1)
+    {
+        Scierror(999, _("%s: Wrong number of output argument(s): %d expected.\n"), funname, 1);
+        return types::Function::Error;
+    }
 
-    /* iconPath setup */
-    if (readSingleString(pvApiCtx, 1, &iconPath, fname))
+    const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(in[0]);
+    if (o == nullptr || o->kind() != BLOCK)
     {
-        return 0;
+        Scierror(999, _("%s: Argument #%d: ""%s"" expected.\n"), funname, 1, "Block");
+        return types::Function::Error;
     }
 
+    if (!in[1]->isString())
+    {
+        Scierror(999, _("%s: Argument #%d: ""%s"" expected.\n"), funname, 2, "String");
+        return types::Function::Error;
+    }
+    types::String* path = in[1]->getAs<types::String>();
+    if (path->getSize() != 1)
+    {
+        Scierror(999, _("%s: Argument #%d: Scalar (1 element) expected.\n"), funname, 2);
+        return types::Function::Error;
+    }
+    std::string iconPath = scilab::UTF8::toUTF8(path->get(0));
+
     /* Call the java implementation */
     set_loaded_status(XCOS_CALLED);
     try
     {
-        Controller controller;
-        Palette::generatePaletteIcon(getScilabJavaVM(), controller.createObject(DIAGRAM), iconPath);
+        Palette::generatePaletteIcon(getScilabJavaVM(), o->id(), iconPath.c_str());
     }
     catch (GiwsException::JniCallMethodException &exception)
     {
-        Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
+        Scierror(999, "%s: %s\n", funname, exception.getJavaDescription().c_str());
+        return types::Function::Error;
     }
     catch (GiwsException::JniException &exception)
     {
-        Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
+        Scierror(999, "%s: %s\n", funname, exception.whatStr().c_str());
+        return types::Function::Error;
     }
 
-    FREE(iconPath);
-
-    LhsVar(1) = 0;
-    PutLhsVar();
-    return 0;
+    return types::Function::OK;
 }
+
index 9efa5b8..caf358e 100644 (file)
@@ -30,7 +30,6 @@
     <gateway name="sci_xcosPalMove"             function="xcosPalMove"              type="0" />
     <gateway name="sci_xcosPalEnable"           function="xcosPalEnable"            type="0" />
     <gateway name="sci_xcosPalDisable"          function="xcosPalDisable"           type="0" />
-    <gateway name="sci_xcosPalGenerateIcon"     function="xcosPalGenerateIcon"      type="0" />
     <gateway name="sci_xcosConfigureXmlFile"    function="xcosConfigureXmlFile"     type="0" />
     <gateway name="sci_xcosAddToolsMenu"        function="xcosAddToolsMenu"         type="0" />
     <gateway name="sci_loadXcos"                function="loadXcos"                 type="0" />
@@ -40,5 +39,6 @@
     <gateway name="sci_Xcos"                    function="xcos"                     type="1" />
     <gateway name="sci_xcosCellCreated"         function="xcosCellCreated"          type="1" />
     <gateway name="sci_xcosDiagramToScilab"     function="xcosDiagramToScilab"      type="1" />
+    <gateway name="sci_xcosPalGenerateIcon"     function="xcosPalGenerateIcon"      type="1" />
 </module>
 
index 7598233..8dae111 100644 (file)
@@ -299,7 +299,7 @@ public final class XcosCellFactory {
         return block;
     }
 
-    private static BasicBlock createBlock(final JavaController controller, long uid, Kind kind) {
+    public static BasicBlock createBlock(final JavaController controller, long uid, Kind kind) {
         String[] interfaceFunction = new String[1];
         if (kind == Kind.BLOCK) {
             controller.getObjectProperty(uid, kind, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
index 9678549..2f746ba 100644 (file)
@@ -56,7 +56,7 @@ import com.mxgraph.util.mxCellRenderer;
 import com.mxgraph.util.mxRectangle;
 import com.mxgraph.view.mxGraphView;
 import com.mxgraph.view.mxStylesheet;
-import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.graph.model.XcosCellFactory;
 
 /**
  * Utility class which is the entry point from Scilab for palette related
@@ -285,7 +285,7 @@ public final class Palette {
                 if (root instanceof PreLoaded) {
                     pal = (PreLoaded) root;
                 } else if (root instanceof Category) {
-                    LinkedList<Category> stash = new LinkedList<Category>();
+                    LinkedList<Category> stash = new LinkedList<>();
                     stash.add((Category) root);
 
                     pal = new PreLoaded();
@@ -318,7 +318,7 @@ public final class Palette {
     }
 
     private static List<PaletteBlock> list(Deque<Category> stash, PreLoaded pal) {
-        final ArrayList<PaletteBlock> blocks = new ArrayList<PaletteBlock>();
+        final ArrayList<PaletteBlock> blocks = new ArrayList<>();
         while (!stash.isEmpty()) {
             final Category c = stash.pop();
             for (PaletteNode n : c.getNode()) {
@@ -515,16 +515,7 @@ public final class Palette {
         JavaController controller = new JavaController();
         Kind kind = controller.getKind(uid);
 
-        String[] strUID = new String[] { "" };
-        controller.getObjectProperty(uid, kind, ObjectProperties.UID, strUID);
-
-        String[] label = new String[] { "" };
-        controller.getObjectProperty(uid, kind, ObjectProperties.LABEL, label);
-
-        String[] style = new String[] { "" };
-        controller.getObjectProperty(uid, kind, ObjectProperties.STYLE, style);
-
-        final BasicBlock block = new BasicBlock(new JavaController(), uid, kind, label[0], null, style[0], strUID[0]);
+        final BasicBlock block = XcosCellFactory.createBlock(controller, uid, kind);
         generateIcon(block, iconPath);
 
         if (LOG.isLoggable(Level.FINEST)) {
@@ -571,8 +562,5 @@ public final class Palette {
 
         final String extension = iconPath.substring(iconPath.lastIndexOf('.') + 1);
         ImageIO.write(image, extension, new File(iconPath));
-
-
-        controller.deleteObject(graph.getUID());
     }
 }
index 1f4c4b1..7192b22 100644 (file)
@@ -1,4 +1,4 @@
-        <package name="org.scilab.modules.xcos.palette">
+<package name="org.scilab.modules.xcos.palette">
     <object name="Palette">
         <method name="loadPal" returnType="void" modifier="static">
             <parameter name="name" type="String"/>