* Bug 10702 fixed: FROMWSB & TOWS_c icons show varname
[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         x.graphics.style = "FROMWSB;displayedLabel=From workspace<BR><font color=""orange"">[ <b>" + ..
108                              xxn.graphics.exprs(1) + "</b> ]</font>;align=center";
109         typ=newpar
110
111     case "define" then
112         scs_m_1=scicos_diagram(..
113         version="scicos4.2",..
114         props=scicos_params(..
115         wpar=[-159.096,811.104,-121.216,617.984,1323,1008,331,284,630,480,1426,231,1.4],..
116         Title="FROMWSB",..
117         tol=[0.0001,0.000001,1.000D-10,100001,0,0],..
118         tf=100000,..
119         context=" ",..
120         void1=[],..
121         options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],..
122         list([5,1],[4,1]),[0.8,0.8,0.8]),..
123         void2=[],..
124         void3=[],..
125         doc=list()))
126         scs_m_1.objs(1)=scicos_block(..
127         gui="FROMWS_c",..
128         graphics=scicos_graphics(..
129         orig=[260.37067,261.584],..
130         sz=[70,40],..
131         exprs=["V";"1";"1";"0"],..
132         pin=[],..
133         pout=4,..
134         pein=2,..
135         peout=2,..
136         gr_i=[],..
137         id="",..
138         in_implicit=[],..
139         out_implicit="E"),..
140         model=scicos_model(..
141         sim=list("fromws_c",4),..
142         in=[],..
143         in2=[],..
144         intyp=1,..
145         out=-1,..
146         out2=-2,..
147         outtyp=-1,..
148         evtin=1,..
149         evtout=1,..
150         state=[],..
151         dstate=[],..
152         odstate=list(),..
153         rpar=[],..
154         ipar=[1;-31;1;1;0],..
155         opar=list(),..
156         blocktype="d",..
157         firing=0,..
158         dep_ut=[%f,%t],..
159         label="",..
160         nzcross=0,..
161         nmode=0,..
162         equations=list()),..
163         doc=list())
164         scs_m_1.objs(2)=scicos_link(..
165         xx=[295.37067;295.37067;233.23733;233.23733;295.37067;295.37067],..
166         yy=[255.86971;223.45067;223.45067;337.85067;337.85067;307.29829],..
167         id="drawlink",..
168         thick=[0,0],..
169         ct=[5,-1],..
170         from=[1,1,0],..
171         to=[1,1,1])
172         scs_m_1.objs(3)=scicos_block(..
173         gui="OUT_f",..
174         graphics=scicos_graphics(..
175         orig=[358.9421,271.584],..
176         sz=[20,20],..
177         exprs="1",..
178         pin=4,..
179         pout=[],..
180         pein=[],..
181         peout=[],..
182         gr_i=[],..
183         id="",..
184         in_implicit="E",..
185         out_implicit=[]),..
186         model=scicos_model(..
187         sim="output",..
188         in=-1,..
189         in2=-2,..
190         intyp=-1,..
191         out=[],..
192         out2=[],..
193         outtyp=1,..
194         evtin=[],..
195         evtout=[],..
196         state=[],..
197         dstate=[],..
198         odstate=list(),..
199         rpar=[],..
200         ipar=1,..
201         opar=list(),..
202         blocktype="c",..
203         firing=[],..
204         dep_ut=[%f,%f],..
205         label="",..
206         nzcross=0,..
207         nmode=0,..
208         equations=list()),..
209         doc=list())
210         scs_m_1.objs(4)=scicos_link(..
211         xx=[338.9421;358.9421],..
212         yy=[281.584;281.584],..
213         id="drawlink",..
214         thick=[0,0],..
215         ct=[1,1],..
216         from=[1,1,0],..
217         to=[3,1,1])
218         model=scicos_model(..
219         sim="csuper",..
220         in=[],..
221         in2=[],..
222         intyp=1,..
223         out=-1,..
224         out2=-2,..
225         outtyp=1,..
226         evtin=[],..
227         evtout=[],..
228         state=[],..
229         dstate=[],..
230         odstate=list(),..
231         rpar=scs_m_1,..
232         ipar=[],..
233         opar=list(),..
234         blocktype="h",..
235         firing=[],..
236         dep_ut=[%f,%f],..
237         label="",..
238         nzcross=0,..
239         nmode=0,..
240         equations=list())
241         //## modif made by hand
242         gr_i=[]
243         x=standard_define([5 2],model,[],gr_i)
244     end
245 endfunction