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 | 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_angle(self): |
---|
67 | return self.theta |
---|
68 | |
---|
69 | def update(self,r1=None, r2=None, theta=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 | if theta !=None: |
---|
78 | self.theta= theta |
---|
79 | |
---|
80 | print "in the edge r1, r2",self.r1,self.r2,math.degrees(self.theta) |
---|
81 | x1= self.r1*math.cos(self.theta) |
---|
82 | y1= self.r1*math.sin(self.theta) |
---|
83 | x2= self.r2*math.cos(self.theta) |
---|
84 | y2= self.r2*math.sin(self.theta) |
---|
85 | |
---|
86 | self.line.set(xdata=[x1,x2], ydata=[y1,y2]) |
---|
87 | |
---|
88 | |
---|
89 | def save(self, ev): |
---|
90 | """ |
---|
91 | Remember the roughness for this layer and the next so that we |
---|
92 | can restore on Esc. |
---|
93 | """ |
---|
94 | self.save_theta= math.atan2(ev.y,ev.x) |
---|
95 | #self.save_theta= self.theta |
---|
96 | self.base.freeze_axes() |
---|
97 | |
---|
98 | def moveend(self, ev): |
---|
99 | self.has_move= False |
---|
100 | self.base.moveend(ev) |
---|
101 | |
---|
102 | def restore(self): |
---|
103 | """ |
---|
104 | Restore the roughness for this layer. |
---|
105 | """ |
---|
106 | self.theta = self.save_theta |
---|
107 | |
---|
108 | def move(self, x, y, ev): |
---|
109 | """ |
---|
110 | Process move to a new position, making sure that the move is allowed. |
---|
111 | """ |
---|
112 | |
---|
113 | self.theta= math.atan2(y,x) |
---|
114 | self.has_move= True |
---|
115 | |
---|
116 | self.base.base.update() |
---|
117 | |
---|
118 | def set_cursor(self,r_min, r_max, theta): |
---|
119 | self.theta= theta |
---|
120 | self.r1= r_min |
---|
121 | self.r2=r_max |
---|
122 | self.update() |
---|
123 | |
---|
124 | |
---|
125 | def get_params(self): |
---|
126 | params = {} |
---|
127 | params["radius1"] = self.r1 |
---|
128 | params["radius2"] = self.r2 |
---|
129 | params["theta"] = self.theta |
---|
130 | return params |
---|
131 | |
---|
132 | def set_params(self, params): |
---|
133 | print "when here set curcor arc" |
---|
134 | |
---|
135 | x1 = params["radius1"] |
---|
136 | x2 = params["radius2"] |
---|
137 | theta= params["theta"] |
---|
138 | self.set_cursor(x1, x2, theta) |
---|
139 | |
---|
140 | |
---|