Scicos: fix do_version before simulation
[scilab.git] / scilab / modules / scicos / macros / scicos_scicos / update_scs_m.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 function scs_m_new = update_scs_m(scs_m,version)
22     // update_scs_m : function to do certification of
23     //                main data structure of
24     //                a scicos diagram (scs_m)
25     //                for current version of scicos
26     //
27     //   certification is done through initial value of fields in :
28     //      scicos_diagram()
29     //         scicos_params()
30     //         scicos_block()
31     //            scicos_graphics()
32     //            scicos_model()
33     //         scicos_link()
34     //
35     // Initial rev 12/05/07 : Alan
36     // Copyright INRIA
37     rhs = argn(2)
38     if rhs<2 then
39         version=get_scicos_version();
40     end
41
42     scs_m_new = scicos_diagram();
43
44     F = getfield(1,scs_m);
45
46     for i=2:size(F,2)
47
48         select F(i)
49
50             //******************* props *******************//
51         case "props" then
52
53             sprops = scs_m.props;
54             T = getfield(1,scs_m.props);
55             T_txt = "";
56             for j=2:size(T,2)
57                 T_txt = T_txt + strsubst(T(1,j),"title","Title") + ...
58                 "=" + "sprops." + T(1,j);
59                 if j<>size(T,2) then
60                     T_txt = T_txt + ",";
61                 end
62             end
63             T_txt = "sprops=scicos_params(" + T_txt + ")";
64             execstr(T_txt)
65             scs_m_new.props = sprops;
66             //*********************************************//
67
68             //******************** objs *******************//
69         case "objs" then
70
71             for j=1:lstsize(scs_m.objs) //loop on objects
72
73                 o=scs_m.objs(j);
74
75                 select typeof(o)
76
77                     //************** Block ***************//
78                 case "Block" then
79
80                     o_new=scicos_block();
81                     T = getfield(1,o);
82
83                     for k=2:size(T,2)
84                         select T(k)
85                             //*********** graphics **********//
86                         case "graphics" then
87                             ogra  = o.graphics;
88                             G     = getfield(1,ogra);
89                             G_txt = "";
90                             for l=2:size(G,2)
91                                 G_txt = G_txt + G(1,l) + ...
92                                 "=" + "ogra." + G(1,l);
93                                 if l<>size(G,2) then
94                                     G_txt = G_txt + ",";
95                                 end
96                             end
97                             G_txt = "ogra=scicos_graphics(" + G_txt + ")";
98                             execstr(G_txt)
99                             o_new.graphics = ogra;
100                             //*******************************//
101
102                             //************* model ***********//
103                         case "model" then
104                             omod  = o.model;
105                             M     = getfield(1,o.model);
106                             M_txt = "";
107                             for l=2:size(M,2)
108                                 M_txt = M_txt + M(1,l) + ...
109                                 "=" + "omod." + M(1,l);
110                                 if l<>size(M,2) then
111                                     M_txt = M_txt + ",";
112                                 end
113                             end
114                             M_txt = "omod=scicos_model(" + M_txt + ")";
115                             execstr(M_txt)
116                             //******** super block case ********//
117                             if omod.sim=="super"|omod.sim=="csuper" then
118                                 rpar=update_scs_m(omod.rpar,version)
119                                 omod.rpar=rpar
120                             end
121                             o_new.model = omod;
122                             //*******************************//
123
124                             //************* doc ***********//
125                         case "doc" then
126                             o_new.doc = list();
127                             //*******************************//
128
129                             //************* other ***********//
130                         else
131                             T_txt = "o."+T(k);
132                             T_txt = "o_new." + T(k) + "=" + T_txt;
133                             execstr(T_txt)
134                             //*******************************//
135
136                         end  //end of select T(k)
137                     end  //end of for k=
138                     scs_m_new.objs(j) = o_new;
139                     //************************************//
140
141                     //************** Link ****************//
142                 case "Link" then
143
144                     T     = getfield(1,o);
145                     T_txt = "";
146                     for k=2:size(T,2)
147                         T_txt = T_txt + T(1,k) + ...
148                         "=" + "o." + T(1,k);
149                         if k<>size(T,2) then
150                             T_txt = T_txt + ",";
151                         end
152                     end
153                     T_txt = "o_new=scicos_link(" + T_txt + ")";
154                     execstr(T_txt)
155                     scs_m_new.objs(j) = o_new;
156                     //************************************//
157
158                     //************** Text ****************//
159                 case "Text" then
160                     o_new = scicos_new(["Text","graphics","model","void","gui"],...
161                     scicos_graphics(),scicos_model()," ","TEXT_f")
162
163                     T     = getfield(1,o);
164                     T_txt = "";
165                     for k=2:size(T,2)
166                         select T(k)
167                             //*********** graphics **********//
168                         case "graphics" then
169                             ogra  = o.graphics;
170                             G     = getfield(1,ogra);
171                             G_txt = "";
172                             for l=2:size(G,2)
173                                 G_txt = G_txt + G(1,l) + ...
174                                 "=" + "ogra." + G(1,l);
175                                 if l<>size(G,2) then
176                                     G_txt = G_txt + ",";
177                                 end
178                             end
179                             G_txt = "ogra=scicos_graphics(" + G_txt + ")";
180                             execstr(G_txt)
181                             o_new.graphics = ogra;
182                             //*******************************//
183
184                             //************* model ***********//
185                         case "model" then
186                             // ignored by the MVC
187                             //*******************************//
188
189                             //************* other ***********//
190                         else
191                             T_txt = "o."+T(k);
192                             T_txt = "o_new." + T(k) + "=" + T_txt;
193                             execstr(T_txt)
194                             //*******************************//
195
196                         end  //end of select T(k)
197                     end  //end of for k=
198                     scs_m_new.objs(j) = o_new;
199                     //************************************//
200
201                     //************* other ***********//
202                 else  // JESAISPASIYADAUTRESOBJS
203                     // QUEDESBLOCKSDESLINKETDUTEXTESDANSSCICOS
204                     // ALORSICIJEFAISRIEN
205                     scs_m_new.objs(j) = o;
206                     //************************************//
207
208                 end //end of select typeof(o)
209
210             end //end of for j=
211             //*********************************************//
212
213             //** version **//
214         case "version" then
215             //do nothing here
216             //this should be done later
217
218         end  //end of select  F(i)
219
220     end //end of for i=
221
222     //**update version **//
223     scs_m_new.version = version;
224 endfunction
225