-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabXpmToLayout.ils
More file actions
588 lines (545 loc) · 20.7 KB
/
abXpmToLayout.ils
File metadata and controls
588 lines (545 loc) · 20.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/* abXpmToLayout.ils
Author A.D.Beckett
Group Custom IC (UK), Cadence Design Systems Ltd.
Language SKILL
Date Jun 15, 2001
Modified
By
NOTE: This is SKILL++ code, so please preserve the .ils suffix.
Code to read an X pixmap and draw a layout.
The main entry function is abXpmToLayout(), which should
be invoked with a layout window being the current window.
Limitations/Ideas for future:
1. This only handles up to something like 62 layers
properly. This is because the pixmap format changes to use
more than one character per pixel, and the code rather
dumbly assumes that there will only ever be one. To
be fair, setting up all the layer purpose pairs would
be a nightmare.
2. Could merge colours which appear similar, to avoid
having to specify similar colours lots of times.
3. Some convenience toggles could be added, to turn on or
off all layers.
Primarily this expected to be used for a small number of
colours in the pixmap file. This can be arranged using
other tools (xv, gimp, PC tools etc).
These tools can also be used to convert from other formats
to xpm.
***************************************************
SCCS Info: @(#) abXpmToLayout.ils 06/15/01.15:27:13 1.4
*/
(importSkillVar abPixMapOptionsForm)
;------------------------------------------------------------------------
; Define classes used within the code
;------------------------------------------------------------------------
(defclass abPixMap ()
(
(width @initarg width @reader abPixMapGetWidth)
(height @initarg height @reader abPixMapGetHeight)
(colours @initarg colours @reader abPixMapGetColours)
(pixels @initarg pixels @reader abPixMapGetPixels)
)
)
(defclass abPixMapColour ()
(
(char @initarg char)
(red @initarg red @reader abPixMapColourGetRed)
(green @initarg green @reader abPixMapColourGetGreen)
(blue @initarg blue @reader abPixMapColourGetBlue)
(lpp @reader abPixMapColourGetLpp @writer abPixMapColourSetLpp)
)
)
/***************************************************************
* *
* (abPixMapColourGetLpp _colour) *
* *
* A dummy method, so that if the colour isn't found for a *
* character in the pixel strings, it returns nil *
* *
***************************************************************/
(defmethod abPixMapColourGetLpp ((_colour list))
nil
)
/***************************************************************
* *
* (abPixMapReadFile fileName) *
* *
* Read a pixmap file, and return an instance of the abPixMap *
* structure. *
* *
***************************************************************/
(defun abPixMapReadFile (fileName)
(let (prt staticFound line data dimensions width height ncolours
colourTable colourInfo red green blue pixmap)
(unless (setq prt (infile fileName))
(error "Could not read pixmap file %s" fileName)
)
(rexCompile "static char")
(while (and (null staticFound) (gets line prt))
(setq staticFound (rexExecute line))
)
(when staticFound
(setq data t)
(while (equal (setq data (lineread prt)) t) t)
;-----------------------------------------------------------
; Swallow any warnings about closing } etc
;-----------------------------------------------------------
(getWarn)
)
(close prt)
(when (and data (nequal data t))
;-----------------------------------------------------------
; first entry in the list will be the dimensional information
;-----------------------------------------------------------
(setq dimensions (linereadstring (car data)))
(setq width (car dimensions))
(setq height (cadr dimensions))
(setq ncolours (caddr dimensions))
(setq data (cdr data))
;-----------------------------------------------------------
; Now read the colours
;-----------------------------------------------------------
(setq colourTable (makeTable 'colourTable nil))
(for colour 1 ncolours
(setq colourInfo (parseString (car data)))
(setq data (cdr data))
(when (cddr colourInfo)
(sscanf (caddr colourInfo)
"#%2x%2x%2x" red green blue
)
(setarray colourTable
(car colourInfo)
(makeInstance 'abPixMapColour
?char (car colourInfo)
?red red || 0
?green green || 0
?blue blue || 0
)
)
)
)
;-----------------------------------------------------------
; Now create the pixmap object
;-----------------------------------------------------------
(setq pixmap
(makeInstance 'abPixMap
?width width
?height height
?colours colourTable
?pixels data
)
)
) ; when
pixmap
)
)
/***************************************************************
* *
* abPixMapDrawLayout(@key pixmap (pixelSize 0.1) *
* (cellView (geGetEditCellView)) *
* (origin 0:0)) *
* *
* Draw the layout itself from the pixmap structure. *
* *
***************************************************************/
(defun abPixMapDrawLayout (@key pixmap (pixelSize 0.1)
(cellView (geGetEditCellView))
(origin 0:0))
(let (x y colours rectList lpp)
(setq colours (abPixMapGetColours pixmap))
(setq y (yCoord origin))
;-----------------------------------------------------------------
; Iterate over each row
;-----------------------------------------------------------------
(foreach row (abPixMapGetPixels pixmap)
(setq x (xCoord origin))
(foreach pixel (parseString row "")
;-----------------------------------------------
; Determine the layer purpose pair
;-----------------------------------------------
(setq lpp
(abPixMapColourGetLpp (arrayref colours pixel)))
;-----------------------------------------------
; Draw the rectangle
;-----------------------------------------------
(when (and (listp lpp) lpp)
(setq rectList
(cons
(dbCreateRect
cellView
lpp
(list
(list x y)
(list
(plus x pixelSize)
(difference y pixelSize)
)
)
)
rectList
)))
(setq x (plus x pixelSize))
)
(setq y (difference y pixelSize))
)
;-----------------------------------------------------------------
; Merge all the shapes to reduce the shape count
;-----------------------------------------------------------------
(leMergeShapes rectList)
t
))
/***************************************************************
* *
* (abPixMapCreateForm) *
* *
* Create the options form for the pixmap drawer. *
* Note that all the layers aren't put on the form until *
* the file has been read *
* *
***************************************************************/
(defun abPixMapCreateForm ()
(let (fileName selectFile pixelSize scrollRegion readFile)
(setq fileName
(hiCreateStringField
?name 'fileName
?prompt "Pixmap File"
?callback "(abUpdateSelectFile)"
)
)
(setq selectFile
(hiCreateButton
?name 'selectFile
?buttonText "Select File"
?callback "(abPixMapSyncWithSelectFile)"
)
)
(setq readFile
(hiCreateButton
?name 'readFile
?buttonText "Read File"
?callback "(abPixMapReadFileCB)"
)
)
(setq pixelSize
(hiCreateFloatField
?name 'pixelSize
?defValue 0.1
?prompt "Pixel Size"
)
)
(setq scrollRegion
(hiCreateScrollRegion
?borderWidth 0
?name 'layers
)
)
(hiCreateAppForm
?name 'abPixMapOptionsForm
?formTitle "Choose pixmap settings"
?formType 'options
?buttonLayout 'HideCancel
?fields (list
(list fileName 0:0 405:35 105)
(list selectFile 105:35 95:30)
(list readFile 205:35 95:30)
(list pixelSize 0:70 405:35 105)
(list
(hiCreateLabel
?name 'colourLab
?labelText "Colour"
)
105:105 35:30)
(list
(hiCreateLabel
?name 'convertLab
?labelText "Draw"
)
160:105 32:30)
(list
(hiCreateLabel
?name 'lppLab
?labelText "Layer"
)
205:105 32:30)
(list scrollRegion 105:130 300:200)
)
)
)
)
/***************************************************************
* *
* (abPixMapAddPointCB _windowId _pointList) *
* *
* Ignore any points entered before the pixmap has been *
* read. *
* *
***************************************************************/
(defun abPixMapAddPointCB (_windowId _pointList)
(unless (getq abPixMapOptionsForm pixmap)
(deletePoint)
)
)
/***************************************************************
* *
* (abPixMapDoneCB _windowId ok points) *
* *
* When the points have been entered, and all is OK, proceed *
* to fill the colour structure with the selected layer purpose *
* pairs, and then draw the pixmap starting at the specified *
* coordinates. *
* *
***************************************************************/
(defun abPixMapDoneCB (_windowId ok points)
(let (pixmap)
(setq pixmap (getq abPixMapOptionsForm pixmap))
(when (and ok points pixmap)
(abPixMapFillInLpps (getq abPixMapOptionsForm layers) pixmap)
(abPixMapDrawLayout
?pixmap pixmap
?pixelSize (getq (getq abPixMapOptionsForm pixelSize) value)
?cellView (getq abPixMapOptionsForm cellView)
?origin (car points)
)
)
)
)
/***************************************************************
* *
* (abPixMapGetLayer layerString) *
* *
* Because we have multiple layer cyclic fields, need *
* to extract the layer purpose pair name ourselves *
* *
***************************************************************/
(defun abPixMapGetLayer (layerString)
(let (layer)
(setq layer (linereadstring layerString))
(list (get_string (car layer))
(get_string (caadr layer)))))
/***************************************************************
* *
* (abPixMapFillInLpps region pixmap) *
* *
* Given the scroll region on the form, and the pixmap *
* instance, fill in the lpp information in the colour *
* structures, based on what was selected on the form. *
* *
***************************************************************/
(defun abPixMapFillInLpps (region pixmap)
(let (colours colourNum colour)
(setq colours (abPixMapGetColours pixmap))
(setq colourNum 0)
;-----------------------------------------------------------------
; Loop through all the colour names
;-----------------------------------------------------------------
(foreach colourName (getq region colourNames)
(setq colour (arrayref colours colourName))
(abPixMapColourSetLpp
colour
(and (getq (get region (concat 'convert colourNum)) value)
(abPixMapGetLayer
(cadddr
(getq (get region (concat 'lpp colourNum)) value))
)
)
)
(postincrement colourNum)
)
)
)
/***************************************************************
* *
* (abPixMapSyncWithSelectFile) *
* *
* Set up the synchronisation with the file selecter *
* *
***************************************************************/
(defun abPixMapSyncWithSelectFile ()
(abSyncWithSelectFile
abPixMapOptionsForm
'fileName
nil))
/****************************************************************
* *
* (abPixMapReadFileCB) *
* *
* Callback for the read file button. When this is done, it must *
* read the pixmap structure, and fill in the scroll region with *
* the appropriate layers. *
* *
****************************************************************/
(defun abPixMapReadFileCB ()
(let (fileName pixmap)
(setq fileName (getq (getq abPixMapOptionsForm fileName) value))
(unless (blankstrp fileName)
;---------------------------------------------------------
; Read the pixmap
;---------------------------------------------------------
(setq pixmap (abPixMapReadFile fileName))
(when pixmap
;---------------------------------------------------
; Put the layers into the scroll region
;---------------------------------------------------
(abPixMapFillScrollRegion
pixmap (getq abPixMapOptionsForm layers)
(getq abPixMapOptionsForm cellView))
;---------------------------------------------------
; Record the pixmap for posterity
;---------------------------------------------------
(putpropq abPixMapOptionsForm pixmap pixmap)
;---------------------------------------------------
; Change the enter function - primarily to change
; the prompt
;---------------------------------------------------
(changeEnterFun 'enterPoint
?prompts
'("Point at top left origin of pixmap")
?form abPixMapOptionsForm
?addPointProc "abPixMapAddPointCB"
?doneProc "abPixMapDoneCB"
?noInfix t
?alwaysMap t
)
)
)
)
)
/***************************************************************
* *
* (abPixMapCreateColourIcon colour) *
* *
* Build a small coloured icon in the colour which was in the *
* original pixmap (or as close to it as we can get given *
* the colour limitations in DFII) *
* *
***************************************************************/
(defun abPixMapCreateColourIcon (colour)
(let (colourArray
(line "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
)
(setq colourArray (hiCreateColorArray))
(setarray colourArray 0
(hiMatchColor
(foreach mapcar intensity
(list
(abPixMapColourGetRed colour)
(abPixMapColourGetGreen colour)
(abPixMapColourGetBlue colour)
)
(round (times intensity 3.915))
)
)
)
(hiStringToIcon
colourArray
strcat(line line line line line line)
32 6
)
)
)
/***************************************************************
* *
* (abPixMapFillScrollRegion pixmap region cellView) *
* *
* Fill the scroll region with all the colours found in the *
* pixmap file *
* *
***************************************************************/
(defun abPixMapFillScrollRegion (pixmap region cellView)
(let (current colours colourNames colourNum button y lpp tfId convert
icon)
(setq tfId (techGetTechFile cellView))
;-----------------------------------------------------------------
; Erase any current layer definitions
;-----------------------------------------------------------------
(setq current (getq region fieldList))
(when current (hiDeleteFields region current))
;-----------------------------------------------------------------
; Add the labels at the top
;-----------------------------------------------------------------
(setq colours (abPixMapGetColours pixmap))
(setq colourNames (sort (getq colours ?) 'alphalessp))
(setq colourNum 0)
;-----------------------------------------------------------------
; Remember the colour names to ease lookup later
;-----------------------------------------------------------------
(putpropq region colourNames colourNames)
;-----------------------------------------------------------------
; Build the scrollable region on the form
;-----------------------------------------------------------------
(foreach colourName colourNames
(setq icon
(abPixMapCreateColourIcon (arrayref colours colourName)))
;--------------------------------------------------------
; The pretty coloured button, corresponding
; to the colour in the original pixmap
;--------------------------------------------------------
(setq button
(hiCreateButton
?name (concat 'colour colourNum)
?buttonIcon icon
)
)
;--------------------------------------------------------
; Boolean button to enable the layer
;--------------------------------------------------------
(setq convert
(hiCreateBooleanButton
?name (concat 'convert colourNum)
?buttonText " "
?defValue t
?value t
)
)
;--------------------------------------------------------
; Create the layer cyclic box
;--------------------------------------------------------
(setq lpp
(hiCreateLayerCyclicField
tfId
"Choose"
""
(leGetValidLayerList tfId)
))
;--------------------------------------------------------
; Make sure field symbol is unique
;--------------------------------------------------------
(putpropq lpp
(concat 'lpp colourNum) hiFieldSym)
(setq y (times colourNum 35))
(hiAddFields region
(list
(list button 0:y+11 32:12)
(list convert 60:y 20:35 0)
(list lpp 100:y 150:35 0)
)
)
(postincrement colourNum)
)
)
)
/***************************************************************
* *
* (abXpmToLayout) *
* *
* Main entry point for the pixmap drawer. *
* *
***************************************************************/
(defun abXpmToLayout ()
(let (current)
(unless (boundp 'abPixMapOptionsForm)
(abPixMapCreateForm))
(setq current (getq (getq abPixMapOptionsForm layers) fieldList))
(when current (hiDeleteFields (getq abPixMapOptionsForm layers) current))
(putpropq abPixMapOptionsForm (geGetEditCellView) cellView)
(putpropq abPixMapOptionsForm nil pixmap)
(enterPoint
?prompts '("Use options form to specify file to read")
?form abPixMapOptionsForm
?addPointProc "abPixMapAddPointCB"
?doneProc "abPixMapDoneCB"
?noInfix t
?alwaysMap t
)
)
)