[Solved] 0.19pre, auto off Draft grid on Sketcher edit mode

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

[Solved] 0.19pre, auto off Draft grid on Sketcher edit mode

Post by fc_tofu »

When Sketcher grid overlays on Draft grid, it's quite confusing and even annoying.
fsc_2020-02-10_212324.jpg
fsc_2020-02-10_212324.jpg (146.07 KiB) Viewed 4387 times
fsc_2020-02-10_212306.jpg
fsc_2020-02-10_212306.jpg (135.19 KiB) Viewed 4387 times
There is already 3 ways to toggle on/off Draft grid display,
1. Preferences, setup Draft grid auto on/off
2. DraftWB, with menu/button
3. within other workbench, accel key
But here is a exception scenario, Sketcher edit mode.
fsc_2020-02-10_212436.jpg
fsc_2020-02-10_212436.jpg (154.36 KiB) Viewed 4387 times
fsc_2020-02-10_212445.jpg
fsc_2020-02-10_212445.jpg (108.63 KiB) Viewed 4387 times
Once you have entered here and find Draft grid on, you cannot toggle it off with above methods (even the accel key is hijacked by Sketcher accel key). You have to do,
step 1. exit edit mode,
step 2. toggle off Draft grid with accel key,
setp 3. enter back edit mode.
Maybe a little tedious.

My suggestion is,
1. when receiving the command to enter Sketcher edit mode, check Draft grid status and record it.
2. if Draft grid is on, toggle it off.
3. if Draft grid is off, go on.
4. enter Sketcher edit mode
...
5. when exit edit mode, restore Draft grid status (recorded in step 1) back.

Hope some discussions follow my suggestion.
Last edited by fc_tofu on Sat Mar 07, 2020 4:38 pm, edited 1 time in total.
chrisb
Veteran
Posts: 54288
Joined: Tue Mar 17, 2015 9:14 am

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by chrisb »

Not using Sketcher grid at all I have the strong feeling that it could very well be the same grid as in Draft. Furthermore it should be an editing aid which should not be hooked to the sketch.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by fc_tofu »

chrisb wrote: Mon Feb 10, 2020 5:36 pm Not using Sketcher grid at all I have the strong feeling that it could very well be the same grid as in Draft. Furthermore it should be an editing aid which should not be hooked to the sketch.
Same working plane and same grid for DraftWB and Sketcher?
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by vocx »

chrisb wrote: Mon Feb 10, 2020 5:36 pm Not using Sketcher grid at all I have the strong feeling that it could very well be the same grid as in Draft...
This is not right. The Draft grid is created by some code inside the Draft Workbench, maybe inside DraftGui.py.

The Sketcher grid is something all planar 2D objects have. All such objects are derived from a class called Part_Part2DObject.

It seems this class defines some sort of internal grid. This internal grid is not really used by Draft objects. I suspect for Sketches this is the grid that you see when you edit the Sketch.

Code: Select all

obj = App.ActiveDocument.addObject("Part::Part2DObject")
obj.ViewObject.ShowGrid = True

obj2 = App.ActiveDocument.addObject("Sketcher::SketchObject")
obj2.ViewObject.ShowGrid = True
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.
chrisb
Veteran
Posts: 54288
Joined: Tue Mar 17, 2015 9:14 am

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by chrisb »

I still cannot see an argument, why from a user's point of view not the same grid should be used. Implementation could be tweaked; it can be an explanation why things are the way they are, but it should not be an argument why they must stay so.
I am unsure though as far as the working plane is involved.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by vocx »

chrisb wrote: Sat Feb 15, 2020 9:11 pm I still cannot see an argument, why from a user's point of view not the same grid should be used. ...
A sketch is a sort of container. It contains geometrical shapes, namely, lines, arcs, splines, etc. They are tied to each other by means of constraints (the ending of this line should be the beginning of that other line...). They need to be referred to the same origin, and thus they all use the same grid.

Draft objects exist freely, so they use the global coordinate system to position their points. Therefore, they need a "global grid" to which you can attach those shapes. This global grid is created by the Draft Workbench, and is independent of any object. The same thing with the working plane, the Draft Workbench defines such global working plane. All planar objects, Draft and sketches, they have their own internal working plane.

