Scicos_blocks macros: proper object comparison
[scilab.git] / scilab / modules / scicos_blocks / macros / Misc / EDGE_TRIGGER.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]=EDGE_TRIGGER(job,arg1,arg2)
23     x=[];
24     y=[];
25     typ=[];
26     select job
27     case "set" then
28         // look for the internal edge trigger 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 == "EDGETRIGGER" then
32                 ppath = list(i);
33                 break;
34             end
35         end
36         newpar=list();
37         y=0;
38         for path=ppath do
39             np=size(path,"*")
40             spath=list()
41             for k=1:np
42                 spath($+1)="model"
43                 spath($+1)="rpar"
44                 spath($+1)="objs"
45                 spath($+1)=path(k)
46             end
47             xx=arg1(spath)// get the block
48             execstr("xxn="+xx.gui+"(''set'',xx)")
49             if or(xxn<>xx) then
50                 model=xx.model
51                 model_n=xxn.model
52                 if ~is_modelica_block(xx) then
53                     modified=or(model.sim<>model_n.sim)|..
54                     ~isequal(model.state,model_n.state)|..
55                     ~isequal(model.dstate,model_n.dstate)|..
56                     ~isequal(model.rpar,model_n.rpar)|..
57                     ~isequal(model.ipar,model_n.ipar)|..
58                     ~isequal(model.label,model_n.label)
59                     if or(model.in<>model_n.in)|or(model.out<>model_n.out) then
60                         needcompile=1
61                     end
62                     if or(model.firing<>model_n.firing)  then
63                         needcompile=2
64                     end
65                     if (size(model.in,"*")<>size(model_n.in,"*"))|..
66                         (size(model.out,"*")<>size(model_n.out,"*")) then
67                         needcompile=4
68                     end
69                     if model.sim=="input"|model.sim=="output" then
70                         if model.ipar<>model_n.ipar then
71                             needcompile=4
72                         end
73                     end
74                     if or(model.blocktype<>model_n.blocktype)|..
75                         or(model.dep_ut<>model_n.dep_ut)  then
76                         needcompile=4
77                     end
78                     if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then
79                         needcompile=4
80                     end
81                     if prod(size(model_n.sim))>1 then
82                         if model_n.sim(2)>1000 then
83                             if model.sim(1)<>model_n.sim(1) then
84                                 needcompile=4
85                             end
86                         end
87                     end
88                 else
89                     modified=or(model_n<>model)
90                     eq=model.equations;eqn=model_n.equations;
91                     if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|..
92                         or(eq.outputs<>eqn.outputs) then
93                         needcompile=4
94                     end
95                 end
96                 // parameter or states changed
97                 arg1(spath)=xxn// Update
98                 newpar(size(newpar)+1)=path// Notify modification
99                 y=max(y,needcompile)
100             end
101         end
102         x=arg1
103         typ=newpar
104     case "define" then
105         scs_m_1=scicos_diagram();
106         scs_m_1.objs(1) = EDGETRIGGER("define");
107         scs_m_1.objs(2) = IFTHEL_f("define");
108         scs_m_1.objs(3) = IN_f("define");
109         scs_m_1.objs(4) = CLKOUTV_f("define");
110         scs_m_1.objs(5) = scicos_link();
111         scs_m_1.objs(6) = scicos_link();
112         scs_m_1.objs(7) = scicos_link();
113
114         // EDGETRIGGER
115         blk = scs_m_1.objs(1);
116         graphics = blk.graphics;
117         model = blk.model;
118
119         graphics.orig = [60 0];
120         graphics.sz = [60 40];
121
122         graphics.exprs = "0";
123         model.ipar = 0;
124
125         graphics.pin = 5;
126         graphics.pout = 6;
127
128         blk.graphics = graphics;
129         blk.model = model;
130         scs_m_1.objs(1) = blk;
131
132         // IFTHEL_f
133         blk = scs_m_1.objs(2);
134         graphics = blk.graphics;
135         model = blk.model;
136
137         graphics.orig = [160 0];
138         graphics.sz = [60 40];
139
140         graphics.exprs = ["0";"0"];
141         model.evtin = [];
142         model.nzcross = 0;
143         model.nmode = 0;
144
145         graphics.pin = 6;
146         graphics.peout = [7;0];
147
148         blk.graphics = graphics;
149         blk.model = model;
150         scs_m_1.objs(2) = blk;
151
152         // IN_f
153         blk = scs_m_1.objs(3);
154         graphics = blk.graphics;
155         model = blk.model;
156
157         graphics.orig = [0 10];
158         graphics.sz = [20 20];
159
160         graphics.exprs = ["1"];
161         model.ipar = 1;
162
163         graphics.pout = 5;
164
165         blk.graphics = graphics;
166         blk.model = model;
167         scs_m_1.objs(3) = blk;
168
169         // CLKOUTV_f
170         blk = scs_m_1.objs(4);
171         graphics = blk.graphics;
172         model = blk.model;
173
174         graphics.orig = [170 -60];
175         graphics.sz = [20 20];
176
177         graphics.exprs = ["1"];
178         model.ipar = 1;
179
180         graphics.pein = 7;
181
182         blk.graphics = graphics;
183         blk.model = model;
184         scs_m_1.objs(4) = blk;
185
186         // IN_f -> EDGETRIGGER
187         lnk = scs_m_1.objs(5);
188
189         lnk.from = [3 1 0];
190         lnk.to = [1 1 1];
191
192         scs_m_1.objs(5) = lnk;
193
194         // EDGETRIGGER -> IFTHEL_f
195         lnk = scs_m_1.objs(6);
196
197         lnk.from = [1 1 0];
198         lnk.to = [2 1 1];
199
200         scs_m_1.objs(6) = lnk;
201
202         // IFTHEL_f -> CLKOUTV_f
203         lnk = scs_m_1.objs(7);
204
205         lnk.ct = [5 -1];
206         lnk.from = [2 1 0];
207         lnk.to = [4 1 1];
208
209         scs_m_1.objs(7) = lnk;
210
211         clear blk lnk
212
213         model=scicos_model();
214         model.sim = "csuper";
215         model.in = 1;
216         model.evtout = 1;
217         model.rpar = scs_m_1;
218
219         gr_i=[];
220         x=standard_define([3 2],model,[],gr_i)
221     end
222 endfunction
223