IfcOpenShell

From FreeCAD Documentation
Revision as of 12:50, 23 July 2020 by Vocx (talk | contribs) (IfcOpenShell is primarily a collection of C++ libraries, however, as it has Python bindings, it can be easily integrated with programs like FreeCAD and Blender.)
Other languages:

Description

IfcOpenShell is an open source (LGPL 3) software library that helps developers work with the industry foundation classes (IFC) file format. The IFC file format can be used to describe building and construction data. The format is commonly used for building information modelling (BIM), for example, mechanical loading analysis and thermal studies. IfcOpenShell is primarily a collection of C++ libraries, however, as it has Python bindings, it can be easily integrated with programs like FreeCAD and Blender.

IfcOpenShell uses OpenCASCADE internally to convert the implicit geometry in IFC files into explicit geometry that other CAD packages can understand.

As of v0.19, FreeCAD is able to import IFC files as long as the ifcopenshell Python module is available in the system. Likewise, the Arch and BIM Workbenches can export a building model to the IFC format so that it can be used in other applications.

To verify that IfcOpenShell is installed in your system, try to import it from the Python console; the library is correctly installed if no error message is returned.

import ifcopenshell

Installation

IfcOpenShell can be installed in various ways depending on your operating system.

Conda

For Windows and MacOS users, which use the Conda-based FreeCAD distributions, IfcOpenShell is usually included in the respective package so normally no further installation is necessary. Get this distribution from the Download page.

The AppImage available for Linux is also based on Conda, and it also includes IfcOpenShell.

Linux

You may install IfcOpenShell from your local package manager, if it is available.

sudo apt install ifcopenshell

However, please remember that the package provided by a repository may be out of date. In this case, use a Conda-based distribution of FreeCAD, or compile IfcOpenShell yourself.

Compiling

Compiling IfcOpenShell is recommended only for advanced users. The process uses the CMake configuration tool to produce a custom Makefile for use with the Make tool. The general instructions are outlined in the code repository.

The general steps are as follows:

  1. Get the source code of IfcOpenShell from its main repository.
  2. Gather all dependencies for compiling, including installing a C++ compiler, CMake, and Make, and the development files for Boost, libxml2, OpenCASCADE, SWIG, Python, and OpenCOLLADA (optional). Most of these components are strictly optional, however, for use with FreeCAD they should all be installed except for OpenCOLLADA, as it only provides support for DAE files.
  3. Run cmake to generate a Makefile, then compile the libraries by running make.
  4. Install the ifcopenshell Python module in the appropriate site-packages directory so that it is found by FreeCAD.

Prerequisites

Get the source code of the project and place it in a custom directory to which you have full write access.

As of this writing (2020), the master branch of the IfcOpenShell project does not contain the latest code, so we need to clone a specific branch.

git clone https://github.com/IfcOpenShell/IfcOpenShell -b v0.6.0 ifcopenshell-source

Install the basic compilation tools.

sudo apt install git cmake gcc g++ libboost-all-dev

OpenCASCADE

Install the development files of OpenCASCADE.

sudo apt install libocct*-dev

Which expands to

sudo apt install libocct-data-exchange-dev libocct-draw-dev libocct-foundation-dev libocct-modeling-algorithms-dev libocct-modeling-data-dev libocct-ocaf-dev libocct-visualization-dev

You may use the community edition (OCE) of OpenCASCADE as well, however, please notice that this version is old and no longer recommended by FreeCAD as of 2020.

Python wrapper

For usage with FreeCAD you need the Python wrapper which uses SWIG to generate the proper interfaces from the C++ classes.

sudo apt-get install python-all-dev swig

CMake configuration

It is recommended to perform the compilation in a specific build directory.

mkdir -p ifcopenshell-build
cd ifcopenshell-build

cmake ../ifcopenshell-source/cmake/

Notice that the CMakeLists.txt file that drives CMake is inside the cmake/ directory.

Depending on your Linux distribution, and the way you installed the dependencies, you may have to define some CMake variables so that the proper libraries are found.

Specifying the OpenCASCADE libraries

If you manually compiled OpenCASCADE, or if the libraries are not in a standard directory, you may have to set up the proper variables.

cmake \
    -DOCC_INCLUDE_DIR=/usr/include/opencascade \
    -DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
    ../ifcopenshell-source/cmake/

Specifying the libxml2 libraries

If the libxml2 libraries are not found, or if the libraries are not in a standard directory, you may have to set up the proper variables.

cmake \
    -DOCC_INCLUDE_DIR=/usr/include/opencascade \
    -DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
    -DLIBXML2_INCLUDE_DIR=/usr/include/libxml2 \
    -DLIBXML2_LIBRARIES=/usr/lib/x86_64-linux-gnu/libxml2.so \
    ../ifcopenshell-source/cmake/

Without OpenCOLLADA

If you don't need OpenCOLLADA support you need to turn it off explicitly.

cmake \
    -DOCC_INCLUDE_DIR=/usr/include/opencascade \
    -DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
    -DLIBXML2_INCLUDE_DIR=/usr/include/libxml2 \
    -DLIBXML2_LIBRARIES=/usr/lib/x86_64-linux-gnu/libxml2.so \
    -DCOLLADA_SUPPORT=FALSE \
    ../ifcopenshell-source/cmake/

With OpenCOLLADA

If you manually compiled OpenCOLLADA, or if the libraries are not in a standard directory, you may have to set up the proper variables.

cmake \
    -DOCC_INCLUDE_DIR=/usr/include/opencascade \
    -DOCC_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu \
    -DLIBXML2_INCLUDE_DIR=/usr/include/libxml2 \
    -DLIBXML2_LIBRARIES=/usr/lib/x86_64-linux-gnu/libxml2.so \
    -DOPENCOLLADA_INCLUDE_DIR=/usr/local/include/opencollada \
    -DOPENCOLLADA_LIBRARY_DIR=/usr/local/lib/opencollada  \
    -DPCRE_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu/
    ../ifcopenshell-source/cmake/

Troubleshooting and other options

All configuration options are available in the CMakeLists.txt file located inside the cmake/ directory. You may look for other options that can be set here if there are problem when running CMake.

Installing

If the configuration doesn't report any error, you may install the compiled shared and static libraries to the corresponding directories.

sudo make install

By default, the CMAKE_INSTALL_PREFIX is /usr/local, so all compiled files will be tried to be installed to this directory, which normally requires elevated privileges.

/usr/local/bin
/usr/local/include
/usr/local/lib

In similar way, the Python wrapper will be placed in

/usr/lib/python3/dist-packages/ifcopenshell/

Related