New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sketcher: Add concentric capabilities to coincidence constraint. #7703
Conversation
66ca9e6
to
37564f6
Compare
@@ -2033,42 +2046,67 @@ void CmdSketcherConstrainCoincident::activated(int iMsg) | |||
|
|||
void CmdSketcherConstrainCoincident::applyConstraint(std::vector<SelIdPair> &selSeq, int seqIndex) | |||
{ | |||
SketcherGui::ViewProviderSketch* sketchgui = static_cast<SketcherGui::ViewProviderSketch*>(getActiveGuiDocument()->getInEdit()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a stylistic comment, you don't have to change it here, but in future code: when using static_cast
, dynamic_cast
, etc. where we already explicitly state the type, that's a good place to use auto
for the variable definition. Sort of a micro-example of the DRY principle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has just been moved.
But I take note of your message. I will try to use auto in those situation in the future.
If I come accross such occurence while making a PR, should I always fix such things along?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to make a general statement about it: knowing now that this code was simply relocated, then no, I'd say leave it alone. Switching to auto
is a minuscule change that makes almost no practical difference, so the very small increase in readability is not worth complicating the review. On the other hand, if you ran across an old-style for loop, and you were already touching that line of code for some other reason, then I'd say yes, let's go ahead and switch to a ranged-for. Brand new code is different, but working with old code IMO there's more wiggle room. There isn't a "policy" either way, we just discuss it in the PR review process and come to a consensus. You are always welcome to push back and tell me why you don't think a particular suggestion makes sense in this particular context: I won't take it personally, we're both trying to make incremental improvements to the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me, I like the re-use of the coincident constraint here. A little bit of refactoring to reduce code duplication and this should be good to go.
geo->getTypeId() == Part::GeomCircle::getClassTypeId() || | ||
geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId())) { | ||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), | ||
QObject::tr("Select two vertices from the sketch. Or two circles, ellipses, arcs or arcs of ellipse for concentric constraint.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest a slight wording change:
QObject::tr("Select two vertices from the sketch. Or two circles, ellipses, arcs or arcs of ellipse for concentric constraint.")); | |
QObject::tr("Select two vertices from the sketch for a coincident constraint, or two circles, ellipses, arcs or arcs of ellipse for a concentric constraint.")); |
and since it's used twice, it's probably best to create it above and re-use it, e.g.
const QString errorMessage = QObject::tr("Select two vertices from the sketch for a coincident constraint, or two circles, ellipses, arcs or arcs of ellipse for a concentric constraint.");
...
QMessageBox::warning (Gui::getMainWindow(), QObject::tr("Wrong selection"), errorMessage );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really, this whole code block has a lot of nearly identical lines. Maybe create a function that takes a Geometry *
and returns whether it is "concentric-capable"? You could even make it a lambda right inside applyConstraint
, if it really wasn't needed anywhere else in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also in activated()
I thought about making a function, but wasn't sure where to put the function.
I thought about lambda in applyConstraint, but then the occurence in activated is left behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok just on top of the file I guess. There are a few other functions like this there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - probably in an anonymous namespace, just like the other PR. That will help cut down on what's already a beast of a file!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other functions aren't in anonymous namespace. So doing so would break homogeneity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm unsure. What do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say don't worry about the anonymous namespace bit for now: it's relatively recent modern C++ coding advice that we should seek to follow when it's reasonable to do so, but don't stress ourselves out over. Someday maybe someone will decide to do a cleanup pass on this file and address some of the linter issues, and they can put all of those functions in an anonymous namespace then. It's not glamorous work, but it's also pretty low-hanging fruit 😄 .
37564f6
to
c1c168e
Compare
I just fixed the sentence, and added the function to remove code repeat and forced pushed. |
c1c168e
to
129011e
Compare
I forgot your comment for the tooltip. I jsut added it and re-force-pushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great now, thanks! I'm going to wait for the CI to complete before merging, but it compiles, runs, and behaves correctly on MSVC/Win11.
@PaddleStroke This PR introduced severe regression.
This virtually is the case with any conic + any point selected. |
Fixed in : #7794 |
Wiki pages about Coincident constraint and Release notes to be updated |
@luzpaz can you please check and let me know if those changes are correct? Don't hesitate to modify if necessary. |
What is important is that information about changes is pushed there. Then we have awesome people working on the wiki and they eventually can fix wording and so on (the good strategy IMO is that you learn from what these regulars fix).
|
Enable the coincidence tool to select edges. If those edges are circle, ellipse, arc or arc of ellipse, then it create concentric constraint.
#7546 (comment)
Thank you for creating a pull request to contribute to FreeCAD! To ease integration, we ask you to conform to the following items. Pull requests which don't satisfy all the items below might be rejected. If you are in doubt with any of the items below, don't hesitate to ask for help in the FreeCAD forum!
App
,Base
,Gui
or one of theMod
subfolders. If you need to make changes in several locations, make several pull requests and wait for the first one to be merged before submitting the next onesgit pull --rebase upstream master
./bin/FreeCAD --run-test 0
Fixes typo in Draft Move command text
Draft: Fixed typos
issue #<id>
orfixes #<id>
where<id>
is the issue ID number from our Issues database in case a particular commit solves or is related to an existing issue. Ex:Draft: fix typos - fixes #4805
And please remember to update the Wiki with the features added or changed once this PR is merged.
Note: If you don't have wiki access, then please mention your contribution on the 1.0 Changelog Forum Thread.