Sketcher: contextual right click context menu based on selection#11884
Sketcher: contextual right click context menu based on selection#11884WandererFan merged 1 commit intoFreeCAD:mainfrom
Conversation
|
A first comment on the functionality :
|
PaddleStroke
left a comment
There was a problem hiding this comment.
I have not finished reviewing. Tomorrow I will check the core of the feature
|
Overall very good, it seems you are learning fast and your contribution is smart. Thanks for contributing ! By the way, to ease your life, here is the code block with the modifications I offered. I have not tested so please do. To make special cases of line vs circle, have a look at how to get the geometry from the name in sketcher_dimension tool (see line 1510 of CommandConstraints.cpp, function handleInitialSelection) |
|
@maxwxyz I have just edited my previous block of code to integrate counting edges and conics. I let you adapt the menu based on these values. |
|
If you want finer control than line vs conics, you can add more variables : |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
Ok maybe the macos build failure is unrelated to your PR then. Btw one last thing, this feature is adding a lot of lines of code to the mouseButtonPressed function. So please make a new function to put all this new code in, for example : |
|
@PaddleStroke Thanks for reviewing.
off-topic: Fillet/Trim/Extend edge does currently not work with a pre-selection. Is this already in progress or should I create an issue? |
This comment was marked as resolved.
This comment was marked as resolved.
|
@maxwxyz do you actually need those additional lines in ViewProviderSketch.h ? |
This comment was marked as resolved.
This comment was marked as resolved.
|
@maxwxyz it's going to be a few hours before I have more than one CPU core free as I'm doing a Git Bisect from 2021 to trace a bug. If it's still not solved then I'll compile your PR just to make sure I get the same error as being reported in the CI builds. |
This comment was marked as resolved.
This comment was marked as resolved.
There's always some 'specifics' with Linux that Windows compiling won't highlight, that's why the CI's are across platforms though I don't have a lot of confidence in the Mac one at present. |
c00d98e to
2d6e18f
Compare
|
Please fix my last comment (and squash the change), then compile and make sure everything works as expected. Then I think it's ready to merge @chennes. |
2d6e18f to
09f6a2b
Compare
|
@PaddleStroke @chennes done and thanks! |
|
Ah sorry one thing I missed : Can be simplified to : |
09f6a2b to
55a6e7f
Compare
|
all done |
55a6e7f to
195813b
Compare
| { | ||
| return editCoinManager != nullptr; | ||
| } | ||
| void ViewProviderSketch::generateContextMenu() |
There was a problem hiding this comment.
I'm OK with merging this code as-is, and I know there is a LONG history in FreeCAD of methods that look like this, but IMO it should really be something like eight individual methods, so would look something like:
void ViewProviderSketch::generateContextMenu()
{
// I'm using structured bindings here, but you could write countSelection in a number of different ways
// to achieve the same basic idea...
const auto [selectedEdges, selectedLines, selectedConics, selectedPoints, selectedConstraints] = countSelection();
if (selectedEdges >= 1 && selectedPoints == 0) {
setContextMenuForEdges(menu, selectedConics, selectedLines);
} else if (selectedEdges == 1 && selectedPoints >= 1) {
setContextMenuForOneEdgeAndPoints(menu, selectedConics, selectedPoints);
}
// and so forth, for each of your top-level conditionals -- the functions can be local
// to the CPP file, in an anonymous namespace, since they don't need access to `this`
}
There was a problem hiding this comment.
@chennes shall I redo it or do it like this for future PRs?
There was a problem hiding this comment.
But then you are creating a lot of functions which are cluttering VPSketch. Even if only the cpp file.
So the solution might be to create a class in another file to handle this. But it seems a bit overkill. And also Max is a new c++ contributor asking him that wouldn't be easy.
So perhaps we can keep like this for now? This function is long but only because of the menu names taking many lines not because of complexity.
There was a problem hiding this comment.
I'd also say that this is fine. Every branch of the if consists basically of one statement - which is pretty long but it still is one statement. Introducing more functions into that case would be harder to maintain as every added or removed scenario will require adding or removing a function which won't be reusable anyways as it is so specific.
|
Congrats on a nice feature @maxwxyz |




fixes #11818
This PR introduces a contextual right click context menu in the Sketcher WB which shows different commands based on the selection of the user (none, one or multiple geometry elements, or constraints).
The current context menu is static and is overloaded with commands which are either greyed out or not working in Sketcher.
New:
sketcher-context-menu.mp4
Old:
