CAD and rigid body simulation

The upcoming pythonOCC-0.5 release will provide an environment dedicated to rigid body simulation. The ODE dynamic engine (http://www.ode.org) is being embedded in a DYN package. It will be possible to use these features and benefit at the same time from the paramteric modeling framework, meshing, topology and all Level2 subpackages. Here are two screencast showing the status of this project.






Use pythonOCC with PyQt4 under MacOSX Snow Leopard (10.6)

The OpenCASCADE library is built upon X11. It doesn’t use Cocoa/Carbon. In order to be able to use the 3D viewer of pythonOCC with PyQt, you must first install Qt4-x11 and then PyQt4.7.

First, from the finkproject, download/install the qt4-x11 package. You can use finkcommander, a graphical frontend to fink, to manage your fink packages. Select the package named ‘qt4-X11′, install from source, and just be patient. When the build is achieved, your fink commander window should look like that:

The Qt4.5.2 libraries have been installed to /sw/lib/qt4-X11. Add the following line to your .bash_profile:

export PATH=$PATH:/sw/lib/qt4-x11/lib/:/sw/lib/qt4-x11/bin/

To check that your Qt installation is clean, just try to launch Qt Designer:

thomas-macbookpro:bin thomas$ designer

The next step is to install PyQt4. You will find below a link to a precopiled binary of PyQt4.7 that works with the previous installation.

PyQt4.7-MacOSX-SL-64.zip (11.5Mb)

Just extract the content of this file to /Library/Python/2.6/site-packages and you should get done. Test the installation (no linkage errors):

Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from PyQt4.QtCore import *
>>> from PyQt4.QtGui import *
>>>

You can run one of the pythonOCC samples. The PyQt4 package should be automatically detected. For instance, running the Geometry.py sample (/samples/Level1/Geometry) :

MacOSX Snow Leopard (10.6) Intel-64 bit binaries

If you want to skip the compilation process of both OpenCASCADE, GEOM, SMESH and pythonOCC, here are a few precompiled binaries.

Download and install the four following files:

Before you can run pythonOCC, you have to care that a few env variables are defined. Add the following lines to your .bash_profile script :

# OpenCASCADE
export CASROOT=/Library/OpenCASCADE/6.3.0
export OCC_SOURCE_ROOT=${CASROOT}
export DYLD_LIBRARY_PATH=${CASROOT}/lib:$DYLD_LIBRARY_PATH
# needed to get the visualization going…
export CSF_GraphicShr=${CASROOT}/lib/libTKOpenGl.dylib
export CSF_EXCEPTION_PROMPT=1
# OCC required variables
export CSF_IGESDefaults=${OCC_SOURCE_ROOT}/src/XSTEPResource
export CSF_LANGUAGE=us
export CSF_MDTVFontDirectory=${OCC_SOURCE_ROOT}/src/FontMFT
export CSF_MDTVTexturesDirectory=${OCC_SOURCE_ROOT}/src/Textures
export CSF_PluginDefaults=${OCC_SOURCE_ROOT}/src/StdResource
export CSF_SHMessage=${OCC_SOURCE_ROOT}/src/SHMessage
export CSF_StandardDefaults=${OCC_SOURCE_ROOT}/src/StdResource
export CSF_StandardLiteDefaults=${OCC_SOURCE_ROOT}/src/StdResource
export CSF_STEPDefaults=${OCC_SOURCE_ROOT}/src/XSTEPResource
export CSF_UnitsDefinition=${OCC_SOURCE_ROOT}/src/UnitsAPI/Units.dat
# GEOM shared libraries
export DYLD_LIBRARY_PATH=/usr/local/lib/GEOM-5.1.2.7:$DYLD_LIBRARY_PATH
# SMESH shared libraries
export DYLD_LIBRARY_PATH=/usr/local/lib/SMESH-5.1.2.2:$DYLD_LIBRARY_PATH

Then, from a python console, just check the installation is ok (i.e. no linkage errors):

Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from OCC.Standard import *
>>>

Under MacOSX, unless you properly installed PyQt4-X11, you’ll need the python-xlib (0.15rc1 or higher) package in order to use the 3D viewer. You can now run the samples.

pythonOCC-0.4 released

pythonOCC 0.4 was released today. Here are the main changes since the 0.3 release:

  • pythonOCC 0.4 comes with new advanced meshing features coming from the smesh project,
  • many new samples,
  • the OCC wrapper was improved (few missing modules were added, typical C++ mechanisms were pythonized),
  • 64 bits support for Windows/Mac,Linux
  • New graphical backends: PyQt and python-xlib
  • MacOSX Snow Leopard support,
  • better installation script
  • many minor fixes/enhancements in the Parametric Application Framework and Display packages

pythonOCC-0.4 was successfully built/tested on Windows platforms (XP/Seven with py2.5/2.6), Linux (Ubuntu 9.10, OpenSuse) as well as MacOSX (SnowLeopard).

Table design

Recently I’ve been so fortunate to have an exposition at design gallery Vivid in Rotterdam. The exposition was an overview of the work of EZCT Architecture & Design Research, of which I’m one of the founding partners. An interesting aspect of the design is that its been implemtend with pythonOCC! It really is wonderful to see the hard work poored into the project have physical consequences. Thomas came from Paris (just moved from Paris -> Rotterdam to start working on my PhD at the Hyperbody research group ) to come and see the results for himself. The work on the design instigated the development of a high-level, pythonic module. Take for example and Edge or a Wire. Rather than grinding through heaps of documentation, you’d expect an API that succintly presents you the functionality in an orderly, well documentated fashion. Well, that’s what I’m working on. In pythonOCC we’ll start to refer to the Level1 API ( OCC wrapper ) and the Level2 API ( the pythonic API I’m talking about ).

Its coming along nicely we’ve targeted public release for the Level2 API for pythonOCC 0.5, which we expect to release in March ( 0.4 will follow in short notice ). Surely we’d appreciate your involvement though! Have a look at what’s here, if you’ve checked pythonOCC out from svn, you’ll find it in src/addons/KBE/Level2API.py

Gettin started with PyQt, wxPython and pythonOCC

In this sample, we will set up a simple application that:

  • create a menu and 2 menus items,
  • these 2 menu items create a box for the first one, and a cylinder for the second one,
  • for both wxPython and PyQt

We first call the SimpleGui module, that provides a simple interface to design GUI for both PyQt, wxPython and python-xlib:

from OCC.Display.SimpleGui import *

If you want to use wxPython, just set the backend as following:

set_backend(‘wx’)

If you want to use rather PyQt, just replace the previous line with

set_backend(‘qt’)

or, for python-xlib:

set_backend(‘X’)

The next step is to init the display:

display, start_display, add_menu, add_function_to_menu = init_display()

Let’s now define the two function that create and display a box and a cylinder:

def simple_test(event=None):
display.Test()

def simple_cylinder(event=None):
from OCC.BRepPrimAPI import BRepPrimAPI_MakeCylinder
s = BRepPrimAPI_MakeCylinder(60, 200)
display.DisplayShape(s.Shape())

Now we create a menu named ’simple test’ and add the two functions:

add_menu(’simple test’)
add_function_to_menu(’simple test’,simple_test)
add_function_to_menu(’simple test’,simple_cylinder)

Finally, ask the display to be rendered:

display.View_Iso()
display.FitAll()
start_display()

Here is the result under Windows XP/wxPython:

wx_demo

Source code for this sample is available in the /samples/Level2/Display folder.

pythonOCC 0.4 meshing features

Volumic mesh

The screencast below shows a volumic quandrangular mesh of a shapes resulting from a boolean operation (a cylinder removed from a box).

Screencast generated from the volumic_mesh.py sample from the /samples/Level1/SMESH folder.

Triangle/Quadrangle surfacic mesh

With pythonOCC 0.4, you can mesh any TopoDS_Shape object (either a surface or the boundary of a volume) with triangles. You can use:

  • the basic Mesher provided with OCC (first scenario on the screencast below),
  • use the standard triangle mesher of SMESH (second scenario) or
  • use the MEFISTO2 triangle mesher from SMESH.

This screencast was generated from the sample surfacic_mesh.py available in the /samples/src/Level1/SMESH folder.

Parametric modeling and meshing

The new release (0.4) of pythonOCC comes with the Parametric Application Framework (known as PAF) as well as a meshing suite (SMESH). Here is a small demo that shows how to use both these tools to achieve a parametric mesh.

On the screencast below, a simple box is drilled with a hole of diameter 10mm. The box is parametrized with its with, height, depth, and the whole with two parameters: R1 (the radius) and Angle1 (the angle of the revolution, by default set to 0). In the PAF, each time a parameter is modified, the geometry is re-computed and displayed. It’s also possible to register customized callbacks: they are called each time a paramater is updated. In the following demo, we just added a ‘Mesh’ callback: whenever the parameter R1 or Angle1 is modified, the mesh is re-computed and displayed (using the MEFISTO2 mesher).

The source code of this sample can be found in the samples/Level2/PAF directory.

Introduction to OCAF

What is OCAF and Why Might I Need It?

OCAF is the OpenCascade Application Framework. At it’s core, it provides the functionality to manage structured documents. The framework defines a document model but it’s up to the application to define the specific document structure (in the same way that xml defines a file format, but an application defines a specific xml schema). OCAF documents can be loaded from or saved to disk using a native format, or import/exported from a number of other formats.

Using OCAF you can:

  • Manage multiple documents and visualise document contents
  • store BRep Shapes, including their evolution (version control for Shapes), for undo/redo for example
  • define components and assemblies
  • define shape metadata like: colour, material, tolerancies, layers
  • define other metadata based on either existing standard types, or custom-defined types
  • import / export support for STEP and IGES, including layers, colours, materials and tolerances
  • define functions for reconstruction of parametric models

Basic OCAF Strucuture

OCAF documents are based on a hierarchy of labels (TDF.TDF_Label objects). At any one level in the tree, labels are identified by an index number. The series of index numbers from the root of the tree to a given label uniquely defines that label. The fully qualified label entry is writen as a colon-separated list of these integers e.g.

  • root label (0:)
    • label A (0:1)
      • label D (0:1:1)
      • label E (0:1:2)
    • label B (0:2)
    • label C (0:3)
      • label F (0:3:1)

Basic OCAF Use

Each OCAF app requires a single Application object.
Creating a new OCAF document

How is OCAF implemented in pythonOCC?

A recent developement of pythonOCC is the PAF framework, which implements Associativity, Parameters, Rules and Relations in a pythonic manner.