The function update the palette icons according to changes of the interface function.
Change-Id: I885cf2e661c35d98f07b7c30e59d14cef7ef0987
* 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.
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/ \
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)
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/ \
@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@
@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
--- /dev/null
+<?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>
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);
/*--------------------------------------------------------------------------*/
/**
{sci_xcosAddToolsMenu, "xcosAddToolsMenu"},
{sci_xcosUpdateBlock, "xcosUpdateBlock"},
{sci_loadXcos, "loadXcos"},
- {sci_xcosSimulationStarted, "xcosSimulationStarted"}
+ {sci_xcosSimulationStarted, "xcosSimulationStarted"},
+ {sci_xcosPalGenerateAllIcons, "xcosPalGenerateAllIcons"}
};
/*--------------------------------------------------------------------------*/
--- /dev/null
+/*
+ * 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;
+}
+
<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>
<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>
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;
}
/**
- * 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.");
+ });
+ }
}
}
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;
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;
* @throws ScicosFormatException
* on error
*/
- protected BasicBlock loadBlock() throws ScicosFormatException {
+ private BasicBlock loadBlock() throws ScicosFormatException {
BasicBlock block;
if (model.getName().compareTo("TEXT_f") != 0) {
}
/**
+ * @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.
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;
}
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;
}
}
}
+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);
+}
+}
+
}
<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>
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
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
--- /dev/null
+// 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");
--- /dev/null
+// 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");
+