Scicos_blocks macros: proper object comparison
[scilab.git] / scilab / modules / scicos_blocks / macros / Sources / FROMWSB.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] = FROMWSB(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 == "FROMWS_c" 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.odstate,model_n.odstate)|..
57                     ~isequal(model.rpar,model_n.rpar)|..
58                     ~isequal(model.ipar,model_n.ipar)|..
59                     ~isequal(model.opar,model_n.opar)|..
60                     ~isequal(model.label,model_n.label)
61                     if or(model.in<>model_n.in)|or(model.out<>model_n.out)|..
62                         or(model.in2<>model_n.in2)|or(model.out2<>model_n.out2)|..
63                         or(model.outtyp<>model_n.outtyp)|or(model.intyp<>model_n.intyp) then
64                         needcompile=1
65                     end
66                     if or(model.firing<>model_n.firing) then
67                         needcompile=2
68                     end
69                     if (size(model.in,"*")<>size(model_n.in,"*"))|..
70                         (size(model.out,"*")<>size(model_n.out,"*")) then
71                         needcompile=4
72                     end
73                     if model.sim=="input"|model.sim=="output" then
74                         if model.ipar<>model_n.ipar then
75                             needcompile=4
76                         end
77                     end
78                     if or(model.blocktype<>model_n.blocktype)|..
79                         or(model.dep_ut<>model_n.dep_ut) then
80                         needcompile=4
81                     end
82                     if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then
83                         needcompile=4
84                     end
85                     if prod(size(model_n.sim))>1 then
86                         if model_n.sim(2)>1000 then
87                             if model.sim(1)<>model_n.sim(1) then
88                                 needcompile=4
89                             end
90                         end
91                     end
92                 else
93                     modified=or(model_n<>model)
94                     eq=model.equations;eqn=model_n.equations;
95                     if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|..
96                         or(eq.outputs<>eqn.outputs) then
97                         needcompile=4
98                     end
99                 end
100                 //parameter or states changed
101                 arg1(spath)=xxn// Update
102                 newpar(size(newpar)+1)=path// Notify modification
103                 y=max(y,needcompile)
104             end
105         end
106         x=arg1
107         typ=newpar
108     case "define" then
109         scs_m_1=scicos_diagram(..
110         version="scicos4.2",..
111         props=scicos_params(..
112         wpar=[-159.096,811.104,-121.216,617.984,1323,1008,331,284,630,480,1426,231,1.4],..
113         Title="FROMWSB",..
114         tol=[0.0001,0.000001,1.000D-10,100001,0,0],..
115         tf=100000,..
116         context=" ",..
117         void1=[],..
118         options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],..
119         list([5,1],[4,1]),[0.8,0.8,0.8]),..
120         void2=[],..
121         void3=[],..
122         doc=list()))
123         scs_m_1.objs(1)=scicos_block(..
124         gui="FROMWS_c",..
125         graphics=scicos_graphics(..
126         orig=[260.37067,261.584],..
127         sz=[70,40],..
128         exprs=["V";"1";"1";"0"],..
129         pin=[],..
130         pout=4,..
131         pein=2,..
132         peout=2,..
133         gr_i=[],..
134         id="",..
135         in_implicit=[],..
136         out_implicit="E"),..
137         model=scicos_model(..
138         sim=list("fromws_c",4),..
139         in=[],..
140         in2=[],..
141         intyp=1,..
142         out=-1,..
143         out2=-2,..
144         outtyp=-1,..
145         evtin=1,..
146         evtout=1,..
147         state=[],..
148         dstate=[],..
149         odstate=list(),..
150         rpar=[],..
151         ipar=[1;-31;1;1;0],..
152         opar=list(),..
153         blocktype="d",..
154         firing=0,..
155         dep_ut=[%f,%t],..
156         label="",..
157         nzcross=0,..
158         nmode=0,..
159         equations=list()),..
160         doc=list())
161         scs_m_1.objs(2)=scicos_link(..
162         xx=[295.37067;295.37067;233.23733;233.23733;295.37067;295.37067],..
163         yy=[255.86971;223.45067;223.45067;337.85067;337.85067;307.29829],..
164         id="drawlink",..
165         thick=[0,0],..
166         ct=[5,-1],..
167         from=[1,1,0],..
168         to=[1,1,1])
169         scs_m_1.objs(3)=scicos_block(..
170         gui="OUT_f",..
171         graphics=scicos_graphics(..
172         orig=[358.9421,271.584],..
173         sz=[20,20],..
174         exprs="1",..
175         pin=4,..
176         pout=[],..
177         pein=[],..
178         peout=[],..
179         gr_i=[],..
180         id="",..
181         in_implicit="E",..
182         out_implicit=[]),..
183         model=scicos_model(..
184         sim="output",..
185         in=-1,..
186         in2=-2,..
187         intyp=-1,..
188         out=[],..
189         out2=[],..
190         outtyp=1,..
191         evtin=[],..
192         evtout=[],..
193         state=[],..
194         dstate=[],..
195         odstate=list(),..
196         rpar=[],..
197         ipar=1,..
198         opar=list(),..
199         blocktype="c",..
200         firing=[],..
201         dep_ut=[%f,%f],..
202         label="",..
203         nzcross=0,..
204         nmode=0,..
205         equations=list()),..
206         doc=list())
207         scs_m_1.objs(4)=scicos_link(..
208         xx=[338.9421;358.9421],..
209         yy=[281.584;281.584],..
210         id="drawlink",..
211         thick=[0,0],..
212         ct=[1,1],..
213         from=[1,1,0],..
214         to=[3,1,1])
215         model=scicos_model(..
216         sim="csuper",..
217         in=[],..
218         in2=[],..
219         intyp=1,..
220         out=-1,..
221         out2=-2,..
222         outtyp=1,..
223         evtin=[],..
224         evtout=[],..
225         state=[],..
226         dstate=[],..
227         odstate=list(),..
228         rpar=scs_m_1,..
229         ipar=[],..
230         opar=list(),..
231         blocktype="h",..
232         firing=[],..
233         dep_ut=[%f,%f],..
234         label="",..
235         nzcross=0,..
236         nmode=0,..
237         equations=list())
238         //## modif made by hand
239         gr_i=[]
240         x=standard_define([5 2],model,[],gr_i)
241     end
242 endfunction