Package reflectometry :: Package model1d :: Package profileview :: Module roughnessInteractor

Source Code for Module reflectometry.model1d.profileview.roughnessInteractor

  1  """ 
  2  roughness  interactor. 
  3  """ 
  4   
  5  from reflutils      import roughness_color, roughness_pickradius 
  6  from baseInteractor import BaseInteractor 
  7   
  8  # --------------- Roughness  interactors --------------- 
  9  # GUI starts here 
 10  # ------------------------------------------------------ 
 11   
12 -class RoughnessInteractor(BaseInteractor):
13 """ 14 Control the roughness of the layers. 15 """
16 - def __init__(self, 17 base, 18 axes, 19 color=roughness_color 20 ):
21 BaseInteractor.__init__(self, base, axes, color=color) 22 23 self.layernum = 0 24 self.axes = axes 25 26 # markers for roughness 27 self.mrough=[self.axes.plot([0],[0.05], 28 linestyle = '', 29 transform = self.xcoords, 30 marker = 's', #square 31 markersize = 7, 32 color = self.color, 33 alpha = 0.6, 34 pickradius = roughness_pickradius, 35 label = label, 36 zorder = 8, #Prefer this to other lines 37 visible = False)[0] 38 for label in ('left rough','right rough') 39 ] 40 41 # lines for roughness 42 self.lrough=[self.axes.plot([0,0],[0.05,0.05], 43 transform = self.xcoords, 44 linestyle = '-', 45 marker = '', 46 color = self.color, 47 visible = False)[0] 48 for label in ('left lrough','right lrough') 49 ] 50 51 self.markers = self.mrough 52 self.connect_markers(self.markers)
53 54
55 - def set_layer(self, n):
56 """ 57 Set the layer number 58 """ 59 self.layernum = n 60 self.update()
61 62
63 - def update(self):
64 """ 65 Draw the new roughness on the graph. 66 """ 67 model = self.base.model 68 n = self.layernum 69 70 showLeft = (n>0 and n<=model.numlayers+1) 71 self.mrough[0].set( visible = showLeft ) 72 self.lrough[0].set( visible = showLeft ) 73 if n > 0: 74 self.mrough[0].set(xdata=[model.offset[n]+model.rough[n-1]]) 75 self.lrough[0].set(xdata=[model.offset[n], 76 model.offset[n]+model.rough[n-1]]) 77 78 showRight = (n<=model.numlayers and n>=0) 79 self.mrough[1].set( visible = showRight ) 80 self.lrough[1].set( visible = showRight ) 81 if n <= model.numlayers: 82 self.mrough[1].set(xdata=[model.offset[n+1]-model.rough[n]]) 83 self.lrough[1].set(xdata=[model.offset[n+1], 84 model.offset[n+1]-model.rough[n]])
85 86
87 - def clear(self):
88 """ 89 clear roughness( line and marker) on the graph. 90 """ 91 for line in self.lrough: 92 line.remove() 93 self.clear_markers()
94 95
96 - def save(self, event):
97 """ 98 Remember the roughness for this layer and the next so that we 99 can restore on Esc. 100 """ 101 model = self.base.model 102 self._save_n = self.mrough.index(event.artist) 103 104 self._save_v = model.rough[self.layernum + self._save_n-1] 105 106 # Freeze the x axes 107 self.base.freeze_axes()
108 109
110 - def moveend(self, event):
111 self.base.thaw_axes()
112 113
114 - def restore(self):
115 """ 116 Restore the roughness for this layer. 117 """ 118 try: 119 model = self.base.model 120 model.rough[self.layernum + self._save_n] = self._save_v 121 except: 122 pass
123 124
125 - def GetMaxRough(self, n):
126 """ 127 Get the max rough for layer n 128 """ 129 model = self.base.model 130 if n == 0 : 131 # You can change this number to show the depth in incident layer 132 # is infinite 133 return 1000.0 134 else: 135 return model.depth[n]/model.max_rough
136 137
138 - def move(self, x, y, event):
139 """ 140 Process move to a new position, making sure that the move is allowed. 141 """ 142 model = self.base.model 143 n = self.layernum 144 145 self._save_n = self.mrough.index(event.artist) 146 147 148 if self._save_n == 0: # Left 149 150 v = x - model.offset[n] 151 if v < 0: 152 v = 0 153 154 if n >= 1 and v > self.GetMaxRough(n-1): 155 v = self.GetMaxRough(n-1) 156 157 if n <= model.numlayers and v > self.GetMaxRough(n): 158 v = self.GetMaxRough(n) 159 160 model.rough[n-1] = v 161 162 else: # Right 163 164 v = model.offset[n+1] - x 165 if v < 0: 166 v = 0 167 168 if n > 0 and v > self.GetMaxRough(n): 169 v = self.GetMaxRough(n) 170 171 if n < model.numlayers and v > self.GetMaxRough(n+1): 172 v = self.GetMaxRough(n+1) 173 174 model.rough[n] = v
175 176
177 - def getRough(self, n):
178 """ 179 Get the rough for layer n 180 """ 181 try: 182 val = self.base.model.rough[n] 183 except: 184 val = None 185 return val
186 187
188 - def setValue(self, event):
189 """ 190 Set the rough 191 192 First call move(), so we can directly use the updated data(rough). 193 """ 194 n = self.layernum 195 idx = self.mrough.index(event.artist) 196 197 if idx==1: 198 val = self.getRough(n) 199 else: 200 val = self.getRough(n-1) 201 202 if val == None: 203 return 204 205 self.infopanel.updateNLayer( n ) 206 207 if idx==1: self.infopanel.updateRRoughValue( val ) 208 else: self.infopanel.updateLRoughValue( val )
209 210
211 - def showValue(self, event):
212 """ 213 Show the rough 214 """ 215 n = self.model.find( event.xdata ) 216 idx = self.mrough.index(event.artist) 217 218 if idx ==1: self._save_rough_n = n 219 else: self._save_rough_n = n-1 220 221 self.infopanel.updateNLayer( n ) 222 223 if idx == 1: self.infopanel.showRRoughValue( ) 224 else: self.infopanel.showLRoughValue( )
225