Skip to content

PD: Add experimental ability to disable single-solid rule#13960

Merged
adrianinsaval merged 5 commits intoFreeCAD:mainfrom
kadet1090:disable-single-solid-rule
May 20, 2024
Merged

PD: Add experimental ability to disable single-solid rule#13960
adrianinsaval merged 5 commits intoFreeCAD:mainfrom
kadet1090:disable-single-solid-rule

Conversation

@kadet1090
Copy link
Member

@kadet1090 kadet1090 commented May 11, 2024

No squash please - I do take care about commits and they are structured in a way that allows to easily revert one change like GUI without affecting the rest.

Based on discussion in #9747 this is PR that adds experimental setting to disable the single solid rule enforcement. As far as I tested it works and does not cause any major problems.

It is exposed as Experimental / Allow Compound boolean Body property. Default value of this proparty that can be changed from the GUI in the preferences Part/Part Design / General page.

image

Technically it implements two modes:

  • enforced which is the current behavior,
  • disabled which disables single-solid checks and allows compound shapes as value of the body.

The code is structured in a way that should allow us to add third mode "Suggested" that will only warn user that operation will result in multiple solids which may not be the goal.

image

@github-actions github-actions bot added Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Mod: Part Design Related to the Part Design Workbench Mod: Part Related to the Part Workbench labels May 11, 2024
@MisterMakerNL
Copy link
Contributor

Would love to have this! This was the best thing from Linkstage!
Keep up the good work!!!!

@kadet1090 kadet1090 force-pushed the disable-single-solid-rule branch 3 times, most recently from a16dbd2 to b2e54d8 Compare May 12, 2024 16:29
@kadet1090
Copy link
Member Author

After discussion on discord I changed UI to be more descriptive - screenshot in description got updated.

@FEA-eng
Copy link
Contributor

FEA-eng commented May 12, 2024

Nice, I tested this and it works as expected. Too bad we won’t just have the single solid rule removed by default in 1.0 but this is much better than nothing.

.GetUserParameter()
.GetGroup("BaseApp/Preferences/Mod/PartDesign");

return static_cast<Feature::SingleSolidRuleMode>(hGrp->GetInt("SingleSolidRule", int(SingleSolidRuleMode::Enforced)));
Copy link
Contributor

Choose a reason for hiding this comment

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

The parameter "SingleSolidRule" can be set to an arbitrary value different to 0 or 1. Thus, a static cast to this enum type is unspecified or even undefined behaviour: https://wiki.sei.cmu.edu/confluence/display/cplusplus/INT50-CPP.+Do+not+cast+to+an+out-of-range+enumeration+value

Since the enum has only two values a simple boolean will be enough. Alternatively, defining two constant long int variables instead will work, too. The variables don't need to reside in the header file but can go to the source.
And singleSolidRuleMode() should be declared as private function.

But I wonder whether it's a good idea to make this behaviour dependent on a user parameter because it's clearly a code smell (the parameter adds global mutable state, direct dependencies to other classes is added, writing test code will be more complicated). And there is a practicable problem if a user has changed the default parameter and shares a project with another user who uses the default value. After a recompute the project will break if a feature has multiple solids.

Using a hidden PropertyBool instead solves these problems. IMO, it makes most sense to add this property to the class Body or BodyBase and not to PartDesign::Feature.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since the enum has only two values a simple boolean will be enough.

As said in the PR description - It is in preparation for additional mode that will allow multiple solids in body but warn user about creating such potentially unwanted situation. That's why it is enum value. I also personally dislike booleans as they are not very descriptive.

But I wonder whether it's a good idea to make this behaviour dependent on a user parameter because it's clearly a code smell (the parameter adds global mutable state, direct dependencies to other classes is added, writing test code will be more complicated). And there is a practicable problem if a user has changed the default parameter and shares a project with another user who uses the default value. After a recompute the project will break if a feature has multiple solids.

Yeah, I also thought about that. I'd still leave this option in the preferences as the default value used for new bodies but I can move this to the Body parameter. Then in fact it can be simple Boolean and the option warning users on this potentially unwanted scenario could be implemented globally.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think?

I prefer adding a hidden property to the Body (or BodyBase) class. But we can bring this back to the forum and wait for opinions of the user base.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I was referring to adding it to the Body class

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I also thought about that. I'd still leave this option in the preferences as the default value used for new bodies but I can move this to the Body parameter. Then in fact it can be simple Boolean and the option warning users on this potentially unwanted scenario could be implemented globally.

this seems like a better idea

Copy link
Member Author

Choose a reason for hiding this comment

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

@wwmayer I updated the code. I did implement it using normal (not hidden) PropertyBoolean on PartDesign::Body . I don't want to make it hidden as this would break the first of Nielsen’s Heuristics - Visibility of system status - causing possible confusion for users.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to make it hidden as this would break the first of Nielsen’s Heuristics - Visibility of system status - causing possible confusion for users.

No problem!

I only thought to make it hidden because it's considered as experimental at the moment and once it's considered stable I would have made it a regular property.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, making it in the experimental group should be enough of a warning. At least I hope so!

@adrianinsaval
Copy link
Member

I want to allow this but having this a preference is problematic because models made by someone who had enabled this will not work for others. I'm more in favor of generally allowing and offering a preference option to warn about multiple solids

@kadet1090
Copy link
Member Author

I want to allow this but having this a preference is problematic because models made by someone who had enabled this will not work for others

Once I rework it to be based on body property instead of global user setting it will be stored in the file so it won't be a problem anymore. Option in the preferences would only affect default setting of this property then.

@adrianinsaval
Copy link
Member

do you wish to merge this first and then do the rework or will you be doing that in this PR?

@kadet1090
Copy link
Member Author

This PR - it is easy to rework, I'll probably tackle that in few hours

@kadet1090 kadet1090 marked this pull request as draft May 13, 2024 19:12
This refactors a single solid rule checking code from using the solid
count directly to using well abstracted `isSingleSolidRuleSatisfied`
method. This makes code easier to read and is the basis for next step
which is allowing users to disable this checks.
@kadet1090 kadet1090 force-pushed the disable-single-solid-rule branch from b2e54d8 to 2c33f97 Compare May 14, 2024 20:11
This adds "SingleSolidRuleMode" enum that controls if PartDesign will
enforce singular solid. By default the single-solid is enforced so
nothing changes for the user, it must be explicitly disabled by setting
new Allow Compound boolean property on a given body.

Default for this value is controled using user parameter under
Mod/PartDesign/AllowCompoundDefault
@kadet1090 kadet1090 force-pushed the disable-single-solid-rule branch from 2c33f97 to 8d4be90 Compare May 14, 2024 20:32
@kadet1090 kadet1090 marked this pull request as ready for review May 14, 2024 20:37
@wwmayer
Copy link
Contributor

wwmayer commented May 15, 2024

For some reason this PR makes the Pad test to fail. Have you checked why this is the case?

@kadet1090 kadet1090 force-pushed the disable-single-solid-rule branch from 4ef9605 to d346ba9 Compare May 15, 2024 11:25
@kadet1090
Copy link
Member Author

I assumed that for PartDesign Feature there always will be body present - but as it seems that is not the case. Event if this is a bug in other place there is no reason to not check body for being nullptr. I fixed it - the test now works fine.

@bgbsww
Copy link
Contributor

bgbsww commented May 17, 2024

Reviewing the code here, it looks good. Question: has this been tested with a build with FC_USE_TNP_FIX set? I can't see any obvious issues, but it might be a useful data point. Also, those CI build failures look pretty spurious.

@kadet1090
Copy link
Member Author

kadet1090 commented May 18, 2024

CI failures for me seemed to come from another commit as more PRs failed on this step. Let's uprate it and check. Edit: it works now.

IIRC I have this flag enabled in my setup, but I will make sure tomorrow.

@adrianinsaval adrianinsaval merged commit 90a7778 into FreeCAD:main May 20, 2024
@duarteframos
Copy link

This sound pretty useful, great work.

From a UI perspective I think I'd prefer if the Property View read instead something along the lines of

Compound Body Allow, Forbid, Warn

@kadet1090
Copy link
Member Author

From a UI perspective I think I'd prefer if the Property View read instead something along the lines of

It was initially implemented like that, then we decided to change it to checkboxes. I don't think that warning preference should be stored alongside the body - I feel that it is pretty much user preference not something that should be set per body. However, this is something that should be discussed broader.

@herrdeh
Copy link

herrdeh commented Jun 19, 2024

Can't wait for this feature. Which release will be the first to have it?
My 37738 seems not...?

@FEA-eng
Copy link
Contributor

FEA-eng commented Jun 19, 2024

Can't wait for this feature. Which release will be the first to have it? My 37738 seems not...?

It’s already there in weekly builds for quite some time. I mentioned it in the release notes.

@herrdeh
Copy link

herrdeh commented Jun 19, 2024

Ah. It's actually there, hadn't read the need for activation at the body as well.
Thanks for extra dummy support... (;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Mod: Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Mod: Part Design Related to the Part Design Workbench Mod: Part Related to the Part Workbench

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants