I like to discuss realthunders link implementation from an architecture point of view. As this is a very important piece of functionality in FreeCAD we should be all aligned if this is the way to go, with all advantages and disadvantages it has. Note that I may have missunderstood some things from the code, so please feel free to correct me (Many changes, little time to review). I try to paint a high-level picture of the architecture for the discussion.
So it was already decided to have each Item in FreeCAD only once and make duplicates via instance objects, or link objects. There are IMHO two general possible ways to do this:
Create special link objects like done by realthunder
No changes to the current object/selection mechanism in FreeCAD, a Link is just a new object that would appear in the tree, as well as the selection and all PropertyLinks that uses the link object. The LinkObject than allows has an API to retreive the original object and all needed placement infos.
Advantage:
- Basically no base system changes
- No changes to tools nesseccary
- Lots of functionality can be added to the link object to ease the usage of links
- Tools cannot directly use selected links
- To not adjust tools, and make them work with links directly, a special link object type has to be created for each object (like currently done for Part::Link). This than results in quite some data duplication
This means a link to an object would not be valid by only holding the object itself, but only with the pair {object, InstancePath}. One could easily extend the PropertyLink properties to hold both, and also extend selection mechanism to return both on selection. So the Instance Object would be a new object in the tree, but when selected it returns the pair {object, InstancePath} with the original object and just a different instancePath. Than all tools would need to be adjusted to handle the Instance Path.
Advantage:
- All links are still to the object of correct type, features using them would only need to do some placement calculation via instance path. This is a small change.
- Very coherent architecture, e.g. no real special cases
- Some changes in the base system
- Every tool in FreeCAD would need to be adjusted to work with InstancePath
So the question is if we are ok with this kind of implementation. I personally see the problem of interoperability with the chossen approach, the Part::Link for example looks like a hack solution, and making this for other objects as well gives me some headaches. The second approach seems to be more streamlined, even though more laboursome to implement. Do you see more advantages or dificulties than described? Do you think I'm wrong in my assumption? Thats an open discussion and I'm fine with been proven wrong, lets go