source: sasview/guiframe/local_perspectives/plotting/Arc.py @ b06ef8c

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 b06ef8c was b06ef8c, checked in by Gervaise Alina <gervyh@…>, 15 years ago

sector averaging

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