Xcos: update some blocks to avoid user-redefinition 38/18238/3
Clément DAVID [Fri, 10 Jun 2016 14:27:29 +0000 (16:27 +0200)]
  - `INVBLK`: add a divide by zero parameter to ignore the error
  - `PRODUCT`: add a divide by zero parameter to ignore the error

Change-Id: I48e2b3ce7b5162de06ac612dd0fac3fa0432598f

14 files changed:
scilab/CHANGES.md
scilab/modules/helptools/images/INVBLK_gui.png [new file with mode: 0644]
scilab/modules/helptools/images/PRODUCT_gui.png [new file with mode: 0644]
scilab/modules/scicos_blocks/macros/NonLinear/INVBLK.sci
scilab/modules/scicos_blocks/macros/NonLinear/PRODUCT.sci
scilab/modules/scicos_blocks/src/c/invblk4.c
scilab/modules/scicos_blocks/src/c/product.c
scilab/modules/xcos/help/en_US/palettes/Mathoperations_pal/INVBLK.xml
scilab/modules/xcos/help/en_US/palettes/Mathoperations_pal/PRODUCT.xml
scilab/modules/xcos/help/fr_FR/palettes/Mathoperations_pal/INVBLK.xml
scilab/modules/xcos/help/fr_FR/palettes/Mathoperations_pal/PRODUCT.xml
scilab/modules/xcos/images/gui/INVBLK_gui.png [new file with mode: 0644]
scilab/modules/xcos/images/gui/PRODUCT_gui.gif [deleted file]
scilab/modules/xcos/images/gui/PRODUCT_gui.png [new file with mode: 0644]

index fe35269..9a807ac 100644 (file)
@@ -239,6 +239,9 @@ The memory usage on diagram edition is also slightly reduced.
 Scilab 5.5.2 is able to open the newly saved files, but the ports have to be repositioned manually.
 * Implicit fixed-size step ODE solver added: Crank-Nicolson 2(3). 
 Added to the CVode package, it also benefits from the CVode rootfinding feature.
+* Block modifications :
+  - `INVBLK`: add a divide by zero parameter to ignore the error
+  - `PRODUCT`: add a divide by zero parameter to ignore the error
 
 
 API modification
diff --git a/scilab/modules/helptools/images/INVBLK_gui.png b/scilab/modules/helptools/images/INVBLK_gui.png
new file mode 100644 (file)
index 0000000..3f37600
Binary files /dev/null and b/scilab/modules/helptools/images/INVBLK_gui.png differ
diff --git a/scilab/modules/helptools/images/PRODUCT_gui.png b/scilab/modules/helptools/images/PRODUCT_gui.png
new file mode 100644 (file)
index 0000000..ae1663f
Binary files /dev/null and b/scilab/modules/helptools/images/PRODUCT_gui.png differ
index 4960187..f2d5d04 100644 (file)
@@ -1,6 +1,7 @@
 //  Scicos
 //
 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//  Copyright (C) 2016-2016 - Scilab Enterprises - Clement David
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -26,16 +27,46 @@ function [x,y,typ]=INVBLK(job,arg1,arg2)
     select job
     case "set" then
         x=arg1;
+        graphics=arg1.graphics;
+        exprs=graphics.exprs
+        model=arg1.model;
+
+        // Compatibility before 6.0.0, there was no divideByZero parameter
+        if exprs == " " then
+            exprs($+1) = "1";
+        end
+
+        while %t do
+            [ok,divideByZero,exprs]=..
+            scicos_getvalue("Set block parameters",..
+            ["Error on divide by zero (1: yes) (0:no)"],..
+            list("vec",1),exprs)
+            if ~ok then
+                break,
+            end
+            graphics.exprs=exprs
+            if ok then
+                if divideByZero==0 then
+                    model.rpar=%eps;
+                else
+                    model.rpar=0;
+                end
+                x.graphics=graphics;
+                x.model=model
+                break
+            end
+        end
     case "define" then
         in=-1
         model=scicos_model()
         model.sim=list("invblk4",4)
         model.in=in
         model.out=in
+        model.rpar=0;
         model.blocktype="c"
         model.dep_ut=[%t %f]
 
-        exprs=" "
+        exprs="1"
         gr_i=[]
         x=standard_define([2 2],model,exprs,gr_i)
     end
index ed4ff19..f0daf6f 100644 (file)
@@ -1,6 +1,7 @@
 //  Scicos
 //
 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//  Copyright (C) 2016-2016 - Scilab Enterprises - Clement David
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -29,11 +30,16 @@ function [x,y,typ] = PRODUCT(job,arg1,arg2)
         graphics=arg1.graphics
         model=arg1.model
         exprs=graphics.exprs
