1 | |
---|
2 | import math |
---|
3 | import wx |
---|
4 | from copy import deepcopy |
---|
5 | |
---|
6 | from BaseInteractor import _BaseInteractor |
---|
7 | from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | class 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 | """ |
---|
52 | """ |
---|
53 | self.layernum = n |
---|
54 | self.update() |
---|
55 | |
---|
56 | def clear(self): |
---|
57 | """ |
---|
58 | """ |
---|
59 | self.clear_markers() |
---|
60 | try: |
---|
61 | self.line.remove() |
---|
62 | |
---|
63 | except: |
---|
64 | # Old version of matplotlib |
---|
65 | for item in range(len(self.axes.lines)): |
---|
66 | del self.axes.lines[0] |
---|
67 | |
---|
68 | def get_angle(self): |
---|
69 | """ |
---|
70 | """ |
---|
71 | return self.theta |
---|
72 | |
---|
73 | def update(self,r1=None, r2=None, theta=None): |
---|
74 | """ |
---|
75 | Draw the new roughness on the graph. |
---|
76 | """ |
---|
77 | if r1 != None: |
---|
78 | self.r1 = r1 |
---|
79 | if r2 != None: |
---|
80 | self.r2 = r2 |
---|
81 | if theta !=None: |
---|
82 | self.theta= theta |
---|
83 | |
---|
84 | #print "in the edge r1, r2",self.r1,self.r2,math.degrees(self.theta) |
---|
85 | x1= self.r1*math.cos(self.theta) |
---|
86 | y1= self.r1*math.sin(self.theta) |
---|
87 | x2= self.r2*math.cos(self.theta) |
---|
88 | y2= self.r2*math.sin(self.theta) |
---|
89 | |
---|
90 | self.line.set(xdata=[x1,x2], ydata=[y1,y2]) |
---|
91 | |
---|
92 | |
---|
93 | def save(self, ev): |
---|
94 | """ |
---|
95 | Remember the roughness for this layer and the next so that we |
---|
96 | can restore on Esc. |
---|
97 | """ |
---|
98 | self.save_theta= math.atan2(ev.y,ev.x) |
---|
99 | #self.save_theta= self.theta |
---|
100 | self.base.freeze_axes() |
---|
101 | |
---|
102 | def moveend(self, ev): |
---|
103 | """ |
---|
104 | """ |
---|
105 | self.has_move= False |
---|
106 | self.base.moveend(ev) |
---|
107 | |
---|
108 | def restore(self): |
---|
109 | """ |
---|
110 | Restore the roughness for this layer. |
---|
111 | """ |
---|
112 | self.theta = self.save_theta |
---|
113 | |
---|
114 | def move(self, x, y, ev): |
---|
115 | """ |
---|
116 | Process move to a new position, making sure that the move is allowed. |
---|
117 | """ |
---|
118 | self.theta= math.atan2(y,x) |
---|
119 | self.has_move= True |
---|
120 | self.base.base.update() |
---|
121 | |
---|
122 | def set_cursor(self,r_min, r_max, theta): |
---|
123 | """ |
---|
124 | """ |
---|
125 | self.theta= theta |
---|
126 | self.r1= r_min |
---|
127 | self.r2=r_max |
---|
128 | self.update() |
---|
129 | |
---|
130 | def get_params(self): |
---|
131 | """ |
---|
132 | """ |
---|
133 | params = {} |
---|
134 | params["radius1"] = self.r1 |
---|
135 | params["radius2"] = self.r2 |
---|
136 | params["theta"] = self.theta |
---|
137 | return params |
---|
138 | |
---|
139 | def set_params(self, params): |
---|
140 | """ |
---|
141 | """ |
---|
142 | #print "when here set curcor arc" |
---|
143 | x1 = params["radius1"] |
---|
144 | x2 = params["radius2"] |
---|
145 | theta= params["theta"] |
---|
146 | self.set_cursor(x1, x2, theta) |
---|
147 | |
---|
148 | |
---|