Xcos: add hooks pre/post simulation 13/4413/7
Clément DAVID [Wed, 6 Jul 2011 12:33:17 +0000 (14:33 +0200)]
- SEP 66
- xcos_simulate documentation
- Examples

Change-Id: I809b9c5a10d239a3898513f6ea51db073757daaa

13 files changed:
SEP/SEP_066_Xcos_hooks.odt
scilab/modules/xcos/demos/Command.xcos [new file with mode: 0644]
scilab/modules/xcos/demos/Command_bode.xcos [new file with mode: 0644]
scilab/modules/xcos/help/en_US/batch_functions/xcos_simulate.xml [new file with mode: 0644]
scilab/modules/xcos/help/images/Command.png [new file with mode: 0644]
scilab/modules/xcos/help/images/Command_bode.png [new file with mode: 0644]
scilab/modules/xcos/macros/xcos_simulate.sci
scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_bad_hooks.dia.ref [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_bad_hooks.tst [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_hooks.dia.ref [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_hooks.tst [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_stop_hooks.dia.ref [new file with mode: 0644]
scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_stop_hooks.tst [new file with mode: 0644]

index b1314ec..a588265 100644 (file)
Binary files a/SEP/SEP_066_Xcos_hooks.odt and b/SEP/SEP_066_Xcos_hooks.odt differ
diff --git a/scilab/modules/xcos/demos/Command.xcos b/scilab/modules/xcos/demos/Command.xcos
new file mode 100644 (file)
index 0000000..fedc198
Binary files /dev/null and b/scilab/modules/xcos/demos/Command.xcos differ
diff --git a/scilab/modules/xcos/demos/Command_bode.xcos b/scilab/modules/xcos/demos/Command_bode.xcos
new file mode 100644 (file)
index 0000000..a3ec531
Binary files /dev/null and b/scilab/modules/xcos/demos/Command_bode.xcos differ
diff --git a/scilab/modules/xcos/help/en_US/batch_functions/xcos_simulate.xml b/scilab/modules/xcos/help/en_US/batch_functions/xcos_simulate.xml
new file mode 100644 (file)
index 0000000..a89e70a
--- /dev/null
@@ -0,0 +1,264 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="xcos_simulate">
+  <refnamediv>
+    <refname>xcos_simulate</refname>
+    <refpurpose>Function for running xcos simulation in batch mode</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>Info=xcos_simulate(scs_m, needcompile)</synopsis>
+  </refsynopsisdiv>
+  <refsection id="Parameters_xcos_simulate">
+    <title>Arguments</title>
+    <variablelist>
+      <varlistentry>
+        <term>scs_m</term>: A diagram data structure (see <link linkend="scicos_diagram">scs_m structure</link>).
+        <para/>
+      </varlistentry>
+      <varlistentry>
+        <term>needcompile</term>: An integer. If it equals 4,
+        then the simulator will perform a complete compilation of the diagram.
+        If not, it will use cached value of %cpr. DEPRECATED
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection id="Module_xcos_simulate">
+    <title>Module</title>
+    <itemizedlist>
+      <listitem>
+        <para>
+          <link linkend="xcos">xcos</link>
+        </para>
+      </listitem>
+    </itemizedlist>
+  </refsection>
+  <refsection id="Description_xcos_simulate">
+    <title>Description</title>
+    This function is used to simulate xcos diagrams in batch
+    mode. It requires the <link linkend="scicos_diagram">scs_m
+    structure</link>which can be obtained by loading in Scilab the
+    <literal>.xcos</literal> file (see <link linkend="importXcosDiagram">
+    importXcosDiagram</link>).
+
+    <para>
+      User can also define <literal>pre_xcos_simulate</literal>
+      function that will run before simulation.
+      <programlisting role="example"><![CDATA[
+      function continueSimulation = pre_xcos_simulate(scs_m, needcompile)
+      // Do nothing
+      continueSimulation = %t;
+      endfunction
+      ]]></programlisting>
+      If this function fails the error will be trapped and the simulation aborted.
+      If <literal>continueSimulation</literal> is set to false, the simulation will stop.
+    </para>
+    <para>
+      User can also define <literal>post_xcos_simulate</literal>
+      function that will run after simulation.
+      <programlisting role="example"><![CDATA[
+      function post_xcos_simulate(%cpr, scs_m, needcompile)
+      // Do Nothing
+      endfunction
+      ]]></programlisting>
+      If this function fails the error will be trapped.
+    </para>
+  </refsection>
+  <refsection id="Filecontent_xcos_simulate">
+    <title>File content</title>
+    <itemizedlist>
+      <listitem>
+        <para> SCI/modules/xcos/macros/xcos_simulate.sci</para>
+      </listitem>
+    </itemizedlist>
+  </refsection>
+  <refsection id="Examples_xcos_simulate">
+    <title>Examples</title>
+    <para>
+      The xcos diagram in <literal>SCI/modules/xcos/demos/batch_simulation.xcos</literal>
+      <mediaobject><imageobject><imagedata align="center" fileref="../../images/batch_simulation.png"/></imageobject></mediaobject>
+      Simulate this diagram in batch mode and change some context values.
+      <programlisting role="example"><![CDATA[
+      importXcosDiagram("SCI/modules/xcos/demos/batch_simulation.xcos")
+
+      typeof(scs_m) //The diagram data structure
+
+      //This diagram uses 3 context variables :
+      //  Amplitude : the sin function amplitude
+      //  Pulsation : the sin function pulsation
+      //  Tf        : the final simulation time
+      scs_m.props.context //the embedded definition
+
+      //first batch simulation with the parameters embedded in the diagram
+      xcos_simulate(scs_m, 4);
+
+      // Change the final time value
+      scs_m.props.context = ["Amplitude=2" "Pulsation=3" "Tf=10"];
+      xcos_simulate(scs_m, 4);
+
+      // Now Change pulsation
+      scs_m.props.context = ["Amplitude=2" "Pulsation=9" "Tf=10"];
+      xcos_simulate(scs_m, 4);
+      //get the variable created by the "from workspace block"
+      counter
+
+      ]]></programlisting>
+    </para>
+    <para>
+      Statistic analysis of the diagram using pre_xcos_simulate function.
+      <programlisting role="example"><![CDATA[
+importXcosDiagram("SCI/modules/xcos/demos/batch_simulation.xcos")
+
+typeof(scs_m) //The diagram data structure
+
+// Declare pre_xcos_simulation to only analyze Diagram.
+
+function continueSimulation=pre_xcos_simulate(scs_m, needcompile)
+    // Retrieve all objects
+    objs = scs_m.objs;
+
+    links = 0;
+    blocks = 0;
+    other = 0;
+    // Count Links and Blocks
+    for i = 1:size(objs)
+        currentType = typeof(objs(i));
+        select (currentType)
+        case "Link"
+            links = links + 1;
+        case "Block"
+            blocks = blocks + 1;
+        else
+            other = other + 1;
+        end
+    end
+
+        // Diplay Diagram analisys.
+        disp("Diagram Analysis:")
+        disp("Found "+string(blocks)+" Blocks.")
+        disp("Found "+string(links)+" Links.")
+        disp("Found "+string(other)+" Other component.")
+
+        // We do not want any simulation, just analyze Diagram
+        continueSimulation = %f;
+    endfunction
+
+    //first batch simulation with the parameters embedded in the diagram
+    xcos_simulate(scs_m, 4);
+      ]]></programlisting>
+    </para>
+    <para>
+      The xcos diagram: <literal>SCI/modules/xcos/demos/Command.xcos</literal>
+      <mediaobject><imageobject><imagedata align="center" fileref="../../images/Command.png"/></imageobject></mediaobject>
+      Simulate this diagram in batch mode and perform bode plotting of transfert function using post_xcos_simulate,
+      <programlisting role="example"><![CDATA[
+importXcosDiagram("SCI/modules/xcos/demos/Command.xcos")
+
+// Clear any pre_xcos_simulation;
+clear pre_xcos_simulate;
+
+function post_xcos_simulate(%cpr, scs_m, needcompile)
+    // Retrieve all objects
+    objs = scs_m.objs;
+
+    clrBlock = [];
+    //Looking for CLR block
+    for i=1:size(objs)
+        if objs(i).gui == "CLR" then
+            clrBlock = objs(i);
+            break;
+        end
+    end
+
+    // Check if we found some CLR
+    if isempty(clrBlock) then
+        disp("No CLR block found.")
+        return
+    end
+
+    // Retrieve exprs
+    exprs = clrBlock.graphics.exprs;
+    s = poly(0,'s');
+    num = eval(exprs(1));
+    den = eval(exprs(2));
+    h = syslin('c', num/den);
+    // Open new figure then plot Bode
+    scf(max(winsid())+1);
+    bode(h, 0.01, 100);
+endfunction
+
+xcos_simulate(scs_m, 4);
+
+      ]]></programlisting>
+    </para>
+   <para>
+      The xcos diagram: <literal>SCI/modules/xcos/demos/Command_bode.xcos</literal>
+      <mediaobject><imageobject><imagedata align="center" fileref="../../images/Command_bode.png"/></imageobject></mediaobject>
+      Simulate this diagram in batch mode and perform bode plotting of transfert function using post_xcos_simulate,
+      <programlisting role="example"><![CDATA[
+importXcosDiagram("SCI/modules/xcos/demos/Command_bode.xcos")
+
+// Clear any post_xcos_simulation;
+clear post_xcos_simulate;
+
+function continueSimulation = pre_xcos_simulate(scs_m, needcompile)
+    // Retrieve all objects
+    objs = scs_m.objs;
+
+    clrBlock = [];
+    //Looking for CLR block
+    for i=1:size(objs)
+        if objs(i).gui == "CLR" then
+            clrBlock = objs(i);
+            break;
+        end
+    end
+
+    // Check if we found some CLR
+    if isempty(clrBlock) then
+        disp("No CLR block found.")
+        return
+    end
+
+    // Retrieve exprs
+    exprs = clrBlock.graphics.exprs;
+    s = poly(0,'s');
+    num = eval(exprs(1));
+    den = eval(exprs(2));
+    h = syslin('c', num/den);
+    // Open new figure then plot Bode
+    scf(max(winsid())+1);
+    bode(h, 0.01, 100);
+
+    // Stop after bode plot. We do not want any simulation.
+    continueSimulation = %f;
+endfunction
+
+xcos_simulate(scs_m, 4);
+
+      ]]></programlisting>
+    </para>
+  </refsection>
+  <refsection id="SeeAlso_xcos_simulate">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="scicos_diagram">scs_m structure</link>
+      </member>
+      <member>
+        <link linkend="importXcosDiagram"> importXcosDiagram</link>
+      </member>
+      <member>
+        <link linkend="scicosim">scicosim: xcos batch simulation function</link>
+      </member>
+      <member>
+        <link linkend="xcos">xcos: Block diagram editor and GUI for the hybrid simulator</link>
+      </member>
+      <member>
+        <link linkend="steadycos">steadycos: Finds an equilibrium state of an xcos diagram</link>
+      </member>
+      <member>
+        <link linkend="lincos">lincos: Constructs by linearization a linear state-space model from an xcos diagram</link>
+      </member>
+    </simplelist>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/xcos/help/images/Command.png b/scilab/modules/xcos/help/images/Command.png
new file mode 100644 (file)
index 0000000..83c3227
Binary files /dev/null and b/scilab/modules/xcos/help/images/Command.png differ
diff --git a/scilab/modules/xcos/help/images/Command_bode.png b/scilab/modules/xcos/help/images/Command_bode.png
new file mode 100644 (file)
index 0000000..87bf012
Binary files /dev/null and b/scilab/modules/xcos/help/images/Command_bode.png differ
index 05a5c4e..7ba63e1 100644 (file)
@@ -20,14 +20,29 @@ function %cpr = xcos_simulate(scs_m, needcompile)
     end
   funcprot(prot);
 
+    // Hook according to SEP066
+    if isdef("pre_xcos_simulate") then
+      try
+      continueSimulation = pre_xcos_simulate(scs_m, needcompile);
+      if ~continueSimulation then
+        %cpr = []
+        return
+      end
+      catch
+      disp(_("Error occured in pre_xcos_simulate: Cancelling simulation."))
+      %cpr = []
+      return
+      end
+    end
+
   //**---- prepare from and to workspace stuff ( "From workspace" block )
   xcos_workspace_init()
 
+
 //** extract tolerances from scs_m.props.tol
   tolerances = scs_m.props.tol ;
   //** extract solver type from tolerances
-  solver = tolerances(6) ; 
+  solver = tolerances(6) ;
   //** initialize a "scicos_debug_gr" variable
   %scicos_debug_gr = %f;
 
@@ -45,39 +60,39 @@ function %cpr = xcos_simulate(scs_m, needcompile)
     %state0 = %cpr.state;
     alreadyran = %f;
   end
-  
+
   tf          = scs_m.props.tf;
   %zoom       = 1.4;
   Select      = [];
-  
+
   //** extract tolerances from scs_m.props.tol
   tolerances = scs_m.props.tol ;
   //** extract solver type from tolerances
-  solver = tolerances(6) ; 
+  solver = tolerances(6) ;
 
   // Propagate context through all blocks
   %scicos_context = struct();
   context = scs_m.props.context;
   //** context eval here
   [%scicos_context, ierr] = script2var(context, %scicos_context);
-  
+
   //for backward compatibility for scifunc
   if ierr==0 then
     %mm = getfield(1,%scicos_context)
     for %mi=%mm(3:$)
       ierr = execstr(%mi+'=%scicos_context(%mi)','errcatch')
       if ierr<>0 then
-       break; //** in case of error exit 
+       break; //** in case of error exit
       end
     end
   end
   //end of for backward compatibility for scifuncpagate context values
-  
+
   [scs_m,%cpr,needcompile,ok] = do_eval(scs_m, %cpr, %scicos_context);
   if ~ok then
     error(msprintf(gettext("%s: Error during block parameters evaluation.\n"), "xcos_simulate"));
   end
-  
+
   //** update parameters or compilation results
   [%cpr,%state0_n,needcompile,alreadyran,ok] = do_update(%cpr,%state0,needcompile)
   if ~ok then
@@ -124,12 +139,12 @@ function %cpr = xcos_simulate(scs_m, needcompile)
   if %cpr.sim.xptr($)-1<size(%cpr.state.x,'*') & solver<100 then
     message(["Diagram has been compiled for implicit solver"
              "switching to implicit Solver"])
-    solver = 100 ; //** Magic number 
+    solver = 100 ; //** Magic number
     tolerances(6) = solver ; //** save Magic number solver type
   elseif (%cpr.sim.xptr($)-1==size(%cpr.state.x,'*')) & (solver==100 & size(%cpr.state.x,'*')<>0) then
     message(["Diagram has been compiled for explicit solver"
              "switching to explicit Solver"])
-    solver = 0 ; //** Magic number 
+    solver = 0 ; //** Magic number
     tolerances(6) = solver ; //** save Magic number solver type
   end
 
@@ -146,15 +161,15 @@ function %cpr = xcos_simulate(scs_m, needcompile)
 
     select choix(to_do)
 
-      case "Continue" then 
+      case "Continue" then
         needstart = %f ;
         state     = %cpr.state ;
 
-      case "Restart" then 
+      case "Restart" then
         needstart = %t ;
         state     = %state0 ;
 
-      case "End" then 
+      case "End" then
         state     = %cpr.state ;
         needstart = %t ;
         tf        = scs_m.props.tf;
@@ -187,11 +202,11 @@ function %cpr = xcos_simulate(scs_m, needcompile)
           end
           ok = %f
         end
-       
+
         return
     end
-  
-  else //** Normal first start simulation 
+
+  else //** Normal first start simulation
 
     needstart = %t
     state     = %state0
@@ -212,18 +227,18 @@ function %cpr = xcos_simulate(scs_m, needcompile)
     %tcur      = 0
     %cpr.state = %state0
     tf         = scs_m.props.tf;
-    if tf*tolerances==[] then 
+    if tf*tolerances==[] then
       message(["Simulation parameters not set";"use setup button"]);
       return;
     end
 
-    //** Run the normal first start simulation here 
+    //** Run the normal first start simulation here
 
     //** run scicosim via 'start' flag
     ierr = execstr('[state,t]=scicosim(%cpr.state,%tcur,tf,%cpr.sim,'+..
                    '''start'',tolerances)','errcatch')
 
-    %cpr.state = state ; //** save the state 
+    %cpr.state = state ; //** save the state
     //** error case
     if ierr<>0 then
       str_err=split_lasterror(lasterror());
@@ -235,7 +250,7 @@ function %cpr = xcos_simulate(scs_m, needcompile)
         //** get error cmd for the block
         disp(str_err);
         get_errorcmd(path,gettext('Initialisation problem'),str_err);
-        
+
 
       else //** simulator error
         message(['Initialisation problem:';str_err])
@@ -262,7 +277,7 @@ function %cpr = xcos_simulate(scs_m, needcompile)
                     '''run'',tolerances)','errcatch')
 
   %cpr.state = state
-  
+
   //** no error
   if ierr==0 then
     alreadyran = %t;
@@ -318,7 +333,7 @@ function %cpr = xcos_simulate(scs_m, needcompile)
     end
     ok = %f;
   end
-  
+
   //restore saved variables in Scilab environment ( "To workspace" block )
   [txt,files]=returntoscilab()
   n=size(files,1)
@@ -328,6 +343,15 @@ function %cpr = xcos_simulate(scs_m, needcompile)
   end
   execstr(txt)
 
+    // Hook according to SEP066
+    if isdef("post_xcos_simulate") then
+      try
+      post_xcos_simulate(%cpr, scs_m, needcompile);
+      catch
+      disp(_("Error in post_xcos_simulate: ending simulation."))
+      end
+    end
+
   needreplay = resume(needreplay);
 endfunction
 
diff --git a/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_bad_hooks.dia.ref b/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_bad_hooks.dia.ref
new file mode 100644 (file)
index 0000000..40a0b87
--- /dev/null
@@ -0,0 +1,30 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+//
+// This file is distributed under the same license as the Scilab package.
+// <-- TEST WITH XCOS -->
+//
+// <-- Short Description -->
+// Check the API of the Xcos hooks, see SEP_066_Xcos_hooks.odt
+loadXcosLibs();
+global status;
+status = [];
+function continueSimulation = pre_xcos_simulate(scs_m, needcompile)
+  global status;
+  1 + "string"
+  status = [status 'pre_called'];
+endfunction
+function post_xcos_simulate(%cpr, scs_m, needcompile)
+  global status;
+  1 + "string"
+  status = [status 'post_called'];
+endfunction
+assert_checktrue(importXcosDiagram(SCI + "/modules/xcos/demos/Simple_Demo.xcos"));
+xcos_simulate(scs_m, 4);
+ Error occured in pre_xcos_simulate: proceeding with simulation anyway. 
+ Error in post_xcos_simulate: ending simulation.   
+assert_checkequal(status, [])
+ ans  =
+  T  
diff --git a/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_bad_hooks.tst b/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_bad_hooks.tst
new file mode 100644 (file)
index 0000000..467b340
--- /dev/null
@@ -0,0 +1,32 @@
+// 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 the Xcos hooks, see SEP_066_Xcos_hooks.odt
+
+loadXcosLibs();
+global status;
+status = [];
+
+function continueSimulation = pre_xcos_simulate(scs_m, needcompile)
+  global status;
+
+  1 + "string"
+  status = [status 'pre_called'];
+endfunction
+
+function post_xcos_simulate(%cpr, scs_m, needcompile)
+  global status;
+
+  1 + "string"
+  status = [status 'post_called'];
+endfunction
+
+assert_checktrue(importXcosDiagram(SCI + "/modules/xcos/demos/Simple_Demo.xcos"));
+xcos_simulate(scs_m, 4);
+
+assert_checkequal(status, [])
diff --git a/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_hooks.dia.ref b/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_hooks.dia.ref
new file mode 100644 (file)
index 0000000..57046b8
--- /dev/null
@@ -0,0 +1,30 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+//
+// This file is distributed under the same license as the Scilab package.
+// <-- TEST WITH XCOS -->
+//
+// <-- Short Description -->
+// Check the API of the Xcos hooks, see SEP_066_Xcos_hooks.odt
+loadXcosLibs();
+global status;
+status = [];
+function continueSimulation = pre_xcos_simulate(scs_m, needcompile)
+        global status;
+        status = [status 'pre_called'];
+        continueSimulation = %t;
+endfunction
+function post_xcos_simulate(%cpr, scs_m, needcompile)
+        global status;
+        // check that the simulation has been run
+        f=gcf();
+        a=gca();
+        p=a.children(1);
+        assert_checkalmostequal(p.data($,1), 29.9);
+        status = [status 'post_called'];
+endfunction
+assert_checktrue(importXcosDiagram(SCI + "/modules/xcos/demos/Simple_Demo.xcos"));
+xcos_simulate(scs_m, 4);
+assert_checkequal(status, ["pre_called" "post_called"])
+ ans  =
+  T  
diff --git a/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_hooks.tst b/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_hooks.tst
new file mode 100644 (file)
index 0000000..871cf58
--- /dev/null
@@ -0,0 +1,38 @@
+// 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 the Xcos hooks, see SEP_066_Xcos_hooks.odt
+
+loadXcosLibs();
+global status;
+status = [];
+
+function continueSimulation = pre_xcos_simulate(scs_m, needcompile)
+        global status;
+
+        status = [status 'pre_called'];
+        continueSimulation = %t;
+endfunction
+
+function post_xcos_simulate(%cpr, scs_m, needcompile)
+        global status;
+
+        // check that the simulation has been run
+        f=gcf();
+        a=gca();
+        p=a.children(1);
+        assert_checkalmostequal(p.data($,1), 29.9);
+
+        status = [status 'post_called'];
+endfunction
+
+assert_checktrue(importXcosDiagram(SCI + "/modules/xcos/demos/Simple_Demo.xcos"));
+xcos_simulate(scs_m, 4);
+
+assert_checkequal(status, ["pre_called" "post_called"])
+
diff --git a/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_stop_hooks.dia.ref b/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_stop_hooks.dia.ref
new file mode 100644 (file)
index 0000000..4f0a4ba
--- /dev/null
@@ -0,0 +1,30 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+//
+// This file is distributed under the same license as the Scilab package.
+// <-- TEST WITH XCOS -->
+//
+// <-- Short Description -->
+// Check the API of the Xcos hooks, see SEP_066_Xcos_hooks.odt
+loadXcosLibs();
+global status;
+status = [];
+function continueSimulation = pre_xcos_simulate(scs_m, needcompile)
+        global status;
+        status = [status 'pre_called'];
+        continueSimulation = %f;
+endfunction
+function post_xcos_simulate(%cpr, scs_m, needcompile)
+        global status;
+        // check that the simulation has been run
+        f=gcf();
+        a=gca();
+        p=a.children(1);
+        assert_checkalmostequal(p.data($,1), 29.9);
+        status = [status 'post_called'];
+endfunction
+assert_checktrue(importXcosDiagram(SCI + "/modules/xcos/demos/Simple_Demo.xcos"));
+xcos_simulate(scs_m, 4);
+assert_checkequal(status, ["pre_called"])
+ ans  =
+  T  
diff --git a/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_stop_hooks.tst b/scilab/modules/xcos/tests/unit_tests/SEP_066_Xcos_stop_hooks.tst
new file mode 100644 (file)
index 0000000..34e6e28
--- /dev/null
@@ -0,0 +1,38 @@
+// 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 the Xcos hooks, see SEP_066_Xcos_hooks.odt
+
+loadXcosLibs();
+global status;
+status = [];
+
+function continueSimulation = pre_xcos_simulate(scs_m, needcompile)
+        global status;
+
+        status = [status 'pre_called'];
+        continueSimulation = %f;
+endfunction
+
+function post_xcos_simulate(%cpr, scs_m, needcompile)
+        global status;
+
+        // check that the simulation has been run
+        f=gcf();
+        a=gca();
+        p=a.children(1);
+        assert_checkalmostequal(p.data($,1), 29.9);
+
+        status = [status 'post_called'];
+endfunction
+
+assert_checktrue(importXcosDiagram(SCI + "/modules/xcos/demos/Simple_Demo.xcos"));
+xcos_simulate(scs_m, 4);
+
+assert_checkequal(status, ["pre_called"])
+