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