tbx_build_pal_loader created according to SEP #120 49/12249/5
serge.steer [Thu, 8 Aug 2013 16:17:31 +0000 (18:17 +0200)]
Change-Id: I03052d2c74451eb274db8f4fc35812f5594c4885

SEP/INDEX
SEP/SEP_120_tbx_gen_pal_loader.odt [new file with mode: 0644]
scilab/CHANGES_5.5.X
scilab/contrib/xcos_toolbox_skeleton/.gitignore
scilab/contrib/xcos_toolbox_skeleton/etc/xcos_toolbox_skeleton.start
scilab/contrib/xcos_toolbox_skeleton/macros/buildmacros.sce
scilab/modules/modules_manager/help/en_US/tbx_build_pal_loader.xml [new file with mode: 0644]
scilab/modules/modules_manager/macros/tbx_build_pal_loader.sci [new file with mode: 0644]

index c023d28..138a934 100644 (file)
--- a/SEP/INDEX
+++ b/SEP/INDEX
@@ -115,3 +115,4 @@ SEP #116: conjgrad function, to regroup the Conjugate Gradient solvers. pcg obso
 SEP #117: New function ilib_build_jar
 SEP #118: New function ifftshift
 SEP #119: Management of encoding in xmlRead
+SEP #120: New function tbx_build_pal_loader
diff --git a/SEP/SEP_120_tbx_gen_pal_loader.odt b/SEP/SEP_120_tbx_gen_pal_loader.odt
new file mode 100644 (file)
index 0000000..d336a64
Binary files /dev/null and b/SEP/SEP_120_tbx_gen_pal_loader.odt differ
index 21e5d9b..77007ec 100644 (file)
@@ -344,11 +344,13 @@ Scilab Bug Fixes
 * Bug #13392 fixed - Typo in the CACSD help chapter fixed.
 
 
-Xcos Bug Fixes
-==============
+Xcos
+====
 
 * xcos_debug_gui function added  for a simple use of the Debug block.
 
