[ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by paullee »

Some interesting finding:-
  1. s.Shape.Edges returned 6 edges strangely as Roy_043 found ( ~ in Sketch.Shape / Sketch.Shape.Wires )
    s.Shape.OrderedEdges returned only 5 edges :o
  2. s.Shape.Vertexes returned 4 vertices
    s.Shape.OrderedVertexes returned 5 vertices :shock:

Code: Select all

>>> s.Shape.Edges
[<Edge object at 0x55b8d4793db0>, <Edge object at 0x55b8d46b5710>, <Edge object at 0x55b8d4dbdfc0>, <Edge object at 0x55b8d5543520>, <Edge object at 0x55b8d4ef86d0>, <Edge object at 0x55b8d4ecd400>]
>>> s.Shape.OrderedEdges
[<Edge object at 0x7fbd7400b120>, <Edge object at 0x55b8d48760d0>, <Edge object at 0x55b8d4ef7650>, <Edge object at 0x55b8d4e71670>, <Edge object at 0x55b8d4cad1d0>]
>>> 

Code: Select all

>>> s.Shape.Vertexes
[<Vertex object at 0x55b8d5518c80>, <Vertex object at 0x55b8d55104c0>, <Vertex object at 0x55b8d5510560>, <Vertex object at 0x55b8d5510600>]
>>> s.Shape.OrderedVertexes
[<Vertex object at 0x55b8d48760d0>, <Vertex object at 0x55b8d4ca8780>, <Vertex object at 0x55b8d4ee8e90>, <Vertex object at 0x55b8d4f90d30>, <Vertex object at 0x55b8d4793e50>]
Screenshot from 2023-01-10 01-18-02.png
Screenshot from 2023-01-10 01-18-02.png (175.76 KiB) Viewed 1132 times
Screenshot from 2023-01-10 01-19-19.png
Screenshot from 2023-01-10 01-19-19.png (173.6 KiB) Viewed 1132 times
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by paullee »

Tested wire.isClosed() methods, so far it return as expected results

All return False :)

Screenshot from 2023-01-10 01-56-21.png
Screenshot from 2023-01-10 01-56-21.png (153.83 KiB) Viewed 1101 times
Screenshot from 2023-01-10 01-59-57.png
Screenshot from 2023-01-10 01-59-57.png (154.98 KiB) Viewed 1101 times
Screenshot from 2023-01-10 02-03-32.png
Screenshot from 2023-01-10 02-03-32.png (158.5 KiB) Viewed 1101 times
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by edwilliams16 »

Roy_043 wrote: Sun Jan 08, 2023 9:51 pm I must say that I have learned a lot from this topic. Some of my assumption regarding wires were wrong. The first surprise is that edges need not be in sequence. But what is really strange is that the edges need not result in a single polyline. A wire can be 3 straight edged that share a single point for example.
I had the same misconception. Roman Lygin's blog http://edwilliams.org/FreeCAD/TOPOLOGY_ ... ASCADE.pdf is a bit vague on Wires. However, https://old.opencascade.com/doc/occt-7. ... a00cbced41 essentially says that in OpenCascade a wire is any collection of connected edges - they need not line up as a path - any connected graph is OK. So given any collection of edges, it could be sorted into a set of connected wire clusters. Planar such wires it seems can be Part|Extruded.

I was able to make a 3D wire via a subShapeBinder. OTOH, using Part|ShapeBuilder, I could only get a polyline subset of the edges.

It seems wires in FreeCAD depend on context - sometimes general OpenCascade wires, sometimes restricted to polylines.
Screenshot 2023-01-09 at 1.05.17 PM.png
Screenshot 2023-01-09 at 1.05.17 PM.png (12.44 KiB) Viewed 1049 times
Attachments
3DWire.FCStd
(10.58 KiB) Downloaded 25 times
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by edwilliams16 »

paullee wrote: Mon Jan 09, 2023 5:23 pm Some interesting finding:-
  1. s.Shape.Edges returned 6 edges strangely as Roy_043 found ( ~ in Sketch.Shape / Sketch.Shape.Wires )
    s.Shape.OrderedEdges returned only 5 edges :o
  2. s.Shape.Vertexes returned 4 vertices
    s.Shape.OrderedVertexes returned 5 vertices :shock:
crossedrect.png
crossedrect.png (20.96 KiB) Viewed 1002 times

Code: Select all

[[Part.show(edge, f"Edge_{i}_{j}") for j, edge in enumerate(edgelist)] for i, edgelist in enumerate(Part.sortEdges(shp.Edges))]
yields [[1,2,3,4],[4],[5]] where the number/letter corresponds to the edge/vertex in the Figure.

