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, newparameters, needcompile, edited] = scicos(scs_m, menus)
25 // scicos - block diagram graphic editor
27 // scs_m=scicos(scs_m,job)
29 // scs_m : scilab list, scicos main data structure
30 // scs_m.props contains system name and other infos
31 // scs_m.objs(i) contains description of ith block diagram element
32 // scs_m.version contains the number version of the diagram
33 // menus : vector of character strings,optional parameter giving usable menus
35 //--------------------------------------------------------------------------------------------
38 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
39 //** Magic Global Variable for Diagram Browser and more
41 global %diagram_path_objective
42 global inactive_windows
43 global Scicos_commands // programmed commands
45 //** "0" standard scicos oblique link ; "1" SL orthogonanal links
46 global SL_mode ; SL_mode = 0 ;
48 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
50 //**-----------------------------------------------------------------------------------------
51 //** Check for Scilab "command line mode" that does not support SCICOS
52 //** This check verify if "scicos()" is started form a command line Scilab with no graphics
53 //** support (almost obsolete function)
55 noguimode = find(sciargs()=="-nogui");
56 if (noguimode <>[]) then
58 warning(" Scilab in no gui mode : Scicos unavailable");
59 abort ; //** EXIT form Scicos ()
63 //**-----------------------------------------------------------------------------------------
65 // Define Scicos data tables ===========================================
66 if ( ~isdef("scicos_pal") | ~isdef("%scicos_menu") | ..
67 ~isdef("%scicos_short") | ~isdef("%scicos_help") | ..
68 ~isdef("%scicos_display_mode") | ~isdef("modelica_libs") | ..
69 ~isdef("scicos_pal_libs") | ~isdef("%scicos_gif") | ..
70 ~isdef("%scicos_contrib") | ~isdef("%scicos_libs") ) then
72 [scicos_pal, %scicos_menu, %scicos_short, %scicos_help, ...
73 %scicos_display_mode, modelica_libs,scicos_pal_libs, ...
74 %scicos_lhb_list, %CmenuTypeOneVector, %scicos_gif, ...
75 %scicos_contrib,%scicos_libs] = initial_scicos_tables();
76 clear initial_scicos_tables
78 // =====================================================================
81 //** -------------------- Check the recurring calling level of scicos ----------------------
82 [%ljunk, %mac] = where() ; //** where I am ?
83 slevel = prod ( size ( find ( %mac=='scicos') ) ) ; //** "slevel" is the superblock level
84 super_block = slevel > 1 ; //** ... means that the actual SCICOS is a superblock diagram
87 //** ----------------------- Scicos splash message and workspace stuff -----------------------
89 global next_scicos_call
91 //**--------------------------- Scicos splash message --------------------------------------
92 if next_scicos_call==[] then
93 next_scicos_call = 1 ;
94 verscicos = get_scicos_version() ;
95 ttxxtt = ['Scicos version '+part(verscicos,7:length(verscicos)) + ' (adapted for Scilab 5 by The Scilab Consortium)'
96 'Copyright (c) 1992-2009 Metalau project INRIA'
97 'Licensed under the GNU Public License (GPL)']
101 //**---- prepare from and to workspace stuff
107 %a = %a(1:$-predef()+1); //** exclude protected variables
111 if var<>'ans' & typeof(evstr(var))=='st' then
112 ierr = execstr('x='+var+'.values','errcatch')
114 ierr = execstr('t='+var+'.time','errcatch')
117 execstr('save('"'+var+''",x,t)')
123 //**----- end of /prepare from and to workspace stuff
126 super_path = [] // path to the currently opened superblock
128 inactive_windows = list(list(),[])
129 Scicos_commands = [];
131 //**----------------------------------------------------------------------------------------------
134 //**----------------------------------------------------------------------------------------------
135 %diagram_open = %t //** default choice
136 if super_path<>[] then //** main diagram
137 if isequal(%diagram_path_objective,super_path) then
138 if %scicos_navig<>[] then
141 gh_curwin = scf(curwin);
143 elseif %scicos_navig<>[] then
148 //**-----------------------------------------------------------------------------------------------
151 // Check and define SCICOS palette , menu , shortcut , display mode , palette libraries
152 if exists('scicos_pal')==0 | exists('%scicos_menu')==0 | exists('%scicos_short')==0 | ...
153 exists('%scicos_display_mode')==0 | exists('scicos_pal_libs')==0 | ...
154 exists('%scicos_lhb_list')==0 | exists('%CmenuTypeOneVector')==0 | ...
155 exists('%scicos_gif')==0 | exists('%scicos_contrib')==0 then
157 [scicos_pal_d, %scicos_menu_d, %scicos_short_d, %scicos_help_d,...
158 %scicos_display_mode_d, modelica_libs_d, scicos_pal_libs_d,...
159 %scicos_lhb_list_d, %CmenuTypeOneVector_d, %scicos_gif_d,...
160 %scicos_contrib_d ] = initial_scicos_tables() ;
162 if exists('scicos_pal')==0 then
163 message(["scicos_pal not defined"; "using default values"])
164 scicos_pal = scicos_pal_d ;
167 if exists('%scicos_menu')==0 then
168 message(["%scicos_menu not defined"; "using default values"])
169 %scicos_menu = %scicos_menu_d ;
172 if exists('%scicos_short')==0 then
173 message(["%scicos_short not defined"; "using default values"])
174 %scicos_short = %scicos_short_d ;
177 if exists('%scicos_help')==0 then
178 message(["%scicos_help not defined"; "using default values"])
179 %scicos_help = %scicos_help_d ;
182 if exists('%scicos_display_mode')==0 then
183 message(["%scicos_display_mode not defined"; "using default values"])
184 %scicos_display_mode = %scicos_display_mode_d ;
187 if exists('modelica_libs')==0 then
188 message(["modelica_libs not defined"; "using default values"])
189 modelica_libs = modelica_libs_d ;
192 if exists('scicos_pal_libs')==0 then
193 message(["scicos_pal_libs not defined"; "using default values"])
194 scicos_pal_libs = scicos_pal_libs_d ;
197 if exists('%scicos_lhb_list')==0 then
198 message(["%scicos_lhb_list not defined"; "using default values"])
199 %scicos_lhb_list = %scicos_lhb_list_d ;
202 if exists('%CmenuTypeOneVector')==0 then
203 message(["%CmenuTypeOneVector not defined"; "using default values"])
204 %CmenuTypeOneVector = %CmenuTypeOneVector_d ;
207 if exists('%scicos_gif')==0 then
208 message(["%scicos_gif not defined"; "using default values"])
209 %scicos_gif = %scicos_gif_d ;
212 if exists('%scicos_contrib')==0 then
213 message(["%scicos_contrib not defined"; "using default values"])
214 %scicos_contrib = %scicos_contrib_d ;
216 end //** ... of the initialization variable
219 //**--------------------------------------------------------------
220 //** initialize the "scicos_contex" data structure (Scilab script inside SCICOS simulation)
222 if ~exists('%scicos_context') then
223 %scicos_context = struct() ;
226 //**-----------------------------
228 //** initialize a "scicos_debug_gr" variable for debugging editor
229 if ~exists('%scicos_debug_gr') then
230 %scicos_debug_gr = %f; //** debug mode : default is "%f"
233 //** initialize a "scicos_with_grid" variable for drawing a grid
234 if ~exists('%scicos_with_grid') then
235 %scicos_with_grid = %f;
237 if ~exists('%scs_wgrid') then
238 //** %scs_wgrid(1:2) : space of grid
239 //** %scs_wgrid(3) : color
240 %scs_wgrid = [10;10;12];
243 //** disable scilab function protection
248 //** Activate Graphics editor in Scicos
249 exec(SCI+'/modules/graphics/macros/ged.sci',-1);
251 //** restore scilab function protection
254 //** check and - eventually - load the Scicos function library
255 if exists('scicos_scicoslib')==0 then
256 load("SCI/modules/scicos/macros/scicos_scicos/lib") ;
259 exec(loadpallibs, 1) //** load library that contains the INTERFACING functions
262 end //** end of the main if() not superblock initialization
264 //** ----------------------------- End the NOT-Superbloc initialization and check ----------------------
267 Main_Scicos_window = 1000 ; //** set default value of the main scicos window
270 newparameters = list() ;
280 //**----------------------------------------------------------------------------------
282 //** Some "magic numbers", try to load ".scicos_pal" and "scicos_short" trom the current
286 %zoom = 1.4 ; //** original value by Ramine
287 pal_mode = %f ; // Palette edition mode
289 scicos_paltmp = scicos_pal ;
291 //** try to load the local ".scicos_pal" files that contains the user defined
292 //** palette relatives to the local directory
293 if execstr('load(''.scicos_pal'')','errcatch')==0 then
294 //** if the load has been positive
295 scicos_pal = gunique(scicos_pal,scicos_paltmp); //** remove the duplicate item(s) in the palette
296 //** check is given palettes paths are still valid
297 scicos_pal = check_palettes_paths(scicos_pal)
301 //** load - if present - the used defined local shortcut
302 execstr('load(''.scicos_short'')','errcatch') // keyboard shortcuts
305 //**----------------------------------------------------------------------------------
307 //** Scilab 5 patch for font handling. This patch fif the "Symbol" font issue
310 scilab5fonts = xlfont() ; //** recover the full font list
311 xlfont(scilab5fonts(1), 1) ; //** substitute the font in position one
313 //**----------------------------------------------------------------------------------
315 [lhs, rhs] = argn(0) ; //** recover the arguments of "scicos(<rhs>)"
317 if rhs>=1 then //** scicos_new(...) is called with some arguments
319 if type(scs_m)==10 then // diagram is given by its filename
322 [ok,scs_m,%cpr,edited] = do_load(%fil,'diagram');
323 if ~ok then return, end
325 if size(%cpr)==0 then
329 %state0 = %cpr.state;
333 else // diagram is given by its data structure
336 %cpr=list(); needcompile=4 ; alreadyran=%f , %state0=list()
341 else //** scicos() is called without arguments (AND - implicitly - is NOT a superblock)
343 gh_Main_Scicos_window = scf(Main_Scicos_window);
344 //** In case a back up file exists
345 ierr = execstr('load(TMPDIR+''/BackupSave.cos'')','errcatch')
347 scs_m = scicos_diagram(version = get_scicos_version()) ;
353 load(TMPDIR+'/BackupInfo');
359 if typeof(scs_m)<>'diagram' then
360 error("First argument must be a Scicos diagram");
365 //**----------------------- Dynamic menu and shortcut preparation -----------------------------------------
367 %cor_item_exec = []; //** init
369 //** scan all the "%scicos_menu" an load "%cor_item_exec" ; dispose the first string (2:$) because
370 //** is the name of the dynamic menu
371 for %Y=1 : length(%scicos_menu)
372 %cor_item_exec = [%cor_item_exec, %scicos_menu(%Y)(2:$)] ;
375 %cor_item_exec = %cor_item_exec'; //** transpose the vector
377 %R = stripblanks(%R)+'_' ; //** delete all the blanks and add an underscore at the end "Save As PAlette" -> "SaveAsPalette_"
378 %R = strsubst(%R,'/','') ; //** delete "/"
379 %R = strsubst(%R,' ','') ; //** delete " "
380 %R = strsubst(%R,'.','') ; //** delete "."
381 %R = strsubst(%R,'-','') ; //** delete "-"
382 %cor_item_exec = [%cor_item_exec, %R]; //** create the two column matrix [<MenuName> <FunctionToCall>]
384 // add fixed menu items not visible
385 %cor_item_exec = [%cor_item_exec;
386 _('Link') , 'Link_' ;
387 _('Open/Set') , 'OpenSet_' ;
388 _('MoveLink') , 'MoveLink_' ;
389 _('SelectLink') , 'SelectLink_' ;
390 _('CtrlSelect') , 'CtrlSelect_' ;
391 _('SelectRegion'), 'SelectRegion_' ;
392 _('Popup') , 'Popup_' ;
393 _('PlaceinDiagram'), 'PlaceinDiagram_' ;
394 _('TkPopup') , 'TkPopup_' ;
395 _('BrowseTo') , 'BrowseTo_' ;
396 _('Place in Browser'), 'PlaceinBrowser_';
397 _('Select All'), 'SelectAll_'
400 menus = tlist('xxx');
402 for %Y=1:length(%scicos_menu)
403 menus(1) = [menus(1), %scicos_menu(%Y)(1)];
404 menus($+1)= %scicos_menu(%Y)(2:$);
407 for %Y=1:length(%scicos_menu)
408 %R = %scicos_menu(%Y);
409 %w = 'menus('''+%R(1)+''')('+ string(1:(size(%R,'*')-1)) + ')';
410 execstr(%R(1)+ '=%w;');
413 //----------------------------------------------------------------
414 // single key shortcut: keyboard definition
415 %tableau = emptystr([1:100]);
416 for %Y = 1 : size(%scicos_short,1)
417 %tableau(-31+ascii(%scicos_short(%Y,1)))=%scicos_short(%Y,2);
419 //----------------------------------------------------------------
424 options = scs_m.props.options
427 %scicos_solver = scs_m.props.tol(6)
429 //** ------- GRAPHICS INITIALIZATION: Palettes, TK functions, ---------
430 //**-------------------------- I'm NOT inside a superblock -----------
433 gh_current_window = scf(Main_Scicos_window);
434 curwin = get ( gh_current_window, "figure_id") ;
438 windows = [1 curwin] ;
439 pixmap = %scicos_display_mode ; //** obsolete: the pixmap is "on" as default
443 // Force sci_gui_mode to 1
444 // Scicos does not absolutely need Tk
445 // Except for some Screen Size
446 // will be improved soon
449 //if ~exists('%scicos_gui_mode') then
453 // %scicos_gui_mode = 0
457 %diagram_i_h = generic_i_h //** allows to write inside the "user_data" field
458 //** of the graphics windows
460 if %scicos_gui_mode==1 then
461 //** scicos is active in graphical mode
465 getfile = uigetfile ; //** brand new aliases
466 savefile = uigetfile ;
468 mpopup = createpopup ;
469 mdialog = x_mdialog ;
471 //** In Scilab 4.1.2 "getvalue = tk_getvalue ;"
472 //** In scilab 5 we use "modules/scicos/macros/scicos_util/getvalue.sci"
473 //** by Alan Layec, modified in order to accept string, etc.
477 choose = tk_scicos_choose ; //** please check with Allan Cornet
480 deff('x = choose(varargin)', 'x = x_choose(varargin(1:$))');
486 //** Scicos works in "text mode"
487 disp("Scicos in text mode is not supported");
488 //** RAMINE : TEXT MODE is not supported !
489 // deff('x=getfile(varargin)','x=xgetfile(varargin(1:$))');
490 // savefile = getfile;
491 // deff('Cmenu=mpopup(x)','Cmenu=[]')
492 // deff('x=choose(varargin)','x=x_choose(varargin(1:$))');
493 end //** of %scicos_gui_mode
497 else //** super block case
499 //** NO Pupup function definition in the super block ------------
500 //** because they are already defined
501 noldwin = size(windows,1) ;
502 windows = [windows ; slevel curwin] ;
503 palettes = palettes ;
505 end //** end of not superblock
509 //**------------------------- CONTEXT -----------------------
510 //set context (variable definition...)
512 if type(scs_m.props.context) == 10 then //** if the variable is defined
514 gh_percent_now_win = gcf(); //** save current figure handle
516 [%scicos_context,ierr] = script2var(scs_m.props.context,%scicos_context)
517 //for backward compatibility for scifunc
519 %mm = getfield(1,%scicos_context)
521 ierr = execstr(%mi+'=%scicos_context(%mi)','errcatch')
527 //end of for backward compatibility for scifunc
530 message(['Error occur when evaluating context:' lasterror() ]) ;
532 deff('%fonct()',scs_m.props.context)
533 %outfun = macrovar(%fonct);
535 //** perform eval only if context contains functions which may give
536 //** different results from one execution to next
537 if or(%outfun(4)=='rand')|or(%outfun(4)=='exec')|or(%outfun(4)=='load') then
539 [scs_m, %cpr, needcompile, ok] = do_eval(scs_m, %cpr);
544 scf(gh_percent_now_win); //** restore current figure handle
548 scs_m.props.context = ' ' ; //** put the variable to empty state
551 //** ---------- End of "Contex" handling and evaluation -----------
554 //** Begin of the Main command interpreter loop
556 //** Initial conditions
557 Cmenu = [] ; //** valid command = empty
558 %pt = [] ; //** valid last mouse position = empty
559 %win = curwin ; //** curwin is dynamically modified if a superblock window is open
560 %curwpar = [] ; // window dimensions
562 //** 'Select' and 'Select_back' are matrix;
563 //** Each line is: [object_id win_id] : "object_id" is the same INDEX used in "scs_m.obj"
564 //** and "win_id" is the Scilab window id.
565 //** Multiple selection is permitted: each object is a line of the matrix.
566 Select = [] ; //** empty
567 Select_back = [] ; //** empty
568 %ppt = []; //** used to store last valid click position for "Paste" operation
569 //Clipboard = []; //** used in Copy Cut and Paste function
570 //** ------------------- GRAPHICS INITIALIZATION ---------
572 //** This section is executed in any case
573 // initialize graphics
575 if %diagram_open then
576 gh_current_window = gcf() ; //** get the current graphics window
578 if (gh_current_window.user_data==[]) | (~isequalbitwise(gh_current_window.user_data(1),scs_m)) then
579 %zoom = restore(gh_current_window) ;
580 execstr('drawobjs(scs_m)', 'errcatch') ;
582 Select = gh_current_window.user_data(2) ;
583 enable_undo = gh_current_window.user_data(3) ;
584 scs_m_save = gh_current_window.user_data(4) ;
585 nc_save = gh_current_window.user_data(5) ;
589 else //** diagram is NOT open
591 if or(curwin==winsid()) then
592 gh_current_window = scf(curwin) ;
593 if (gh_current_window.user_data~=[]) & (isequalbitwise(gh_current_window.user_data(1),scs_m)) then
594 Select = gh_current_window.user_data(2) ;
599 exec(restore_menu,-1);
601 //** --- End of initialization -----------------------------------------------------------
603 global Clipboard //** to make it possible to copy and paste from one
604 //** super block to another
607 //** ------------- M A I N L O O P -----------------------------
608 //** --------- Command Interpreter / State Machine ------------
609 while ( Cmenu <> "Quit" & Cmenu <> "Leave" ) //** Cmenu -> exit from Scicos
611 //** Dynamic stacksize for very big diagram //
612 [%stack] = stacksize() //
613 if %stack(2)/%stack(1)> 0.3 then //
614 stacksize(2*%stack(1)) //
615 disp("Stacksize increased to "+string(2*%stack(1))) //
617 //**----------------------------------------------------
619 //** Dynamic window resizing and centering -------------------------
620 if or(winsid()==curwin) then //** if the current window is in the
621 winsize = gh_current_window.figure_size;
622 axsize = gh_current_window.axes_size;
624 //** +21 is to compensate for scrollbar under windows
625 if or(winsize > axsize+21) then
626 viewport = gh_current_window.viewport;
627 viewport = max([0,0], min(viewport,-winsize+axsize));
628 window_set_size(gh_current_window, viewport)
629 drawnow(); //** update the diagram on screen
633 // store win dims, it should only be in do_exit but not possible
635 scf(gh_current_window);
637 data_bounds = gh_axes.data_bounds;
638 winpos = gh_current_window.figure_position ;
639 viewport = gh_current_window.viewport ;
640 axsize = gh_current_window.axes_size;
641 %curwpar = [data_bounds(:)', axsize, viewport, winsize, winpos, %zoom];
643 if ~isequal(scs_m.props.wpar, %curwpar) then
644 scs_m.props.wpar = %curwpar // keep window dimensions
647 end //** edited section
650 //**... end of: Dynamic window resizing and centering ----------
652 //** Dynamic mark size
653 //** mark_size = int(%zoom*3.0); //** in pixel : size of the selection square markers
655 if %scicos_navig==[] then
656 if Scicos_commands<>[] then
657 execstr(Scicos_commands(1))
658 Scicos_commands(1)=[]
662 if Cmenu=="Quit" then
663 break ; //** EXIT point ...
666 //**--------------------------------------------------------------------
667 if %scicos_navig<>[] then //** navigation mode active
668 while %scicos_navig<>[] do
669 if ~isequal(%diagram_path_objective,super_path) then
672 [Cmenu,Select] = Find_Next_Step(%diagram_path_objective, super_path)
674 if or(curwin==winsid()) & ~isequal(Select,Select_back) then
676 selecthilite(Select_back, "off") ; // unHilite previous objects
677 selecthilite(Select, "on") ; // Hilite the actual selected object
681 if Cmenu=="OpenSet" then
683 execstr('ierr=exec(OpenSet_,''errcatch'',-1)')
684 //execstr('exec(OpenSet_,-1)')
685 //**---------------------------------------------------
686 if ierr<>0 then message(lasterror()),end
687 if isequal(%diagram_path_objective,super_path) then // must add after testing &%scicos_navig<>[]
688 if ~or(curwin==winsid()) then
689 gh_current_window = scf(curwin);
690 %zoom = restore(gh_current_window);
691 execstr('drawobjs(scs_m)', 'errcatch') ;
696 gh_current_window = scf(curwin);
699 if ~or(curwin==winsid())&%scicos_navig==[] then
701 %diagram_path_objective = [] ;
704 elseif Cmenu=="Quit" then
708 //**---------------------------------------------------
716 //** not in navigation mode
719 if ~or(curwin==winsid()) then
720 gh_current_window = scf(curwin);
721 %zoom = restore(gh_current_window)
722 execstr('drawobjs(scs_m)', 'errcatch') ;
726 gh_current_window = scf(curwin);
730 if ~or(Select(1,2) == winsid()) then
731 Select = [] ; //** imply a full Reset
735 //**--------------------------------------------------------------------
737 //** Command classification and message retrivial
738 [CmenuType, mess] = CmType(Cmenu); //** local function: see below in this file
739 xinfo(mess); //** show the message associated to the command
741 //** ----------------- State variable filtering ----------------
742 //** clear the %pt information for backward compatibility
743 //** if 'Cmenu' is empty (no command) but '%pt' is not , it is better to clear '%pt'
745 if ( Cmenu == [] & %pt <> [] ) then %pt=[]; end
747 //** if 'Cmenu' is NOT empty and 'CmenuType' is "0" I don't' need '%pt' then clear '%pt'
748 if ( Cmenu<> [] & CmenuType==0) then %pt=[]; end
749 gh_current_window = scf(curwin);
750 //** if 'Cmenu' is NOT empty and 'CmenuType' is "1" and there is at least one object selected
751 if (Cmenu<>[] & CmenuType==1 & %pt==[] & Select<>[]) then
752 [%pt,%win] = get_selection(Select) //** recover the %pt and %win from 'Select'
754 //** ------------------------------------------------------------------------------------
756 //** ---------------------- Main decisional section --------------------------------------
757 //** if no command is issued "Cmenu==[]" or
758 //** CmenuType==1 and no %pt information and no object selected
759 if ( Cmenu==[] | (CmenuType==1 & %pt==[] & Select==[]) ) then
761 //** I'm not ready to exec a command: I need more information using cosclik()
763 [btn_n, %pt_n, win_n, Cmenu_n] = cosclick() ;
766 if (Cmenu_n=="SelectLink" | Cmenu_n=="MoveLink") & Cmenu<>[] & CmenuType==1 & %pt==[] then
767 if %pt_n<>[] then %pt = %pt_n; end
769 if Cmenu_n<>[] then Cmenu = Cmenu_n; end
770 if %pt_n <> [] then %pt = %pt_n; end
777 //** I'm ready to exec a command
778 %koko = find( Cmenu==%cor_item_exec(:,1) );
779 if size(%koko,'*') == 1 then
781 Select_back = Select; //** save the selected object list
784 //** exec(path [,mode]) executes sequentialy the scilab instructions contained in the file given by path with
785 //** an optional execution mode mode .
786 //** 0 : the default value
787 //** -1 : nothing is printed
788 //** 1 : echo of each command line
789 //** 2 : prompt --> is printed
790 //** 3 : echoes + prompts
791 //** 4 : stops before each prompt. Execution resumes after a carriage return.
792 //** 7 : stops + prompts + echoes : useful mode for demos.
794 //** Used for AGGRESSIVE DEBUG ONLY -->
795 //** execstr('exec('+%cor_item_exec(%koko,2)+',1)')
797 //** Used for standard DEBUG ONLY -->
798 //** disp(%cor_item_exec(%koko,2)); //** disp the current exec
799 //** execstr('exec('+%cor_item_exec(%koko,2)+',-1)'); //** nothing is printed
801 //** RELEASE --> Please reactivate the error catcher before final release
802 execstr('ierr=exec('+%cor_item_exec(%koko,2)+',''errcatch'',-1)')
808 terr = ["I recovered from the following error:";
810 'in '+%cor_item_exec(%koko,2)'+' action.'];
811 mprintf('%s\n',terr);
813 elseif or(curwin==winsid()) then
814 gh_current_window = scf(curwin);
816 if ~isequal(Select,Select_back) then
818 selecthilite(Select_back, "off") ; // unHilite previous objects
819 selecthilite(Select, "on") ; // Hilite the actual selected object
824 if %scicos_navig==[] then // in case window is not open
826 %diagram_path_objective = []
831 //** if the command is not valid clear the state variable
833 end //** a valid/invalid command to exec
835 end //** not_ready / ready ... to exec a command
837 end //** not in navigation mode ???
839 end //**---> end of the while loop: exit with the 'Quit' OR 'Leave' commands
841 //** if you are exited from the main loop with 'Quit'
842 if Cmenu=="Quit" then
843 //** -------------- 'Quit' ------------------------------------
844 //** Quit exit from suberblock or go back to Scilab command line
846 if ~super_block then // even after quiting, workspace variables
847 // must be saved and be usable in Scilab
848 if find(%mac=='scilab2scicos') ==[] then
849 [txt,files]=returntoscilab()
852 load(TMPDIR+'/Workspace/'+files(i))
853 execstr(files(i)+'=struct('"values'",x,'"time'",t)')
858 mdelete(TMPDIR+'/BackupSave.cos') // no backup needed
859 mdelete(TMPDIR+'/BackupInfo')
861 //TCL_EvalStr('catch {destroy .palettes}')
862 //TCL_EvalStr('catch {destroy .ss}')
863 //TCL_EvalStr('catch {destroy .scsTree}')
864 // clear all globals defore leaving
865 clearglobal Clipboard
866 clearglobal Scicos_commands
868 clearglobal %scicos_navig
869 clearglobal %diagram_path_objective
870 close_inactive_windows(inactive_windows,[])
871 clearglobal inactive_windows
873 //** restore the original Scilab 5 font list before exit
874 //** xlfont(scilab5fonts(2),1);
877 //** For future implementation .....
878 //** This is the place of the windows cleaning section
882 elseif Cmenu=="Leave" then
883 //** -------------- 'Leave' ------------------------------------
884 //** "Leave" go to Scilab leaving Scicos active in the background
885 //** and use "seteventhandler" do to the job
886 ok = do_save(scs_m,TMPDIR+'/BackupSave.cos')
887 if ok then //need to save %cpr because the one in .cos cannot be
888 //used to continue simulation
889 if ~exists('%tcur') then %tcur=[];end
890 if ~exists('%scicos_solver') then %scicos_solver=0;end
891 save(TMPDIR+'/BackupInfo', edited,needcompile,alreadyran, %cpr,%state0,%tcur,..
892 %scicos_solver,inactive_windows)
894 OpenPals=windows(find(windows(:,1)<0),2 ) //close palettes
896 if or(winu==winsid()) then
897 gh_del = scf(winu) ; //** select the 'winu'window and get the
899 delete (gh_del) ; //** delete the window
905 message(["Problem saving a backup; I cannot activate Scilab.";
906 "Save your diagram scs_m manually."]);
910 AllWindows = unique([windows(:,2);inactive_windows(2)])
911 AllWindows = intersect(AllWindows',winsid())
913 //** activate the same event handler for all the active Scicos windows
914 for win_i= AllWindows
915 scf(win_i); //** select
916 seteventhandler("scilab2scicos"); //** activate the event handler
919 save(TMPDIR+'/AllWindows',AllWindows)
920 // scf(0) // to protect scicos windows when in Scilab
921 mprintf('%s\n','To reactivate Scicos, click on a diagram or type '"scicos();'"')
925 mprintf("%s\n","Your diagram is not saved. Do not quit Scilab or "+...
926 "open a new Scicos diagram before returning to Scicos.")
928 // prepare from and to workspace stuff
930 if find(%mac=='scilab2scicos') ==[] then
931 [txt,files] = returntoscilab();
934 load(TMPDIR+'/Workspace/'+files(i))
935 execstr(files(i)+'=struct('"values'",x,'"time'",t)')
942 endfunction //** scicos(); end here :) : you had a good day
943 //**------------------------------------------------------------------------------------
946 function [itype, mess] = CmType(Cmenu)
947 //** look inside "%CmenuTypeOneVector" if the command is type 1 (need both Cmenu and %pt)
948 k = find (Cmenu == %CmenuTypeOneVector(:,1));
949 if k==[] then //** if is not type 1 (empty k)
950 itype = 0 ; //** type zero
951 mess='' ; //** set message to empty
952 return ; //** --> EXIT point : return back
955 if size(k,'*')>1 then //** if found more than one command
956 message('Warning '+string( size(k,'*'))+' menus have identical name '+Cmenu);
957 k = k(1); //** extract the index
960 itype = 1 ; //** type one
962 mess = %CmenuTypeOneVector(k,2) ; //** use the index to recover the message
966 //** ----------------------------------------------------------------------------------------------------------------
968 function uni = gunique(m1,m2)
969 // Used to eliminate duplicate palette item(s)
970 uni = [m1;m2] ; //** merge the two matrix
971 [j,ind] = unique(uni(:,1) + uni(:,2)) ; //** remove the duplicate palette name
972 uni = uni(-gsort(-ind),:); //** reorder the merged palette without duplicate
975 //** ----------------------------------------------------------------------------------------------------------------
977 function restore_menu()
978 //** disp("//** [Call] restore_menu...")
979 for %Y=1:length(%scicos_menu)
980 execstr( %scicos_menu(%Y)(1)+'_'+string(curwin)+'='+%scicos_menu(%Y)(1) )
984 //**---------------------------------------------------------------------------------------------------------------------
986 function scicos_pal = check_palettes_paths(scicos_pal)
988 for k=1:size(scicos_pal,1)
989 if fileinfo(scicos_pal(k,2))==[] then toremove=[toremove k],end
991 //remove invalid ones out of scicos_pal
993 rmpal=scicos_pal(toremove,:)
994 rmpal(:,1)=part(rmpal(:,1),1:max(length(rmpal(:,1))))
995 message(['Following palette(s) ignored (associated file(s) no more exist):';
997 rmpal(:,1)+': '+rmpal(:,2)
999 ' To avoid this message, please update the ""'+pwd()+filesep()+'.scicos_pal"" file'])
1000 scicos_pal(toremove,:)=[];