Changeset 3554b99a in sasview
- Timestamp:
- Jan 8, 2009 5:16:58 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- dd40217
- Parents:
- 116da060
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/boxSlicer.py
r030873e r3554b99a 17 17 import wx 18 18 19 def find_intersection(a1= 2, a2= -0.5,b1= 1,b2= 1 ): 20 """ @ return x, y coordinates of an intersection between 2 lines 21 @param a1: the slope of the first line 22 @param a2 : the slope of the 2nd line 23 @param b1 : line intercept of the 1 st line 24 @param b2 : line intercept of the 2 nd ligne 25 @note 1st line equation is y= a1*x +b1 ; 2nd line equation is y= a2*x +b2 26 """ 27 x= ( b2- b1) /(a1- a1) 28 y= ( -a2*b1 + a1*b2 )/(a1 -a2) 29 return x, y 19 30 class BoxInteractor(_BaseInteractor): 20 31 """ … … 35 46 self.ymax= y_max 36 47 37 self.theta2= math.pi/ 448 self.theta2= math.pi/3 38 49 ## Number of points on the plot 39 50 self.nbins = 20 … … 44 55 theta= self.theta2) 45 56 self.main_line.qmax = self.base.qmax 46 47 57 self.left_line = VerticalLine(self, self.base.subplot,color='blue', 48 58 zorder=zorder, … … 54 64 theta2= self.theta2) 55 65 self.left_line.qmax = self.base.qmax 56 57 self.right_line= VerticalLine(self, self.base.subplot,color='black',58 zorder=zorder,59 mline= self.main_line,60 ymin= self.ymin ,61 ymax= self.ymax,62 xmin= self.xmax,63 xmax= self.xmax,64 theta2= self.theta2)65 self.right_line.qmax = self.base.qmax66 67 self.top_line= HorizontalLine(self, self.base.subplot,color='green',68 zorder=zorder,69 mline= self.main_line,70 xmin=self.right_line.x1,71 xmax=self.left_line.x1,72 ymin=self.right_line.y1,73 ymax=self.left_line.y1)74 self.top_line.qmax= self.base.qmax75 76 self.bottom_line= HorizontalLine(self, self.base.subplot,color='grey',77 zorder=zorder,78 mline= self.main_line,79 xmin=self.right_line.x2,80 xmax=self.left_line.x2,81 ymin=self.right_line.y2,82 ymax=self.left_line.y2)83 self.bottom_line.qmax= self.base.qmax84 66 self.update() 85 67 #self._post_data() … … 116 98 def clear(self): 117 99 self.clear_markers() 118 self.left_line.clear() 119 self.right_line.clear() 120 self.top_line.clear() 121 self.bottom_line.clear() 100 101 122 102 self.main_line.clear() 123 103 #self.base.connect.disconnect() … … 139 119 ymax=self.ymax, 140 120 translation=True) 141 self.right_line.update( 142 xmin= self.xmax, 143 xmax= self.xmax, 144 ymin= self.ymin, 145 ymax=self.ymax, 146 translation=True) 147 self.top_line.update(xmin= self.right_line.x1, 148 xmax= self.left_line.x1, 149 ymin= self.right_line.y1, 150 ymax= self.left_line.y1) 151 self.bottom_line.update(xmin= self.right_line.x2, 152 xmax= self.left_line.x2, 153 ymin= self.right_line.y2, 154 ymax= self.left_line.y2) 155 if self.left_line.has_move: 156 print "left has moved" 157 self.left_line.update() 158 self.right_line.update(opline= self.left_line ) 159 160 self.top_line.update(xmin= self.right_line.x2, 161 xmax= self.left_line.x1, 162 ymin= self.right_line.y2, 163 ymax= self.left_line.y1) 164 165 166 self.bottom_line.update(xmin= self.right_line.x1, 167 xmax= self.left_line.x2, 168 ymin= self.right_line.y1, 169 ymax= self.left_line.y2) 170 171 if self.right_line.has_move: 172 print "right has moved" 173 self.right_line.update() 174 self.left_line.update(opline= self.right_line ) 175 176 self.top_line.update(xmin= self.right_line.x1, 177 xmax= self.left_line.x2, 178 ymin= self.right_line.y1, 179 ymax= self.left_line.y2) 180 181 self.bottom_line.update(xmin= self.right_line.x2, 182 xmax= self.left_line.x1, 183 ymin= self.right_line.y2, 184 ymax= self.left_line.y1) 185 if self.top_line.has_move: 186 self.top_line.update(translation=True) 121 187 122 def save(self, ev): 188 123 """ … … 239 174 def get_params(self): 240 175 params = {} 241 params["x_min"] = self.left_line.L_width 242 params["x_max"] = self.right_line.R_width 243 #params["y_min"] = self.bottom_line.y 244 #params["y_max"] = self.top_line.y 245 params["count"] = self.count 246 params["error"] = self.error 176 247 177 params["phi"] = self.main_line.theta 248 178 return params … … 250 180 def set_params(self, params): 251 181 252 x_min = params["x_min"] 253 x_max = params["x_max"] 254 #y_min = params["y_min"] 255 #y_max = params["y_max"] 182 256 183 theta = params["theta"] 257 258 self.left_line.update(ymin= y_min ,ymax= y_max) 259 self.right_line.update(ymin= y_min ,ymax= y_max) 260 #self.top_line.update( xmin= x_min ,xmax= xmax) 261 #self.bottom_line.update(xmin= xmin ,xmax= xmax) 184 print "theta setparams",theta 262 185 self.main_line.update(theta) 263 186 … … 283 206 self.markers = [] 284 207 self.axes = axes 285 286 self.ymin= ymin 287 self.save_ymin = ymin 288 self.mline = mline 289 self.ymax= ymax 290 self.save_ymax = ymax 291 self.xmin = xmin 292 self.save_xmin = xmin 293 self.xmax = xmax 294 self.save_xmax = xmax 295 self.top_hight= self.ymax 296 297 self.theta2 = theta2 298 299 self.line = self.axes.plot([self.xmax,self.xmin], 300 [self.ymax,self.ymin], 208 self.x1= self.xmax 209 self.save_x1= self.xmax 210 211 self.x2= self.xmin 212 self.save_x2= self.xmin 213 214 self.y1= self.ymax 215 self.save_y1= self.ymax 216 217 self.y2= self.ymin 218 self.save_y2= self.ymin 219 self.mline= mline 220 self.line = self.axes.plot([self.x1,self.x2], 221 [self.y1,self.y2], 301 222 linestyle='-', marker='', 302 223 color=self.color, 303 224 visible=True)[0] 304 305 306 225 226 self.slope= -1*math.tan(self.mline.theta) 227 self.b= self.y1- self.slope* self.x1 228 229 print "slope from point",(self.y2- self.y1)/(self.x2- self.x1) 230 print "my slope horizontal", self.slope 231 print "b from point ", self.y2- self.slope*self.x1, self.b 307 232 self.npts = 20 308 233 self.has_move=False 309 234 self.connect_markers([self.line]) 310 self.update(xmin= self.xmin, 311 xmax= self.xmax, 312 ymin= self.ymin, 313 ymax= self.ymax) 235 self.update() 314 236 315 237 def set_layer(self, n): … … 337 259 if translation : 338 260 print "translation ",self.top_hight 339 self.x1= self.xmax + 340 self.x2= self.xmin + 341 self.y1= self.ymin - self.top_hight*math. cos(math.pi/2 + self.mline.theta)342 self.y2= self.ymax -self.top_hight*math. cos(math.pi/2 + self.mline.theta)261 self.x1= self.xmax +_self.top_hight*math.sin(math.pi/2 + self.mline.theta) 262 self.x2= self.xmin +self.top_hight*math.sin(math.pi/2 + self.mline.theta) 263 self.y1= self.ymin - self.top_hight*math.sin(math.pi/2 + self.mline.theta) 264 self.y2= self.ymax -self.top_hight*math.sin(math.pi/2 + self.mline.theta) 343 265 self.line.set(xdata=[self.x1,self.x2], 344 266 ydata=[self.y1,self.y2]) 345 267 return 346 #print "update main line", self.has_move 347 self.xmin=xmin 348 self.xmax=xmax 349 self.ymin=ymin 350 self.ymax=ymax 351 self.line.set(xdata=[self.xmin,self.xmax], 352 ydata=[self.ymin,self.ymax]) 268 if xmin !=None: 269 self.x2 = xmin 270 if xmax !=None: 271 self.x1 = xmax 272 if ymin !=None: 273 self.y2 = ymin 274 if ymax != None: 275 self.y1 = ymax 276 self.line.set(xdata=[self.x1,self.x2], 277 ydata=[self.y1,self.y2]) 353 278 354 279 … … 359 284 can restore on Esc. 360 285 """ 361 self.save_x min= self.xmin362 self.save_x max= self.xmax363 364 self.save_y min= self.ymin365 self.save_y max= self.ymax366 self.top_hight= self.ymax286 self.save_x1= self.x1 287 self.save_x2= self.x2 288 289 self.save_y1= self.y1 290 self.save_y2= self.y2 291 367 292 self.base.freeze_axes() 368 293 … … 376 301 Restore the roughness for this layer. 377 302 """ 378 self.x min = self.save_xmin379 self.x max = self.save_xmax380 self.y min = self.save_ymin381 self.y max = self.save_ymax303 self.x1 = self.save_x1 304 self.x2 = self.save_x2 305 self.y1 = self.save_y1 306 self.y2 = self.save_y2 382 307 383 308 def move(self, x, y, ev): … … 385 310 Process move to a new position, making sure that the move is allowed. 386 311 """ 387 388 self.top_hight= y 312 self.b = - self.slope.x 389 313 self.has_move=True 390 314 self.base.base.update() … … 397 321 def get_params(self): 398 322 params = {} 399 params["radius"] = self.x min400 params["theta"] = self.xmax323 params["radius"] = self.x1 324 #params["theta"] = self.xmax 401 325 return params 402 326 … … 421 345 self.axes = axes 422 346 423 self.L_width=xmin 424 self.save_L_width=xmin 425 426 self.save_xmin= xmin 427 self.R_width=xmax 428 self.save_xmax=xmax 429 self.ymin=ymin 430 self.save_ymin= ymin 431 self.ymax=ymax 432 self.save_ymax= ymax 433 434 self.theta2= theta2 435 436 self.mline= mline 437 438 self.detax=0 439 self.deltay=0 440 441 442 self.clickxf=0 443 self.clickyf=0 347 self.theta2 = mline.theta 348 self.mline =mline 349 self.xmin= xmin 444 350 self.x1= mline.x1 + xmin*math.cos(math.pi/2 - self.theta2) 445 351 self.x2= mline.x2 + xmin*math.cos(math.pi/2 - self.theta2) 446 352 self.y1= mline.y1 - xmin*math.sin(math.pi/2 - self.theta2) 447 353 self.y2= mline.y2 - xmin*math.sin(math.pi/2 - self.theta2) 448 449 354 self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2], 450 355 linestyle='-', marker='', … … 452 357 visible=True)[0] 453 358 454 self.npts = 20 455 # Check vertical line motion 359 360 self.slope= math.tan(self.mline.theta) 361 print "vertical line intercetp ",self.y2- self.slope*self.x2, self.y1- self.slope* self.x1 362 363 self.b = self.y1- self.slope* self.x1 456 364 self.has_move=False 457 365 self.connect_markers([self.line]) … … 480 388 Draw the new roughness on the graph. 481 389 """ 482 if opline !=None: 483 self.x1= -1*opline.x1 484 self.x2= -1*opline.x2 485 self.y1= -1*opline.y1 486 self.y2= -1*opline.y2 487 self.line.set(xdata=[self.x1,self.x2], 390 self.x1= self.mline.x1 + self.xmin*math.cos(math.pi/2 - self.mline.theta) 391 self.x2= self.mline.x2 + self.xmin*math.cos(math.pi/2 - self.mline.theta) 392 self.y1= self.mline.y1 - self.xmin*math.sin(math.pi/2 - self.mline.theta) 393 self.y2= self.mline.y2 - self.xmin*math.sin(math.pi/2 - self.mline.theta) 394 self.line.set(xdata=[self.x1,self.x2], 488 395 ydata=[self.y1,self.y2]) 489 return 490 if xmin== None: 491 xmin= self.L_width 492 if xmax== None: 493 xmax= self.R_width 494 #print "vertical line: xmin, xmax , ymin , ymax", xmin, self.mline.theta 495 self.x1= self.mline.x1 + xmin*math.cos(math.pi/2 - self.mline.theta) 496 self.x2= self.mline.x2 + xmin*math.cos(math.pi/2 - self.mline.theta) 497 self.y1= self.mline.y1 - xmin*math.sin(math.pi/2 - self.mline.theta) 498 self.y2= self.mline.y2 - xmin*math.sin(math.pi/2 - self.mline.theta) 499 #print "vertical line: main line value ", self.mline.x1, self.mline.x2, self.mline.y1,self.mline.y2 500 #print "vertical line: new value ", self.x1, self.x2, self.y1,self.y2 501 502 self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) 503 if opline !=None: 504 self.line.set(xdata=[-1*self.opline.x1,-1*self.opline.x2], 505 ydata=[self.opline.y1,self.opline.y2]) 506 return 507 if translation: 508 print "xmin L_width", xmin, self.L_width 509 self.x1= self.mline.x1 + self.L_width*math.cos(math.pi/2 - self.mline.theta) 510 self.x2= self.mline.x2 + self.L_width*math.cos(math.pi/2 - self.mline.theta) 511 self.y1= self.mline.y1 - self.L_width*math.sin(math.pi/2 - self.mline.theta) 512 self.y2= self.mline.y2 - self.L_width*math.sin(math.pi/2 - self.mline.theta) 513 514 print"translation x1, x2,y1,y2",self.x1, self.x2,self.y1,self.y2 515 self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) 516 517 396 #print "update slope ", (self.y2-self.y1)/(self.x2- self.x1) 397 #print "main slope", math.tan(self.mline.theta) 398 518 399 def save(self, ev): 519 400 """ … … 538 419 Restore the roughness for this layer. 539 420 """ 540 self.x min = self.save_xmin541 self.x max = self.save_xmax542 self.y min = self.save_ymin543 self.y max = self.save_ymax544 self.L_width= self.save_L_width421 self.x1 = self.save_x1 422 self.x2 = self.save_x2 423 self.y1 = self.save_y1 424 self.y2= self.save_y2 425 545 426 546 427 def move(self, x, y, ev): … … 549 430 """ 550 431 self.has_move=True 551 self.L_width = x 552 print "move L_width", self.L_width 432 433 # compute the b intercept of the vertical line 434 self.b= math.fabs( y - self.mline.theta * x) 435 436 437 print "move L_width", self.L_width, self.L_hight 553 438 self.base.base.update() 554 439 … … 596 481 self.radius2 = ymin 597 482 self.scale = 10.0 598 483 599 484 # Inner circle 600 485 self.x1= self.radius1*math.cos(self.theta) … … 653 538 self.radius2 =radius2 654 539 print "update main line", math.degrees(self.theta),self.radius1, self.radius2 540 655 541 self.x1= self.radius1*math.cos(self.theta) 656 542 self.y1= self.radius1*math.sin(self.theta) 657 543 self.x2= -1*self.radius2*math.cos(self.theta) 658 544 self.y2= -1*self.radius2*math.sin(self.theta) 659 545 print "init mainline sintercept ", self.y1 - math.tan(self.theta)*self.x1,\ 546 self.y2 - math.tan(self.theta)*self.x2 547 print "main line slope ", (self.y2- self.y1)/(self.x2- self.x1) 548 print "theta", math.tan(self.theta) 660 549 self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) 661 550
Note: See TracChangeset
for help on using the changeset viewer.