1 | #TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it |
---|
2 | # before pushing a new 1D data update. |
---|
3 | |
---|
4 | # |
---|
5 | #TODO: NEED MAJOR REFACTOR |
---|
6 | # |
---|
7 | |
---|
8 | |
---|
9 | # Debug printout |
---|
10 | #from config import printEVT |
---|
11 | from BaseInteractor import _BaseInteractor |
---|
12 | from copy import deepcopy |
---|
13 | import math |
---|
14 | |
---|
15 | #from Plotter1D import AddPlotEvent |
---|
16 | import SlicerParameters |
---|
17 | import wx |
---|
18 | #(SlicerParamUpdateEvent, EVT_SLICER_PARS_UPDATE) = wx.lib.newevent.NewEvent() |
---|
19 | from sans.guicomm.events import SlicerParamUpdateEvent |
---|
20 | class BoxSum(_BaseInteractor): |
---|
21 | """ |
---|
22 | Select an annulus through a 2D plot |
---|
23 | """ |
---|
24 | def __init__(self,base,axes,color='black', zorder=3, x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): |
---|
25 | |
---|
26 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
27 | self.markers = [] |
---|
28 | self.axes = axes |
---|
29 | self.qmax = self.base.data2D.xmax |
---|
30 | self.connect = self.base.connect |
---|
31 | self.xmin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) |
---|
32 | self.ymin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) |
---|
33 | #self.xmax= x_max |
---|
34 | #self.ymax= y_max |
---|
35 | self.xmax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) |
---|
36 | self.ymax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) |
---|
37 | # center of the figure |
---|
38 | self.center_x= 0.0002 |
---|
39 | self.center_y= 0.0003 |
---|
40 | |
---|
41 | ## Number of points on the plot |
---|
42 | self.nbins = 20 |
---|
43 | self.count=0 |
---|
44 | self.error=0 |
---|
45 | self.has_move= False |
---|
46 | |
---|
47 | self.horizontal_lines= Horizontal_DoubleLine(self, self.base.subplot,color='blue', |
---|
48 | zorder=zorder, |
---|
49 | y= self.ymax, |
---|
50 | x= self.xmax, |
---|
51 | center_x= self.center_x, |
---|
52 | center_y= self.center_y) |
---|
53 | self.horizontal_lines.qmax = self.qmax |
---|
54 | |
---|
55 | self.vertical_lines= Vertical_DoubleLine(self, self.base.subplot,color='black', |
---|
56 | zorder=zorder, |
---|
57 | y= self.ymax, |
---|
58 | x= self.xmax, |
---|
59 | center_x= self.center_x, |
---|
60 | center_y= self.center_y) |
---|
61 | self.vertical_lines.qmax = self.qmax |
---|
62 | self.center= PointInteractor(self, self.base.subplot,color='grey', |
---|
63 | zorder=zorder, |
---|
64 | center_x= self.center_x, |
---|
65 | center_y= self.center_y) |
---|
66 | |
---|
67 | |
---|
68 | #self.connect_markers([]) |
---|
69 | |
---|
70 | self.update() |
---|
71 | self._post_data() |
---|
72 | |
---|
73 | # Bind to slice parameter events |
---|
74 | print "box sum self.base.parent",self.base.parent |
---|
75 | self.base.parent.Bind(SlicerParameters.EVT_SLICER_PARS, self._onEVT_SLICER_PARS) |
---|
76 | |
---|
77 | def _onEVT_SLICER_PARS(self, event): |
---|
78 | #printEVT("AnnulusSlicer._onEVT_SLICER_PARS") |
---|
79 | event.Skip() |
---|
80 | if event.type == self.__class__.__name__: |
---|
81 | self.set_params(event.params) |
---|
82 | self.base.update() |
---|
83 | |
---|
84 | def update_and_post(self): |
---|
85 | self.update() |
---|
86 | self._post_data() |
---|
87 | |
---|
88 | def save_data(self, path, image, x, y): |
---|
89 | output = open(path, 'w') |
---|
90 | |
---|
91 | data_x, data_y = self.get_data(image, x, y) |
---|
92 | |
---|
93 | output.write("<phi> <average>\n") |
---|
94 | for i in range(len(data_x)): |
---|
95 | output.write("%g %g\n" % (data_x[i], data_y[i])) |
---|
96 | output.close() |
---|
97 | |
---|
98 | def set_layer(self, n): |
---|
99 | self.layernum = n |
---|
100 | self.update() |
---|
101 | |
---|
102 | def clear(self): |
---|
103 | self.clear_markers() |
---|
104 | self.horizontal_lines.clear() |
---|
105 | self.vertical_lines.clear() |
---|
106 | self.center.clear() |
---|
107 | |
---|
108 | #self.base.connect.disconnect() |
---|
109 | self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS) |
---|
110 | |
---|
111 | def update(self): |
---|
112 | """ |
---|
113 | Respond to changes in the model by recalculating the profiles and |
---|
114 | resetting the widgets. |
---|
115 | """ |
---|
116 | if self.center.has_move: |
---|
117 | print "center has move" |
---|
118 | self.center.update() |
---|
119 | self.horizontal_lines.update( center= self.center) |
---|
120 | self.vertical_lines.update( center= self.center) |
---|
121 | |
---|
122 | if self.horizontal_lines.has_move: |
---|
123 | print "top has moved" |
---|
124 | self.horizontal_lines.update() |
---|
125 | self.vertical_lines.update(y1=self.horizontal_lines.y1, |
---|
126 | y2=self.horizontal_lines.y2, |
---|
127 | height= self.horizontal_lines.half_height ) |
---|
128 | if self.vertical_lines.has_move: |
---|
129 | print "right has moved" |
---|
130 | self.vertical_lines.update() |
---|
131 | self.horizontal_lines.update(x1=self.vertical_lines.x1, |
---|
132 | x2=self.vertical_lines.x2, |
---|
133 | width=self.vertical_lines.half_width) |
---|
134 | |
---|
135 | |
---|
136 | def save(self, ev): |
---|
137 | """ |
---|
138 | Remember the roughness for this layer and the next so that we |
---|
139 | can restore on Esc. |
---|
140 | """ |
---|
141 | self.base.freeze_axes() |
---|
142 | self.horizontal_lines.save(ev) |
---|
143 | self.vertical_lines.save(ev) |
---|
144 | self.center.save(ev) |
---|
145 | |
---|
146 | def _post_data(self): |
---|
147 | # Compute data |
---|
148 | print |
---|
149 | |
---|
150 | data = self.base.data2D |
---|
151 | from DataLoader.manipulations import Boxavg |
---|
152 | radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) |
---|
153 | x_min= self.vertical_lines.x2 |
---|
154 | x_max= self.vertical_lines.x1 |
---|
155 | y_min= self.vertical_lines.y2 |
---|
156 | y_max= self.vertical_lines.y1 |
---|
157 | box = Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) |
---|
158 | self.count, self.error = box(self.base.data2D) |
---|
159 | print "count, error",self.count, self.error |
---|
160 | |
---|
161 | def moveend(self, ev): |
---|
162 | self.base.thaw_axes() |
---|
163 | # Post paramters |
---|
164 | self._post_data() |
---|
165 | """ |
---|
166 | event = SlicerParameters.SlicerParameterEvent() |
---|
167 | event.type = self.__class__.__name__ |
---|
168 | print "event type boxsum: ", event.type |
---|
169 | event.params = self.get_params() |
---|
170 | wx.PostEvent(self.base, event) |
---|
171 | """ |
---|
172 | self.type= self.__class__.__name__ |
---|
173 | params= self.get_params() |
---|
174 | event = SlicerParamUpdateEvent(type=self.type, params=params) |
---|
175 | wx.PostEvent(self.base, event) |
---|
176 | |
---|
177 | |
---|
178 | def restore(self): |
---|
179 | """ |
---|
180 | Restore the roughness for this layer. |
---|
181 | """ |
---|
182 | self.horizontal_lines.restore() |
---|
183 | self.vertical_lines.restore() |
---|
184 | self.center.restore() |
---|
185 | def move(self, x, y, ev): |
---|
186 | """ |
---|
187 | Process move to a new position, making sure that the move is allowed. |
---|
188 | """ |
---|
189 | pass |
---|
190 | |
---|
191 | def set_cursor(self, x, y): |
---|
192 | pass |
---|
193 | |
---|
194 | def get_params(self): |
---|
195 | params = {} |
---|
196 | |
---|
197 | params["x"] = math.fabs(self.horizontal_lines.half_width) |
---|
198 | params["y"] = math.fabs(self.vertical_lines.half_height) |
---|
199 | |
---|
200 | params["center_x"] = self.center.x |
---|
201 | params["center_y"] =self.center.y |
---|
202 | params["count"] = self.count |
---|
203 | params["errors"]= self.error |
---|
204 | |
---|
205 | return params |
---|
206 | |
---|
207 | |
---|
208 | def get_result(self): |
---|
209 | """ |
---|
210 | return the result of box summation |
---|
211 | """ |
---|
212 | result={} |
---|
213 | result["count"] = self.count |
---|
214 | result["error"] = self.error |
---|
215 | return result |
---|
216 | |
---|
217 | |
---|
218 | def set_params(self, params): |
---|
219 | |
---|
220 | x_max = math.fabs(params["x"] ) |
---|
221 | y_max = math.fabs(params["y"] ) |
---|
222 | |
---|
223 | self.center_x=params["center_x"] |
---|
224 | self.center_y=params["center_y"] |
---|
225 | |
---|
226 | self.center.update(center_x=self.center_x,center_y=self.center_y) |
---|
227 | |
---|
228 | self.horizontal_lines.update(center= self.center, |
---|
229 | width=x_max, |
---|
230 | height=y_max) |
---|
231 | self.vertical_lines.update(center= self.center, |
---|
232 | width=x_max, |
---|
233 | height=y_max) |
---|
234 | |
---|
235 | self._post_data() |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | def freeze_axes(self): |
---|
240 | self.base.freeze_axes() |
---|
241 | |
---|
242 | def thaw_axes(self): |
---|
243 | self.base.thaw_axes() |
---|
244 | |
---|
245 | def draw(self): |
---|
246 | self.base.draw() |
---|
247 | class PointInteractor(_BaseInteractor): |
---|
248 | """ |
---|
249 | Select an annulus through a 2D plot |
---|
250 | """ |
---|
251 | def __init__(self,base,axes,color='black', zorder=5, |
---|
252 | center_x= 0.0, |
---|
253 | center_y= 0.0): |
---|
254 | |
---|
255 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
256 | self.markers = [] |
---|
257 | self.axes = axes |
---|
258 | # center |
---|
259 | self.x = center_x |
---|
260 | self.y = center_y |
---|
261 | |
---|
262 | self.save_x = center_x |
---|
263 | self.save_y = center_y |
---|
264 | |
---|
265 | |
---|
266 | try: |
---|
267 | self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', |
---|
268 | marker='s', markersize=10, |
---|
269 | color=self.color, alpha=0.6, |
---|
270 | pickradius=5, label="pick", |
---|
271 | zorder=zorder, # Prefer this to other lines |
---|
272 | visible=True)[0] |
---|
273 | except: |
---|
274 | self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', |
---|
275 | marker='s', markersize=10, |
---|
276 | color=self.color, alpha=0.6, |
---|
277 | label="pick", |
---|
278 | visible=True)[0] |
---|
279 | message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" |
---|
280 | message += "Get the SVN version that is at least as recent as June 1, 2007" |
---|
281 | |
---|
282 | #raise "Version error", message |
---|
283 | |
---|
284 | # line |
---|
285 | self.center = self.axes.plot([self.x],[self.y], |
---|
286 | linestyle='-', marker='', |
---|
287 | color=self.color, |
---|
288 | visible=True)[0] |
---|
289 | |
---|
290 | self.npts = 30 |
---|
291 | self.has_move=False |
---|
292 | self.connect_markers([self.center_marker]) |
---|
293 | self.update() |
---|
294 | |
---|
295 | def set_layer(self, n): |
---|
296 | self.layernum = n |
---|
297 | self.update() |
---|
298 | |
---|
299 | def clear(self): |
---|
300 | self.clear_markers() |
---|
301 | try: |
---|
302 | self.center.remove() |
---|
303 | self.center_marker.remove() |
---|
304 | except: |
---|
305 | # Old version of matplotlib |
---|
306 | for item in range(len(self.axes.lines)): |
---|
307 | del self.axes.lines[0] |
---|
308 | |
---|
309 | def get_radius(self): |
---|
310 | |
---|
311 | return 0 |
---|
312 | |
---|
313 | def update(self, center_x=None,center_y=None): |
---|
314 | """ |
---|
315 | Draw the new roughness on the graph. |
---|
316 | """ |
---|
317 | if center_x !=None: self.x= center_x |
---|
318 | if center_y !=None: self.y= center_y |
---|
319 | |
---|
320 | self.center_marker.set(xdata=[self.x], ydata=[self.y]) |
---|
321 | self.center.set(xdata=[self.x], ydata=[self.y]) |
---|
322 | |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | def save(self, ev): |
---|
327 | """ |
---|
328 | Remember the roughness for this layer and the next so that we |
---|
329 | can restore on Esc. |
---|
330 | """ |
---|
331 | self.save_x= self.x |
---|
332 | self.save_y= self.y |
---|
333 | |
---|
334 | self.base.freeze_axes() |
---|
335 | |
---|
336 | def moveend(self, ev): |
---|
337 | |
---|
338 | self.has_move=False |
---|
339 | self.base.moveend(ev) |
---|
340 | |
---|
341 | def restore(self): |
---|
342 | """ |
---|
343 | Restore the roughness for this layer. |
---|
344 | """ |
---|
345 | self.y= self.save_y |
---|
346 | self.x= self.save_x |
---|
347 | |
---|
348 | def move(self, x, y, ev): |
---|
349 | """ |
---|
350 | Process move to a new position, making sure that the move is allowed. |
---|
351 | """ |
---|
352 | self.x= x |
---|
353 | self.y= y |
---|
354 | |
---|
355 | self.has_move=True |
---|
356 | self.base.base.update() |
---|
357 | |
---|
358 | def set_cursor(self, x, y): |
---|
359 | self.move(x, y, None) |
---|
360 | self.update() |
---|
361 | |
---|
362 | |
---|
363 | def get_params(self): |
---|
364 | params = {} |
---|
365 | params["x"] = self.x |
---|
366 | params["y"] = self.y |
---|
367 | |
---|
368 | return params |
---|
369 | |
---|
370 | def set_params(self, params): |
---|
371 | center_x = params["x"] |
---|
372 | center_y = params["y"] |
---|
373 | self.update(center_x=center_x,center_y=center_y) |
---|
374 | |
---|
375 | |
---|
376 | class Vertical_DoubleLine(_BaseInteractor): |
---|
377 | """ |
---|
378 | Select an annulus through a 2D plot |
---|
379 | """ |
---|
380 | def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, |
---|
381 | center_x= 0.0, |
---|
382 | center_y= 0.0): |
---|
383 | |
---|
384 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
385 | self.markers = [] |
---|
386 | self.axes = axes |
---|
387 | # center |
---|
388 | self.center_x = center_x |
---|
389 | self.center_y = center_y |
---|
390 | |
---|
391 | |
---|
392 | |
---|
393 | self.y1 = y + self.center_y |
---|
394 | self.save_y1= self.y1 |
---|
395 | |
---|
396 | delta= self.y1- self.center_y |
---|
397 | self.y2= self.center_y - delta |
---|
398 | self.save_y2= self.y2 |
---|
399 | |
---|
400 | self.x1 = x + self.center_x |
---|
401 | self.save_x1 = self.x1 |
---|
402 | |
---|
403 | delta= self.x1- self.center_x |
---|
404 | self.x2= self.center_x - delta |
---|
405 | self.save_x2 = self.x2 |
---|
406 | |
---|
407 | self.color=color |
---|
408 | |
---|
409 | self.half_height= math.fabs(y) |
---|
410 | self.save_half_height= math.fabs(y) |
---|
411 | |
---|
412 | self.half_width= math.fabs(x) |
---|
413 | self.save_half_width=math.fabs(x) |
---|
414 | |
---|
415 | try: |
---|
416 | self.right_marker = self.axes.plot([self.x1],[0], linestyle='', |
---|
417 | marker='s', markersize=10, |
---|
418 | color=self.color, alpha=0.6, |
---|
419 | pickradius=5, label="pick", |
---|
420 | zorder=zorder, # Prefer this to other lines |
---|
421 | visible=True)[0] |
---|
422 | except: |
---|
423 | self.right_marker = self.axes.plot([self.x1],[0], linestyle='', |
---|
424 | marker='s', markersize=10, |
---|
425 | color=self.color, alpha=0.6, |
---|
426 | label="pick", |
---|
427 | visible=True)[0] |
---|
428 | message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" |
---|
429 | message += "Get the SVN version that is at least as recent as June 1, 2007" |
---|
430 | |
---|
431 | #raise "Version error", message |
---|
432 | |
---|
433 | # line |
---|
434 | self.right_line = self.axes.plot([self.x1,self.x1],[self.y1,self.y2], |
---|
435 | linestyle='-', marker='', |
---|
436 | color=self.color, |
---|
437 | visible=True)[0] |
---|
438 | self.left_line = self.axes.plot([self.x2,self.x2],[self.y1,self.y2], |
---|
439 | linestyle='-', marker='', |
---|
440 | color=self.color, |
---|
441 | visible=True)[0] |
---|
442 | |
---|
443 | self.npts = 30 |
---|
444 | self.has_move=False |
---|
445 | self.connect_markers([self.right_marker]) |
---|
446 | self.update() |
---|
447 | |
---|
448 | |
---|
449 | def set_layer(self, n): |
---|
450 | self.layernum = n |
---|
451 | self.update() |
---|
452 | |
---|
453 | def clear(self): |
---|
454 | self.clear_markers() |
---|
455 | try: |
---|
456 | self.right_marker.remove() |
---|
457 | self.right_line.remove() |
---|
458 | self.left_line.remove() |
---|
459 | except: |
---|
460 | # Old version of matplotlib |
---|
461 | for item in range(len(self.axes.lines)): |
---|
462 | del self.axes.lines[0] |
---|
463 | |
---|
464 | def get_radius(self): |
---|
465 | |
---|
466 | return 0 |
---|
467 | |
---|
468 | def update(self,x1=None,x2=None, y1=None,y2=None,width=None, height=None, center=None): |
---|
469 | """ |
---|
470 | Draw the new roughness on the graph. |
---|
471 | """ |
---|
472 | if width!=None: |
---|
473 | self.half_width= width |
---|
474 | if height!=None: |
---|
475 | self.half_height= height |
---|
476 | if center!=None: |
---|
477 | self.center_x= center.x |
---|
478 | self.center_y= center.y |
---|
479 | |
---|
480 | self.x1 = self.half_width + self.center_x |
---|
481 | self.x2= -self.half_width + self.center_x |
---|
482 | |
---|
483 | self.y1 = self.half_height + self.center_y |
---|
484 | self.y2= -self.half_height + self.center_y |
---|
485 | |
---|
486 | self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) |
---|
487 | self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) |
---|
488 | self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) |
---|
489 | return |
---|
490 | if x1 !=None: |
---|
491 | self.x1= x1 |
---|
492 | if x2 !=None: |
---|
493 | self.x2= x2 |
---|
494 | if y1 !=None: |
---|
495 | self.y1= y1 |
---|
496 | if y2 !=None: |
---|
497 | self.y2= y2 |
---|
498 | |
---|
499 | |
---|
500 | |
---|
501 | self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) |
---|
502 | self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) |
---|
503 | self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) |
---|
504 | |
---|
505 | |
---|
506 | def save(self, ev): |
---|
507 | """ |
---|
508 | Remember the roughness for this layer and the next so that we |
---|
509 | can restore on Esc. |
---|
510 | """ |
---|
511 | self.save_x2= self.x2 |
---|
512 | self.save_y2= self.y2 |
---|
513 | |
---|
514 | self.save_x1= self.x1 |
---|
515 | self.save_y1= self.y1 |
---|
516 | |
---|
517 | self.save_half_height= self.half_height |
---|
518 | self.save_half_width = self.half_width |
---|
519 | self.base.freeze_axes() |
---|
520 | |
---|
521 | def moveend(self, ev): |
---|
522 | |
---|
523 | self.has_move=False |
---|
524 | self.base.moveend(ev) |
---|
525 | |
---|
526 | def restore(self): |
---|
527 | """ |
---|
528 | Restore the roughness for this layer. |
---|
529 | """ |
---|
530 | self.y2= self.save_y2 |
---|
531 | self.x2= self.save_x2 |
---|
532 | |
---|
533 | self.y1= self.save_y1 |
---|
534 | self.x1= self.save_x1 |
---|
535 | |
---|
536 | self.half_height= self.save_half_height |
---|
537 | self.half_width= self.save_half_width |
---|
538 | |
---|
539 | def move(self, x, y, ev): |
---|
540 | """ |
---|
541 | Process move to a new position, making sure that the move is allowed. |
---|
542 | """ |
---|
543 | self.x1= x |
---|
544 | delta= self.x1- self.center_x |
---|
545 | self.x2= self.center_x - delta |
---|
546 | |
---|
547 | self.half_width= math.fabs(self.x1)-self.center_x |
---|
548 | self.has_move=True |
---|
549 | self.base.base.update() |
---|
550 | |
---|
551 | def set_cursor(self, x, y): |
---|
552 | self.move(x, y, None) |
---|
553 | self.update() |
---|
554 | |
---|
555 | |
---|
556 | def get_params(self): |
---|
557 | params = {} |
---|
558 | params["x"] = self.x1 |
---|
559 | params["y"] = self.y1 |
---|
560 | |
---|
561 | return params |
---|
562 | |
---|
563 | def set_params(self, params): |
---|
564 | x = params["x"] |
---|
565 | y = params["y"] |
---|
566 | self.update(x=x, y=y, center_x=None,center_y=None) |
---|
567 | |
---|
568 | class Horizontal_DoubleLine(_BaseInteractor): |
---|
569 | """ |
---|
570 | Select an annulus through a 2D plot |
---|
571 | """ |
---|
572 | def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, |
---|
573 | center_x= 0.0, |
---|
574 | center_y= 0.0): |
---|
575 | |
---|
576 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
577 | self.markers = [] |
---|
578 | self.axes = axes |
---|
579 | # center |
---|
580 | self.center_x = center_x |
---|
581 | self.center_y = center_y |
---|
582 | |
---|
583 | self.y1 = y + self.center_y |
---|
584 | self.save_y1= self.y1 |
---|
585 | |
---|
586 | delta= self.y1- self.center_y |
---|
587 | self.y2= self.center_y - delta |
---|
588 | self.save_y2= self.y2 |
---|
589 | |
---|
590 | self.x1 = x + self.center_x |
---|
591 | self.save_x1 = self.x1 |
---|
592 | |
---|
593 | delta= self.x1- self.center_x |
---|
594 | self.x2= self.center_x - delta |
---|
595 | self.save_x2 = self.x2 |
---|
596 | |
---|
597 | self.color=color |
---|
598 | |
---|
599 | self.half_height= math.fabs(y) |
---|
600 | self.save_half_height= math.fabs(y) |
---|
601 | |
---|
602 | self.half_width= math.fabs(x) |
---|
603 | self.save_half_width=math.fabs(x) |
---|
604 | |
---|
605 | try: |
---|
606 | self.top_marker = self.axes.plot([0],[self.y1], linestyle='', |
---|
607 | marker='s', markersize=10, |
---|
608 | color=self.color, alpha=0.6, |
---|
609 | pickradius=5, label="pick", |
---|
610 | zorder=zorder, # Prefer this to other lines |
---|
611 | visible=True)[0] |
---|
612 | except: |
---|
613 | self.top_marker = self.axes.plot([0],[self.y1], linestyle='', |
---|
614 | marker='s', markersize=10, |
---|
615 | color=self.color, alpha=0.6, |
---|
616 | label="pick", |
---|
617 | visible=True)[0] |
---|
618 | message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" |
---|
619 | message += "Get the SVN version that is at least as recent as June 1, 2007" |
---|
620 | |
---|
621 | #raise "Version error", message |
---|
622 | |
---|
623 | # line |
---|
624 | self.top_line = self.axes.plot([self.x1,-self.x1],[self.y1,self.y1], |
---|
625 | linestyle='-', marker='', |
---|
626 | color=self.color, |
---|
627 | visible=True)[0] |
---|
628 | self.bottom_line = self.axes.plot([self.x1,-self.x1],[self.y2,self.y2], |
---|
629 | linestyle='-', marker='', |
---|
630 | color=self.color, |
---|
631 | visible=True)[0] |
---|
632 | |
---|
633 | self.npts = 30 |
---|
634 | self.has_move=False |
---|
635 | self.connect_markers([self.top_marker]) |
---|
636 | self.update() |
---|
637 | |
---|
638 | |
---|
639 | def set_layer(self, n): |
---|
640 | self.layernum = n |
---|
641 | self.update() |
---|
642 | |
---|
643 | def clear(self): |
---|
644 | self.clear_markers() |
---|
645 | try: |
---|
646 | self.top_marker.remove() |
---|
647 | self.bottom_line.remove() |
---|
648 | self.top_line.remove() |
---|
649 | except: |
---|
650 | # Old version of matplotlib |
---|
651 | for item in range(len(self.axes.lines)): |
---|
652 | del self.axes.lines[0] |
---|
653 | |
---|
654 | def get_radius(self): |
---|
655 | |
---|
656 | return 0 |
---|
657 | |
---|
658 | def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None): |
---|
659 | """ |
---|
660 | Draw the new roughness on the graph. |
---|
661 | """ |
---|
662 | if width!=None: |
---|
663 | self.half_width= width |
---|
664 | if height!=None: |
---|
665 | self.half_height= height |
---|
666 | if center!=None: |
---|
667 | self.center_x= center.x |
---|
668 | self.center_y= center.y |
---|
669 | |
---|
670 | self.x1 = self.half_width + self.center_x |
---|
671 | self.x2= -self.half_width + self.center_x |
---|
672 | |
---|
673 | self.y1 = self.half_height + self.center_y |
---|
674 | self.y2= -self.half_height + self.center_y |
---|
675 | |
---|
676 | self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) |
---|
677 | self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) |
---|
678 | self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) |
---|
679 | return |
---|
680 | if x1 !=None: |
---|
681 | self.x1= x1 |
---|
682 | if x2 !=None: |
---|
683 | self.x2= x2 |
---|
684 | if y1 !=None: |
---|
685 | self.y1= y1 |
---|
686 | if y2 !=None: |
---|
687 | self.y2= y2 |
---|
688 | |
---|
689 | |
---|
690 | self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) |
---|
691 | self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) |
---|
692 | self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) |
---|
693 | |
---|
694 | |
---|
695 | |
---|
696 | def save(self, ev): |
---|
697 | """ |
---|
698 | Remember the roughness for this layer and the next so that we |
---|
699 | can restore on Esc. |
---|
700 | """ |
---|
701 | self.save_x2= self.x2 |
---|
702 | self.save_y2= self.y2 |
---|
703 | |
---|
704 | self.save_x1= self.x1 |
---|
705 | self.save_y1= self.y1 |
---|
706 | |
---|
707 | self.save_half_height= self.half_height |
---|
708 | self.save_half_width = self.half_width |
---|
709 | self.base.freeze_axes() |
---|
710 | |
---|
711 | |
---|
712 | def moveend(self, ev): |
---|
713 | |
---|
714 | self.has_move=False |
---|
715 | self.base.moveend(ev) |
---|
716 | |
---|
717 | def restore(self): |
---|
718 | """ |
---|
719 | Restore the roughness for this layer. |
---|
720 | """ |
---|
721 | self.y2= self.save_y2 |
---|
722 | self.x2= self.save_x2 |
---|
723 | |
---|
724 | self.y1= self.save_y1 |
---|
725 | self.x1= self.save_x1 |
---|
726 | self.half_height= self.save_half_height |
---|
727 | self.half_width= self.save_half_width |
---|
728 | |
---|
729 | def move(self, x, y, ev): |
---|
730 | """ |
---|
731 | Process move to a new position, making sure that the move is allowed. |
---|
732 | """ |
---|
733 | self.y1= y |
---|
734 | delta= self.y1- self.center_y |
---|
735 | self.y2= self.center_y - delta |
---|
736 | self.half_height= math.fabs(self.y1)-self.center_y |
---|
737 | self.has_move=True |
---|
738 | self.base.base.update() |
---|
739 | |
---|
740 | def set_cursor(self, x, y): |
---|
741 | self.move(x, y, None) |
---|
742 | self.update() |
---|
743 | |
---|
744 | |
---|
745 | def get_params(self): |
---|
746 | params = {} |
---|
747 | params["x"] = self.x |
---|
748 | params["y"] = self.y |
---|
749 | |
---|
750 | return params |
---|
751 | |
---|
752 | def set_params(self, params): |
---|
753 | x = params["x"] |
---|
754 | y = params["y"] |
---|
755 | self.update(x=x, y=y, center_x=None,center_y=None) |
---|
756 | |
---|