3 // Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
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.
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.
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.
19 // See the file ../license.txt
22 function %model_p(model)
26 if type(sim(1))==13 then
29 txt=sim(1)+" type: "+string(sim(2))
38 if size(fn, "*") > 4 then // Rule out the Annotations
39 if or(fn == "rpar") && typeof(model.rpar) == "diagram" then // Do nothing if model("rpar") is already a mlist
40 rpar = diagram2mlist(model.rpar);
41 // Define a new model omitting 'rpar' because writing 'model.rpar=l' triggers cloning.
42 newModel = scicos_model( sim=model.sim,in=model.in,in2=model.in2,intyp=model.intyp,out=model.out,out2=model.out2,outtyp=model.outtyp,evtin=model.evtin,evtout=model.evtout,state=model.state,dstate=model.dstate,odstate=model.odstate,ipar=model.ipar,opar=model.opar,blocktype=model.blocktype,firing=model.firing,dep_ut=model.dep_ut,label=model.label,nzcross=model.nzcross,nmode=model.nmode,equations=model.equations,uid=model.uid );
45 for i=1:size(newModel.rpar.objs)
46 newModelObj = newModel.rpar.objs(i);
47 if typeof(newModelObj) == "Block" && typeof(newModelObj.model.rpar) == "diagram"
48 subRpar = diagram2mlist(newModelObj.model.rpar);
49 // Define a new model omitting 'rpar' because writing 'model.rpar=l' triggers cloning.
50 newSubModel = scicos_model( sim=newModel.sim,in=newModel.in,in2=newModel.in2,intyp=newModel.intyp,out=newModel.out,out2=newModel.out2,outtyp=newModel.outtyp,evtin=newModel.evtin,evtout=newModel.evtout,state=newModel.state,dstate=newModel.dstate,odstate=newModel.odstate,ipar=newModel.ipar,opar=newModel.opar,blocktype=newModel.blocktype,firing=newModel.firing,dep_ut=newModel.dep_ut,label=newModel.label,nzcross=newModel.nzcross,nmode=newModel.nmode,equations=newModel.equations,uid=newModel.uid );
51 newSubModel.rpar = subRpar;
52 newModelObj.model = newSubModel;
53 newModel.rpar.objs(i) = newModelObj;
58 mprintf("%s\n", sci2exp(newModel(fn(k)),fn(k)))
64 mprintf("%s\n", sci2exp(eval("model."+fn(k)),fn(k)))
68 function ml = diagram2mlist(d)
69 ml = mlist(["diagram", "props", "objs", "version", "contrib"], d.props, [], d.version, d.contrib);
70 // Add 'objs' later to prevent cloning
73 // Also convert the sub-blocks and sub-links
74 listObjs=list(ones(1, size(ml.objs)));
76 select typeof(ml.objs(k))
79 listObjs(k) = mlist(["Block", "graphics", "model", "gui", "doc"], b.graphics, b.model, b.gui, b.doc);
82 listObjs(k) = mlist(["Link", "xx", "yy", "id", "thick", "ct", "from", "to"], l.xx, l.yy, l.id, l.thick, l.ct, l.from, l.to);
83 case "Annotation" then
85 listObjs(k) = mlist(["Annotation", "graphics", "model", "void", "gui"], t.graphics, t.model, t.void, t.gui);
87 listObjs(k) = mlist(["Deleted"]);
89 error(msprintf(_("Wrong type for diagram element #%d: %s %s or %s expected.\n"), k, "Block", "Link", "Annotation"));