Scicos_blocks macros: proper object comparison
[scilab.git] / scilab / modules / scicos_blocks / macros / Events / MCLOCK_f.sci
1 //  Scicos
2 //
3 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //
19 // See the file ../license.txt
20 //
21
22 function [x,y,typ]=MCLOCK_f(job,arg1,arg2)
23     x=[];
24     y=[];
25     typ=[];
26     select job
27     case "set" then
28         // look for the clock block
29         for i=1:length(arg1.model.rpar.objs) do
30             o = arg1.model.rpar.objs(i);
31             if typeof(o) == "Block" & o.gui == "MFCLCK_f" then
32                 path = i;
33                 break;
34             end
35         end
36
37         newpar=list();
38         spath=list("model","rpar","objs",path)
39         xx=arg1(spath)// get the block
40         execstr("xxn="+xx.gui+"(''set'',xx)")
41         if or(xxn<>xx) then
42             // parameter or states changed
43             arg1(spath)=xxn// Update
44             newpar(size(newpar)+1)=path// Notify modification
45         end
46         x=arg1
47         y=0
48         typ=newpar
49     case "define" then
50         nn=2
51         dt=0.1
52         exprs=[string(dt);string(nn)]
53
54         mfclck=MFCLCK_f("define")
55         mfclck.graphics.orig=[334,199]
56         mfclck.graphics.sz=[40,40]
57         mfclck.graphics.exprs=exprs
58         mfclck.graphics.pein=12
59         mfclck.graphics.peout=[4;3]
60         mfclck.model.rpar=0.1
61         mfclck.model.ipar=nn
62         mfclck.model.firing=[-1 0]
63
64         clksom=CLKSOM_f("define")
65         clksom.graphics.orig=[457,161]
66         clksom.graphics.sz=[16.666667,16.666667]
67         clksom.graphics.exprs=["0.1";"0.1"]
68         clksom.graphics.pein=[4;9;0]
69         clksom.graphics.peout=5
70
71         output_port1=CLKOUT_f("define")
72         output_port1.graphics.orig=[509,261]
73         output_port1.graphics.sz=[20,20]
74         output_port1.graphics.exprs="1"
75         output_port1.graphics.pein=10
76         output_port1.model.ipar=1
77
78         output_port2=CLKOUT_f("define")
79         output_port2.graphics.orig=[509,142]
80         output_port2.graphics.sz=[20,20]
81         output_port2.graphics.exprs="2"
82         output_port2.graphics.pein=13
83         output_port2.model.ipar=2
84
85
86         split1=CLKSPLIT_f("define")
87         split1.graphics.orig=[411.92504;169.33333]
88         split1.graphics.pein=3,
89         split1.graphics.peout=[9;10]
90
91         split2=CLKSPLIT_f("define")
92         split2.graphics.orig=[482.45315;169.33333]
93         split2.graphics.pein=5
94         split2.graphics.peout=[12;13]
95
96         gr_i=[]
97
98         diagram=scicos_diagram();
99         diagram.objs(1)=mfclck
100         diagram.objs(2)=clksom
101         diagram.objs(3)=scicos_link(xx=[360.7;360.7;411.9],..
102         yy=[193.3;169.3;169.3],..
103         ct=[10,-1],from=[1,2],to=[8,1])
104         diagram.objs(4)=scicos_link(xx=[347.3;347.3;461.8;461.8],..
105         yy=[193.3;155.5;155.5;161],..
106         ct=[10,-1],from=[1,1],to=[2,1])
107         diagram.objs(5)=scicos_link(xx=[468.9;482.5],yy=[169.3;169.3],..
108         ct=[10,-1],from=[2,1],to=[11,1])
109
110         diagram.objs(6)=output_port1
111         diagram.objs(7)=output_port2
112         diagram.objs(8)=split1
113
114         diagram.objs(9)=scicos_link(xx=[411.9;457],..
115         yy=[169.3;169.3],..
116         ct=[10,-1],from=[8,1],to=[2,2])
117         diagram.objs(10)=scicos_link(xx=[411.9;411.9;509],yy=[169.3;271;271],..
118         ct=[10,-1],from=[8,2],to=[6,1])
119
120         diagram.objs(11)=split2
121
122         diagram.objs(12)=scicos_link(xx=[482.5;489.6;489.6;354;354],..
123         yy=[169.3;169.3;338.3;338.3;244.7],..
124         ct=[10,-1],from=[11,1],to=[1,1])
125         diagram.objs(13)=scicos_link(xx=[482.4;482.4;509],yy=[169.3;152;152],..
126         ct=[10,-1],from=[11,2],to=[7,1])
127         x=scicos_block()
128         x.gui="MCLOCK_f"
129         x.graphics.sz=[3,2]
130         x.graphics.gr_i=gr_i
131         x.model.sim="csuper"
132         x.model.evtout=[1;1]
133         x.model.blocktype="h"
134         x.model.rpar=diagram
135         x.graphics.peout=[0;0]
136     end
137 endfunction