[0d9dae8] | 1 | |
---|
[b06ef8c] | 2 | import math |
---|
[0d9dae8] | 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 | |
---|
[b06ef8c] | 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 |
---|
[356aea78] | 29 | self.move_stop=False |
---|
| 30 | self.theta_left=None |
---|
| 31 | self.theta_right=None |
---|
[b06ef8c] | 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] |
---|
[356aea78] | 43 | self.phi= theta |
---|
[b06ef8c] | 44 | self.npts = 20 |
---|
[2d107b8] | 45 | self.has_move= False |
---|
[b06ef8c] | 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 | |
---|
[e8c96f5] | 66 | def get_angle(self): |
---|
[b06ef8c] | 67 | return self.theta |
---|
| 68 | |
---|
[e8c96f5] | 69 | def update(self,r1=None, r2=None, theta=None): |
---|
[b06ef8c] | 70 | """ |
---|
| 71 | Draw the new roughness on the graph. |
---|
| 72 | """ |
---|
[b98db8c] | 73 | if r1 !=None: |
---|
| 74 | self.r1=r1 |
---|
| 75 | if r2!=None: |
---|
| 76 | self.r2=r2 |
---|
[e8c96f5] | 77 | if theta !=None: |
---|
| 78 | self.theta= theta |
---|
| 79 | |
---|
| 80 | print "in the edge r1, r2",self.r1,self.r2,math.degrees(self.theta) |
---|
[b06ef8c] | 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]) |
---|
[356aea78] | 87 | |
---|
[b06ef8c] | 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 | """ |
---|
[e8c96f5] | 94 | self.save_theta= math.atan2(ev.y,ev.x) |
---|
| 95 | #self.save_theta= self.theta |
---|
[b06ef8c] | 96 | self.base.freeze_axes() |
---|
| 97 | |
---|
| 98 | def moveend(self, ev): |
---|
[2d107b8] | 99 | self.has_move= False |
---|
[b06ef8c] | 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 | """ |
---|
[e8c96f5] | 112 | |
---|
[b98db8c] | 113 | self.theta= math.atan2(y,x) |
---|
| 114 | self.has_move= True |
---|
[356aea78] | 115 | |
---|
[b06ef8c] | 116 | self.base.base.update() |
---|
| 117 | |
---|
[e8c96f5] | 118 | def set_cursor(self,r_min, r_max, theta): |
---|
| 119 | self.theta= theta |
---|
| 120 | self.r1= r_min |
---|
| 121 | self.r2=r_max |
---|
[b06ef8c] | 122 | self.update() |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | def get_params(self): |
---|
| 126 | params = {} |
---|
| 127 | params["radius1"] = self.r1 |
---|
| 128 | params["radius2"] = self.r2 |
---|
[e8c96f5] | 129 | params["theta"] = self.theta |
---|
[b06ef8c] | 130 | return params |
---|
| 131 | |
---|
| 132 | def set_params(self, params): |
---|
[e8c96f5] | 133 | print "when here set curcor arc" |
---|
[b06ef8c] | 134 | |
---|
| 135 | x1 = params["radius1"] |
---|
| 136 | x2 = params["radius2"] |
---|
[e8c96f5] | 137 | theta= params["theta"] |
---|
| 138 | self.set_cursor(x1, x2, theta) |
---|
[b06ef8c] | 139 | |
---|
| 140 | |
---|