+
+        // Compatibility before 6.0.0, there was no divideByZero parameter
+        if size(exprs) == [1 1] then
+            exprs($+1) = "1";
+        end
+
         while %t do
-            [ok,sgn,exprs]=scicos_getvalue(["         Set multiplication block parameters";
-            "(multiplication is set with + 1, division with -1)";""],...
-            "Number of inputs or sign vector",...
-            list("vec",-1),exprs)
+            [ok,sgn,divideByZero,exprs]=scicos_getvalue(["Set block parameters"],...
+            ["<html>Number of inputs or sign vector<br>(multiplication is set with + 1, division with -1)</html>"; "Error on divide by zero<br>(1: yes) (0: no)"],...
+            list("vec",-1, "vec", 1),exprs)
             if ~ok then
                 break,
             end
@@ -63,6 +69,13 @@ function [x,y,typ] = PRODUCT(job,arg1,arg2)
             if ok then
                 [model,graphics,ok]=check_io(model,graphics,in,nout,[],[])
             end
+
+            if divideByZero==0 then
+                model.rpar=%eps;
+            else
+                model.rpar=0;
+            end
+
             if ok then
                 model.ipar=sgn
                 graphics.exprs=exprs
@@ -78,11 +91,12 @@ function [x,y,typ] = PRODUCT(job,arg1,arg2)
         model.in=[-1;-1]
         model.out=-1
         model.ipar=sgn
+        model.rpar=0
         model.blocktype="c"
         model.dep_ut=[%t %f]
 
 
-        exprs=sci2exp(sgn)
+        exprs=[sci2exp(sgn) ; "1"]
         gr_i=[]
         x=standard_define([2 3],model, exprs,gr_i)
     end
index e846fa1..d13350c 100644 (file)
@@ -54,8 +54,16 @@ SCICOS_BLOCKS_IMPEXP void invblk4(scicos_block *block, int flag)
             }
             else
             {
-                set_block_error(-2);
-                return;
+                if (block->rpar[0] == 0.0)
+                {
+                    set_block_error(-2);
+                    return;
+                }
+                else
+                {
+                    // ignore the divide by zero, divide by a value stored in rpar
+                    block->outptr[0][i] = 1.0 / block->rpar[0];
+                }
             }
         }
     }
