Changeset 2a3a890 in sasview


Ignore:
Timestamp:
Jan 16, 2009 5:19:39 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:
568e1a5
Parents:
633ba04
Message:

working box sum interface—→need to display values

File:
1 edited

Legend:

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

    r0f6d05f8 r2a3a890  
    2121         Select an annulus through a 2D plot 
    2222    """ 
    23     def __init__(self,base,axes,color='black', zorder=3, x_min=0.0025, x_max=0.0025, y_min=0.0025, y_max=0.0025): 
     23    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): 
    2424         
    2525        _BaseInteractor.__init__(self, base, axes, color=color) 
    2626        self.markers = [] 
    2727        self.axes = axes 
    28         self.qmax = self.base.qmax 
     28        self.qmax = self.base.data2D.xmax 
    2929        self.connect = self.base.connect 
    3030         
     
    3434        self.ymax=  y_max 
    3535        # center of the figure 
    36         self.center_x= 0.0 
    37         self.center_y= 0.0 
     36        self.center_x= 0.002 
     37        self.center_y= 0.003 
    3838        
    3939        ## Number of points on the plot 
     
    4141        self.count=0 
    4242        self.error=0 
    43          
    44         self.left_line = VerticalLine(self, self.base.subplot,color='blue', zorder=zorder,  
    45                                         ymin= self.ymin, ymax= self.ymax, 
    46                                         x= self.xmin, 
    47                                         center_x= self.center_x, 
    48                                         center_y= self.center_y) 
    49         self.left_line.qmax = self.base.qmax 
    50          
    51         self.right_line= VerticalLine(self, self.base.subplot,color='black', zorder=zorder, 
    52                                      ymin= self.ymin, ymax= self.ymax, 
    53                                      x=self.xmax, 
    54                                      center_x= self.center_x, 
    55                                      center_y= self.center_y) 
    56         self.right_line.qmax = self.base.qmax 
    57          
    58         self.top_line= HorizontalLine(self, self.base.subplot,color='green', zorder=zorder, 
     43        self.has_move= False 
     44     
     45        self.horizontal_lines= Horizontal_DoubleLine(self, self.base.subplot,color='blue', 
     46                                                      zorder=zorder, 
    5947                                    y= self.ymax, 
    60                                     xmin= self.xmin, xmax= self.xmax, 
     48                                    x= self.xmax, 
    6149                                    center_x= self.center_x, 
    6250                                    center_y= self.center_y) 
    63         self.top_line.qmax = self.base.qmax 
    64          
    65         self.bottom_line= HorizontalLine(self, self.base.subplot,color='red', zorder=zorder, 
    66                                     y =self.ymin, 
    67                                     xmin= self.xmin, xmax= self.xmax, 
     51        self.horizontal_lines.qmax = self.qmax 
     52         
     53        self.vertical_lines= Vertical_DoubleLine(self, self.base.subplot,color='black', 
     54                                                      zorder=zorder, 
     55                                    y= self.ymax, 
     56                                    x= self.xmax, 
    6857                                    center_x= self.center_x, 
    6958                                    center_y= self.center_y) 
    70         self.bottom_line.qmax = self.base.qmax 
    71         #self.outer_circle.set_cursor(self.base.qmax/1.8, 0) 
    72          
     59        self.vertical_lines.qmax = self.qmax 
     60        self.center= PointInteractor(self, self.base.subplot,color='grey', 
     61                                                      zorder=zorder, 
     62                                    center_x= self.center_x, 
     63                                    center_y= self.center_y) 
     64       
     65             
    7366        self.connect_markers([]) 
    7467                       
     
    107100    def clear(self): 
    108101        self.clear_markers() 
    109         self.left_line.clear() 
    110         self.right_line.clear() 
    111         self.top_line.clear() 
    112         self.bottom_line.clear() 
     102        self.horizontal_lines.clear() 
     103        self.vertical_lines.clear() 
     104        self.center.clear() 
    113105         
    114106        #self.base.connect.disconnect() 
     
    120112        resetting the widgets. 
    121113        """ 
    122         if self.left_line.has_move: 
    123             print "left has moved" 
    124             self.left_line.update(mline=[self.center_x, self.center_y],translation=True) 
    125              
    126             #self.right_line.update(mline= [self.center_x, self.center_y],translation=True) 
    127             self.top_line.update( xmin= self.left_line.x ,xmax= self.right_line.x, 
    128                                   mline= [self.center_x, self.center_y],translation=True) 
    129             self.bottom_line.update(xmin= self.left_line.x ,xmax= self.right_line.x, 
    130                                     mline= [self.center_x, self.center_y],translation=True) 
    131         if self.right_line.has_move: 
     114        if self.center.has_move: 
     115            print "center has move" 
     116            self.center.update() 
     117            self.horizontal_lines.update( center= self.center) 
     118            self.vertical_lines.update( center= self.center) 
     119             
     120        if self.horizontal_lines.has_move: 
     121            print "top has moved" 
     122            self.horizontal_lines.update() 
     123            self.vertical_lines.update(y1=self.horizontal_lines.y1, 
     124                                       y2=self.horizontal_lines.y2, 
     125                                       height= self.horizontal_lines.half_height ) 
     126        if self.vertical_lines.has_move: 
    132127            print "right has moved" 
    133             self.right_line.update(mline= [self.center_x, self.center_y],translation=True) 
    134             #self.left_line.update(mline=[self.center_x, self.center_y],translation=True) 
    135             #self.left_line.update(xmin= self.right_line.x ,xmax=-1*self.right_line.x) 
    136             self.top_line.update( xmin= self.left_line.x ,xmax= self.right_line.x, 
    137                                   mline= [self.center_x, self.center_y],translation=True) 
    138             self.bottom_line.update(xmin= self.left_line.x ,xmax= self.right_line.x, 
    139                                     mline= [self.center_x, self.center_y],translation=True) 
    140              
    141              
    142         if self.bottom_line.has_move: 
    143             print "bottom has moved" 
    144             self.bottom_line.update(mline= [self.center_x, self.center_y],translation=True) 
    145             #self.top_line.update(y= -1*self.top_line.y,translation=True) 
    146             self.left_line.update( ymin= self.bottom_line.y ,ymax= self.top_line.y, 
    147                                    mline= [self.center_x, self.center_y],translation=True) 
    148             self.right_line.update(ymin= self.bottom_line.y ,ymax= self.top_line.y, 
    149                                    mline= [self.center_x, self.center_y],translation=True) 
    150              
    151         if self.top_line.has_move: 
    152             print "top has moved" 
    153             self.top_line.update(mline= [self.center_x, self.center_y],translation=True) 
    154              
    155             #self.bottom_line.update(y= -1*self.top_line.y,mline= [self.center_x, self.center_y], 
    156             #                        translation=True ) 
    157             self.left_line.update(ymin= self.bottom_line.y ,ymax= self.top_line.y, 
    158                                   mline= [self.center_x, self.center_y],translation=True) 
    159             self.right_line.update(ymin= self.bottom_line.y ,ymax= self.top_line.y, 
    160                                    mline= [self.center_x, self.center_y],translation=True) 
    161              
    162      
     128            self.vertical_lines.update() 
     129            self.horizontal_lines.update(x1=self.vertical_lines.x1, 
     130                                         x2=self.vertical_lines.x2, 
     131                                         width=self.vertical_lines.half_width) 
     132             
     133 
    163134    def save(self, ev): 
    164135        """ 
     
    167138        """ 
    168139        self.base.freeze_axes() 
    169         self.inner_circle.save(ev) 
    170         self.outer_circle.save(ev) 
    171  
     140        self.horizontal_lines.save(ev) 
     141        self.vertical_lines.save(ev) 
     142        self.center.save(ev) 
     143         
    172144    def _post_data(self): 
    173145        # Compute data 
     146        print  
     147        """ 
    174148        data = self.base.data2D 
    175149        from DataLoader.manipulations import  Boxavg 
     
    182156        self.count, self.error = box(self.base.data2D) 
    183157        print "count, error",self.count, self.error 
    184          
     158        """ 
    185159                                        
    186160    def moveend(self, ev): 
     
    194168         
    195169        wx.PostEvent(self.base.parent, event) 
    196  
     170       
    197171        self._post_data() 
    198172             
     
    201175        Restore the roughness for this layer. 
    202176        """ 
    203         self.inner_circle.restore() 
    204         self.outer_circle.restore() 
    205  
     177        self.horizontal_lines.restore() 
     178        self.vertical_lines.restore() 
     179        self.center.restore() 
    206180    def move(self, x, y, ev): 
    207181        """ 
    208182        Process move to a new position, making sure that the move is allowed. 
    209183        """ 
    210         print "in move" 
    211         if self.xmin <= x and x <= self.xmax: 
    212             print "has move whole", x 
    213          
     184        pass 
     185     
    214186    def set_cursor(self, x, y): 
    215187        pass 
     
    217189    def get_params(self): 
    218190        params = {} 
    219         params["x_min"] = self.left_line.x  
    220         params["x_max"] = self.right_line.x  
    221         params["y_min"] = self.bottom_line.y 
    222         params["y_max"] = self.top_line.y 
     191        
     192        params["x"] = math.fabs(self.horizontal_lines.half_width) 
     193        params["y"] = math.fabs(self.vertical_lines.half_height)  
     194         
     195        params["center_x"] = self.center.x 
     196        params["center_y"] =self.center.y 
    223197        params["count"] = self.count 
    224198        params["errors"]= self.error 
     199         
    225200        return params 
    226201     
     
    238213    def set_params(self, params): 
    239214         
    240         x_min = -math.fabs(params["x_min"] ) 
    241         x_max = math.fabs(params["x_max"] ) 
    242         y_min = -math.fabs(params["y_min"]) 
    243         y_max = math.fabs(params["y_max"])  
    244          
    245         self.left_line.update(ymin= y_min ,ymax= y_max , x= x_min) 
    246         self.right_line.update(ymin= y_min ,ymax= y_max, x= x_max) 
    247         self.top_line.update( xmin= x_min ,xmax= x_max, y= y_max) 
    248         self.bottom_line.update(xmin= x_min ,xmax= x_max, y=y_min) 
    249         """ 
    250         self.left_line.update(mline= [center_x, center_y],ymin= y_min ,ymax= y_max) 
    251         self.right_line.update(mline= [center_x, center_y],ymin= y_min ,ymax= y_max) 
    252         self.top_line.update(mline= [center_x, center_y], xmin= x_min ,xmax= xmax) 
    253         self.bottom_line.update(mline= [center_x, center_y],xmin= xmin ,xmax= xmax) 
    254         """ 
     215        x_max = math.fabs(params["x"] ) 
     216        y_max = math.fabs(params["y"] ) 
     217         
     218        self.center_x=params["center_x"]  
     219        self.center_y=params["center_y"] 
     220         
     221        self.center.update(center_x=self.center_x,center_y=self.center_y) 
     222        
     223        self.horizontal_lines.update(center= self.center, 
     224                                     width=x_max, 
     225                                     height=y_max) 
     226         
     227         
     228        self.vertical_lines.update(center= self.center, 
     229                                    width=x_max, 
     230                                    height=y_max) 
    255231         
    256232        self._post_data() 
     233         
     234         
     235         
    257236    def freeze_axes(self): 
    258237        self.base.freeze_axes() 
     
    263242    def draw(self): 
    264243        self.base.draw() 
    265  
    266 class HorizontalLine(_BaseInteractor): 
     244class PointInteractor(_BaseInteractor): 
    267245    """ 
    268246         Select an annulus through a 2D plot 
    269247    """ 
    270     def __init__(self,base,axes,color='black', zorder=5, y=0.5, 
    271                  xmin=0.0,xmax=0.5, 
     248    def __init__(self,base,axes,color='black', zorder=5, 
     249                 center_x= 0.0, 
     250                 center_y= 0.0): 
     251         
     252        _BaseInteractor.__init__(self, base, axes, color=color) 
     253        self.markers = [] 
     254        self.axes = axes 
     255        # center 
     256        self.x = center_x 
     257        self.y = center_y 
     258         
     259        self.save_x = center_x 
     260        self.save_y = center_y 
     261          
     262         
     263        try: 
     264            self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', 
     265                                          marker='s', markersize=10, 
     266                                          color=self.color, alpha=0.6, 
     267                                          pickradius=5, label="pick",  
     268                                          zorder=zorder, # Prefer this to other lines 
     269                                          visible=True)[0] 
     270        except: 
     271            self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', 
     272                                          marker='s', markersize=10, 
     273                                          color=self.color, alpha=0.6, 
     274                                          label="pick",  
     275                                          visible=True)[0] 
     276            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
     277            message += "Get the SVN version that is at least as recent as June 1, 2007" 
     278             
     279            #raise "Version error", message 
     280             
     281        # line 
     282        self.center = self.axes.plot([self.x],[self.y], 
     283                                      linestyle='-', marker='', 
     284                                      color=self.color, 
     285                                      visible=True)[0] 
     286     
     287        self.npts = 30 
     288        self.has_move=False     
     289        self.connect_markers([self.center_marker]) 
     290        self.update() 
     291 
     292 
     293    def set_layer(self, n): 
     294        self.layernum = n 
     295        self.update() 
     296         
     297    def clear(self): 
     298        self.clear_markers() 
     299        try: 
     300            self.center.remove() 
     301        except: 
     302            # Old version of matplotlib 
     303            for item in range(len(self.axes.lines)): 
     304                del self.axes.lines[0] 
     305         
     306    def get_radius(self): 
     307         
     308        return 0 
     309    
     310    def update(self, center_x=None,center_y=None): 
     311        """ 
     312        Draw the new roughness on the graph. 
     313        """ 
     314        if center_x !=None: self.x= center_x 
     315        if center_y !=None: self.y= center_y 
     316    
     317        self.center_marker.set(xdata=[self.x], ydata=[self.y]) 
     318        self.center.set(xdata=[self.x], ydata=[self.y]) 
     319         
     320         
     321         
     322         
     323    def save(self, ev): 
     324        """ 
     325        Remember the roughness for this layer and the next so that we 
     326        can restore on Esc. 
     327        """ 
     328        self.save_x= self.x 
     329        self.save_y= self.y 
     330         
     331        self.base.freeze_axes() 
     332 
     333    def moveend(self, ev): 
     334         
     335        self.has_move=False 
     336        self.base.moveend(ev) 
     337             
     338    def restore(self): 
     339        """ 
     340        Restore the roughness for this layer. 
     341        """ 
     342        self.y= self.save_y 
     343        self.x= self.save_x 
     344         
     345    def move(self, x, y, ev): 
     346        """ 
     347        Process move to a new position, making sure that the move is allowed. 
     348        """ 
     349        self.x= x 
     350        self.y= y 
     351        
     352        self.has_move=True 
     353        self.base.base.update() 
     354         
     355    def set_cursor(self, x, y): 
     356        self.move(x, y, None) 
     357        self.update() 
     358         
     359         
     360    def get_params(self): 
     361        params = {} 
     362        params["x"] = self.x 
     363        params["y"] = self.y 
     364         
     365        return params 
     366     
     367    def set_params(self, params): 
     368        center_x = params["x"]  
     369        center_y = params["y"]  
     370        self.update(center_x=center_x,center_y=center_y) 
     371        
     372         
     373class Vertical_DoubleLine(_BaseInteractor): 
     374    """ 
     375         Select an annulus through a 2D plot 
     376    """ 
     377    def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, 
    272378                 center_x= 0.0, 
    273379                 center_y= 0.0): 
     
    280386        self.center_y = center_y 
    281387         
    282         self.y= y - self.center_y 
    283         self.save_y= y- self.center_y 
    284          
    285         self.xmin = xmin - self.center_x 
    286         self.save_xmin = xmin - self.center_x 
    287         self.xmax = xmax - self.center_x 
    288         self.save_xmax = xmax - self.center_x 
    289          
    290         
    291         self.line = self.axes.plot([self.xmin,self.xmax],[self.y,self.y], 
     388        
     389         
     390        self.y1     = y + self.center_y 
     391        self.save_y1= self.y1 
     392         
     393        delta= self.y1- self.center_y 
     394        self.y2= self.center_y - delta 
     395        self.save_y2= self.y2 
     396         
     397        self.x1      = x + self.center_x 
     398        self.save_x1 = self.x1 
     399          
     400        delta= self.x1- self.center_x 
     401        self.x2= self.center_x - delta 
     402        self.save_x2 = self.x2 
     403         
     404        self.color=color 
     405         
     406        self.half_height= math.fabs(y) 
     407        self.save_half_height= math.fabs(y) 
     408         
     409        self.half_width= math.fabs(x) 
     410        self.save_half_width=math.fabs(x) 
     411         
     412        try: 
     413            self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 
     414                                          marker='s', markersize=10, 
     415                                          color=self.color, alpha=0.6, 
     416                                          pickradius=5, label="pick",  
     417                                          zorder=zorder, # Prefer this to other lines 
     418                                          visible=True)[0] 
     419        except: 
     420            self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 
     421                                          marker='s', markersize=10, 
     422                                          color=self.color, alpha=0.6, 
     423                                          label="pick",  
     424                                          visible=True)[0] 
     425            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
     426            message += "Get the SVN version that is at least as recent as June 1, 2007" 
     427             
     428            #raise "Version error", message 
     429             
     430        # line 
     431        self.right_line = self.axes.plot([self.x1,self.x1],[self.y1,self.y2], 
    292432                                      linestyle='-', marker='', 
    293433                                      color=self.color, 
    294434                                      visible=True)[0] 
    295   
    296  
    297         self.npts = 20 
    298         self.has_move=False 
    299         self.connect_markers([self.line]) 
    300         self.update() 
     435        self.left_line = self.axes.plot([self.x2,self.x2],[self.y1,self.y2], 
     436                                      linestyle='-', marker='', 
     437                                      color=self.color, 
     438                                      visible=True)[0] 
     439     
     440        self.npts = 30 
     441        self.has_move=False     
     442        self.connect_markers([self.right_marker]) 
     443        self.update() 
     444 
    301445 
    302446    def set_layer(self, n): 
     
    307451        self.clear_markers() 
    308452        try: 
    309              
    310             self.line.remove() 
     453            self.right_line.remove() 
     454            self.left_line.remove() 
    311455        except: 
    312456            # Old version of matplotlib 
     
    318462        return 0 
    319463    
    320     def update(self,xmin=None, xmax=None,y=None, mline=None,translation=False): 
     464    def update(self,x1=None,x2=None, y1=None,y2=None,width=None, height=None, center=None): 
    321465        """ 
    322466        Draw the new roughness on the graph. 
    323467        """ 
    324         #print "update main line", self.has_move 
    325         if xmin !=None: 
    326             self.xmin = xmin # - self.center_x 
    327         if xmax !=None: 
    328             self.xmax = xmax #- self.center_x 
    329         if y !=None: 
    330             self.y = y #- self.center_y 
    331          
    332         self.line.set(xdata=[self.xmin,self.xmax], ydata=[self.y,self.y]) 
    333       
     468        if width!=None: 
     469            self.half_width= width 
     470        if height!=None: 
     471            self.half_height= height 
     472        if center!=None: 
     473            self.center_x= center.x 
     474            self.center_y= center.y 
     475             
     476            self.x1 = self.half_width + self.center_x 
     477            self.x2= -self.half_width + self.center_x 
     478             
     479            self.y1 = self.half_height + self.center_y 
     480            self.y2= -self.half_height + self.center_y 
     481          
     482            self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) 
     483            self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) 
     484            self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) 
     485            return  
     486        if x1 !=None:  
     487            self.x1= x1 
     488        if x2 !=None:  
     489            self.x2= x2 
     490        if y1 !=None:  
     491            self.y1= y1 
     492        if y2 !=None:  
     493            self.y2= y2 
     494         
     495        
     496        
     497        self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) 
     498        self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) 
     499        self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) 
    334500         
    335501         
     
    339505        can restore on Esc. 
    340506        """ 
    341         self.save_xmin= self.xmin 
    342         self.save_xmax= self.xmax 
    343         
    344         self.save_y= self.y 
     507        self.save_x2= self.x2 
     508        self.save_y2= self.y2 
     509         
     510        self.save_x1= self.x1 
     511        self.save_y1= self.y1 
     512         
     513        self.save_half_height= self.half_height 
     514        self.save_half_width =  self.half_width 
    345515        self.base.freeze_axes() 
    346516 
     
    354524        Restore the roughness for this layer. 
    355525        """ 
    356         self.y= self.save_y 
     526        self.y2= self.save_y2 
     527        self.x2= self.save_x2 
     528         
     529        self.y1= self.save_y1 
     530        self.x1= self.save_x1 
     531         
     532        self.half_height= self.save_half_height 
     533        self.half_width= self.save_half_width 
    357534        
    358535    def move(self, x, y, ev): 
     
    360537        Process move to a new position, making sure that the move is allowed. 
    361538        """ 
    362         self.y= y - self.center_y 
    363          
     539        self.x1= x 
     540        delta= self.x1- self.center_x 
     541        self.x2= self.center_x - delta 
     542         
     543        self.half_width= math.fabs(self.x1)-self.center_x 
    364544        self.has_move=True 
    365545        self.base.base.update() 
     
    372552    def get_params(self): 
    373553        params = {} 
    374         params["radius"] = self.xmin 
    375         params["theta"] = self.xmax 
     554        params["x"] = self.x1 
     555        params["y"] = self.y1 
    376556         
    377557        return params 
    378558     
    379559    def set_params(self, params): 
    380  
    381         x = params["radius"]  
    382         self.set_cursor(x, self._inner_mouse_y) 
    383          
    384  
    385  
    386  
    387 class VerticalLine(_BaseInteractor): 
     560        x = params["x"]  
     561        y = params["y"]  
     562        self.update(x=x, y=y, center_x=None,center_y=None) 
     563 
     564class Horizontal_DoubleLine(_BaseInteractor): 
    388565    """ 
    389566         Select an annulus through a 2D plot 
    390567    """ 
    391     def __init__(self,base,axes,color='black', zorder=5, ymin=0.0,  
    392                  ymax=0.5,x= 0.5, 
    393                    center_x= 0, 
    394                  center_y= 0): 
     568    def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, 
     569                 center_x= 0.0, 
     570                 center_y= 0.0): 
    395571         
    396572        _BaseInteractor.__init__(self, base, axes, color=color) 
    397573        self.markers = [] 
    398574        self.axes = axes 
    399         # x coordinate of the vertical line 
    400         self.center_x= center_x 
    401         self.center_y= center_y 
    402         self.x = x - center_x 
    403         self.save_x = x - center_x 
    404         # minimum value of y coordinate of the vertical line  
    405         self.ymin = ymin - center_y 
    406         self.save_ymin = ymin - center_y 
    407         # maximum value of y coordinate of the vertical line  
    408         self.ymax= ymax - center_y 
    409         self.save_ymax= ymax - center_y 
    410          
    411         # Draw vertical line 
    412         self.line = self.axes.plot([self.x,self.x],[self.ymin,self.ymax], 
     575        # center 
     576        self.center_x = center_x 
     577        self.center_y = center_y 
     578         
     579        self.y1     = y + self.center_y 
     580        self.save_y1= self.y1 
     581         
     582        delta= self.y1- self.center_y 
     583        self.y2=  self.center_y - delta 
     584        self.save_y2= self.y2 
     585         
     586        self.x1      = x + self.center_x 
     587        self.save_x1 = self.x1 
     588         
     589        delta= self.x1- self.center_x 
     590        self.x2=  self.center_x - delta 
     591        self.save_x2 = self.x2 
     592         
     593        self.color=color 
     594         
     595        self.half_height= math.fabs(y) 
     596        self.save_half_height= math.fabs(y) 
     597         
     598        self.half_width= math.fabs(x) 
     599        self.save_half_width=math.fabs(x) 
     600     
     601        try: 
     602            self.top_marker = self.axes.plot([0],[self.y1], linestyle='', 
     603                                          marker='s', markersize=10, 
     604                                          color=self.color, alpha=0.6, 
     605                                          pickradius=5, label="pick",  
     606                                          zorder=zorder, # Prefer this to other lines 
     607                                          visible=True)[0] 
     608        except: 
     609            self.top_marker = self.axes.plot([0],[self.y1], linestyle='', 
     610                                          marker='s', markersize=10, 
     611                                          color=self.color, alpha=0.6, 
     612                                          label="pick",  
     613                                          visible=True)[0] 
     614            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
     615            message += "Get the SVN version that is at least as recent as June 1, 2007" 
     616             
     617            #raise "Version error", message 
     618             
     619        # line 
     620        self.top_line = self.axes.plot([self.x1,-self.x1],[self.y1,self.y1], 
    413621                                      linestyle='-', marker='', 
    414622                                      color=self.color, 
    415623                                      visible=True)[0] 
    416        
    417         self.npts = 20 
    418         # Check vertical line motion 
    419         self.has_move=False 
    420         self.connect_markers([self.line]) 
    421         self.update() 
     624        self.bottom_line = self.axes.plot([self.x1,-self.x1],[self.y2,self.y2], 
     625                                      linestyle='-', marker='', 
     626                                      color=self.color, 
     627                                      visible=True)[0] 
     628     
     629        self.npts = 30 
     630        self.has_move=False     
     631        self.connect_markers([self.top_marker]) 
     632        self.update() 
     633 
    422634 
    423635    def set_layer(self, n): 
     
    428640        self.clear_markers() 
    429641        try: 
    430              
    431             self.line.remove() 
     642            self.bottom_line.remove() 
     643            self.top_line.remove() 
    432644        except: 
    433645            # Old version of matplotlib 
     
    436648         
    437649    def get_radius(self): 
     650         
    438651        return 0 
    439      
    440     def update(self,x=None,ymin=None, ymax=None, mline=None,translation=False): 
     652    
     653    def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None): 
    441654        """ 
    442655        Draw the new roughness on the graph. 
    443656        """ 
    444         if x!=None: 
    445             self.x = x #-self.center_x 
    446         if ymin !=None: 
    447             self.ymin = ymin #- self.center_y 
    448         if ymax !=None: 
    449             self.ymax = ymax #- self.center_y 
    450          
    451         self.line.set(xdata=[self.x,self.x], ydata=[self.ymin,self.ymax]) 
    452       
     657        if width!=None: 
     658            self.half_width= width 
     659        if height!=None: 
     660            self.half_height= height 
     661        if center!=None: 
     662            self.center_x= center.x 
     663            self.center_y= center.y 
     664             
     665            self.x1 = self.half_width + self.center_x 
     666            self.x2= -self.half_width + self.center_x 
     667             
     668            self.y1 = self.half_height + self.center_y 
     669            self.y2= -self.half_height + self.center_y 
     670             
     671            self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) 
     672            self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) 
     673            self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) 
     674            return  
     675        if x1 !=None:  
     676            self.x1= x1 
     677        if x2 !=None:  
     678            self.x2= x2 
     679        if y1 !=None:  
     680            self.y1= y1 
     681        if y2 !=None:  
     682            self.y2= y2 
     683        
     684              
     685        self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) 
     686        self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) 
     687        self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) 
     688        
    453689         
    454690         
     
    458694        can restore on Esc. 
    459695        """ 
    460         self.save_x= self.x 
    461         self.save_ymin= self.ymin 
    462         self.save_ymax= self.ymax 
    463          
     696        self.save_x2= self.x2 
     697        self.save_y2= self.y2 
     698         
     699        self.save_x1= self.x1 
     700        self.save_y1= self.y1 
     701         
     702        self.save_half_height= self.half_height 
     703        self.save_half_width =  self.half_width 
    464704        self.base.freeze_axes() 
     705 
    465706 
    466707    def moveend(self, ev): 
     
    473714        Restore the roughness for this layer. 
    474715        """ 
    475         self.x = self.save_x 
    476          
    477         self.ymin=self.save_ymin 
    478         self.ymax=self.save_ymax 
     716        self.y2= self.save_y2 
     717        self.x2= self.save_x2 
     718         
     719        self.y1= self.save_y1 
     720        self.x1= self.save_x1 
     721        self.half_height= self.save_half_height 
     722        self.half_width= self.save_half_width 
     723         
    479724    def move(self, x, y, ev): 
    480725        """ 
    481726        Process move to a new position, making sure that the move is allowed. 
    482727        """ 
    483         self.x = x - self.center_x 
    484         
     728        self.y1= y 
     729        delta= self.y1- self.center_y 
     730        self.y2=  self.center_y - delta 
     731        self.half_height=  math.fabs(self.y1)-self.center_y 
    485732        self.has_move=True 
    486733        self.base.base.update() 
    487734         
    488          
    489735    def set_cursor(self, x, y): 
    490736        self.move(x, y, None) 
     
    494740    def get_params(self): 
    495741        params = {} 
    496         params["x"] = self.xmin 
    497         params["ymin"] = self.ymin 
    498         params["ymax"] = self.ymax 
     742        params["x"] = self.x 
     743        params["y"] = self.y 
     744         
    499745        return params 
    500746     
    501747    def set_params(self, params): 
    502         """ 
    503             Draw a vertical line given some value of params 
    504             @param params: a dictionary containing value for x, ymin , ymax to draw  
    505             a vertical line 
    506         """ 
    507748        x = params["x"]  
    508         ymin = params["ymin"]  
    509         ymax = params["ymax"]  
    510         #self.set_cursor(x, self._inner_mouse_y) 
    511         self.update(self,x =x,ymin =ymin, ymax =ymax) 
    512          
    513  
     749        y = params["y"]  
     750        self.update(x=x, y=y, center_x=None,center_y=None) 
    514751          
Note: See TracChangeset for help on using the changeset viewer.