Selection bug: selected object missing in getSelection()/getSelectionEx

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Selection bug: selected object missing in getSelection()/getSelectionEx

Post by DeepSOIC »

1. open this file:
selection-bug.FCStd
(8.44 KiB) Downloaded 33 times
2. in model tree, select Cube and then Cut
3.

Code: Select all

>>> [o.Name for o in Gui.Selection.getSelection()]
['Cut']
Cube is missing from selection. The same happens with getSelectionEx() and is seen in selection view.

If i select these things in 3d view, everything works correctly.

This bug is causing me serious trouble - it blocks me from using Part-o-magic Replace tool just about always.
https://github.com/DeepSOIC/Part-o-magic/issues/66

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.0.32457 (Git)
Build type: Release
Branch: master
Hash: 85216bd12730bbc4c3cbf8f0bc50416ab1556cbb
Python 3.10.9, Qt 5.15.8, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/Germany (en_DE)
Installed mods: 
  * CurvesWB 0.4.4
  * DeepConsole
  * fir_design
  * Lattice2 1.0.0
  * Part-o-magic 1.1.0
  * TabBar
  * _disabled
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by Syres »

This is an old regression, the last build I have that worked is:

Code: Select all

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4 (GitTag)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
and the next build that I have that fails is:

Code: Select all

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.20909 (Git)
Build type: Release
Branch: (HEAD detached at 0.19.alpha2)
Hash: 8be2c08141f0275e9da005bd143771953e982a59
Python version: 3.7.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United Kingdom (en_GB)
Gulp!!!

Edit: Found an older build with the regression.
Last edited by Syres on Wed Mar 29, 2023 2:51 pm, edited 1 time in total.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by Syres »

I've had a thought, there was a major change in August 2020 which I have the builds either side of on an old HDD, hopefully I'll have an answer tomorrow to narrow it down. This regression is pre 3rd May 2020, in order to compile the 0.19dev cycle will be fun no doubt.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by Syres »

Investigation will be centred around :
https://github.com/FreeCAD/FreeCAD/comm ... s%2Fmaster back to 16th August 2019.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by DeepSOIC »

thanks for looking into this. BTW, i have another selection api bug: viewtopic.php?t=77219. It is unlikely to be related, though.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by openBrain »

Yes, If you select from 3D view, you select sub-objects.
In tree view you select complete objects, and then the Selection is simplified because Cube (as an object) is fully included (consumed) in Cut.

If you want full selection, same as my reply in your other thread. ;)

Code: Select all

Gui.Selection.getCompleteSelection()
PS : I'm not saying current behavior is good (or bad). Just say it responds as it is designed to do.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by DeepSOIC »

openBrain wrote: Wed Mar 29, 2023 7:35 pm the Selection is simplified because Cube (as an object) is fully included (consumed) in Cut.
First, no, the cube is not fully included in Cut, i'd even go as far as to say, cube has nothing to do with cut, apart from Cut using Cube's shape somehow. (Part Mirror is a nice example, and it is prone to this bug too).
Second, if you select in a different order, both objects are in selection.
Third, if all this stuff is not in Part container but in root, both are included in getSelection().
Fourth, Cube is selected in tree, why then?
Fifth, getCompleteSelection also returns just one object for me :roll:
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by openBrain »

OK, the situation comes from git commit c18bf118.

Very basically, when adding the Cube, it adds ("Part", "Cut.Box.") while IMO it should add ("Part", "Box.").
I'll continue investigating.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by wmayer »

First, no, the cube is not fully included in Cut, i'd even go as far as to say, cube has nothing to do with cut, apart from Cut using Cube's shape somehow.
With the link support RT has reworked the selection mechanism and objects are not independent any more as before but an object that is a child of another object is now considered a sub-element.

So, in this case Cube is a child of Cut and thus it's considered a sub-element. And Cut is a child of Part and thus Cut and Cube are sub-elements of Part.

Now if you select the Cube then the actual object is Part with the sub-element "Cut.Box." (FYI, Box is the internal name of the Cube)

If the Cut object is selected then selected sub-elements are automatically de-selected, i.e. the item with the sub-name "Cut.Box." is removed from the selection list. The automatic de-selection happens in DocumentItem::updateItemSelection() where it passes the object name "Cut" to rmvSelection() and in checkSelection() it's determined that "Cut.Box." is a sub-element and removed from the selection.

Since the selection depends on the order the question indeed is whether there is a must that sub-element have to be removed from the selection first.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Selection bug: selected object missing in getSelection()/getSelectionEx

Post by openBrain »

I made a tentative fix in https://github.com/FreeCAD/FreeCAD/pull/9124
But as said there, I more or less jacked the code based on analysis without deep understanding of it, so I may have miss regressions or side-effects.
Post Reply