Xcos palette: add xcosPalGenerateAllIcon utility 38/9738/7
Clément DAVID [Mon, 19 Nov 2012 13:27:43 +0000 (14:27 +0100)]
The function update the palette icons according to changes of the interface function.

Change-Id: I885cf2e661c35d98f07b7c30e59d14cef7ef0987

17 files changed:
SEP/SEP_045_xcos_palette.odt
scilab/CHANGES_5.4.X
scilab/modules/xcos/Makefile.am
scilab/modules/xcos/Makefile.in
scilab/modules/xcos/help/en_US/scilab_utilities_functions/xcosPalGenerateAllIcons.xml [new file with mode: 0644]
scilab/modules/xcos/includes/gw_xcos.h
scilab/modules/xcos/sci_gateway/c/gw_xcos.c
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalGenerateAllIcons.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/java/org/scilab/modules/xcos/palette/Palette.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteBlockCtrl.java
scilab/modules/xcos/src/jni/Palette.cpp
scilab/modules/xcos/src/jni/Palette.giws.xml
scilab/modules/xcos/src/jni/Palette.hxx
scilab/modules/xcos/tests/unit_tests/xcosPalGenerateAllIcons.dia.ref [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/xcosPalGenerateAllIcons.tst [new file with mode: 0644]

index cd3d48d..3d0d5b4 100644 (file)
Binary files a/SEP/SEP_045_xcos_palette.odt and b/SEP/SEP_045_xcos_palette.odt differ
index 95d9a9e..85ef0f7 100644 (file)
@@ -53,6 +53,8 @@ Xcos
 
 * Update the Palette icons and the rendering of some blocks.
 
+* xcosPalGenerateAllIcons added as an Xcos palette utility function.
+
 * Add a new ODE solver : LSodar. Automatically switches methods to efficiently solve both stiff and nonstiff problems. Includes a rootfinding feature.
 
 * Add a new ODE solver : Dormand-Price 4(5). Included in the CVode package, so benefits from the rootfinding feature.
index b6e3068..0ddad61 100644 (file)
@@ -69,7 +69,8 @@ GATEWAY_CXX_SOURCES = \
        sci_gateway/cpp/sci_xcosAddToolsMenu.cpp \
        sci_gateway/cpp/sci_xcosUpdateBlock.cpp \
        sci_gateway/cpp/sci_loadXcos.cpp \
-       sci_gateway/cpp/sci_xcosSimulationStarted.cpp
+       sci_gateway/cpp/sci_xcosSimulationStarted.cpp \
+       sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp
 
 libscixcos_la_CPPFLAGS = \
                        -I$(srcdir)/includes/ \
index edfc8de..965fc44 100644 (file)
@@ -169,7 +169,8 @@ am__objects_4 = libscixcos_la-sci_Xcos.lo \
        libscixcos_la-sci_xcosAddToolsMenu.lo \
        libscixcos_la-sci_xcosUpdateBlock.lo \
        libscixcos_la-sci_loadXcos.lo \
-       libscixcos_la-sci_xcosSimulationStarted.lo
+       libscixcos_la-sci_xcosSimulationStarted.lo \
+       libscixcos_la-sci_xcosPalGenerateAllIcons.lo
 am_libscixcos_la_OBJECTS = $(am__objects_3) $(am__objects_4)
 libscixcos_la_OBJECTS = $(am_libscixcos_la_OBJECTS)
 @GUI_TRUE@@XCOS_TRUE@am_libscixcos_la_rpath = -rpath $(pkglibdir)
@@ -516,7 +517,8 @@ GATEWAY_CXX_SOURCES = \
        sci_gateway/cpp/sci_xcosAddToolsMenu.cpp \
        sci_gateway/cpp/sci_xcosUpdateBlock.cpp \
        sci_gateway/cpp/sci_loadXcos.cpp \
-       sci_gateway/cpp/sci_xcosSimulationStarted.cpp
+       sci_gateway/cpp/sci_xcosSimulationStarted.cpp \
+       sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp
 
 libscixcos_la_CPPFLAGS = \
                        -I$(srcdir)/includes/ \
@@ -1041,6 +1043,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosPalDelete.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosPalDisable.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosPalEnable.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosPalGenerateAllIcons.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosPalGenerateIcon.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosPalMove.Plo@am__quote@
@@ -1243,6 +1246,13 @@ libscixcos_la-sci_xcosSimulationStarted.lo: sci_gateway/cpp/sci_xcosSimulationSt
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixcos_la-sci_xcosSimulationStarted.lo `test -f 'sci_gateway/cpp/sci_xcosSimulationStarted.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosSimulationStarted.cpp
 
+libscixcos_la-sci_xcosPalGenerateAllIcons.lo: sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixcos_la-sci_xcosPalGenerateAllIcons.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-sci_xcosPalGenerateAllIcons.Tpo -c -o libscixcos_la-sci_xcosPalGenerateAllIcons.lo `test -f 'sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-sci_xcosPalGenerateAllIcons.Tpo $(DEPDIR)/libscixcos_la-sci_xcosPalGenerateAllIcons.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp' object='libscixcos_la-sci_xcosPalGenerateAllIcons.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixcos_la-sci_xcosPalGenerateAllIcons.lo `test -f 'sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
diff --git a/scilab/modules/xcos/help/en_US/scilab_utilities_functions/xcosPalGenerateAllIcons.xml b/scilab/modules/xcos/help/en_US/scilab_utilities_functions/xcosPalGenerateAllIcons.xml
new file mode 100644 (file)
index 0000000..123f661
--- /dev/null
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="xcosPalGenerateAllIcons" xml:lang="en">
+    <refnamediv>
+        <refname>xcosPalGenerateAllIcons</refname>
+        <refpurpose>Update the palette icons (gif files) from a Scilab instance
+        </refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>
+            pal = xcosPalGenerateAllIcons(path)
+        </synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>path</term>
+                <listitem>
+                    <para>the palette path</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>This functionnality updates the image file used on the palette accordingly to the Scilab interface function. It can be used to update the representation of a block at any time after the first generation.
+        </para>
+    </refsection>
+    <refsection>
+        <title>Example</title>
+        <programlisting role="example"><![CDATA[
+// load all the default palettes
+loadXcosLibs();
+
+// will update the default palette
+xcosPalGenerateAllIcons(["Palettes" "Commonly Used Blocks"]);
+   ]]></programlisting>
+    </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.4.1</revnumber>
+                <revremark>
+                    Function added.
+                </revremark>
+            </revision>
+        </revhistory>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="xcosPalAdd">xcosPalAdd</link>
+            </member>
+            <member>
+                <link linkend="xcosPalAddBlock">xcosPalAddBlock</link>
+            </member>
+        </simplelist>
+    </refsection>
+</refentry>
index 69e064c..319303d 100644 (file)
@@ -38,6 +38,7 @@ int sci_xcosAddToolsMenu(char *fname, unsigned long l);
 int sci_xcosUpdateBlock(char *fname, unsigned long l);
 int sci_loadXcos(char *fname, unsigned long l);
 int sci_xcosSimulationStarted(char *fname, unsigned long l);
+int sci_xcosPalGenerateAllIcons(char *fname, unsigned long l);
 
 /*--------------------------------------------------------------------------*/
 /**
index 879ab10..67ab6d5 100644 (file)
@@ -42,7 +42,8 @@ static gw_generic_table Tab[] =
     {sci_xcosAddToolsMenu, "xcosAddToolsMenu"},
     {sci_xcosUpdateBlock, "xcosUpdateBlock"},
     {sci_loadXcos, "loadXcos"},
-    {sci_xcosSimulationStarted, "xcosSimulationStarted"}
+    {sci_xcosSimulationStarted, "xcosSimulationStarted"},
+    {sci_xcosPalGenerateAllIcons, "xcosPalGenerateAllIcons"}
 };
 
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalGenerateAllIcons.cpp
new file mode 100644 (file)
index 0000000..4762a80
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) DIGITEO - 2010-2010 - Clément DAVID <clement.david@scilab.org>
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "Palette.hxx"
+#include "GiwsException.hxx"
+#include "xcosUtilities.hxx"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "freeArrayOfString.h"
+#include "MALLOC.h"
+#include "getScilabJavaVM.h"
+}
+
+using namespace org_scilab_modules_xcos_palette;
+
+int sci_xcosPalGenerateAllIcons(char *fname, unsigned long fname_len)
+{
+    CheckInputArgument(pvApiCtx, 1, 1);
+    CheckOutputArgument(pvApiCtx, 0, 1);
+
+    char **path = NULL;
+    int pathLength = 0;
+
+    /* path setup */
+    if (readVectorString(pvApiCtx, 1, &path, &pathLength, fname))
+    {
+        return 0;
+    }
+
+    /* Call the java implementation */
+    try
+    {
+        Palette::generateAllImages(getScilabJavaVM(), path, pathLength);
+    }
+    catch (GiwsException::JniCallMethodException &exception)
+    {
+        Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
+    }
+    catch (GiwsException::JniException &exception)
+    {
+        Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
+    }
+
+    freeArrayOfString(path, pathLength);
+
+    AssignOutputVariable(pvApiCtx, 1) = 0;
+    ReturnArguments(pvApiCtx);
+
+    return 0;
+}
+
index ebca3e3..c73ba9b 100644 (file)
@@ -37,4 +37,5 @@
     <PRIMITIVE gatewayId="64" primitiveId="14" primitiveName="xcosUpdateBlock"/>
     <PRIMITIVE gatewayId="64" primitiveId="15" primitiveName="loadXcos"/>
     <PRIMITIVE gatewayId="64" primitiveId="16" primitiveName="xcosSimulationStarted"/>
