GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Contributions from the participants, questions and answers to their projects.
Discussions of proposals for upcoming events.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by ickby »

After our discussion yesterday I looked up the handling of normals. In coin they are specified via a SoNormal node, and an accompying SoNormalBinding node. For example see the Part Workbench Viewprovider.

You can extract the normals there without the need to recompute them yourself. That should give more accurate results, as the normals come from the shape directly and hence are more accurate.
User avatar
kryptokommunist
Posts: 70
Joined: Fri Mar 27, 2020 6:29 pm
Location: Berlin
Contact:

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by kryptokommunist »

kryptokommunist wrote: Wed Jul 29, 2020 12:35 am
  • find out where in FreeCAD I can access the names of edges and surfaces
Thanks to Werner I have this information now.

  • extending my current pythreejs scene graph function to attach labels to it's surfaces and edges

I slightly varied the approach to selection of edges and faces. The basic functionality on pythreejs is working. I still have to link it up to the FreeCAD edge and face labels. Implementing this entirely on the Javascript side is a task I would take on in the future since there are still some issues on integrating that cleanly with the library. Currently the best way for highlighting I could get working is replacing the entire scene. Just changing the colour of a single object I couldn't get to work yet, therefore the flickering after selection. That also makes highlighting on hovering over the object very unpleasant. Therefore I will stick to clicking for now.

selection_demo.gif
selection_demo.gif (650.05 KiB) Viewed 4338 times

  • hard copy default camera, lighting defaults from FreeCAD
Kinda done, I still have to modify the mouse panning inside the 3D view to pan the object only and not the entire universe as currently (this means the lighting is fixed relative to the object which does not match the desktop apps 3D view).

