File: ged_insert.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (229 lines) | stat: -rw-r--r-- 6,893 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
function ged_insert(k,win)
//xset, xget used because ged should handle both old and new style
  
  global active men  
  
  //check if user changes is mind 
  active=active+1;men=k
  if  active>1 then return,end
  
  ged_current_figure=xget('window')
  xset('window',win) 
  isold=get('figure_style')=='old'
  if isold then 
    message('this menu does not apply to old style graphics')
    xset('window',ged_current_figure)
    return
  end

  scf(win);
  ged_cur_fig_handle=gcf();
  
  mess1 = "Press the right mouse button (during a while) to stop the line creation";
  mess2 = "Press any mouse button to complete the object drawing"
  entities=['Rectangle','Segment','Polyline','Arrow','Double Arrow', ...
	    'Text','Circle']
  
  default_axes = gca(); // get the default axes where we start
  f=gcf();
  job='annotation'
  if job=='annotation' then axes = get_insertion_axes(job,f),end

  [k,xc,yc]=ged_click()
    
  pix=f.pixmap; f.pixmap='on'
  default_axes = gca(); // get the default axes where we start
  rep(3)=-1
  select k
  case -100 then //window has been closed
     ged_insert_end(),return
  case 1 then //Single Line
    axes = get_insertion_axes(job,f,default_axes,xc,yc)
    [xc,yc] = xchange(xc,yc,'f2i'); // I pass to pixel
    sca(axes);  // I change axes and therefore change the scale
    [xc,yc] = xchange(xc,yc,'i2f'); // in the new scale I recompute the corresponding pixel values
    xpoly([xc;xc],[yc;yc])
    show_pixmap()
    r=gce();r.foreground=-1;
    r.clip_state='off';
    xinfo(mess2)
    while rep(3)==-1 do
      rep=xgetmouse(0,[%t %t])
      r.data=[xc,yc;rep(1),rep(2)]
      show_pixmap()
      xinfo(mess2)
    end 
  case 2 then //Polyline (stroken line)
    axes = get_insertion_axes(job,f,default_axes,xc,yc)
    [xc,yc] = xchange(xc,yc,'f2i');
    sca(axes);
    [xc,yc] = xchange(xc,yc,'i2f');
    xpoly([xc;xc],[yc;yc])
    show_pixmap()
    r=gce();r.foreground=-1;
    r.data(:,3)=0.;
    r.clip_state='off';
    xinfo(mess1)
    while %t
      rep(3)=-1;
      while rep(3)==-1 do
	rep=xgetmouse(0)
	r.data($,:)= [rep(1),rep(2),0]
	show_pixmap()
	xinfo(mess1)
      end 
      if or(rep(3)==[2 5 -100]) then break,end
      r.data=[r.data;r.data($,:)]
    end
  case 3 // Arrow (single arrow)
    axes = get_insertion_axes(job,f,default_axes,xc,yc)
    [xc,yc] = xchange(xc,yc,'f2i');
    sca(axes);
    [xc,yc] = xchange(xc,yc,'i2f');
    xpoly([xc;xc],[yc;yc])
    show_pixmap()
    r=gce();r.foreground=-1;
    r.data(:,3)=0.;
    r.polyline_style = 4;
    r.arrow_size_factor=10; // change the factor to have a nice arrow
    r.clip_state='off';
    xinfo(mess2)
    yc = [];
    while rep(3)==-1 do
      rep=xgetmouse(0,[%t %t])
      r.data($,:)= [rep(1),rep(2),0]
      show_pixmap()
      xinfo(mess2)
    end 
