PR #4752 Topological Naming

Post here if you have re-based and finalised code to integrate into master, which was discussed, agreed to and tested in other forums. You can also submit your PR directly on github.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
C_h_o_p_i_n
Posts: 225
Joined: Fri Apr 26, 2019 3:14 pm

Re: PR #4752 Topological Naming

Post by C_h_o_p_i_n »

jonasb wrote: Mon Jun 28, 2021 7:14 pm
C_h_o_p_i_n wrote: Mon Jun 28, 2021 12:23 pm ... I was wondering, why I can't tag (attach a name to) a surface and tag two edges as "origin" to have a reference to attach any folloing sketches - relaying to this surface - to ...
This is basically the what Datum Planes offer you. The problem comes afterwards: when "something" changes, if happen that your plane/tag/name looses its attachment point, or is attached where you don't expect it. For a human it's usually easy to tell what's "the same" surface before and after the change. For the software, it's not.
Well - I know - took some time to understand the "why datum planes".

Also for Software I can imagine a way of keeping track ... if the dataset of an Object(node) not just holds the data defining its place in space but also an fixed "tag" ... or ... by it's managed position in a linked list of datasets ... and also it might be unique due to it's relative position & size an relation to the/an origin.

But of course - in case , a dataset within the linked list or an attachment-point gets deleted - I wouldn't expect the software to guess the attachment points for the subsequent elements in the linked list.

Regards,
Stefan
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: PR #4752 Topological Naming

Post by realthunder »

Zolko wrote: Fri Jun 25, 2021 3:11 pm ... thinking further: I didn't read the code, and wouldn't be able to understand it, but from what I can infer I think that each element has at least 2 states: normal and construction. We could add a third state: deleted.
Hi, Zolko, you can try my current release to test if the sketch behavior meets your expectation. The new name will be shown in Selection View, or in the status bar when hovered when editing the sketch. My implementation actually covers most of your requirement here, if not all. There is even a hidden 'deleted' state in the sketch. The new name used for sketch is just a plain integer ID that keeps increasing. But the sketcher keeps an internal partial history (not saved to document) of all created geometries keyed on its start and end point coordinates (the actual logic is a bit more complex than that). So if you delete a line, and add an Arc at the exact same start and ending point, it will reuse the line's ID. There is eve an dedicate command to let you swap the ID of two geometry elements. All of these are not really part of the topo naming algorithm. It's just a showcase of possible applications using the topo naming framework.

Regarding the analysis about the shape history, please keep in mind that the modeling code belongs to OCC, so we have to treat it more like black box. Like I mentioned in the OP, the history tracing functionality relies on heuristics. The most important functionality of the topo naming is to detect and signal changes to user. The auto fix in response to change is just a bonus.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
wsteffe
Posts: 461
Joined: Thu Aug 21, 2014 8:17 pm

Re: PR #4752 Topological Naming

Post by wsteffe »

realthunder wrote: Tue Jun 29, 2021 11:01 pm the history tracing functionality relies on heuristics
Hi realthunder, may you please say something about the heuristic rules you are using to track the evolution of 3D shapes ?
Perhaps you could extend the wiki page https://github.com/realthunder/asm3-wik ... -Naming.md considering also the algorithms/rules for generation of stable names in Sketch and Part Design WB.

Thanks
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: PR #4752 Topological Naming

Post by Zolko »

realthunder wrote: Tue Jun 29, 2021 11:01 pm Hi, Zolko, you can try my current release to test if the sketch behavior meets your expectation.
thank-you, I will do.

realthunder wrote: Tue Jun 29, 2021 11:01 pm
Zolko wrote: Fri Jun 25, 2021 3:11 pm each element has at least 2 states: normal and construction. We could add a third state: deleted.
There is even a hidden 'deleted' state in the sketch.
but you don't use the GeometryMode for that:

https://github.com/realthunder/FreeCAD/ ... sion.h#L52

Don't you think we could use that state-parameter for that ?
try the Assembly4 workbench for FreCAD — tutorials here and here
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: PR #4752 Topological Naming

Post by chrisb »

Can the changes be localized in the source code or is it spread all over the place?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: PR #4752 Topological Naming

Post by Zolko »

realthunder wrote: Tue Jun 29, 2021 11:01 pm Hi, Zolko, you can try my current release to test if the sketch behavior meets your expectation. The new name will be shown in Selection View, or in the status bar when hovered when editing the sketch
Hello realthunder, I tested your branch and here is what I found about the toponaming thing: I created a sketch, draw a square, and attached an LCS to a corner aligned OXY on 2 edges. Then:

  • when setting one of the lines of the square (in sketcher) to construction, the names of the edges (in 3D view) got changed, but the attachment references of the LCS where adapted to the new names, thus there was no error and also no misplacement
  • when I deleted a line (in sketcher) and added some new lines, again the names of the edges (in 3D view) changed, but again the attachment references where adapted and there was no error and no misplacement