The distinction is a bit like Part and PartDesign. In Part, the objects can be placed freely in the 3D view as they use the global coordinate system. In PartDesign, the individual features use the Origin of the PartDesign Body as reference.
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.
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by fc_tofu »

vocx wrote: Sat Feb 15, 2020 9:47 pm
chrisb wrote: Sat Feb 15, 2020 9:11 pm I still cannot see an argument, why from a user's point of view not the same grid should be used. ...
A sketch is a sort of container. It contains geometrical shapes, namely, lines, arcs, splines, etc. They are tied to each other by means of constraints (the ending of this line should be the beginning of that other line...). They need to be referred to the same origin, and thus they all use the same grid.

Draft objects exist freely, so they use the global coordinate system to position their points. Therefore, they need a "global grid" to which you can attach those shapes. This global grid is created by the Draft Workbench, and is independent of any object. The same thing with the working plane, the Draft Workbench defines such global working plane. All planar objects, Draft and sketches, they have their own internal working plane.

The distinction is a bit like Part and PartDesign. In Part, the objects can be placed freely in the 3D view as they use the global coordinate system. In PartDesign, the individual features use the Origin of the PartDesign Body as reference.
Very thank your detailed explanation. I need some time to digest it.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by vocx »

The code that turns on and off Draft's grid is a class called the Snapper. This class is initialized when we first switch to the Draft Workbench. Then the Snapper lives inside the FreeCADGui namespace.

This means that Sketcher's code needs to be augmented in the following way. When we enter the edit mode of the Sketch, we need to test for the Snapper, and turn off the grid.

Code: Select all

if hasattr(FreeCADGui,"Snapper"):
    if FreeCADGui.Snapper.grid:
        if FreeCADGui.Snapper.grid.Visible:
            FreeCADGui.Snapper.grid.off()
            FreeCADGui.Snapper.forceGridOff=True
When we exit the Sketch, we could do the opposite and re-activate it.

Code: Select all

if hasattr(FreeCADGui,"Snapper"):
    if FreeCADGui.Snapper.grid:
        FreeCADGui.Snapper.grid.on()
        FreeCADGui.Snapper.forceGridOff=False
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.
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by fc_tofu »

vocx wrote: Mon Feb 17, 2020 5:45 pm The code that turns on and off Draft's grid is a class called the Snapper. This class is initialized when we first switch to the Draft Workbench. Then the Snapper lives inside the FreeCADGui namespace.

This means that Sketcher's code needs to be augmented in the following way. When we enter the edit mode of the Sketch, we need to test for the Snapper, and turn off the grid.

Code: Select all

if hasattr(FreeCADGui,"Snapper"):
    if FreeCADGui.Snapper.grid:
        if FreeCADGui.Snapper.grid.Visible:
            FreeCADGui.Snapper.grid.off()
            FreeCADGui.Snapper.forceGridOff=True
When we exit the Sketch, we could do the opposite and re-activate it.

Code: Select all

if hasattr(FreeCADGui,"Snapper"):
    if FreeCADGui.Snapper.grid:
        FreeCADGui.Snapper.grid.on()
        FreeCADGui.Snapper.forceGridOff=False
ATM, your code is what I mean. In python console, I tested it worked ok.
Can you give a fixed .py file to apply into my current FreeCAD_0.19.19510_x64_LP_12.1.2_PY3QT5-WinVS2015?
Thank you.

In the long run, if same set of workingplane/grid (and/or other aid tools, ie, LCS) can be merged into FreeCAD "core" and shared between modeling workbenches, just like navigation cube has already done, both coders and non-coders would welcome, IMHO.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: 0.19pre UI suggestion, auto off Draft grid on Sketcher edit mode

Post by triplus »

As for Sketcher and Draft grid. I personally rarely use them. First got an impression the question is about having them turn off by default.

In Sketcher there is a persistent setting, to turn the Sketcher grid off. In Draft, whenever Draft workbench gets activated, the grid will show. And it's expected for the people to turn it off, before going in a workbench like Sketcher. As if going in a workbench like Arch, people that actually do use Draft grid, there it should stay visible. As there is already a command available, to control the Draft grid visibility, i feel that it doesn't make much sense to go any further and to introduce some workbench specific show and hide filters. As in that case some people might start to wonder, on why does the Draft grid show up or hide randomly.
Post Reply