//   case 4 // Double Arrow
//      axes = get_insertion_axes(job,f,default_axes,xc,yc)
//     [xc,yc] = xchange(xc,yc,'f2i');
//     sca(axes);
//     [xc,yc] = xchange(xc,yc,'i2f');
//     xpoly([xc;xc],[yc;yc])
//     r1=gce();r.foreground=-1;
//     r1.data(:,3)=0.;
//     r1.polyline_style = 4;
//     r1.arrow_size_factor=5; // change the factor to have a nice arrow
//     r1.clip_state='off';
//     
//     // second polyline (for the seconf arrow from end to origin)
//     xpoly([xc;xc],[yc;yc])
//     //xpoly([r.data(2,1);r.data(1,1)],[r.data(2,2);r.data(1,2)])
//     r2=gce();r.foreground=-1;
//     r2.data(:,3)=0.;
//     r2.polyline_style = 4;
//     r2.arrow_size_factor=5; // change the factor to have a nice arrow
//     r2.clip_state='off';
//     
//     xinfo(mess2)
//     show_pixmap()
//     while rep(3)==-1 do
//       rep=xgetmouse(0,[%t %t])
//       drawlater();
//       r1.data($,:)= [rep(1),rep(2),0]
//       r2.data(1,:)= [rep(1),rep(2),0]
//       drawnow();
//       show_pixmap()
//       xinfo(mess2)
//     end 
  
  case 4 then //Text
    // open a dialog to enter the text
    text = x_dialog("Enter the new text here.","") ;
    if ( text <> [] & text <> "" ) then
      // do nothing if cancel button has been pressed or no text entered
      // get the position of the text
      xstring( xc, yc, text ) ;
    end
      show_pixmap() ;
  case 5 then //Rectangle
    axes = get_insertion_axes(job,f,default_axes,xc,yc)
    [xc,yc] = xchange(xc,yc,'f2i');
    sca(axes);
    [xc,yc] = xchange(xc,yc,'i2f'); 
    xrect(xc,yc,0,0)
    show_pixmap()
    r=gce();r.foreground=-1;
    r.clip_state='off';
    xinfo(mess2)
    while rep(3)==-1 do
      rep=xgetmouse(0,[%t %t])
      r.data=[mini(xc,rep(1)),maxi(yc,rep(2)),abs(xc-rep(1)),abs(yc-rep(2))]
      show_pixmap()
      xinfo(mess2)
    end    
  case 6 then //Circle
     axes = get_insertion_axes(job,f,default_axes,xc,yc)
    [xc,yc] = xchange(xc,yc,'f2i');
    sca(axes);
    [xc,yc] = xchange(xc,yc,'i2f');
    xarc(xc,yc,0,0,0,64*360)
    show_pixmap()
    r=gce();r.foreground=-1;
    r.clip_state='off';
    xinfo(mess2)
    while rep(3)==-1 do
      rep=xgetmouse(0,[%t %t])
      r.data=[mini(xc,rep(1)),maxi(yc,rep(2)),abs(xc-rep(1)),abs(yc-rep(2)),0,64*360]
      show_pixmap()
      xinfo(mess2)
    end 
  end
  ged_insert_end()
endfunction



function axes = get_insertion_axes(job,f,default_axes,xc,yc)
  if job=='annotation' then //special axes used
    axes=f.children(1)
    if axes.user_data=="annotation" then return,end
    //  create a new specialized axes at left bottom of the window
    //it shoud be better if the annotation axes be directly attached to
    //the figure (to be done)
    axes=newaxes();
    axes.user_data="annotation"
    axes.axes_bounds=[0,1,0.15,0.15];
    axes.margins=[0 0 0 0];
    axes.axes_visible = ["off","off","off"]
    axes.background=f.background;
  else //get the axes containing the point xc,yc
    //the point  xc,yc is given in user coordinate relative to the 
    //default_axes axes entity.
    nb_axes = size(f.children,'*') 
    // for now I consider that all children of a figure are of type Axes
    axes_size = f.axes_size // given in pixels
    axes_size = [axes_size axes_size];
    [x,y]=xchange(xc,yc,'f2i')
    found=%f
    for i=1:nb_axes
      axes = f.children(i);
      cur_axes_bounds = axes.axes_bounds;
      rect = cur_axes_bounds.*axes_size; // rectangle in pixels (margins inside)
      rect(3) = rect(3) + rect(1);
      rect(4) = rect(4) + rect(2);
      if (x>rect(1) & x<rect(3) & y>rect(2) & y<rect(4)) then  found=%t,break,end
    end
    if ~found then axes=[],end
  end
endfunction

function  ged_insert_end()
  if or(win==winsid()) then //  the window still exists
    sca(default_axes); // resume the default axes
    f=gcf()
    f.pixmap=stripblanks(pix)
    clearglobal active men  
  end
  if win<>ged_current_figure then xset('window',ged_current_figure),end

endfunction
function [men,xc,yc]=ged_click()
  global  men
  [btn,xc,yc]=xclick()
  if btn==-100 then men=-100,end
  for k=1:3,end
  job=men
endfunction