Changeset 3554b99a in sasview


Ignore:
Timestamp:
Jan 8, 2009 5:16:58 PM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
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
Message:

working on boxslicer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/local_perspectives/plotting/boxSlicer.py

    r030873e r3554b99a  
    1717import wx 
    1818 
     19def 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 
    1930class BoxInteractor(_BaseInteractor): 
    2031    """ 
     
    3546        self.ymax=  y_max 
    3647         
    37         self.theta2= math.pi/4 
     48        self.theta2= math.pi/3 
    3849        ## Number of points on the plot 
    3950        self.nbins = 20 
     
    4455                                           theta= self.theta2) 
    4556        self.main_line.qmax = self.base.qmax 
    46          
    4757        self.left_line = VerticalLine(self, self.base.subplot,color='blue',  
    4858                                      zorder=zorder, 
     
    5464                                        theta2= self.theta2) 
    5565        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.qmax 
    66          
    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.qmax 
    75          
    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.qmax 
    8466        self.update() 
    8567        #self._post_data() 
     
    11698    def clear(self): 
    11799        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        
    122102        self.main_line.clear() 
    123103        #self.base.connect.disconnect() 
     
    139119                                  ymax=self.ymax, 
    140120                                  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           
    187122    def save(self, ev): 
    188123        """ 
     
    239174    def get_params(self): 
    240175        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        
    247177        params["phi"] = self.main_line.theta 
    248178        return params 
     
    250180    def set_params(self, params): 
    251181         
    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        
    256183        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 
    262185        self.main_line.update(theta) 
    263186         
     
    283206        self.markers = [] 
    284207        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], 
    301222                                      linestyle='-', marker='', 
    302223                                      color=self.color, 
    303224                                      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 
    307232        self.npts = 20 
    308233        self.has_move=False 
    309234        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() 
    314236 
    315237    def set_layer(self, n): 
     
    337259        if translation : 
    338260            print "translation ",self.top_hight 
    339             self.x1= self.xmax + self.top_hight*math.sin(math.pi/2 + self.mline.theta) 
    340             self.x2= self.xmin + self.top_hight*math.sin(math.pi/2 + self.mline.theta) 
    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) 
    343265            self.line.set(xdata=[self.x1,self.x2], 
    344266                       ydata=[self.y1,self.y2]) 
    345267            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]) 
    353278     
    354279         
     
    359284        can restore on Esc. 
    360285        """ 
    361         self.save_xmin= self.xmin 
    362         self.save_xmax= self.xmax 
    363         
    364         self.save_ymin= self.ymin 
    365         self.save_ymax= self.ymax 
    366         self.top_hight= self.ymax 
     286        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         
    367292        self.base.freeze_axes() 
    368293 
     
    376301        Restore the roughness for this layer. 
    377302        """ 
    378         self.xmin = self.save_xmin 
    379         self.xmax = self.save_xmax 
    380         self.ymin = self.save_ymin 
    381         self.ymax = self.save_ymax 
     303        self.x1 = self.save_x1 
     304        self.x2 = self.save_x2 
     305        self.y1 = self.save_y1 
     306        self.y2 = self.save_y2 
    382307 
    383308    def move(self, x, y, ev): 
     
    385310        Process move to a new position, making sure that the move is allowed. 
    386311        """ 
    387          
    388         self.top_hight= y 
     312        self.b = - self.slope.x 
    389313        self.has_move=True 
    390314        self.base.base.update() 
     
    397321    def get_params(self): 
    398322        params = {} 
    399         params["radius"] = self.xmin 
    400         params["theta"] = self.xmax 
     323        params["radius"] = self.x1 
     324        #params["theta"] = self.xmax 
    401325        return params 
    402326     
     
    421345        self.axes = axes 
    422346         
    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 
    444350        self.x1= mline.x1 + xmin*math.cos(math.pi/2 - self.theta2) 
    445351        self.x2= mline.x2 + xmin*math.cos(math.pi/2 - self.theta2) 
    446352        self.y1= mline.y1 - xmin*math.sin(math.pi/2 - self.theta2) 
    447353        self.y2= mline.y2 - xmin*math.sin(math.pi/2 - self.theta2) 
    448          
    449354        self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2], 
    450355                                      linestyle='-', marker='', 
     
    452357                                      visible=True)[0] 
    453358       
    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  
    456364        self.has_move=False 
    457365        self.connect_markers([self.line]) 
     
    480388        Draw the new roughness on the graph. 
    481389        """ 
    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], 
    488395                           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         
    518399    def save(self, ev): 
    519400        """ 
     
    538419        Restore the roughness for this layer. 
    539420        """ 
    540         self.xmin = self.save_xmin 
    541         self.xmax = self.save_xmax 
    542         self.ymin = self.save_ymin 
    543         self.ymax = self.save_ymax 
    544         self.L_width= self.save_L_width 
     421        self.x1 = self.save_x1 
     422        self.x2 = self.save_x2 
     423        self.y1 = self.save_y1 
     424        self.y2= self.save_y2 
     425       
    545426         
    546427    def move(self, x, y, ev): 
     
    549430        """ 
    550431        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 
    553438        self.base.base.update() 
    554439         
     
    596481        self.radius2 = ymin 
    597482        self.scale = 10.0 
    598              
     483            
    599484        # Inner circle 
    600485        self.x1= self.radius1*math.cos(self.theta) 
     
    653538            self.radius2 =radius2 
    654539        print "update main line", math.degrees(self.theta),self.radius1, self.radius2 
     540         
    655541        self.x1= self.radius1*math.cos(self.theta) 
    656542        self.y1= self.radius1*math.sin(self.theta) 
    657543        self.x2= -1*self.radius2*math.cos(self.theta) 
    658544        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) 
    660549        self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2])   
    661550      
Note: See TracChangeset for help on using the changeset viewer.