source: sasview/guiframe/local_perspectives/plotting/Arc.py @ 65a8b34

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 65a8b34 was 83f4445, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on documentation

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[0d9dae8]1
[b06ef8c]2import math
[0d9dae8]3import wx 
4from copy import deepcopy
[b06ef8c]5
[0d9dae8]6from BaseInteractor import _BaseInteractor
7from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS
8 
9 
[b06ef8c]10class ArcInteractor(_BaseInteractor):
11    """
[83f4445]12    Select an annulus through a 2D plot
[b06ef8c]13    """
14    def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta1=math.pi/8,
15                 theta2=math.pi/4):
16       
17        _BaseInteractor.__init__(self, base, axes, color=color)
18        self.markers = []
19        self.axes = axes
[cd84dca]20        self._mouse_x = r
21        self._mouse_y = 0
[b06ef8c]22       
[cd84dca]23        self._save_x  = r
24        self._save_y  = 0
[b06ef8c]25       
26        self.scale = 10.0
27       
28        self.theta1=theta1
29        self.theta2=theta2
[e8c96f5]30        self.radius= r
[cd84dca]31        [self.arc] = self.axes.plot([],[],
[b06ef8c]32                                      linestyle='-', marker='',
33                                      color=self.color)
34        self.npts = 20
[2d107b8]35        self.has_move= False   
[cd84dca]36        self.connect_markers([self.arc])
[b06ef8c]37        self.update()
38
39    def set_layer(self, n):
[83f4445]40        """
41        """
[b06ef8c]42        self.layernum = n
43        self.update()
44       
45    def clear(self):
[83f4445]46        """
47        """
[b06ef8c]48        self.clear_markers()
49        try:
[cd84dca]50            self.marker.remove()
51            self.arc.remove()
[b06ef8c]52        except:
53            # Old version of matplotlib
54            for item in range(len(self.axes.lines)):
55                del self.axes.lines[0]
56       
57    def get_radius(self):
[83f4445]58        """
59        """
[cd84dca]60        radius =math.sqrt(math.pow(self._mouse_x, 2)+math.pow(self._mouse_y, 2))
[b06ef8c]61        return radius
62       
[e8c96f5]63    def update(self,theta1=None,theta2=None, nbins=None, r=None):
[b06ef8c]64        """
65        """
66        # Plot inner circle
67        x = []
68        y = []
69        if theta1 !=None:
70            self.theta1= theta1
71        if theta2 !=None:
72            self.theta2= theta2
[e8c96f5]73       
[b98db8c]74        print "ring update theta1 theta2", math.degrees(self.theta1), math.degrees(self.theta2)
[b06ef8c]75        while self.theta2 < self.theta1: self.theta2 += 2*math.pi
[cd84dca]76        while self.theta2 >= self.theta1+2*math.pi: self.theta2 -= 2*math.pi
77
78        npts = int((self.theta2 - self.theta1)/(math.pi/120)) 
79             
80        if r ==None:
81            self.radius=  math.sqrt(math.pow(self._mouse_x, 2)+math.pow(self._mouse_y, 2))
82        else:
83            self.radius= r
84           
[b06ef8c]85        for i in range(self.npts):
86           
87            phi =(self.theta2-self.theta1)/(self.npts-1)*i +self.theta1
[e8c96f5]88           
89            xval = 1.0*self.radius*math.cos(phi) 
90            yval = 1.0*self.radius*math.sin(phi) 
91           
[b06ef8c]92            x.append(xval)
93            y.append(yval)
94       
[cd84dca]95        #self.marker.set(xdata=[self._mouse_x],ydata=[0])
96        self.arc.set_data(x, y) 
[b06ef8c]97       
[e8c96f5]98     
[b06ef8c]99    def save(self, ev):
100        """
101        Remember the roughness for this layer and the next so that we
102        can restore on Esc.
103        """
[cd84dca]104        self._save_x = self._mouse_x
105        self._save_y = self._mouse_y
106        #self._save_x = ev.xdata
107        #self._save_y = ev.ydata
[e8c96f5]108       
[b06ef8c]109        self.base.freeze_axes()
110
111    def moveend(self, ev):
[83f4445]112        """
113        """
[2d107b8]114        self.has_move= False
[e8c96f5]115       
[0d9dae8]116        event = SlicerParameterEvent()
[e8c96f5]117        event.type = self.__class__.__name__
118        event.params = self.get_params()
119        print "in arc moveend params",self.get_params()
120        #wx.PostEvent(self.base.base.parent, event)
121       
[b06ef8c]122        self.base.moveend(ev)
123           
124    def restore(self):
125        """
126        Restore the roughness for this layer.
127        """
[cd84dca]128        self._mouse_x = self._save_x
129        self._mouse_y = self._save_y
[b06ef8c]130       
131    def move(self, x, y, ev):
132        """
133        Process move to a new position, making sure that the move is allowed.
134        """
[e8c96f5]135        #print "ring move x, y", x,y
[cd84dca]136        self._mouse_x = x
137        self._mouse_y = y
[2d107b8]138        self.has_move= True
[b06ef8c]139        self.base.base.update()
140       
[e8c96f5]141    def set_cursor(self,radius, phi_min, phi_max,nbins):
[83f4445]142        """
143        """
[e8c96f5]144        self.theta1= phi_min
145        self.theta2= phi_max
146        self.update(nbins=nbins, r=radius)
[b06ef8c]147       
148       
149    def get_params(self):
[83f4445]150        """
151        """
[b06ef8c]152        params = {}
[e8c96f5]153        params["radius"] = self.radius
154        params["theta1"] = self.theta1
155        params["theta2"] = self.theta2
[b06ef8c]156        return params
157   
158    def set_params(self, params):
[83f4445]159        """
160        """
[b06ef8c]161        x = params["radius"] 
[cd84dca]162        self.set_cursor(x, self._mouse_y)
[b06ef8c]163       
164   
Note: See TracBrowser for help on using the repository browser.