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
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Draft Grid: improvements

Post by yorik »

Roy_043 wrote: Thu Oct 20, 2022 9:14 am IMO this would make sense. But it raises a number of questions:

Should the grids in the views belonging to the same document be allowed to have different grid spacings? Or would that be too confusing?
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?
Indeed we should think of how to implement this first. For me we should, somewhere, in the FreeCAD session, keep a table of all opened views + their working plane and grid settings (if we keep per-view working plane parameters, there is no reason to not keep grid settings too. Note that the grid coin object needs to be drawn for each view, so at the moment there is already (in the snapper IIRC) a structure to store several grid objects.

So at any moment, for a given view, we could query the table to know the working plane and grid settings to use. The grid itself is already redrawn frequently, basically at each Draft operation, but there might be a need for a more robust system to call a grid redraw.

At the moment we store the WP in FreeCAD.DraftWorkingPlane. We could change this with for ex. something like Draft.get_working_plane() so it becomes dynamic, it would return a different WP depending on the active document/view
drmacro
Veteran
Posts: 8984
Joined: Sun Mar 02, 2014 4:35 pm

Re: Draft Grid: improvements

Post by drmacro »

Roy_043 wrote: Fri Sep 02, 2022 12:00 pm 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.
With the current build these files don't work as described. Apparently enough has changed that they no longer allow Draft to function.

Thus we still get the behaviour of essentially ignoring the preference settings to show grid only when in a command, etc.

Code: Select all

OS: Debian GNU/Linux 11 (bullseye) (XFCE/lightdm-xsession)
Word size of FreeCAD: 64-bit
Version: 0.21.0.31238 (Git)
Build type: Release
Branch: master
Hash: 6f0afb4d0b8b7a901a8b5b54e07c25e36e840548
Python 3.9.2, Qt 5.15.2, Coin 4.0.0, Vtk 7.1.1, OCC 7.5.1
Locale: English/United States (en_US)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft Grid: improvements

Post by Roy_043 »

The files are still a work in progress. No PR has been made.
drmacro
Veteran
Posts: 8984
Joined: Sun Mar 02, 2014 4:35 pm

Re: Draft Grid: improvements

Post by drmacro »

Roy_043 wrote: Tue Dec 06, 2022 5:50 pm The files are still a work in progress. No PR has been made.
Is this in progress?

Do these files work with the latest 0.21 source?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
calligarov
Posts: 47
Joined: Sun Jan 01, 2023 3:08 pm
Location: Cadore, Italy
Contact:

Re: Draft Grid: improvements

Post by calligarov »

Hi Everyone! :)

I arrived in this topic following Roy's suggestion on topic viewtopic.php?p=706094#p706094

As of now I simply downloaded the Draft_grid_improvements folder from the first post of this topic, tested it and made modifications trying to get it working on 0.22 dev version.
Honestly speaking I still need to read again the posts in this topic and the discussion on the GitHub issue at least another couple of times to have a more complete knowledge of the modifications discussed but ATM I can say that, with the py files I modified, the grid auto-hide features looks working.

Therefore @drmacro I think I can at least say that somebody's looking at this ;)

@Roy_043 Do you think it could make sense now to open a PR, or better a draft PR, to keep track of the modifications and discuss the details?
You can find some more info about me at https://wiki.opensourceecology.org/wiki/User:Calligarov

My GitLab profile: https://gitlab.com/calligarov
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft Grid: improvements

Post by Roy_043 »

@calligarov I have to look at these files again myself to see what makes the most sense. My plan was to deal with the Draft WorkingPlane first and then integrate the code I have proposed here. But it may be possible to change that order.
User avatar
calligarov
Posts: 47
Joined: Sun Jan 01, 2023 3:08 pm
Location: Cadore, Italy
Contact:

Re: Draft Grid: improvements

Post by calligarov »

Thanks for the reply @Roy_043.

I see that you created issue #10766 that introduces the PlaneBase class.
Now, if I understood correctly by reading issue #5603, the next steps are:
  • develop the PlaneGui class
  • manage the current Plane/plane class for compatibility
  • move some functions outside of the current Plane class
Not sure if the PlaneBase class you introduced needs further work.

Do you think there's something I can do to help you moving forward with the modifications?
You can find some more info about me at https://wiki.opensourceecology.org/wiki/User:Calligarov

My GitLab profile: https://gitlab.com/calligarov
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft Grid: improvements

Post by Roy_043 »

Thanks for your offer. I'll try to give more detailed information about the plans and what has already been done later this week. A lot of things still need to be decided BTW.

For an overview of open Draft issues:
https://github.com/FreeCAD/FreeCAD/labels/WB%20Draft
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Draft Grid: improvements

Post by Roy_043 »

Small update:

There are some new ideas related to the grid:
https://github.com/FreeCAD/FreeCAD/pull ... 1737049751

In the Contributor Meeting this Sunday (2023-10-01) the grid will be discussed.
viewtopic.php?t=81584
User avatar
calligarov
Posts: 47
Joined: Sun Jan 01, 2023 3:08 pm
Location: Cadore, Italy
Contact:

Re: Draft Grid: improvements

Post by calligarov »

Thanks again Roy!
Roy_043 wrote: Fri Sep 29, 2023 7:29 pm There are some new ideas related to the grid:
https://github.com/FreeCAD/FreeCAD/pull ... 1737049751
I'll have a look at that and see if there's something I can do with small or no assistance at all ;)
Roy_043 wrote: Tue Sep 26, 2023 8:09 am For an overview of open Draft issues:
https://github.com/FreeCAD/FreeCAD/labels/WB%20Draft
Do you have some specific points in mind for me to study?
I was thinking about issue #7573 as part of code involved is what I already studied for issue #10655 but let me know if you think it's better if I focus on else :)

p.s.: sorry for the late reply, trying to figure out issue #7062 :roll:
You can find some more info about me at https://wiki.opensourceecology.org/wiki/User:Calligarov

My GitLab profile: https://gitlab.com/calligarov
Post Reply