source: sasview/sansguiframe/src/sans/guiframe/local_perspectives/plotting/SectorSlicer.py @ 6a7cf2c

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 6a7cf2c was 13382fc7, checked in by Jae Cho <jhjcho@…>, 13 years ago

update average to the data explorer

  • Property mode set to 100644
File size: 22.4 KB
RevLine 
[ef0c170]1
2import math
[0d9dae8]3import wx
[32c0841]4#from copy import deepcopy
[0d9dae8]5from BaseInteractor import _BaseInteractor
[55a0dc1]6from sans.guiframe.events import NewPlotEvent
7from sans.guiframe.events import StatusEvent
8from sans.guiframe.events import SlicerParameterEvent
9from sans.guiframe.events import EVT_SLICER_PARS
[4ac8556]10from sans.guiframe.dataFitting import Data1D
[ef0c170]11
[32c0841]12
[ef0c170]13class SectorInteractor(_BaseInteractor):
14    """
[d955bf19]15    Draw a sector slicer.Allow to performQ averaging on data 2D
[ef0c170]16    """
[32c0841]17    def __init__(self, base, axes, color='black', zorder=3):
[ef0c170]18       
19        _BaseInteractor.__init__(self, base, axes, color=color)
[6c0568b]20        ## Class initialization
[ef0c170]21        self.markers = []
[6c0568b]22        self.axes = axes   
23        ## connect the plot to event
[ef0c170]24        self.connect = self.base.connect
25       
[6c0568b]26        ## compute qmax limit to reset the graph     
[32c0841]27        x = math.pow(max(self.base.data2D.xmax, 
28                         math.fabs(self.base.data2D.xmin)), 2)
29        y = math.pow(max(self.base.data2D.ymax, 
30                         math.fabs(self.base.data2D.ymin)), 2)
31        self.qmax = math.sqrt(x + y)
[ef0c170]32        ## Number of points on the plot
[b783024]33        self.nbins = 20
[6c0568b]34        ## Angle of the middle line
[32c0841]35        self.theta2 = math.pi/3
[6c0568b]36        ## Absolute value of the Angle between the middle line and any side line
[32c0841]37        self.phi = math.pi/12
[6c0568b]38        ## Middle line
[32c0841]39        self.main_line = LineInteractor(self, self.base.subplot, color='blue', 
40                                        zorder=zorder, r=self.qmax,
[ef0c170]41                                           theta= self.theta2)
[2dda74ac]42        self.main_line.qmax = self.qmax
[6c0568b]43        ## Right Side line
[32c0841]44        self.right_line = SideInteractor(self, self.base.subplot, color='black',
45                                          zorder=zorder, r=self.qmax,
46                                          phi=-1*self.phi, theta2=self.theta2)
[2dda74ac]47        self.right_line.qmax = self.qmax
[6c0568b]48        ## Left Side line
[32c0841]49        self.left_line = SideInteractor(self, self.base.subplot, color='black',
50                                        zorder=zorder, r=self.qmax,
51                                           phi=self.phi, theta2=self.theta2)
[2dda74ac]52        self.left_line.qmax = self.qmax
[6c0568b]53        ## draw the sector               
[ef0c170]54        self.update()
55        self._post_data()
[6c0568b]56        ## Bind to slice parameter events
[1ce365f8]57        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS)
[ef0c170]58
59    def _onEVT_SLICER_PARS(self, event):
[6c0568b]60        """
[d955bf19]61        receive an event containing parameters values to reset the slicer
62       
63        :param event: event of type SlicerParameterEvent with params as
64        attribute
65       
[6c0568b]66        """
[32c0841]67        wx.PostEvent(self.base.parent,
68                     StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS"))
[ef0c170]69        event.Skip()
70        if event.type == self.__class__.__name__:
71            self.set_params(event.params)
72            self.base.update()
[d955bf19]73           
[ef0c170]74    def set_layer(self, n):
[6c0568b]75        """
[d955bf19]76         Allow adding plot to the same panel
77         
78        :param n: the number of layer
79       
[6c0568b]80        """
[ef0c170]81        self.layernum = n
82        self.update()
83       
84    def clear(self):
[6c0568b]85        """
[d955bf19]86        Clear the slicer and all connected events related to this slicer
[6c0568b]87        """
[ef0c170]88        self.clear_markers()
89        self.main_line.clear()
90        self.left_line.clear()
91        self.right_line.clear()
[18eba35]92        self.base.connect.clearall()
[d468daa]93        self.base.Unbind(EVT_SLICER_PARS)
[ef0c170]94       
95    def update(self):
96        """
[d955bf19]97        Respond to changes in the model by recalculating the profiles and
98        resetting the widgets.
[ef0c170]99        """
[6c0568b]100        # Update locations 
[32c0841]101        ## Check if the middle line was dragged and
102        #update the picture accordingly     
[ef0c170]103        if self.main_line.has_move:
104            self.main_line.update()
[32c0841]105            self.right_line.update(delta=-self.left_line.phi/2,
106                                    mline=self.main_line.theta)
107            self.left_line.update(delta=self.left_line.phi/2,
108                                   mline=self.main_line.theta)
[6c0568b]109        ## Check if the left side has moved and update the slicer accordingly 
[ef0c170]110        if self.left_line.has_move:
111            self.main_line.update()
[32c0841]112            self.left_line.update(phi=None, delta=None, mline=self.main_line,
113                                  side=True, left=True)
114            self.right_line.update(phi=self.left_line.phi, delta=None,
115                                     mline=self.main_line, side=True,
116                                     left=False, right=True)
117        ## Check if the right side line has moved and
118        #update the slicer accordingly
[ef0c170]119        if self.right_line.has_move:
120            self.main_line.update()
[32c0841]121            self.right_line.update(phi=None, delta=None, mline=self.main_line,
122                                   side=True, left=False, right=True)
123            self.left_line.update(phi=self.right_line.phi, delta=None,
124                                    mline=self.main_line, side=True, left=False)
[d955bf19]125           
[ef0c170]126    def save(self, ev):
127        """
128        Remember the roughness for this layer and the next so that we
129        can restore on Esc.
130        """
131        self.base.freeze_axes()
[6c0568b]132        self.main_line.save(ev)
133        self.right_line.save(ev)
134        self.left_line.save(ev)
[ef0c170]135
136    def _post_data(self, nbins=None):
[6c0568b]137        """
[d955bf19]138        compute sector averaging of data2D into data1D
139       
140        :param nbins: the number of point to plot for the average 1D data
[6c0568b]141        """
142        ## get the data2D to average
[ef0c170]143        data = self.base.data2D
144        # If we have no data, just return
145        if data == None:
146            return
[6c0568b]147        ## Averaging
[db7a82e]148        from sans.dataloader.manipulations import SectorQ
[6c0568b]149        radius = self.qmax
150        phimin =  -self.left_line.phi + self.main_line.theta
151        phimax = self.left_line.phi + self.main_line.theta
[32c0841]152        if nbins == None:
[1ce365f8]153            nbins = 20
[32c0841]154        sect = SectorQ(r_min=0.0, r_max=radius,
155                        phi_min=phimin + math.pi,
156                        phi_max=phimax + math.pi, nbins=nbins)
[6c0568b]157     
[ef0c170]158        sector = sect(self.base.data2D)
[6c0568b]159        ##Create 1D data resulting from average
[4ac8556]160       
[32c0841]161        if hasattr(sector, "dxl"):
162            dxl = sector.dxl
[ef0c170]163        else:
[32c0841]164            dxl = None
165        if hasattr(sector, "dxw"):
166            dxw = sector.dxw
[ef0c170]167        else:
[32c0841]168            dxw = None
[21969a4a]169        new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy, dx=sector.dx)
[4ac8556]170        new_plot.dxl = dxl
171        new_plot.dxw = dxw
[32c0841]172        new_plot.name = "SectorQ" + "(" + self.base.data2D.name + ")"
173        new_plot.source = self.base.data2D.source
[8b30e62]174        #new_plot.info=self.base.data2D.info
[ef0c170]175        new_plot.interactive = True
[32c0841]176        new_plot.detector = self.base.data2D.detector
[21969a4a]177        ## If the data file does not tell us what the axes are, just assume...
178        new_plot.xaxis("\\rm{Q}", "A^{-1}")
[7f59ee8e]179        new_plot.yaxis("\\rm{Intensity}", "cm^{-1}")
[fcf072d]180        if hasattr(data, "scale") and data.scale == 'linear' and \
181                self.base.data2D.name.count("Residuals") > 0:
[7f59ee8e]182            new_plot.ytransform = 'y'
183            new_plot.yaxis("\\rm{Residuals} ", "/")
184
[32c0841]185        new_plot.group_id = "SectorQ" + self.base.data2D.name
[21969a4a]186        new_plot.id = None
[32c0841]187        new_plot.is_data = True
[13382fc7]188        self.base.parent.update_theory(data_id=data, \
189                                       theory=new_plot)
[ef0c170]190        wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot,
[32c0841]191                                    title="SectorQ" + self.base.data2D.name))
[ef0c170]192       
193    def moveend(self, ev):
[6c0568b]194        """
[d955bf19]195        Called a dragging motion ends.Get slicer event
[6c0568b]196        """
[ef0c170]197        self.base.thaw_axes()
[6c0568b]198        ## Post parameters
[0d9dae8]199        event = SlicerParameterEvent()
[ef0c170]200        event.type = self.__class__.__name__
201        event.params = self.get_params()
[6c0568b]202        ## Send slicer paramers to plotter2D
[d468daa]203        wx.PostEvent(self.base, event)
[d955bf19]204       
[ef0c170]205    def restore(self):
206        """
207        Restore the roughness for this layer.
208        """
209        self.main_line.restore()
210        self.left_line.restore()
211        self.right_line.restore()
212
213    def move(self, x, y, ev):
214        """
215        Process move to a new position, making sure that the move is allowed.
216        """
217        pass
218       
219    def set_cursor(self, x, y):
[d955bf19]220        """
221        """
[ef0c170]222        pass
223       
224    def get_params(self):
[6c0568b]225        """
[d955bf19]226        Store a copy of values of parameters of the slicer into a dictionary.
227       
228        :return params: the dictionary created
229       
[6c0568b]230        """
[ef0c170]231        params = {}
[6c0568b]232        ## Always make sure that the left and the right line are at phi
233        ## angle of the middle line
[ef0c170]234        if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi):
[32c0841]235            msg = "Phi left and phi right are different"
236            msg += " %f, %f" % (self.left_line.phi, self.right_line.phi)
237            raise ValueError, msg
[6c0568b]238        params["Phi"] = self.main_line.theta
[1a6ec25]239        params["Delta_Phi"] = math.fabs(self.left_line.phi)
[ef0c170]240        params["nbins"] = self.nbins
241        return params
242   
243    def set_params(self, params):
[6c0568b]244        """
[d955bf19]245        Receive a dictionary and reset the slicer with values contained
246        in the values of the dictionary.
247       
248        :param params: a dictionary containing name of slicer parameters and
[6c0568b]249            values the user assigned to the slicer.
250        """
[1a6ec25]251        main = params["Phi"] 
[32c0841]252        phi = math.fabs(params["Delta_Phi"])
[ef0c170]253        self.nbins = int(params["nbins"])
[32c0841]254        self.main_line.theta = main
[6c0568b]255        ## Reset the slicer parameters
[ef0c170]256        self.main_line.update()
[32c0841]257        self.right_line.update(phi=phi, delta=None, mline=self.main_line,
258                               side=True, right=True)
259        self.left_line.update(phi=phi, delta=None, 
260                              mline=self.main_line, side=True)
[6c0568b]261        ## post the new corresponding data
[ef0c170]262        self._post_data(nbins=self.nbins)
263       
264    def freeze_axes(self):
[d955bf19]265        """
266        """
[ef0c170]267        self.base.freeze_axes()
[d955bf19]268   
[ef0c170]269    def thaw_axes(self):
[d955bf19]270        """
271        """
[ef0c170]272        self.base.thaw_axes()
273
274    def draw(self):
[d955bf19]275        """
276        """
[ef0c170]277        self.base.draw()
278
279       
280class SideInteractor(_BaseInteractor):
281    """
[d955bf19]282    Draw an oblique line
283   
284    :param phi: the phase between the middle line and one side line
285    :param theta2: the angle between the middle line and x- axis
286   
[ef0c170]287    """
[32c0841]288    def __init__(self, base, axes, color='black', zorder=5, r=1.0,
289                 phi=math.pi/4, theta2= math.pi/3):
290        """
291        """
[ef0c170]292        _BaseInteractor.__init__(self, base, axes, color=color)
[6c0568b]293        ## Initialize the class
[ef0c170]294        self.markers = []
295        self.axes = axes
[6c0568b]296        ## compute the value of the angle between the current line and
297        ## the x-axis 
[ef0c170]298        self.save_theta = theta2 + phi
[32c0841]299        self.theta = theta2 + phi
[6c0568b]300        ## the value of the middle line angle with respect to the x-axis
[ef0c170]301        self.theta2 = theta2
[6c0568b]302        ## Radius to find polar coordinates this line's endpoints
[ef0c170]303        self.radius = r
[6c0568b]304        ## phi is the phase between the current line and the middle line
[ef0c170]305        self.phi = phi
[6c0568b]306        ## End points polar coordinates
[32c0841]307        x1 = self.radius * math.cos(self.theta)
308        y1 = self.radius * math.sin(self.theta)
309        x2 = -1 * self.radius * math.cos(self.theta)
310        y2 = -1 * self.radius * math.sin(self.theta)
[6c0568b]311        ## defining a new marker
[7a28ba7]312        try:
[32c0841]313            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',
[7a28ba7]314                                          marker='s', markersize=10,
315                                          color=self.color, alpha=0.6,
316                                          pickradius=5, label="pick", 
[32c0841]317                                          # Prefer this to other lines
318                                          zorder=zorder, visible=True)[0]
[7a28ba7]319        except:
[0c218d9]320            self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='',
[7a28ba7]321                                          marker='s', markersize=10,
322                                          color=self.color, alpha=0.6,
[32c0841]323                                          label="pick", visible=True)[0]
324            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST"
325            message += " VERSION OF MATPLOTLIB\n Get the SVN version that"
326            message += " is at least as recent as June 1, 2007"
327            owner = self.base.base.parent
328            wx.PostEvent(owner, 
329                         StatusEvent(status="sectorSlicer: %s" % message))
[6c0568b]330       
331        ## Defining the current line
[32c0841]332        self.line = self.axes.plot([x1, x2], [y1, y2],
[ef0c170]333                                      linestyle='-', marker='',
[32c0841]334                                      color=self.color, visible=True)[0]
[6c0568b]335        ## Flag to differentiate the left line from the right line motion
[32c0841]336        self.left_moving = False
[6c0568b]337        ## Flag to define a motion
[32c0841]338        self.has_move = False
[6c0568b]339        ## connecting markers and draw the picture
[7a28ba7]340        self.connect_markers([self.inner_marker, self.line])
[6c0568b]341       
[ef0c170]342    def set_layer(self, n):
[6c0568b]343        """
[d955bf19]344        Allow adding plot to the same panel
345         
346        :param n: the number of layer
347       
[6c0568b]348        """
[ef0c170]349        self.layernum = n
350        self.update()
351       
352    def clear(self):
[6c0568b]353        """
[d955bf19]354        Clear the slicer and all connected events related to this slicer
[6c0568b]355        """
[ef0c170]356        self.clear_markers()
357        try:
358            self.line.remove()
[7a28ba7]359            self.inner_marker.remove()
[ef0c170]360        except:
361            # Old version of matplotlib
362            for item in range(len(self.axes.lines)):
363                del self.axes.lines[0]
[d955bf19]364   
[6c0568b]365    def update(self, phi=None, delta=None, mline=None,
366               side=False, left= False, right=False):
[ef0c170]367        """
[d955bf19]368        Draw oblique line
369       
370        :param phi: the phase between the middle line and the current line
371        :param delta: phi/2 applied only when the mline was moved
372       
[ef0c170]373        """
374        #print "update left or right ", self.has_move
[32c0841]375        self.left_moving = left
376        theta3 = 0
377        if phi != None:
378            self.phi = phi
379        if delta == None:
[31e3298]380            delta = 0
[7a28ba7]381        if  right:
[32c0841]382            self.phi = -1 * math.fabs(self.phi)
[31e3298]383            #delta=-delta
[7a28ba7]384        else:
[32c0841]385            self.phi = math.fabs(self.phi)
[e23a20c]386        if side:
[32c0841]387            self.theta = mline.theta + self.phi
[31e3298]388                   
[32c0841]389        if mline != None :
390            if delta != 0:
391                self.theta2 = mline + delta
[31e3298]392            else:
393                self.theta2 = mline.theta
[32c0841]394        if delta == 0:
395            theta3 = self.theta + delta
[31e3298]396        else:
[32c0841]397            theta3 = self.theta2 + delta
398        x1 = self.radius * math.cos(theta3)
399        y1 = self.radius * math.sin(theta3)
400        x2 = -1 * self.radius * math.cos(theta3)
401        y2 = -1 * self.radius * math.sin(theta3)
402        self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5])
403        self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 
[ef0c170]404       
405    def save(self, ev):
406        """
407        Remember the roughness for this layer and the next so that we
408        can restore on Esc.
409        """
[32c0841]410        self.save_theta = self.theta
[ef0c170]411        self.base.freeze_axes()
412
413    def moveend(self, ev):
[d955bf19]414        """
415        """
[32c0841]416        self.has_move = False
[ef0c170]417        self.base.moveend(ev)
418           
419    def restore(self):
420        """
421        Restore the roughness for this layer.
422        """
423        self.theta = self.save_theta
424
425    def move(self, x, y, ev):
426        """
427        Process move to a new position, making sure that the move is allowed.
428        """
[32c0841]429        self.theta = math.atan2(y, x)
430        self.has_move = True
[0c218d9]431        #ToDo: Simplify below
[7a28ba7]432        if not self.left_moving:
[32c0841]433            if  self.theta2 - self.theta <= 0 and self.theta2 > 0:
[0c218d9]434                self.restore()
435                return 
[32c0841]436            elif self.theta2 < 0 and self.theta < 0 and \
437                self.theta-self.theta2 >= 0:
[0c218d9]438                self.restore()
439                return                             
[32c0841]440            elif  self.theta2 < 0 and self.theta > 0 and \
441                (self.theta2 + 2 * math.pi - self.theta) >= math.pi/2:
[0c218d9]442                #print "my theta", self.theta
443                self.restore()
444                return 
[32c0841]445            elif  self.theta2 < 0 and self.theta < 0 and \
446                (self.theta2 - self.theta) >= math.pi/2:
[0c218d9]447                #print "my theta", self.theta
[7a28ba7]448                self.restore()
449                return 
[32c0841]450            elif self.theta2 > 0 and (self.theta2-self.theta >= math.pi/2 or \
451                (self.theta2-self.theta >= math.pi/2)):
[0c218d9]452                #print "self theta encore"
[7a28ba7]453                self.restore()
454                return 
455        else:
[0c218d9]456            #print "left move"
[32c0841]457            if  self.theta < 0 and (self.theta + math.pi*2-self.theta2) <= 0:
[7a28ba7]458                self.restore()
459                return 
[32c0841]460            elif self.theta2 < 0 and (self.theta-self.theta2) <= 0:
[0c218d9]461                self.restore()
462                return                             
[32c0841]463            elif  self.theta > 0 and self.theta-self.theta2 <= 0:
[0c218d9]464                #print "my theta", self.theta
465                self.restore()
466                return 
[32c0841]467            elif self.theta-self.theta2 >= math.pi/2 or  \
468                ((self.theta + math.pi * 2 - self.theta2) >= math.pi/2 and \
469                 self.theta < 0 and self.theta2 > 0):
[0c218d9]470                #print "self theta encore"
[7a28ba7]471                self.restore()
472                return 
[0c218d9]473           
[32c0841]474        self.phi = math.fabs(self.theta2 - self.theta)
475        if self.phi > math.pi:
476            self.phi = 2 * math.pi - math.fabs(self.theta2 - self.theta)
[ef0c170]477        self.base.base.update()
478       
479    def set_cursor(self, x, y):
[d955bf19]480        """
481        """
[ef0c170]482        self.move(x, y, None)
483        self.update()
[d955bf19]484   
[ef0c170]485    def get_params(self):
[d955bf19]486        """
487        """
[ef0c170]488        params = {}
489        params["radius"] = self.radius
490        params["theta"] = self.theta
491        return params
492   
493    def set_params(self, params):
[d955bf19]494        """
495        """
[ef0c170]496        x = params["radius"] 
497        self.set_cursor(x, self._inner_mouse_y)
498       
[d955bf19]499
[ef0c170]500class LineInteractor(_BaseInteractor):
501    """
[d955bf19]502    Select an annulus through a 2D plot
[ef0c170]503    """
[32c0841]504    def __init__(self, base, axes, color='black',
505                 zorder=5, r=1.0, theta=math.pi/4):
[d955bf19]506        """
507        """
[ef0c170]508        _BaseInteractor.__init__(self, base, axes, color=color)
[d955bf19]509       
[ef0c170]510        self.markers = []
511        self.axes = axes
512        self.save_theta = theta
513        self.theta= theta
514        self.radius = r
515        self.scale = 10.0
516        # Inner circle
[32c0841]517        x1 = self.radius * math.cos(self.theta)
518        y1 = self.radius * math.sin(self.theta)
519        x2 = -1*self.radius * math.cos(self.theta)
520        y2 = -1*self.radius * math.sin(self.theta)
[7a28ba7]521        try:
522            # Inner circle marker
[32c0841]523            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',
[7a28ba7]524                                          marker='s', markersize=10,
525                                          color=self.color, alpha=0.6,
526                                          pickradius=5, label="pick", 
[32c0841]527                                          # Prefer this to other lines
528                                          zorder=zorder, 
[7a28ba7]529                                          visible=True)[0]
530        except:
[32c0841]531            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',
[7a28ba7]532                                          marker='s', markersize=10,
533                                          color=self.color, alpha=0.6,
534                                          label="pick", 
535                                          visible=True)[0]
[32c0841]536            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION"
537            message += " OF MATPLOTLIB\n Get the SVN version that is at"
538            message += " least as recent as June 1, 2007"
539        self.line = self.axes.plot([x1, x2], [y1, y2],
[ef0c170]540                                      linestyle='-', marker='',
[32c0841]541                                      color=self.color, visible=True)[0]
[ef0c170]542        self.npts = 20
[32c0841]543        self.has_move = False
[7a28ba7]544        self.connect_markers([self.inner_marker, self.line])
[ef0c170]545        self.update()
546
547    def set_layer(self, n):
[d955bf19]548        """
549        """
[ef0c170]550        self.layernum = n
551        self.update()
552       
553    def clear(self):
[d955bf19]554        """
555        """
[ef0c170]556        self.clear_markers()
557        try:
[7a28ba7]558            self.inner_marker.remove()
[ef0c170]559            self.line.remove()
560        except:
561            # Old version of matplotlib
562            for item in range(len(self.axes.lines)):
563                del self.axes.lines[0]
[6c0568b]564 
[ef0c170]565    def update(self, theta=None):
566        """
567        Draw the new roughness on the graph.
568        """
[6c0568b]569       
[32c0841]570        if theta != None:
571            self.theta = theta
572        x1 = self.radius * math.cos(self.theta)
573        y1 = self.radius * math.sin(self.theta)
574        x2 = -1 * self.radius * math.cos(self.theta)
575        y2 = -1 * self.radius * math.sin(self.theta)
576       
577        self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5])
578        self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 
[d955bf19]579   
[ef0c170]580    def save(self, ev):
581        """
582        Remember the roughness for this layer and the next so that we
583        can restore on Esc.
584        """
585        self.save_theta= self.theta
586        self.base.freeze_axes()
587
588    def moveend(self, ev):
[d955bf19]589        """
590        """
[32c0841]591        self.has_move = False
[ef0c170]592        self.base.moveend(ev)
593           
594    def restore(self):
595        """
596        Restore the roughness for this layer.
597        """
598        self.theta = self.save_theta
599
600    def move(self, x, y, ev):
601        """
602        Process move to a new position, making sure that the move is allowed.
603        """
[32c0841]604        self.theta = math.atan2(y, x)
605        self.has_move = True
[ef0c170]606        self.base.base.update()
607       
608    def set_cursor(self, x, y):
[d955bf19]609        """
610        """
[ef0c170]611        self.move(x, y, None)
612        self.update()
613       
614    def get_params(self):
[d955bf19]615        """
616        """
[ef0c170]617        params = {}
618        params["radius"] = self.radius
619        params["theta"] = self.theta
620        return params
621   
622    def set_params(self, params):
[d955bf19]623        """
624        """
[ef0c170]625        x = params["radius"] 
626        self.set_cursor(x, self._inner_mouse_y)
[356aea78]627       
Note: See TracBrowser for help on using the repository browser.