ged and object editor unavailabilities on MacOS is now documented.
[scilab.git] / scilab / modules / graphics / macros / ged.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA
3 // This file must be used under the terms of the CeCILL.
4 // This source file is licensed as described in the file COPYING, which
5 // you should have received as part of this distribution.  The terms
6 // are also available at
7 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
8
9 function ged(k,win)
10
11     if getos() == "Darwin" then
12         error(msprintf(gettext("The ged function is not available on MacOSX.")));
13     end
14
15     if ~%tk then
16         warning(msprintf(gettext("Tcl/Tk interface not installed.")));
17         return
18     end
19
20     // Check number of arguments
21     if argn(2) ==1 then
22         win=get(gcf(),"figure_id")
23     elseif argn(2)<>2 then
24         error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "ged", 2));
25     end
26
27     // Check argument #1
28     if typeof(k) <> "constant" then
29         error(msprintf(gettext("%s: Wrong type for input argument #%d: A Real expected.\n"), "ged", 1));
30     end
31     if size(k, "*") <> 1 then
32         error(msprintf(gettext("%s: Wrong size for input argument #%d: A Real expected.\n"), "ged", 1));
33     end
34
35     // Check argument #2
36     if typeof(win) <> "constant" then
37         error(msprintf(gettext("%s: Wrong type for input argument #%d: A Real expected.\n"), "ged", 2));
38     end
39     if size(win, "*") <> 1 then
40         error(msprintf(gettext("%s: Wrong size for input argument #%d: A Real expected.\n"), "ged", 2));
41     end
42
43     global ged_current_figure
44     global ged_cur_fig_handle
45
46     ged_current_figure=gcf(); //Preserve current figure
47
48     ged_cur_fig_handle=scf(win);
49     show_window(ged_cur_fig_handle);
50
51     // for TCL input args built with string(). See bug http://bugzilla.scilab.org/2479
52     initFormat = format()
53     format("v",18)  // To be restored with initFormat before leaving
54
55     if k>3 then
56         TCL_EvalStr("set isgedinterp [interp exists ged]")
57         if ~TCL_ExistInterp( "ged" ) then
58             TCL_CreateSlave( "ged" ) ;
59         end
60
61     end
62
63     select k
64     case 1 then //Select (make it current)
65         format(initFormat(2),initFormat(1))
66         return
67     case 2 then //redraw
68         // nothing to do in new graphic mode
69     case 3 then //erase
70         clf()
71     case 4 then //copy
72         ged_copy_entity()
73     case 5 then //past
74         ged_paste_entity()
75     case 6 then //move
76         ged_move_entity()
77     case 7 then //Delete Entity
78         ged_delete_entity()
79
80     case 8 then //edit current figure properties
81
82         // hierarchical viewer
83         TK_send_handles_list(ged_cur_fig_handle)
84         TCL_SetVar("curgedindex",string(Get_handle_pos_in_list(ged_cur_fig_handle)))
85
86         //color_map array for color sample display
87         f=ged_cur_fig_handle;
88         for i=1:size(f.color_map,1)
89             redname= "RED("+string(i)+")";
90             TCL_EvalStr("set "+redname+" "+string(f.color_map(i,1)));
91             grename= "GREEN("+string(i)+")";
92             TCL_EvalStr("set "+grename+" "+string(f.color_map(i,2)));
93             bluname= "BLUE("+string(i)+")";
94             TCL_EvalStr("set "+bluname+" "+string(f.color_map(i,3)));
95         end
96
97         TCL_SetVar("msdos",string(getos() == "Windows")) // to know the OS
98
99         // get the number of the window associated with ged
100         TCL_SetVar("sciGedIsAlive",string(ged_cur_fig_handle.figure_id)) ;
101         TCL_SetVar("SCIHOME", SCIHOME) // to know the home directory to put temporary files
102
103         ged_figure(ged_cur_fig_handle)
104     case 9 then //edit current axes
105
106         // hierarchical viewer
107         TK_send_handles_list(ged_cur_fig_handle)
108         TCL_SetVar("curgedindex",string(Get_handle_pos_in_list(gca())))
109
110         //color_map array for color sample display
111         f=ged_cur_fig_handle;
112         for i=1:size(f.color_map,1)
113             redname= "RED("+string(i)+")";
114             TCL_EvalStr("set "+redname+" "+string(f.color_map(i,1)));
115             grename= "GREEN("+string(i)+")";
116             TCL_EvalStr("set "+grename+" "+string(f.color_map(i,2)));
117             bluname= "BLUE("+string(i)+")";
118             TCL_EvalStr("set "+bluname+" "+string(f.color_map(i,3)));
119         end
120
121         TCL_SetVar("msdos",string(getos() == "Windows")) // to know the OS
122
123         // get the number of the window associated with ged
124         TCL_SetVar("sciGedIsAlive",string(ged_cur_fig_handle.figure_id)) ;
125         TCL_SetVar("SCIHOME", SCIHOME) // to know the home directory to put temporary files
126
127         ged_axes(gca())
128     case 10 then //start Entity picker
129         fig=ged_cur_fig_handle
130         fig_ud=get(fig,"user_data")
131         if fig.event_handler<>""& fig.event_handler<>"ged_eventhandler" then
132             //push current event handler in fig user data if possible
133             if fig_ud==[] then fig_ud=struct();end
134             if typeof(fig_ud)=="st" then
135                 if ~isfield(fig_ud,"handlers") then  fig_ud.handlers=[],end
136                 fig_ud.handlers=[fig_ud.handlers;
137                 fig.event_handler fig.event_handler_enable]
138                 set(fig,"user_data",fig_ud)
139             else
140                 warning(_("Entity picker cannot be enabled, user data figure field is already used" ))
141                 return
142             end
143             fig.event_handler_enable = "off" //to prevent against bug 7855
144             fig.event_handler="ged_eventhandler"
145             fig.event_handler_enable="on"
146         end
147         ged_cur_fig_handle.info_message=_("Left click on a graphic entity to open its property editor");
148     case 11 then //stop Entity picker
149         fig=ged_cur_fig_handle
150         fig_ud=get(fig,"user_data")
151         seteventhandler("")
152         fig.event_handler_enable = "off"
153         if typeof(fig_ud)=="st"&isfield(fig_ud,"handlers")&fig_ud.handlers<>[] then
154             fig.event_handler=fig_ud.handlers($,1)
155             fig.event_handler_enable=fig_ud.handlers($,2)
156             fig_ud.handlers= fig_ud.handlers(1:$-1,:)
157             set(fig,"user_data",fig_ud)
158         else
159             fig.event_handler_enable = "off"
160         end
161     end
162     scf(ged_current_figure)
163     format(initFormat(2), initFormat(1))
164 endfunction