My goals for this week are (kanban link)
  • Matching and displaying the correct FreeCAD labels when selecting or hovering over the objects in the pythreejs 3D view
  • create example files for various workbenches and test them
  • fix edge bug (currently the displayed edges don't fully match the desktop 3D view
Last edited by kryptokommunist on Fri Aug 21, 2020 11:59 pm, edited 4 times in total.
SylvainCorlay
Posts: 6
Joined: Fri Aug 14, 2020 12:40 pm

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by SylvainCorlay »

Hi there,

Jupyter core developer here - I am thrilled to see work being done to better integrate FreeCAD and Jupyter!

We have been working with some folks at Kitware on a similar problem to integrate Jupyter with the Python interpreter embedded into Slicer3D. (Check out our blog post: https://blog.jupyter.org/slicerjupyter- ... 2ad829f635). Also, I see that you are making use of ipywidgets and pythreejs for the rendering.

We would love to help! Besides, I think that this kind of integration could be a good subject for a guest post on the Jupyter blog (blog.jupyter.org). Let us know if you would like to connect for a catch up over video some time in the next couple of weeks to discuss all of this in more detail!

Cheers,

Sylvain
User avatar
kryptokommunist
Posts: 70
Joined: Fri Mar 27, 2020 6:29 pm
Location: Berlin
Contact:

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by kryptokommunist »

SylvainCorlay wrote: Fri Aug 14, 2020 12:55 pm (Check out our blog post: https://blog.jupyter.org/slicerjupyter- ... 2ad829f635). Also, I see that you are making use of ipywidgets and pythreejs for the rendering.
Hi Sylvain,

the Slicer looks great! Currently the notebook integration approach with FreeCAD is simply ignoring the entire QT event loop. This way FreeCAD can be loaded and used just like any python library. My work here is visualizing the 3D and other data present. But knowing how the QT loop could be integrated would be valuable since there are some FreeCAD functionalities that require running the QT event loop. Still the functionality without it is already powerful (my impression so far).

We would love to help! Besides, I think that this kind of integration could be a good subject for a guest post on the Jupyter blog (blog.jupyter.org). Let us know if you would like to connect for a catch up over video some time in the next couple of weeks to discuss all of this in more detail!
Sounds good, I'm happy to discuss the implementation and where I could use some help from you guys. I ran into some problems with customising widgets. And the blog offer would be perfect :) I'll send you my contacts via PM.
Last edited by kryptokommunist on Mon Aug 17, 2020 4:45 pm, edited 2 times in total.
User avatar
kryptokommunist
Posts: 70
Joined: Fri Mar 27, 2020 6:29 pm
Location: Berlin
Contact:

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by kryptokommunist »

Here is a demo on using interactive widgets that control FreeCAD. Really great way to quickly build custom interactive UI for work with FreeCAD. The code can be found at the bottom of the notebook.

jupyter_widget_demo.gif
jupyter_widget_demo.gif (957.67 KiB) Viewed 4238 times
User avatar
kryptokommunist
Posts: 70
Joined: Fri Mar 27, 2020 6:29 pm
Location: Berlin
Contact:

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by kryptokommunist »

kryptokommunist wrote: Wed Jul 29, 2020 12:35 am
  • Matching and displaying the correct FreeCAD labels when selecting or hovering over the objects in the pythreejs 3D view
Done. (Will upload demo later) Thanks to a very helpful tip from @ickby this is correct and matches the FreeCAD indices. Still need to implement edge indices, but this should be very similar.

  • create example files for various workbenches and test them
Still working on this.

  • fix edge bug (currently the displayed edges don't fully match the desktop 3D view

I have not solved this yet, but I will debug this using simple geometries as suggested by @ickby.


My goals for this week are (kanban link)
  • Enable line selection equivalent to the face selection
  • create example files for various workbenches and test them
  • fix edge bug (currently the displayed edges don't fully match the desktop 3D view
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by ickby »

Good to hear the selection works!
User avatar
kryptokommunist
Posts: 70
Joined: Fri Mar 27, 2020 6:29 pm
Location: Berlin
Contact:

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by kryptokommunist »

kryptokommunist wrote: Fri Aug 21, 2020 11:53 pm
kryptokommunist wrote: Wed Jul 29, 2020 12:35 am
  • Matching and displaying the correct FreeCAD labels when selecting or hovering over the objects in the pythreejs 3D view
Done. (Will upload demo later) Thanks to a very helpful tip from @ickby this is correct and matches the FreeCAD indices. Still need to implement edge indices, but this should be very similar.

We are now in the final week and the face highlighting now works correctly and after some input from @ickby on the last call I finally managed to get rid of the edge bug and as you can see the edges are now rendered as they appear in FreeCAD:

highlighting_demo.gif
highlighting_demo.gif (909.07 KiB) Viewed 3877 times


So for the final week I intend to get these points done (kanban link):

  • Enable line selection/highlighting equivalent to the face selection
  • Enable vertice selection/highlighting equivalent to the face selection
  • package everything up into an class that can be used as FreeCAD Add On or similar easy to use scheme
  • Extend documentation and add a clean example Notebook
  • Write Blogpost or create a Video demoing the result (will discuss this with the mentors)
Even though I don't feel this is really done yet, I'm excited and confident that this is ready to be used by the community. Some further tweaking on details is needed and I certainly won't abandon this project!
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by keithsloan52 »

Question will it work with Part::FeaturePython objects?

With my GDML workbench https://github.com/KeithSloan/GDML Graphic objects are implemented as Part::FeaturePython Objects and it would be great to create Models/Designs via programming in a Jupyter notebook.

I suspect I would have to add some new function definitions to make this easy as at present functions tend to access lxml Elements, but it should be easy enough for me to add functions that just rely on passed python variables.

If you have any spare time after you finish it would be good to have a Skype or similar session to discuss.
User avatar
kryptokommunist
Posts: 70
Joined: Fri Mar 27, 2020 6:29 pm
Location: Berlin
Contact:

Re: GSoC 2020: A better IPython and Jupyter Notebook Integration for FreeCAD

Post by kryptokommunist »

keithsloan52 wrote: Sat Aug 29, 2020 5:28 am I suspect I would have to add some new function definitions to make this easy as at present functions tend to access lxml Elements, but it should be easy enough for me to add functions that just rely on passed python variables.

If you have any spare time after you finish it would be good to have a Skype or similar session to discuss.
That is a very good question, as one goal of the project was to have general solution that would mostly copy the view this might work just out of the box. But I didn't get to testing things outside of Part Workbench generated Objects. As far as I understand most Workbenches just recycle the Part API to create their objects. If at least the structure of the Coin3D graph being generated is similar it should work out of the box. In the scene graph to my current understanding there are ultimately just Faces, Lines and Points and that's what the project can currently render. So in the end it might need some tweaking of where the Jupyter 3D view renderer will look in the scene graph to display your objects, but no special functions from your side.

Only you'd need to make sure that your workbench will run headless in the sense that the QT loop won't run.
Post Reply