Xcos: add SEP 45 implementation (xcos palette management from Scilab) 42/942/4
Clément DAVID [Wed, 9 Jun 2010 12:54:49 +0000 (14:54 +0200)]
Add the implementation
Update the SEP from the implementation
Simple test case added (modules/xcos/tests/unit_tests/xcosPal.sci)

Change-Id: Idf9294786b660b5b82efa3340b4153a2d2dc7d9d

30 files changed:
SEP/SEP_45_xcos_palette.odt
scilab/modules/xcos/Makefile.am
scilab/modules/xcos/Makefile.in
scilab/modules/xcos/includes/gw_xcos.h
scilab/modules/xcos/macros/generateBlockImage.sci
scilab/modules/xcos/macros/generateBlockImages.sci
scilab/modules/xcos/macros/xcosPal.sci [new file with mode: 0644]
scilab/modules/xcos/macros/xcosPalAdd.sci [new file with mode: 0644]
scilab/modules/xcos/macros/xcosPalAddBlock.sci [new file with mode: 0644]
scilab/modules/xcos/macros/xcosPalExport.sci [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/c/gw_xcos.c
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalDelete.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalDisable.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalEnable.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalLoad.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalMove.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/cpp/xcosUtilities.cpp [new file with mode: 0644]
scilab/modules/xcos/sci_gateway/xcos_gateway.xml
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/scicos/ScicosFormatException.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/Palette.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteBlockCtrl.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteManager.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PreLoadedElement.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/StyleElement.java [new file with mode: 0644]
scilab/modules/xcos/src/jni/Palette.cpp [new file with mode: 0644]
scilab/modules/xcos/src/jni/Palette.giws.xml [new file with mode: 0644]
scilab/modules/xcos/src/jni/Palette.hxx [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/xcosPal.sci [new file with mode: 0644]

index d75ed8b..2e13b6e 100644 (file)
Binary files a/SEP/SEP_45_xcos_palette.odt and b/SEP/SEP_45_xcos_palette.odt differ
index ad40f42..774f30f 100644 (file)
@@ -35,9 +35,12 @@ XCOS_C_SOURCES =
 XCOS_CPP_SOURCES =     src/cpp/callxcos.cpp \
                        src/jni/Xcos.cpp \
                        src/jni/Xcos.hxx \
+                       src/jni/Palette.cpp \
+                       src/jni/Palette.hxx \
                        src/jni/GiwsException.cpp
 
-GIWS_WRAPPERS = src/jni/Xcos.giws.xml
+GIWS_WRAPPERS = src/jni/Xcos.giws.xml \
+                       src/jni/Palette.giws.xml
 
 if GIWS
 BUILT_SOURCES=giws
@@ -52,7 +55,15 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
        sci_gateway/cpp/sci_xcosDiagramToHDF5.cpp \
        sci_gateway/cpp/sci_xcosDiagramOpen.cpp \
-       sci_gateway/cpp/sci_xcosDiagramClose.cpp
+       sci_gateway/cpp/sci_xcosDiagramClose.cpp \
+       sci_gateway/cpp/xcosUtilities.cpp \
+       sci_gateway/cpp/sci_xcosPalLoad.cpp \
+       sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
+       sci_gateway/cpp/sci_xcosPalDelete.cpp \
+       sci_gateway/cpp/sci_xcosPalMove.cpp \
+       sci_gateway/cpp/sci_xcosPalEnable.cpp \
+       sci_gateway/cpp/sci_xcosPalDisable.cpp \
+       sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp
 
 libscixcos_la_CFLAGS= $(JAVA_JNI_INCLUDE) \
                        -I$(top_srcdir)/libs/MALLOC/includes/ \
@@ -111,7 +122,7 @@ libscixcos_la_sci_gateway_DATA = sci_gateway/xcos_gateway.xml
 #### xcos : images files ####
 #
 # Generated with:
-#   $ find images/ -type f -printf "%p \\ \n" -name *.svg -or -name *.gif -or -name *.jpg -or -name *.png -not -name *_pal.jpg -not -name gui |sort |awk '{sub(/[ \t]+$/, "")};1' |awk '$0 !~ /gui/{print;}' |awk '$0 !~ /_pal.jpg/ {print;}'
+#   $ find images/ -type f -printf "%p \\ \n" -name *.svg -or -name *.gif -or -name *.jpg -or -name *.png -not -name *_pal.jpg -not -name gui |sort |awk '{sub(/[ \t]+$/, "")};1' |awk '$0 !~ /gui/{print;}' |awk '$0 !~ /_pal.jpg/{print;}'
 libscixcos_la_imagesdir=$(mydatadir)/
 nobase_libscixcos_la_images_DATA = images/blocks/3DSCOPE.svg \
 images/blocks/ANDBLK.svg \
index 30275c4..dfaf75f 100644 (file)
@@ -138,9 +138,17 @@ am__objects_4 = libscixcos_la-sci_Xcos.lo \
        libscixcos_la-sci_closeXcosFromScilab.lo \
        libscixcos_la-sci_xcosDiagramToHDF5.lo \
        libscixcos_la-sci_xcosDiagramOpen.lo \
-       libscixcos_la-sci_xcosDiagramClose.lo
+       libscixcos_la-sci_xcosDiagramClose.lo \
+       libscixcos_la-xcosUtilities.lo \
+       libscixcos_la-sci_xcosPalLoad.lo \
+       libscixcos_la-sci_xcosPalCategoryAdd.lo \
+       libscixcos_la-sci_xcosPalDelete.lo \
+       libscixcos_la-sci_xcosPalMove.lo \
+       libscixcos_la-sci_xcosPalEnable.lo \
+       libscixcos_la-sci_xcosPalDisable.lo \
+       libscixcos_la-sci_xcosPalGenerateIcon.lo
 am__objects_5 = libscixcos_la-callxcos.lo libscixcos_la-Xcos.lo \
-       libscixcos_la-GiwsException.lo
+       libscixcos_la-Palette.lo libscixcos_la-GiwsException.lo
 am_libscixcos_la_OBJECTS = $(am__objects_2) $(am__objects_3) \
        $(am__objects_4) $(am__objects_5)
 libscixcos_la_OBJECTS = $(am_libscixcos_la_OBJECTS)
@@ -446,9 +454,13 @@ XCOS_C_SOURCES =
 XCOS_CPP_SOURCES = src/cpp/callxcos.cpp \
                        src/jni/Xcos.cpp \
                        src/jni/Xcos.hxx \
+                       src/jni/Palette.cpp \
+                       src/jni/Palette.hxx \
                        src/jni/GiwsException.cpp
 
-GIWS_WRAPPERS = src/jni/Xcos.giws.xml
+GIWS_WRAPPERS = src/jni/Xcos.giws.xml \
+                       src/jni/Palette.giws.xml
+
 @GIWS_TRUE@BUILT_SOURCES = giws
 GATEWAY_C_SOURCES = sci_gateway/c/gw_xcos.c
 GATEWAY_CPP_SOURCES = \
@@ -457,7 +469,15 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
        sci_gateway/cpp/sci_xcosDiagramToHDF5.cpp \
        sci_gateway/cpp/sci_xcosDiagramOpen.cpp \
-       sci_gateway/cpp/sci_xcosDiagramClose.cpp
+       sci_gateway/cpp/sci_xcosDiagramClose.cpp \
+       sci_gateway/cpp/xcosUtilities.cpp \
+       sci_gateway/cpp/sci_xcosPalLoad.cpp \
+       sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
+       sci_gateway/cpp/sci_xcosPalDelete.cpp \
+       sci_gateway/cpp/sci_xcosPalMove.cpp \
+       sci_gateway/cpp/sci_xcosPalEnable.cpp \
+       sci_gateway/cpp/sci_xcosPalDisable.cpp \
+       sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp
 
 libscixcos_la_CFLAGS = $(JAVA_JNI_INCLUDE) \
                        -I$(top_srcdir)/libs/MALLOC/includes/ \
@@ -919,6 +939,7 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_disable_la-noxcos.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-GiwsException.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-Palette.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-Xcos.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-callxcos.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-gw_xcos.Plo@am__quote@
@@ -928,6 +949,14 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosDiagramClose.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosDiagramOpen.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosDiagramToHDF5.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixcos_la-sci_xcosPalCategoryAdd.Plo@am__quote@
+@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_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__include@ @am__quote@./$(DEPDIR)/libscixcos_la-xcosUtilities.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -1027,6 +1056,62 @@ libscixcos_la-sci_xcosDiagramClose.lo: sci_gateway/cpp/sci_xcosDiagramClose.cpp
 @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_xcosDiagramClose.lo `test -f 'sci_gateway/cpp/sci_xcosDiagramClose.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosDiagramClose.cpp
 
+libscixcos_la-xcosUtilities.lo: sci_gateway/cpp/xcosUtilities.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-xcosUtilities.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-xcosUtilities.Tpo -c -o libscixcos_la-xcosUtilities.lo `test -f 'sci_gateway/cpp/xcosUtilities.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/xcosUtilities.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-xcosUtilities.Tpo $(DEPDIR)/libscixcos_la-xcosUtilities.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/xcosUtilities.cpp' object='libscixcos_la-xcosUtilities.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-xcosUtilities.lo `test -f 'sci_gateway/cpp/xcosUtilities.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/xcosUtilities.cpp
+
+libscixcos_la-sci_xcosPalLoad.lo: sci_gateway/cpp/sci_xcosPalLoad.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_xcosPalLoad.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Tpo -c -o 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__mv) $(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Tpo $(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xcosPalLoad.cpp' object='libscixcos_la-sci_xcosPalLoad.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_xcosPalLoad.lo `test -f 'sci_gateway/cpp/sci_xcosPalLoad.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalLoad.cpp
+
+libscixcos_la-sci_xcosPalCategoryAdd.lo: sci_gateway/cpp/sci_xcosPalCategoryAdd.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_xcosPalCategoryAdd.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-sci_xcosPalCategoryAdd.Tpo -c -o libscixcos_la-sci_xcosPalCategoryAdd.lo `test -f 'sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-sci_xcosPalCategoryAdd.Tpo $(DEPDIR)/libscixcos_la-sci_xcosPalCategoryAdd.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp' object='libscixcos_la-sci_xcosPalCategoryAdd.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_xcosPalCategoryAdd.lo `test -f 'sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp
+
+libscixcos_la-sci_xcosPalDelete.lo: sci_gateway/cpp/sci_xcosPalDelete.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_xcosPalDelete.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-sci_xcosPalDelete.Tpo -c -o libscixcos_la-sci_xcosPalDelete.lo `test -f 'sci_gateway/cpp/sci_xcosPalDelete.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalDelete.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-sci_xcosPalDelete.Tpo $(DEPDIR)/libscixcos_la-sci_xcosPalDelete.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xcosPalDelete.cpp' object='libscixcos_la-sci_xcosPalDelete.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_xcosPalDelete.lo `test -f 'sci_gateway/cpp/sci_xcosPalDelete.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalDelete.cpp
+
+libscixcos_la-sci_xcosPalMove.lo: sci_gateway/cpp/sci_xcosPalMove.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_xcosPalMove.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-sci_xcosPalMove.Tpo -c -o libscixcos_la-sci_xcosPalMove.lo `test -f 'sci_gateway/cpp/sci_xcosPalMove.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalMove.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-sci_xcosPalMove.Tpo $(DEPDIR)/libscixcos_la-sci_xcosPalMove.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xcosPalMove.cpp' object='libscixcos_la-sci_xcosPalMove.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_xcosPalMove.lo `test -f 'sci_gateway/cpp/sci_xcosPalMove.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalMove.cpp
+
+libscixcos_la-sci_xcosPalEnable.lo: sci_gateway/cpp/sci_xcosPalEnable.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_xcosPalEnable.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-sci_xcosPalEnable.Tpo -c -o libscixcos_la-sci_xcosPalEnable.lo `test -f 'sci_gateway/cpp/sci_xcosPalEnable.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalEnable.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-sci_xcosPalEnable.Tpo $(DEPDIR)/libscixcos_la-sci_xcosPalEnable.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xcosPalEnable.cpp' object='libscixcos_la-sci_xcosPalEnable.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_xcosPalEnable.lo `test -f 'sci_gateway/cpp/sci_xcosPalEnable.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalEnable.cpp
+
+libscixcos_la-sci_xcosPalDisable.lo: sci_gateway/cpp/sci_xcosPalDisable.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_xcosPalDisable.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-sci_xcosPalDisable.Tpo -c -o libscixcos_la-sci_xcosPalDisable.lo `test -f 'sci_gateway/cpp/sci_xcosPalDisable.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalDisable.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-sci_xcosPalDisable.Tpo $(DEPDIR)/libscixcos_la-sci_xcosPalDisable.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xcosPalDisable.cpp' object='libscixcos_la-sci_xcosPalDisable.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_xcosPalDisable.lo `test -f 'sci_gateway/cpp/sci_xcosPalDisable.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalDisable.cpp
+
+libscixcos_la-sci_xcosPalGenerateIcon.lo: sci_gateway/cpp/sci_xcosPalGenerateIcon.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_xcosPalGenerateIcon.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-sci_xcosPalGenerateIcon.Tpo -c -o libscixcos_la-sci_xcosPalGenerateIcon.lo `test -f 'sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-sci_xcosPalGenerateIcon.Tpo $(DEPDIR)/libscixcos_la-sci_xcosPalGenerateIcon.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp' object='libscixcos_la-sci_xcosPalGenerateIcon.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_xcosPalGenerateIcon.lo `test -f 'sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp
+
 libscixcos_la-callxcos.lo: src/cpp/callxcos.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-callxcos.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-callxcos.Tpo -c -o libscixcos_la-callxcos.lo `test -f 'src/cpp/callxcos.cpp' || echo '$(srcdir)/'`src/cpp/callxcos.cpp
 @am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-callxcos.Tpo $(DEPDIR)/libscixcos_la-callxcos.Plo
@@ -1041,6 +1126,13 @@ libscixcos_la-Xcos.lo: src/jni/Xcos.cpp
 @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-Xcos.lo `test -f 'src/jni/Xcos.cpp' || echo '$(srcdir)/'`src/jni/Xcos.cpp
 
+libscixcos_la-Palette.lo: src/jni/Palette.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-Palette.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-Palette.Tpo -c -o libscixcos_la-Palette.lo `test -f 'src/jni/Palette.cpp' || echo '$(srcdir)/'`src/jni/Palette.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-Palette.Tpo $(DEPDIR)/libscixcos_la-Palette.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='src/jni/Palette.cpp' object='libscixcos_la-Palette.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-Palette.lo `test -f 'src/jni/Palette.cpp' || echo '$(srcdir)/'`src/jni/Palette.cpp
+
 libscixcos_la-GiwsException.lo: src/jni/GiwsException.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-GiwsException.lo -MD -MP -MF $(DEPDIR)/libscixcos_la-GiwsException.Tpo -c -o libscixcos_la-GiwsException.lo `test -f 'src/jni/GiwsException.cpp' || echo '$(srcdir)/'`src/jni/GiwsException.cpp
 @am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixcos_la-GiwsException.Tpo $(DEPDIR)/libscixcos_la-GiwsException.Plo
index b3a58be..598de7f 100644 (file)
@@ -1,6 +1,7 @@
 /*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2009 - DIGITEO - Allan CORNET
+* Copyright (C) DIGITEO - 2009-2010 - Allan CORNET
+* Copyright (C) DIGITEO - 2010-2010 - 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
@@ -23,6 +24,13 @@ XCOS_IMPEXP int sci_closeXcosFromScilab(char* fname, unsigned long l);
 XCOS_IMPEXP int sci_xcosDiagramToHDF5(char* fname, unsigned long l);
 XCOS_IMPEXP int sci_xcosDiagramOpen(char* fname, unsigned long l);
 XCOS_IMPEXP int sci_xcosDiagramClose(char* fname, unsigned long l);
+XCOS_IMPEXP int sci_xcosPalLoad(char* fname, unsigned long l);
+XCOS_IMPEXP int sci_xcosPalCategoryAdd(char* fname, unsigned long l);
+XCOS_IMPEXP int sci_xcosPalDelete(char* fname, unsigned long l);
+XCOS_IMPEXP int sci_xcosPalMove(char* fname, unsigned long l);
+XCOS_IMPEXP int sci_xcosPalEnable(char* fname, unsigned long l);
+XCOS_IMPEXP int sci_xcosPalDisable(char* fname, unsigned long l);
+XCOS_IMPEXP int sci_xcosPalGenerateIcon(char* fname, unsigned long l);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_XCOS__ */
 /*--------------------------------------------------------------------------*/
index 9838ade..01854a6 100644 (file)
@@ -102,8 +102,10 @@ function status = generateBlockImage(block, path, file, handle, imageType)
     
     if imageType == "svg" then
         xs2svg(handle.figure_id, outFile);
+        disp(outFile);
     elseif imageType == "gif" then
         xs2gif(handle.figure_id, outFile);
+        disp(outFile);
     end
     
     // post operations
index 705c677..10a59cc 100644 (file)
@@ -99,8 +99,7 @@ function generateBlockImages(palFiles, iconsOutPath, imagesOutPath, traceEnable)
             mprintf("%d: %s",  kBlock, varsToLoad(kBlock));
         end
         if ierr == 0 then
-            status = generateBlockImage(scs_m, iconsOutPath, handle=f, imageType="gif");
-            status = status & generateBlockImage(scs_m, imagesOutPath, handle=f, imageType="svg");
+            status = generateBlockImage(scs_m, imagesOutPath, handle=f, imageType="svg");
             if status & traceEnable then
                 mprintf(" SUCCEED\n");
             elseif traceEnable then
diff --git a/scilab/modules/xcos/macros/xcosPal.sci b/scilab/modules/xcos/macros/xcosPal.sci
new file mode 100644 (file)
index 0000000..c2afbcd
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) DIGITEO - 2010-2010 - 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-en.txt
+//
+//
+
+// Create a new palette
+// 
+// @param[opt] name the palette name
+// @param[opt] scs_m the source scicos palette to import
+// @return pal the palette instance.
+function pal = xcosPal(name, scs_m)
+    [lhs,rhs] = argn(0);
+    
+    if rhs > 2 then
+        error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "xcosPal", 0, 2));
+    end
+    
+    if exists("name", 'l') == 0 then
+        name = "New palette";
+    elseif typeof(name) == "diagram" then
+        scs_m = name;
+        name = "New palette";
+    end
+    // loading the scicos_diagram macro
+    if exists("scicos_diagram", 'a') == 0 then loadScicosLibs(), end
+    if exists("scs_m", 'l') == 0 then scs_m = scicos_diagram(), end
+    
+    if typeof(name) <> "string" then
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": string type expected.\n"), "xcosPal","name"));
+    end
+    
+    if typeof(scs_m) <> "diagram" then
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": diagram type expected.\n"), "xcosPal","scs_m"));
+    end
+    
+    // default instance
+    pal = tlist(["palette", "name", "blockNames",  "blocks", "icons", "style"],..
+                            [],     [],            [],       [],      []);
+                            
+    // find palette name
+    if ~isempty(scs_m.objs) then
+        name = scs_m.props.title(1);
+    end
+    
+    // getting a block name list
+    varsToLoad = [];
+    for block = scs_m.objs
+        if typeof(block)=="Block" & block.gui == "PAL_f" then
+            // customize palette name
+            name = block.model.rpar.props.title;
+            
+            // Add PAL_f children blocks
+            children = block.model.rpar.objs;
+            for jBlock = 1:size(children)
+                varsToLoad($+1) = children(jBlock).gui;
+            end
+        elseif typeof(block)=="Block" then
+            // old scicos palettes doesn't have a PAL_f block but directly
+            // the reference instances instead.
+            varsToLoad($+1) = block.gui
+        end
+    end
+    
+    // set name
+    pal.name = name;
+    
+    // add block instance by interfunction (will generate a new reference instance).
+    for index = 1:size(varsToLoad, '*')
+        pal = xcosPalAddBlock(pal, varsToLoad(index));
+    end
+endfunction
+
diff --git a/scilab/modules/xcos/macros/xcosPalAdd.sci b/scilab/modules/xcos/macros/xcosPalAdd.sci
new file mode 100644 (file)
index 0000000..3d37c30
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) DIGITEO - 2010-2010 - 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-en.txt
+//
+//
+
+// Add a palette to the palette manager as a child of the category name.
+//
+// @param pal the current palette
+// @param[opt] the category name
+// @return status %T if the operation is successful, %F otherwise.
+// @return[opt] msg Contains the error message in case of %F status or an empty 
+//              string when no error as occurred.
+function [status, msg] = xcosPalAdd(pal, category)
+    status = %F;
+    msg = "";
+
+    // Checking arguments
+    [lhs,rhs] = argn(0)
+    if rhs < 1 | rhs > 2 then
+        error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "xcosPalAdd", 1, 2));
+    end
+    
+    if lhs > 3 then
+        error(msprintf(gettext("%s: Wrong number of output arguments: %d to %d expected.\n"), "xcosPalAdd", 1, 2));
+    end
+    
+    if typeof(pal) <> "palette" & typeof(pal) <> "string" then
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": palette type or path expected.\n"), "xcosPalAdd", "pal"));
+    end
+    
+    if typeof(pal) == "string" & ~isfile(pal) then
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": File not found.\n"), "xcosPalAdd", "pal"));
+    end
+    
+    if exists("category", 'l') == 0 then category="", end
+    
+    if typeof(category) <> "string" & or(size(category) == [1 1]) then
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": string vector expected.\n"), "xcosPalAdd", "pal"));
+    end
+    
+    if typeof(pal) == "palette" then
+        myPalette = pal;
+        pal = TMPDIR + "palette.h5";
+        [status, msg] = xcosPalExport(myPalette, pal);
+        if ~status then
+            return;
+        end
+    end
+    
+    // call the gateway with a full path string and the category as
+    // a string vector
+    xcosPalLoad(pal, category);
+endfunction
+
diff --git a/scilab/modules/xcos/macros/xcosPalAddBlock.sci b/scilab/modules/xcos/macros/xcosPalAddBlock.sci
new file mode 100644 (file)
index 0000000..a13ad56
--- /dev/null
@@ -0,0 +1,133 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) DIGITEO - 2010-2010 - 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-en.txt
+//
+//
+
+// Add a block to a palette instance.
+//
+// @param pal the "Palette" instance
+// @param block the block to add
+// @param[opt] pal_block_img full path to the block image used in the palette.
+// @param[opt] style full path to the block image used in the diagram or block style (jgraphx format)
+// @return pal the modified pal instance
+function pal = xcosPalAddBlock(pal, block, pal_block_img, style)
+
+    // Checking arguments
+    [lhs,rhs] = argn(0)
+    if rhs < 2 | rhs > 5 then
+        error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "xcosPalAddBlock", 2, 5));
+    end
+    
+    if lhs > 1 then
+        error(msprintf(gettext("%s: Wrong number of output arguments: %d expected.\n"), "xcosPalAddBlock", 1));
+    end
+    
+    if typeof(pal) <> "palette" then
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": palette type expected.\n"), "xcosPalAddBlock", "pal"));
+    end
+    
+    // check and tranform block argument
+    
+    if typeof(block) == "Block" then
+        path = TMPDIR + "/" + block.gui + ".h5";
+        scs_m = block;
+        err = export_to_hdf5(path, "scs_m");
+        if err <> %T then
+            error(msprintf(gettext("%s: Unable to export ""%s"" to ""%s"".\n"), "xcosPalAddBlock", "block", path));
+        end
+        
+        block = path; // block mute to a full path string.
+    end
+    
+    if typeof(block) == "string" then
+        if exists(block) <> 0 & typeof(evstr(block)) == "function" then
+            execstr("scs_m = " + block + "(""define"");");
+            path = TMPDIR + "/" + block + ".h5";
+            err = export_to_hdf5(path, "scs_m");
+            if err <> %T then
+                error(msprintf(gettext("%s: Unable to export ""%s"" to ""%s"".\n"), "xcosPalAddBlock", "block", path));
+            end
+            
+            block = path; // block mute to a full path string.
+        else // assume this is a path
+            fd = mopen(block, "rb");
+            [err, msg] = merror(fd);
+            if err <> 0 then
+                error(msg);
+            end
+            block = fullpath(block);
+            mclose(fd);
+            
+            // store the block instance if not already saved
+            if exists("scs_m", 'l') == 0 then
+               status = import_from_hdf5(block);
+               if ~status then
+                       error(msprintf(gettext("%s: Unable to load block from ""%s"": hdf5 file expected.\n"), "xcosPalAddBlock", block));
+               end
+               
+               if exists("scs_m", 'l') == 0 then
+                       error(msprintf(gettext("%s: Unable to load block from ""%s"": no `scs_m'' variable found.\n"), "xcosPalAddBlock", block));
+               end
+            end
+        end
+    else
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": function as string or Block type or full path string expected.\n"), "xcosPalAddBlock", "block"));
+    end
+    
+    // at this point we can assert that `block' is a full path string to a 
+    // saved block reference instance (hdf5 format) also kept into 
+    // `scs_m'.
+    // now handle pal_block_img and style arguments
+    
+    if exists("pal_block_img", 'l') == 0 then
+        pal_block_img = TMPDIR + "/" + scs_m.gui + ".gif";
+        if isfile(pal_block_img) then
+            error(msprintf(gettext("%s: Unable to generate the palette icon : ""%s"" already exists.\n"), "xcosPalAddBlock", pal_block_img));
+        end
+    else
+        if typeof(pal_block_img) <> "string" | ~isfile(pal_block_img) then
+            error(msprintf(gettext("%s: Wrong type for input argument ""%s"": path string expected.\n"), "xcosPalAddBlock", "pal_block_img"));
+        end
+        pal_block_img = fullpath(pal_block_img);
+    end
+    
+    if exists("style", 'l') == 0 then
+        block_img = TMPDIR + "/" + scs_m.gui + ".svg";
+        style = "image=" + block_img + ";";
+        status = generateBlockImage(scs_m, TMPDIR, imageType="svg");
+        if ~status then
+               error(msprintf(gettext("%s: Unable to generate the image ""%s"".\n"), "xcosPalAddBlock", block_img));
+        end
+    else
+        if typeof(style) <> "string" & typeof(style) <> "struct" then
+            error(msprintf(gettext("%s: Wrong type for input argument ""%s"": string or struct expected.\n"), "xcosPalAddBlock", "style"));
+        elseif typeof(style) <> "struct" then
+            formattedStyle = "";
+               fields = fieldnames(style);
+               for field = fields
+                   formattedStyle = field + "=" + getfield(field, style) + ";";
+               end
+               style = formattedStyle;
+        elseif typeof(style) == "string" & isfile(style) then
+            style = "image=" + style + ";";
+        elseif typeof(style) == "string" then
+            // assume well formatted string, do nothing
+        else
+               style = "";
+        end
+    end
+    
+    // Store the data into the palette structure
+    pal.blockNames($+1) = scs_m.gui // block named class
+    pal.blocks($+1) = block; // reference instance full path string
+    pal.icons($+1) = pal_block_img; // palette icon full path string
+    pal.style($+1) = style; // block style (linked to style definition)
+endfunction
+
diff --git a/scilab/modules/xcos/macros/xcosPalExport.sci b/scilab/modules/xcos/macros/xcosPalExport.sci
new file mode 100644 (file)
index 0000000..78205ee
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) DIGITEO - 2010-2010 - 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-en.txt
+//
+//
+
+// Export a palette instance to an hdf5 file.
+//
+// @param pal the "palette" type
+// @param path Fullpath to the hdf5 file (.h5)
+// @return status %T if the export has been successful, %F otherwise
+// @return[opt] msg Contains the error message in case of %F status or an empty
+//                  string when no error as occurred.
+function [status, msg] = xcosPalExport(pal, path)
+    status = %F;
+    msg = "";
+    
+    // Checking arguments
+    [lhs,rhs] = argn(0)
+    if rhs <> 2 then
+        error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "xcosPalExport", 2));
+    end
+    
+    if lhs > 2 then
+        error(msprintf(gettext("%s: Wrong number of output arguments: %d to %d expected.\n"), "xcosPalExport", 1, 2));
+    end
+    
+    if typeof(pal) <> "palette" then
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": palette type expected.\n"), "xcosPalExport", "pal"));
+    end
+    
+    if typeof(path) <> "string" then
+        error(msprintf(gettext("%s: Wrong type for input argument ""%s"": full path string expected.\n"), "xcosPalExport", "path"));
+    end
+    fd = mopen(path, "wb");
+    [err, msg] = merror(fd);
+    if err <> 0 then
+        mclose(fd);
+        error(msg);
+    end
+    
+    path = fullpath(path);
+    mclose(fd);
+    
+    // export the data to the temp file
+    pal = pal; // #7242 workaround
+    status = export_to_hdf5(path, "pal");
+    if ~status then
+        msg = msprintf(gettext("%s: Unable to export the palette to hdf5.\n"), "xcosPalExport");
+        if  lhs == 1 then
+            error(msg);
+        end
+    end
+endfunction
+
index fe787d6..625b122 100644 (file)
 static BOOL loadedDep = FALSE;
 /*--------------------------------------------------------------------------*/
 static gw_generic_table Tab[] = {
-  {sci_Xcos, "xcos"},
-  {sci_warnBlockByUID, "warnBlockByUID"},
-  {sci_closeXcosFromScilab, "closeXcos"},
-  {sci_xcosDiagramToHDF5, "xcosDiagramToHDF5"},
-  {sci_xcosDiagramOpen, "xcosDiagramOpen"},
-  {sci_xcosDiagramClose, "xcosDiagramClose"}
+  {sci_Xcos,                            "xcos"},
+  {sci_warnBlockByUID,                  "warnBlockByUID"},
+  {sci_closeXcosFromScilab,             "closeXcos"},
+  {sci_xcosDiagramToHDF5,               "xcosDiagramToHDF5"},
+  {sci_xcosDiagramOpen,                 "xcosDiagramOpen"},
+  {sci_xcosDiagramClose,                "xcosDiagramClose"},
+  {sci_xcosPalLoad,                     "xcosPalLoad"},
+  {sci_xcosPalCategoryAdd,              "xcosPalCategoryAdd"},
+  {sci_xcosPalDelete,                   "xcosPalDelete"},
+  {sci_xcosPalMove,                     "xcosPalMove"},
+  {sci_xcosPalEnable,                   "xcosPalEnable"},
+  {sci_xcosPalDisable,                  "xcosPalDisable"},
+  {sci_xcosPalGenerateIcon,             "xcosPalGenerateIcon"}
 };
 
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp
new file mode 100644 (file)
index 0000000..f1675cb
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "stack-c.h"
+#include "callxcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "freeArrayOfString.h"
+#include "getScilabJavaVM.h"
+}
+
+extern int
+readVectorString(int rhsPosition, char*** out, int* vectorLength, char* fname);
+extern int
+readSingleBoolean(int rhsPosition, bool* out, const char* fname);
+
+using namespace org_scilab_modules_xcos_palette;
+
+int
+sci_xcosPalCategoryAdd(char *fname, unsigned long fname_len)
+{
+    CheckRhs(1, 2);
+    CheckLhs(1, 1);
+
+    SciErr sciErr;
+
+    char** name;
+    int nameLength;
+    bool visible;
+
+    /* name setup */
+    if (readVectorString(1, &name, &nameLength, fname))
+    {
+        return 0;
+    }
+
+    /* visible setup */
+    if (Rhs > 2)
+    {
+        if (readSingleBoolean(2, &visible, fname))
+        {
+            return 0;
+        }
+    }
+    else
+    {
+        visible = true;
+    }
+
+    /* Call the java implementation */
+    try
+    {
+        Palette::addCategory(getScilabJavaVM(), name, nameLength,
+                visible);
+    }
+    catch (GiwsException::JniCallMethodException& exception)
+    {
+        Scierror(999, "%s: %s", fname, exception.getJavaDescription().c_str());
+        return 0;
+    }
+
+    LhsVar(1) = 1;
+    PutLhsVar();
+    return 0;
+}
+
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalDelete.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalDelete.cpp
new file mode 100644 (file)
index 0000000..bace932
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "stack-c.h"
+#include "callxcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "getScilabJavaVM.h"
+}
+
+extern int
+readVectorString(int rhsPosition, char*** out, int* vectorLength, char* fname);
+
+using namespace org_scilab_modules_xcos_palette;
+
+int
+sci_xcosPalDelete(char *fname, unsigned long fname_len)
+{
+    CheckRhs(1, 1);
+    CheckLhs(1, 1);
+
+    SciErr sciErr;
+
+    char** name;
+    int nameLength;
+
+    /* name setup */
+    if (readVectorString(1, &name, &nameLength, fname))
+    {
+        return 0;
+    }
+
+    /* Call the java implementation */
+    try
+    {
+        Palette::remove(getScilabJavaVM(), name, nameLength);
+    }
+    catch (GiwsException::JniCallMethodException& exception)
+    {
+        Scierror(999, "%s: %s", fname, exception.getJavaDescription().c_str());
+        return 0;
+    }
+
+    LhsVar(1) = 1;
+    PutLhsVar();
+    return 0;
+}
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalDisable.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalDisable.cpp
new file mode 100644 (file)
index 0000000..951e647
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "stack-c.h"
+#include "callxcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "getScilabJavaVM.h"
+}
+
+extern int
+readVectorString(int rhsPosition, char*** out, int* vectorLength, char* fname);
+
+using namespace org_scilab_modules_xcos_palette;
+
+int
+sci_xcosPalDisable(char *fname, unsigned long fname_len)
+{
+    CheckRhs(1, 1);
+    CheckLhs(1, 1);
+
+    SciErr sciErr;
+
+    char** name;
+    int nameLength;
+
+    /* name setup */
+    if (readVectorString(1, &name, &nameLength, fname))
+    {
+        return 0;
+    }
+
+    /* Call the java implementation */
+    try
+    {
+        Palette::enable(getScilabJavaVM(), name, nameLength, false);
+    }
+    catch (GiwsException::JniCallMethodException& exception)
+    {
+        Scierror(999, "%s: %s", fname, exception.getJavaDescription().c_str());
+        return 0;
+    }
+
+    LhsVar(1) = 1;
+    PutLhsVar();
+    return 0;
+}
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalEnable.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalEnable.cpp
new file mode 100644 (file)
index 0000000..305ad17
--- /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"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "stack-c.h"
+#include "callxcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "freeArrayOfString.h"
+#include "getScilabJavaVM.h"
+}
+
+extern int
+readVectorString(int rhsPosition, char*** out, int* vectorLength, char* fname);
+
+using namespace org_scilab_modules_xcos_palette;
+
+int
+sci_xcosPalEnable(char *fname, unsigned long fname_len)
+{
+    CheckRhs(1, 1);
+    CheckLhs(1, 1);
+
+    SciErr sciErr;
+
+    char** name;
+    int nameLength;
+
+    /* name setup */
+    if (readVectorString(1, &name, &nameLength, fname))
+    {
+        return 0;
+    }
+
+    /* Call the java implementation */
+    try
+    {
+        Palette::enable(getScilabJavaVM(), name, nameLength, true);
+    }
+    catch (GiwsException::JniCallMethodException& exception)
+    {
+        Scierror(999, "%s: %s", fname, exception.getJavaDescription().c_str());
+        return 0;
+    }
+
+    LhsVar(1) = 1;
+    PutLhsVar();
+    return 0;
+}
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalGenerateIcon.cpp
new file mode 100644 (file)
index 0000000..508a580
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "stack-c.h"
+#include "callxcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "getScilabJavaVM.h"
+}
+
+extern int readSingleString(int rhsPosition, char** out, const char* fname);
+
+using namespace org_scilab_modules_xcos_palette;
+
+int
+sci_xcosPalGenerateIcon(char *fname, unsigned long fname_len)
+{
+    CheckRhs(2, 2);
+    CheckLhs(0, 1);
+
+    SciErr sciErr;
+
+    char* blockPath = NULL;
+    
+    char* iconPath = NULL;
+
+    /* blockPath setup */
+    if(readSingleString(1, &blockPath, fname))
+    {
+        return 0;
+    }
+
+    /* iconPath setup */
+    if(readSingleString(2, &iconPath, fname))
+    {
+        FREE(blockPath);
+        return 0;
+    }
+
+    /* Call the java implementation */
+    try
+    {
+        Palette::generatePaletteIcon(getScilabJavaVM(), blockPath, iconPath);
+    }
+    catch (GiwsException::JniCallMethodException& exception)
+    {
+        Scierror(999, "%s : %s", fname, exception.getJavaDescription().c_str());
+        return 0;
+    }
+
+    LhsVar(1) = 0;
+    PutLhsVar();
+    return 0;
+}
+
+
+
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalLoad.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalLoad.cpp
new file mode 100644 (file)
index 0000000..7c3d37f
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "stack-c.h"
+#include "callxcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "getScilabJavaVM.h"
+}
+
+extern int readSingleString(int rhsPosition, char** out, const char* fname);
+extern int readVectorString(int rhsPosition, char*** out, int* vectorLength, char* fname);
+
+using namespace org_scilab_modules_xcos_palette;
+
+int
+sci_xcosPalLoad(char *fname, unsigned long fname_len)
+{
+    CheckRhs(2, 2);
+    CheckLhs(0, 1);
+
+    SciErr sciErr;
+
+    char* path = NULL;
+    
+    int lenCategory = 0;
+    char** category = NULL;
+
+    /* path setup */
+    if(readSingleString(1, &path, fname))
+    {
+        return 0;
+    }
+
+    /* category setup */
+    if(readVectorString(2, &category, &lenCategory, fname))
+    {
+        FREE(path);
+        return 0;
+    }
+
+    /* Call the java implementation */
+    try
+    {
+        Palette::loadPal(getScilabJavaVM(), path, category, lenCategory);
+    }
+    catch (GiwsException::JniCallMethodException& exception)
+    {
+        Scierror(999, "%s: %s", fname, exception.getJavaDescription().c_str());
+        return 0;
+    }
+
+    LhsVar(1) = 0;
+    PutLhsVar();
+    return 0;
+}
+
+
+
diff --git a/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalMove.cpp b/scilab/modules/xcos/sci_gateway/cpp/sci_xcosPalMove.cpp
new file mode 100644 (file)
index 0000000..a8d6715
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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"
+
+extern "C"
+{
+#include "gw_xcos.h"
+#include "stack-c.h"
+#include "callxcos.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+#include "getScilabJavaVM.h"
+}
+
+extern int
+readVectorString(int rhsPosition, char*** out, int* vectorLength, char* fname);
+
+using namespace org_scilab_modules_xcos_palette;
+
+int
+sci_xcosPalMove(char *fname, unsigned long fname_len)
+{
+    CheckRhs(1, 1);
+    CheckLhs(1, 1);
+
+    SciErr sciErr;
+
+    char** source;
+    int sourceLength;
+
+    char** target;
+    int targetLength;
+
+    /* source setup */
+    if (readVectorString(1, &source, &sourceLength, fname))
+    {
+        return 0;
+    }
+
+    /* target setup */
+    if (readVectorString(2, &target, &targetLength, fname))
+    {
+        return 0;
+    }
+
+    /* Call the java implementation */
+    try
+    {
+        Palette::move(getScilabJavaVM(), source, sourceLength, target,
+                targetLength);
+    }
+    catch (GiwsException::JniCallMethodException& exception)
+    {
+        Scierror(999, "%s: %s", fname, exception.getJavaDescription().c_str());
+        return 0;
+    }
+
+    LhsVar(1) = 1;
+    PutLhsVar();
+    return 0;
+}
diff --git a/scilab/modules/xcos/sci_gateway/cpp/xcosUtilities.cpp b/scilab/modules/xcos/sci_gateway/cpp/xcosUtilities.cpp
new file mode 100644 (file)
index 0000000..f68a4a4
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+ * 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
+ *
+ */
+
+extern "C"
+{
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "MALLOC.h"
+}
+
+/**
+ * Read a single boolean on the stack.
+ *
+ * @param rhsPosition the position on the stack.
+ * @param[out] out the read value.
+ * @param fname the function name used for the call.
+ * @return status of the operation (<> 0 on error)
+ */
+int readSingleBoolean(int rhsPosition, bool* out, const char* fname)
+{
+    int* argumentPointer = NULL;
+    int rowsArgument = 0;
+    int colsArgument = 0;
+    int* value = NULL;
+
+    *out = false;
+    SciErr sciErr;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, rhsPosition, &argumentPointer);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    sciErr = getMatrixOfBoolean(pvApiCtx, argumentPointer,
+            &rowsArgument, &colsArgument, NULL);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    if (rowsArgument != 1 || colsArgument != 1)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, rhsPosition);
+        return -1;
+    }
+
+    sciErr = getMatrixOfBoolean(pvApiCtx, argumentPointer,
+            &rowsArgument, &colsArgument, &value);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    *out = (*value == 0);
+    return 0;
+}
+
+/**
+ * Read a single string on the stack.
+ *
+ * @param rhsPosition the position on the stack.
+ * @param[out] out the read value.
+ * @param fname the function name used for the call.
+ * @return status of the operation (<> 0 on error)
+ */
+int readSingleString(int rhsPosition, char** out, const char* fname)
+{
+    int* argumentPointer = NULL;
+    int rowsArgument = 0;
+    int colsArgument = 0;
+    int lenArgument = 0;
+    char* value = NULL;
+
+    *out = NULL;
+    SciErr sciErr;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, rhsPosition, &argumentPointer);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    sciErr = getMatrixOfString(pvApiCtx, argumentPointer, &rowsArgument,
+            &colsArgument, NULL, NULL);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    if (rowsArgument != 1 || colsArgument != 1)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, rhsPosition);
+        return -1;
+    }
+
+    sciErr = getMatrixOfString(pvApiCtx, argumentPointer, &rowsArgument,
+            &colsArgument, &lenArgument, NULL);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    value = (char*) MALLOC(sizeof(char) * (lenArgument + 1)); //+ 1 for null termination
+    value[lenArgument] = '\0';
+    sciErr = getMatrixOfString(pvApiCtx, argumentPointer, &rowsArgument,
+            &colsArgument, &lenArgument, &value);
+    if (sciErr.iErr)
+    {
+        FREE(value);
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    *out = value;
+    return 0;
+}
+
+/**
+ * Read a single string on the stack.
+ *
+ * @param rhsPosition the position on the stack.
+ * @param[out] out the read value.
+ * @param[out] vectorLength the length of the vector.
+ * @param fname the function name used for the call.
+ * @return status of the operation (<> 0 on error)
+ */
+int readVectorString(int rhsPosition, char*** out, int* vectorLength, char* fname)
+{
+    int* argumentPointer = NULL;
+    int rowsArgument = 0;
+    int colsArgument = 0;
+    int* lenArgument = 0;
+    char** value = NULL;
+
+    *out = NULL;
+    *vectorLength = 0;
+    SciErr sciErr;
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, rhsPosition, &argumentPointer);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    sciErr = getMatrixOfString(pvApiCtx, argumentPointer, &rowsArgument,
+            &colsArgument, NULL, NULL);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    if (rowsArgument != 1 && colsArgument != 1)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: A string vector expected.\n"), fname, rhsPosition);
+        return -1;
+    }
+
+    lenArgument = (int*) MALLOC(sizeof(int) * rowsArgument * colsArgument);
+    sciErr = getMatrixOfString(pvApiCtx, argumentPointer, &rowsArgument,
+            &colsArgument, lenArgument, NULL);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    value = (char**) MALLOC(sizeof(char) * rowsArgument * colsArgument);
+    for (int i = 0; i < rowsArgument * colsArgument; ++i)
+    {
+        value[i] = (char*) MALLOC(sizeof(char) * (lenArgument[i] + 1)); // +1 for null termination
+        value[lenArgument[i]] = '\0';
+    }
+
+    sciErr = getMatrixOfString(pvApiCtx, argumentPointer, &rowsArgument,
+            &colsArgument, lenArgument, value);
+    if (sciErr.iErr)
+    {
+        FREE(lenArgument);
+        for (int i = 0; i < rowsArgument * colsArgument; ++i)
+        {
+            FREE(value[i]);
+        }
+        FREE(value);
+        printError(&sciErr, 0);
+        return -1;
+    }
+
+    *out = value;
+    *vectorLength = rowsArgument * colsArgument;
+    return 0;
+}
index ebfd4b6..6b8acb8 100644 (file)
 <PRIMITIVE gatewayId="64" primitiveId="4" primitiveName="xcosDiagramToHDF5" />
 <PRIMITIVE gatewayId="64" primitiveId="5" primitiveName="xcosDiagramOpen" />
 <PRIMITIVE gatewayId="64" primitiveId="6" primitiveName="xcosDiagramClose" />
+<PRIMITIVE gatewayId="64" primitiveId="7" primitiveName="xcosPalLoad" />
+<PRIMITIVE gatewayId="64" primitiveId="8" primitiveName="xcosPalCategoryAdd" />
+<PRIMITIVE gatewayId="64" primitiveId="9" primitiveName="xcosPalDelete" />
+<PRIMITIVE gatewayId="64" primitiveId="10" primitiveName="xcosPalMove" />
+<PRIMITIVE gatewayId="64" primitiveId="11" primitiveName="xcosPalEnable" />
+<PRIMITIVE gatewayId="64" primitiveId="12" primitiveName="xcosPalDisable" />
+<PRIMITIVE gatewayId="64" primitiveId="13" primitiveName="xcosPalGenerateIcon" />
 </GATEWAY>
index 5de82f6..2128e5a 100644 (file)
@@ -19,7 +19,7 @@ import java.util.List;
 /**
  * Default exception for a Xcos - Scicos communication
  */
-public abstract class ScicosFormatException extends Exception {
+public abstract class ScicosFormatException extends RuntimeException {
        /**
         * Used when the {@link Element} cannot be used to decode/encode the instance.
         */
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/Palette.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/Palette.java
new file mode 100644 (file)
index 0000000..6a1dc7a
--- /dev/null
@@ -0,0 +1,456 @@
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.xcos.palette;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.imageio.ImageIO;
+import javax.swing.SwingUtilities;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeNode;
+
+import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.scilab.modules.graph.utils.ScilabExported;
+import org.scilab.modules.hdf5.read.H5Read;
+import org.scilab.modules.jvm.utils.ScilabConstants;
+import org.scilab.modules.types.scilabTypes.ScilabTList;
+import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.io.scicos.H5RWHandler;
+import org.scilab.modules.xcos.palette.model.Category;
+import org.scilab.modules.xcos.palette.model.PaletteBlock;
+import org.scilab.modules.xcos.palette.model.PaletteNode;
+import org.scilab.modules.xcos.palette.model.PreLoaded;
+import org.scilab.modules.xcos.utils.BlockPositioning;
+import org.scilab.modules.xcos.utils.FileUtils;
+import org.scilab.modules.xcos.utils.XcosConstants;
+
+import com.mxgraph.io.mxCodec;
+import com.mxgraph.swing.mxGraphComponent;
+import com.mxgraph.util.mxCellRenderer;
+import com.mxgraph.util.mxRectangle;
+import com.mxgraph.util.mxUtils;
+import com.mxgraph.view.mxStylesheet;
+
+/**
+ * Utility class which is the entry point from Scilab for palette related
+ * functions.
+ */
+public final class Palette {
+       private static final String NAME = "name";
+       private static final String WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH = "Wrong input argument \"%s\": invalid tree path.\n";
+
+       private static final Log LOG = LogFactory.getLog(Palette.class);
+
+       /**
+        * Default hidden constructor
+        */
+       private Palette() {
+       }
+
+       /**
+        * Get the {@link PaletteNode} of the path.
+        * 
+        * @param path
+        *            the path
+        * @param create
+        *            if <code>true</code> the Category path will be created,
+        *            otherwise it will not.
+        * @return the selected node
+        */
+       private static PaletteNode getPathNode(final String[] path,
+                       final boolean create) {
+
+               if (!SwingUtilities.isEventDispatchThread()) {
+                       throw new RuntimeException(
+                                       "Unable to manipulate palette outside the EDT thread.");
+               }
+
+               Category node = PaletteManager.getInstance().getRoot();
+               for (int categoryCounter = 0; categoryCounter < path.length; categoryCounter++) {
+
+                       for (Iterator<PaletteNode> iter = node.getNode().iterator(); iter
+                                       .hasNext();) {
+                               PaletteNode next = iter.next();
+
+                               if (next.toString().equals(path[categoryCounter])
+                                               && next instanceof Category) {
+                                       node = (Category) next;
+                                       break;
+                               } else if (next.toString().equals(path[categoryCounter])
+                                               && (categoryCounter == path.length - 1)) {
+                                       return next; // found the terminal Palette instance
+                               }
+                       }
+
+                       if (!node.toString().equals(path[categoryCounter])) {
+                               if (create) {
+                                       Category cat = new Category();
+                                       cat.setName(path[categoryCounter]);
+                                       cat.setEnable(create);
+
+                                       cat.setParent(node);
+                                       node.getNode().add(cat);
+
+                                       node = cat;
+                               } else {
+                                       return null;
+                               }
+                       }
+               }
+               return node;
+       }
+
+       /**
+        * Load an xcos palette into the palette manager
+        * 
+        * @param path
+        *            full path to the scilab exported palette
+        * @param category
+        *            TreePath of the palette
+        * @throws Exception
+        *             in case of error
+        */
+       @ScilabExported(module = "xcos", filename = "Palette.giws.xml")
+       public static void loadPal(final String path, final String[] category)
+                       throws Exception {
+               /*
+                * Import the palette
+                */
+               final ScilabTList data = new ScilabTList();
+               final String file = new File(path).getAbsolutePath();
+               try {
+                       int fileId = H5Read.openFile(file);
+                       H5Read.readDataFromFile(fileId, data);
+                       H5Read.closeFile(fileId);
+               } catch (HDF5Exception e) {
+                       throw new Exception(String.format("Unable to import %s .\n", file),
+                                       e);
+               }
+
+               /*
+                * Decode the style part of the palette
+                */
+               mxStylesheet styleSheet = new mxStylesheet();
+               FileUtils.decodeStyle(styleSheet);
+               new StyleElement().decode(data, styleSheet);
+               mxUtils.writeFile(mxUtils.getXml(new mxCodec().encode(styleSheet)),
+                               ScilabConstants.SCIHOME.getAbsolutePath() + '/'
+                                               + FileUtils.STYLE_FILENAME);
+
+               /*
+                * Getting the node and create the path to it.
+                */
+               SwingUtilities.invokeAndWait(new Runnable() {
+                       @Override
+                       public void run() {
+                               PaletteNode node = getPathNode(category, true);
+                               if (!(node instanceof Category)) {
+                                       throw new RuntimeException(String.format(
+                                                       WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH,
+                                                       "category"));
+                               }
+                               Category cat = (Category) node;
+
+                               /*
+                                * Adding the palette tree part of the palette
+                                */
+                               cat.getNode().add(new PreLoadedElement().decode(data, null));
+
+                               PaletteManager.getInstance().saveConfig();
+                               if (PaletteManager.getInstance().getView() != null) {
+                                       final DefaultTreeModel model = (DefaultTreeModel) PaletteManager
+                                                       .getInstance().getView().getTree().getModel();
+                                       model.reload(cat);
+                               }
+                       }
+               });
+       }
+
+       /**
+        * Add a category into the palette manager
+        * 
+        * @param name
+        *            TreePath of the palette
+        * @param visible
+        *            default visibility of the palette
+        * @throws Exception
+        *             in case of error
+        */
+       @ScilabExported(module = "xcos", filename = "Palette.giws.xml")
+       public static void addCategory(final String[] name, final boolean visible)
+                       throws Exception {
+               SwingUtilities.invokeAndWait(new Runnable() {
+                       @Override
+                       public void run() {
+                               PaletteNode node = getPathNode(name, true);
+                               if (node instanceof Category) {
+                                       node.setEnable(visible);
+                               } else {
+                                       throw new RuntimeException(String.format(
+                                                       WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH, NAME));
+                               }
+
+                               PaletteManager.getInstance().saveConfig();
+                               if (PaletteManager.getInstance().getView() != null) {
+                                       final DefaultTreeModel model = (DefaultTreeModel) PaletteManager
+                                                       .getInstance().getView().getTree().getModel();
+                                       model.reload(node);
+                               }
+                       }
+               });
+       }
+
+       /**
+        * Remove a palette or a category of the palette manager
+        * 
+        * @param name
+        *            TreePath of the palette
+        * @throws Exception
+        *             in case of error
+        */
+       @ScilabExported(module = "xcos", filename = "Palette.giws.xml")
+       public static void remove(final String[] name) throws Exception {
+               SwingUtilities.invokeAndWait(new Runnable() {
+                       @Override
+                       public void run() {
+                               PaletteNode node = getPathNode(name, false);
+                               if (node == null) {
+                                       throw new RuntimeException(String.format(
+                                                       WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH, NAME));
+                               }
+
+                               final TreeNode toBeReloaded = node.getParent();
+
+                               node.getParent().getNode().remove(node);
+                               node.setParent(null);
+
+                               if (PaletteManager.getInstance().getView() != null) {
+                                       final DefaultTreeModel model = (DefaultTreeModel) PaletteManager
+                                                       .getInstance().getView().getTree().getModel();
+                                       model.reload(toBeReloaded);
+                               }
+
+                               PaletteManager.getInstance().saveConfig();
+                       }
+               });
+       }
+
+       /**
+        * Remove a palette or a category of the palette manager
+        * 
+        * @param name
+        *            TreePath of the palette or category
+        * @param status
+        *            True to set the palette visible, false otherwise
+        * @throws Exception
+        *             in case of error
+        */
+       @ScilabExported(module = "xcos", filename = "Palette.giws.xml")
+       public static void enable(final String[] name, final boolean status)
+                       throws Exception {
+               SwingUtilities.invokeAndWait(new Runnable() {
+                       @Override
+                       public void run() {
+                               PaletteNode node = getPathNode(name, false);
+                               if (node == null) {
+                                       throw new RuntimeException(String.format(
+                                                       WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH, NAME));
+                               }
+
+                               node.setEnable(status);
+
+                               PaletteManager.getInstance().saveConfig();
+                               if (PaletteManager.getInstance().getView() != null) {
+                                       final DefaultTreeModel model = (DefaultTreeModel) PaletteManager
+                                                       .getInstance().getView().getTree().getModel();
+                                       model.reload(node);
+                               }
+                       }
+               });
+       }
+
+       /**
+        * Move a palette or a category of the palette manager
+        * 
+        * @param source
+        *            TreePath of the palette or category
+        * @param target
+        * @link TreePath} of the destination
+        * @throws Exception
+        *             in case of error
+        */
+       @ScilabExported(module = "xcos", filename = "Palette.giws.xml")
+       public static void move(final String[] source, final String[] target)
+                       throws Exception {
+               SwingUtilities.invokeAndWait(new Runnable() {
+                       @Override
+                       public void run() {
+
+                               PaletteNode src = getPathNode(source, false);
+                               if (src == null) {
+                                       throw new RuntimeException(String.format(
+                                                       WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH, "source"));
+                               }
+
+                               PaletteNode trg = getPathNode(target, true);
+                               if (trg == null || !(trg instanceof Category)) {
+                                       throw new RuntimeException(String.format(
+                                                       WRONG_INPUT_ARGUMENT_S_INVALID_TREE_PATH, "target"));
+                               }
+                               Category destination = (Category) trg;
+
+                               final TreeNode toBeReloaded[] = new TreeNode[] {
+                                               src.getParent(), destination };
+
+                               src.getParent().getNode().remove(src);
+                               destination.getNode().add(src);
+                               src.setParent(destination);
+
+                               PaletteManager.getInstance().saveConfig();
+                               if (PaletteManager.getInstance().getView() != null) {
+                                       final DefaultTreeModel model = (DefaultTreeModel) PaletteManager
+                                                       .getInstance().getView().getTree().getModel();
+                                       model.reload(toBeReloaded[0]);
+                                       model.reload(toBeReloaded[1]);
+                               }
+                       }
+               });
+       }
+
+       /**
+        * Generate a palette block image from a block saved instance (need a valid
+        * style).
+        * 
+        * @param blockPath
+        *            the HDF5 block instance
+        * @param iconPath
+        *            the output file path use to save the palette block.
+        * @throws IOException
+        *             in case of write errors
+        */
+       @ScilabExported(module = "xcos", filename = "Palette.giws.xml")
+       public static void generatePaletteIcon(String blockPath, String iconPath)
+                       throws IOException {
+               final BasicBlock block = new H5RWHandler(blockPath).readBlock();
+
+               if (block == null || block.getGeometry() == null) {
+                       return;
+               }
+               block.getGeometry().setX(XcosConstants.PALETTE_BLOCK_WIDTH);
+               block.getGeometry().setY(XcosConstants.PALETTE_BLOCK_HEIGHT);
+
+               XcosDiagram graph = new XcosDiagram();
+               graph.installListeners();
+               graph.getModel().beginUpdate();
+               graph.addCell(block);
+               BlockPositioning.updateBlockView(block);
+               graph.getModel().endUpdate();
+
+               /*
+                * Render
+                */
+               mxGraphComponent graphComponent = graph.getAsComponent();
+               graphComponent.refresh();
+
+               final mxRectangle bounds = graph.getPaintBounds(new Object[] { block });
+               final double width = bounds.getWidth();
+               final double height = bounds.getHeight();
+
+               final double scale;
+               if (width > XcosConstants.PALETTE_BLOCK_WIDTH
+                               || height > XcosConstants.PALETTE_BLOCK_HEIGHT) {
+                       scale = Math.min(XcosConstants.PALETTE_BLOCK_WIDTH / width,
+                                       XcosConstants.PALETTE_BLOCK_HEIGHT / height)
+                                       / XcosConstants.PALETTE_BLOCK_ICON_RATIO;
+               } else {
+                       scale = 1.0;
+               }
+
+               BufferedImage image = mxCellRenderer.createBufferedImage(graph, null,
+                               scale, null, graphComponent.isAntiAlias(), null, graphComponent
+                                               .getCanvas());
+
+               final String extension = iconPath
+                               .substring(iconPath.lastIndexOf('.') + 1);
+               ImageIO.write(image, extension, new File(iconPath));
+
+               if (LOG.isTraceEnabled()) {
+                       LOG.trace(iconPath + " updated.");
+               }
+       }
+
+       /**
+        * Helper function used to regenerate palette block images from block
+        * instance.
+        * 
+        * This method is not export to scilab but is needed for internal purpose
+        * (palette block image generation)
+        */
+       public static void generateAllPaletteImages() {
+               try {
+                       SwingUtilities.invokeAndWait(new Runnable() {
+                               public void run() {
+                                       final PaletteManager current = PaletteManager.getInstance();
+                                       iterate(current.getRoot().getNode());
+                                       current.saveConfig();
+                               }
+
+                               private void iterate(List<PaletteNode> children) {
+                                       for (Iterator<PaletteNode> iter = children.iterator(); iter
+                                                       .hasNext();) {
+                                               PaletteNode next = iter.next();
+
+                                               if (next instanceof Category) {
+                                                       iterate(((Category) next).getNode());
+                                               } else if (next instanceof PreLoaded) {
+                                                       final PreLoaded current = (PreLoaded) next;
+
+                                                       List<PaletteBlock> blocks = current.getBlock();
+                                                       for (Iterator<PaletteBlock> iterator = blocks
+                                                                       .iterator(); iterator.hasNext();) {
+                                                               final PaletteBlock paletteBlock = iterator
+                                                                               .next();
+                                                               final String file = paletteBlock.getIcon()
+                                                                               .getEvaluatedPath();
+
+                                                               try {
+                                                                       generatePaletteIcon(paletteBlock.getData()
+                                                                                       .getEvaluatedPath(), paletteBlock
+                                                                                       .getIcon().getEvaluatedPath());
+                                                               } catch (IOException e) {
+                                                                       LOG.error(file);
+                                                                       LOG.error(e);
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       });
+               } catch (InterruptedException e) {
+                       LOG.error(e);
+               } catch (InvocationTargetException e) {
+                       LOG.error(e);
+               }
+
+               LOG.trace("All images has been generated.");
+       }
+}
index d81fdc7..3e944f6 100644 (file)
@@ -104,7 +104,12 @@ public final class PaletteBlockCtrl {
                        // Load the block from the file
                        String realPath = model.getData().getEvaluatedPath(); 
                        block = new H5RWHandler(realPath).readBlock();
-
+                       
+                       // invalid block case
+                       if (block == null) {
+                               return null;
+                       }
+                       
                        if (block.getStyle().compareTo("") == 0) {
                                block.setStyle(block.getInterfaceFunctionName());
                                block.setValue(block.getInterfaceFunctionName());
index 4fd852e..12538e7 100644 (file)
@@ -100,7 +100,7 @@ public final class PaletteManager {
        /** @return true if the palette window is visible, false otherwise */
        public static boolean isVisible() {
                return getInstance().getView() != null
-                               || getInstance().getView().isVisible();
+                               && getInstance().getView().isVisible();
        }
 
        /**
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PreLoadedElement.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PreLoadedElement.java
new file mode 100644 (file)
index 0000000..024242c
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.xcos.palette;
+
+import static java.util.Arrays.asList;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.scilab.modules.types.scilabTypes.ScilabString;
+import org.scilab.modules.types.scilabTypes.ScilabTList;
+import org.scilab.modules.types.scilabTypes.ScilabType;
+import org.scilab.modules.xcos.io.scicos.AbstractElement;
+import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
+import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongElementException;
+import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongStructureException;
+import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongTypeException;
+import org.scilab.modules.xcos.palette.model.PaletteBlock;
+import org.scilab.modules.xcos.palette.model.PreLoaded;
+import org.scilab.modules.xcos.palette.model.VariablePath;
+
+/**
+ * Decode a palette into a {@link PreLoaded} palette.
+ */
+public class PreLoadedElement extends AbstractElement<PreLoaded> {
+       private static final List<String> DATA_FIELD_NAMES = asList("palette",
+                       "name", "blockNames", "blocks", "icons", "style");
+       
+       /** Mutable field to easily get the data through methods */ 
+       private ScilabTList data;
+       
+       /**
+        * Default constructor 
+        */
+       public PreLoadedElement() { }
+       
+       /**
+        * Check the type name compatibility.
+        * 
+        * @param element the current element
+        * @return <code>true</code> if the data can be decoded by this instance, <code>false</code> otherwise. 
+        * @see org.scilab.modules.xcos.io.scicos.Element#canDecode(org.scilab.modules.types.scilabTypes.ScilabType)
+        */
+       @Override
+       public boolean canDecode(ScilabType element) {
+               data = (ScilabTList) element;
+               
+               final String type = ((ScilabString) data.get(0)).getData()[0][0];
+               return type.equals(DATA_FIELD_NAMES.get(0));
+       }
+
+       /**
+        * Decode the current element on the into argument.
+        * 
+        * @param element the Scilab data
+        * @param into the target of the decoding (may be null)
+        * @return the filled instance
+        * @throws ScicosFormatException on decoding error
+        * @see org.scilab.modules.xcos.io.scicos.Element#decode(org.scilab.modules.types.scilabTypes.ScilabType, java.lang.Object)
+        */
+       @Override
+       public PreLoaded decode(ScilabType element, PreLoaded into)
+                       throws ScicosFormatException {
+               data = (ScilabTList) element;
+               PreLoaded palette = into;
+               
+               validate();
+               
+               if (into == null) {
+                       palette = new PreLoaded();
+               }
+               
+               palette.setEnable(true);
+               
+               /*
+                * get the data
+                */
+               
+               int field = 1;
+               String[][] name = ((ScilabString) data.get(field)).getData();
+               
+               field++;
+               String[][] blockNames = ((ScilabString) data.get(field)).getData();
+               
+               field++;
+               String[][] blocks = ((ScilabString) data.get(field)).getData();
+               
+               field++;
+               String[][] icons = ((ScilabString) data.get(field)).getData();
+               
+               /*
+                * Configure the current palette instance
+                */
+               
+               palette.setName(name[0][0]);
+               
+               final List<PaletteBlock> paletteBlocks = palette.getBlock();
+               for (int i = 0; i < blockNames.length; i++) {
+                       for (int j = 0; j < blockNames[i].length; j++) {
+                               PaletteBlock current = new PaletteBlock();
+                               current.setName(blockNames[i][j]);
+                               
+                               VariablePath dataPath = new VariablePath();
+                               dataPath.setVariable(null);
+                               dataPath.setPath(blocks[i][j]);
+                               current.setData(dataPath);
+                               
+                               VariablePath iconPath = new VariablePath();
+                               iconPath.setVariable(null);
+                               File icon = new File(icons[i][j]);
+                               if (!icon.exists()) {
+                                       try {
+                                               Palette.generatePaletteIcon(blocks[i][j], icons[i][j]);
+                                       } catch (IOException e) {
+                                               throw new WrongTypeException(e);
+                                       }
+                               }
+                               iconPath.setPath(icons[i][j]);
+                               current.setIcon(iconPath);
+                               
+                               paletteBlocks.add(current);
+                       }
+               }
+               
+               return palette;
+       }
+
+       /**
+        * Validate the current data.
+        * 
+        * This method doesn't pass the metrics because it
+        * perform many test. Therefore all these tests are trivial and the
+        * conditioned action only throw an exception.
+        * 
+        * @throws ScicosFormatException
+        *             when there is a validation error.
+        */
+       // CSOFF: CyclomaticComplexity
+       // CSOFF: NPathComplexity
+       private void validate() throws ScicosFormatException {
+               if (!canDecode(data)) {
+                       throw new WrongElementException();
+               }
+               
+               int field = 0;
+               
+               // we test if the structure as enough field
+               if (data.size() != DATA_FIELD_NAMES.size()) {
+                       throw new WrongStructureException(DATA_FIELD_NAMES);
+               }
+               
+               /*
+                * Checking the TList header
+                */
+               
+               // Check the first field
+               if (!(data.get(field) instanceof ScilabString)) {
+                       throw new WrongTypeException(DATA_FIELD_NAMES, field);
+               }
+               final String[] header = ((ScilabString) data.get(field)).getData()[0];
+               
+               // Checking for the field names
+               if (header.length != DATA_FIELD_NAMES.size()) {
+                       throw new WrongStructureException(DATA_FIELD_NAMES);
+               }
+               for (int i = 0; i < header.length; i++) {
+                       if (!header[i].equals(DATA_FIELD_NAMES.get(i))) {
+                               throw new WrongStructureException(DATA_FIELD_NAMES);
+                       }
+               }
+               
+               /*
+                * Checking the data
+                */
+               
+               // the second field must contain the palette name.
+               field++;
+               if (!(data.get(field) instanceof ScilabString)
+                               || data.get(field).getWidth() != 1
+                               || data.get(field).getHeight() != 1) {
+                       throw new WrongTypeException(DATA_FIELD_NAMES, field);
+               }
+               
+               // the third field must contains the block name (row column)
+               field++;
+               if (!(data.get(field) instanceof ScilabString)
+                               || data.get(field).getWidth() != 1) {
+                       throw new WrongTypeException(DATA_FIELD_NAMES, field);
+               }
+               
+               // the fourth field must contains the block instance path (row column)
+               field++;
+               if (!(data.get(field) instanceof ScilabString)
+                               || data.get(field).getWidth() != 1) {
+                       throw new WrongTypeException(DATA_FIELD_NAMES, field);
+               }
+               
+               // the fifth field must contains the block icon path (row column)
+               field++;
+               if (!(data.get(field) instanceof ScilabString)
+                               || data.get(field).getWidth() != 1) {
+                       throw new WrongTypeException(DATA_FIELD_NAMES, field);
+               }
+               
+               // the sixth field is handled by the StyleElement decoder.
+       }
+       
+       /**
+        * Not implemented yet, always return null.
+        * 
+        * @param from the source
+        * @param element the destination
+        * @return null
+        * @see org.scilab.modules.xcos.io.scicos.Element#encode(java.lang.Object, org.scilab.modules.types.scilabTypes.ScilabType)
+        */
+       @Override
+       @Deprecated
+       public ScilabType encode(PreLoaded from, ScilabType element) {
+               return null;
+       }
+
+}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/StyleElement.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/StyleElement.java
new file mode 100644 (file)
index 0000000..579eb63
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * 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-en.txt
+ *
+ */
+
+package org.scilab.modules.xcos.palette;
+
+import static java.util.Arrays.asList;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.scilab.modules.graph.utils.StyleMap;
+import org.scilab.modules.types.scilabTypes.ScilabString;
+import org.scilab.modules.types.scilabTypes.ScilabTList;
+import org.scilab.modules.types.scilabTypes.ScilabType;
+import org.scilab.modules.xcos.io.scicos.AbstractElement;
+import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
+import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongElementException;
+import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongStructureException;
+import org.scilab.modules.xcos.io.scicos.ScicosFormatException.WrongTypeException;
+
+import com.mxgraph.view.mxStylesheet;
+
+/**
+ * Decode a palette into a {@link mxStylesheet}.
+ */
+public class StyleElement extends AbstractElement<mxStylesheet> {
+       private static final List<String> DATA_FIELD_NAMES = asList("palette",
+                       "name", "blockNames", "blocks", "icons", "style");
+
+       /** Mutable field to easily get the data through methods */
+       private ScilabTList data;
+
+       /**
+        * Default constructor
+        */
+       public StyleElement() {
+       }
+
+       /**
+        * Check if the element can be decoded by the current class.
+        * 
+        * @param element
+        *            the data
+        * @return <code>false</code> if {@link #decode(ScilabType, mxStylesheet)}
+        *         will always throw an exception, <code>false</code> is sometimes
+        *         only.
+        * @see org.scilab.modules.xcos.io.scicos.Element#canDecode(org.scilab.modules.types.scilabTypes.ScilabType)
+        */
+       @Override
+       public boolean canDecode(ScilabType element) {
+               data = (ScilabTList) element;
+
+               final String type = ((ScilabString) data.get(0)).getData()[0][0];
+               return type.equals(DATA_FIELD_NAMES.get(0));
+       }
+
+       /**
+        * Decode the current element on the into argument.
+        * 
+        * @param element
+        *            the Scilab data
+        * @param into
+        *            the target of the decoding (may be null)
+        * @return the filled instance
+        * @throws ScicosFormatException
+        *             on decoding error
+        * @see org.scilab.modules.xcos.io.scicos.Element#decode(org.scilab.modules.types.scilabTypes.ScilabType,
+        *      java.lang.Object)
+        */
+       @Override
+       public mxStylesheet decode(ScilabType element, mxStylesheet into)
+                       throws ScicosFormatException {
+               data = (ScilabTList) element;
+               final mxStylesheet styleSheet = into;
+
+               validate();
+
+               if (into == null) {
+                       throw new NullPointerException("No place to decode data");
+               }
+
+               /*
+                * get the data
+                */
+
+               int field = 2;
+               String[][] blockNames = ((ScilabString) data.get(field)).getData();
+
+               field++;
+               field++;
+               field++;
+               String[][] styles = ((ScilabString) data.get(field)).getData();
+
+               /*
+                * Configure the current styleSheet instance
+                */
+
+               for (int i = 0; i < blockNames.length; i++) {
+                       for (int j = 0; j < blockNames[i].length; j++) {
+                               final Map<String, Object> style = new HashMap<String, Object>(
+                                               new StyleMap(styles[i][j]));
+                               styleSheet.putCellStyle(blockNames[i][j], style);
+                       }
+               }
+
+               return styleSheet;
+       }
+
+       /**
+        * Validate the current data.
+        * 
+        * This method doesn't pass the metrics because it perform many test.
+        * Therefore all these tests are trivial and the conditioned action only
+        * throw an exception.
+        * 
+        * @throws ScicosFormatException
+        *             when there is a validation error.
+        */
+       // CSOFF: CyclomaticComplexity
+       // CSOFF: NPathComplexity
+       private void validate() throws ScicosFormatException {
+               if (!canDecode(data)) {
+                       throw new WrongElementException();
+               }
+
+               int field = 0;
+
+               // we test if the structure as enough field
+               if (data.size() != DATA_FIELD_NAMES.size()) {
+                       throw new WrongStructureException(DATA_FIELD_NAMES);
+               }
+
+               /*
+                * Checking the TList header
+                */
+
+               // Check the first field
+               if (!(data.get(field) instanceof ScilabString)) {
+                       throw new WrongTypeException(DATA_FIELD_NAMES, field);
+               }
+               final String[] header = ((ScilabString) data.get(field)).getData()[0];
+
+               // Checking for the field names
+               if (header.length != DATA_FIELD_NAMES.size()) {
+                       throw new WrongStructureException(DATA_FIELD_NAMES);
+               }
+               for (int i = 0; i < header.length; i++) {
+                       if (!header[i].equals(DATA_FIELD_NAMES.get(i))) {
+                               throw new WrongStructureException(DATA_FIELD_NAMES);
+                       }
+               }
+
+               /*
+                * Checking the data
+                */
+
+               // the second field is handled by the PreLoadedElement decoder
+               field++;
+
+               // the third field must contains the block name (row column)
+               field++;
+               if (!(data.get(field) instanceof ScilabString)
+                               || data.get(field).getWidth() != 1) {
+                       throw new WrongTypeException(DATA_FIELD_NAMES, field);
+               }
+
+               // the fourth field is handled by the PreLoadedElement decoder
+               field++;
+
+               // the fifth field is handled by the PreLoadedElement decoder
+               field++;
+
+               // the sixth field must contains a valid style
+               field++;
+               if (!(data.get(field) instanceof ScilabString)
+                               || data.get(field).getWidth() != 1) {
+                       throw new WrongTypeException(DATA_FIELD_NAMES, field);
+               }
+       }
+
+       /**
+        * Not used
+        * 
+        * @param from
+        *            Not used
+        * @param element
+        *            Not used
+        * @return null
+        * @see org.scilab.modules.xcos.io.scicos.Element#encode(java.lang.Object,
+        *      org.scilab.modules.types.scilabTypes.ScilabType)
+        */
+       @Override
+       @Deprecated
+       public ScilabType encode(mxStylesheet from, ScilabType element) {
+               return null;
+       }
+
+}
diff --git a/scilab/modules/xcos/src/jni/Palette.cpp b/scilab/modules/xcos/src/jni/Palette.cpp
new file mode 100644 (file)
index 0000000..b4049cf
--- /dev/null
@@ -0,0 +1,407 @@
+#include "Palette.hxx"
+/* Generated by GIWS (version 1.1.1) */
+/*
+
+Copyright 2007-2008 INRIA
+Copyright 2008-2010 DIGITEO
+
+Author : Sylvestre Ledru & others
+
+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_palette {
+
+// Returns the current env
+
+JNIEnv * Palette::getCurrentEnv() {
+JNIEnv * curEnv = NULL;
+this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+return curEnv;
+}
+// Destructor
+
+Palette::~Palette() {
+JNIEnv * curEnv = NULL;
+this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+
+curEnv->DeleteGlobalRef(this->instance);
+curEnv->DeleteGlobalRef(this->instanceClass);
+curEnv->DeleteGlobalRef(this->stringArrayClass);}
+// Constructors
+
+Palette::Palette(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 */
+voidloadPaljstringjobjectArray_ID=NULL; 
+voidaddCategoryjobjectArray_jbooleanID=NULL; 
+voidremovejobjectArray_ID=NULL; 
+voidenablejobjectArray_jbooleanID=NULL; 
+voidmovejobjectArray_jobjectArray_ID=NULL; 
+voidgeneratePaletteIconjstringjstringID=NULL; 
+
+
+}
+
+Palette::Palette(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 */
+        voidloadPaljstringjobjectArray_ID=NULL; 
+voidaddCategoryjobjectArray_jbooleanID=NULL; 
+voidremovejobjectArray_ID=NULL; 
+voidenablejobjectArray_jbooleanID=NULL; 
+voidmovejobjectArray_jobjectArray_ID=NULL; 
+voidgeneratePaletteIconjstringjstringID=NULL; 
+
+
+}
+
+// Generic methods
+
+void Palette::synchronize() {
+if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
+throw GiwsException::JniMonitorException(getCurrentEnv(), "Palette");
+}
+}
+
+void Palette::endSynchronize() {
+if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
+throw GiwsException::JniMonitorException(getCurrentEnv(), "Palette");
+}
+}
+// Method(s)
+
+void Palette::loadPal (JavaVM * jvm_, char * path, char ** category, int categorySize){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidloadPaljstringjobjectArray_ID = curEnv->GetStaticMethodID(cls, "loadPal", "(Ljava/lang/String;[Ljava/lang/String;)V" ) ;
+if (voidloadPaljstringjobjectArray_ID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "loadPal");
+}
+
+jstring path_ = curEnv->NewStringUTF( path );
+jclass stringArrayClass = curEnv->FindClass("java/lang/String");
+
+// create java array of strings.
+jobjectArray category_ = curEnv->NewObjectArray( categorySize, stringArrayClass, NULL);
+if (category_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+// convert each char * to java strings and fill the java array.
+for ( int i = 0; i < categorySize; i++)
+{
+jstring TempString = curEnv->NewStringUTF( category[i] );
+if (TempString == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+curEnv->SetObjectArrayElement( category_, i, TempString);
+
+// avoid keeping reference on to many strings
+curEnv->DeleteLocalRef(TempString);
+}
+                         curEnv->CallStaticVoidMethod(cls, voidloadPaljstringjobjectArray_ID ,path_, category_);curEnv->DeleteLocalRef(stringArrayClass);
+curEnv->DeleteLocalRef(category_);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+void Palette::addCategory (JavaVM * jvm_, char ** name, int nameSize, bool visible){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidaddCategoryjobjectArray_jbooleanID = curEnv->GetStaticMethodID(cls, "addCategory", "([Ljava/lang/String;Z)V" ) ;
+if (voidaddCategoryjobjectArray_jbooleanID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "addCategory");
+}
+jclass stringArrayClass = curEnv->FindClass("java/lang/String");
+
+// create java array of strings.
+jobjectArray name_ = curEnv->NewObjectArray( nameSize, stringArrayClass, NULL);
+if (name_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+// convert each char * to java strings and fill the java array.
+for ( int i = 0; i < nameSize; i++)
+{
+jstring TempString = curEnv->NewStringUTF( name[i] );
+if (TempString == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+curEnv->SetObjectArrayElement( name_, i, TempString);
+
+// avoid keeping reference on to many strings
+curEnv->DeleteLocalRef(TempString);
+}
+jboolean visible_ = (static_cast<bool>(visible) ? JNI_TRUE : JNI_FALSE);
+
+                         curEnv->CallStaticVoidMethod(cls, voidaddCategoryjobjectArray_jbooleanID ,name_, visible_);curEnv->DeleteLocalRef(stringArrayClass);
+curEnv->DeleteLocalRef(name_);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+void Palette::remove (JavaVM * jvm_, char ** name, int nameSize){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidremovejobjectArray_ID = curEnv->GetStaticMethodID(cls, "remove", "([Ljava/lang/String;)V" ) ;
+if (voidremovejobjectArray_ID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "remove");
+}
+jclass stringArrayClass = curEnv->FindClass("java/lang/String");
+
+// create java array of strings.
+jobjectArray name_ = curEnv->NewObjectArray( nameSize, stringArrayClass, NULL);
+if (name_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+// convert each char * to java strings and fill the java array.
+for ( int i = 0; i < nameSize; i++)
+{
+jstring TempString = curEnv->NewStringUTF( name[i] );
+if (TempString == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+curEnv->SetObjectArrayElement( name_, i, TempString);
+
+// avoid keeping reference on to many strings
+curEnv->DeleteLocalRef(TempString);
+}
+                         curEnv->CallStaticVoidMethod(cls, voidremovejobjectArray_ID ,name_);curEnv->DeleteLocalRef(stringArrayClass);
+curEnv->DeleteLocalRef(name_);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+void Palette::enable (JavaVM * jvm_, char ** name, int nameSize, bool status){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidenablejobjectArray_jbooleanID = curEnv->GetStaticMethodID(cls, "enable", "([Ljava/lang/String;Z)V" ) ;
+if (voidenablejobjectArray_jbooleanID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "enable");
+}
+jclass stringArrayClass = curEnv->FindClass("java/lang/String");
+
+// create java array of strings.
+jobjectArray name_ = curEnv->NewObjectArray( nameSize, stringArrayClass, NULL);
+if (name_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+// convert each char * to java strings and fill the java array.
+for ( int i = 0; i < nameSize; i++)
+{
+jstring TempString = curEnv->NewStringUTF( name[i] );
+if (TempString == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+curEnv->SetObjectArrayElement( name_, i, TempString);
+
+// avoid keeping reference on to many strings
+curEnv->DeleteLocalRef(TempString);
+}
+jboolean status_ = (static_cast<bool>(status) ? JNI_TRUE : JNI_FALSE);
+
+                         curEnv->CallStaticVoidMethod(cls, voidenablejobjectArray_jbooleanID ,name_, status_);curEnv->DeleteLocalRef(stringArrayClass);
+curEnv->DeleteLocalRef(name_);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+void Palette::move (JavaVM * jvm_, char ** source, int sourceSize, char ** target, int targetSize){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidmovejobjectArray_jobjectArray_ID = curEnv->GetStaticMethodID(cls, "move", "([Ljava/lang/String;[Ljava/lang/String;)V" ) ;
+if (voidmovejobjectArray_jobjectArray_ID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "move");
+}
+jclass stringArrayClass = curEnv->FindClass("java/lang/String");
+
+// create java array of strings.
+jobjectArray source_ = curEnv->NewObjectArray( sourceSize, stringArrayClass, NULL);
+if (source_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+// convert each char * to java strings and fill the java array.
+for ( int i = 0; i < sourceSize; i++)
+{
+jstring TempString = curEnv->NewStringUTF( source[i] );
+if (TempString == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+curEnv->SetObjectArrayElement( source_, i, TempString);
+
+// avoid keeping reference on to many strings
+curEnv->DeleteLocalRef(TempString);
+}
+
+// create java array of strings.
+jobjectArray target_ = curEnv->NewObjectArray( targetSize, stringArrayClass, NULL);
+if (target_ == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+// convert each char * to java strings and fill the java array.
+for ( int i = 0; i < targetSize; i++)
+{
+jstring TempString = curEnv->NewStringUTF( target[i] );
+if (TempString == NULL)
+{
+throw GiwsException::JniBadAllocException(curEnv);
+}
+
+curEnv->SetObjectArrayElement( target_, i, TempString);
+
+// avoid keeping reference on to many strings
+curEnv->DeleteLocalRef(TempString);
+}
+                         curEnv->CallStaticVoidMethod(cls, voidmovejobjectArray_jobjectArray_ID ,source_, target_);curEnv->DeleteLocalRef(stringArrayClass);
+curEnv->DeleteLocalRef(source_);
+curEnv->DeleteLocalRef(target_);
+if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+void Palette::generatePaletteIcon (JavaVM * jvm_, char * blockPath, char * iconPath){
+
+JNIEnv * curEnv = NULL;
+jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
+jclass cls = curEnv->FindClass( className().c_str() );
+
+jmethodID voidgeneratePaletteIconjstringjstringID = curEnv->GetStaticMethodID(cls, "generatePaletteIcon", "(Ljava/lang/String;Ljava/lang/String;)V" ) ;
+if (voidgeneratePaletteIconjstringjstringID == NULL) {
+throw GiwsException::JniMethodNotFoundException(curEnv, "generatePaletteIcon");
+}
+
+jstring blockPath_ = curEnv->NewStringUTF( blockPath );
+
+jstring iconPath_ = curEnv->NewStringUTF( iconPath );
+
+                         curEnv->CallStaticVoidMethod(cls, voidgeneratePaletteIconjstringjstringID ,blockPath_, iconPath_);if (curEnv->ExceptionCheck()) {
+throw GiwsException::JniCallMethodException(curEnv);
+}
+}
+
+}
diff --git a/scilab/modules/xcos/src/jni/Palette.giws.xml b/scilab/modules/xcos/src/jni/Palette.giws.xml
new file mode 100644 (file)
index 0000000..788f2d5
--- /dev/null
@@ -0,0 +1,27 @@
+<package name="org.scilab.modules.xcos.palette">
+    <object name="Palette">
+        <method name="loadPal" returnType="void" modifier="static">
+            <parameter name="path" type="String"/>
+            <parameter name="category" type="String[]"/>
+        </method>
+        <method name="addCategory" returnType="void" modifier="static">
+            <parameter name="name" type="String[]"/>
+            <parameter name="visible" type="boolean"/>
+        </method>
+        <method name="remove" returnType="void" modifier="static">
+            <parameter name="name" type="String[]"/>
+        </method>
+        <method name="enable" returnType="void" modifier="static">
+            <parameter name="name" type="String[]"/>
+            <parameter name="status" type="boolean"/>
+        </method>
+        <method name="move" returnType="void" modifier="static">
+            <parameter name="source" type="String[]"/>
+            <parameter name="target" type="String[]"/>
+        </method>
+        <method name="generatePaletteIcon" returnType="void" modifier="static">
+            <parameter name="blockPath" type="String"/>
+            <parameter name="iconPath" type="String"/>
+        </method>
+    </object>
+</package>
diff --git a/scilab/modules/xcos/src/jni/Palette.hxx b/scilab/modules/xcos/src/jni/Palette.hxx
new file mode 100644 (file)
index 0000000..e638606
--- /dev/null
@@ -0,0 +1,143 @@
+/* Generated by GIWS (version 1.1.1) */
+/*
+
+Copyright 2007-2008 INRIA
+Copyright 2008-2010 DIGITEO
+
+Author : Sylvestre Ledru & others
+
+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_PALETTE_PALETTE__
+#define __ORG_SCILAB_MODULES_XCOS_PALETTE_PALETTE__
+#include <iostream>
+#include <string>
+#include <string.h>
+#include <stdlib.h>
+#include <jni.h>
+
+#include "GiwsException.hxx"
+
+#ifndef _MSC_VER /* Defined anyway with Visual */
+#if !defined(byte)
+typedef signed char byte;
+#else
+#pragma message("Byte has been redefined elsewhere. Some problems can happen")
+#endif
+#endif
+
+namespace org_scilab_modules_xcos_palette {
+
+class Palette {
+private:
+JavaVM * jvm;
+jobject instance;
+
+jclass instanceClass; // cache class
+jmethodID voidloadPaljstringjobjectArray_ID; // cache method id
+jclass stringArrayClass;
+jmethodID voidaddCategoryjobjectArray_jbooleanID; // cache method id
+jmethodID voidremovejobjectArray_ID; // cache method id
+jmethodID voidenablejobjectArray_jbooleanID; // cache method id
+jmethodID voidmovejobjectArray_jobjectArray_ID; // cache method id
+jmethodID voidgeneratePaletteIconjstringjstringID; // cache method id
+
+
+/**
+* Get the environment matching to the current thread.
+*/
+JNIEnv * getCurrentEnv();
+
+public:
+// Constructor
+/**
+* Create a wrapping of the object from a JNIEnv.
+* It will call the default constructor
+* @param JEnv_ the Java Env
+*/
+Palette(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
+*/
+Palette(JavaVM * jvm_, jobject JObj);
+
+// Destructor
+~Palette();
+
+// 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 loadPal(JavaVM * jvm_, char * path, char ** category, int categorySize);
+
+static void addCategory(JavaVM * jvm_, char ** name, int nameSize, bool visible);
+
+static void remove(JavaVM * jvm_, char ** name, int nameSize);
+
+static void enable(JavaVM * jvm_, char ** name, int nameSize, bool status);
+
+static void move(JavaVM * jvm_, char ** source, int sourceSize, char ** target, int targetSize);
+
+static void generatePaletteIcon(JavaVM * jvm_, char * blockPath, char * iconPath);
+
+
+                        /**
+                        * 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/palette/Palette";
+                }
+                
+};
+
+
+}
+#endif
diff --git a/scilab/modules/xcos/tests/unit_tests/xcosPal.sci b/scilab/modules/xcos/tests/unit_tests/xcosPal.sci
new file mode 100644 (file)
index 0000000..e4ef1d2
--- /dev/null
@@ -0,0 +1,36 @@
+// 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 is distributed under the same license as the Scilab package.
+
+// <-- TEST WITH XCOS -->
+//
+// <-- Short Description -->
+// Check the API of all xcos palette management methods
+
+loadScicosLibs;
+
+exportedFile = TMPDIR + "/palette.h5";
+palettePath = ["My special palettes" "My sum palettes" "My sum palette"];
+
+// Typical palette adding
+pal = xcosPal(palettePath($));
+pal = xcosPalAddBlock(pal, SUM_f("define"));
+pal = xcosPalAddBlock(pal, BIGSOM_f("define"));
+
+xcosPalExport(pal, exportedFile);
+xcosPalAdd(exportedFile, palettePath);
+
+// Remove the palette and the palette path
+for i=size(palettePath, '*'):-1:1
+       xcosPalDelete(palettePath(1:i));
+end
+
+
+// Import a Scicos palette
+exec(SCI + "/modules/scicos/palettes/Branching.cosf", -1);
+pal = xcosPal(scs_m);
+
+xcosPalExport(pal, exportedFile);
+xcosPalAdd(exportedFile);
+