Graph to show Part of Model, editable etc. - by Graphviz ?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
lvk88
Posts: 10
Joined: Thu Mar 18, 2021 3:56 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by lvk88 »

paullee wrote: Wed Mar 17, 2021 7:18 pm BTW, it seems the standard Dependency Graph is not something by python, there is not an API or something similar which can be tweaked and reported in the Python Console?

Code: Select all

Gui.runCommand('Std_DependencyGraph',0)
Hey @paullee,

you can access the dependency graph in .dot format using:

Code: Select all

FreeCAD.ActiveDocument.DependencyGraph


This should return the string which is passed to dot when the dependency graph is to be visualized. I have a small macro that pipes this to xdot on Linux.

Code: Select all

#Before using, make sure xdot is installed
#pip3 install --user xdot

import xdot

graph = FreeCAD.ActiveDocument.DependencyGraph

window = xdot.DotWindow()
window.set_filter('dot')
window.set_dotcode(graph.encode())
window.connect('delete-event', xdot.ui.window.Gtk.main_quit)
See it in action:
xdot_depgraph_macro.gif
xdot_depgraph_macro.gif (505.79 KiB) Viewed 1461 times
I really like this, because with the F key (or the search box in the toolbar), I can search for nodes in xdot, so it is possible to quickly navigate to stuff which is interesting. Also, arrows are hilighted, which is a bonus. Unfortunately, xdot does not allow for moving nodes, but there are other tools that support this feature also, e.g. qvge.

I don't think there is functionality in-place that allows for making graphs of sub-selections of the tree. Nevertheless, I would be very interested in implementing something like that if time allows. Are there any specs/ticket for this already?
paullee
Veteran
Posts: 5135
Joined: Wed May 04, 2016 3:58 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by paullee »

lvk88 wrote: Mon Mar 22, 2021 11:05 am
you can access the dependency graph in .dot format using:

Code: Select all

FreeCAD.ActiveDocument.DependencyGraph

Excited to read this ! :D
Would study your post in details !!!
paullee
Veteran
Posts: 5135
Joined: Wed May 04, 2016 3:58 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by paullee »

Hmmm.... always installation problems :)

Probably not compatible with FreeCAD AppImage with python 3.8.6 ?

Code: Select all

>>> import xdot
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ModuleNotFoundError: No module named 'xdot'

>>> sys.path.append("/home/paullee/.local/lib/python3.7/site-packages/")
>>> 
>>> import xdot
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/paullee/.local/lib/python3.7/site-packages/xdot/__init__.py", line 26, in <module>
    from . import ui
  File "/home/paullee/.local/lib/python3.7/site-packages/xdot/ui/__init__.py", line 3, in <module>
    from .window import DotWidget, DotWindow
  File "/home/paullee/.local/lib/python3.7/site-packages/xdot/ui/window.py", line 25, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'
>>> 
User avatar
lvk88
Posts: 10
Joined: Thu Mar 18, 2021 3:56 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by lvk88 »

paullee wrote: Tue Mar 23, 2021 12:49 am Hmmm.... always installation problems :)

Probably not compatible with FreeCAD AppImage with python 3.8.6 ?

Code: Select all

>>> import xdot
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ModuleNotFoundError: No module named 'xdot'

>>> sys.path.append("/home/paullee/.local/lib/python3.7/site-packages/")
>>> 
>>> import xdot
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/paullee/.local/lib/python3.7/site-packages/xdot/__init__.py", line 26, in <module>
    from . import ui
  File "/home/paullee/.local/lib/python3.7/site-packages/xdot/ui/__init__.py", line 3, in <module>
    from .window import DotWidget, DotWindow
  File "/home/paullee/.local/lib/python3.7/site-packages/xdot/ui/window.py", line 25, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'
>>> 
It looks like you are missing the gi module. Could you try to install these stuff?

Code: Select all

apt install gir1.2-gtk-3.0 python3-gi 
Source: xdot project page.
paullee
Veteran
Posts: 5135
Joined: Wed May 04, 2016 3:58 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by paullee »

lvk88 wrote: Tue Mar 23, 2021 5:39 am It looks like you are missing the gi module. Could you try to install these stuff?

Code: Select all

apt install gir1.2-gtk-3.0 python3-gi 
I see, but no luck ... I am on Fedora 31

Code: Select all

(base) [paullee@f31 topologic]$ dnf search gir1.2-gtk-3.0 python3-gi
Last metadata expiration check: 9 days, 21:04:43 ago on Sun 14 Mar 2021 04:55:17 AM CST.
No matches found.
User avatar
lvk88
Posts: 10
Joined: Thu Mar 18, 2021 3:56 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by lvk88 »

paullee wrote: Tue Mar 23, 2021 6:02 pm I see, but no luck ... I am on Fedora 31
Oh, sorry, I'm not familiar with Fedora... Maybe something like this?

Code: Select all

dnf install python-xdot
Let me know if this works!
paullee
Veteran
Posts: 5135
Joined: Wed May 04, 2016 3:58 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by paullee »

lvk88 wrote: Tue Mar 23, 2021 7:07 pm

Code: Select all

dnf install python-xdot
Let me know if this works!
Thanks, I think I had done -

Code: Select all

conda install -c conda-forge xdot
Your code also run. But still gi is missing. Dnf search python3-gi, python-gi but nothing.
User avatar
lvk88
Posts: 10
Joined: Thu Mar 18, 2021 3:56 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by lvk88 »

paullee wrote: Wed Mar 24, 2021 12:03 am
lvk88 wrote: Tue Mar 23, 2021 7:07 pm

Code: Select all

dnf install python-xdot
Let me know if this works!
Thanks, I think I had done -

Code: Select all

conda install -c conda-forge xdot
Your code also run. But still gi is missing. Dnf search python3-gi, python-gi but nothing.
I'm sorry, I think I can't help you further with this :S

I even installed a Fedora 31 in a VirtualBox and managed to reproduce your issue, but I'm unsure how to make it work. I think the problem is that the AppImage version of FreeCAD comes with a bundled Python installation and therefore might ignore the system-wide installations of other python packages? I'm not sure how to help you further with this - maybe someone else on this forum knows? I'm also interested in the answer...

But, what should work at least is if you save the string that comes from FreeCAD.ActiveDocument.DependencyGraph to a file somewhere and open it with some other GraphViz editor.
paullee
Veteran
Posts: 5135
Joined: Wed May 04, 2016 3:58 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by paullee »

Thanks indeed for helping so far :)

And hope partial display of dependency graph could be implemented :D
paullee
Veteran
Posts: 5135
Joined: Wed May 04, 2016 3:58 pm

Re: Graph to show Part of Model, editable etc. - by Graphviz ?

Post by paullee »

lvk88 wrote: Mon Mar 22, 2021 11:05 am Are there any specs/ticket for this already?
Any idea @chrisb?
chrisb wrote: Tue Mar 16, 2021 6:59 pm I have proposed the first point already quite some time ago. I think that could well be doable by giving only limited data to the external program (dot).
The second point would be great too, but that's probably rather not a FreeCAD thing.
Thanks.
Post Reply