a python script to import a 3D structure from klayout. Help Needed

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
wsteffe
Posts: 461
Joined: Thu Aug 21, 2014 8:17 pm

a python script to import a 3D structure from klayout. Help Needed

Post by wsteffe »

Hello all,
I am reposting here the same topic posted on https://github.com/realthunder/FreeCAD/issues/422.
I would lika to have a script to convert a layout (made with klayout) into a FC document.
Here annexed a first version of this script but I need help to go on with the development.

Usage: layout2fc.py -stack stack_file dxf_file

The document generated by klayout consists of a dxf file (containing several layers) and a stackup definition.
The latter is formatted with following colums:
layerNum/LayerDataType : zstart zstop #user layer name (not parsed)

Here is an example of stack_file:

scale: 0.001 0
10/0: 0.0 70.0 # TR
4/0: 70.0 71.0 # N1
6/0: 70.0 71.0 # RM
16/0: 70.0 71.0 # RHWH
5/0: 71.0 71.19 # DPC
40/0: 71.19 74.19 # EL
40/2: 74.19 77.19 # EL2
40/1: 77.19 80.19 # EL1:

This format is identical to the Z stack section of the tecnology file generated by klayout (Tools/Manage Technology/...)
But, to be used by my script, these data must be separated in a new file with extension ".stack"
The scale entry was added by me (not present in the klayout technology file) to handle the conversion from micron (unit used in klayout) to mm (unit used in FC).

The script is already able to generate a 3D structure but there are some problems:

1) Generated objects are not visible in the opened FC document. Visibility can be toggled on manually but it is nasty because, typically, a PCB struture may hold many thousends of objects. I do not like to use Select All because I do not want to make visible sketches that are childs of pads.
Ideally I would like to make visible all objects with Visibility=True set on 91 and 112 of annexed script:

Code: Select all

91: body.Visibility = True
112: pad.Visibility =True
Would it possible to do that with a macro?

2) When I open the generated document I get a lot of error messages like:

Code: Select all

0.000354148 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.Y_Axis. not found
0.00052545 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.Z_Axis. not found
0.000678069 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.XY_Plane. not found
0.000830951 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.XZ_Plane. not found
0.00097343 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.YZ_Plane. not found
0.0124574 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#TR.X_Axis001. not found
0.0126192 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#TR.Y_Axis001. not found
I think that some reference system/axis used in pads (or in sketches) have been lost. Any idea ?

If somebody would like to help on this he should install klayout (on ubuntu/debian using "klayout_0.27.9-1_amd64.deb") and draw a test layout.
The recommanded FC branch is LinkDaily because there are many things on each layer. The script puts all these things in a single body (named as the layer). Unfortunately the one solid per body limitation of master prevents its usage in this application.
Attachments
layout2fc.py.zip
(1.37 KiB) Downloaded 15 times
User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: a python script to import a 3D structure from klayout. Help Needed

Post by johnwang »

wsteffe wrote: Mon May 23, 2022 8:21 am If somebody would like to help on this he should install klayout
You can provide one test file, so he doesn't need to install klayout.
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
wsteffe
Posts: 461
Joined: Thu Aug 21, 2014 8:17 pm

Re: a python script to import a 3D structure from klayout. Help Needed

Post by wsteffe »

johnwang wrote: Mon May 23, 2022 9:31 am You can provide one test file, so he doesn't need to install klayout.
Yes I will prepare one. I can not send that one I am using because it is derived from a MMIC design property of Thales which can not be shared.
Last edited by wsteffe on Mon May 23, 2022 10:25 am, edited 1 time in total.
wsteffe
Posts: 461
Joined: Thu Aug 21, 2014 8:17 pm

Re: a python script to import a 3D structure from klayout. Help Needed

Post by wsteffe »

You may use the here annexed "test_case.dxf".
For the stack file please put the following lines:
scale: 0.001 0
10/0: 0.0 70.0 # TR
4/0: 70.0 71.0 # N1
6/0: 70.0 71.0 # RM
16/0: 70.0 71.0 # RHWH
5/0: 71.0 71.19 # DPC
40/0: 71.19 74.19 # EL
40/2: 74.19 77.19 # EL2
40/1: 77.19 80.19 # EL1:
into a file with extension .stack.

Thanks for looking into it.
Attachments
test_case.dxf
(11.82 KiB) Downloaded 14 times
wsteffe
Posts: 461
Joined: Thu Aug 21, 2014 8:17 pm

Re: a python script to import a 3D structure from klayout. Help Needed

Post by wsteffe »

Please take notice that, before using the script, FC Import Preferences must be set as explained by RealThunder in the thread https://github.com/realthunder/FreeCAD/issues/419.
Beside that dxf scaling must be set to the same value as that one applied to the stack.
Scaling is 0.001 in my example because the layout lenghth unit is supposed to be micron while the FC unit is supposed to be mm.
For the script tests you may remove the scaling in both places: remove first line in the stack file and set scaling to 1(default) in Import preferences.
wsteffe
Posts: 461
Joined: Thu Aug 21, 2014 8:17 pm

Re: a python script to import a 3D structure from klayout. Help Needed

Post by wsteffe »

I have just discovered that the errors:

Code: Select all

0.000354148 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.Y_Axis. not found
0.00052545 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.Z_Axis. not found
0.000678069 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.XY_Plane. not found
0.000830951 Selection.cpp(1964): Sub-object Stage_1_2_3_LNA_layout_EM#DPC.XZ_Plane. not found
do not depend on my script and probably are the result of a FC BUG (at least in the LinkDaily Branch).
In fact I have osserved that the same kind of error is generated with any other document created by me in FC
(without using this script) when I am using the "Select All" command.
Post Reply