+* tbx_build_pal_loader function added to ease external module creation (See SEP #120).
+
 * Bug #12423 fixed - Data types of SWITCH2_m were not documented.
 
 * Bug #12998 fixed - 'ans' was not ignored in the context results.
index 8f8f896..60496ca 100644 (file)
@@ -9,6 +9,7 @@ sci_gateway/c/xcos_toolbox_skeleton_c.c
 libxcos_toolbox_skeleton*.*
 cleaner_gateway.sce
 *.bin
+macros/loader_pal.sce
 macros/lib
 macros/names
 images/h5/*.h5
index 9ac4b01..66a6cc5 100644 (file)
@@ -34,20 +34,7 @@ function xcos_skeletonlib = startModule()
 // Add blocks to the Xcos palette
 // =============================================================================
   mprintf("\tLoad palette\n");
-  pal = xcosPal("Xcos toolbox blocks");
-
-  blocks = ["TBX_SUM_c" "TBX_MUT_STYLE" "TBX_SUM_sci"];
-  for i=1:size(blocks, "*")
-    h5  = ls(root_tlbx + "/images/h5/"  + blocks(i) + "." + ["sod" "h5"]);
-    gif = ls(root_tlbx + "/images/gif/" + blocks(i) + "." + ["png" "jpg" "gif"]);
-    svg = ls(root_tlbx + "/images/svg/" + blocks(i) + "." + ["png" "jpg" "gif" "svg"]);
-
-    pal = xcosPalAddBlock(pal, h5(1), gif(1), svg(1));
-  end
-
-  if ~xcosPalAdd(pal) then
-    error(msprintf(gettext("%s: Unable to export %s.\n"), "xcos_toolbox_skeleton.start", "pal"));
-  end
+  exec(pathconvert(root_tlbx+"/macros/loader_pal.sce", %f));
 
 // Load simulation functions
 // =============================================================================
index 8e9f9af..54f7f57 100644 (file)
@@ -2,9 +2,12 @@
 
 function buildmacros()
     macros_path = get_absolute_file_path("buildmacros.sce");
-    tbx_build_macros(TOOLBOX_NAME, macros_path);
+
     blocks = ["TBX_SUM_c" "TBX_MUT_STYLE", "TBX_SUM_sci"];
+
+    tbx_build_macros(TOOLBOX_NAME, macros_path);
     tbx_build_blocks(toolbox_dir, blocks);
+    tbx_build_pal_loader(TOOLBOX_TITLE, blocks, toolbox_dir, macros_path)
 endfunction
 
 buildmacros();
diff --git a/scilab/modules/modules_manager/help/en_US/tbx_build_pal_loader.xml b/scilab/modules/modules_manager/help/en_US/tbx_build_pal_loader.xml
new file mode 100644 (file)
index 0000000..07564e3
--- /dev/null
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) - DIGITEO 
+ * 
+ * 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.1-en.txt
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="tbx_build_pal_loader" xml:lang="en">
+    <refnamediv>
+        <refname>tbx_build_pal_loader</refname>
+        <refpurpose>Generate a loader_pal.sce script for loading Xcos palette module(toolbox compilation process)</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>
+            tbx_build_pal_loader(palette_name, block_names , module_path [, script_path])
+        </synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>palette_name</term>
+                <listitem>
+                    <para>a character string, the name of the palette.</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>block_names</term>
+                <listitem>
+                    <para>Block interface function list (in a string vector) ; all name should have a corresponding interface function macro (on the macros subdirectory).</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>module_path</term>
+                <listitem>
+                    <para>a character string, the path of the directory containing the module.</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>script_path</term>
+                <listitem>
+                    <para>an optional character string that can be used
+                        to specify the location of the created
+                        loader_pal.sce script file. If not given the script
+                        file will be created in the module_path+"/macros"
+                        directory.
+                    </para>
+                    <para>Generaly the loader_pal.sce script file is
+                        created in the directory which contains the block
+                        interface functions files. The script_path argument
+                        can be used to handle modules that define several
+                        palettes.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[ 
+//The recommended buildmacros.sce file
+function buildMacrosAndBlocks()
+  script_path = get_absolute_file_path("buildmacros.sce");
+  module_path = part(script_path,1:length(script_path)-length("macros"))
+  
+  tbx_build_macros(NAME,  script_path);
+  interface_functions = //to be defined
+  
+  tbx_build_blocks(module_path, interface_functions);
+  tbx_build_pal_loader(TITLE,interface_functions,module_path,script_path)
+endfunction
+buildMacrosAndBlocks()
+clear buildMacrosAndBlocks; 
+ ]]></programlisting>
+        
+    </refsection>
+</refentry>
diff --git a/scilab/modules/modules_manager/macros/tbx_build_pal_loader.sci b/scilab/modules/modules_manager/macros/tbx_build_pal_loader.sci
new file mode 100644 (file)
index 0000000..946c16a
--- /dev/null
@@ -0,0 +1,78 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - INRIA - Serge STEER
+//
+// 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.1-en.txt
+
+function tbx_build_pal_loader(palettename,interfacefunctions,module_path,script_path)
+    if argn(2) < 3 then
+        error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"tbx_build_blocks",3));
+    end
+    // checking palettename argument
+    if type(palettename) <> 10 then
+        error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"tbx_build_blocks",1));
+    end
+    if size(palettename,"*") <> 1 then
+        error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"tbx_build_blocks",1));
+    end
+
+    // checking module_path argument
+    if type(module_path) <> 10 then
+        error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"tbx_build_blocks",3));
+    end
+    if size(module_path,"*") <> 1 then
+        error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"tbx_build_blocks",3));
+    end
+    if ~isdir(module_path) then
+        error(msprintf(gettext("%s: The directory ''%s'' doesn''t exist or is not read accessible.\n"),"tbx_build_blocks",module_path));
+    end
+
+    // checking interfacefunctions argument
+    if type(interfacefunctions) <> 10 then
+        error(msprintf(gettext("%s: Wrong type for input argument #%d: A string array expected.\n"),"tbx_build_blocks",2));
+    end
+
+    // checking optional script_path argument
+    if argn(2)==4 then
+        if type(script_path) <> 10 then
+            error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"tbx_build_blocks",4));
+        end
+        if size(script_path,"*") <> 1 then
+            error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"tbx_build_blocks",4));
+        end
+    else
+        script_path=module_path + "/macros"
+    end
+    if ~isdir(script_path) then
+        error(msprintf(gettext("%s: The directory ''%s'' doesn''t exist or is not read accessible.\n"),"tbx_build_blocks",script_path));
+    end
+
+
+    t=["function loaderpal()"
+    "  xpal = xcosPal("""+palettename+""");"
+    "  images_path = "+sci2exp(module_path+"/images/");
+    "  interfacefunctions ="+sci2exp(interfacefunctions);
+    "  for i=1:size(interfacefunctions,""*"")"
+    "    h5_instances  = ls(images_path + ""h5/""  + interfacefunctions(i) + "".sod"");"
+    "    if h5_instances==[] then"
+    "      error(msprintf(_(""%s: block %s has not been built.\n""),""loader_pal.sce"",interfacefunctions(i)))"
+    "    end"
+    "    pal_icons     = ls(images_path + ""gif/"" + interfacefunctions(i) + ""."" + [""png"" ""jpg"" ""gif""]);"
+    "    if pal_icons==[] then"
+    "      error(msprintf(_(""%s: block %s has no palette icon.\n""),""loader_pal.sce"",interfacefunctions(i)))"
+    "    end"
+    "    graph_icons   = ls(images_path + ""svg/"" + interfacefunctions(i) + ""."" + [""svg"" ""png"" ""jpg"" ""gif""]);"
+    "    if graph_icons==[] then"
+    "      error(msprintf(_(""%s: block %s has no editor icon.\n""),""loader_pal.sce"",interfacefunctions(i)))"
+    "    end"
+    "    xpal = xcosPalAddBlock(xpal, h5_instances(1), pal_icons , graph_icons(1));"
+    "  end"
+    "  xcosPalAdd(xpal);"
+    "endfunction"
+    "loaderpal(),clear loaderpal"]
+    mputl(t,script_path+"loader_pal.sce")
+endfunction
+