Therefore, my conclusion is that your branch doesn't really solve the topological naming problem but circumvents it. My fear would be that for large and complex models/assemblies, following the changes for any feature and changing the references for all impacted objects is a dangerous endeavor. My personal preference, at least for sketcher, would be to solve the naming issue as much as possible, meaning that in the above scenarios the names of the resulting edges should remain constant.


EDIT: when I do the same in the main FreeCAD branch, the attachment engine doesn't find the relevant edges and fails with an error:

Code: Select all

<Exception> AttachEngine3D: subshape not found
try the Assembly4 workbench for FreCAD — tutorials here and here
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: PR #4752 Topological Naming

Post by realthunder »

Zolko wrote: Sat Jul 03, 2021 2:22 pm Therefore, my conclusion is that your branch doesn't really solve the topological naming problem but circumvents it. My fear would be that for large and complex models/assemblies, following the changes for any feature and changing the references for all impacted objects is a dangerous endeavor. My personal preference, at least for sketcher, would be to solve the naming issue as much as possible, meaning that in the above scenarios the names of the resulting edges should remain constant.
Glad that you tried my branch. There are so much more than meets the eye there. For compatibility reason, the indexed based topo name can still be used just the same. Once the name is assigned to some PropertyLink, it will be internally tracked using the new topo name. For those boolean features, the new topo name is generated based on their history. But for sketches, the name is a simple integer ID that sticks with a given geometry. In other words, the topo name for a sketch geometry is stable. To reveal that name (I call it mapped name), you can either use the View -> Panels -> Selection view. Or, use the 'Preselection geometry info" enabled by keyboard shortcut 'M, P' and select "Show preselection geometry info", and then mouse over any sketch edge to see more information.

And of course, you can also use script

Code: Select all

# Get mapped name from indexed name
App.ActiveDocument.Sketch.Shape.getElementMappedName('Edge3')

# Get indexed name from mapped name
App.ActiveDocument.Sketch.Shape.getElementIndexedName('g3;SKT')
Screenshot from 2021-07-04 21-45-19.png
Screenshot from 2021-07-04 21-45-19.png (12.81 KiB) Viewed 5299 times
Screenshot from 2021-07-04 21-46-07.png
Screenshot from 2021-07-04 21-46-07.png (31.87 KiB) Viewed 5299 times
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: PR #4752 Topological Naming

Post by realthunder »

wsteffe wrote: Wed Jun 30, 2021 6:25 am Hi realthunder, may you please say something about the heuristic rules you are using to track the evolution of 3D shapes ?
Perhaps you could extend the wiki page https://github.com/realthunder/asm3-wik ... -Naming.md considering also the algorithms/rules for generation of stable names in Sketch and Part Design WB.
The heuristic rules is to recursively decode the history encoded topo name until one can find a named geometry element in some shape in the history. Then, search the current (modified) shape for elements that can be traced back to the same geometry element. See here for an explanation of how the recursive encoding using shape history works. There are APIs available to help tracing back and forth. The heuristics lies in the fact that one can often find more than one match, and I usually just pick the first one.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: PR #4752 Topological Naming

Post by Zolko »

realthunder wrote: Sun Jul 04, 2021 2:08 pm Glad that you tried my branch. There are so much more than meets the eye there.
yes, I've seen that, very nice

But for sketches, the name is a simple integer ID that sticks with a given geometry. In other words, the topo name for a sketch geometry is stable. To reveal that name (I call it mapped name), you can either use the View -> Panels -> Selection view.
Ah, Ok, now I see it. Yes, this is the behaviour I expected to have, very nice ... but confusing, because the edge# changes, while the g# doesn't. When hoovering above an object, it's the edge# name that is shown in the status bar and in the Attachment Editor also.

So if I understand well, there is now a new internal, hidden, stable name, and an old, external (shown), and changing name. Did I understand correctly ?

And when an object references an element (edge, vertex...), does it so with the new name or the old one ?
try the Assembly4 workbench for FreCAD — tutorials here and here
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: PR #4752 Topological Naming

Post by realthunder »

Zolko wrote: Sun Jul 04, 2021 3:30 pm Ah, Ok, now I see it. Yes, this is the behaviour I expected to have, very nice ... but confusing, because the edge# changes, while the g# doesn't. When hoovering above an object, it's the edge# name that is shown in the status bar and in the Attachment Editor also.

So if I understand well, there is now a new internal, hidden, stable name, and an old, external (shown), and changing name. Did I understand correctly ?

And when an object references an element (edge, vertex...), does it so with the new name or the old one ?
There is a reason for using the index based name, because that's how OCC organizes its topologies internally, as an array of an array of another array and so on. So naturally, when an element is deleted, it will affect the indices of all subsequent elements. The new topo names are stored as a string table inside each shape (Part::TopoShape) that maps the encoded name to index. Internally, we still need the index name to access OCC sub-shapes. Externally, it's also much more human readable than the mapped name, which may get quite long for some generated geometries. That's why it's hidden by default.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
Post Reply