Skip to content

Gui: Respect Selectable property for objects inside Part containers#25009

Merged
chennes merged 3 commits intoFreeCAD:mainfrom
tetektoza:fix/24290_respect_selectable_option_if_nested_objs
Jan 4, 2026
Merged

Gui: Respect Selectable property for objects inside Part containers#25009
chennes merged 3 commits intoFreeCAD:mainfrom
tetektoza:fix/24290_respect_selectable_option_if_nested_objs

Conversation

@tetektoza
Copy link
Member

@tetektoza tetektoza commented Nov 2, 2025

Currently if user selects object with Selectable=false property which is nested inside a Part container, for example Part->Body->Pad, parent Part container will get highlighted in the 3D view, even though the user clicked on a non-selectable child object.

Cause of that is that tree view's getTopParent() function resolves nested objects selections to their top-level container. When a Pad inside Part is selected, SoFCUnifiedSelection was only checking Part's isSelectable() status, even though the target is Pad.

So the fix is to resolve subname to get the final target object and checks its isSelectable() status before checking for highlighting.

Resolves: #24940

@tetektoza tetektoza force-pushed the fix/24290_respect_selectable_option_if_nested_objs branch from 7a85790 to 947d1d6 Compare November 2, 2025 22:42
@tetektoza tetektoza changed the title Gui: Respect Selectable property for objects isnide Part containers Gui: Respect Selectable property for objects inside Part containers Nov 2, 2025
@github-actions github-actions bot added the Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD label Nov 2, 2025
@maxwxyz maxwxyz added the Type: Bug This issue or PR is related to a bug label Nov 3, 2025
@maxwxyz maxwxyz added this to the 1.1 milestone Nov 3, 2025
@chennes chennes modified the milestones: 1.1, 1.2 Nov 3, 2025
@chennes chennes self-assigned this Nov 3, 2025
@maxwxyz
Copy link
Collaborator

maxwxyz commented Nov 14, 2025

PR has a conflict

@tetektoza tetektoza force-pushed the fix/24290_respect_selectable_option_if_nested_objs branch 2 times, most recently from 688a004 to 68c9124 Compare November 25, 2025 01:16
@chennes chennes requested a review from PaddleStroke December 2, 2025 04:21
@PaddleStroke
Copy link
Contributor

Great thanks

@PaddleStroke
Copy link
Contributor

PaddleStroke commented Dec 2, 2025

However I think checking just the subobject is not ideal.
If I understand the code correctly, then now if you have :

Part (not selectable)

  • Box (selectable)

Then the box is selectable. No?

Then it is not good. If the parent container is set as not selectable then the child should also be not selectable.

Selectable should be acting like the Visibility property :
Objects within a container should be selectable only if his parents are recursively selectable.

@PaddleStroke
Copy link
Contributor

So I think the solution is rather to keep the topParent->isSelectable() function.
And override App::Part (or maybe OriginGroupExtension) ::isSelectable such that it checkes child objects

something like :

App::Part::isSelectable(subname)
{
    if (!this->isSelectable){
         return false;
    }
    childObj = this->getDocument()->getObject(subName.split[0])
    return childObj->isSelectable();
}

@PaddleStroke
Copy link
Contributor

Maybe it's worth checking how Visibility is doing it and just copying the same behavior

@PaddleStroke
Copy link
Contributor

Actually I just checked and in current main FreeCAD, App::Part do not have Selectable Property. Only in Realthunder's branch there is.

Yet again a feature that got lost in Linkstage and never got merged...

Additionally I have just tested in more details and found that :

Part

  • Box (Not selectable)
    Works OK.

Body (selectable)

  • Pad (Not selectable)
    OK

Body (Not selectable)

  • Pad (Not selectable)
    OK

Part

  • Body (Not selectable)
    • Pad (selectable)
      NOT OK

Part

  • Body (selectable)
    • Pad (Not selectable)
      OK

So what we learn here is that what is actually broken here is the Body's Selectable property.
It override the Tip's Selectable property only if body is the root object.

My guess is that all of this works properly in LinkStage. @realthunder

Currently if user selects object with `Selectable=false` property which
is nested inside a Part container, for example `Part->Body->Pad`, parent
Part container will get highlighted in the 3D view, even though the user
clicked on a non-selectable child object.

