[78ed1ad] | 1 | #TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it |
---|
| 2 | # before pushing a new 1D data update. |
---|
| 3 | |
---|
| 4 | # |
---|
| 5 | #TODO: NEED MAJOR REFACTOR |
---|
| 6 | # |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | # Debug printout |
---|
| 10 | #from config import printEVT |
---|
| 11 | from BaseInteractor import _BaseInteractor |
---|
| 12 | from copy import deepcopy |
---|
| 13 | import math |
---|
| 14 | |
---|
| 15 | #from Plotter1D import AddPlotEvent |
---|
| 16 | import SlicerParameters |
---|
| 17 | import wx |
---|
[54cc36a] | 18 | #(SlicerParamUpdateEvent, EVT_SLICER_PARS_UPDATE) = wx.lib.newevent.NewEvent() |
---|
| 19 | from sans.guicomm.events import SlicerParamUpdateEvent |
---|
[78ed1ad] | 20 | class BoxSum(_BaseInteractor): |
---|
| 21 | """ |
---|
| 22 | Select an annulus through a 2D plot |
---|
| 23 | """ |
---|
[2a3a890] | 24 | def __init__(self,base,axes,color='black', zorder=3, x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): |
---|
[78ed1ad] | 25 | |
---|
| 26 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 27 | self.markers = [] |
---|
| 28 | self.axes = axes |
---|
[2a3a890] | 29 | self.qmax = self.base.data2D.xmax |
---|
[78ed1ad] | 30 | self.connect = self.base.connect |
---|
| 31 | |
---|
| 32 | self.xmin= -1* x_min |
---|
| 33 | self.ymin= -1* y_min |
---|
| 34 | self.xmax= x_max |
---|
| 35 | self.ymax= y_max |
---|
| 36 | # center of the figure |
---|
[2a3a890] | 37 | self.center_x= 0.002 |
---|
| 38 | self.center_y= 0.003 |
---|
[78ed1ad] | 39 | |
---|
| 40 | ## Number of points on the plot |
---|
| 41 | self.nbins = 20 |
---|
| 42 | self.count=0 |
---|
| 43 | self.error=0 |
---|
[2a3a890] | 44 | self.has_move= False |
---|
| 45 | |
---|
| 46 | self.horizontal_lines= Horizontal_DoubleLine(self, self.base.subplot,color='blue', |
---|
| 47 | zorder=zorder, |
---|
[78ed1ad] | 48 | y= self.ymax, |
---|
[2a3a890] | 49 | x= self.xmax, |
---|
[78ed1ad] | 50 | center_x= self.center_x, |
---|
| 51 | center_y= self.center_y) |
---|
[2a3a890] | 52 | self.horizontal_lines.qmax = self.qmax |
---|
[78ed1ad] | 53 | |
---|
[2a3a890] | 54 | self.vertical_lines= Vertical_DoubleLine(self, self.base.subplot,color='black', |
---|
| 55 | zorder=zorder, |
---|
| 56 | y= self.ymax, |
---|
| 57 | x= self.xmax, |
---|
[78ed1ad] | 58 | center_x= self.center_x, |
---|
| 59 | center_y= self.center_y) |
---|
[2a3a890] | 60 | self.vertical_lines.qmax = self.qmax |
---|
| 61 | self.center= PointInteractor(self, self.base.subplot,color='grey', |
---|
| 62 | zorder=zorder, |
---|
| 63 | center_x= self.center_x, |
---|
| 64 | center_y= self.center_y) |
---|
| 65 | |
---|
| 66 | |
---|
[54cc36a] | 67 | #self.connect_markers([]) |
---|
[78ed1ad] | 68 | |
---|
| 69 | self.update() |
---|
[92c2345] | 70 | self._post_data() |
---|
[78ed1ad] | 71 | |
---|
| 72 | # Bind to slice parameter events |
---|
[54cc36a] | 73 | print "box sum self.base.parent",self.base.parent |
---|
[78ed1ad] | 74 | self.base.parent.Bind(SlicerParameters.EVT_SLICER_PARS, self._onEVT_SLICER_PARS) |
---|
[54cc36a] | 75 | |
---|
[78ed1ad] | 76 | def _onEVT_SLICER_PARS(self, event): |
---|
| 77 | #printEVT("AnnulusSlicer._onEVT_SLICER_PARS") |
---|
| 78 | event.Skip() |
---|
| 79 | if event.type == self.__class__.__name__: |
---|
[92c2345] | 80 | self.set_params(event.params) |
---|
[78ed1ad] | 81 | self.base.update() |
---|
| 82 | |
---|
| 83 | def update_and_post(self): |
---|
| 84 | self.update() |
---|
| 85 | self._post_data() |
---|
| 86 | |
---|
| 87 | def save_data(self, path, image, x, y): |
---|
| 88 | output = open(path, 'w') |
---|
| 89 | |
---|
| 90 | data_x, data_y = self.get_data(image, x, y) |
---|
| 91 | |
---|
| 92 | output.write("<phi> <average>\n") |
---|
| 93 | for i in range(len(data_x)): |
---|
| 94 | output.write("%g %g\n" % (data_x[i], data_y[i])) |
---|
| 95 | output.close() |
---|
| 96 | |
---|
| 97 | def set_layer(self, n): |
---|
| 98 | self.layernum = n |
---|
| 99 | self.update() |
---|
| 100 | |
---|
| 101 | def clear(self): |
---|
| 102 | self.clear_markers() |
---|
[2a3a890] | 103 | self.horizontal_lines.clear() |
---|
| 104 | self.vertical_lines.clear() |
---|
| 105 | self.center.clear() |
---|
[78ed1ad] | 106 | |
---|
| 107 | #self.base.connect.disconnect() |
---|
| 108 | self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS) |
---|
| 109 | |
---|
| 110 | def update(self): |
---|
| 111 | """ |
---|
| 112 | Respond to changes in the model by recalculating the profiles and |
---|
| 113 | resetting the widgets. |
---|
| 114 | """ |
---|
[2a3a890] | 115 | if self.center.has_move: |
---|
| 116 | print "center has move" |
---|
| 117 | self.center.update() |
---|
| 118 | self.horizontal_lines.update( center= self.center) |
---|
| 119 | self.vertical_lines.update( center= self.center) |
---|
[78ed1ad] | 120 | |
---|
[2a3a890] | 121 | if self.horizontal_lines.has_move: |
---|
[78ed1ad] | 122 | print "top has moved" |
---|
[2a3a890] | 123 | self.horizontal_lines.update() |
---|
| 124 | self.vertical_lines.update(y1=self.horizontal_lines.y1, |
---|
| 125 | y2=self.horizontal_lines.y2, |
---|
| 126 | height= self.horizontal_lines.half_height ) |
---|
| 127 | if self.vertical_lines.has_move: |
---|
| 128 | print "right has moved" |
---|
| 129 | self.vertical_lines.update() |
---|
| 130 | self.horizontal_lines.update(x1=self.vertical_lines.x1, |
---|
| 131 | x2=self.vertical_lines.x2, |
---|
| 132 | width=self.vertical_lines.half_width) |
---|
[78ed1ad] | 133 | |
---|
[2a3a890] | 134 | |
---|
[78ed1ad] | 135 | def save(self, ev): |
---|
| 136 | """ |
---|
| 137 | Remember the roughness for this layer and the next so that we |
---|
| 138 | can restore on Esc. |
---|
| 139 | """ |
---|
| 140 | self.base.freeze_axes() |
---|
[2a3a890] | 141 | self.horizontal_lines.save(ev) |
---|
| 142 | self.vertical_lines.save(ev) |
---|
| 143 | self.center.save(ev) |
---|
| 144 | |
---|
[78ed1ad] | 145 | def _post_data(self): |
---|
| 146 | # Compute data |
---|
[2a3a890] | 147 | print |
---|
[54cc36a] | 148 | |
---|
[78ed1ad] | 149 | data = self.base.data2D |
---|
| 150 | from DataLoader.manipulations import Boxavg |
---|
| 151 | radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) |
---|
[54cc36a] | 152 | x_min= self.vertical_lines.x2 |
---|
| 153 | x_max= self.vertical_lines.x1 |
---|
| 154 | y_min= self.vertical_lines.y2 |
---|
| 155 | y_max= self.vertical_lines.y1 |
---|
[78ed1ad] | 156 | box = Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) |
---|
[92c2345] | 157 | self.count, self.error = box(self.base.data2D) |
---|
| 158 | print "count, error",self.count, self.error |
---|
[54cc36a] | 159 | |
---|
[78ed1ad] | 160 | def moveend(self, ev): |
---|
| 161 | self.base.thaw_axes() |
---|
| 162 | # Post paramters |
---|
[54cc36a] | 163 | self._post_data() |
---|
| 164 | """ |
---|
[78ed1ad] | 165 | event = SlicerParameters.SlicerParameterEvent() |
---|
| 166 | event.type = self.__class__.__name__ |
---|
[92c2345] | 167 | print "event type boxsum: ", event.type |
---|
| 168 | event.params = self.get_params() |
---|
[54cc36a] | 169 | wx.PostEvent(self.base, event) |
---|
| 170 | """ |
---|
| 171 | self.type= self.__class__.__name__ |
---|
| 172 | params= self.get_params() |
---|
| 173 | event = SlicerParamUpdateEvent(type=self.type, params=params) |
---|
| 174 | wx.PostEvent(self.base, event) |
---|
[92c2345] | 175 | |
---|
[78ed1ad] | 176 | |
---|
| 177 | def restore(self): |
---|
| 178 | """ |
---|
| 179 | Restore the roughness for this layer. |
---|
| 180 | """ |
---|
[2a3a890] | 181 | self.horizontal_lines.restore() |
---|
| 182 | self.vertical_lines.restore() |
---|
| 183 | self.center.restore() |
---|
[78ed1ad] | 184 | def move(self, x, y, ev): |
---|
| 185 | """ |
---|
| 186 | Process move to a new position, making sure that the move is allowed. |
---|
| 187 | """ |
---|
[2a3a890] | 188 | pass |
---|
| 189 | |
---|
[78ed1ad] | 190 | def set_cursor(self, x, y): |
---|
| 191 | pass |
---|
| 192 | |
---|
| 193 | def get_params(self): |
---|
| 194 | params = {} |
---|
[2a3a890] | 195 | |
---|
| 196 | params["x"] = math.fabs(self.horizontal_lines.half_width) |
---|
| 197 | params["y"] = math.fabs(self.vertical_lines.half_height) |
---|
| 198 | |
---|
| 199 | params["center_x"] = self.center.x |
---|
| 200 | params["center_y"] =self.center.y |
---|
[0f6d05f8] | 201 | params["count"] = self.count |
---|
| 202 | params["errors"]= self.error |
---|
[2a3a890] | 203 | |
---|
[78ed1ad] | 204 | return params |
---|
| 205 | |
---|
[92c2345] | 206 | |
---|
| 207 | def get_result(self): |
---|
| 208 | """ |
---|
| 209 | return the result of box summation |
---|
| 210 | """ |
---|
| 211 | result={} |
---|
| 212 | result["count"] = self.count |
---|
| 213 | result["error"] = self.error |
---|
| 214 | return result |
---|
| 215 | |
---|
| 216 | |
---|
[78ed1ad] | 217 | def set_params(self, params): |
---|
| 218 | |
---|
[2a3a890] | 219 | x_max = math.fabs(params["x"] ) |
---|
| 220 | y_max = math.fabs(params["y"] ) |
---|
[78ed1ad] | 221 | |
---|
[2a3a890] | 222 | self.center_x=params["center_x"] |
---|
| 223 | self.center_y=params["center_y"] |
---|
| 224 | |
---|
| 225 | self.center.update(center_x=self.center_x,center_y=self.center_y) |
---|
| 226 | |
---|
| 227 | self.horizontal_lines.update(center= self.center, |
---|
| 228 | width=x_max, |
---|
| 229 | height=y_max) |
---|
| 230 | self.vertical_lines.update(center= self.center, |
---|
| 231 | width=x_max, |
---|
| 232 | height=y_max) |
---|
[78ed1ad] | 233 | |
---|
| 234 | self._post_data() |
---|
[2a3a890] | 235 | |
---|
| 236 | |
---|
| 237 | |
---|
[78ed1ad] | 238 | def freeze_axes(self): |
---|
| 239 | self.base.freeze_axes() |
---|
| 240 | |
---|
| 241 | def thaw_axes(self): |
---|
| 242 | self.base.thaw_axes() |
---|
| 243 | |
---|
| 244 | def draw(self): |
---|
| 245 | self.base.draw() |
---|
[2a3a890] | 246 | class PointInteractor(_BaseInteractor): |
---|
[78ed1ad] | 247 | """ |
---|
| 248 | Select an annulus through a 2D plot |
---|
| 249 | """ |
---|
[2a3a890] | 250 | def __init__(self,base,axes,color='black', zorder=5, |
---|
[9b05b2f] | 251 | center_x= 0.0, |
---|
| 252 | center_y= 0.0): |
---|
[78ed1ad] | 253 | |
---|
| 254 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 255 | self.markers = [] |
---|
| 256 | self.axes = axes |
---|
| 257 | # center |
---|
[2a3a890] | 258 | self.x = center_x |
---|
| 259 | self.y = center_y |
---|
[78ed1ad] | 260 | |
---|
[2a3a890] | 261 | self.save_x = center_x |
---|
| 262 | self.save_y = center_y |
---|
| 263 | |
---|
[78ed1ad] | 264 | |
---|
[2a3a890] | 265 | try: |
---|
| 266 | self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', |
---|
| 267 | marker='s', markersize=10, |
---|
| 268 | color=self.color, alpha=0.6, |
---|
| 269 | pickradius=5, label="pick", |
---|
| 270 | zorder=zorder, # Prefer this to other lines |
---|
| 271 | visible=True)[0] |
---|
| 272 | except: |
---|
| 273 | self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', |
---|
| 274 | marker='s', markersize=10, |
---|
| 275 | color=self.color, alpha=0.6, |
---|
| 276 | label="pick", |
---|
| 277 | visible=True)[0] |
---|
| 278 | message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" |
---|
| 279 | message += "Get the SVN version that is at least as recent as June 1, 2007" |
---|
| 280 | |
---|
| 281 | #raise "Version error", message |
---|
| 282 | |
---|
| 283 | # line |
---|
| 284 | self.center = self.axes.plot([self.x],[self.y], |
---|
[78ed1ad] | 285 | linestyle='-', marker='', |
---|
| 286 | color=self.color, |
---|
| 287 | visible=True)[0] |
---|
[2a3a890] | 288 | |
---|
| 289 | self.npts = 30 |
---|
| 290 | self.has_move=False |
---|
| 291 | self.connect_markers([self.center_marker]) |
---|
[78ed1ad] | 292 | self.update() |
---|
[54cc36a] | 293 | |
---|
[78ed1ad] | 294 | def set_layer(self, n): |
---|
| 295 | self.layernum = n |
---|
| 296 | self.update() |
---|
| 297 | |
---|
| 298 | def clear(self): |
---|
| 299 | self.clear_markers() |
---|
| 300 | try: |
---|
[2a3a890] | 301 | self.center.remove() |
---|
[54cc36a] | 302 | self.center_marker.remove() |
---|
[78ed1ad] | 303 | except: |
---|
| 304 | # Old version of matplotlib |
---|
| 305 | for item in range(len(self.axes.lines)): |
---|
| 306 | del self.axes.lines[0] |
---|
| 307 | |
---|
| 308 | def get_radius(self): |
---|
| 309 | |
---|
| 310 | return 0 |
---|
| 311 | |
---|
[2a3a890] | 312 | def update(self, center_x=None,center_y=None): |
---|
[78ed1ad] | 313 | """ |
---|
| 314 | Draw the new roughness on the graph. |
---|
| 315 | """ |
---|
[2a3a890] | 316 | if center_x !=None: self.x= center_x |
---|
| 317 | if center_y !=None: self.y= center_y |
---|
| 318 | |
---|
| 319 | self.center_marker.set(xdata=[self.x], ydata=[self.y]) |
---|
| 320 | self.center.set(xdata=[self.x], ydata=[self.y]) |
---|
| 321 | |
---|
[78ed1ad] | 322 | |
---|
| 323 | |
---|
| 324 | |
---|
| 325 | def save(self, ev): |
---|
| 326 | """ |
---|
| 327 | Remember the roughness for this layer and the next so that we |
---|
| 328 | can restore on Esc. |
---|
| 329 | """ |
---|
[2a3a890] | 330 | self.save_x= self.x |
---|
[78ed1ad] | 331 | self.save_y= self.y |
---|
[2a3a890] | 332 | |
---|
[78ed1ad] | 333 | self.base.freeze_axes() |
---|
| 334 | |
---|
| 335 | def moveend(self, ev): |
---|
| 336 | |
---|
| 337 | self.has_move=False |
---|
| 338 | self.base.moveend(ev) |
---|
| 339 | |
---|
| 340 | def restore(self): |
---|
| 341 | """ |
---|
| 342 | Restore the roughness for this layer. |
---|
| 343 | """ |
---|
[9b05b2f] | 344 | self.y= self.save_y |
---|
[2a3a890] | 345 | self.x= self.save_x |
---|
| 346 | |
---|
[78ed1ad] | 347 | def move(self, x, y, ev): |
---|
| 348 | """ |
---|
| 349 | Process move to a new position, making sure that the move is allowed. |
---|
| 350 | """ |
---|
[2a3a890] | 351 | self.x= x |
---|
| 352 | self.y= y |
---|
| 353 | |
---|
[78ed1ad] | 354 | self.has_move=True |
---|
| 355 | self.base.base.update() |
---|
| 356 | |
---|
| 357 | def set_cursor(self, x, y): |
---|
| 358 | self.move(x, y, None) |
---|
| 359 | self.update() |
---|
| 360 | |
---|
| 361 | |
---|
| 362 | def get_params(self): |
---|
| 363 | params = {} |
---|
[2a3a890] | 364 | params["x"] = self.x |
---|
| 365 | params["y"] = self.y |
---|
[92c2345] | 366 | |
---|
[78ed1ad] | 367 | return params |
---|
| 368 | |
---|
| 369 | def set_params(self, params): |
---|
[2a3a890] | 370 | center_x = params["x"] |
---|
| 371 | center_y = params["y"] |
---|
| 372 | self.update(center_x=center_x,center_y=center_y) |
---|
| 373 | |
---|
[78ed1ad] | 374 | |
---|
[2a3a890] | 375 | class Vertical_DoubleLine(_BaseInteractor): |
---|
[78ed1ad] | 376 | """ |
---|
| 377 | Select an annulus through a 2D plot |
---|
| 378 | """ |
---|
[2a3a890] | 379 | def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, |
---|
| 380 | center_x= 0.0, |
---|
| 381 | center_y= 0.0): |
---|
[78ed1ad] | 382 | |
---|
| 383 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 384 | self.markers = [] |
---|
| 385 | self.axes = axes |
---|
[2a3a890] | 386 | # center |
---|
| 387 | self.center_x = center_x |
---|
| 388 | self.center_y = center_y |
---|
| 389 | |
---|
| 390 | |
---|
| 391 | |
---|
| 392 | self.y1 = y + self.center_y |
---|
| 393 | self.save_y1= self.y1 |
---|
| 394 | |
---|
| 395 | delta= self.y1- self.center_y |
---|
| 396 | self.y2= self.center_y - delta |
---|
| 397 | self.save_y2= self.y2 |
---|
| 398 | |
---|
| 399 | self.x1 = x + self.center_x |
---|
| 400 | self.save_x1 = self.x1 |
---|
| 401 | |
---|
| 402 | delta= self.x1- self.center_x |
---|
| 403 | self.x2= self.center_x - delta |
---|
| 404 | self.save_x2 = self.x2 |
---|
| 405 | |
---|
| 406 | self.color=color |
---|
| 407 | |
---|
| 408 | self.half_height= math.fabs(y) |
---|
| 409 | self.save_half_height= math.fabs(y) |
---|
| 410 | |
---|
| 411 | self.half_width= math.fabs(x) |
---|
| 412 | self.save_half_width=math.fabs(x) |
---|
| 413 | |
---|
| 414 | try: |
---|
| 415 | self.right_marker = self.axes.plot([self.x1],[0], linestyle='', |
---|
| 416 | marker='s', markersize=10, |
---|
| 417 | color=self.color, alpha=0.6, |
---|
| 418 | pickradius=5, label="pick", |
---|
| 419 | zorder=zorder, # Prefer this to other lines |
---|
| 420 | visible=True)[0] |
---|
| 421 | except: |
---|
| 422 | self.right_marker = self.axes.plot([self.x1],[0], linestyle='', |
---|
| 423 | marker='s', markersize=10, |
---|
| 424 | color=self.color, alpha=0.6, |
---|
| 425 | label="pick", |
---|
| 426 | visible=True)[0] |
---|
| 427 | message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" |
---|
| 428 | message += "Get the SVN version that is at least as recent as June 1, 2007" |
---|
| 429 | |
---|
| 430 | #raise "Version error", message |
---|
| 431 | |
---|
| 432 | # line |
---|
| 433 | self.right_line = self.axes.plot([self.x1,self.x1],[self.y1,self.y2], |
---|
[78ed1ad] | 434 | linestyle='-', marker='', |
---|
| 435 | color=self.color, |
---|
| 436 | visible=True)[0] |
---|
[2a3a890] | 437 | self.left_line = self.axes.plot([self.x2,self.x2],[self.y1,self.y2], |
---|
| 438 | linestyle='-', marker='', |
---|
| 439 | color=self.color, |
---|
| 440 | visible=True)[0] |
---|
| 441 | |
---|
| 442 | self.npts = 30 |
---|
| 443 | self.has_move=False |
---|
| 444 | self.connect_markers([self.right_marker]) |
---|
[78ed1ad] | 445 | self.update() |
---|
| 446 | |
---|
[2a3a890] | 447 | |
---|
[78ed1ad] | 448 | def set_layer(self, n): |
---|
| 449 | self.layernum = n |
---|
| 450 | self.update() |
---|
| 451 | |
---|
| 452 | def clear(self): |
---|
| 453 | self.clear_markers() |
---|
| 454 | try: |
---|
[54cc36a] | 455 | self.right_marker.remove() |
---|
[2a3a890] | 456 | self.right_line.remove() |
---|
| 457 | self.left_line.remove() |
---|
[78ed1ad] | 458 | except: |
---|
| 459 | # Old version of matplotlib |
---|
| 460 | for item in range(len(self.axes.lines)): |
---|
| 461 | del self.axes.lines[0] |
---|
| 462 | |
---|
| 463 | def get_radius(self): |
---|
[2a3a890] | 464 | |
---|
[78ed1ad] | 465 | return 0 |
---|
[2a3a890] | 466 | |
---|
| 467 | def update(self,x1=None,x2=None, y1=None,y2=None,width=None, height=None, center=None): |
---|
[78ed1ad] | 468 | """ |
---|
| 469 | Draw the new roughness on the graph. |
---|
| 470 | """ |
---|
[2a3a890] | 471 | if width!=None: |
---|
| 472 | self.half_width= width |
---|
| 473 | if height!=None: |
---|
| 474 | self.half_height= height |
---|
| 475 | if center!=None: |
---|
| 476 | self.center_x= center.x |
---|
| 477 | self.center_y= center.y |
---|
| 478 | |
---|
| 479 | self.x1 = self.half_width + self.center_x |
---|
| 480 | self.x2= -self.half_width + self.center_x |
---|
| 481 | |
---|
| 482 | self.y1 = self.half_height + self.center_y |
---|
| 483 | self.y2= -self.half_height + self.center_y |
---|
| 484 | |
---|
| 485 | self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) |
---|
| 486 | self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) |
---|
| 487 | self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) |
---|
| 488 | return |
---|
| 489 | if x1 !=None: |
---|
| 490 | self.x1= x1 |
---|
| 491 | if x2 !=None: |
---|
| 492 | self.x2= x2 |
---|
| 493 | if y1 !=None: |
---|
| 494 | self.y1= y1 |
---|
| 495 | if y2 !=None: |
---|
| 496 | self.y2= y2 |
---|
[78ed1ad] | 497 | |
---|
[2a3a890] | 498 | |
---|
| 499 | |
---|
| 500 | self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) |
---|
| 501 | self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) |
---|
| 502 | self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) |
---|
[78ed1ad] | 503 | |
---|
| 504 | |
---|
| 505 | def save(self, ev): |
---|
| 506 | """ |
---|
| 507 | Remember the roughness for this layer and the next so that we |
---|
| 508 | can restore on Esc. |
---|
| 509 | """ |
---|
[2a3a890] | 510 | self.save_x2= self.x2 |
---|
| 511 | self.save_y2= self.y2 |
---|
[78ed1ad] | 512 | |
---|
[2a3a890] | 513 | self.save_x1= self.x1 |
---|
| 514 | self.save_y1= self.y1 |
---|
| 515 | |
---|
| 516 | self.save_half_height= self.half_height |
---|
| 517 | self.save_half_width = self.half_width |
---|
[78ed1ad] | 518 | self.base.freeze_axes() |
---|
| 519 | |
---|
| 520 | def moveend(self, ev): |
---|
| 521 | |
---|
| 522 | self.has_move=False |
---|
| 523 | self.base.moveend(ev) |
---|
| 524 | |
---|
| 525 | def restore(self): |
---|
| 526 | """ |
---|
| 527 | Restore the roughness for this layer. |
---|
| 528 | """ |
---|
[2a3a890] | 529 | self.y2= self.save_y2 |
---|
| 530 | self.x2= self.save_x2 |
---|
| 531 | |
---|
| 532 | self.y1= self.save_y1 |
---|
| 533 | self.x1= self.save_x1 |
---|
[78ed1ad] | 534 | |
---|
[2a3a890] | 535 | self.half_height= self.save_half_height |
---|
| 536 | self.half_width= self.save_half_width |
---|
| 537 | |
---|
[78ed1ad] | 538 | def move(self, x, y, ev): |
---|
| 539 | """ |
---|
| 540 | Process move to a new position, making sure that the move is allowed. |
---|
| 541 | """ |
---|
[2a3a890] | 542 | self.x1= x |
---|
| 543 | delta= self.x1- self.center_x |
---|
| 544 | self.x2= self.center_x - delta |
---|
| 545 | |
---|
| 546 | self.half_width= math.fabs(self.x1)-self.center_x |
---|
[78ed1ad] | 547 | self.has_move=True |
---|
| 548 | self.base.base.update() |
---|
| 549 | |
---|
| 550 | def set_cursor(self, x, y): |
---|
| 551 | self.move(x, y, None) |
---|
| 552 | self.update() |
---|
| 553 | |
---|
| 554 | |
---|
| 555 | def get_params(self): |
---|
| 556 | params = {} |
---|
[2a3a890] | 557 | params["x"] = self.x1 |
---|
| 558 | params["y"] = self.y1 |
---|
| 559 | |
---|
[78ed1ad] | 560 | return params |
---|
| 561 | |
---|
| 562 | def set_params(self, params): |
---|
[2a3a890] | 563 | x = params["x"] |
---|
| 564 | y = params["y"] |
---|
| 565 | self.update(x=x, y=y, center_x=None,center_y=None) |
---|
| 566 | |
---|
| 567 | class Horizontal_DoubleLine(_BaseInteractor): |
---|
| 568 | """ |
---|
| 569 | Select an annulus through a 2D plot |
---|
| 570 | """ |
---|
| 571 | def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, |
---|
| 572 | center_x= 0.0, |
---|
| 573 | center_y= 0.0): |
---|
| 574 | |
---|
| 575 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 576 | self.markers = [] |
---|
| 577 | self.axes = axes |
---|
| 578 | # center |
---|
| 579 | self.center_x = center_x |
---|
| 580 | self.center_y = center_y |
---|
| 581 | |
---|
| 582 | self.y1 = y + self.center_y |
---|
| 583 | self.save_y1= self.y1 |
---|
| 584 | |
---|
| 585 | delta= self.y1- self.center_y |
---|
| 586 | self.y2= self.center_y - delta |
---|
| 587 | self.save_y2= self.y2 |
---|
| 588 | |
---|
| 589 | self.x1 = x + self.center_x |
---|
| 590 | self.save_x1 = self.x1 |
---|
| 591 | |
---|
| 592 | delta= self.x1- self.center_x |
---|
| 593 | self.x2= self.center_x - delta |
---|
| 594 | self.save_x2 = self.x2 |
---|
| 595 | |
---|
| 596 | self.color=color |
---|
| 597 | |
---|
| 598 | self.half_height= math.fabs(y) |
---|
| 599 | self.save_half_height= math.fabs(y) |
---|
| 600 | |
---|
| 601 | self.half_width= math.fabs(x) |
---|
| 602 | self.save_half_width=math.fabs(x) |
---|
| 603 | |
---|
| 604 | try: |
---|
| 605 | self.top_marker = self.axes.plot([0],[self.y1], linestyle='', |
---|
| 606 | marker='s', markersize=10, |
---|
| 607 | color=self.color, alpha=0.6, |
---|
| 608 | pickradius=5, label="pick", |
---|
| 609 | zorder=zorder, # Prefer this to other lines |
---|
| 610 | visible=True)[0] |
---|
| 611 | except: |
---|
| 612 | self.top_marker = self.axes.plot([0],[self.y1], linestyle='', |
---|
| 613 | marker='s', markersize=10, |
---|
| 614 | color=self.color, alpha=0.6, |
---|
| 615 | label="pick", |
---|
| 616 | visible=True)[0] |
---|
| 617 | message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" |
---|
| 618 | message += "Get the SVN version that is at least as recent as June 1, 2007" |
---|
| 619 | |
---|
| 620 | #raise "Version error", message |
---|
| 621 | |
---|
| 622 | # line |
---|
| 623 | self.top_line = self.axes.plot([self.x1,-self.x1],[self.y1,self.y1], |
---|
| 624 | linestyle='-', marker='', |
---|
| 625 | color=self.color, |
---|
| 626 | visible=True)[0] |
---|
| 627 | self.bottom_line = self.axes.plot([self.x1,-self.x1],[self.y2,self.y2], |
---|
| 628 | linestyle='-', marker='', |
---|
| 629 | color=self.color, |
---|
| 630 | visible=True)[0] |
---|
| 631 | |
---|
| 632 | self.npts = 30 |
---|
| 633 | self.has_move=False |
---|
| 634 | self.connect_markers([self.top_marker]) |
---|
| 635 | self.update() |
---|
| 636 | |
---|
| 637 | |
---|
| 638 | def set_layer(self, n): |
---|
| 639 | self.layernum = n |
---|
| 640 | self.update() |
---|
| 641 | |
---|
| 642 | def clear(self): |
---|
| 643 | self.clear_markers() |
---|
| 644 | try: |
---|
[54cc36a] | 645 | self.top_marker.remove() |
---|
[2a3a890] | 646 | self.bottom_line.remove() |
---|
| 647 | self.top_line.remove() |
---|
| 648 | except: |
---|
| 649 | # Old version of matplotlib |
---|
| 650 | for item in range(len(self.axes.lines)): |
---|
| 651 | del self.axes.lines[0] |
---|
| 652 | |
---|
| 653 | def get_radius(self): |
---|
| 654 | |
---|
| 655 | return 0 |
---|
| 656 | |
---|
| 657 | def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None): |
---|
[78ed1ad] | 658 | """ |
---|
[2a3a890] | 659 | Draw the new roughness on the graph. |
---|
[78ed1ad] | 660 | """ |
---|
[2a3a890] | 661 | if width!=None: |
---|
| 662 | self.half_width= width |
---|
| 663 | if height!=None: |
---|
| 664 | self.half_height= height |
---|
| 665 | if center!=None: |
---|
| 666 | self.center_x= center.x |
---|
| 667 | self.center_y= center.y |
---|
| 668 | |
---|
| 669 | self.x1 = self.half_width + self.center_x |
---|
| 670 | self.x2= -self.half_width + self.center_x |
---|
| 671 | |
---|
| 672 | self.y1 = self.half_height + self.center_y |
---|
| 673 | self.y2= -self.half_height + self.center_y |
---|
| 674 | |
---|
| 675 | self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) |
---|
| 676 | self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) |
---|
| 677 | self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) |
---|
| 678 | return |
---|
| 679 | if x1 !=None: |
---|
| 680 | self.x1= x1 |
---|
| 681 | if x2 !=None: |
---|
| 682 | self.x2= x2 |
---|
| 683 | if y1 !=None: |
---|
| 684 | self.y1= y1 |
---|
| 685 | if y2 !=None: |
---|
| 686 | self.y2= y2 |
---|
| 687 | |
---|
| 688 | |
---|
| 689 | self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) |
---|
| 690 | self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) |
---|
| 691 | self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) |
---|
| 692 | |
---|
| 693 | |
---|
| 694 | |
---|
| 695 | def save(self, ev): |
---|
| 696 | """ |
---|
| 697 | Remember the roughness for this layer and the next so that we |
---|
| 698 | can restore on Esc. |
---|
| 699 | """ |
---|
| 700 | self.save_x2= self.x2 |
---|
| 701 | self.save_y2= self.y2 |
---|
| 702 | |
---|
| 703 | self.save_x1= self.x1 |
---|
| 704 | self.save_y1= self.y1 |
---|
[78ed1ad] | 705 | |
---|
[2a3a890] | 706 | self.save_half_height= self.half_height |
---|
| 707 | self.save_half_width = self.half_width |
---|
| 708 | self.base.freeze_axes() |
---|
[78ed1ad] | 709 | |
---|
[2a3a890] | 710 | |
---|
| 711 | def moveend(self, ev): |
---|
| 712 | |
---|
| 713 | self.has_move=False |
---|
| 714 | self.base.moveend(ev) |
---|
| 715 | |
---|
| 716 | def restore(self): |
---|
| 717 | """ |
---|
| 718 | Restore the roughness for this layer. |
---|
| 719 | """ |
---|
| 720 | self.y2= self.save_y2 |
---|
| 721 | self.x2= self.save_x2 |
---|
| 722 | |
---|
| 723 | self.y1= self.save_y1 |
---|
| 724 | self.x1= self.save_x1 |
---|
| 725 | self.half_height= self.save_half_height |
---|
| 726 | self.half_width= self.save_half_width |
---|
| 727 | |
---|
| 728 | def move(self, x, y, ev): |
---|
| 729 | """ |
---|
| 730 | Process move to a new position, making sure that the move is allowed. |
---|
| 731 | """ |
---|
| 732 | self.y1= y |
---|
| 733 | delta= self.y1- self.center_y |
---|
| 734 | self.y2= self.center_y - delta |
---|
| 735 | self.half_height= math.fabs(self.y1)-self.center_y |
---|
| 736 | self.has_move=True |
---|
| 737 | self.base.base.update() |
---|
| 738 | |
---|
| 739 | def set_cursor(self, x, y): |
---|
| 740 | self.move(x, y, None) |
---|
| 741 | self.update() |
---|
| 742 | |
---|
| 743 | |
---|
| 744 | def get_params(self): |
---|
| 745 | params = {} |
---|
| 746 | params["x"] = self.x |
---|
| 747 | params["y"] = self.y |
---|
| 748 | |
---|
| 749 | return params |
---|
| 750 | |
---|
| 751 | def set_params(self, params): |
---|
| 752 | x = params["x"] |
---|
| 753 | y = params["y"] |
---|
| 754 | self.update(x=x, y=y, center_x=None,center_y=None) |
---|
[78ed1ad] | 755 | |
---|