+    <PRIMITIVE gatewayId="64" primitiveId="17" primitiveName="xcosPalGenerateAllIcons"/>
 </GATEWAY>
index 16ed652..467018c 100644 (file)
     <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosUpdateBlock.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_loadXcos.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosSimulationStarted.cpp" />
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalGenerateAllIcons.cpp" />
     <ClCompile Include="..\jni\Xcos.cpp" />
     <ClCompile Include="..\cpp\xcosUtilities.cpp" />
   </ItemGroup>
index 5ac5aaa..d0864b9 100644 (file)
 package org.scilab.modules.xcos.palette;
 
 import java.awt.GraphicsEnvironment;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -481,53 +484,66 @@ public final class Palette {
     }
 
     /**
-     * Helper function used to regenerate palette block images from block
+     * Helper function used to regenerate palette block images from the block
      * instance.
      *
-     * This method is not export to scilab but is needed for internal purpose
-     * (palette block image generation)
+     * @param path
+     *            the path to emit the images for.
      */
-    public static void generateAllPaletteImages() {
+    public static void generateAllImages(final String[] path) {
+        PaletteManager.getInstance();
+
         SwingUtilities.invokeLater(new Runnable() {
+
             @Override
             public void run() {
-                final PaletteManager current = PaletteManager.getInstance();
-                iterate(current.getRoot().getNode());
-                current.saveConfig();
+                final PaletteNode src = getPathNode(path, false);
+                if (src == null) {
+                    System.err.print(String.format(WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH, "path"));
+                    return;
+                }
+
+                iterate(Collections.singletonList(src));
             }
+        });
 
-            private void iterate(final List<PaletteNode> children) {
-                for (final PaletteNode next : children) {
-                    if (next instanceof Category) {
-                        iterate(((Category) next).getNode());
-                    } else if (next instanceof PreLoaded) {
-                        generatePreLoadedIcon((PreLoaded) next);
-                    }
-                }
+        LOG.finest("All images has been generated.");
+    }
+
+    private static void iterate(final List<PaletteNode> children) {
+        for (final PaletteNode next : children) {
+            if (next instanceof Category) {
+                iterate(((Category) next).getNode());
+            } else if (next instanceof PreLoaded) {
+                generatePreLoadedIcon((PreLoaded) next);
             }
+        }
+    }
 
-            /**
-             * Generate PreLoaded icon file.
-             *
-             * @param current
-             *            the current node
-             */
-            private void generatePreLoadedIcon(final PreLoaded current) {
-                final List<PaletteBlock> blocks = current.getBlock();
-                for (final PaletteBlock paletteBlock : blocks) {
+    /**
+     * Generate PreLoaded icon file.
+     *
+     * @param current
+     *            the current node
+     */
+    private static void generatePreLoadedIcon(final PreLoaded current) {
+        final List<PaletteBlock> blocks = current.getBlock();
+        for (final PaletteBlock paletteBlock : blocks) {
+
+            new PaletteBlockCtrl(paletteBlock).loadBlock(new ActionListener() {
 
+                @Override
+                public void actionPerformed(ActionEvent event) {
                     try {
-                        final BasicBlock block = new PaletteBlockCtrl(paletteBlock).loadBlock();
-                        generateIcon(block, paletteBlock.getIcon().getEvaluatedPath());
+                        generateIcon((BasicBlock) event.getSource(), paletteBlock.getIcon().getEvaluatedPath());
+                        if (LOG.isLoggable(Level.FINEST)) {
+                            LOG.finest(String.format("%s has been generated", paletteBlock.getIcon()));
+                        }
                     } catch (IOException e) {
                         e.printStackTrace();
-                    } catch (ScicosFormatException e) {
-                        e.printStackTrace();
                     }
                 }
-            }
-        });
-
-        LOG.finest("All images has been generated.");
+            });
+        }
     }
 }
