[0d9dae8] | 1 | |
---|
[b06ef8c] | 2 | import math |
---|
[32c0841] | 3 | #import wx |
---|
| 4 | #from copy import deepcopy |
---|
[0d9dae8] | 5 | from BaseInteractor import _BaseInteractor |
---|
[32c0841] | 6 | #from sans.guicomm.events import NewPlotEvent |
---|
| 7 | #from sans.guicomm.events import StatusEvent |
---|
| 8 | #from sans.guicomm.events import SlicerParameterEvent |
---|
| 9 | #from sans.guicomm.events import EVT_SLICER_PARS |
---|
[0d9dae8] | 10 | |
---|
[b06ef8c] | 11 | |
---|
| 12 | class RadiusInteractor(_BaseInteractor): |
---|
| 13 | """ |
---|
[d955bf19] | 14 | Select an annulus through a 2D plot |
---|
[b06ef8c] | 15 | """ |
---|
[32c0841] | 16 | def __init__(self, base, axes, color='black', zorder=5, arc1=None, |
---|
| 17 | arc2=None, theta=math.pi/8): |
---|
| 18 | """ |
---|
| 19 | """ |
---|
[b06ef8c] | 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 |
---|
[32c0841] | 26 | self.theta = theta |
---|
| 27 | self.save_theta = theta |
---|
[b06ef8c] | 28 | #self.scale = 10.0 |
---|
[32c0841] | 29 | self.move_stop = False |
---|
| 30 | self.theta_left = None |
---|
| 31 | self.theta_right = None |
---|
| 32 | self.arc1 = arc1 |
---|
| 33 | self.arc2 = arc2 |
---|
[b06ef8c] | 34 | #raise "Version error", message |
---|
[32c0841] | 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], |
---|
[b06ef8c] | 40 | linestyle='-', marker='', |
---|
| 41 | color=self.color, |
---|
| 42 | visible=True)[0] |
---|
[32c0841] | 43 | self.phi = theta |
---|
[b06ef8c] | 44 | self.npts = 20 |
---|
[32c0841] | 45 | self.has_move = False |
---|
[b06ef8c] | 46 | self.connect_markers([self.line]) |
---|
| 47 | self.update() |
---|
| 48 | |
---|
| 49 | def set_layer(self, n): |
---|
[d955bf19] | 50 | """ |
---|
| 51 | """ |
---|
[b06ef8c] | 52 | self.layernum = n |
---|
| 53 | self.update() |
---|
| 54 | |
---|
| 55 | def clear(self): |
---|
[d955bf19] | 56 | """ |
---|
| 57 | """ |
---|
[b06ef8c] | 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] |
---|
[d955bf19] | 65 | |
---|
[e8c96f5] | 66 | def get_angle(self): |
---|
[d955bf19] | 67 | """ |
---|
| 68 | """ |
---|
[b06ef8c] | 69 | return self.theta |
---|
| 70 | |
---|
[32c0841] | 71 | def update(self, r1=None, r2=None, theta=None): |
---|
[b06ef8c] | 72 | """ |
---|
| 73 | Draw the new roughness on the graph. |
---|
| 74 | """ |
---|
[d955bf19] | 75 | if r1 != None: |
---|
| 76 | self.r1 = r1 |
---|
| 77 | if r2 != None: |
---|
| 78 | self.r2 = r2 |
---|
[32c0841] | 79 | if theta != None: |
---|
| 80 | self.theta = theta |
---|
[d955bf19] | 81 | #print "in the edge r1, r2",self.r1,self.r2,math.degrees(self.theta) |
---|
[32c0841] | 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]) |
---|
[356aea78] | 87 | |
---|
[b06ef8c] | 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 | """ |
---|
[32c0841] | 93 | self.save_theta = math.atan2(ev.y,ev.x) |
---|
[e8c96f5] | 94 | #self.save_theta= self.theta |
---|
[b06ef8c] | 95 | self.base.freeze_axes() |
---|
| 96 | |
---|
| 97 | def moveend(self, ev): |
---|
[d955bf19] | 98 | """ |
---|
| 99 | """ |
---|
[32c0841] | 100 | self.has_move = False |
---|
[b06ef8c] | 101 | self.base.moveend(ev) |
---|
| 102 | |
---|
[32c0841] | 103 | def restore(self, ev): |
---|
[b06ef8c] | 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 | """ |
---|
[32c0841] | 113 | self.theta = math.atan2(y, x) |
---|
| 114 | self.has_move = True |
---|
[b06ef8c] | 115 | self.base.base.update() |
---|
| 116 | |
---|
[32c0841] | 117 | def set_cursor(self, r_min, r_max, theta): |
---|
[d955bf19] | 118 | """ |
---|
| 119 | """ |
---|
[32c0841] | 120 | self.theta = theta |
---|
| 121 | self.r1 = r_min |
---|
| 122 | self.r2 = r_max |
---|
[b06ef8c] | 123 | self.update() |
---|
| 124 | |
---|
| 125 | def get_params(self): |
---|
[d955bf19] | 126 | """ |
---|
| 127 | """ |
---|
[b06ef8c] | 128 | params = {} |
---|
| 129 | params["radius1"] = self.r1 |
---|
| 130 | params["radius2"] = self.r2 |
---|
[e8c96f5] | 131 | params["theta"] = self.theta |
---|
[b06ef8c] | 132 | return params |
---|
| 133 | |
---|
| 134 | def set_params(self, params): |
---|
[d955bf19] | 135 | """ |
---|
| 136 | """ |
---|
| 137 | #print "when here set curcor arc" |
---|
[b06ef8c] | 138 | x1 = params["radius1"] |
---|
| 139 | x2 = params["radius2"] |
---|
[e8c96f5] | 140 | theta= params["theta"] |
---|
| 141 | self.set_cursor(x1, x2, theta) |
---|
[b06ef8c] | 142 | |
---|
| 143 | |
---|