* bug 10048 fixed - Superblock based blocks index sub-blocks
[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., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 // See the file ../license.txt
20 //
21
22 function [x,y,typ]=ENDBLK(job,arg1,arg2)
23 x=[];y=[],typ=[]
24 select job
25 case 'plot' then
26   standard_draw(arg1)
27 case 'getinputs' then
28   [x,y,typ]=standard_inputs(arg1)
29 case 'getoutputs' then
30   [x,y,typ]=standard_outputs(arg1)
31 case 'getorigin' then
32   [x,y]=standard_origin(arg1)
33 case 'set' then
34   // look for the internal edge trigger block
35   for i=1:length(arg1.model.rpar.objs) do
36     o = arg1.model.rpar.objs(i);
37     if typeof(o) == "Block" & o.gui == "END_c" then
38       ppath = list(i);
39       break;
40     end
41   end
42   newpar=list();
43   y=0;
44   for path=ppath do
45     np=size(path,'*')
46     spath=list()
47     for k=1:np
48       spath($+1)='model'
49       spath($+1)='rpar'
50       spath($+1)='objs'
51       spath($+1)=path(k)
52     end
53     xx=arg1(spath)// get the block
54     execstr('xxn='+xx.gui+'(''set'',xx)')
55     if ~isequalbitwise(xxn,xx) then 
56       model=xx.model
57       model_n=xxn.model
58       if ~is_modelica_block(xx) then
59         modified=or(model.sim<>model_n.sim)|..
60                  ~isequal(model.state,model_n.state)|..
61                  ~isequal(model.dstate,model_n.dstate)|..
62                  ~isequal(model.odstate,model_n.odstate)|..
63                  ~isequal(model.rpar,model_n.rpar)|..
64                  ~isequal(model.ipar,model_n.ipar)|..
65                  ~isequal(model.opar,model_n.opar)|..
66                  ~isequal(model.label,model_n.label)
67         if or(model.in<>model_n.in)|or(model.out<>model_n.out)|..
68            or(model.in2<>model_n.in2)|or(model.out2<>model_n.out2)|..
69            or(model.outtyp<>model_n.outtyp)|or(model.intyp<>model_n.intyp) then
70           needcompile=1
71         end
72         if or(model.firing<>model_n.firing) then
73           needcompile=2
74         end
75         if (size(model.in,'*')<>size(model_n.in,'*'))|..
76           (size(model.out,'*')<>size(model_n.out,'*'))|..
77           (size(model.evtin,'*')<>size(model_n.evtin,'*')) then
78           needcompile=4
79         end
80         if model.sim=='input'|model.sim=='output' then
81           if model.ipar<>model_n.ipar then
82             needcompile=4
83           end
84         end
85         if or(model.blocktype<>model_n.blocktype)|..
86            or(model.dep_ut<>model_n.dep_ut) then
87           needcompile=4
88         end
89         if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then
90           needcompile=4
91         end
92         if prod(size(model_n.sim))>1 then
93           if model_n.sim(2)>1000 then
94             if model.sim(1)<>model_n.sim(1) then
95               needcompile=4
96             end
97           end
98         end
99       else
100         modified=or(model_n<>model)
101         eq=model.equations;eqn=model_n.equations;
102         if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|..
103            or(eq.outputs<>eqn.outputs) then
104           needcompile=4
105         end
106       end
107      //parameter or states changed
108       arg1(spath)=xxn// Update
109       newpar(size(newpar)+1)=path// Notify modification
110       y=max(y,needcompile)
111     end
112   end
113   x=arg1
114   typ=newpar
115 case 'define' then
116 scs_m_1=scicos_diagram(..
117         version="scicos4.2",..
118         props=scicos_params(..
119               wpar=[-159.096,811.104,-121.216,617.984,1323,1008,331,284,630,480,0,7,1.4],..
120               Title="ENDBLK",..
121               tol=[0.0001,0.000001,1.000E-10,100001,0,0],..
122               tf=100000,..
123               context=" ",..
124               void1=[],..
125               options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],..
126               list([5,1],[4,1]),[0.8,0.8,0.8]),..
127               void2=[],..
128               void3=[],..
129               doc=list()))
130 scs_m_1.objs(1)=scicos_block(..
131                 gui="END_c",..
132                 graphics=scicos_graphics(..
133                          orig=[272.104,249.11733],..
134                          sz=[40,40],..
135                          flip=%t,..
136                          theta=0,..
137                          exprs="1.000E+08",..
138                          pin=[],..
139                          pout=[],..
140                          pein=2,..
141                          peout=2,..
142                          gr_i=list("xstringb(orig(1),orig(2),'' END '',sz(1),sz(2),''fill'');",8),..
143                          id="",..
144                          in_implicit=[],..
145                          out_implicit=[]),..
146                 model=scicos_model(..
147                          sim=list("scicosexit",4),..
148                          in=[],..
149                          in2=[],..
150                          intyp=1,..
151                          out=[],..
152                          out2=[],..
153                          outtyp=1,..
154                          evtin=1,..
155                          evtout=1,..
156                          state=[],..
157                          dstate=[],..
158                          odstate=list(),..
159                          rpar=[],..
160                          ipar=[],..
161                          opar=list(),..
162                          blocktype="d",..
163                          firing=1.000E+08,..
164                          dep_ut=[%f,%f],..
165                          label="",..
166                          nzcross=0,..
167                          nmode=0,..
168                          equations=list()),..
169                 doc=list())
170 scs_m_1.objs(2)=scicos_link(..
171                   xx=[292.104;292.104;261.83733;261.83733;292.104;292.104],..
172                   yy=[243.40305;234.45067;234.45067;305.584;305.584;294.83162],..
173                   id="drawlink",..
174                   thick=[0,0],..
175                   ct=[5,-1],..
176                   from=[1,1,0],..
177                   to=[1,1,1])
178 model=scicos_model(..
179          sim="csuper",..
180          in=[],..
181          in2=[],..
182          intyp=1,..
183          out=[],..
184          out2=[],..
185          outtyp=1,..
186          evtin=[],..
187          evtout=[],..
188          state=[],..
189          dstate=[],..
190          odstate=list(),..
191          rpar=scs_m_1,..
192          ipar=[],..
193          opar=list(),..
194          blocktype="h",..
195          firing=[],..
196          dep_ut=[%f,%f],..
197          label="",..
198          nzcross=0,..
199          nmode=0,..
200          equations=list())
201   gr_i='xstringb(orig(1),orig(2),'' END '',sz(1),sz(2),''fill'')';
202   x=standard_define([2 2],model,[],gr_i)
203 end
204 endfunction