index cc6e081..e9c2f36 100644 (file)
@@ -52,8 +52,16 @@ SCICOS_BLOCKS_IMPEXP void product(scicos_block *block, int flag)
                     {
                         if (block->inptr[k][j] == 0)
                         {
-                            set_block_error(-2);
-                            return;
+                            if (block->rpar[0] == 0.0)
+                            {
+                                set_block_error(-2);
+                                return;
+                            }
+                            else
+                            {
+                                // ignore the divide by zero, divide by a value stored in rpar
+                                block->outptr[0][j] = block->outptr[0][j] / block->rpar[0];
+                            }
                         }
                         else
                         {
index 14bbbbc..e067512 100644 (file)
                     </listitem>
                     <listitem>
                         <para>
+                            <xref linkend="Dialogbox_INVBLK">Dialog box</xref>
+                        </para>
+                    </listitem>
+                    <listitem>
+                        <para>
                             <xref linkend="Defaultproperties_INVBLK">Default properties</xref>
                         </para>
                     </listitem>
     <refsection id="Description_INVBLK">
         <title>Description</title>
         <para>
-            This block computes the output vector y with y[i]=1/u[i] where u is the input vector.The input and output sizes are
-            determined by the context.
+            This block computes the output vector y with y[i]=1/u[i] where u is the input vector.The input and output sizes are determined by the context.
         </para>
     </refsection>
+    <refsection id="Dialogbox_INVBLK">
+        <title>Dialog box</title>
+        <para>
+            <inlinemediaobject>
+                <imageobject>
+                    <imagedata fileref="../../../../images/gui/INVBLK_gui.png" align="center" valign="middle"/>
+                </imageobject>
+            </inlinemediaobject>
+        </para>
+        <para>
+            
+        </para>
+        <itemizedlist>
+            <listitem>
+                <para>
+                    <emphasis role="bold">Error on divide by zero (1: yes) (0:no)</emphasis>
+                </para>
+                <para> Halt the simulation on divide by zero.</para>
+                <para> Properties : Type 'vec' of size 1</para>
+            </listitem>
+        </itemizedlist>
+    </refsection>
     <refsection id="Defaultproperties_INVBLK">
         <title>Default properties</title>
         <itemizedlist>
index bb40e9d..b385e49 100644 (file)
@@ -98,8 +98,7 @@
     <refsection id="Description_PRODUCT">
         <title>Description</title>
         <para>
-            That bloc computes element-wise multiplication or division of its vector inputs. The number of inputs
-            and operation are specified with the <emphasis role="bold">Number of inputs or sign vector</emphasis> parameter.
+            That bloc computes element-wise multiplication or division of its vector inputs. The number of inputs and operation are specified with the <emphasis role="bold">Number of inputs or sign vector</emphasis> parameter.
         </para>
         <itemizedlist>
             <listitem>
         <para>
             <inlinemediaobject>
                 <imageobject>
-                    <imagedata fileref="../../../../images/gui/PRODUCT_gui.gif" align="center" valign="middle"/>
+                    <imagedata fileref="../../../../images/gui/PRODUCT_gui.png" align="center" valign="middle"/>
                 </imageobject>
             </inlinemediaobject>
         </para>
                 <para>
                     <emphasis role="bold">Number of inputs or sign vector </emphasis>
                 </para>
-                <para> Enter the number of inputs.</para>
-                <para> Properties : Type 'vec' of size 1</para>
+                <para>Set the number of inputs and the associated operation.</para>
+                <para>Properties : Type 'vec' of size N</para>
+            </listitem>
+            <listitem>
+                <para>
+                    <emphasis role="bold">Error on divide by zero (1: yes) (0:no)</emphasis>
+                </para>
+                <para>Halt the simulation on divide by zero.</para>
+                <para>Properties : Type 'vec' of size 1</para>
             </listitem>
         </itemizedlist>
     </refsection>
index 7c1843b..3249705 100644 (file)
                     </listitem>
                     <listitem>
                         <para>
+                            <xref linkend="Dialogbox_INVBLK">Boîte de dialogue</xref>
+                        </para>
+                    </listitem>
+                    <listitem>
+                        <para>
                             <xref linkend="Defaultproperties_INVBLK">Propriétés par défaut</xref>
                         </para>
                     </listitem>
             et sorties est déterminée par le contexte.
         </para>
     </refsection>
+    <refsection id="Dialogbox_INVBLK">
+        <title>Dialog box</title>
+        <para>
+            <inlinemediaobject>
+                <imageobject>
+                    <imagedata fileref="../../../../images/gui/INVBLK_gui.png" align="center" valign="middle"/>
+                </imageobject>
+            </inlinemediaobject>
+        </para>
+        <para>
+        </para>
+        <itemizedlist>
+            <listitem>
+                <para>
+                    <emphasis role="bold">Error on divide by zero (1: yes) (0:no)</emphasis>
+                </para>
+                <para>Arrête la simulation en cas de division par zéro.</para>
+                <para>Propriétés : Type 'vec' de taille 1</para>
+            </listitem>
+        </itemizedlist>
+    </refsection>
     <refsection id="Defaultproperties_INVBLK">
         <title>Propriétés par défaut</title>
         <itemizedlist>
index 42d66d3..886ef47 100644 (file)
         <para>
             <inlinemediaobject>
                 <imageobject>
-                    <imagedata fileref="../../../../images/gui/PRODUCT_gui.gif" align="center" valign="middle"/>
+                    <imagedata fileref="../../../../images/gui/PRODUCT_gui.png" align="center" valign="middle"/>
                 </imageobject>
             </inlinemediaobject>
         </para>
                 <para>
                     <emphasis role="bold">Number of inputs or sign vector</emphasis>
                 </para>
-                <para> Le nombre d'entrées.</para>
-                <para> Propriétés : Type 'vec' de taille 1</para>
+                <para>Le nombre d'entrées et l'opération associée</para>
+                <para>Propriétés : Type 'vec' de taille N</para>
+            </listitem>
+            <listitem>
+                <para>
+                    <emphasis role="bold">Error on divide by zero (1: yes) (0:no)</emphasis>
+                </para>
+                <para>Arrête la simulation en cas de division par zéro.</para>
+                <para>Propriétés : Type 'vec' de taille 1</para>
             </listitem>
         </itemizedlist>
     </refsection>
diff --git a/scilab/modules/xcos/images/gui/INVBLK_gui.png b/scilab/modules/xcos/images/gui/INVBLK_gui.png
new file mode 100644 (file)
index 0000000..3f37600
Binary files /dev/null and b/scilab/modules/xcos/images/gui/INVBLK_gui.png differ
diff --git a/scilab/modules/xcos/images/gui/PRODUCT_gui.gif b/scilab/modules/xcos/images/gui/PRODUCT_gui.gif
deleted file mode 100644 (file)
index b42cef0..0000000
Binary files a/scilab/modules/xcos/images/gui/PRODUCT_gui.gif and /dev/null differ
diff --git a/scilab/modules/xcos/images/gui/PRODUCT_gui.png b/scilab/modules/xcos/images/gui/PRODUCT_gui.png
new file mode 100644 (file)
index 0000000..ae1663f
Binary files /dev/null and b/scilab/modules/xcos/images/gui/PRODUCT_gui.png differ