source: sasview/sansguiframe/src/sans/guiframe/local_perspectives/plotting/Arc.py @ fec4939

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 fec4939 was 8c347a6, checked in by Gervaise Alina <gervyh@…>, 13 years ago

moving guiframe under sansguiframe

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