index 306d533..0ae5723 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.scilab.modules.xcos.palette;
 
+import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.asynchronousScilabExec;
 import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.buildCall;
 import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.synchronousScilabExec;
 
@@ -22,6 +23,8 @@ import java.awt.dnd.DragGestureEvent;
 import java.awt.dnd.DragGestureListener;
 import java.awt.dnd.DragSource;
 import java.awt.dnd.InvalidDnDOperationException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.MouseListener;
 import java.lang.ref.WeakReference;
 import java.util.logging.Level;
@@ -160,7 +163,7 @@ public final class PaletteBlockCtrl {
      * @throws ScicosFormatException
      *             on error
      */
-    protected BasicBlock loadBlock() throws ScicosFormatException {
+    private BasicBlock loadBlock() throws ScicosFormatException {
         BasicBlock block;
         if (model.getName().compareTo("TEXT_f") != 0) {
 
@@ -195,6 +198,57 @@ public final class PaletteBlockCtrl {
     }
 
     /**
+     * @param callback
+     *            called after the block loading
+     */
+    protected void loadBlock(final ActionListener callback) {
+        if (model.getName().compareTo("TEXT_f") != 0) {
+
+            // Load the block with a reference instance
+            final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
+            if (handler == null) {
+                return;
+            }
+
+            final ActionListener internalCallback = new ActionListener() {
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    try {
+                        final BasicBlock block = handler.readBlock();
+
+                        // invalid block case
+                        if (block == null) {
+                            return;
+                        }
+
+                        // update style
+                        if (block.getStyle().compareTo("") == 0) {
+                            block.setStyle(block.getInterfaceFunctionName());
+                        }
+
+                        callback.actionPerformed(new ActionEvent(block, 0, "loaded"));
+                    } catch (ScicosFormatException e1) {
+                        e1.printStackTrace();
+                    } finally {
+                        handler.release();
+                    }
+                }
+            };
+
+            try {
+                asynchronousScilabExec(internalCallback, ScilabDirectHandler.BLK + " = " + buildCall(model.getName(), "define"));
+            } catch (InterpreterException e1) {
+                LOG.severe(e1.toString());
+            } finally {
+                handler.release();
+            }
+        } else {
+            final BasicBlock block = BlockFactory.createBlock(BlockInterFunction.TEXT_f);
+            callback.actionPerformed(new ActionEvent(block, 0, "loaded"));
+        }
+    }
+
+    /**
      * This function load the block and render it on the hidden diagram. This
      * can be time-consuming and each block should be cached on the caller when
      * possible.
index 860aaa8..1039305 100644 (file)
@@ -111,6 +111,7 @@ voidremovejobjectArray_java_lang_Stringjava_lang_StringID=NULL;
 voidenablejobjectArray_java_lang_Stringjava_lang_StringjbooleanbooleanID=NULL;
 voidmovejobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringID=NULL;
 voidgeneratePaletteIconjstringjava_lang_StringID=NULL;
+voidgenerateAllImagesjobjectArray_java_lang_Stringjava_lang_StringID=NULL;
 
 
 }
@@ -140,6 +141,7 @@ voidremovejobjectArray_java_lang_Stringjava_lang_StringID=NULL;
 voidenablejobjectArray_java_lang_Stringjava_lang_StringjbooleanbooleanID=NULL;
 voidmovejobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringID=NULL;
 voidgeneratePaletteIconjstringjava_lang_StringID=NULL;
+voidgenerateAllImagesjobjectArray_java_lang_Stringjava_lang_StringID=NULL;
 
 
 }
@@ -456,4 +458,46 @@ throw GiwsException::JniCallMethodException(curEnv);
 }
 }
 
+void Palette::generateAllImages (JavaVM * jvm_, char const* const* path, int pathSize){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidgenerateAllImagesjobjectArray_java_lang_Stringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "generateAllImages", "([Ljava/lang/String;)V" ) ;
+if (voidgenerateAllImagesjobjectArray_java_lang_Stringjava_lang_StringID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "generateAllImages");
+}
+jclass stringArrayClass = curEnv->FindClass("java/lang/String");
+
+// create java array of strings.
+jobjectArray path_ = curEnv->NewObjectArray( pathSize, stringArrayClass, NULL);
+if (path_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+// convert each char * to java strings and fill the java array.
+for ( int i = 0; i < pathSize; i++)
+{
+jstring TempString = curEnv->NewStringUTF( path[i] );
+if (TempString == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+curEnv->SetObjectArrayElement( path_, i, TempString);
+
+// avoid keeping reference on to many strings
+curEnv->DeleteLocalRef(TempString);
+}
+                         curEnv->CallStaticVoidMethod(cls, voidgenerateAllImagesjobjectArray_java_lang_Stringjava_lang_StringID ,path_);
+                        curEnv->DeleteLocalRef(stringArrayClass);
+curEnv->DeleteLocalRef(path_);
+curEnv->DeleteLocalRef(cls);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
 }
index a0b10f1..40b8c06 100644 (file)
@@ -25,5 +25,8 @@
         <method name="generatePaletteIcon" returnType="void" modifier="static">
             <parameter name="iconPath" type="String"/>
         </method>
+        <method name="generateAllImages" returnType="void" modifier="static">
+            <parameter name="path" type="String[]"/>
+        </method>
     </object>
 </package>
index e8263aa..73b2141 100644 (file)
@@ -84,6 +84,7 @@ jmethodID voidremovejobjectArray_java_lang_Stringjava_lang_StringID; // cache me
 jmethodID voidenablejobjectArray_java_lang_Stringjava_lang_StringjbooleanbooleanID; // cache method id
 jmethodID voidmovejobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringID; // cache method id
 jmethodID voidgeneratePaletteIconjstringjava_lang_StringID; // cache method id
+jmethodID voidgenerateAllImagesjobjectArray_java_lang_Stringjava_lang_StringID; // cache method id
 
 
 
@@ -157,6 +158,8 @@ static void move(JavaVM * jvm_, char const* const* source, int sourceSize, char
 
 static void generatePaletteIcon(JavaVM * jvm_, char const* iconPath);
 
+static void generateAllImages(JavaVM * jvm_, char const* const* path, int pathSize);
+
 
                         /**
                         * Get class name to use for static methods
diff --git a/scilab/modules/xcos/tests/unit_tests/xcosPalGenerateAllIcons.dia.ref b/scilab/modules/xcos/tests/unit_tests/xcosPalGenerateAllIcons.dia.ref
new file mode 100644 (file)
index 0000000..54522bf
--- /dev/null
@@ -0,0 +1,16 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+//
+// This file is distributed under the same license as the Scilab package.
+// <-- XCOS TEST -->
+// <-- ENGLISH IMPOSED -->
+//
+// <-- Short Description -->
+// White-box test for the xcosPalGenerateAllIcons.
+loadXcosLibs();
+// on the standard palette
+xcosPalGenerateAllIcons(["Palettes" "Commonly Used Blocks"]);
+// on a custom palette
+pal = xcosPal();
+pal = xcosPalAddBlock(pal, "BIGSOM_f", "SCI/modules/xcos/images/palettes/GOTO.png", "SCI/modules/xcos/images/palettes/GOTO.png");
+assert_checktrue(xcosPalAdd(pal, "my Summation blocks"));
+xcosPalGenerateAllIcons("my Summation blocks");
diff --git a/scilab/modules/xcos/tests/unit_tests/xcosPalGenerateAllIcons.tst b/scilab/modules/xcos/tests/unit_tests/xcosPalGenerateAllIcons.tst
new file mode 100644 (file)
index 0000000..1edb6c7
--- /dev/null
@@ -0,0 +1,23 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) Scilab Enterprises - 2012 - Clément DAVID
+//
+// This file is distributed under the same license as the Scilab package.
+
+// <-- XCOS TEST -->
+// <-- ENGLISH IMPOSED -->
+//
+// <-- Short Description -->
+// White-box test for the xcosPalGenerateAllIcons.
+
+loadXcosLibs();
+
+// on the standard palette
+xcosPalGenerateAllIcons(["Palettes" "Commonly Used Blocks"]);
+
+// on a custom palette
+pal = xcosPal();
+pal = xcosPalAddBlock(pal, "BIGSOM_f", "SCI/modules/xcos/images/palettes/GOTO.png", "SCI/modules/xcos/images/palettes/GOTO.png");
+assert_checktrue(xcosPalAdd(pal, "my Summation blocks"));
+
+xcosPalGenerateAllIcons("my Summation blocks");
+