Draft Grid: improvements

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: 8456
Joined: Thu Dec 27, 2018 12:28 pm

Draft Grid: improvements

Post by Roy_043 »

The Draft Grid has a number issues:
  1. If you have an open document and switch to the Draft Workbench the grid is displayed (if the "Always show the grid" preference is checked), but not aligned with the working plane.
  2. If the Draft Workbench is active and you open a new document, or a new 3D view, the grid is not automatically displayed.
  3. In such a case two clicks on the Draft_ToggleGrid button are required to switch the grid on.
  4. When switching to a different workbench the grid remains visible which typically confuses novice FreeCAD users.
  5. When changing the grid via the Draft_SelectPlane command the grid is not switched on automatically.
The attached code tries to improve these issues:
  1. DraftWorkingPlane.setup() is called where appropriate so that the working plane is correct before calling grid.set().
  2. A 'view observer' is introduced to monitor the creation of new 3D views and the activation of existing 3D views. See: https://forum.freecadweb.org/viewtopic. ... 10#p566416. Via this 'observer' a grid is added to views that do not have one.
  3. The grid attached to a view stores its own always_show property. The initial value of this property is based on the "Always show the grid" preference. Draft_ToggleGrid changes this property for the current view only.
  4. When switching to a different workbench all grids are hidden. When switching back to the Draft Workbench, grids that were previously displayed are shown again. Views that were created while another workbench was active are handled by the 'view observer'.
  5. If the properties of the grid are changed with the Draft_SelectPlane command the grid is switched on.
If the "Use grid" preference is on, and the "Always show the grid" preference is off, a newly created view will have a grid with its always_show property set to False, and the grid is not displayed. In such a view the grid is only displayed when there is an active Draft command and Draft_Snap_Grid is switched on.

IMO we should consider removing the "Use grid" preference.

The attached ZIP contains the following file:
gui_edit.py
gui_grid.py
gui_snapper.py
gui_trackers.py
gui_utils.py

The gui_utils.py file goes in Mod/Draft/draftutils/ all other files go in Mod/Draft/draftguitools/.
For reference the Org folder in the ZIP contains the original files.
Attachments
Draft_grid_improvements.zip
(89.01 KiB) Downloaded 77 times
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: Draft Grid: improvements

Post by thomas-neemann »

Roy_043 wrote: Fri Sep 02, 2022 12:00 pm ...
Many Thanks
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
balrobs
Posts: 449
Joined: Fri Apr 24, 2020 8:58 pm

Re: Draft Grid: improvements

Post by balrobs »

Roy_043 wrote: Fri Sep 02, 2022 12:00 pm ...
Annoying issues with:

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.30089 (Git)
Build type: Release
Branch: master
Hash: 335196a468fcf069f365dcbb24279a8295cc4683
Python 3.10.5, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.2
Locale: German/Germany (de_DE)
Installed mods: 
  * Assembly3 0.11.3
  * BIM 2021.12.0
  * ExtremeProDark 1.0.4
  * FreeCAD_SketchArch
  * Help 1.0.3
  * ProDarkThemePreferencePack 1.0.0
  * Pyramids-and-Polyhedrons
  1. confirmed
  2. confirmed
  3. confirmed
  4. confirmed
  5. confirmed
Testing of draft grid improvements:
  1. fixed
  2. fixed
  3. fixed
  4. fixed
  5. fixed
Your improvements make a lot sense to me.
Thanks for your effort!
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: Draft Grid: improvements

Post by heron »

Hello, I was testing the fix and I get an error having the both options "Use grid" and "Always show the grid" disabled. When hitting the Daft_ToogleGrid button I get:

Code: Select all

13:17:52  ----------------
13:17:52  GuiCommand: Toggle grid
13:17:52  Running the Python command 'Draft_ToggleGrid' failed:
Traceback (most recent call last):
  File "C:\Program Files\FreeCAD_weekly-builds-30492-2022-10-09-conda-Windows-x86_64-py310\Mod\Draft\draftguitools\gui_grid.py", line 80, in Activated
    if view_grid.Visible:

'NoneType' object has no attribute 'Visible'

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.30492 (Git)
Build type: Release
Branch: master
Hash: b4578fb3eae842eb510a1bc055d07d369a67ce94
Python 3.10.6, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United States (en_US) [ OS: Spanish/Spain (es_ES) ]
Installed mods: 
  * Assembly4 0.12.4
  * BIM 2021.12.0
  * Curves 0.5.8
  * DynamicData 2.46.0
  * ExtremeProDark 2.0.0
  * ExtremeProDark.backup1663693999.0253184
  * fasteners 0.4.6
  * fcgear 1.0.0
  * Help 1.0.3
  * InvGears 0.1.2
  * Manipulator 1.4.9
  * ProDarkThemePreferencePack 1.0.0
  * ProDarkThemePreferencePack.backup1663694123.8106258
  * ratchetWB 0.1.0
  * Render 2022.2.0
  * sheetmetal 0.2.57
  * Woodworking 0.20.29177
Edit: No tested in 0.20.1
Roy_043 wrote: Fri Sep 02, 2022 12:00 pm IMO we should consider removing the "Use grid" preference.
I agree, at this point, the two options and their possible combinations don't make much sense, probably making it simpler would be easier to fix.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Draft Grid: improvements

Post by yorik »

I was always reluctant to introduce a document observer in draft, but my arguments against it were getting weaker everyday :) And indeed we need to fix this issue.

Two other additional questions I would like to attack too:

- Should we maintain the "one single working plane across all open documents" or switch to a "one different working plane per document" or even "one different working plane per view" paradigm?

- Should we store the working plane in the document? (for ex. in the document.Meta) and restore it on load?
User avatar
thomas-neemann
Veteran
Posts: 11801
Joined: Wed Jan 22, 2020 6:03 pm
Location: Osnabrück DE 🇩🇪
Contact:

Re: Draft Grid: improvements

Post by thomas-neemann »

yorik wrote: Mon Oct 17, 2022 8:24 am ...
i think it's good to have one working-plane per document that is saved with it.
Gruß Dipl.-Ing. (FH) Thomas Neemann

https://www.youtube.com/@thomasneemann5 ... ry=freecad
chrisb
Veteran
Posts: 53945
Joined: Tue Mar 17, 2015 9:14 am

Re: Draft Grid: improvements

Post by chrisb »

One working plane per document could be nice. I don't need it stored. If I need a certain orientation, I place the mode accordingly.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Palmtree
Posts: 104
Joined: Wed Apr 08, 2020 5:06 am

Re: Draft Grid: improvements

Post by Palmtree »

balrobs wrote: Fri Sep 02, 2022 2:46 pm
Roy_043 wrote: Fri Sep 02, 2022 12:00 pm Your improvements make a lot sense to me.
Thanks for your effort!
I strongly agree, Many thanks @Roy_043
User avatar
Roy_043
Veteran
Posts: 8456
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft Grid: improvements

Post by Roy_043 »

yorik wrote: Mon Oct 17, 2022 8:24 am "one different working plane per view" paradigm?
IMO this would make sense. But it raises a number of questions:
  1. Should the grids in the views belonging to the same document be allowed to have different grid spacings? Or would that be too confusing?
  2. How should grid preferences be handled? Should the view that is closed last overwrite the grid preferences and should its grid settings be stored in the document?
User avatar
Roy_043
Veteran
Posts: 8456
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft Grid: improvements

Post by Roy_043 »

Many thanks to all who have test the code.

heron wrote: Sun Oct 16, 2022 12:18 pm Hello, I was testing the fix and I get an error
I'll try to fix that.
Post Reply