Embedding FreeCADGui/it

Sapete già che è possibile importare il modulo FreeCAD in un'applicazione python, e utilizzare tutti i suoi strumenti dall'applicazione che lo ospita. Ma l'interfaccia utente di FreeCAD (GUI) può anche essere importata come modulo python. Normalmente è possibile importare in blocco solo l'interfaccia completa, non le sue singole parti. Questo perché il sistema dell'interfaccia di FreeCAD non è fatto di widget e di barre degli strumenti indipendenti, ma è una costruzione complessa in cui sono necessari diversi componenti invisibili (come ad esempio il sistema di selezione, ecc) affinchè la vista principale 3D possa funzionare.

Ma, con un po' di hacking, è possibile importare prima l'intera interfaccia di FreeCAD e poi spostare la vista 3D nella propria applicazione Qt. Mostriamo qui 3 diversi metodi.

Using the FreeCAD 3D view widget directly
Be aware that there are a lot of problems with this approach. The Qt event handling doesn't seem to work (no idea why) and if you use the 3d view's context-menu the application crashes. A better way could be to create your own 3d view SoQtExaminerViewer or SoQtViewer and "push" the content of FreeCAD's 3d view to your view, as shown in the other sections below.

First, get the main window via PyQt: Then get the View3DInventor view the same way: The following code is generated automatically, by creating a Ui-file with QtDesigner, and converting it to python code with the pyuic tool: Then, create a main window that should be your application's main window, apply the UI setup above to it in order to add an MDI area and "move" our 3d view to it

Creating a soGui Examiner Viewer
Alternatively, you can also use the FreeCADGui module to extract a coin/openInventor representation of the objects of your scene, then use that coin data in an external viewer (your application). Here is an easy way to get the 3d representation of an object: Then, create a standalone viewer with pivy: Then you just need to run your viewer:

Using the quarter module
Instead of using the sogui viewer, you can also use the more modern quarter module. This is probably the best solution of the 3.

Without even firing up the FreeCAD Gui
Starting from FreeCAD rev2760, it is now possible to obtain the coin representation of any FreeCAD object without opening the main window. This makes it extremely easy to implement your own viewer and transparently have FreeCAD updating it. After importing the FreeCADGui module, you need to fire it up with the setupWithoutGUI method, after which you can use all of FreeCAD's view providers to obtain coin/openInventor nodes. Or, if using pivy's sogui module doesn't work for you (the sogui module is becoming obsoleted and the coin developers are now favoring the new quarter library, which has much better interaction with qt), this is the same script but with using quarter: