[ Fixed ] Draft snap toolbar: several issues
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Draft snap toolbar: several issues
Renamed this topic from:
[ Bug ] Draft snap toolbar: wrong highlighting when starting without user.cfg
To:
Draft snap toolbar: several issues
[ Bug ] Draft snap toolbar: wrong highlighting when starting without user.cfg
To:
Draft snap toolbar: several issues
Re: Draft snap toolbar: several issues
Looking at the gui_snapper.py file I notice that the Draft.getParam() function is also used to retrieve parameters. Apparently these calls are to be replaced by:
Is this correct? Another approach might be to keep and enhance the Draft.getParam() function (to handle the defaults and also validate the parameters).
Code: Select all
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
param.Get*()
Re: Draft snap toolbar: several issues
Update of issues (the first two have already been mentioned):
- Wrong highlighting when starting without user.cfg.
- If there is no active document it is possible to click buttons in the snap toolbar or in the statusbar snap section (flyout). This will only toggle the clicked button, and not the corresponding button in the other GUI element, nor will it change the button's snap value.
- The '_tip' texts in gui_snaps.py are not displayed in the GUI.
- Adding a Snap button to a custom toolbar is possible but this button will not be toggled.
Re: Draft snap toolbar: several issues
2.
If there is no active document it is possible to click buttons in the snap toolbar or in the statusbar snap section (flyout). This will only toggle the clicked button, and not the corresponding button in the other GUI element, nor will it change the button's snap value.
To solve this 2nd issue there are two options:
Solution A is relatively easy to implement.
2.A1:
All that is required is adding a new class to gui_base.py.
This class is then simpler than GuiCommandSimplest. The classes in gui_base.py are a bit confusing anyway. The 'base' class is not used as the base for the other classes and does not have an Activated function.
2.A2:
Of course it is also possible to not use a class from gui_base.py when defining the Snap classes.
2.B
Solution B requires the use of a DocumentObserver I believe. I have been playing around with this option. See the attached code. If imported after starting the Draft WB the toolbars are correctly disabled/enabled based on the number of documents.
Before going on with this we should decide if we prefer solution 2.A or 2.B.
If there is no active document it is possible to click buttons in the snap toolbar or in the statusbar snap section (flyout). This will only toggle the clicked button, and not the corresponding button in the other GUI element, nor will it change the button's snap value.
To solve this 2nd issue there are two options:
- Make sure the Snap commands can be executed if there is no active document. This matches the V0.18 behavior.
- Disable the Snap toolbar and the Snap statusbar if there is no active document.
Solution A is relatively easy to implement.
2.A1:
All that is required is adding a new class to gui_base.py.
Code: Select all
class GuiCommandNoDoc:
def __init__(self, name="None"):
self.command_name = name
def Activated(self):
_log("GuiCommand: {}".format(self.command_name))
_msg("{}".format(16*"-"))
_msg("GuiCommand: {}".format(self.command_name))
2.A2:
Of course it is also possible to not use a class from gui_base.py when defining the Snap classes.
2.B
Solution B requires the use of a DocumentObserver I believe. I have been playing around with this option. See the attached code. If imported after starting the Draft WB the toolbars are correctly disabled/enabled based on the number of documents.
Before going on with this we should decide if we prefer solution 2.A or 2.B.
- Attachments
-
- Draft_Toolbar_DocumentObserver.py
- (1.36 KiB) Downloaded 30 times
Re: Draft snap toolbar: several issues
Issue 1: Wrong highlighting when starting without user.cfg.
https://github.com/FreeCAD/FreeCAD/pull/3834
https://github.com/FreeCAD/FreeCAD/pull/3834
Re: Draft snap toolbar: several issues
PR #3834 for issue 1 has been merged.
Re: Draft snap toolbar: several issues
IMO this is something that should be done. It is the simplest way to deal with issue #2, and would also restore the V0.18 behavior. But I am a bit hesitant to modify gui_base.py.
Re: Draft snap toolbar: several issues
The problem is that the Snap tools aren't typical commands, they are more like status buttons.
Simple commands execute an action (inside Activated) and return. The Snap toolbar is created manually inside DraftGui.py. When the button is pressed, it executes its command, but it has to remain pressed or unpressed depending on its status. The gui_base classes were not written with this in mind, they were written for the regular execute-and-return commands.
However, when Carlo rewrote the Snap modes and Snap commands, he made several changes. I've personally not touched this part, so I'm not entirely sure of the best way of handling this. In my opinion the Snap toolbar should be disabled without a current document, just like most tools in the workbench. The Snap modes react to Coin events in the 3D view, and if you accidentally try to use the 3D view with none being available (that is, without a document), it may crash the program, so this is the reason I prefer disabling the buttons altogether. Of course, it currently doesn't seem to crash so maybe this is already handled correctly in DraftGui.py.
If you want to go inside the Snap modes and DraftGui.py, go ahead, but it's a convoluted piece of code.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Draft snap toolbar: several issues
Yes, indeed. Sorry for being quite idle: i'm overwhelmed by work and it'll be like this for the next 2 months at least.
I would not recomend to have a document observer for snaps. And I also think that it's good if they are disabled when no active document is found. Before we changed them in the last year, the activation of snaps was quite convoluted: the Snapper had to check if the toolbar button was toggled to decide if the snap was active, and that seemd really odd to me. So now the Snapper holds a list of active snaps, and store them as before in the user Parameters.
When the user presses the button in the toolbar, the snap command is launched, and the snap command itself updates the toolbar. This makes possible to have more than one snap toolbar, and makes the Snap toolbar more similar to other FreeCAD toolbars.
Of course I may have messed up something if the toolbar is not initialized correctly. But it's just a matter of correct syncronization with the user parameters I guess...
Hope this convoluted explanation may be of some help.
follow my experiments on BIM modelling for architecture design
Re: Draft snap toolbar: several issues
A similar issue here:
https://forum.freecadweb.org/viewtopic.php?f=10&t=50475
The config option was added in this PR: https://github.com/FreeCAD/FreeCAD/pull/3228