-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
png2cds.il
56 lines (47 loc) · 1.39 KB
/
png2cds.il
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
(defun RALpng2cds ()
png2gds = "/path/to/bin/png2gds"
cv = deGetEditCellView()
(if cv then
pngfile = (buildString (hiGetExistingFile ?filter "PNG Images (*.png)" ?caption "Import PNG" ?workingDir (getShellEnvVar "HOME")) "/")
(if pngfile != "" then
tech = (techGetTechFile cv~>lib)
grid = (techGetMfgGridResolution tech)
validLayers = (listToVector (leGetValidLayerList tech))
layerCount = (length validLayers)
cid = (ipcBeginProcess (strcat png2gds " " pngfile " stdout 1"))
x1 = 0
y1 = 0
x2 = 0
y2 = 0
partialString = ""
(if cid != nil then
(ipcWaitForProcess cid)
(while data = (ipcReadProcess cid 10)
/* A line is formated as: layer x1 y1 x2 y2 */
data = (strcat partialString data)
partialString = ""
lines = (parseString data "\n")
(foreach line lines
args = (sscanf line "%d %d %d %d %d " layer x1 y1 x2 y2)
x1 = x1 * grid
y1 = y1 * grid
x2 = x2 * grid
y2 = y2 * grid
(if args == 5 then
bbox = (list (list x1 y1) (list x2 y2))
(if (isBBox bbox) == t then
(if (dbCreateRect cv validLayers[(mod layer layerCount)] bbox) == nil then
(printf "Bad dbCreateRect: %s\n" line))
else
(printf "Bad bbox: %s\n" line))
else
partialString = line
)
)
)
(if (ipcIsAliveProcess cid) then
(ipcKillProcess cid))
)
)
)
)