PD: Add experimental ability to disable single-solid rule#13960
PD: Add experimental ability to disable single-solid rule#13960adrianinsaval merged 5 commits intoFreeCAD:mainfrom
Conversation
|
Would love to have this! This was the best thing from Linkstage! |
a16dbd2 to
b2e54d8
Compare
|
After discussion on discord I changed UI to be more descriptive - screenshot in description got updated. |
|
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. |
src/Mod/PartDesign/App/Feature.cpp
Outdated
| .GetUserParameter() | ||
| .GetGroup("BaseApp/Preferences/Mod/PartDesign"); | ||
|
|
||
| return static_cast<Feature::SingleSolidRuleMode>(hGrp->GetInt("SingleSolidRule", int(SingleSolidRuleMode::Enforced))); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes I was referring to adding it to the Body class
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, making it in the experimental group should be enough of a warning. At least I hope so!
|
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 |
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. |
|
do you wish to merge this first and then do the rework or will you be doing that in this PR? |
|
This PR - it is easy to rework, I'll probably tackle that in few hours |
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.
b2e54d8 to
2c33f97
Compare
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
2c33f97 to
8d4be90
Compare
|
For some reason this PR makes the Pad test to fail. Have you checked why this is the case? |
4ef9605 to
d346ba9
Compare
|
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. |
|
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. |
|
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. |
|
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
|
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. |
|
Can't wait for this feature. Which release will be the first to have it? |
It’s already there in weekly builds for quite some time. I mentioned it in the release notes. |
|
Ah. It's actually there, hadn't read the need for activation at the body as well. |

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 Compoundboolean Body property. Default value of this proparty that can be changed from the GUI in the preferencesPart/Part Design / Generalpage.Technically it implements two modes:
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.