[ Fixed ] Draft snap toolbar: several issues

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft snap toolbar: several issues

Post by Roy_043 »

Renamed this topic from:
[ Bug ] Draft snap toolbar: wrong highlighting when starting without user.cfg
To:
Draft snap toolbar: several issues
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft snap toolbar: several issues

Post by Roy_043 »

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:

Code: Select all

param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
param.Get*()
Is this correct? Another approach might be to keep and enhance the Draft.getParam() function (to handle the defaults and also validate the parameters).
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft snap toolbar: several issues

Post by Roy_043 »

Update of issues (the first two have already been mentioned):
  1. Wrong highlighting when starting without user.cfg.
  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.
  3. The '_tip' texts in gui_snaps.py are not displayed in the GUI.
  4. Adding a Snap button to a custom toolbar is possible but this button will not be toggled.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft snap toolbar: several issues

Post by Roy_043 »

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:
  1. Make sure the Snap commands can be executed if there is no active document. This matches the V0.18 behavior.
  2. Disable the Snap toolbar and the Snap statusbar if there is no active document.
2.A
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))
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.
Attachments
Draft_Toolbar_DocumentObserver.py
(1.36 KiB) Downloaded 30 times
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft snap toolbar: several issues

Post by Roy_043 »

Issue 1: Wrong highlighting when starting without user.cfg.
https://github.com/FreeCAD/FreeCAD/pull/3834
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft snap toolbar: several issues

Post by Roy_043 »

PR #3834 for issue 1 has been merged.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft snap toolbar: several issues

Post by Roy_043 »

Roy_043 wrote: Mon Aug 31, 2020 1:22 pm 2.A
Solution A is relatively easy to implement.
2.A1:
All that is required is adding a new class to gui_base.py.
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.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Draft snap toolbar: several issues

Post by vocx »

Roy_043 wrote: Fri Sep 18, 2020 10:21 am 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. ...
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.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Draft snap toolbar: several issues

Post by carlopav »

vocx wrote: Fri Sep 18, 2020 10:35 pm If you want to go inside the Snap modes and DraftGui.py, go ahead, but it's a convoluted piece of code.
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
User avatar
vanuan
Posts: 539
Joined: Wed Oct 24, 2018 9:49 pm

Re: Draft snap toolbar: several issues

Post by vanuan »

carlopav wrote: Sat Sep 19, 2020 11:30 am ...
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
Post Reply