jCAE - occjava
What is occjava
occjava is a JNI wrapper which allows using OpenCASCADE from Java. Prior to jCAE 0.11, wrapper was handwritten, but starting from 0.11 version, it is generated by swig.
Setting the environment
These scripts aim at showing how to configure your environment to use occjava.
On Linux
#path to Opencascade CASROOT="/a/path/OpenCASCADE6.2.0/ros" #directory which contains liboccjava.so occjavaDir="/a/path/jcae-0.15.0/jcae/modules/lib" #set the LD_LIBRARY_PATH so Java can find the native libraries export LD_LIBRARY_PATH=$CASROOT/Linux/lib:$occjavaDir #Opencascade require it (don't ask why and don't forget it) export MMGT_OPT=0 #Run java java -classpath /a/path/occjava.jar:my_app_classpath my.application.MainClass #Or like this if you want to visualize the geometry java -classpath /a/path/occjava.jar:/a/path/jcae-viewer3d.jar:my_app_classpath my.application.MainClass
On Windows
REM path to Opencascade (should be set by the Opencascade installer) set CASROOT=C:\a\path\OpenCASCADE6.2.0\ros REM directory which contains occjava.dll set occjavaDir=C:\a\path\jcae-0.15.0\jcae\modules\lib REM set the PATH so Java can find the native libraries set PATH=%CASROOT%\win32\bin;%occjavaDir%;%PATH REM Opencascade require it (don't ask why and don't forget it) set MMGT_OPT=0 REM run java java -classpath c:\a\path\occjava.jar;[my_app_classpath] my.application.MainClass REM Or like this if you want to visualize the geometry java -classpath c:\a\path\occjava.jar;c:\a\path\jcae-viewer3d.jar;[my_app_classpath] my.application.MainClass
In Eclipse
- Go to Project, Properties, Java Build Path, Add external jar, and add occjava.jar.
- Before running go to Run, Run..., [your main class], Environment, and the PATH or LD_LIBRARY_PATH as specified above.
Examples
- Explorer.java
- Topology exploration (TopoDS_Iterator and TopEx_Explorer)
- BRepBuilder.java
- Remove and compose shapes
- Dimensions.java
- Get the dimensions of a shape
- Curvature.java
- Surface local properties (coordinates, derivatives, curvature ...)
More examples can be found here.
Extending
Here are the steps to extend occjava:
- Be sure you really need to extend occjava. May be it is possible to do what you want with existing API and 5 lines of pure Java code.
- Use your prefered Git client to get the sources of occjava from http://github.com/jeromerobert/jCAE/
- Read these pages and build it:
- Find the file you need to modify (or even create) among the src/*.i files. The file name should be the Opencascade package name. For instance if you want to add BRepTools::OuterWire, do it within src/BRepTools.i. The TopoDS_Shape class is in TopoDS.i. There are still dirty things and you may also have to look in OccJava.i (use grep).
- To add a method in an existing class just copy the method prototype from the .hxx file (without the EXPORT keyword).
- To add a class add %{#include <MyOccClass.hxx> %} and describe your class as in a hxx file (without EXPORT keyword). Add only the method you need (occjava should remain as small as possible). Use %rename to let methods match the Java coding convention. Look at already existing classes if you feel lost.
- To add typemap (native to Java type conversion), have a look at examples in gp.i. Adding typemap is not imediate, you may have to read the Swig/Java documentation.
- Send us your patch here.