Activating grid - Api required in FreeCAD core for WB developers

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
mariwan
Posts: 387
Joined: Wed Jan 06, 2021 2:00 pm

Activating grid - Api required in FreeCAD core for WB developers

Post by mariwan »

When you start Draft you don't get the grid activated by just making a new file. But DRAFT activate the grid when you use any tool or drawing. This is a work around the problem.
I believe that there is no API that WB developer can use as a callback to the workbench for activating the grid.
I have the same issue .. I activate the 3D grid with the load of the WB. But if you close the document and create the new document, the 3D grid will not be drawn.
I don't know any API that might help to to use for redrawing the grid. I don't think there is IMHO, otherwise draft would use it.

Can I suggest a simple API that could be used by us WB developer to do things when the new file is created or a file is opened in FreeCAD? It shouldn't be too difficult in Cpp.

Thanks.
openBrain
Posts: 6747
Joined: Fri Nov 09, 2018 5:38 pm

Re: Activating grid - Api required in FreeCAD core for WB developers

Post by openBrain »

marja1 wrote: Sat Sep 04, 2021 7:08 pm When you start Draft you don't get the grid activated by just making a new file. But DRAFT activate the grid when you use any tool or drawing. This is a work around the problem.
I believe that there is no API that WB developer can use as a callback to the workbench for activating the grid.
This is a bit weird. As Draft is coded in Python, all its functions are available. I'd be surprised that there is no one the show/hide the grid.
Can I suggest a simple API that could be used by us WB developer to do things when the new file is created or a file is opened in FreeCAD? It shouldn't be too difficult in Cpp.
You're late. :) It already exists. It's called "DocumentObserver". There are actually 2 slightly different types, depending if you set it in "FreeCAD/App" or "FreeCADGui/Gui" namespace.
openBrain
Posts: 6747
Joined: Fri Nov 09, 2018 5:38 pm

Re: Activating grid - Api required in FreeCAD core for WB developers

Post by openBrain »

Grid toggling :

Code: Select all

Gui.Snapper.grid.off() #turns grid off
Gui.Snapper.grid.off() #turns grid on
Gui.Snapper.forceGridOff = True #force grid off
User avatar
mariwan
Posts: 387
Joined: Wed Jan 06, 2021 2:00 pm

Re: Activating grid - Api required in FreeCAD core for WB developers

Post by mariwan »

openBrain wrote: Mon Sep 06, 2021 5:41 pm About Document Observer :
* Reference to API : https://forum.freecadweb.org/viewtopic. ... 45#p509462
* Example code : https://github.com/0penBrain/FreeCAD-ma ... og.FCMacro
But all that will not be related to New file , Open File.
I need a callback function that let me run my drawing-function for the grid.
I know how to show the grid. and I am using my 3D world .. not Draft.
So, the question is how can I redraw the 3D world when a file is opened or a new file creates?
There is not any API for that. As Draft uses also the tools to toggle the grid if it is not already activated.
am I wrong ?
yorik wrote:ping
There must be a callback mechanism .. I can make a thread that look at the availability of the grid ... but that is a waste of CPU time.
Last edited by mariwan on Tue Sep 07, 2021 4:08 am, edited 1 time in total.
openBrain
Posts: 6747
Joined: Fri Nov 09, 2018 5:38 pm

Re: Activating grid - Api required in FreeCAD core for WB developers

Post by openBrain »

marja1 wrote: Mon Sep 06, 2021 6:33 pm But all that will not be related to New file , Open File.
It is. Just try the example.
User avatar
mariwan
Posts: 387
Joined: Wed Jan 06, 2021 2:00 pm

Re: Activating grid - Api required in FreeCAD core for WB developers

Post by mariwan »

Again, my question is not about activating the grid when WB loads. It is when file opened or new file is created.
I will try OpenBrains tomorrow I have no time now. thanks for your help
adrianinsaval
Posts: 805
Joined: Thu Apr 05, 2018 5:15 pm

Re: Activating grid - Api required in FreeCAD core for WB developers

Post by adrianinsaval »

marja1 wrote: Mon Sep 06, 2021 6:33 pm
yorik wrote:"ping"
you need to include the user_id if you want him to get a notification, like this:

Code: Select all

[quote=yorik user_id=68]ping[/quote]
openBrain
Posts: 6747
Joined: Fri Nov 09, 2018 5:38 pm

Re: Activating grid - Api required in FreeCAD core for WB developers

Post by openBrain »

marja1 wrote: Mon Sep 06, 2021 8:06 pm Again, my question is not about activating the grid when WB loads. It is when file opened or new file is created.
Once again, these events can be get with DocumentObserver. ;)
Post Reply