It looks like you're new here. If you want to get involved, click one of these buttons!
i have a code to convert file dxf to png.
layout = db.Layout()
layout.read(input_dxf_file)
layout_view = lay.LayoutView()
layout_view.show_layout(layout, False)
layout_view.set_config("grid-visible", "false")
layout_view.set_config("background-color", "#FFFFFF")
layout_view.set_config("child-context-color", "#000000")
layout_view.set_config("no-stipple", "true")
layout_view.max_hier()
top_cell = layout.cell(0)
layout_view.active_cellview().cell = top_cell
for lyp in layout_view.each_layer():
if lyp.layer_index() == 1:
lyp.frame_color = blue
box = top_cell.bbox()
layout_view.save_image_with_options(output_dxf_file, box.width()//10, box.height()/10)
my output is:
my expected output is:
Could you give me an idea. Thanks a lot
Comments
Hi hieund,
Here's an example of how to remove cut lines and only show border lines.
This script is to split the holes in every polygons into separate shape and insert them back into the same layer.
@RawrRanger Thank for your help but i try in this file but it not working
Hi hieund,
I've revised the example, the majot different is to flatten the top cell before dumpping shape to region.
Hi Mr RawrRanger,
Im thanks a lot for your support and guidance and I really appreciate it.
But i see a abnormal about image convert, there are maybe missing some box
It doesn't like my expected result.
So, Is this a limitation of the klayout library ?
Because, I try to convert but i get the same result like you ( ~ missing some box):
Thanks you so much ....
Hi hieund,
This version extracts out lines from every shapes and removes the cut lines.
This approach cannot determine which area is Cu traces and which is spacing
so I cannot hight light the Cu spacing region with another color.
another difference is the rect shapes in the layout, this will be preserved unless addidional shape filter is applied.
here's the result:
Thanks a lot Mr @RawrRanger,
Could I answer one more question ?
How can I fill black color for all holes and hulls like that in your example code:
Thanks and best regard.
Hieund
Hi hieund,
Following script kind of work for this particular layout, due to the soruce data have alot of stacked polygons,
If the source pattern stacking rule changes, this code will not work.
The process is to dump all shapes into region, and use this line to process the holes.
result = region.merged() - (region.merged().holes() & region.merged(2).holes())
This hard coded to remove shapes that in side a loop shape of stacked polygon.
and the criteria for stacked polygon is the shape stacked twice.
For color filling, I changed background into black and fill the layer into solid white to match the color theme.
@RawrRanger thanks a lot for your supported and I really appreciated that.
About how this line works.
result = region.merged() - (region.merged().holes() & region.merged(2).holes())
Hi @RawrRanger, Thanks for the nice scripts, they are impressive!
Hi @hieund,
In my opinion, this is a limitation not only of KLayout, but of any commercial CAD tool.
The reason lies in your original design itself.
Let me explain this case by case.
Case-1: AutoCAD and QCad comparison of the original design
As shown below, they disagree. To me, both are wrong.
Let's close to a specific location selected by KLayout.
In fact, there are three polygons involved here; green, yellow, and pink.
This creates a kind of three-body problem.
That is,
in what order and with what polarity (dark or clear) should each polygon be plotted?
The potential ambiguity in the design causes the different (unexpected) results.
A few years ago, I was faced with the exact same problem that a young engineer in my company had designed.
The dialogue between us went something like this.
Me: What were you going to do? Your design will cause a problem in a mask shop after the tape out.
He: I was trying to create an alignment mark made from two polygons (green and yellow) with the same polarity.
Me: OK! Then why pink?.
He: I was taught this by a senior tutor when I was a trainee.
By adding this (pink) polygon, the design looks like the final mask pattern in my CAD.
Me: Hmmm
Do you understand that a DXF file is basically a set of lines?
And there is no concept of
inside
andoutside
? (*)He: No, sir.
Me: That CAD is not suitable for designing a photomask.
Do you think you can convince your boss to change the CAD system?
He: Never, sir!!!
(*) https://github.com/KLayout/klayout/issues/243#issuecomment-475077326
Case-2: AutoCAD and QCad comparison of the design without pink
They agree, as shown below. This is the case my young guy wanted.
Case-3: AutoCAD and QCad comparison of the design without pink and yellow
They also agree, as shown below. This is the case
you
wanted.Summary
I've attached relevant files.
Best regards,
Kazzz-S
Hi Kazzz-S
Thanks for the explanation, matching the output from DXF format is always a guessing game,
Shape filtering with conditions only works for certain layout and often breaks if encounter complex cases.
Dear all,
thanks for this impressive discussion!
@sekigawa's explanation exactly hits the point. DXF does not specify filled polygons. Instead it specifies the boundaries and it is up the the consumer to decide what is inside and outside.
KLayout applies the even-odd rule. So closed contours form some "inside" and every point that is inside an odd number of contours is "filled" while points that are inside an even number of contours is not. In the cases I know this leads to the correct results. KLayout has some options to handle the formation of contours, specifically how to stitch contours from edges with small mismatches. Playing with the options my give better results, but still there is room for interpretation.
Matthias