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
RevLine 
[2d107b8]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
[38224f10]10#from config import printEVT
[2d107b8]11from BaseInteractor import _BaseInteractor
12from copy import deepcopy
13import math
14
[38224f10]15#from Plotter1D import AddPlotEvent
[2d107b8]16import SlicerParameters
17import wx
18
[38224f10]19class BoxInteractor(_BaseInteractor):
[2d107b8]20    """
21         Select an annulus through a 2D plot
22    """
[c73d871]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):
[2d107b8]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
[8ff3ec1]31        self.xmin= -1* x_min
32        self.ymin= -1* y_min
[b6b1669]33       
[8ff3ec1]34        self.xmax= x_max
35        self.ymax=  y_max
36       
[b6b1669]37        self.theta2= math.pi/4
[2d107b8]38        ## Number of points on the plot
39        self.nbins = 20
[38224f10]40        self.count=0
41        self.error=0
[c73d871]42        self.main_line = LineInteractor(self, self.base.subplot,color='orange',
43                                         zorder=zorder, r=self.qmax,
[8ff3ec1]44                                           theta= self.theta2)
45        self.main_line.qmax = self.base.qmax
46       
[c73d871]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,
[8ff3ec1]54                                        theta2= self.theta2)
[2d107b8]55        self.left_line.qmax = self.base.qmax
56       
[c73d871]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)
[2d107b8]65        self.right_line.qmax = self.base.qmax
[c73d871]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
[2d107b8]75       
[c73d871]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,
[8ff3ec1]86                                    y= self.ymax,
87                                    xmin= self.xmin, xmax= self.xmax,
88                                     theta2= self.theta2)
[2d107b8]89        self.top_line.qmax = self.base.qmax
90       
[c73d871]91        self.bottom_line= HorizontalLine(self, self.base.subplot,color='red',
92                                          zorder=zorder,
[8ff3ec1]93                                    y =self.ymin,
94                                    xmin= self.xmin, xmax= self.xmax,
95                                     theta2= self.theta2)
[2d107b8]96        self.bottom_line.qmax = self.base.qmax
97        #self.outer_circle.set_cursor(self.base.qmax/1.8, 0)
98       
[c73d871]99           """           
[38224f10]100        self.update()
101        #self._post_data()
[2d107b8]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):
[38224f10]108        #printEVT("AnnulusSlicer._onEVT_SLICER_PARS")
[2d107b8]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()
[38224f10]134        self.left_line.clear()
135        self.right_line.clear()
[c73d871]136        #self.top_line.clear()
137        #self.bottom_line.clear()
[8ff3ec1]138        self.main_line.clear()
[2d107b8]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        """
[8ff3ec1]147       
148        if self.main_line.has_move:
[c73d871]149           
[8ff3ec1]150            self.main_line.update()
[d5a792a]151            self.left_line.update(
[c73d871]152                                  xmin= self.xmin,
153                                  xmax= self.xmin,
154                                  ymin= self.ymin,
155                                  ymax=self.ymax,
156                                  translation=True)
[d5a792a]157            self.right_line.update(
[c73d871]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)
[8ff3ec1]165       
[2d107b8]166        if self.left_line.has_move:
167            print "left has moved"
[d5a792a]168            self.left_line.update()
169            self.right_line.update(opline= self.left_line )
[c73d871]170            """
[b6b1669]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)
[c73d871]175            """
[2d107b8]176        if self.right_line.has_move:
177            print "right has moved"
[d5a792a]178            self.right_line.update()
179            self.left_line.update(opline= self.right_line )
[c73d871]180            """
[b6b1669]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)
[c73d871]185            """
[2d107b8]186           
[c73d871]187        """   
[2d107b8]188        if self.bottom_line.has_move:
189            print "bottom has moved"
[b6b1669]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)
[2d107b8]198           
199        if self.top_line.has_move:
200            print "top has moved"
[cd68f8c]201            self.top_line.update(mline= self.main_line,translation=True)
[b6b1669]202            self.bottom_line.update(ymin= -1*self.top_line.ymin,
203                                    ymax=-1*self.top_line.ymax,
[cd68f8c]204                                    translation=True )
[b6b1669]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)
[c73d871]209        """
[38224f10]210   
[2d107b8]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
[d054809]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
[c73d871]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)
[38224f10]230       
[c73d871]231        #self.count, self.error= box(self.base.data2D)
[b319def8]232       
[d054809]233        print "post data"
[b319def8]234             
[38224f10]235                                       
[2d107b8]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 = {}
[c73d871]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
[38224f10]269        params["count"] = self.count
270        params["error"] = self.error
[8ff3ec1]271        params["phi"] = self.main_line.theta
[2d107b8]272        return params
273   
274    def set_params(self, params):
275       
[38224f10]276        x_min = params["x_min"] 
277        x_max = params["x_max"] 
[c73d871]278        #y_min = params["y_min"]
279        #y_max = params["y_max"]
[8ff3ec1]280        theta = params["theta"]
[2d107b8]281       
[38224f10]282        self.left_line.update(ymin= y_min ,ymax= y_max)
283        self.right_line.update(ymin= y_min ,ymax= y_max)
[c73d871]284        #self.top_line.update( xmin= x_min ,xmax= xmax)
285        #self.bottom_line.update(xmin= xmin ,xmax= xmax)
[8ff3ec1]286        self.main_line.update(theta)
287       
[38224f10]288        self._post_data()
[2d107b8]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    """
[8ff3ec1]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 ):
[2d107b8]305       
306        _BaseInteractor.__init__(self, base, axes, color=color)
307        self.markers = []
308        self.axes = axes
309       
[78ed1ad]310        self.y= y
[7ab9241]311        self.save_y = y
[2d107b8]312       
[7ab9241]313        self.xmin = xmin
314        self.save_xmin = xmin
315        self.xmax = xmax
316        self.save_xmax = xmax
[8ff3ec1]317       
[78ed1ad]318        self.theta2 = theta2
[8ff3ec1]319       
[b6b1669]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
[c73d871]326       
[78ed1ad]327        x1= self.xmin*math.cos(self.theta2)- self.y*math.sin(self.theta2)
[b6b1669]328        self.ymin= self.xmin*math.sin(self.theta2)+ self.y*math.sin(self.theta2)
[2d107b8]329       
[78ed1ad]330        x2= self.xmax*math.cos(self.theta2)- self.y*math.sin(self.theta2)
[b6b1669]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],
[2d107b8]334                                      linestyle='-', marker='',
335                                      color=self.color,
336                                      visible=True)[0]
[8ff3ec1]337 
[c73d871]338       
339       
[2d107b8]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]
[b6b1669]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
[c73d871]365       
366       
[b6b1669]367        #self.save(ev)
368        return True   
[2d107b8]369    def get_radius(self):
370       
371        return 0
[8ff3ec1]372   
[b6b1669]373    def update(self,xmin=None, xmax=None,ymin=None,ymax=None, mline=None,translation=False):
[2d107b8]374        """
375        Draw the new roughness on the graph.
376        """
377        #print "update main line", self.has_move
[b6b1669]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])
[8ff3ec1]398        if mline !=None:
399            self.theta2= mline.theta
[78ed1ad]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)
[8ff3ec1]406           
407            self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 
408            print x1,x2,y1,y2
409           
[cd68f8c]410        #else:
411        #    self.line.set(xdata=[self.xmin,self.xmax], ydata=[self.y,self.y])
[2d107b8]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):
[b6b1669]427        self.clickxf,self.clickyf = ev.xdata,ev.ydata
428        print "move end ",self.clickxf,self.clickyf
[2d107b8]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        """
[c73d871]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        """
[2d107b8]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    """
[c73d871]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,
[8ff3ec1]477                 theta2= math.pi/3 ):
[2d107b8]478       
479        _BaseInteractor.__init__(self, base, axes, color=color)
480        self.markers = []
481        self.axes = axes
[c73d871]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
[2d107b8]488        self.ymax=ymax
[c73d871]489        self.save_ymax= ymax
[8ff3ec1]490        self.theta2= theta2
[c73d871]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)
[8ff3ec1]495       
[c73d871]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
[b6b1669]501       
[d5a792a]502       
[c73d871]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)
[b6b1669]509       
[c73d871]510        self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2],
[2d107b8]511                                      linestyle='-', marker='',
512                                      color=self.color,
513                                      visible=True)[0]
514     
515        self.npts = 20
[8ff3ec1]516        # Check vertical line motion
[2d107b8]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]
[c73d871]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   
[2d107b8]545    def get_radius(self):
546        return 0
[8ff3ec1]547   
[d5a792a]548    def update(self,xmin=None,xmax=None,ymin=None, ymax=None, opline=None,translation=False):
[2d107b8]549        """
550        Draw the new roughness on the graph.
551        """
[d5a792a]552        if opline !=None:
553            self.line.set(xdata=[-1*opline.x1,-1*opline.x2],
554                           ydata=[-opline.y1,-opline.y2]) 
555            return
[c73d871]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
[b6b1669]567
[c73d871]568        self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) 
[d5a792a]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
[c73d871]573        if translation:
[d5a792a]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
[c73d871]582            self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) 
[2d107b8]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        """
[78ed1ad]588        #self.save_x= self.x
[d054809]589        self.save_xmin= self.x1
590        self.save_xmax= self.x2
591        self.save_ymin= self.y1
592        self.save_ymax= self.y2
[8ff3ec1]593       
[2d107b8]594        self.base.freeze_axes()
595
596    def moveend(self, ev):
[b6b1669]597        self.clickxf,self.clickyf = ev.xdata,ev.ydata
598        print "move end ",self.clickxf,self.clickyf
[2d107b8]599        self.has_move=False
600        self.base.moveend(ev)
601           
602    def restore(self):
603        """
604        Restore the roughness for this layer.
605        """
[78ed1ad]606        self.xmin = self.save_xmin
607        self.xmax = self.save_xmax
[d5a792a]608        self.ymin = self.save_ymin
609        self.ymax = self.save_ymax
[78ed1ad]610       
611       
[2d107b8]612    def move(self, x, y, ev):
613        """
614        Process move to a new position, making sure that the move is allowed.
615        """
[8ff3ec1]616        self.has_move=True
[d5a792a]617        self.L_width=x
618       
619       
[8ff3ec1]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)
[2d107b8]646       
[8ff3ec1]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
[2d107b8]658       
[8ff3ec1]659        self.save_theta = theta
660        self.theta= theta
[2d107b8]661       
[8ff3ec1]662        self.radius = r
663     
664        self.scale = 10.0
665           
666        # Inner circle
[c73d871]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)
[8ff3ec1]671       
[c73d871]672        self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2],
[8ff3ec1]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)
[c73d871]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)
[8ff3ec1]724     
[c73d871]725        self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) 
[8ff3ec1]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)
[2d107b8]754        self.has_move=True
755        self.base.base.update()
756       
[8ff3ec1]757       
[2d107b8]758    def set_cursor(self, x, y):
[8ff3ec1]759       
[2d107b8]760        self.move(x, y, None)
761        self.update()
762       
763       
764    def get_params(self):
[8ff3ec1]765        """
766            return params a dictionary containing values of paramters necessary to draw
767            this line
768        """
[2d107b8]769        params = {}
[8ff3ec1]770        params["radius"] = self.radius
771        params["theta"] = self.theta
[2d107b8]772        return params
773   
774    def set_params(self, params):
[8ff3ec1]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 )
[2d107b8]782       
783
784
[8ff3ec1]785
[2d107b8]786       
Note: See TracBrowser for help on using the repository browser.