gds-viewer 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: gds_viewer
3
+ Version: 0.1.0
4
+ Summary: GDSII viewer and headless PNG export with IHP SG13G2 layer colors and fill patterns
5
+ Author-email: Volker Muehlhaus <volker@muehlhaus.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/VolkerMuehlhaus/gds_viewer
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: gdspy>1.6.0
12
+ Requires-Dist: matplotlib
13
+ Requires-Dist: numpy
14
+ Dynamic: license-file
15
+
16
+ # gds_viewer
17
+
18
+ A command-line GDSII layout viewer built on [gdspy](https://github.com/heitzmann/gdspy), with IHP SG13G2 layer colors and fill patterns applied automatically. No KLayout installation is required to view a layout with correct-looking colors.
19
+
20
+ ```
21
+ pip install gds_viewer
22
+
23
+ gds_viewer layout.gds
24
+ gds_viewer layout.gds --cellname MY_CELL
25
+ gds_viewer layout.gds --screenshot layout.png --width 1200
26
+ ```
27
+
28
+ Without installing, `python gds_viewer.py ...` works the same way.
29
+
30
+ From Python:
31
+
32
+ ```python
33
+ import gdspy, gds_viewer
34
+
35
+ cell = gdspy.GdsLibrary(infile="layout.gds").top_level()[0]
36
+ gds_viewer.render_screenshot(cell, "layout.png", width_px=1200, labels=[(10.0, 0.0, "P1")])
37
+ ```
38
+
39
+ `labels` draws a marker and a text at layout coordinates, for example to show port locations.
40
+
41
+ ## Options
42
+
43
+ - `gds_file` (positional) - input GDSII file
44
+ - `--cellname` - cell to display (default: first top-level cell in the file)
45
+ - `--screenshot FILE.png` - render the layout to a PNG and exit, instead of opening the interactive GUI
46
+ - `--width PIXELS` - width of the `--screenshot` PNG (default 2400)
47
+ - `--version` - print the version
48
+
49
+ ## Interactive viewer
50
+
51
+ With no `--screenshot`, gdspy's built-in Tkinter GUI opens (pan/zoom, ruler, per-layer color/pattern/visibility toggles, ref-level depth control). Colors and fill patterns are hardcoded from `sg13g2.lyp`, so the layout looks close to its KLayout appearance without reading that file at runtime.
52
+
53
+ Purpose (datatype) layers `noqrc`, `filler`, `nofill`, and `block` are hidden by default, across every layer - toggle any of them back on from the layer list if needed.
54
+
55
+ gdspy's viewer only supports 10 built-in fill patterns, so `sg13g2.lyp`'s ~54 distinct dither patterns are mapped to the closest of those 10 by pixel density and hatch/grid orientation - a reasonable approximation, not pixel-exact.
56
+
57
+ ## --screenshot export
58
+
59
+ Renders headlessly via matplotlib (no GUI/display needed, works over SSH or in CI) and saves a PNG. Unlike the interactive viewer, fill patterns here are pixel-accurate reproductions of `sg13g2.lyp`'s actual dither patterns, not an approximation - reverse-engineered by rendering the real IHP SG13G2 technology through KLayout itself and sampling the resulting pixels.
60
+
61
+ [<img src="https://raw.githubusercontent.com/VolkerMuehlhaus/gds_viewer/main/doc/gds_viewer_screenshot.png" width="800" />](https://raw.githubusercontent.com/VolkerMuehlhaus/gds_viewer/main/doc/gds_viewer_screenshot.png)
62
+
63
+ ## Requirements
64
+
65
+ - `gdspy`
66
+ - `matplotlib` and `numpy` (only needed for `--screenshot`; `pip install gds_viewer` installs all three)
67
+
68
+ ## How the layer styling was derived
69
+
70
+ `sg13g2.lyp` (bundled here for reference) is **not** read at runtime - `gds_viewer.py` has no dependency on it or on KLayout once written. Its `<fill-color>` values were copied straight into the `LAYER_STYLES` table.
71
+
72
+ Its `<dither-pattern>` values (e.g. `"C23"`, `"I1"`) don't have documented bitmap definitions anywhere accessible from code - KLayout resolves them internally with no public API to query. They were recovered empirically: a synthetic GDS with one swatch per distinct pattern name was rendered through a real, installed KLayout in batch mode (`klayout_app.exe -z -nc -rx -r script.rb`, using `RBA::LayoutView` to load the layout + `sg13g2.lyp` and save a PNG), then each swatch's minimal repeating tile was recovered from the rendered pixels (2D period detection, then majority-vote over all repeats to denoise anti-aliasing). The resulting bitmaps are hardcoded in `PATTERN_TILES`.
73
+
74
+ If `sg13g2.lyp` ever changes, `LAYER_STYLES` and `PATTERN_TILES` need to be regenerated using that same approach.
75
+
76
+ ## License
77
+
78
+ This project is licensed under the Apache License, Version 2.0 - see [LICENSE](https://github.com/VolkerMuehlhaus/gds_viewer/blob/main/LICENSE) for the full text.
@@ -0,0 +1,63 @@
1
+ # gds_viewer
2
+
3
+ A command-line GDSII layout viewer built on [gdspy](https://github.com/heitzmann/gdspy), with IHP SG13G2 layer colors and fill patterns applied automatically. No KLayout installation is required to view a layout with correct-looking colors.
4
+
5
+ ```
6
+ pip install gds_viewer
7
+
8
+ gds_viewer layout.gds
9
+ gds_viewer layout.gds --cellname MY_CELL
10
+ gds_viewer layout.gds --screenshot layout.png --width 1200
11
+ ```
12
+
13
+ Without installing, `python gds_viewer.py ...` works the same way.
14
+
15
+ From Python:
16
+
17
+ ```python
18
+ import gdspy, gds_viewer
19
+
20
+ cell = gdspy.GdsLibrary(infile="layout.gds").top_level()[0]
21
+ gds_viewer.render_screenshot(cell, "layout.png", width_px=1200, labels=[(10.0, 0.0, "P1")])
22
+ ```
23
+
24
+ `labels` draws a marker and a text at layout coordinates, for example to show port locations.
25
+
26
+ ## Options
27
+
28
+ - `gds_file` (positional) - input GDSII file
29
+ - `--cellname` - cell to display (default: first top-level cell in the file)
30
+ - `--screenshot FILE.png` - render the layout to a PNG and exit, instead of opening the interactive GUI
31
+ - `--width PIXELS` - width of the `--screenshot` PNG (default 2400)
32
+ - `--version` - print the version
33
+
34
+ ## Interactive viewer
35
+
36
+ With no `--screenshot`, gdspy's built-in Tkinter GUI opens (pan/zoom, ruler, per-layer color/pattern/visibility toggles, ref-level depth control). Colors and fill patterns are hardcoded from `sg13g2.lyp`, so the layout looks close to its KLayout appearance without reading that file at runtime.
37
+
38
+ Purpose (datatype) layers `noqrc`, `filler`, `nofill`, and `block` are hidden by default, across every layer - toggle any of them back on from the layer list if needed.
39
+
40
+ gdspy's viewer only supports 10 built-in fill patterns, so `sg13g2.lyp`'s ~54 distinct dither patterns are mapped to the closest of those 10 by pixel density and hatch/grid orientation - a reasonable approximation, not pixel-exact.
41
+
42
+ ## --screenshot export
43
+
44
+ Renders headlessly via matplotlib (no GUI/display needed, works over SSH or in CI) and saves a PNG. Unlike the interactive viewer, fill patterns here are pixel-accurate reproductions of `sg13g2.lyp`'s actual dither patterns, not an approximation - reverse-engineered by rendering the real IHP SG13G2 technology through KLayout itself and sampling the resulting pixels.
45
+
46
+ [<img src="https://raw.githubusercontent.com/VolkerMuehlhaus/gds_viewer/main/doc/gds_viewer_screenshot.png" width="800" />](https://raw.githubusercontent.com/VolkerMuehlhaus/gds_viewer/main/doc/gds_viewer_screenshot.png)
47
+
48
+ ## Requirements
49
+
50
+ - `gdspy`
51
+ - `matplotlib` and `numpy` (only needed for `--screenshot`; `pip install gds_viewer` installs all three)
52
+
53
+ ## How the layer styling was derived
54
+
55
+ `sg13g2.lyp` (bundled here for reference) is **not** read at runtime - `gds_viewer.py` has no dependency on it or on KLayout once written. Its `<fill-color>` values were copied straight into the `LAYER_STYLES` table.
56
+
57
+ Its `<dither-pattern>` values (e.g. `"C23"`, `"I1"`) don't have documented bitmap definitions anywhere accessible from code - KLayout resolves them internally with no public API to query. They were recovered empirically: a synthetic GDS with one swatch per distinct pattern name was rendered through a real, installed KLayout in batch mode (`klayout_app.exe -z -nc -rx -r script.rb`, using `RBA::LayoutView` to load the layout + `sg13g2.lyp` and save a PNG), then each swatch's minimal repeating tile was recovered from the rendered pixels (2D period detection, then majority-vote over all repeats to denoise anti-aliasing). The resulting bitmaps are hardcoded in `PATTERN_TILES`.
58
+
59
+ If `sg13g2.lyp` ever changes, `LAYER_STYLES` and `PATTERN_TILES` need to be regenerated using that same approach.
60
+
61
+ ## License
62
+
63
+ This project is licensed under the Apache License, Version 2.0 - see [LICENSE](https://github.com/VolkerMuehlhaus/gds_viewer/blob/main/LICENSE) for the full text.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: gds_viewer
3
+ Version: 0.1.0
4
+ Summary: GDSII viewer and headless PNG export with IHP SG13G2 layer colors and fill patterns
5
+ Author-email: Volker Muehlhaus <volker@muehlhaus.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/VolkerMuehlhaus/gds_viewer
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: gdspy>1.6.0
12
+ Requires-Dist: matplotlib
13
+ Requires-Dist: numpy
14
+ Dynamic: license-file
15
+
16
+ # gds_viewer
17
+
18
+ A command-line GDSII layout viewer built on [gdspy](https://github.com/heitzmann/gdspy), with IHP SG13G2 layer colors and fill patterns applied automatically. No KLayout installation is required to view a layout with correct-looking colors.
19
+
20
+ ```
21
+ pip install gds_viewer
22
+
23
+ gds_viewer layout.gds
24
+ gds_viewer layout.gds --cellname MY_CELL
25
+ gds_viewer layout.gds --screenshot layout.png --width 1200
26
+ ```
27
+
28
+ Without installing, `python gds_viewer.py ...` works the same way.
29
+
30
+ From Python:
31
+
32
+ ```python
33
+ import gdspy, gds_viewer
34
+
35
+ cell = gdspy.GdsLibrary(infile="layout.gds").top_level()[0]
36
+ gds_viewer.render_screenshot(cell, "layout.png", width_px=1200, labels=[(10.0, 0.0, "P1")])
37
+ ```
38
+
39
+ `labels` draws a marker and a text at layout coordinates, for example to show port locations.
40
+
41
+ ## Options
42
+
43
+ - `gds_file` (positional) - input GDSII file
44
+ - `--cellname` - cell to display (default: first top-level cell in the file)
45
+ - `--screenshot FILE.png` - render the layout to a PNG and exit, instead of opening the interactive GUI
46
+ - `--width PIXELS` - width of the `--screenshot` PNG (default 2400)
47
+ - `--version` - print the version
48
+
49
+ ## Interactive viewer
50
+
51
+ With no `--screenshot`, gdspy's built-in Tkinter GUI opens (pan/zoom, ruler, per-layer color/pattern/visibility toggles, ref-level depth control). Colors and fill patterns are hardcoded from `sg13g2.lyp`, so the layout looks close to its KLayout appearance without reading that file at runtime.
52
+
53
+ Purpose (datatype) layers `noqrc`, `filler`, `nofill`, and `block` are hidden by default, across every layer - toggle any of them back on from the layer list if needed.
54
+
55
+ gdspy's viewer only supports 10 built-in fill patterns, so `sg13g2.lyp`'s ~54 distinct dither patterns are mapped to the closest of those 10 by pixel density and hatch/grid orientation - a reasonable approximation, not pixel-exact.
56
+
57
+ ## --screenshot export
58
+
59
+ Renders headlessly via matplotlib (no GUI/display needed, works over SSH or in CI) and saves a PNG. Unlike the interactive viewer, fill patterns here are pixel-accurate reproductions of `sg13g2.lyp`'s actual dither patterns, not an approximation - reverse-engineered by rendering the real IHP SG13G2 technology through KLayout itself and sampling the resulting pixels.
60
+
61
+ [<img src="https://raw.githubusercontent.com/VolkerMuehlhaus/gds_viewer/main/doc/gds_viewer_screenshot.png" width="800" />](https://raw.githubusercontent.com/VolkerMuehlhaus/gds_viewer/main/doc/gds_viewer_screenshot.png)
62
+
63
+ ## Requirements
64
+
65
+ - `gdspy`
66
+ - `matplotlib` and `numpy` (only needed for `--screenshot`; `pip install gds_viewer` installs all three)
67
+
68
+ ## How the layer styling was derived
69
+
70
+ `sg13g2.lyp` (bundled here for reference) is **not** read at runtime - `gds_viewer.py` has no dependency on it or on KLayout once written. Its `<fill-color>` values were copied straight into the `LAYER_STYLES` table.
71
+
72
+ Its `<dither-pattern>` values (e.g. `"C23"`, `"I1"`) don't have documented bitmap definitions anywhere accessible from code - KLayout resolves them internally with no public API to query. They were recovered empirically: a synthetic GDS with one swatch per distinct pattern name was rendered through a real, installed KLayout in batch mode (`klayout_app.exe -z -nc -rx -r script.rb`, using `RBA::LayoutView` to load the layout + `sg13g2.lyp` and save a PNG), then each swatch's minimal repeating tile was recovered from the rendered pixels (2D period detection, then majority-vote over all repeats to denoise anti-aliasing). The resulting bitmaps are hardcoded in `PATTERN_TILES`.
73
+
74
+ If `sg13g2.lyp` ever changes, `LAYER_STYLES` and `PATTERN_TILES` need to be regenerated using that same approach.
75
+
76
+ ## License
77
+
78
+ This project is licensed under the Apache License, Version 2.0 - see [LICENSE](https://github.com/VolkerMuehlhaus/gds_viewer/blob/main/LICENSE) for the full text.
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ gds_viewer.py
4
+ pyproject.toml
5
+ gds_viewer.egg-info/PKG-INFO
6
+ gds_viewer.egg-info/SOURCES.txt
7
+ gds_viewer.egg-info/dependency_links.txt
8
+ gds_viewer.egg-info/entry_points.txt
9
+ gds_viewer.egg-info/requires.txt
10
+ gds_viewer.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ gds_viewer = gds_viewer:main
@@ -0,0 +1,3 @@
1
+ gdspy>1.6.0
2
+ matplotlib
3
+ numpy
@@ -0,0 +1 @@
1
+ gds_viewer
@@ -0,0 +1,759 @@
1
+ #!/usr/bin/env python3
2
+ ########################################################################
3
+ #
4
+ # Copyright 2025 Volker Muehlhaus and IHP PDK Authors
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ ########################################################################
19
+
20
+ """Command-line GDSII layout viewer, using gdspy, with IHP SG13G2 layer styling."""
21
+
22
+ import argparse
23
+ import sys
24
+
25
+ import gdspy
26
+
27
+ __version__ = "0.1.0"
28
+
29
+ # Hardcoded from sg13g2.lyp (IHP SG13G2 KLayout layer properties): (layer, datatype)
30
+ # -> (fill-color, dither-pattern name). Values are copied verbatim from the .lyp's
31
+ # <fill-color> and <dither-pattern>. See PATTERN_TILES below for what each pattern
32
+ # name actually looks like.
33
+ LAYER_STYLES = {
34
+ (40, 0): ("#ffffff", "I1"), # Substrate.drawing
35
+ (40, 25): ("#39bfff", "C1"), # Substrate.text
36
+ (1, 0): ("#00ff00", "C2"), # Activ.drawing
37
+ (1, 1): ("#00ff00", "C3"), # Activ.label
38
+ (1, 2): ("#00ff00", "C2"), # Activ.pin
39
+ (1, 3): ("#00ff00", "C2"), # Activ.net
40
+ (1, 4): ("#00ff00", "C3"), # Activ.boundary
41
+ (1, 19): ("#ffff00", "I1"), # Activ.lvs
42
+ (1, 20): ("#00ff00", "C2"), # Activ.mask
43
+ (1, 22): ("#00ff00", "C4"), # Activ.filler
44
+ (1, 23): ("#00ff00", "I1"), # Activ.nofill
45
+ (1, 26): ("#00cc66", "C5"), # Activ.OPC
46
+ (1, 27): ("#00ff00", "C6"), # Activ.iOPC
47
+ (1, 28): ("#ff0000", "C3"), # Activ.noqrc
48
+ (5, 0): ("#bf4026", "C7"), # GatPoly.drawing
49
+ (5, 1): ("#bf4026", "C3"), # GatPoly.label
50
+ (5, 2): ("#bf4026", "C3"), # GatPoly.pin
51
+ (5, 3): ("#bf4026", "C7"), # GatPoly.net
52
+ (5, 4): ("#bf4026", "C7"), # GatPoly.boundary
53
+ (5, 22): ("#bf4026", "C7"), # GatPoly.filler
54
+ (5, 23): ("#bf4026", "I1"), # GatPoly.nofill
55
+ (5, 26): ("#9900e6", "I1"), # GatPoly.OPC
56
+ (5, 27): ("#ffff00", "C8"), # GatPoly.iOPC
57
+ (5, 28): ("#ff0000", "C3"), # GatPoly.noqrc
58
+ (128, 0): ("#bf4026", "C7"), # PolyRes.drawing
59
+ (128, 1): ("#bf4026", "C3"), # PolyRes.label
60
+ (128, 2): ("#bf4026", "C3"), # PolyRes.pin
61
+ (128, 3): ("#bf4026", "C7"), # PolyRes.net
62
+ (128, 4): ("#bf4026", "C7"), # PolyRes.boundary
63
+ (31, 0): ("#268c6b", "C9"), # NWell.drawing
64
+ (31, 1): ("#268c6b", "C3"), # NWell.label
65
+ (31, 2): ("#268c6b", "C3"), # NWell.pin
66
+ (31, 3): ("#268c6b", "C9"), # NWell.net
67
+ (31, 4): ("#268c6b", "C3"), # NWell.boundary
68
+ (32, 0): ("#8c8ca6", "C10"), # nBuLay.drawing
69
+ (32, 1): ("#8c8ca6", "C10"), # nBuLay.label
70
+ (32, 2): ("#8c8ca6", "C10"), # nBuLay.pin
71
+ (32, 3): ("#8c8ca6", "C10"), # nBuLay.net
72
+ (32, 4): ("#8c8ca6", "C10"), # nBuLay.boundary
73
+ (32, 21): ("#268c6b", "C3"), # nBuLay.block
74
+ (46, 21): ("#ff8000", "C11"), # PWell.block
75
+ (14, 0): ("#ccb899", "C12"), # pSD.drawing
76
+ (7, 0): ("#00cc66", "C13"), # nSD.drawing
77
+ (7, 21): ("#00cc66", "C14"), # nSD.block
78
+ (28, 0): ("#9900e6", "C15"), # SalBlock.drawing
79
+ (44, 0): ("#ffffcc", "C16"), # ThickGateOx.drawing
80
+ (6, 0): ("#00ffff", "C17"), # Cont.drawing
81
+ (6, 3): ("#00ffff", "C17"), # Cont.net
82
+ (6, 4): ("#00ffff", "C17"), # Cont.boundary
83
+ (6, 26): ("#ffff00", "I1"), # Cont.OPC
84
+ (8, 0): ("#39bfff", "C1"), # Metal1.drawing
85
+ (8, 1): ("#39bfff", "C1"), # Metal1.label
86
+ (8, 2): ("#39bfff", "C1"), # Metal1.pin
87
+ (8, 3): ("#39bfff", "C1"), # Metal1.net
88
+ (8, 4): ("#39bfff", "I1"), # Metal1.boundary
89
+ (8, 20): ("#39bfff", "C1"), # Metal1.mask
90
+ (8, 22): ("#39bfff", "C1"), # Metal1.filler
91
+ (8, 23): ("#39bfff", "I1"), # Metal1.nofill
92
+ (8, 24): ("#000000", "C18"), # Metal1.slit
93
+ (8, 25): ("#39bfff", "C1"), # Metal1.text
94
+ (8, 26): ("#ffff00", "I1"), # Metal1.OPC
95
+ (8, 28): ("#ff0000", "C3"), # Metal1.noqrc
96
+ (8, 29): ("#bf4026", "C19"), # Metal1.res
97
+ (8, 33): ("#39bfff", "I1"), # Metal1.iprobe
98
+ (8, 34): ("#39bfff", "I1"), # Metal1.diffprb
99
+ (19, 0): ("#ccccff", "C20"), # Via1.drawing
100
+ (19, 3): ("#ccccff", "C20"), # Via1.net
101
+ (19, 4): ("#ccccff", "C20"), # Via1.boundary
102
+ (10, 0): ("#ccccd9", "C21"), # Metal2.drawing
103
+ (10, 1): ("#ccccd9", "C21"), # Metal2.label
104
+ (10, 2): ("#ccccd9", "C21"), # Metal2.pin
105
+ (10, 3): ("#ccccd9", "C21"), # Metal2.net
106
+ (10, 4): ("#ccccd9", "C21"), # Metal2.boundary
107
+ (10, 20): ("#ccccd9", "C21"), # Metal2.mask
108
+ (10, 22): ("#ccccd9", "C21"), # Metal2.filler
109
+ (10, 23): ("#ccccd9", "I1"), # Metal2.nofill
110
+ (10, 24): ("#000000", "C18"), # Metal2.slit
111
+ (10, 25): ("#ccccd9", "C21"), # Metal2.text
112
+ (10, 26): ("#ffff00", "I1"), # Metal2.OPC
113
+ (10, 28): ("#ff0000", "C3"), # Metal2.noqrc
114
+ (10, 29): ("#bf4026", "C19"), # Metal2.res
115
+ (10, 33): ("#ccccd9", "I1"), # Metal2.iprobe
116
+ (10, 34): ("#ccccd9", "I1"), # Metal2.diffprb
117
+ (29, 0): ("#ff3736", "C22"), # Via2.drawing
118
+ (29, 3): ("#ff3736", "C22"), # Via2.net
119
+ (29, 4): ("#ff3736", "C22"), # Via2.boundary
120
+ (30, 0): ("#d80000", "C23"), # Metal3.drawing
121
+ (30, 1): ("#d80000", "C23"), # Metal3.label
122
+ (30, 2): ("#d80000", "C23"), # Metal3.pin
123
+ (30, 3): ("#d80000", "C23"), # Metal3.net
124
+ (30, 4): ("#d80000", "C23"), # Metal3.boundary
125
+ (30, 20): ("#d80000", "C23"), # Metal3.mask
126
+ (30, 22): ("#d80000", "C23"), # Metal3.filler
127
+ (30, 23): ("#d80000", "I1"), # Metal3.nofill
128
+ (30, 24): ("#000000", "C18"), # Metal3.slit
129
+ (30, 25): ("#d80000", "C23"), # Metal3.text
130
+ (30, 26): ("#ffff00", "I1"), # Metal3.OPC
131
+ (30, 28): ("#ff0000", "C3"), # Metal3.noqrc
132
+ (30, 29): ("#bf4026", "C19"), # Metal3.res
133
+ (30, 33): ("#d80000", "I1"), # Metal3.iprobe
134
+ (30, 34): ("#d80000", "I1"), # Metal3.diffprb
135
+ (36, 0): ("#268c6b", "C24"), # MIM.drawing
136
+ (36, 3): ("#268c6b", "C24"), # MIM.net
137
+ (36, 4): ("#268c6b", "C3"), # MIM.boundary
138
+ (129, 0): ("#ffe6bf", "C25"), # Vmim.drawing
139
+ (49, 0): ("#9ba940", "C26"), # Via3.drawing
140
+ (49, 3): ("#9ba940", "C26"), # Via3.net
141
+ (49, 4): ("#9ba940", "C26"), # Via3.boundary
142
+ (50, 0): ("#93e837", "C27"), # Metal4.drawing
143
+ (50, 1): ("#93e837", "C27"), # Metal4.label
144
+ (50, 2): ("#93e837", "C27"), # Metal4.pin
145
+ (50, 3): ("#93e837", "C27"), # Metal4.net
146
+ (50, 4): ("#93e837", "C27"), # Metal4.boundary
147
+ (50, 20): ("#93e837", "C27"), # Metal4.mask
148
+ (50, 22): ("#93e837", "C27"), # Metal4.filler
149
+ (50, 23): ("#93e837", "I1"), # Metal4.nofill
150
+ (50, 24): ("#000000", "C18"), # Metal4.slit
151
+ (50, 25): ("#93e837", "C27"), # Metal4.text
152
+ (50, 26): ("#ffff00", "I1"), # Metal4.OPC
153
+ (50, 28): ("#ff0000", "C3"), # Metal4.noqrc
154
+ (50, 29): ("#bf4026", "C19"), # Metal4.res
155
+ (50, 33): ("#d80000", "I1"), # Metal4.iprobe
156
+ (50, 34): ("#d80000", "I1"), # Metal4.diffprb
157
+ (66, 0): ("#deac5e", "C28"), # Via4.drawing
158
+ (66, 3): ("#deac5e", "C28"), # Via4.net
159
+ (66, 4): ("#deac5e", "C28"), # Via4.boundary
160
+ (67, 0): ("#dcd146", "C29"), # Metal5.drawing
161
+ (67, 1): ("#dcd146", "C29"), # Metal5.label
162
+ (67, 2): ("#dcd146", "C29"), # Metal5.pin
163
+ (67, 3): ("#dcd146", "C29"), # Metal5.net
164
+ (67, 4): ("#dcd146", "C29"), # Metal5.boundary
165
+ (67, 20): ("#dcd146", "C29"), # Metal5.mask
166
+ (67, 22): ("#dcd146", "C29"), # Metal5.filler
167
+ (67, 23): ("#dcd146", "I1"), # Metal5.nofill
168
+ (67, 24): ("#000000", "C18"), # Metal5.slit
169
+ (67, 25): ("#dcd146", "C29"), # Metal5.text
170
+ (67, 26): ("#ffff00", "I1"), # Metal5.OPC
171
+ (67, 28): ("#ff0000", "C3"), # Metal5.noqrc
172
+ (67, 29): ("#bf4026", "C19"), # Metal5.res
173
+ (67, 33): ("#dcd146", "I1"), # Metal5.iprobe
174
+ (67, 34): ("#dcd146", "I1"), # Metal5.diffprb
175
+ (125, 0): ("#ffe6bf", "C25"), # TopVia1.drawing
176
+ (125, 3): ("#ffe6bf", "C25"), # TopVia1.net
177
+ (125, 4): ("#ffe6bf", "I1"), # TopVia1.boundary
178
+ (126, 0): ("#ffe6bf", "C30"), # TopMetal1.drawing
179
+ (126, 1): ("#ffe6bf", "C30"), # TopMetal1.label
180
+ (126, 2): ("#ffe6bf", "C30"), # TopMetal1.pin
181
+ (126, 3): ("#ffe6bf", "C30"), # TopMetal1.net
182
+ (126, 4): ("#ffe6bf", "I1"), # TopMetal1.boundary
183
+ (126, 20): ("#ffe6bf", "C30"), # TopMetal1.mask
184
+ (126, 22): ("#ffe6bf", "C30"), # TopMetal1.filler
185
+ (126, 23): ("#ffe6bf", "I1"), # TopMetal1.nofill
186
+ (126, 24): ("#000000", "I1"), # TopMetal1.slit
187
+ (126, 25): ("#ffe6bf", "C0"), # TopMetal1.text
188
+ (126, 28): ("#ff0000", "C3"), # TopMetal1.noqrc
189
+ (126, 29): ("#bf4026", "C19"), # TopMetal1.res
190
+ (126, 33): ("#ffe6bf", "I1"), # TopMetal1.iprobe
191
+ (126, 34): ("#ffe6bf", "I1"), # TopMetal1.diffprb
192
+ (133, 0): ("#ff8000", "C31"), # TopVia2.drawing
193
+ (133, 3): ("#ff8000", "C31"), # TopVia2.net
194
+ (133, 4): ("#ff8000", "I1"), # TopVia2.boundary
195
+ (134, 0): ("#ff8000", "C32"), # TopMetal2.drawing
196
+ (134, 1): ("#ff8000", "C32"), # TopMetal2.label
197
+ (134, 2): ("#ff8000", "C32"), # TopMetal2.pin
198
+ (134, 3): ("#ff8000", "C32"), # TopMetal2.net
199
+ (134, 4): ("#ff8000", "I1"), # TopMetal2.boundary
200
+ (134, 20): ("#ff8000", "C32"), # TopMetal2.mask
201
+ (134, 22): ("#ff8000", "C1"), # TopMetal2.filler
202
+ (134, 23): ("#ff8000", "I1"), # TopMetal2.nofill
203
+ (134, 24): ("#000000", "I1"), # TopMetal2.slit
204
+ (134, 25): ("#ff8000", "C32"), # TopMetal2.text
205
+ (134, 28): ("#ff0000", "C3"), # TopMetal2.noqrc
206
+ (134, 29): ("#bf4026", "C19"), # TopMetal2.res
207
+ (134, 33): ("#ff8000", "I1"), # TopMetal2.iprobe
208
+ (134, 34): ("#ff8000", "I1"), # TopMetal2.diffprb
209
+ (9, 0): ("#e61f0d", "C3"), # Passiv.drawing
210
+ (9, 1): ("#e61f0d", "C3"), # Passiv.label
211
+ (9, 2): ("#e61f0d", "C3"), # Passiv.pin
212
+ (9, 3): ("#e61f0d", "C3"), # Passiv.net
213
+ (9, 4): ("#e61f0d", "C3"), # Passiv.boundary
214
+ (9, 35): ("#e61f0d", "C3"), # Passiv.pillar
215
+ (9, 36): ("#e61f0d", "C3"), # Passiv.sbump
216
+ (9, 40): ("#e61f0d", "C3"), # Passiv.pdl
217
+ (160, 0): ("#d9e6ff", "I1"), # NoMetFiller.drawing
218
+ (146, 0): ("#e61f0d", "C0"), # ThinFilmRes.drawing
219
+ (27, 0): ("#ffff00", "I1"), # IND.drawing
220
+ (27, 2): ("#ffff00", "C0"), # IND.pin
221
+ (27, 4): ("#ffff00", "I1"), # IND.boundary
222
+ (27, 25): ("#ffff00", "C0"), # IND.text
223
+ (39, 0): ("#5e00e6", "I1"), # EdgeSeal.drawing
224
+ (39, 4): ("#5e00e6", "I1"), # EdgeSeal.boundary
225
+ (41, 0): ("#5e00e6", "I1"), # dfpad.drawing
226
+ (41, 35): ("#5e00e6", "I1"), # dfpad.pillar
227
+ (41, 36): ("#5e00e6", "I1"), # dfpad.sbump
228
+ (63, 0): ("#ffffff", "I1"), # TEXT.drawing
229
+ (99, 0): ("#bdcccc", "C0"), # Recog.drawing
230
+ (99, 2): ("#bdcccc", "C0"), # Recog.pin
231
+ (99, 30): ("#ffff00", "I1"), # Recog.esd
232
+ (99, 31): ("#5e00e6", "I1"), # Recog.diode
233
+ (99, 32): ("#ffff00", "I1"), # Recog.tsv
234
+ (99, 33): ("#d9e6ff", "C0"), # Recog.iprobe
235
+ (99, 34): ("#d9e6ff", "C0"), # Recog.diffprb
236
+ (99, 35): ("#5e00e6", "I1"), # Recog.pillar
237
+ (99, 36): ("#5e00e6", "I1"), # Recog.sbump
238
+ (99, 37): ("#d9cc00", "I1"), # Recog.otp
239
+ (99, 38): ("#ffff00", "I1"), # Recog.pdiode
240
+ (99, 39): ("#268c6b", "C0"), # Recog.mom
241
+ (99, 100): ("#ffffcc", "I1"), # Recog.pcm
242
+ (16, 0): ("#ff0000", "C11"), # DigiBnd.drawing
243
+ (16, 10): ("#ff0000", "C11"), # DigiBnd.drawing0
244
+ (24, 0): ("#bf4026", "C19"), # RES.drawing
245
+ (24, 1): ("#bf4026", "C0"), # RES.label
246
+ (25, 0): ("#ffff00", "C2"), # SRAM.drawing
247
+ (25, 1): ("#ffff00", "C3"), # SRAM.label
248
+ (25, 4): ("#ffff00", "I1"), # SRAM.boundary
249
+ (26, 0): ("#00ffff", "C0"), # TRANS.drawing
250
+ (60, 0): ("#ffff00", "C11"), # DigiSub.drawing
251
+ (51, 0): ("#8c8ca6", "I1"), # HeatTrans.drawing
252
+ (52, 0): ("#8c8ca6", "I1"), # HeatRes.drawing
253
+ (148, 0): ("#ff0000", "C3"), # NoRCX.drawing
254
+ (148, 41): ("#ff0000", "C3"), # NoRCX.m2m3
255
+ (148, 42): ("#ff0000", "C3"), # NoRCX.m2m4
256
+ (148, 43): ("#ff0000", "C3"), # NoRCX.m2m5
257
+ (148, 44): ("#ff0000", "C3"), # NoRCX.m2tm1
258
+ (148, 45): ("#ff0000", "C3"), # NoRCX.m2tm2
259
+ (148, 46): ("#ff0000", "C3"), # NoRCX.m3m4
260
+ (148, 47): ("#ff0000", "C3"), # NoRCX.m3m5
261
+ (148, 48): ("#ff0000", "C3"), # NoRCX.m3tm1
262
+ (148, 49): ("#ff0000", "C3"), # NoRCX.m3tm2
263
+ (148, 50): ("#ff0000", "C3"), # NoRCX.m4m5
264
+ (148, 51): ("#ff0000", "C3"), # NoRCX.m4tm1
265
+ (148, 52): ("#ff0000", "C3"), # NoRCX.m4tm2
266
+ (148, 53): ("#ff0000", "C3"), # NoRCX.m5tm1
267
+ (148, 54): ("#ff0000", "C3"), # NoRCX.m5tm2
268
+ (148, 55): ("#ff0000", "C3"), # NoRCX.tm1tm2
269
+ (148, 123): ("#ff0000", "C3"), # NoRCX.m1sub
270
+ (148, 124): ("#ff0000", "C3"), # NoRCX.m2sub
271
+ (148, 125): ("#ff0000", "C3"), # NoRCX.m3sub
272
+ (148, 126): ("#ff0000", "C3"), # NoRCX.m4sub
273
+ (148, 127): ("#ff0000", "C3"), # NoRCX.m5sub
274
+ (148, 300): ("#ff0000", "C3"), # NoRCX.tm1sub
275
+ (148, 301): ("#ff0000", "C3"), # NoRCX.tm2sub
276
+ (3, 0): ("#268c6b", "C7"), # BiWind.drawing
277
+ (3, 26): ("#0000ff", "I1"), # BiWind.OPC
278
+ (13, 0): ("#bf4026", "C34"), # BasPoly.drawing
279
+ (13, 1): ("#bf4026", "C3"), # BasPoly.label
280
+ (13, 2): ("#bf4026", "C3"), # BasPoly.pin
281
+ (13, 3): ("#bf4026", "C35"), # BasPoly.net
282
+ (13, 4): ("#bf4026", "C3"), # BasPoly.boundary
283
+ (33, 0): ("#00cc66", "C3"), # EmWind.drawing
284
+ (33, 26): ("#ffff00", "I1"), # EmWind.OPC
285
+ (35, 0): ("#ff8000", "C3"), # DeepCo.drawing
286
+ (55, 0): ("#ffe6bf", "C3"), # EmPoly.drawing
287
+ (70, 0): ("#00cc66", "C3"), # Varicap.drawing
288
+ (90, 0): ("#00cc66", "C3"), # EmWind3.drawing
289
+ (91, 0): ("#00cc66", "C3"), # EmWiHV3.drawing
290
+ (101, 0): ("#d80000", "C36"), # ColOpen.drawing
291
+ (139, 0): ("#ff00ff", "C37"), # ColWind.drawing
292
+ (156, 0): ("#00cc66", "C3"), # EmWiHV.drawing
293
+ (152, 0): ("#ff8000", "I1"), # DeepVia.drawing
294
+ (157, 0): ("#ff00ff", "C8"), # LBE.drawing
295
+ (20, 0): ("#ffe6bf", "C30"), # BackMetal1.drawing
296
+ (20, 1): ("#ffe6bf", "C30"), # BackMetal1.label
297
+ (20, 2): ("#ffe6bf", "C30"), # BackMetal1.pin
298
+ (20, 3): ("#ffe6bf", "C30"), # BackMetal1.net
299
+ (20, 4): ("#ffe6bf", "I1"), # BackMetal1.boundary
300
+ (20, 20): ("#ffe6bf", "C30"), # BackMetal1.mask
301
+ (20, 22): ("#ffe6bf", "I1"), # BackMetal1.filler
302
+ (20, 23): ("#ffe6bf", "C30"), # BackMetal1.nofill
303
+ (20, 24): ("#ffe6bf", "C30"), # BackMetal1.slit
304
+ (20, 25): ("#39bfff", "C1"), # BackMetal1.text
305
+ (20, 26): ("#ffe6bf", "C30"), # BackMetal1.OPC
306
+ (20, 28): ("#ff0000", "C3"), # BackMetal1.noqrc
307
+ (20, 29): ("#bf4026", "C19"), # BackMetal1.res
308
+ (20, 33): ("#ffe6bf", "I1"), # BackMetal1.iprobe
309
+ (20, 34): ("#ffe6bf", "I1"), # BackMetal1.diffprb
310
+ (23, 0): ("#ffe6bf", "C30"), # BackPassiv.drawing
311
+ (72, 0): ("#268c6b", "C29"), # IntBondVia.drawing
312
+ (73, 0): ("#268c6b", "C29"), # IntBondMet.drawing
313
+ (74, 0): ("#5e00e6", "C30"), # DevBondVia.drawing
314
+ (75, 0): ("#5e00e6", "C30"), # DevBondMet.drawing
315
+ (76, 0): ("#ffffff", "C0"), # DevTrench.drawing
316
+ (77, 0): ("#ff00ff", "C0"), # Redist.drawing
317
+ (54, 0): ("#ffff00", "I1"), # FBE.drawing
318
+ (83, 0): ("#9900e6", "C38"), # AntVia1.drawing
319
+ (84, 0): ("#bf4026", "C39"), # AntMetal2.drawing
320
+ (132, 0): ("#9900e6", "C38"), # AntMetal1.drawing
321
+ (142, 0): ("#333399", "C0"), # FLM.drawing
322
+ (135, 0): ("#ff8000", "C7"), # SNSRing.drawing
323
+ (136, 0): ("#bdcccc", "C7"), # Sensor.drawing
324
+ (137, 0): ("#ff8000", "C7"), # SNSArms.drawing
325
+ (138, 0): ("#ff8000", "C7"), # SNSCMOSVia.drawing
326
+ (149, 0): ("#ccb899", "C40"), # SNSBotVia.drawing
327
+ (151, 0): ("#00ff00", "C40"), # SNSTopVia.drawing
328
+ (15, 0): ("#ffff00", "C0"), # NLDB.drawing
329
+ (45, 0): ("#ffff00", "C0"), # PLDB.drawing
330
+ (92, 0): ("#d9cc00", "C10"), # RedBuLay.drawing
331
+ (112, 0): ("#ffff00", "C41"), # NLDD.drawing
332
+ (113, 0): ("#ffff00", "C42"), # PLDD.drawing
333
+ (114, 0): ("#ffff00", "C43"), # NExt.drawing
334
+ (115, 0): ("#ffff00", "C44"), # PExt.drawing
335
+ (127, 0): ("#ffff00", "C41"), # INLDPWL.drawing
336
+ (131, 0): ("#ffff00", "C45"), # nBuLayCut.drawing
337
+ (78, 0): ("#9900e6", "C39"), # GraphBot.drawing
338
+ (79, 0): ("#ff00ff", "C46"), # GraphTop.drawing
339
+ (85, 0): ("#268c6b", "C29"), # GraphCont.drawing
340
+ (86, 0): ("#d80000", "C15"), # SiWG.drawing
341
+ (86, 22): ("#d80000", "C15"), # SiWG.filler
342
+ (86, 23): ("#d80000", "I1"), # SiWG.nofill
343
+ (87, 0): ("#8c8ca6", "C4"), # SiGrating.drawing
344
+ (88, 0): ("#008539", "C9"), # SiNGrating.drawing
345
+ (89, 0): ("#ff8000", "I1"), # GraphPas.drawing
346
+ (97, 0): ("#e61f0d", "C4"), # GraphPad.drawing
347
+ (109, 0): ("#00b300", "C29"), # GraphMetal1.drawing
348
+ (109, 22): ("#00b300", "C29"), # GraphMetal1.filler
349
+ (109, 23): ("#00b300", "I1"), # GraphMetal1.nofill
350
+ (109, 24): ("#00b300", "I1"), # GraphMetal1.slit
351
+ (109, 26): ("#00b300", "I1"), # GraphMetal1.OPC
352
+ (110, 0): ("#34b7ab", "C27"), # GraphMet1L.drawing
353
+ (110, 22): ("#34b7ab", "C27"), # GraphMet1L.filler
354
+ (110, 23): ("#34b7ab", "I1"), # GraphMet1L.nofill
355
+ (110, 24): ("#34b7ab", "I1"), # GraphMet1L.slit
356
+ (110, 26): ("#34b7ab", "I1"), # GraphMet1L.OPC
357
+ (118, 0): ("#ffff00", "C2"), # GraphGate.drawing
358
+ (119, 0): ("#ffffcc", "C15"), # SiNWG.drawing
359
+ (119, 22): ("#ffffcc", "C15"), # SiNWG.filler
360
+ (119, 23): ("#ffffcc", "I1"), # SiNWG.nofill
361
+ (46, 0): ("#ffff00", "C47"), # PWell.drawing
362
+ (46, 1): ("#ffff00", "C0"), # PWell.label
363
+ (46, 2): ("#ffff00", "C0"), # PWell.pin
364
+ (46, 3): ("#ffff00", "C47"), # PWell.net
365
+ (46, 4): ("#ffff00", "I1"), # PWell.boundary
366
+ (48, 0): ("#ffff00", "I1"), # IC.drawing
367
+ (62, 0): ("#ff0000", "C3"), # NoDRC.drawing
368
+ (68, 0): ("#ff76fb", "C0"), # RadHard.drawing
369
+ (69, 0): ("#ff00ff", "C48"), # MemCap.drawing
370
+ (93, 0): ("#ffff00", "C39"), # SMOS.drawing
371
+ (98, 0): ("#e61f0d", "C10"), # Polimide.drawing
372
+ (98, 1): ("#e61f0d", "C10"), # Polimide.label
373
+ (98, 2): ("#e61f0d", "C10"), # Polimide.pin
374
+ (98, 3): ("#e61f0d", "C10"), # Polimide.net
375
+ (111, 0): ("#5e00e6", "I1"), # EXTBlock.drawing
376
+ (116, 0): ("#ffff00", "C49"), # NExtHV.drawing
377
+ (117, 0): ("#ffff00", "C8"), # PExtHV.drawing
378
+ (124, 0): ("#ffff00", "C50"), # MEMPAD.drawing
379
+ (143, 0): ("#ff8000", "C7"), # HafniumOx.drawing
380
+ (145, 0): ("#d9cc00", "C0"), # MEMVia.drawing
381
+ (147, 0): ("#ff8000", "I1"), # RFMEM.drawing
382
+ (153, 0): ("#5e00e6", "C11"), # FGEtch.drawing
383
+ (154, 0): ("#ffffff", "C0"), # CtrGat.drawing
384
+ (155, 0): ("#d80000", "C0"), # FGImp.drawing
385
+ (159, 0): ("#ffffcc", "C0"), # AlCuStop.drawing
386
+ (189, 0): ("#9900e6", "I1"), # prBoundary.drawing
387
+ (189, 1): ("#9900e6", "I1"), # prBoundary.label
388
+ (189, 4): ("#9900e6", "I1"), # prBoundary.boundary
389
+ (190, 0): ("#00cc66", "C51"), # Exchange0.drawing
390
+ (190, 1): ("#00ff00", "C3"), # Exchange0.label
391
+ (190, 2): ("#00cc66", "C52"), # Exchange0.pin
392
+ (190, 25): ("#ccb899", "C3"), # Exchange0.text
393
+ (191, 0): ("#ffff00", "C42"), # Exchange1.drawing
394
+ (191, 1): ("#ffff00", "C3"), # Exchange1.label
395
+ (191, 2): ("#ffff00", "C52"), # Exchange1.pin
396
+ (191, 25): ("#00cc66", "C3"), # Exchange1.text
397
+ (192, 0): ("#ffbff2", "C43"), # Exchange2.drawing
398
+ (192, 1): ("#ffbff2", "C3"), # Exchange2.label
399
+ (192, 2): ("#ffbff2", "C52"), # Exchange2.pin
400
+ (192, 25): ("#ff76fb", "C3"), # Exchange2.text
401
+ (193, 0): ("#00ffff", "C44"), # Exchange3.drawing
402
+ (193, 1): ("#00ffff", "I1"), # Exchange3.label
403
+ (193, 2): ("#00ffff", "C53"), # Exchange3.pin
404
+ (193, 25): ("#ffba31", "C3"), # Exchange3.text
405
+ (194, 0): ("#ff8000", "C49"), # Exchange4.drawing
406
+ (194, 1): ("#ff8000", "I1"), # Exchange4.label
407
+ (194, 2): ("#ff8000", "C52"), # Exchange4.pin
408
+ (194, 25): ("#39bfff", "C3"), # Exchange4.text
409
+ (257, 0): ("#ff00ff", "I1"), # isoNWell.drawing
410
+ }
411
+
412
+ # Exact per-pattern bitmaps for every dither-pattern name used in sg13g2.lyp.
413
+ #
414
+ # KLayout ships this technology's dither-pattern definitions internally (not in
415
+ # the .lyp file itself), keyed by names like "I1" (built-in pattern) or "C23"
416
+ # (a further pattern beyond the built-in set). There's no public API to query
417
+ # them, so they were reverse-engineered empirically: a synthetic GDS with one
418
+ # swatch per pattern name was rendered through the real, installed KLayout
419
+ # (klayout_app.exe, batch mode) with sg13g2.lyp applied, then each swatch's
420
+ # minimal repeating tile was recovered from the rendered pixels (2D period
421
+ # detection, then majority-vote over all repeats to denoise anti-aliasing).
422
+ # Each value is a list of equal-length row strings; "*" = filled, "." = empty.
423
+ # A `None` value means the pattern renders with no fill at all (outline only) -
424
+ # used by several purpose layers (labels/pins/etc.) in this technology.
425
+ PATTERN_TILES = {
426
+ "C0": None,
427
+ "C1": ["........*.......", ".......*........", "......*.........", ".....*..........", "....*...........", "...*............", "..*.............", ".*..............", "*...............", "...............*", "..............*.", ".............*..", "............*...", "...........*....", "..........*.....", ".........*......"],
428
+ "C2": ["................", "*....*.......*..", ".........*......", "...*............", ".......*........", "................", "..............*.", "......*....*....", "..**............", "..........*.....", "...*.........*..", "...............*", "......*.........", "................", "..*......*......", "................"],
429
+ "C3": [".*.*", "..*.", ".*.*", "*..."],
430
+ "C4": ["...*....*.....*.", "....*....*....*.", "....*.....*....*", "*....*....*.....", "*.....*....*....", ".*....*.....*...", "..*....*....*...", "..*.....*....*.."],
431
+ "C5": ["...*", "....", ".*..", "...."],
432
+ "C6": ["*...*...*..**...", "................", "................", "................"],
433
+ "C7": ["......*.", "......*.", "........", ".*......", ".*......", ".*......", "****...*", ".*......", ".*......", ".*......", "........", "......*.", "......*.", "......*.", "*...****", "......*."],
434
+ "C8": ["................", "................", "................", "....*....*.....*", "*..*.*..*.*...*.", "....*....*.....*", "................", "....*...........", "....*....*.....*", "*..*.*..*.*...*.", "....*....*.....*", "................", "................", "....*....*.....*", "*..*.*..*.*...*.", "....*....*.....*"],
435
+ "C9": [".......*", "**......", "..*.....", "...**...", ".....*..", "......**", "*.......", ".**.....", "...*....", "....**..", "......*.", "*......*", ".*......", "..**....", "....*...", ".....**."],
436
+ "C10": [".*****..........", "*.....*.........", ".......*.......*", "........*.....*.", ".........*...*..", ".........*...*..", ".........*...*..", ".........*...*..", ".........*...*..", "........*.....*.", ".......*.......*", "*.....*.........", ".*****..........", "................", "................", "................"],
437
+ "C11": None,
438
+ "C12": ["................", ".*...........*.*", ".....*.*.*......", "................", "......*.*.*.....", "................", "................", "*.*...........*.", "................", ".*.*...........*", "................", "................", "......*.*.*.....", "................", ".......*.*.*....", "*...........*.*."],
439
+ "C13": ["..*.", "..*.", "..*.", "..*."],
440
+ "C14": [".*.*", "..*.", ".*.*", "*..."],
441
+ "C15": ["................", "........*.......", "................", "................", "....*..........*", "................", "..........*.....", "................", "................", ".........*......", "..............*.", "....*...........", "................", "................", "................", "*..............."],
442
+ "C16": ["...*...*........", "................", "................", "................", "................", ".........*....*.", "................", ".*..............", "................", "................", ".......*........", "................", "...............*", "................", "................", "................"],
443
+ "C17": ["......*.........", ".....*..........", "....*...........", "...*............", "..*.............", ".*..............", "*...............", "...............*", "..............*.", ".............*..", "............*...", "...........*....", "..........*.....", ".........*......", "........*.......", ".......*........"],
444
+ "C18": None,
445
+ "C19": ["..*..*..*..**..*", ".*..*..*..*...*.", "*..*..*..*...*..", "..*..*..*..**..*", ".*..*..*..*...*.", "*..*..*..*...*..", "..*..*..*..**..*", ".*..*..*..*...*.", "*..*..*..*...*..", "..*..*..*..**..*", "..*..*..*..**..*", ".*..*..*..*...*.", "*..*..*..*...*..", "..*..*..*..**..*", ".*..*..*..*...*.", "*..*..*..*...*.."],
446
+ "C20": [".............*..", "............*...", "...........*....", "..........*.....", ".........*......", "........*.......", ".......*........", "......*.........", ".....*..........", "....*...........", "...*............", "..*.............", ".*..............", "*...............", "...............*", "..............*."],
447
+ "C21": ["...............*", "..............*.", ".............*..", "............*...", "...........*....", "..........*.....", ".........*......", "........*.......", ".......*........", "......*.........", ".....*..........", "....*...........", "...*............", "..*.............", ".*..............", "*..............."],
448
+ "C22": ["..............*.", "...............*", "*...............", ".*..............", "..*.............", "...*............", "....*...........", ".....*..........", "......*.........", ".......*........", "........*.......", ".........*......", "..........*.....", "...........*....", "............*...", ".............*.."],
449
+ "C23": ["..........*.....", "...........*....", "............*...", ".............*..", "..............*.", "...............*", "*...............", ".*..............", "..*.............", "...*............", "....*...........", ".....*..........", "......*.........", ".......*........", "........*.......", ".........*......"],
450
+ "C24": ["*..***..*..***..", "...*.*...*.....*", ".***.***..*...*.", ".*.....*...*.*..", "**..*..***..*..*", "...*.*...*.....*", "..*...*..***.***", ".*.....*...*.*.."],
451
+ "C25": ["...........*....", "............*...", ".............*..", "..............*.", "...............*", "*...............", ".*..............", "..*.............", "...*............", "....*...........", ".....*..........", "......*.........", ".......*........", "........*.......", ".........*......", "..........*....."],
452
+ "C26": ["....*...........", ".....*..........", "......*.........", ".......*........", "........*.......", ".........*......", "..........*.....", "...........*....", "............*...", ".............*..", "..............*.", "...............*", "*...............", ".*..............", "..*.............", "...*............"],
453
+ "C27": ["*...............", ".*..............", "..*.............", "...*............", "....*...........", ".....*..........", "......*.........", ".......*........", "........*.......", ".........*......", "..........*.....", "...........*....", "............*...", ".............*..", "..............*.", "...............*"],
454
+ "C28": [".........*......", "........*.......", ".......*........", "......*.........", ".....*..........", "....*...........", "...*............", "..*.............", ".*..............", "*...............", "...............*", "..............*.", ".............*..", "............*...", "...........*....", "..........*....."],
455
+ "C29": [".............*..", "............*...", "...........*....", "..........*.....", ".........*......", "........*.......", ".......*........", "......*.........", ".....*..........", "....*...........", "...*............", "..*.............", ".*..............", "*...............", "...............*", "..............*."],
456
+ "C30": ["....*...........", ".....*..........", "......*.........", ".......*........", "........*.......", ".........*......", "..........*.....", "...........*....", "............*...", ".............*..", "..............*.", "...............*", "*...............", ".*..............", "..*.............", "...*............"],
457
+ "C31": [".........*......", "..........*.....", "...........*....", "............*...", ".............*..", "..............*.", "...............*", "*...............", ".*..............", "..*.............", "...*............", "....*...........", ".....*..........", "......*.........", ".......*........", "........*......."],
458
+ "C32": [".....*..........", "......*.........", ".......*........", "........*.......", ".........*......", "..........*.....", "...........*....", "............*...", ".............*..", "..............*.", "...............*", "*...............", ".*..............", "..*.............", "...*............", "....*..........."],
459
+ "C34": [".*.....*........", "*.....*.........", ".....*.....*...*", "....*.....*...*.", "...*.....*...*..", "..*.....*...*...", ".*.....*........", "*.....*.........", ".....*.....*...*", "....*.....*...*.", "...*.....*...*..", "..*.....*...*...", ".*.....*........", "*.....*.........", ".....*.....*...*", "....*.....*...*."],
460
+ "C35": ["*...", "....", "..*.", "...."],
461
+ "C36": ["*...", "....", "..*.", "...."],
462
+ "C37": [".*....*...*.....", ".......*........", ".............*..", "................", ".*...*..........", ".......*..*.....", "..............*.", "....*........*..", "..*........*....", ".*..............", "........*.....*.", "*...............", "....*...........", "......*.........", "................", "..............*."],
463
+ "C38": ["*...............", ".*..............", "..*.............", "...*............", "....*...........", ".....*..........", "......*.........", ".......*........", "........*.......", ".........*......", "..........*.....", "...........*....", "............*...", ".............*..", "..............*.", "...............*"],
464
+ "C39": [".......*", "*.......", ".*......", "..*.....", "...*....", "....*...", ".....*..", "......*."],
465
+ "C40": ["................", "................", ".......*.......*", ".......*.......*", ".......*.......*", ".......*.......*", ".......*.......*", ".......*.......*", "...*...*.......*", "...*...*.......*", "...*............", "...*............", "...*............", "...*............", "...*............", "...*............"],
466
+ "C41": ["................", "................", ".........*.....*", "................", "..*...*.........", "..*...*.........", "................", "..............*.", ".........*......", "................", "................", "...........**...", "................", "...*............", "................", "...........**..."],
467
+ "C42": ["....*..*........", "*...............", "................", "................", "*..*............", "................", "................", "................", "......*......*..", "................", "................", "*.....*..*...*..", "................", "....*...........", "................", "................"],
468
+ "C43": [".............*..", "........*.......", "................", "*...............", "....*...........", "................", "...........**...", "................", ".........*......", "................", "...*..........*.", "................", "......*...*.....", "................", "..*.............", "................"],
469
+ "C44": ["....*...........", ".........*......", "................", "................", "................", ".............*..", "................", "................", "................", "................", "..........*.....", "................", "................", "................", "..............*.", "................"],
470
+ "C45": ["................", "................", "................", ".......*........", "......*.*.......", ".....*...*......", "....*.....*.....", "...*********....", "................", "................", "................", "*...............", ".*.............*", "..*...........*.", "...*.........*..", "*****.......****"],
471
+ "C46": [".......*", "......*.", ".....*..", "....*...", "...*....", "..*.....", ".*......", "*......."],
472
+ "C47": ["....", "...*", "....", ".*.."],
473
+ "C48": ["..*.............", ".*..............", "*...............", "...............*", "..............*.", ".............*..", "............*...", "...........*....", "..........*.....", ".........*......", "........*.......", ".......*........", "......*.........", ".....*..........", "....*...........", "...*............"],
474
+ "C49": ["*.........*.....", "..............*.", ".........*......", "...*..........*.", "................", "................", "..*.....*.......", "..............*.", "................", "....*...........", "............*...", "........*.......", "..............*.", "..*.............", "................", ".....*.........."],
475
+ "C50": [".*", ".*", ".*", ".*", "*.", "*.", "*.", "*."],
476
+ "C51": ["........*.......", "....*.........*.", ".*.......*......", "................", ".......*...*...*", "................", "......*..*...*..", "...*............", "...........*...*", ".............*..", ".*..*...........", ".........*....*.", "...*............", "....*...*......*", "................", "................"],
477
+ "C52": ["*......*", "*......*", ".*....*.", "..*..*..", "...**...", "...**...", "..*..*..", ".*....*."],
478
+ "C53": ["...**...", "...**...", "..*..*..", ".*....*.", "*......*", "*......*", ".*....*.", "..*..*.."],
479
+ "I1": None,
480
+ }
481
+
482
+ DEFAULT_COLOR = "#a0a0a0"
483
+ DEFAULT_PATTERN = None # solid, for any layer/datatype not in sg13g2.lyp
484
+ FULL_DEPTH = 32 # expand all reference levels instead of drawing name-labeled boxes
485
+ OUTLINE_LINEWIDTH = 0.5 # --screenshot: polygon outline width, in points
486
+
487
+ # For the interactive GUI: gdspy's Tkinter viewer only supports 10 built-in fill
488
+ # patterns (indices 0-9: 0/1/2 dense hatches, 3/4/6 sparser line/cross hatches,
489
+ # 5 dense cross-hatch, 7 sparse dots, 8 solid, 9 invisible/no-fill), so the exact
490
+ # PATTERN_TILES bitmaps can't be used there directly. Each pattern name is instead
491
+ # mapped to whichever of those 10 gdspy patterns is the closest visual match, by
492
+ # comparing pixel density and hatch/grid orientation against PATTERN_TILES.
493
+ PATTERN_TO_GDSPY_INDEX = {
494
+ "C0": 9,
495
+ "C1": 2,
496
+ "C2": 3,
497
+ "C3": 5,
498
+ "C4": 6,
499
+ "C5": 6,
500
+ "C6": 3,
501
+ "C7": 6,
502
+ "C8": 6,
503
+ "C9": 6,
504
+ "C10": 6,
505
+ "C11": 9,
506
+ "C12": 6,
507
+ "C13": 4,
508
+ "C14": 5,
509
+ "C15": 2,
510
+ "C16": 2,
511
+ "C17": 2,
512
+ "C18": 9,
513
+ "C19": 2,
514
+ "C20": 2,
515
+ "C21": 2,
516
+ "C22": 1,
517
+ "C23": 1,
518
+ "C24": 5,
519
+ "C25": 1,
520
+ "C26": 1,
521
+ "C27": 1,
522
+ "C28": 2,
523
+ "C29": 2,
524
+ "C30": 1,
525
+ "C31": 1,
526
+ "C32": 1,
527
+ "C34": 2,
528
+ "C35": 6,
529
+ "C36": 6,
530
+ "C37": 6,
531
+ "C38": 1,
532
+ "C39": 1,
533
+ "C40": 4,
534
+ "C41": 3,
535
+ "C42": 2,
536
+ "C43": 1,
537
+ "C44": 2,
538
+ "C45": 3,
539
+ "C46": 2,
540
+ "C47": 6,
541
+ "C48": 2,
542
+ "C49": 3,
543
+ "C50": 5,
544
+ "C51": 6,
545
+ "C52": 6,
546
+ "C53": 6,
547
+ "I1": 9,
548
+ }
549
+ DEFAULT_GDSPY_PATTERN = 8 # solid
550
+
551
+ # Purpose (datatype) numbers to hide from both the GUI and --screenshot, across
552
+ # every layer. Verified against LAYER_STYLES above (derived straight from
553
+ # sg13g2.lyp) rather than trusted by name alone: sibling repo gds_prepare_for_EM
554
+ # lists these same 4 purposes as [20, 22, 23, 32], but per the real .lyp, 20 is
555
+ # "mask" and 32 is a layer number (nBuLay), not a purpose - noqrc is actually 28
556
+ # and block is actually 21. The set below uses the .lyp-verified numbers.
557
+ HIDDEN_DATATYPES = {21, 22, 23, 28} # block, filler, nofill, noqrc
558
+
559
+
560
+ def pick_cell(lib, cellname):
561
+ if cellname is not None:
562
+ try:
563
+ return lib.cells[cellname]
564
+ except KeyError:
565
+ names = ", ".join(sorted(lib.cells))
566
+ sys.exit(f"Cell '{cellname}' not found. Available cells: {names}")
567
+ top_cells = lib.top_level()
568
+ if not top_cells:
569
+ sys.exit("No top-level cell found in this GDS file.")
570
+ return top_cells[0]
571
+
572
+
573
+ def render_screenshot(cell, output_path, background="#000000", width_px=None, labels=None,
574
+ outline_layers=None):
575
+ """Render the cell's full geometry (no GUI window needed) and save it as PNG.
576
+
577
+ Uses the exact PATTERN_TILES bitmaps (not gdspy's 10-pattern GUI palette),
578
+ so this is a pixel-accurate reproduction of sg13g2.lyp's fill patterns.
579
+
580
+ output_path: file name or binary file object.
581
+ width_px: image width in pixels (default 2400).
582
+ labels: optional list of (x, y, text) in layout coordinates, drawn on top
583
+ with a marker, e.g. to show port locations.
584
+ outline_layers: optional set of layer numbers drawn as outlines only, e.g.
585
+ helper layers without SG13G2 style that would otherwise hide other layers.
586
+ """
587
+ import matplotlib
588
+
589
+ matplotlib.use("Agg")
590
+ import matplotlib.pyplot as plt
591
+ import numpy as np
592
+ from matplotlib.path import Path
593
+ from matplotlib.patches import PathPatch
594
+
595
+ polygons_by_spec = cell.get_polygons(by_spec=True, depth=FULL_DEPTH)
596
+
597
+ (x0, y0), (x1, y1) = cell.get_bounding_box()
598
+ width, height = x1 - x0, y1 - y0
599
+ fig_width = 12.0
600
+ fig_height = max(4.0, min(20.0, fig_width * height / width))
601
+ dpi = 200 if width_px is None else width_px / fig_width
602
+
603
+ fig, ax = plt.subplots(figsize=(fig_width, fig_height), facecolor=background)
604
+ ax.set_facecolor(background)
605
+
606
+ # Texture resolution matched to the final output resolution (not a fixed
607
+ # px/um): a fixed density blows up to a huge array for PCB-scale designs
608
+ # (millimeters, not microns) and wastes memory on chip-scale ones.
609
+ px_per_um = (fig_width * dpi) / width
610
+
611
+ # Draw in the same order sg13g2.lyp lists its layers, so layers stack the same
612
+ # way they do in KLayout, instead of gdspy's arbitrary GDS-stream element order.
613
+ ordered_keys = [k for k in LAYER_STYLES if k in polygons_by_spec]
614
+ ordered_keys += [k for k in polygons_by_spec if k not in LAYER_STYLES]
615
+
616
+ for key in ordered_keys:
617
+ if key[1] in HIDDEN_DATATYPES:
618
+ continue
619
+ polygons = polygons_by_spec[key]
620
+ color, pattern_name = LAYER_STYLES.get(key, (DEFAULT_COLOR, DEFAULT_PATTERN))
621
+ compound_path = Path.make_compound_path(*(Path(p) for p in polygons))
622
+
623
+ tile_rows = PATTERN_TILES.get(pattern_name) if pattern_name else None
624
+ if pattern_name is not None and tile_rows is None and pattern_name in PATTERN_TILES:
625
+ # A pattern that resolves to "no fill" (e.g. label/pin outline layers).
626
+ ax.add_patch(
627
+ PathPatch(
628
+ compound_path,
629
+ facecolor="none",
630
+ edgecolor=color,
631
+ linewidth=OUTLINE_LINEWIDTH,
632
+ linestyle="solid",
633
+ )
634
+ )
635
+ continue
636
+
637
+ if key[0] in (outline_layers or ()):
638
+ ax.add_patch(
639
+ PathPatch(
640
+ compound_path,
641
+ facecolor="none",
642
+ edgecolor=color,
643
+ linewidth=OUTLINE_LINEWIDTH * 2,
644
+ linestyle="solid",
645
+ )
646
+ )
647
+ continue
648
+
649
+ if tile_rows is None:
650
+ # DEFAULT_PATTERN (unknown layer) -> plain solid fill.
651
+ ax.add_patch(
652
+ PathPatch(
653
+ compound_path,
654
+ facecolor=color,
655
+ edgecolor=color,
656
+ linewidth=OUTLINE_LINEWIDTH,
657
+ linestyle="solid",
658
+ )
659
+ )
660
+ continue
661
+
662
+ tile = np.array([[c == "*" for c in row] for row in tile_rows], dtype=bool)
663
+ th, tw = tile.shape
664
+ rgb = tuple(int(color[i : i + 2], 16) for i in (1, 3, 5))
665
+ rgba_tile = np.zeros((th, tw, 4), dtype=np.uint8)
666
+ rgba_tile[tile] = (*rgb, 255)
667
+
668
+ verts = compound_path.vertices
669
+ bx0, by0 = verts.min(axis=0)
670
+ bx1, by1 = verts.max(axis=0)
671
+ out_w = max(1, int((bx1 - bx0) * px_per_um))
672
+ out_h = max(1, int((by1 - by0) * px_per_um))
673
+ reps_x = out_w // tw + 2
674
+ reps_y = out_h // th + 2
675
+ big = np.tile(rgba_tile, (reps_y, reps_x, 1))[:out_h, :out_w]
676
+
677
+ im = ax.imshow(
678
+ big,
679
+ extent=(bx0, bx0 + out_w / px_per_um, by0, by0 + out_h / px_per_um),
680
+ origin="upper",
681
+ interpolation="nearest",
682
+ )
683
+ im.set_clip_path(PathPatch(compound_path, transform=ax.transData))
684
+ ax.add_patch(
685
+ PathPatch(
686
+ compound_path,
687
+ facecolor="none",
688
+ edgecolor=color,
689
+ linewidth=OUTLINE_LINEWIDTH,
690
+ linestyle="solid",
691
+ )
692
+ )
693
+
694
+ import matplotlib.patheffects as patheffects
695
+
696
+ outline = [patheffects.withStroke(linewidth=3, foreground="black")]
697
+ for x, y, text in labels or []:
698
+ ax.plot(x, y, marker="o", markersize=7, markerfacecolor="none", markeredgecolor="white",
699
+ markeredgewidth=1.5, path_effects=outline)
700
+ ax.annotate(text, (x, y), xytext=(6, 6), textcoords="offset points", color="white",
701
+ fontsize=13, fontweight="bold", path_effects=outline)
702
+
703
+ ax.set_xlim(x0, x1)
704
+ ax.set_ylim(y0, y1)
705
+ ax.set_aspect("equal")
706
+ ax.axis("off")
707
+ fig.tight_layout(pad=0)
708
+ fig.savefig(output_path, facecolor=background, dpi=dpi)
709
+ plt.close(fig)
710
+
711
+
712
+ def main():
713
+ parser = argparse.ArgumentParser(
714
+ description="View a GDSII layout with IHP SG13G2 (sg13g2.lyp) layer colors."
715
+ )
716
+ parser.add_argument("gds_file", help="input GDSII file")
717
+ parser.add_argument(
718
+ "--cellname", help="cell to display (default: first top-level cell)"
719
+ )
720
+ parser.add_argument(
721
+ "--screenshot",
722
+ metavar="FILE.png",
723
+ help="save the layout as a PNG to FILE.png instead of opening the GUI",
724
+ )
725
+ parser.add_argument(
726
+ "--width", type=int, default=None, metavar="PIXELS",
727
+ help="width of the --screenshot PNG in pixels (default 2400)",
728
+ )
729
+ parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
730
+ args = parser.parse_args()
731
+
732
+ lib = gdspy.GdsLibrary(infile=args.gds_file)
733
+ cell = pick_cell(lib, args.cellname)
734
+ print(f"Displaying cell '{cell.name}' from {args.gds_file}")
735
+
736
+ if args.screenshot:
737
+ render_screenshot(cell, args.screenshot, width_px=args.width)
738
+ print(f"Saved screenshot to {args.screenshot}")
739
+ return
740
+
741
+ colors = {"default": DEFAULT_COLOR}
742
+ patterns = {"default": DEFAULT_GDSPY_PATTERN}
743
+ for key, (color, pattern_name) in LAYER_STYLES.items():
744
+ colors[key] = color
745
+ patterns[key] = PATTERN_TO_GDSPY_INDEX.get(pattern_name, DEFAULT_GDSPY_PATTERN)
746
+ hidden = [key for key in LAYER_STYLES if key[1] in HIDDEN_DATATYPES]
747
+
748
+ gdspy.LayoutViewer(
749
+ cells=[cell],
750
+ color=colors,
751
+ pattern=patterns,
752
+ hidden_types=hidden,
753
+ background="#000000",
754
+ depth=FULL_DEPTH,
755
+ )
756
+
757
+
758
+ if __name__ == "__main__":
759
+ main()
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=65", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "gds_viewer"
7
+ dynamic = ["version"]
8
+ description = "GDSII viewer and headless PNG export with IHP SG13G2 layer colors and fill patterns"
9
+ authors = [
10
+ { name = "Volker Muehlhaus", email = "volker@muehlhaus.com" }
11
+ ]
12
+ license = "Apache-2.0"
13
+ readme = "README.md"
14
+ requires-python = ">=3.9"
15
+ dependencies = [
16
+ "gdspy>1.6.0",
17
+ "matplotlib",
18
+ "numpy",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/VolkerMuehlhaus/gds_viewer"
23
+
24
+ [project.scripts]
25
+ gds_viewer = "gds_viewer:main"
26
+
27
+ [tool.setuptools]
28
+ py-modules = ["gds_viewer"]
29
+
30
+ [tool.setuptools.dynamic]
31
+ version = {attr = "gds_viewer.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+