1
2
3
4 dmn
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 ( define verbose #t )
29
30
31
32
33
34 ( use-modules ( srfi srfi-1 ) )
35 ( use-modules ( lepton page ) )
36 ( use-modules ( lepton object ) )
37 ( use-modules ( lepton attrib ) )
38 ( use-modules ( lepton log ) )
39 ( use-modules ( lepton config ) )
40 ( use-modules ( schematic window ) )
41 ( use-modules ( schematic selection ) )
42 ( use-modules ( schematic gui keymap ) )
43
44
45
46
47
48 ( define ( locked-comps )
49
50 ( define ( locked-comp? obj )
51 ( and
52 ( component? obj )
53 ( not (object-selectable? obj) )
54 )
55 )
56
57
58
59 ( filter locked-comp? (page-contents (active-page)) )
60
61 )
62
63
64
65
66
67 ( define ( deselect-all )
68 ( for-each deselect-object! (page-contents (active-page)) )
69 )
70
71
72
73
74
75 ( define ( select-comp comp )
76 ( select-object! comp )
77 ( for-each select-object! (object-attribs comp) )
78 )
79
80
81
82
83
84
85 ( define ( select-locked-all )
86 ( let
87 (
88 ( comps ( locked-comps ) )
89 )
90
91 ( unless ( null? comps )
92 ( deselect-all )
93 ( for-each select-comp comps )
94 )
95
96 ( if ( null? comps )
97 ( log!
98 'message
99 "select-locked: no locked components found"
100 )
101 ( log!
102 'message
103 "select-locked: ~a locked component(s) selected~a"
104 ( length comps )
105 ( if verbose ". press <E Shift+L> to unlock" "" )
106 )
107 )
108
109
110 )
111 )
112
113
114
115
116
117
118 ( define ( select-locked-next )
119 ( let*
120 (
121 ( comps ( locked-comps ) )
122 ( len ( length comps ) )
123 ( sel ( page-selection (active-page) ) )
124 ( ndx )
125 ( comp #f )
126 )
127
128
129
130 ( define ( print-msg i c )
131 ( log! 'message
132 "select-locked: ~a of ~a (~a)~a"
133 ( i )
134 len
135 ( component-basename c )
136 ( if verbose
137 ". press <E E> to edit, <E Shift+L> to unlock"
138 ""
139 )
140 )
141 )
142
143
144 ( define ( next-ndx i )
145
146 ( if ( = i ( len) )
147
148 ( i )
149 )
150 )
151
152 ( define ( locked-obj? obj )
153
154 ( not (object-selectable? obj) )
155 )
156
157
158 ( define ( go? c )
159
160 ( or
161 ( null? sel )
162 ( not (find locked-obj? sel) )
163 ( object-selected? c )
164 )
165 )
166
167
168
169 ( when ( null? comps )
170 ( log! 'message "select-locked: no locked components found" )
171 )
172
173 ( while ( < ndx len )
174 ( set! comp ( list-ref comps ndx ) )
175
176 ( when ( go? comp )
177 ( deselect-all )
178 ( set! comp (list-ref comps (next-ndx ndx) ) )
179 ( select-comp comp )
180 ( print-msg ndx comp )
181 ( break )
182 )
183
184 ( set! ndx ( ndx) )
185 )
186
187 )
188 )
189
190
191
192
193
194
195
196
197 ( define ( placeholder-bounds-small c )
198 ( let*
199 (
200 ( pt ( component-position c ) )
201 ( x ( car pt ) )
202 ( y ( cdr pt ) )
203 ( bounds1 ( cons (cons x (+ y )) (cons (+ x ) y) ) )
204 ( str ( component-basename c ) )
205 ( txt
206 ( make-text
207 (cons (+ x ) (+ y )) 'lower-left str #t 'both ) )
208 ( bounds2 ( object-bounds txt ) )
209 )
210
211
212 ( fold-bounds bounds1 bounds2 )
213
214 )
215 )
216
217
218
219
220
221
222 ( define ( placeholder-bounds-big c )
223 ( let*
224 (
225 ( pt ( component-position c ) )
226 ( x ( car pt ) )
227 ( y ( cdr pt ) )
228 ( bounds1 ( cons (cons x (+ y )) (cons (+ x ) y) ) )
229 ( str
230 ( format #f "Component not found:\n~a" (component-basename c) ) )
231 ( txt
232 ( make-text
233 (cons (+ x ) (+ y )) 'lower-left str #t 'both ) )
234 ( bounds2 ( object-bounds txt ) )
235 ( b2-top-left ( car bounds2 ) )
236 ( b2-bot-right ( cdr bounds2 ) )
237 ( x1 ( car b2-top-left ) )
238 ( x2 ( car b2-bot-right ) )
239 ( dx ( / (- x2 x1) ) )
240 ( y1 ( cdr b2-top-left ) )
241 ( dy )
242 ( triangle-top-left ( cons (+ x1 dx) (+ y1 dy ) ) )
243 ( triangle-bot-right ( cons (+ x1 dx ) (+ y1 dy) ) )
244 ( bounds3 ( cons triangle-top-left triangle-bot-right ) )
245 )
246
247 debug
248
249
250
251
252
253
254
255
256
257
258 ( fold-bounds bounds1 bounds2 bounds3 )
259
260 )
261 )
262
263
264
265
266 ( define ( placeholder-bounds c )
267 ( let*
268 (
269 ( cfg ( path-config-context (getcwd) ) )
270 ( small #t )
271 )
272
273 ( catch #t
274 ( lambda()
275 ( set! small
276 ( config-boolean cfg "schematic.gui" "small-placeholders" )
277 )
278 )
279 ( lambda( ex . args )
280 ( log! 'message
281 "select-locked: assuming small placeholders used" )
282 )
283 )
284
285
286 ( if small
287 ( placeholder-bounds-small c )
288 ( placeholder-bounds-big c )
289 )
290
291 )
292 )
293
294
295
296
297
298
299 ( define ( select-locked-under-mouse )
300
301
302
303 ( define ( point-in-bounds? pt bounds )
304 ( let*
305 (
306 ( top-left ( car bounds ) )
307 ( bot-right ( cdr bounds ) )
308 ( x1 ( car top-left ) )
309 ( x2 ( car bot-right ) )
310 ( y1 ( cdr bot-right ) )
311 ( y2 ( cdr top-left ) )
312 ( ptx ( car pt ) )
313 ( pty ( cdr pt ) )
314 )
315
316
317 ( and
318 ( >= ptx x1 ) ( <= ptx x2 )
319 ( >= pty y1 ) ( <= pty y2 )
320 )
321
322 )
323 )
324
325
326 ( define ( comp-contents c )
327 ( define ( non-txt-obj? o )
328 ( not (text? o) )
329 )
330 ( let*
331 (
332 ( cc ( component-contents c ) )
333 ( oo ( filter non-txt-obj? cc ) )
334 )
335
336
337 ( if ( null? oo )
338 cc
339 oo
340 )
341
342 )
343 )
344
345
346 ( define ( placeholder? c )
347 ( null? (component-contents c) )
348 )
349
350
351 ( define ( comp-bounds c )
352
353 ( if ( placeholder? c )
354 ( placeholder-bounds c )
355 ( apply fold-bounds
356 ( map object-bounds (comp-contents c) ) )
357 )
358 )
359
360
361 ( define ( comp-area c )
362 ( let*
363 (
364 ( bounds ( comp-bounds c ) )
365 ( top-left ( car bounds ) )
366 ( bot-right ( cdr bounds ) )
367 ( x1 ( car top-left ) )
368 ( x2 ( car bot-right ) )
369 ( y1 ( cdr bot-right ) )
370 ( y2 ( cdr top-left ) )
371 )
372
373
374 ( * (- x2 x1) (- y2 y1) )
375
376 )
377 )
378
379
380 ( define ( less-area? c1 c2 )
381 ( < (comp-area c1) (comp-area c2) )
382 )
383
384
385 ( define ( comp-under-mouse? c )
386
387 ( if ( and (pointer-position) (comp-bounds c) )
388 ( point-in-bounds? (pointer-position) (comp-bounds c) )
389 #f
390 )
391 )
392
393
394
395
396 ( let*
397 (
398
399
400
401 ( comps ( sort (locked-comps) less-area? ) )
402 ( comp ( find comp-under-mouse? comps ) )
403 )
404
405 ( deselect-all )
406
407 ( if comp
408 ( select-comp comp )
409 ( log! 'message
410 "select-locked: no locked components under mouse" )
411 )
412
413 )
414 )
415
416
417
418
419
420
421 ( global-set-key "<Control><Shift>L" 'select-locked-all )
422 ( global-set-key "<Shift>L" 'select-locked-next )
423 ( global-set-key "<Control>L" 'select-locked-under-mouse )
424
425
426
427