Realthunder Link implementation: Architecture discussion

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Realthunder Link implementation: Architecture discussion

Post by realthunder »

chrisb wrote: Sun Jan 14, 2018 10:49 am I think it's not a good idea to have such a general concept. The Workbenches and every other operation should be able to handle a link as if it was the object itself, keeping the radius of implications as small as possible.
If the workbench does have special needs when accessing through a Link, it sure can create a specialized type of Link, like what I did in asm3. I implemented the core function of Link as an extension, which adds some APIs to the extended object to obtain the linked object, and optionally, the accumulated transformation of the object, and its python object.

That being said, I don't think it is necessary to have that many specialized Link as you suggested. Because it doesn't add much benefit doing so. On the contrary, it will become harder to maintain. Take Part::Feature for an example. Most of Part WB code unreasonably insist on obtaining the Shape property through a type derived from Part::Feature. It can simply be relaxed to obtain a property named Shape with type PropertyShape from any type of object, much like what Python code does. The recently introduced concept of Extension is certainly another way of handling this, but still has its limitation. Let's not forget about the possibility of accessing an object in a container, or a linked container?

I did some modification to Part WB to make it support the general version of Link. There is a new convenience function, Part.getShape(), in both C++ and Python. Any code in need of an OCC shape from some object can be changed to call this function, which can return the shape with the correct transformation, regardless of whether the input object is a Link, a Part::Feature in a container, a Part::Feature in a Linked container, a Link in a Linked container. You can even obtain a compound shape from the whole container with correct children visibility by calling this function.

My idea is that, if the workbench has a narrow requirement of its operating objects, like Part WB, a super function like Part.getShape() is the easier and cleaner way to go.
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
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Realthunder Link implementation: Architecture discussion

Post by DeepSOIC »

realthunder wrote: Sun Jan 14, 2018 11:40 pmYou can even obtain a compound shape from the whole container with correct children visibility by calling this function.
Now that is just evil. Example:
1. PartWB Fuse a Part with another Part. Right stuff is visible, so we're good.
2. I want to edit something in Part, so I hide some stuff that gets in the way (or, Part-o-magic-like functionality does it for me).
3. I change it, Recompute. Now, the fusion is recomputed, but visibility is incorrect, so not right stuff is included.
4. Now I restore the proper visibilities, and see that my fusion has some stuff missing. And recompute button is blocked. WTF?
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Realthunder Link implementation: Architecture discussion

Post by realthunder »

DeepSOIC wrote: Mon Jan 15, 2018 12:43 am
realthunder wrote: Sun Jan 14, 2018 11:40 pmYou can even obtain a compound shape from the whole container with correct children visibility by calling this function.
Now that is just evil. Example:
1. PartWB Fuse a Part with another Part. Right stuff is visible, so we're good.
2. I want to edit something in Part, so I hide some stuff that gets in the way (or, Part-o-magic-like functionality does it for me).
3. I change it, Recompute. Now, the fusion is recomputed, but visibility is incorrect, so not right stuff is included.
4. Now I restore the proper visibilities, and see that my fusion has some stuff missing. And recompute button is blocked. WTF?
Yes indeed, this may be a problem, and the user should be cautious when using a container directly for geometry modeling. But there are situations where the user want a snapshot of the container, and write code to obtain a compound shape with nested container is tricky (because of my addition of Link), and that's where Part.getShape() is going to help.

The real reason of missing recomputation is because I added a Visibility property to DocumentObject, which is synced by the ViewProviderDocumentObject Visibility. To make things backward compatible, that Visibility property is marked as Output, meaning it won't touch the object when changed, hence the mute recompute button. You can dynamically change the property status though (python code obj.setPropertyStatus('Visibility','-Output')), this opens the possibility for python code to customize the behavior.
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