Scicos_blocks macros: proper object comparison
[scilab.git] / scilab / modules / scicos_blocks / macros / Events / freq_div.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]=freq_div(job,arg1,arg2)
23     x=[];
24     y=[];
25     typ=[];
26     select job
27     case "set" then
28         // look for the modulo 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 == "Modulo_Count" then
32                 path = i;
33                 break;
34             end
35         end
36
37         // paths to updatable parameters or states
38         newpar=list();
39         y=0;
40         spath=list()
41         spath($+1)="model"
42         spath($+1)="rpar"
43         spath($+1)="objs"
44         spath($+1)=path
45
46         xx=arg1(spath)// get the block
47         //execstr('xxn='+xx.gui+'(''set'',xx)')
48         xxn=xx;
49         graphics=xx.graphics;
50         exprs=graphics.exprs
51         model=xx.model;
52         while %t do
53             [ok,%ph,%df,exprs]=scicos_getvalue..
54             ("Set frequency division block parameters",..
55             ["Phase (0 to division factor -1)";"Division factor"],..
56             list("vec",1,"vec",1),exprs)
57             if ~ok then
58                 break,
59             end
60             if ok then
61                 if %df<1 then
62                     %df=1,
63                 end
64                 %ph=abs(%ph)
65                 if %ph>%df-1 then
66                     %ph=%df-1,
67                 end
68                 graphics.exprs=exprs
69                 model.ipar=%df;
70                 model.dstate=%ph;
71                 xxn.graphics=graphics;
72                 xxn.model=model
73                 break
74             end
75         end
76
77
78         if or(xxn<>xx) then
79             model=xx.model
80             model_n=xxn.model
81             if ~is_modelica_block(xx) then
82                 modified=or(model.sim<>model_n.sim)|..
83                 ~isequal(model.state,model_n.state)|..
84                 ~isequal(model.dstate,model_n.dstate)|..
85                 ~isequal(model.rpar,model_n.rpar)|..
86                 ~isequal(model.ipar,model_n.ipar)|..
87                 ~isequal(model.label,model_n.label)
88                 if or(model.in<>model_n.in)|or(model.out<>model_n.out) then
89                     needcompile=1
90                 end
91                 if or(model.firing<>model_n.firing)  then
92                     needcompile=2
93                 end
94                 if model.sim=="input"|model.sim=="output" then
95                     if model.ipar<>model_n.ipar then
96                         needcompile=4
97                     end
98                 end
99                 if or(model.blocktype<>model_n.blocktype)|..
100                     or(model.dep_ut<>model_n.dep_ut)  then
101                     needcompile=4
102                 end
103                 if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then
104                     needcompile=4
105                 end
106                 if prod(size(model_n.sim))>1 then
107                     if model_n.sim(2)>1000 then
108                         if model.sim(1)<>model_n.sim(1) then
109                             needcompile=4
110                         end
111                     end
112                 end
113             else
114                 modified=or(model_n<>model)
115                 eq=model.equations;eqn=model_n.equations;
116                 if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|..
117                     or(eq.outputs<>eqn.outputs) then
118                     needcompile=4
119                 end
120             end
121             // parameter or states changed
122             arg1(spath)=xxn// Update
123             newpar(size(newpar)+1)=1// Notify modification
124             y=max(y,needcompile)
125         end
126         x=arg1
127         typ=newpar
128     case "define" then
129         scs_m_1=scicos_diagram();
130         scs_m_1.objs(1) = Modulo_Count("define");
131         scs_m_1.objs(2) = CLKINV_f("define");
132         scs_m_1.objs(3) = CLKOUTV_f("define");
133         scs_m_1.objs(4) = IFTHEL_f("define");
134         scs_m_1.objs(5) = CLKSPLIT_f("define");
135         scs_m_1.objs(6) = scicos_link();
136         scs_m_1.objs(7) = scicos_link();
137         scs_m_1.objs(8) = scicos_link();
138         scs_m_1.objs(9) = scicos_link();
139         scs_m_1.objs(10) = scicos_link();
140
141         // Modulo_Count
142         blk = scs_m_1.objs(1);
143         graphics = blk.graphics;
144         model = blk.model;
145
146         graphics.orig = [0 -100];
147         graphics.sz = [60 40];
148
149         graphics.exprs = ["0";"3"];
150         model.dstate = 3;
151         model.ipar = 3;
152
153         graphics.pout = 7;
154         graphics.pein = 10;
155
156         blk.graphics = graphics;
157         blk.model = model;
158         scs_m_1.objs(1) = blk;
159
160         // CLKINV_f
161         blk = scs_m_1.objs(2);
162         graphics = blk.graphics;
163         model = blk.model;
164
165         graphics.orig = [120 0];
166         graphics.sz = [20 20];
167
168         graphics.exprs = ["1"];
169         model.ipar = 1;
170
171         graphics.peout = 6;
172
173         blk.graphics = graphics;
174         blk.model = model;
175         scs_m_1.objs(2) = blk;
176
177         // CLKOUTV_f
178         blk = scs_m_1.objs(3);
179         graphics = blk.graphics;
180         model = blk.model;
181
182         graphics.orig = [130 -160];
183         graphics.sz = [20 20];
184
185         graphics.exprs = ["1"];
186         model.ipar = 1;
187
188         graphics.pein = 8;
189
190         blk.graphics = graphics;
191         blk.model = model;
192         scs_m_1.objs(3) = blk;
193
194         // IFTHEL_f
195         blk = scs_m_1.objs(4);
196         graphics = blk.graphics;
197         model = blk.model;
198
199         graphics.orig = [100 -100];
200         graphics.sz = [60 40];
201
202         graphics.exprs = ["1";"0"];
203         model.ipar = 1;
204
205         graphics.pin = 7;
206         graphics.pein = 9;
207         graphics.peout = [0;8];
208
209         blk.graphics = graphics;
210         blk.model = model;
211         scs_m_1.objs(4) = blk;
212
213         // CLKSPLIT_f
214         blk = scs_m_1.objs(5);
215         graphics = blk.graphics;
216         model = blk.model;
217
218         graphics.orig = [127 -33];
219         graphics.sz = [7 7];
220
221         graphics.pein = 6;
222         graphics.peout = [9;10];
223
224         blk.graphics = graphics;
225         blk.model = model;
226         scs_m_1.objs(5) = blk;
227
228         // CLKINV_f -> CLKSPLIT_f
229         lnk = scs_m_1.objs(6);
230
231         lnk.ct = [5 -1];
232         lnk.from = [2 1 0];
233         lnk.to = [5 1 1];
234
235         scs_m_1.objs(6) = lnk;
236
237         // Modulo_Count -> IFTHEL_f
238         lnk = scs_m_1.objs(7);
239
240         lnk.from = [1 1 0];
241         lnk.to = [4 1 1];
242
243         scs_m_1.objs(7) = lnk;
244
245         // IFTHEL_f -> CLKOUTV_f
246         lnk = scs_m_1.objs(8);
247
248         lnk.ct = [5 -1];
249         lnk.from = [4 2 0];
250         lnk.to = [3 1 1];
251
252         scs_m_1.objs(8) = lnk;
253
254         // CLKSPLIT_f -> IFTHEL_f
255         lnk = scs_m_1.objs(9);
256
257         lnk.ct = [5 -1];
258         lnk.from = [5 1 0];
259         lnk.to = [4 1 1];
260
261         scs_m_1.objs(9) = lnk;
262
263         // CLKSPLIT_f -> Modulo_Count
264         lnk = scs_m_1.objs(10);
265
266         lnk.xx = [0 30 1];
267         lnk.yy = [0 -30 1];
268
269         lnk.ct = [5 -1];
270         lnk.from = [5 2 0];
271         lnk.to = [1 1 1];
272
273         scs_m_1.objs(10) = lnk;
274
275         clear blk lnk
276
277         model=scicos_model();
278         model.sim = "csuper";
279         model.evtin = 1;
280         model.evtout = 1;
281         model.rpar = scs_m_1;
282
283         gr_i=[];
284         x=standard_define([3 2],model,[],gr_i)
285     end
286 endfunction
287