1 """
2 Reflectometry interface interactor.
3 """
4
5 from reflutils import interface_color, interface_pickradius
6 from baseInteractor import BaseInteractor
7
8
9
10
11
13 """
14 Control the size of the layers.
15 """
26
27
52
53
54
56 """
57 Refreah all markers.
58
59 Also we clear up all the connects with the markers
60 """
61 if self.markers:
62 self.base.connect.clear(*self.markers)
63
64 self.reset_layers()
65
66
68 """
69 Look up the layer number from event.
70 """
71 try: n = self.markers.index(event.artist)
72 except: n = None
73 return n
74
75
76 - def _set_text(self, show=True, update=False):
77 """
78 Place the layer names on the graph mid way between the interfaces.
79 The incident layer name is placed just before the first interface,
80 and the substrate name is placed just after the last interface.
81 """
82 ax = self.axes
83 model = self.base.model
84
85
86 if show:
87 self.textmark = [ ax.text(model.offset[i]+model.depth[i]/2.0,
88 1.0,
89 str(s),
90
91 ha='left',
92 va='bottom',
93 rotation=30,
94 fontsize=10
95 ) for i,s in enumerate(model.names)
96 ]
97
98 pos = ax.get_xlim()
99 ax.set_xlim( (pos[0], pos[1]+200) )
100 else:
101 for i in xrange( len(self.textmark) ):
102 self.textmark[i].remove()
103
104 self.textmark=None
105
106 if update:
107 self.update()
108
109
111 """
112 Remove interfaces and layer names from the graph.
113 """
114 for h in self.markers:
115 h.remove()
116
117 for h in self.textmark:
118 h.remove()
119
120 self.textmark=[]
121
122
124 """
125 Remove interfaces and layer names from the graph.
126 """
127 self.clear_markers()
128 for i in xrange( len(self.textmark) ):
129 self.textmark[i].remove()
130
131
155
156
157 - def save(self, ev):
158 """
159 Remember the depths for this layer and the next so that we
160 can drag interfaces and restore on Esc.
161 """
162 self.base.freeze_axes()
163
164
166 """
167 Restore the depths for this layer and the next.
168 """
169 try:
170 model = self.base.model
171 model.depth[self._save_n] = self._save_d
172 if self._save_n < model.numlayers:
173 model.depth[self._save_n+1] = self._save_dnext
174 except:
175 pass
176
177
178 - def move(self, x, y, event):
179 """
180 Process move to a new position, making sure that the move is allowed.
181 """
182 layer_n = self._lookupLayerNumber(event)
183 if layer_n == None:
184 return
185
186 model = self.base.model
187 lo = model.offset[layer_n]
188
189
190 min_depth = 1
191 max_depth = 10000
192 d = abs(x-lo)
193 if d < min_depth:
194 model.depth[ layer_n ] = min_depth
195 return True
196
197 if d >= max_depth:
198 model.depth[ layer_n ] = max_depth
199 return True
200
201
202 model.depth[ layer_n ] = d
203
204
207
208
210 """
211 Show the depth Value
212 """
213 n = self._lookupLayerNumber(event)
214 if n == None:
215 return
216
217
218 self._save_depth_n = n
219
220 self.infopanel.updateNLayer( n )
221 self.infopanel.showDepthValue( )
222
223
225 """
226 Set the depth Value
227
228 First call move(), so we can directly use the updated data(depth).
229 """
230 n = self._lookupLayerNumber(event)
231 if n == None:
232 return
233
234 self.infopanel.updateNLayer( n )
235 self.infopanel.updateDepthValue( self.base.model.depth[n] )
236