source: sasview/guiframe/local_perspectives/plotting/Edge.py @ d250f7d

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

comment added

  • Property mode set to 100644
File size: 4.8 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
10import wx.lib.newevent
11       
12class RadiusInteractor(_BaseInteractor):
13    """
14         Select an annulus through a 2D plot
15    """
16    def __init__(self,base,axes,color='black', zorder=5, arc1=None,arc2=None,
17                 theta=math.pi/8):
18       
19        _BaseInteractor.__init__(self, base, axes, color=color)
20        self.markers = []
21        self.axes = axes
22       
23        self.r1 = arc1.get_radius()
24        self.r2 = arc2.get_radius()
25        #print "radius init", self.r1, self.r2
26        self.theta=theta
27        self.save_theta= theta
28        #self.scale = 10.0
29        self.move_stop=False
30        self.theta_left=None
31        self.theta_right=None
32        self.arc1= arc1
33        self.arc2=arc2
34        #raise "Version error", message
35        x1= self.r1*math.cos(self.theta)
36        y1= self.r1*math.sin(self.theta)
37        x2= self.r2*math.cos(self.theta)
38        y2= self.r2*math.sin(self.theta)
39        self.line = self.axes.plot([x1,x2],[y1,y2],
40                                      linestyle='-', marker='',
41                                      color=self.color,
42                                      visible=True)[0]
43        self.phi= theta
44        self.npts = 20
45        self.has_move= False
46        self.connect_markers([self.line])
47        self.update()
48       
49       
50    def set_layer(self, n):
51        self.layernum = n
52        self.update()
53       
54    def clear(self):
55        self.clear_markers()
56        try:
57            self.line.remove()
58         
59        except:
60            # Old version of matplotlib
61            for item in range(len(self.axes.lines)):
62                del self.axes.lines[0]
63       
64       
65       
66    def get_radius(self):
67        return self.theta
68       
69    def update(self,r1=None, r2=None, theta_right=None, theta_left=None):
70        """
71        Draw the new roughness on the graph.
72        """
73        if r1 !=None:
74            self.r1=r1
75        if r2!=None:
76            self.r2=r2
77        """
78        self.theta_left=theta_left
79        self.theta_right=theta_right
80        if r1 !=None:
81            self.r1=r1
82        if r2!=None:
83            self.r2=r2
84        if theta_right!=None:
85            if theta_right < self.theta:
86                self.move_stop=True
87            else:
88                self.move_stop=False
89        if theta_left !=None:
90            if theta_left > self.theta:
91                self.move_stop=True
92            else:
93                self.move_stop=False
94        if theta_left ==None and theta_right==None:
95            self.move_stop=True
96        """
97        #print "in the edge theta_right theta_left",theta_right,theta_left,self.theta
98        x1= self.r1*math.cos(self.theta)
99        y1= self.r1*math.sin(self.theta)
100        x2= self.r2*math.cos(self.theta)
101        y2= self.r2*math.sin(self.theta) 
102             
103        self.line.set(xdata=[x1,x2], ydata=[y1,y2])
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.save_theta= self.theta
112        self.base.freeze_axes()
113   
114    def moveend(self, ev):
115        self.has_move= False
116        self.base.moveend(ev)
117           
118    def restore(self):
119        """
120        Restore the roughness for this layer.
121        """
122        self.theta = self.save_theta
123
124    def move(self, x, y, ev):
125        """
126        Process move to a new position, making sure that the move is allowed.
127        """
128        #print "on move theta left , theta right",self.theta_left,self.theta_right
129        theta= math.atan2(y,x)
130        """print "on move theta left , theta right",self.theta_left,self.theta_right,theta
131            if self.theta_left !=None:
132                if self.theta_left >= theta:
133                    print "went hier"
134                        self.move_stop= True
135                if self.theta_right !=None:
136                    if self.theta_right <= theta:
137                        self.move_stop= True
138           
139            self.move_stop= True
140            if self.move_stop:
141         """
142        self.theta= math.atan2(y,x)
143        self.has_move= True
144           
145        self.base.base.update()
146       
147    def set_cursor(self, x, y):
148        self.move(x, y, None)
149        self.update()
150       
151       
152    def get_params(self):
153        params = {}
154        params["radius1"] = self.r1
155        params["radius2"] = self.r2
156        return params
157   
158    def set_params(self, params):
159
160        x1 = params["radius1"] 
161        x2 = params["radius2"] 
162        self.set_cursor(x, self._inner_mouse_y)
163       
164   
Note: See TracBrowser for help on using the repository browser.