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

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

comment added

  • Property mode set to 100644
File size: 4.7 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        self.has_move= False   
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", math.degrees(self.theta1), math.degrees(self.theta2)
72        while self.theta2 < self.theta1: self.theta2 += 2*math.pi
73        npts = int((self.theta2 - self.theta1)/(math.pi/120))
74       
75       
76           
77           
78        for i in range(self.npts):
79           
80            phi =(self.theta2-self.theta1)/(self.npts-1)*i +self.theta1
81            #delta= phi1-phi
82            r=  math.sqrt(math.pow(self._inner_mouse_x, 2)+math.pow(self._inner_mouse_y, 2))
83            xval = 1.0*r*math.cos(phi) 
84            yval = 1.0*r*math.sin(phi) 
85            #xval = 1.0*self._inner_mouse_x*math.cos(phi)
86            #yval = 1.0*self._inner_mouse_x*math.sin(phi)
87         
88           
89            x.append(xval)
90            y.append(yval)
91       
92        #self.inner_marker.set(xdata=[self._inner_mouse_x],ydata=[0])
93        self.inner_circle.set_data(x, y) 
94       
95        """
96        r=  math.sqrt(math.pow(self._inner_mouse_x, 2)+math.pow(self._inner_mouse_y, 2))
97        x1=  r*math.cos(self.theta1)
98        y1= r*math.sin(self.theta1)
99        """
100        #x1= self._inner_mouse_x*math.cos(self.theta1)
101        #y1= self._inner_mouse_x*math.sin(self.theta1)
102        #x2= r2*math.cos(self.theta1)
103        #y2= r2*math.sin(self.theta1)
104       
105   
106    def save(self, ev):
107        """
108        Remember the roughness for this layer and the next so that we
109        can restore on Esc.
110        """
111        #self._inner_save_x = self._inner_mouse_x
112        #self._inner_save_y = self._inner_mouse_y
113        self._inner_save_x = ev.xdata
114        self._inner_save_y = ev.ydata
115        print "save value",self._inner_save_x ,self._inner_save_y
116        self.base.freeze_axes()
117
118    def moveend(self, ev):
119        self.has_move= False
120        self.base.moveend(ev)
121           
122    def restore(self):
123        """
124        Restore the roughness for this layer.
125        """
126        self._inner_mouse_x = self._inner_save_x
127        self._inner_mouse_y = self._inner_save_y
128       
129    def move(self, x, y, ev):
130        """
131        Process move to a new position, making sure that the move is allowed.
132        """
133        print "ring move x, y", x,y
134        self._inner_mouse_x = x
135        self._inner_mouse_y = y
136        self.has_move= True
137        self.base.base.update()
138       
139    def set_cursor(self, x, y):
140        self.move(x, y, None)
141        self.update()
142       
143       
144    def get_params(self):
145        params = {}
146        params["radius"] = self._inner_mouse_x
147        return params
148   
149    def set_params(self, params):
150
151        x = params["radius"] 
152        self.set_cursor(x, self._inner_mouse_y)
153       
154   
Note: See TracBrowser for help on using the repository browser.