how to check if every entity/polyline on your drawing is closed? and strange behaviour of creating polylines

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

how to check if every entity/polyline on your drawing is closed? and strange behaviour of creating polylines

tetukowski
Hi all,

In the application for photolithography, I have learned that every polyline has to be "closed".
To create a polyline I use the "Create Polyline from Segments" button.

For the reason that I still don't understand,
I found a polyline that is not closed, even though it appears as a closed object (if you select the object you can only select it as a single object, not as separate lines).
I also found if I repeat the "Create Polyline from Segments" button on the same object, the status of closed is sometimes changing.
Is it supposed to be like that?

Currently, I use the button `properties` --> select object --> see if the "closed" is checked or not.
But this is troublesome since for each drawing I can have thousands of objects.

Is there any way to check the "closed" status for the whole drawing automatically?

By the way, I hope there will be LibreCAD 3 (or any update) in the future.

Thank you!



   
Reply | Threaded
Open this post in threaded view
|

Re: how to check if every entity/polyline on your drawing is closed? and strange behaviour of creating polylines

LordOfBikes
Administrator
Sadly there is no better way than the properties dialog, as you already described.

You probably can use the List entities plugin.
Select all entities and use the plugin will give you a list with all entities, where you can also see the closed property.
But there is no way to bulk-change this. And it will be hard to identify listed polylines to modify them.

For explanation:
When you create a new polyline using the Polyline tools, there is a button in the tool option bar to close the polyline. This button sets the closed property for the polyline and close it.
On the other hand you can use snapping and finish the polyline on the starting vertex. This results also in a visually closed polyline, but the closed property is not set.
You can check this with the List plugin too. Create two polyline rectangles, both cases as described.
One U shaped with the close button and one with snap on starting point.
Then look at them in the List plugin.
The closed polyline has only 4 vertices, where the first and last one are not identical. These 4 vertices create 3 lines and the closed flag creates the 4th line between the first and last vertex.
The other one has 5 vertices and the first and last one are the same. These 5 vertices create 4 lines and a closed shape too.

The DXF reference is not detailed about the closed flag, so it leaves room for interpretation.
- The interpretation of LibreCAD is, that a polyline, with closed flag set, has to be drawn closed.
- Without the closed flag set, the polyline is not modified.
- There is no rule which says that the closed flag has to be set for polylines with identical first and last vertex.

So this is just the current state and background of polyline in LibreCAD. I can't and won't say if this is all correct. I also don't know how AutoCAD handle this, to use this as reference.
Inside LibreCAD we need closed polylines too, e.g. for Hatch. We use the condition closed flag set OR first vertex match with last vertex to identify closed contours.

We could check if first vertex is equal to the last and set closed flag then. But without a clear reference I can't estimate what will happen then in other CAD software with this kind of polylines.

My recommendation is, that the photolithography application should accept both kind of closed polylines (the OR approach).
Even when we modify LibreCAD behavior, there are other DXF creating applications which may have same DXF interpretation.
What I can imagine is a plugin for LibreCAD, which does the bulk-conversion. This way the current, long approved functionality doesn't change.
investing less than half an hour into Search function can save hours or days of waiting for a solution
Reply | Threaded
Open this post in threaded view
|

Re: how to check if every entity/polyline on your drawing is closed? and strange behaviour of creating polylines

tetukowski
Hi, LordOfBikes (it's always you, thank you!)

I have not tried the list entities plugin yet, but I will, for sure!

I want to add something to our discussion about "closed."

First, I don't use the polyline tool.
I draw an entity using lines, circles, trim it, etc.
In the end, I use the Create Polylines from existing segments.
Of course, polyline won't be created if there's a disconnected vertex.
But this is not a problem.

I have re-checked what causes the problem, and I can repeat the problem this time.
If you're interested, try this:
1. Draw a rectangle using four straight lines. (Do not use rectangle tool)
2. use "Create Polylines from existing segments,"
3. In the command line, we will see: polyline created (a single rectangle)
4. use Properties --> select the entity --> on the window: "Closed" is checked.
5. deselect
6. Repeat step 2-->4 on the same rectangle
7. Although the rectangle is not broken, this time you will see:


I'm guessing this is a bug (?).

From the programming point of view, I don't understand what does "closed" means.
But this is the effect of "closed" or "no-closed" using Klayout software (also open-source).
I use Klayout to create a mask file for the next step.

When we open the DXF file that contains the rectangle In the Klayout:
The closed rectangle is a single polygon with four coordinates points.
The no-closed rectangle becomes a " path ", i.e. a connected line with eight coordinate points.
Both appear as a polyline in the LibreCAD.
Here is an example from the Klayout, left is the no-closed entity, right is the closed entity:


So this is the effect of "closed" or "no closed" polyline read by another software.
Before this, I always thought a polyline was always "closed."
What is a polyline that is not closed?
We can check and uncheck the "closed" checkbox using the Properties tool.

In AutoCAD, if we move a single line on a closed entity, the shape will change, but it stays as a single entity.
If we move a line from the not-closed entity, the vertex which is not connected will stay at its position.
And the polyline will be disconnected (broken).  

It is a big problem for a drawing with many entities.
The bulk-changing is crucial.
Too bad there is no solution.

Many thanks!
Reply | Threaded
Open this post in threaded view
|

Re: how to check if every entity/polyline on your drawing is closed? and strange behaviour of creating polylines

LordOfBikes
Administrator
No problem, you're welcome.

So with your explanation I could reproduce your issue.
But your steps are missing an important step. It makes a difference if you select the tool first or the entities.

On the first iteration it is no problem. You have 4 single 2-Point lines building a closed rectangle. The result is a closed polyline, no matter what is selected first.
On the second iteration, you select the polyline first and then fire the "Create Polyline ..." tool.
This applies the tool on the existing, closed polyline and this program path seems to have an issue.

When you deselect all entities before you fire the "Create Polyline ..." tool, you are expected to select the entities for the polyline and finish the selection with ENTER. In this mode, it is not possible to select the polyline, because an already closed polyline could not be part of another polyline. The command history shows an error message.
So here it is prohibited to select an illegal entity, presumably to protect the code which fails when the polyline is already selected when the tool is fired.

So it seems that the "Create Polyline ..." tool gives what is expected on first hit. But using the tool a second time on an already closed polyline, the issue arise.
But this only happens when the polyline is selected first and then the tool.


From DXF point of view lines and polylines are totally different. Lines are independent entities with a starting and ending point. But a polyline is collection of vertices, connected with straight lines or arcs.
The polyline format in DXF is bad for rendering and thus inside LibreCAD a polyline is not a container of vertices, but of lines and arcs. Presumably KLayout handle this that way too.
Now you can think of the closed flag as a switch which defines if the first and last vertex of the polyline is connected.
In your Polygon case, the start point is 90,0 and the end point is 140,0. Connecting the 4 vertices you'll have an upside down U shaped path from 3 lines. And the closed flag is responsible for the 4th line on the bottom from 140,0 to 90,0 which closes the area.
In the Path case there seems to be an issue with KLayout, because 50,0 exists 4 times. Normally there should be 5 coordinates and the first point 50,50 is equal to the last point. This gives 4 lines and a closed shape too.

An open polyline is commonly used in CAM applications, where a continuous tool path is required. And there are surely other use cases too, so open polylines have their right to exist.

What I want to say with my recommendation for an OR approach is that KLayout or other applications should not only count on the closed flag, but also create a Polygon when first and last vertex of a polyline is equal, this would be less restrictive and avoid issues.
Because the intention of a draftsman drawing a polyline, ending on the starting point, is a closed polyline. He don't care or even know about closed flag.
investing less than half an hour into Search function can save hours or days of waiting for a solution
Reply | Threaded
Open this post in threaded view
|

Re: how to check if every entity/polyline on your drawing is closed? and strange behaviour of creating polylines

LordOfBikes
Administrator
I just created an issue on GitHub for that:
https://github.com/LibreCAD/LibreCAD/issues/1517
investing less than half an hour into Search function can save hours or days of waiting for a solution
Reply | Threaded
Open this post in threaded view
|

Re: how to check if every entity/polyline on your drawing is closed? and strange behaviour of creating polylines

tetukowski
Yes, I forgot that polyline doesn't have to be a closed-loop.
Another case is that if we have another line on top of another line,
for example in our square drawing previously, we have a double line in the same position.
The result of the polyline will be not closed and the extra line is "consumed" inside the polyline.
Hopefully, this information will be useful for others.

Thank you for creating this issue on GitHub.
Just curious, is there going to be an update on LibreCAD?
I hope so. If I were a developer I would contribute. Unfortunately, I am just a mech engineer.
LibreCAD is still an indispensable tool, at least, in Linux.
2D CAD drawing seems outdated because of the 3D CAD.
However, in applications where you do manufacturing layer by layer:
- toolpath for milling CNC, laser cutting
- photolithography
There is still a need for 2D CAD.

Thank you.