8d7c98ec961b524d80e23c656292127ab0cd0cb2
[scilab.git] / scilab / modules / scicos_blocks / macros / Misc / ENDBLK.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]=ENDBLK(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 == "END_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,"*"))|..
71                         (size(model.evtin,"*")<>size(model_n.evtin,"*")) then
72                         needcompile=4
73                     end
74                     if model.sim=="input"|model.sim=="output" then
75                         if model.ipar<>model_n.ipar then
76                             needcompile=4
77                         end
78                     end
79                     if or(model.blocktype<>model_n.blocktype)|..
80                         or(model.dep_ut<>model_n.dep_ut) then
81                         needcompile=4
82                     end
83                     if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then
84                         needcompile=4
85                     end
86                     if prod(size(model_n.sim))>1 then
87                         if model_n.sim(2)>1000 then
88                             if model.sim(1)<>model_n.sim(1) then
89                                 needcompile=4
90                             end
91                         end
92                     end
93                 else
94                     modified=or(model_n<>model)
95                     eq=model.equations;eqn=model_n.equations;
96                     if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|..
97                         or(eq.outputs<>eqn.outputs) then
98                         needcompile=4
99                     end
100                 end
101                 //parameter or states changed
102                 arg1(spath)=xxn// Update
103                 newpar(size(newpar)+1)=path// Notify modification
104                 y=max(y,needcompile)
105             end
106         end
107         x=arg1
108         typ=newpar
109     case "define" then
110         scs_m_1=scicos_diagram(..
111         version="scicos4.2",..
112         props=scicos_params(..
113         wpar=[-159.096,811.104,-121.216,617.984,1323,1008,331,284,630,480,0,7,1.4],..
114         Title="ENDBLK",..
115         tol=[0.0001,0.000001,1.000E-10,100001,0,0],..
116         tf=100000,..
117         context=" ",..
118         void1=[],..
119         options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],..
120         list([5,1],[4,1]),[0.8,0.8,0.8]),..
121         void2=[],..
122         void3=[],..
123         doc=list()))
124         scs_m_1.objs(1)=scicos_block(..
125         gui="END_c",..
126         graphics=scicos_graphics(..
127         orig=[272.104,249.11733],..
128         sz=[40,40],..
129         exprs="1.000E+08",..
130         pin=[],..
131         pout=[],..
132         pein=2,..
133         peout=2,..
134         gr_i=[],..
135         id="",..
136         in_implicit=[],..
137         out_implicit=[]),..
138         model=scicos_model(..
139         sim=list("scicosexit",4),..
140         in=[],..
141         in2=[],..
142         intyp=1,..
143         out=[],..
144         out2=[],..
145         outtyp=1,..
146         evtin=1,..
147         evtout=1,..
148         state=[],..
149         dstate=[],..
150         odstate=list(),..
151         rpar=[],..
152         ipar=[],..
153         opar=list(),..
154         blocktype="d",..
155         firing=1.000E+08,..
156         dep_ut=[%f,%f],..
157         label="",..
158         nzcross=0,..
159         nmode=0,..
160         equations=list()),..
161         doc=list())
162         scs_m_1.objs(2)=scicos_link(..
163         xx=[292.104;292.104;261.83733;261.83733;292.104;292.104],..
164         yy=[243.40305;234.45067;234.45067;305.584;305.584;294.83162],..
165         id="drawlink",..
166         thick=[0,0],..
167         ct=[5,-1],..
168         from=[1,1,0],..
169         to=[1,1,1])
170         model=scicos_model(..
171         sim="csuper",..
172         in=[],..
173         in2=[],..
174         intyp=1,..
175         out=[],..
176         out2=[],..
177         outtyp=1,..
178         evtin=[],..
179         evtout=[],..
180         state=[],..
181         dstate=[],..
182         odstate=list(),..
183         rpar=scs_m_1,..
184         ipar=[],..
185         opar=list(),..
186         blocktype="h",..
187         firing=[],..
188         dep_ut=[%f,%f],..
189         label="",..
190         nzcross=0,..
191         nmode=0,..
192         equations=list())
193         gr_i=[];
194         x=standard_define([2 2],model,[],gr_i)
195     end
196 endfunction