Extra python modules/pl

Informacje ogólne
Ta strona zawiera listę kilku dodatkowych modułów środowiska Python lub innych elementów oprogramowania, które można pobrać z Internetu i dodać do swojej instalacji FreeCAD.



PySide (poprzednio PyQt)

 * strona główna (PySide): http://qt-project.org/wiki/PySide
 * licencja: LGPL
 * opcjonalny, ale wymagany przez kilka modułów: Rysunek Roboczy, Architektura, Statek, Wykres, OpenSCAD, Arkusz Kalkulacyjny

PySide (wcześniej PyQt) jest wymagany przez kilka modułów FreeCAD, aby uzyskać dostęp do interfejsu Qt FreeCAD. Jest on już dołączony do wersji FreeCAD dla systemu Windows i jest zwykle instalowany automatycznie przez FreeCAD w systemie Linux podczas instalacji z oficjalnych repozytoriów. Jeśli te moduły (Rysunek Roboczy, Architektura itp.) są włączone po zainstalowaniu FreeCAD, oznacza to, że PySide (wcześniej PyQt) już tam jest i nie trzeba nic więcej robić.

Uwaga: FreeCAD stopniowo odchodził od PyQt po wersji 0.13, na rzecz PySide, który wykonuje dokładnie to samo zadanie, ale ma licencję (LGPL) bardziej kompatybilną z FreeCAD.

Linux
Najprostszym sposobem na zainstalowanie PySide jest skorzystanie z menedżera pakietów danej dystrybucji. W systemach Debian / Ubuntu nazwa pakietu to zazwyczaj python-PySide, podczas gdy w systemach opartych na RPM nosi on nazwę pyside. Niezbędne zależności (Qt i SIP) zostaną pobrane automatycznie.

Windows
Program można pobrać ze strony http://qt-project.org/wiki/Category:LanguageBindings::PySide::Downloads. Przed instalacją PySide należy zainstalować biblioteki Qt i SIP (co zostanie udokumentowane).

Mac OS
PySide na Maca może być zainstalowany przez lub. Więcej informacji można znaleźć w Instalacja zależności.

Użycie
Po zainstalowaniu można sprawdzić, czy wszystko działa, wpisując w konsoli Python programu FreeCAD:

Aby uzyskać dostęp do interfejsu programu FreeCAD, należy wpisać:

Teraz możesz zacząć poznawać interfejs za pomocą polecenia dir. Możesz dodać nowe elementy, takie jak niestandardowy widżet, za pomocą poleceń takich jak:

Praca z Unicode:

Praca z QFileDialog i OpenFileName:

Praca z QFileDialog i SaveFileName:



Przykład przejścia z PyQt4 i PySide
PS: te przykłady błędów zostały znalezione podczas przejścia z PyQt4 na PySide i te poprawki zostały wprowadzone, inne rozwiązania są z pewnością dostępne w powyższych przykładach

Aby uzyskać dostęp do interfejsu FreeCAD, wpisz: Możesz dodawać nowe elementy, takie jak niestandardowy widżet, za pomocą poleceń takich jak:

Praca z Unicode:

Praca z QFileDialog i OpenFileName:

Praca z QFileDialog i SaveFileName:

Okno dialogowe:

Praca z setProperty (PyQt4) i setValue (PySide)

zastąp:

Praca z setToolTip

zastąp:

lub:



Dokumentacja dodatkowa

 * Qt official documentation site

Pivy

 * homepage: https://bitbucket.org/Coin3D/coin/wiki/Home
 * license: BSD
 * optional, but needed by several modules of FreeCAD: Draft, Arch

Pivy is a needed by several modules to access the 3D view of FreeCAD. On windows, Pivy is already bundled inside the FreeCAD installer, and on Linux it is usually automatically installed when you install FreeCAD from an official repository. On macOS, unfortunately, you will need to compile pivy yourself.

Prerequisites
I believe before compiling Pivy you will want to have Coin and SoQt installed.

I found for building on Mac it was sufficient to install the Coin3 binary package. Attempting to install coin from MacPorts was problematic: tried to add a lot of X Windows packages and ultimately crashed with a script error.

For Fedora I found an RPM with Coin3.

SoQt compiled from source fine on Mac and Linux.

Debian & Ubuntu
Starting with Debian Squeeze and Ubuntu Lucid, pivy will be available directly from the official repositories, saving us a lot of hassle. In the meantime, you can either download one of the packages we made (for debian and ubuntu karmic) availables on the Download pages, or compile it yourself.

