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