Code: Select all

[[Part.show(edge, f"Edge_{i}_{j}") for j, edge in enumerate(edgelist)] for i, edgelist in enumerate([Part.__sortEdges__(shp.Edges)])]
yields [1,2,3,4] - just the first element in the above list.

Code: Select all

[[Part.show(edge, f"Edge_{i}_{j}") for j, edge in enumerate(edgelist)] for i, edgelist in enumerate(Part.sortEdges(shp.OrderedEdges))]
yields [[1,2,3,4],[5]] - missing edge 6

Code: Select all

[Part.show(vertex, f"Vertex_{j}") for j, vertex in enumerate(shp.Vertexes)]
yields [A,B,C,D]

Code: Select all

[Part.show(vertex, f"Vertex_{j}") for j, vertex in enumerate(shp.OrderedVertexes)]
yields [A,B,C,D,A]

Code: Select all

[[Part.show(edge, f"Edge_{i}_{j}") for j, edge in enumerate(edgelist)] for i, edgelist in enumerate(Part.getSortedClusters(shp.Edges))]
yields [[1,2,3,4,5][6]]

Need more data to get firm conclusions...
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by paullee »

edwilliams16 wrote: Mon Jan 09, 2023 11:11 pm I was able to make a 3D wire via a subShapeBinder. OTOH, using Part|ShapeBuilder, I could only get a polyline subset of the edges.
Interesting !

Screenshot from 2023-01-10 23-54-55.png
Screenshot from 2023-01-10 23-54-55.png (153.07 KiB) Viewed 928 times
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by paullee »

Roy_043 wrote: Sun Jan 08, 2023 9:51 pm Removing the redundant sorting (#4) should not be a problem. Calling functions can pre-sort the list.
Switching to isClosed (#5) is possible but the wire argument can also be a Face. So we need to handle that case. See attached file.
Checking the code again, not sure who is using offsetwire() and maybe sorting here is need if input edges had not been sorted in the first place.

The isClosed() could be used directly in ArchWall, instead of used instead ?

Thanks.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by Roy_043 »

In the Draft WB offsetWire is always passed a Shape. In the Arch WB offsetWire is only used by ArchWall. So for those two workbenches the proposed change should not be a problem. The Path WB has its own offsetWire function. Other default workbenches do not use offsetWire. Of course a macro or external WB may use Draft.offsetWire and pass an unsorted list, but that does not seem very likely.

paullee wrote: Tue Jan 10, 2023 5:20 pm The isClosed() could be used directly in ArchWall, instead of used instead ?
I don't understand.
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by paullee »

Roy_043 wrote: Tue Jan 10, 2023 6:07 pm In the Draft WB offsetWire is always passed a Shape. In the Arch WB offsetWire is only used by ArchWall. So for those two workbenches the proposed change should not be a problem. The Path WB has its own offsetWire function. Other default workbenches do not use offsetWire. Of course a macro or external WB may use Draft.offsetWire and pass an unsorted list, but that does not seem very likely.

Thanks, maybe add #remarks in the code for ease of understanding -

Code: Select all

...
    # For ArchWall which may pass a list of Edges if Base is Sketch
    elif isinstance(wire, list):
        if isinstance(wire[0], Part.Edge):
            edges = wire.copy()
            # How to avoid __sortEdges__ again?
            # Make getNormal directly tackle edges?
            #wire = Part.Wire(Part.__sortEdges__(edges))
            wire = Part.Wire(edges)
...

Roy_043 wrote: Tue Jan 10, 2023 6:07 pm
paullee wrote: Tue Jan 10, 2023 5:20 pm The isClosed() could be used directly in ArchWall, instead of used instead ?
I don't understand.

Sorry for confusing, I should had meant using isClosed() directly in offsetWires(), instead of bothering draftgeoutils.wires.isReallyClosed().

i.e. all updating is in offsets.py only.

Code: Select all

...
    #Seems wire.isClosed() works
    #closed = isReallyClosed(wire)
    closed = wire.isClosed()
...
offsets.py
(21.62 KiB) Downloaded 20 times
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by Roy_043 »

paullee wrote: Wed Jan 11, 2023 12:07 am using isClosed() directly in offsetWires()
Already implemented in the file attached to a previous post:
https://forum.freecadweb.org/viewtopic. ... 40#p652253
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by Roy_043 »

paullee wrote: Wed Jan 11, 2023 12:07 am Thanks, maybe add #remarks in the code for ease of understanding -
The docstring already mentions that the wire argument can be a list.
Post Reply