The best way to compile pivy easily is to grab the debian source package for pivy and make a package with debuild. It is the same source code from the official pivy site, but the debian people made several bug-fixing additions. It also compiles fine on ubuntu karmic: http://packages.debian.org/squeeze/python-pivy download the .orig.gz and the .diff.gz file, then unzip both, then apply the .diff to the source: go to the unzipped pivy source folder, and apply the .diff patch:

then

to have pivy properly built into an official installable package. Then, just install the package with gdebi.

Other linux distributions
First get the latest sources from the project's repository:

As of March 2012, the latest version is Pivy-0.5.

Then you need a tool called SWIG to generate the C++ code for the Python bindings. Pivy-0.5 reports that it has only been tested with SWIG 1.3.31, 1.3.33, 1.3.35, and 1.3.40. So you can download a source tarball for one of these old versions from http://www.swig.org. Then unpack it and from a command line do (as root):

It takes just a few seconds to build.

Alternatively, you can try building with a more recent SWIG. As of March 2012, a typical repository version is 2.0.4. Pivy has a minor compile problem with SWIG 2.0.4 on macOS (see below) but seems to build fine on Fedora Core 15.

After that go to the pivy sources and call

which creates the source files. Note that build can produce thousands of warnings, but hopefully there will be no errors.

This is probably obsolete, but you may run into a compiler error where a 'const char*' cannot be converted in a 'char*'. To fix that you just need to write a 'const' before in the appropriate lines. There are six lines to fix.

After that, install by issuing (as root):

That's it, pivy is installed.

MacOS
These instructions may not be complete. Something close to this worked for OS 10.7 as of March 2012. I use MacPorts for repositories, but other options should also work.

As for linux, get the latest source:

If you don't have hg, you can get it from MacPorts:

Then, as above you need SWIG. It should be a matter of:

I found I needed also:

As of March 2012, MacPorts SWIG is version 2.0.4. As noted above for linux, you might be better off downloading an older version. SWIG 2.0.4 seems to have a bug that stops Pivy building. See first message in this digest

This can be corrected by editing the 2 source locations to add dereferences: *arg4, *arg5 in place of arg4, arg5. Now Pivy should build:

Windows
Assuming you are using Visual Studio 2005 or later you should open a command prompt with 'Visual Studio 2005 Command prompt' from the Tools menu. If the Python interpreter is not yet in the system path do

To get pivy working you should get the latest sources from the project's repository:

Then you need a tool called SWIG to generate the C++ code for the Python bindings. It is recommended to use version 1.3.25 of SWIG, not the latest version, because at the moment pivy will only function correctly with 1.3.25. Download the binaries for 1.3.25 from http://www.swig.org. Then unpack it and from the command line add it to the system path

and set COINDIR to the appropriate path

On Windows the pivy config file expects SoWin instead of SoQt as default. I didn't find an obvious way to build with SoQt, so I modified the file setup.py directly. In line 200 just remove the part 'sowin': ('gui._sowin', 'sowin-config', 'pivy.gui.') (do not remove the closing parenthesis).

After that go to the pivy sources and call

which creates the source files. You may run into a compiler error several header files couldn't be found. In this case adjust the INCLUDE variable

and if the SoQt headers are not in the same place as the Coin headers also

and finally the Qt headers

If you are using the Express Edition of Visual Studio you may get a Python keyerror exception. In this case you have to modify a few things in msvccompiler.py located in your Python installation.

Przejdź do linii 122 i zastąp linię

przez

Następnie spróbuj ponownie. Jeśli pojawi się drugi błąd jak np.

musisz również zastąpić linię 128

przez

Retry once again. If you get again an error like

then you should check the environment variables DISTUTILS_USE_SDK and MSSDK with

If not yet set then just set it e.g. to 1

Now, you may run into a compiler error where a 'const char*' cannot be converted in a 'char*'. To fix that you just need to write a 'const' before in the appropriate lines. There are six lines to fix. After that copy the generated pivy directory to a place where the Python interpreter in FreeCAD can find it.

Usage
To check if Pivy is correctly installed:

To have Pivy access the FreeCAD scenegraph do the following:

You can now explore the FCSceneGraph with the dir command.

Additonal Documentation
Unfortunately documentation about pivy is still almost nonexistant on the net. But you might find Coin documentation useful, since pivy simply translate Coin functions, nodes and methods in Python, everything keeps the same name and properties, keeping in mind the difference of syntax between C and Python:


 * https://bitbucket.org/Coin3D/coin/wiki/Documentation - Coin3D API Reference
 * http://www-evasion.imag.fr/~Francois.Faure/doc/inventorMentor/sgi_html/index.html - The Inventor Mentor - The "bible" of Inventor scene description language.