Cause of that is that tree view's `getTopParent()` function resolves
nested objects selections to their top-level container. When a Pad
inside Part is selected, `SoFCUnifiedSelection` was only checking Part's
`isSelectable()` status, even though the target is `Pad`.

So the fix is to resolve subname to get the final target object and
checks its `isSelectable()` status before checking for highlighting.
@tetektoza tetektoza force-pushed the fix/24290_respect_selectable_option_if_nested_objs branch from 68c9124 to 585e957 Compare December 26, 2025 12:52
@tetektoza
Copy link
Member Author

@PaddleStroke thanks for catching this and sorry for late reply, been busy last month. Could you recheck it? I decided to not port RT for now as I will be probably refactoring those parts of the code so I left area for improvement. I've just added a simple parents check for the currently selected object, so it will reject selection if parent is not selectable.

@tetektoza tetektoza force-pushed the fix/24290_respect_selectable_option_if_nested_objs branch from 25c85b5 to b44d754 Compare December 26, 2025 12:55
if (vp) {
if (selectionAction->SelChange.pSubName && selectionAction->SelChange.pSubName[0]) {
// get the entire object hierarchy from root to leaf
auto objList = obj->getSubObjectList(selectionAction->SelChange.pSubName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is obj included in objList? If not then you also need to check if obj is selectable.

Copy link
Member Author

@tetektoza tetektoza Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks like it is included:

res.push_back(const_cast<DocumentObject*>(this)); in DocumentObject::getSubObjectList.

@PaddleStroke
Copy link
Contributor

Sounds good I think. Although I have never used getSubObjectList before so I'm not sure how it behaves, but if it behaves as I think it should then it's a convenient helper that I just learned about.

Then we can also add a Selectable property to App::Part and override App::Part::isSelectable and it should all work with your current code I think.

Change `ViewProviderPart` to inherit from `ViewProviderGeometryObject`,
giving Part containers the Selectable property. This allows recursive
selectability checks to respect the entire container hierarchy.
@tetektoza
Copy link
Member Author

@PaddleStroke I've implemented this in a separate commit by changing ViewProviderPart to inherit from ViewProviderGeometryObject (instead of ViewProviderDragger).

This adds the property to Part containers, since it is inherited from ViewProviderGeometryObject, and also gives the override of isSelectable() as it is already implemented in ViewProviderGeometryObject class. But you can double check.

@PaddleStroke
Copy link
Contributor

I've implemented this in a separate commit by changing ViewProviderPart to inherit from ViewProviderGeometryObject (instead of ViewProviderDragger).

Oh wait I am already doing that in a PR : https://github.com/FreeCAD/FreeCAD/pull/26174/files#diff-afbda03a6d43c61b6d039dbc3e361c32f8481082209088e133135c40fda1ce5b

Although the conflict is quite minimal so it's no matter.

@tetektoza
Copy link
Member Author

@PaddleStroke Hmm.. want me to adapt or will you adapt the PR?

@PaddleStroke
Copy link
Contributor

You can leave it, it'll be a small conflict no problem.

@tetektoza
Copy link
Member Author

@PaddleStroke so, is the patch alright? Can we merge this soon?

@PaddleStroke
Copy link
Contributor

It looks good to me.

@maxwxyz maxwxyz added the Approved: Code Quality The PR was checked for code quality and approved label Dec 31, 2025
@maxwxyz maxwxyz moved this from Queue to Approved in Merge Queue Dec 31, 2025
@maxwxyz maxwxyz modified the milestones: 1.2, 1.1 Dec 31, 2025
@kadet1090 kadet1090 added the Requires: Testing The PR needs testing by users and developers label Jan 3, 2026
@maxwxyz maxwxyz added Approved: Tested The PR was manually tested and approved and removed Requires: Testing The PR needs testing by users and developers labels Jan 3, 2026
@chennes chennes merged commit 239567c into FreeCAD:main Jan 4, 2026
16 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in Merge Queue Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved: Code Quality The PR was checked for code quality and approved Approved: Tested The PR was manually tested and approved Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Type: Bug This issue or PR is related to a bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

PartDesign: Selectable not working on a Body in a Part

5 participants