-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Sketcher: Snap initial implementation. #8387
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: Snap initial implementation. #8387
Conversation
687cd34
to
33917ea
Compare
c9bf39e
to
8d91249
Compare
I took a initial fast look to the code. I have not compiled yet. I did not go into the detail of the code. However, it looks reasonably good. There is one aspect that could be improved. The code is checking the parameter preferences on every function execution (hgrp + getint). This is unnecessary, as a parameter observer can update local variables used in the functions when they change. This leads to faster and more readable code. You have similar code here:
Basically, this class does the following:
A nested class can access private members of the outer class. So if you make the observer as a nested class, you can directly change local private variables of the outer class (the SnapManager). Do you feel like making this improvement? |
@abdullahtahiriyo yes it's ok. I will implement the parameter observer if it is helpful. |
Thanks. It will be helpful and you will get a performance gain in sections where snapping gets called intensively, as you won't need to access parameters in each iteration. |
@abdullahtahiriyo Do I keep the static map structure even though there're only 2 parameters and the code would be much simpler without? Let me know what you prefer. Edit: I used the same structure as coinmanager in the end. If you prefer otherwise let me know. |
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.
End of first review. Code review only, didn't tried to compile yet (hopefully other will do :p).
I should say it was very pleasant. Could have been a bit more commented in places where there are some tricky maths, but this is how a PR should look.
I guess it's the maximum size for it to be "easy to reviewed". But the code is well structured, at all levels. It makes it easy to review, and beyond "easy to merge" because maintainer isn't feared what will happen if it introduces a bug,. It will be well contained, and probably easy to solve.
Congrats. Keep up the good work, and if you're looking for other bones to eat, tell me. ;)
QList<QAction*> acts = ui->settingsButton->actions(); | ||
|
||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/General"); | ||
hGrp->SetBool("SnapToObjects", acts[0]->isChecked()); |
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.
Better to use same code structure as function just below.
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.
What do you mean?
isNamingBoxChecked = acts[1]->isChecked();
is not needed because the value is not used anywhere in the widget.
slotElementsChanged();
is not needed either.
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.
There are 2 functions that do same thing. Better if they do it the same way, whatever it is.
I missed your question from two days ago. I prefer the map solution because of its scalability and uniform initilisation/change. I have a strong preference to merge first the grid PR and then this. But if I do not manage to move forward the grid PR this weekend, then I will jump to this PR. |
Compilation throws a warning regarding the initialisation order. Take a look to the CI/Ubuntu 22-04 line 4367. |
f890aee
to
a2f8479
Compare
a2f8479
to
ccfb9c2
Compare
…ss. - Move grid snap to this new class. - Add snap to object. - Add snap at angle.
…erent from class declaration
…e other snap flags
…ls to retrieve preference parameters
We got some kind of messy history in the commits. I am rebasing to master and will force-push it as soon as I ensure it is building properly. |
ccfb9c2
to
2d041f5
Compare
Ok. Now take a look and let me know. |
Got it I will check it out (this evening probably). |
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.
Looks good. Thanks for sharing the different commits separated it's very informative.
Fantastic effort! |
Thanks guys for reviewing! |
The priority order is : snap at angle, then snap to object, then snap to grid. This is the order that makes sense in term of UX.
Future improvement ideas :
1 - Enable snapping to object when dragging a point.
2 - Snap to inifite lines rather than line segment.
3 - Snap to bisecting angles between 2 lines.
https://forum.freecad.org/viewtopic.php?t=75856
Thank you for creating a pull request to contribute to FreeCAD! Place an "X" in between the brackets below to "check off" to confirm that you have satisfied the requirement, or ask for help in the FreeCAD forum if there is something you don't understand.
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.