You can also look at the Draft.py file in the FreeCAD Mod/Draft folder, since it makes big use of pivy.

pyCollada

 * homepage: http://pycollada.github.com
 * license: BSD
 * optional, needed to enable import and export of Collada (.DAE) files

pyCollada is a Python library that allow programs to read and write Collada (*.DAE) files. When pyCollada is installed on your system, FreeCAD will be able to handle importing and exporting in the Collada file format.

Linux
You can check if pycollada was correctly installed by issuing in a Python console:

If it returns nothing (no error message), then all is OK

Windows
On Windows since 0.15 pycollada is included in both the FreeCAD release and developer builds so no additional steps are necessary.

MacOS
If you are using the Homebrew build of FreeCAD you can install pycollada into your system Python using pip.

If you need to install pip:

Install pycollada:

If you are using a binary version of FreeCAD, you can tell pip to install pycollada into the site-packages inside FreeCAD.app:

or after downloading the pycollada code

IfcOpenShell

 * homepage: http://www.ifcopenshell.org
 * license: LGPL
 * optional, needed to extend import abilities of IFC files

IFCOpenShell is a library currently in development, that allows to import (and soon export) Industry foundation Classes (*.IFC) files. IFC is an extension to the STEP format, and is becoming the standard in BIM workflows. When ifcopenshell is correctly installed on your system, the FreeCAD Arch Workbench will detect it and use it to import IFC files, instead of its built-in rudimentary importer. Since ifcopenshell is based on OpenCasCade, like FreeCAD, the quality of the import is very high, producing high-quality solid geometry.

Installation
Since ifcopenshell is pretty new, you'll likely need to compile it yourself.

Linux
You will need a couple of development packages installed on your system in order to compile ifcopenshell:

but since FreeCAD requires all of them too, if you can compile FreeCAD, you won't need any extra dependency to compile IfcOpenShell.

Grab the latest source code from here:

The build process is very easy:

or, if you are using oce instead of opencascade:

Since ifcopenshell is made primarily for Blender, it uses Python3 by default. To use it inside FreeCAD, you need to compile it against the same version of Python that is used by FreeCAD. So you might need to force the Python version with additional cmake parameters (adjust the Python version to yours):

Then:

You can check that ifcopenshell was correctly installed by issuing in a Python console:

If it returns nothing (no error message), then all is OK

Windows
Note: Official FreeCAD installers obtained from the FreeCAD website/github page now contain ifcopenshell already.

Copied from the IfcOpenShell README file

Users are advised to use the Visual Studio .sln file in the win/ folder. For Windows users a prebuilt Open CASCADE version is available from the opencascade website. Download and install this version and provide the paths to the Open CASCADE header and library files to MS Visual Studio C++.

For building the IfcPython wrapper, SWIG needs to be installed. Please download the latest swigwin version from swig website. After extracting the .zip file, please add the extracted folder to the PATH environment variable. Python needs to be installed, please provide the include and library paths to Visual Studio.

Links
Tutorial Import/Export IFC - compiling IfcOpenShell

Installation
On all platforms, only by installing the appropriate package from ODA DWG-DXF Converter. After installation, if the utility is not found automatically by FreeCAD, you might need to set the path to the converter executable manually, open Edit → Preferences → Import-Export → DWG and fill "Path to Teigha File Converter" appropriately.

LazyLoader
LazyLoader is a Python module that allows deferred loading, while still importing at the top of the script. This is useful if you are importing another module that is slow, and it is used several times throughout the script. Using LazyLoader can improve workbench startup times, but the module will still need to be loaded on first use.

Installation
LazyLoader is included with FreeCAD v0.19

Użycie
Będziesz musiał zaimportować LazyLoader, a następnie zmienić import dowolnego modułu, który chcesz poddać odroczeniu.

Zmienna Part to nazwa modułu w skrypcie. Możesz powtórzyć "import Part as P", zmieniając zmienną.

You can also import a module from a package.

Nie można importować pojedynczych funkcji, tylko całe moduły.

Odnośniki internetowe

 * Oryginalne źródło: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/lazy_loader.py
 * Dalsze wyjaśnienia: https://wil.yegelwel.com/lazily-importing-python-modules/
 * Kod w kodzie źródłowym FreeCAD: https://github.com/FreeCAD/FreeCAD/tree/master/src/3rdParty/lazy_loader
 * Dyskusja na forum: https://forum.freecadweb.org/viewtopic.php?f=10&t=45298