source: sasview/guiframe/local_perspectives/plotting/boxSlicer.py @ d5a792a

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d5a792a was d5a792a, checked in by Gervaise Alina <gervyh@…>, 16 years ago

working on boxslicer

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