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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 // See the file ../license.txt
22 function [scs_m, fct] = do_addnew(scs_m)
25 //** "fct" is a flag control variable used by the calling function Addnewblock
26 //** it is used to signal modification of the datastructure
28 //**---------- This part handle the file related functions and error handling --------------
31 [ok,name] = getvalue( 'Get block GUI function name', ['Name'],list('str',1),emptystr() )
33 if ~ok then return, end ; //** --> Exit point
35 name = stripblanks(name);
37 if name==emptystr() then
38 messagebox("No block name specified",'modal');
40 end ; //** --> Exit point
44 if exists(name)==0 then
47 execstr('tp=type('+name+')')
48 to_get = tp<>11 & tp<>13
51 if to_get then // try to get it
53 messagebox(['Problem loading block '+name+'.';
54 'Use Activate_Scilab_Window and redefine it in Scilab.'], 'modal' ) ;
58 //path = getfile("*.sci", path, title="File containing function: "+name)
59 //if length(path)<=0 then return,end
60 //[u,err]=file('open',path,'old','formatted')
62 // messagebox(path+' file, Not found','modal')
65 //if execstr('getf(u)','errcatch')<>0 then
67 // messagebox([name + " erroneous function:"; lasterror()],'modal')
71 //if ~exists(name) then
72 // message(name+" is not defined in this file")
84 ierror = execstr('blk='+name+'(''define'')','errcatch')
85 if ierror <>0 & ierror <>4 then
86 messagebox([ "Error in GUI function"; lasterror() ],'modal')
92 irr = messagebox(['Error in GUI function--The error was:';
93 lasterror();'It could be an old GUI';
94 'Should I try to translate (no guarantee)?'],'modal',['yes','no'])
102 funcprot_val=funcprot()
104 standard_define=standard_define_old;
105 funcprot(funcprot_val)
106 ierror=execstr('blk='+name+'(''define'')','errcatch')
109 messagebox("Translation did not work, sorry","modal")
114 do_version = do_version; //load do_version and its subfunctions
116 ierror = execstr('blk=up_to_date(blk)','errcatch');
119 messagebox("Translation did not work, sorry","modal")
128 //**------ Al@n's update 2 ---------/////////////
131 if typeof(blk)=='Text' then
132 o_new = mlist(['Text','graphics','model','void','gui'],...
133 scicos_graphics(),scicos_model(),' ','TEXT_f')
135 o_new=scicos_block();
141 //*********** graphics **********//
144 G = getfield(1,ogra);
147 G_txt = G_txt + G(1,l) + ...
148 "=" + "ogra." + G(1,l);
153 G_txt = 'ogra=scicos_graphics(' + G_txt + ')';
154 ierr = execstr(G_txt,'errcatch')
156 error("Problem in convertion of graphics in block.")
158 o_new.graphics = ogra;
159 //*******************************//
161 //************* model ***********//
164 M = getfield(1,blk.model);
167 M_txt = M_txt + M(1,l) + ...
168 "=" + "omod." + M(1,l);
173 M_txt = 'omod=scicos_model(' + M_txt + ')';
174 ierr = execstr(M_txt,'errcatch')
176 error("Problem in convertion of model in block.")
179 //*******************************//
181 //************* other ***********//
184 T_txt = "o_new." + T(k) + "=" + T_txt;
185 ierr = execstr(T_txt,'errcatch')
187 error("Problem in convertion in objs.")
189 //*******************************//
191 end //end of select T(k)
194 //**------------------------------------/////////
196 //**------ Al@n's update ---------/////////////
197 if blk.model.sim(1)=='super'|...
198 blk.model.sim(1)=='csuper' then
200 scs_m_super = blk.model.rpar;
202 [ierr,scicos_ver,scs_m_super]=update_version(scs_m_super)
205 messagebox("Can''t import block in scicos, sorry (problem in version)","modal")
210 //## if we have do a convertion
211 if scicos_ver<>get_scicos_version() then
212 blk.model.rpar = scs_m_super;
215 if scs_m_super.props.title(1)<>name then
216 scs_m_super.props.title(1)=name
219 //generate a new interfacing function in TMPDIR
220 if blk.model.sim(1)=='super' then
221 save_super(scs_m_super,TMPDIR,blk.graphics.gr_i,blk.graphics.sz)
222 elseif blk.model.sim(1)=='csuper' then
223 save_csuper(scs_m_super,TMPDIR,blk.graphics.gr_i,blk.graphics.sz)
224 tt=mgetl(TMPDIR+'/'+name+'.sci');
225 mputl(tt,TMPDIR+'/'+name+'_new.sci');
226 //**------ R@min's update ---------/////////////
227 [u,err]=file('open',TMPDIR+'/'+name+'.sci','unknown')
229 messagebox('The file '+TMPDIR+'/'+name+'.sci'+' cannot be opened.',"modal")
233 Txte=['function [x,y,typ]='+name+'(job,arg1,arg2)';
235 'if job<>''define'' then ';
236 ' if argn(2)<2 then arg1=[],end'
237 ' [x,y,typ]=%fonct'+name+'(job,arg1)';
240 ierr=execstr('write(u,Txte,''(a)'')','errcatch','n')
242 messagebox('Impossible to write in '+TMPDIR+'/'+name+'.sci'+'; possibly locked.','modal')
246 dimen=blk.graphics.sz// /20 // why RN
248 textdef=[' model=scicos_model()']
251 cos2cosf(u,model.rpar,0)
256 ' model.rpar=scs_m_1'];
258 chval=sci2exp(evstr('model.'+ch))
260 ' model.'+ch+'='+chval(1);
266 ' exprs='+sci2exp(blk.graphics.exprs)
269 gr_i_tmp = sci2exp(blk.graphics.gr_i);
270 if size(gr_i_tmp,1)<>1 then
280 ' x=standard_define('+sci2exp(dimen)+',model,exprs,gr_i)']
285 fun2string(evstr(name),'%fonct'+name);
289 //**-------------------------------/////////////
291 nam_file=strcat([name,name+'_new']+'.sci',' ')
292 messagebox(["Old csuper/super block have been detected !";
293 "New interfacing functions "+nam_file;
294 " have been re-generated in "+TMPDIR+".";
295 "Please save and edit the generated file at your convenience";
296 "to have an updated interfacing function of that block."],"modal")
299 //**------------------------------------/////////////
301 //**--------------------------------------------------------------------------------------
302 //** The requested block is valid, then it is accepted
303 //** ---------------------- The graphics interaction begin here --------------------------
305 //** This code basically works ( :-) ) : it is the "Replot" that need attention :)
307 xinfo("Choose block position in the window");
309 blk.graphics.sz = 20 * blk.graphics.sz;
310 %xc = 100; %yc = 100; //** default start position
312 blk.graphics.orig = xy ;
314 gh_blk = drawobj(blk); //** draw the block (in the buffer) - using the corresponding Interface Function
315 //** Scilab Language - of the specific block (blk) and get back the graphic handler
316 //** to handle the block as a single entity
318 //**-----------------------------------------------------------------
319 //** ---> main loop that move the empty box until you click
321 while rep(3)<=-1 , //move loop
324 rep = xgetmouse([%t,%t]); //**
326 //** Protection from window closing
327 if rep(3)==-1000 then //active window has been closed
328 [%win,Cmenu] = resume(curwin,"Quit")
331 xm = rep(1) ; //** coordinate acquisition
333 dx = xm - %xc ; //** incremental coordinate
336 move (gh_blk , [dx dy]);
337 //**draw(gh_blk.parent); //** re-draw the graphic object and show on screen
339 //** show_pixmap() ; //** not useful on Scilab 5
341 %xc = xm ;%yc = ym ; //** position update
343 end //** ---> of the while loop
344 //**----------------------------------------------------------------------
346 //** out-of-the-loop window closing protection
348 if gh_window.figure_id <> curwin then
349 //active window has been closed
350 [%win, Cmenu] = resume(curwin,"Quit")
356 blk.graphics.orig = xy ; //** update object position in the data strucure
359 nc_save = needcompile ;
361 scs_m.objs($+1) = blk ; //** add the object to the data structure
364 [scs_m_save, nc_save, enable_undo, edited] = resume(scs_m_save,nc_save,%t,%t)
368 //**---------------------------------------------------------------------------------------------------
370 function objsi = up_to_date(o)
371 if size(o(2)) > 8 then
372 if type(o(2)(9))==15 then
374 if o(2)(9)(2)<>[] then
375 back_col=o(2)(9)(2);,
381 gr_i=convert_gri(o(5),gr_io);
382 if gr_i==[] then gr_i=gr_io;, end
383 elseif size(o(2)) < 9 then
387 gr_i=list(gr_i,back_col)
390 if size(o(3))<=12 then
391 mdl(13)=''; mdl(14)=[] ; mdl(15)='';
392 elseif size(o(3))<=13 then
393 mdl(14)=[] ; mdl(15)='';
394 elseif size(o(3))<=14 then
398 if mdl(1)(1)=='super'|mdl(1)(1)=='csuper' then
399 if type(mdl(8))==15 then
400 mdl(8)=do_version27(mdl(8))
404 graphics=scicos_graphics(orig=o(2)(1),sz=o(2)(2),flip=o(2)(3),..
405 exprs=o(2)(4),pin=o(2)(5),pout=o(2)(6),..
406 pein=o(2)(7),peout=o(2)(8),gr_i=gr_i,..
409 model=scicos_model(sim=mdl(1),in=mdl(2),out=mdl(3),evtin=mdl(4),..
410 evtout=mdl(5),state=mdl(6),dstate=mdl(7),..
411 rpar=mdl(8),ipar=mdl(9),blocktype=mdl(10),..
412 firing=mdl(11),dep_ut=mdl(12),label=mdl(13))
415 objsi=scicos_block(graphics=graphics,model=model,gui=o(5),..
417 if objsi.gui=='ESELECT_f' then objsi.model.sim(2)=-2,end