Scicos_blocks macros: fix SELF_SWITCH for Xcos 6
[scilab.git] / scilab / modules / scicos_blocks / macros / Branching / SELF_SWITCH.sci
1 //
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET
4 //
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution.  The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10 //
11 //
12 function [x,y,typ]=SELF_SWITCH(job,arg1,arg2)
13     function diagram = genSwitchInnerDiagram(stateOpen)
14         diagram = scicos_diagram();
15         // Input forward
16         diagram.objs(1) = IN_f("define");
17
18         // Output's forward
19         diagram.objs(2)=OUT_f("define");
20
21         diagram.objs(3)=CONST_m("define");
22         diagram.objs(3).graphics.exprs = "0";
23         diagram.objs(3).model.rpar = 0;
24
25         diagram.objs(4)=SWITCH_f("define");
26         if stateOpen == %t
27             diagram.objs(4).model.ipar = 1;
28             diagram.objs(4).graphics.exprs = ["2";"2"];
29         else
30             diagram.objs(4).model.ipar = 0;
31             diagram.objs(4).graphics.exprs = ["2";"1"];
32         end
33
34         // IN_f <-> SWITCH_f
35         diagram.objs(5) = scicos_link(xx=[0, 0], yy=[0, 0], from=[1, 1], to=[4, 1]);
36         // CONST_m <-> SWITCH_f
37         diagram.objs(6) = scicos_link(xx=[0, 0], yy=[0, 0], from=[3, 1], to=[4, 2]);
38         // SWITCH_f <-> OUT_f
39         diagram.objs(7) = scicos_link(xx=[0, 0], yy=[0, 0], from=[4, 1], to=[2, 1]);
40     endfunction
41     select job
42     case "set" then
43         x = arg1;
44         stateOpen = x.model.opar(1);
45         x.model.rpar = genSwitchInnerDiagram(~stateOpen);
46         x.model.opar = list(~stateOpen);
47         y = 0;
48         typ=list();
49         if stateOpen == %f
50             x.graphics.style="SELF_SWITCH_OFF"
51         else
52             x.graphics.style="SELF_SWITCH_ON"
53         end
54
55     case "define"
56         // By default SWITCH is open
57         stateOpen = %t;
58         x = scicos_block()
59         x.gui="SELF_SWITCH"
60         x.graphics.sz=[2,2]
61         x.graphics.gr_i=[]
62         x.graphics.pin=0
63         x.graphics.pout=0
64         x.model.sim="csuper"
65         x.model.in = 1
66         x.model.out = 1
67         x.model.blocktype="h"
68         x.model.dep_ut=[%f %f]
69         x.model.rpar = genSwitchInnerDiagram(stateOpen);
70         x.model.opar = list(stateOpen);
71         x.graphics.in_implicit=["E"]
72         x.graphics.in_style=""
73         x.graphics.out_implicit=["E"];
74         x.graphics.out_style=""
75         x.graphics.style="SELF_SWITCH_OFF"
76     end
77 endfunction