Bug when using draft modifiers on a part container

A forum dedicated to the Draft, Arch and BIM workbenches development.
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: Bug when using draft modifiers on a part container

Post by realthunder »

yorik wrote: Mon Nov 04, 2019 6:43 pm There is another important difference, which is exactly the relative/absolute placement thing. I tried to work a bit with App::Part (it was my first idea to derive BuildingPart on App Part), and found that very disturbing that object geometry doesn't know its absolute coordinates anymore. If you move an object in/out of the App Part, either its coordinates must change, or it jumps to another place (which is what happens in App Parts). I really wanted to be able to move an object from one buildingpart to another without changing anything to its geometry or its apparent position.
There is a tree view option called 'Sync Placement'. When enabled, it will auto adjust object's placement when drag and drop from/to group like objects, so that it does not jump. It does not work with Draft move currently. But at least it shows that it can be done.

BTW, @yorik, do you mind check on this issue?

tree-view-options.png
tree-view-options.png (39.12 KiB) Viewed 2330 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
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Bug when using draft modifiers on a part container

Post by carlopav »

realthunder wrote: Thu Jan 09, 2020 9:48 pm There is a tree view option called 'Sync Placement'. When enabled, it will auto adjust object's placement when drag and drop from/to group like objects, so that it does not jump. It does not work with Draft move currently. But at least it shows that it can be done.
Wow. I didn't realize it. Is there an option to use that from python too when calling:

Code: Select all

Part.addObject(obj)
I'm on a PR to auto insert new created Draft objects to the active part, but i had to recalculate their placement so they do not jump on a new position.
https://github.com/FreeCAD/FreeCAD/pull ... 87d86e5c07
Would be lovely to just use faster exhisting code.
follow my experiments on BIM modelling for architecture design
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Bug when using draft modifiers on a part container

Post by realthunder »

carlopav wrote: Sat Jan 11, 2020 10:41 am Is there an option to use that from python too when calling:
In order to calculate the placement adjustment, it requires the complete object hierarchy before and after movement. With the patch you linked, you can find the object hierarchy of the active part by passing a second argument set to False, which will return the top level parent, and a string subname describing the object path. You can then find the global transformation matrix of the part container as shown below,

Code: Select all

obj,subname = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False)
matrix = obj.getSubObject(subname,retType=4)
You can probably get the global transformation matrix of the active Arch object the same way. But the problem is that I don't think it is possible to get the object hierarchy of the current 'autogroup'.

Maybe you can post a sample file to let me play around.
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
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Bug when using draft modifiers on a part container

Post by carlopav »

realthunder wrote: Sun Jan 12, 2020 1:38 am

Code: Select all

obj,subname = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False)
matrix = obj.getSubObject(subname,retType=4)
Thx for the tip, but getting the object matrix isn't it like getting global placement of Part container, inverting it and applying it to the grouped object Placement? That BTW is what I did in the patch, and it's working.
You can probably get the global transformation matrix of the active Arch object the same way. But the problem is that I don't think it is possible to get the object hierarchy of the current 'autogroup'.
With arch objects it's not necessary because they don't work like Std::Part, but like Std::Group objects, so you can group them without recalculating their placement. (I'd prefer them to work like app part, but I think they will stay like this for the moment)
follow my experiments on BIM modelling for architecture design
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Bug when using draft modifiers on a part container

Post by realthunder »

carlopav wrote: Sun Jan 12, 2020 5:32 pm Thx for the tip, but getting the object matrix isn't it like getting global placement of Part container, inverting it and applying it to the grouped object Placement? That BTW is what I did in the patch, and it's working.
App::Part globalPlacement works because App::Part has this restriction of allowing an object to be in one and only one App::Part. With the introduction of App::Link, this rule can be broken. So globalPlacement does not work everytime. That's why I introduced the subname object path in get/setActiveObject().

Say you have a child App::Part inside a parent Part, and you create a Link to that parent Part. You can move the Link independently with the linked Part. Although the child Part is the same in both parents, it makes a different which one you set as active part, and getActivePart('part', False) will tell you the top parent object, so that you can find out the global placement using getSubObject().

Same thing goes for Gui.getSelection('', 0). The second argument '0' will cause it to return the top parent object of the selection, and and object path using SubElementNames. That's how tree view 'Sync Placement' calculates the placement adjustment.

With arch objects it's not necessary because they don't work like Std::Part, but like Std::Group objects, so you can group them without recalculating their placement. (I'd prefer them to work like app part, but I think they will stay like this for the moment)
But they can be Link'ed, and when a Std_Group object is Link'ed, it behave similar like an App::Part.
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
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Bug when using draft modifiers on a part container

Post by carlopav »

realthunder wrote: obj,subname = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False)
matrix = obj.getSubObject(subname,retType=4)
Thanks a lot for taking the time to explain it. It's a whole new world to me.
I'm sorry to bother you again, but I'm not succeding with it.
EDIT: I have an App::Part ('Part') and a Link to it ('Link') which have been activated. If I run from the python console:

Code: Select all

obj,subname = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False)
gives this error:

Code: Select all

Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: too many values to unpack (expected 2)
instead:

Code: Select all

obj,sub_obj,string = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False)
returns:

Code: Select all

(<Part object>, <Part object>, '')
their names are:

Code: Select all

('Part', 'Link', '')
I'm not able to make getSubObject work. It just doesn't return anything.
BTW Sorry if this sound silly, but... Can't I have a .getGlobalPlacement() for link objects, so I can just treat them as App::Parts when I get sub_obj from .getActiveObject("part", False)?
follow my experiments on BIM modelling for architecture design
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Bug when using draft modifiers on a part container

Post by realthunder »

carlopav wrote: Mon Jan 13, 2020 9:54 pm instead:

Code: Select all

obj,sub_obj,string = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False)
My mistake. Yes it returns three elements. The first one is the actual active object. The second and third is the parent and subname path. You can obtain the global transformation matrix using the second and third elements. Note that the view deduces the object hierarchy based on the current selection when calling its setActiveObject function. If some program calls setActiveObject without selection, there will be no hierarchy information. I assume active Arch object is setup similarly to active Part. You don't need to know which Part contains the active Arch object. The returned subname path contains the full hierarchy.

Code: Select all

obj, parent, sub = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False)

# return matrix
parent.getSubObject(sub, retType=4)

# return placement, may not work if there is scale in Link
parent.getSubObject(sub, retType=3)
And here is a screencast of setting the same active object but under different hierarchy.

Image
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
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Bug when using draft modifiers on a part container

Post by carlopav »

realthunder wrote: Mon Jan 13, 2020 11:26 pm ping
Works great, thanks. I updated the PR according to your suggestion. Still don't know how to manage when link is scaled, but handled the option with a console message.
Two more questions:
- sometimes when I autogoup the object into a linked part, the object visibility toggle off. Any idea why that happens? I can of course turn it on after grouping, but dont' understand why it happens.
- may I use something similar with every document object, like when i get it from: Gui.Selection.getSelection() ?
Thanks again and sorry for my low coding skills. :)
follow my experiments on BIM modelling for architecture design
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Bug when using draft modifiers on a part container

Post by realthunder »

carlopav wrote: Sat Jan 18, 2020 4:13 pm - sometimes when I autogoup the object into a linked part, the object visibility toggle off. Any idea why that happens? I can of course turn it on after grouping, but dont' understand why it happens.
If it is a plain group, then Link has some special handling on the group member visibility. It allows to have independent child visibility control to the original group. What you describe sounds like a bug. But I have made quite some changes in an pending PR, so it might have already been fixed. Maybe you can provide a sample file showing this problem.

- may I use something similar with every document object, like when i get it from: Gui.Selection.getSelection() ?
Thanks again and sorry for my low coding skills. :)
Yes you can. That's how tree view 'sync placement' does it. You can experiment on different values of 'retType', some will give you a tuple of the sub-object and transformation matrix.

Code: Select all

for sel in Gui.Selection.getSelectionEx('', 0):
	for sub in sel.SubElementNames:
		sel.Object.getSubObject(sub, retType=3)
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
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Bug when using draft modifiers on a part container

Post by carlopav »

realthunder wrote: Sat Jan 18, 2020 11:06 pm Maybe you can provide a sample file showing this problem.
You can find it attached, but to try it wait for this PR to be merged cause I introduced a small bug. To reproduce:
- set the link or another part active by double clicking on the tree;
- open Draft WB
- draw what you prefer (for ex rectangle)
- the object is created but its visibility is toggled off.

Btw for every other aspects, following your suggestion makes autogroup work smoothly with both part and link. I'll try to give a look also to Draft move/rotate.

EDIT: I just experimented with move: it accept a list of objects and a vector. But the list of object is dumb in respect of which viewprovider of the object have been selected by the user... Isn't it? If this is true, the only way i can imagine is to give move also the objects transformation matrix as another list to not break backward compatibility... :roll:
Attachments
Link Test.FCStd
(14.53 KiB) Downloaded 39 times
follow my experiments on BIM modelling for architecture design
Post Reply