OpenCascade is an open-source software development platform used for building 3D modeling and visualization applications. It provides a set of tools that allow developers to create complex geometric models and perform operations on them, such as Boolean operations, intersections, and extrusions.
OpenCascade is often used in the engineering, architecture, and manufacturing industries for designing and analyzing objects and structures.
This is a wrapper that enables using OpenCascade from Nim.
The site it is not maintained. Maybe in the future: Further documentation in occt.nim site
The following has been done with occt.nim.
Right now I am only testing it in Linux (ArchLinux). You can install OpenCascade like:
- ArchLinux:
$ yay -S opencascade
- Ubuntu:
$ sudo apt install libocct-foundation-dev
In order to install the bindings:
$ nimble install https://github.com/mantielero/occt.nim
Right now, a significant part of the library is wrapped. There are 75 packages already wrapped (in better or worst shape). For sure, there are much more functions wrapped than what you might need.
Most of the bindings are untested. On the other hand, they should work (or they should work with very little modification).
Wrapping the functions is the first step. Later you need more convenient functions that make the library more convenient to use (more "Nim-ish" -if that word exists-).
The wrapped packages are located under src/wrapper
.
In the folder src/lib
, some functions are included in order to make easier dealing with OpenCascade.
There are many things that can be done:
- Using the library. This will help to detect issues. This is about populating the
examples
folder. - Improving the usability. Some examples on how to improve the usability can be found in src/lib/foundation/gp.nim or src/lib/foundation/iter.nim.
- Adding easier API's like CadQuery or RepliCAD are proposing. An example is src/lib/sketcher/sketcher2d.nim. With that API you can do things like examples/api/sketcher2d_01.nim.
- OCCTUtils: seems interesting as well. It could serve as inspiration also. See also https://techoverflow.net/category/opencascade/
- If you wanna add a new package, here you can find some instructions. It is pretty straightforward.
I don't know much about licenses (any advise is wellcomed). My code is BSD, but you need to fulfill whatever OpenCascade license requires which is: GNU Lesser General Public License (LGPL) version 2.1.
-
Create the new package folder. For example
src/wrapper/pcdm
. -
Copy the files
genGenerator.nim
anded.nim
fromsrc/wrapper/cdm
into the new folder. -
In
genGenerator.nim
modify the following lines:
let prefix = "CDM"
let packageName = "cdm"
The prefix
indicate the starting string for the header files under /usr/include/opencascade
.
The packageName
is the name of the created folder.
- Execute
genGenerator
:
nim c -r genGenerator
this will create a new file gen.nim
and copy opencascade headers locally.
- Execute
gen.nim
:
nim c -r gen
this will execute c2nim
under the hood.
If all the headers were removed, then everything went fine. If not, you will have to play with gen.nim
commenting parts of the headers in order to avoid c2nim
failing.
- Then we edit
src/wrapper/pp.nim
(not a beauty). Around line 650, you have something like:
let folder = "cdm"
let toolkit = "TKCDF"
comment those lines and add two similar lines with the name of the new folder and the name of the associated toolkit for the package. In this case:
#let folder = "cdm"
#let toolkit = "TKCDF"
let folder = "pcdm"
let toolkit = "TKCDF"
- Execute it, by going into folder
src/wrapper
and then:
nim c -r pp
Notes:
a. Fixing Iterator
. Iterators are defined in ncollection_types
. If you have something like:
StorageDataMapIteratorOfMapOfPers* = Iterator....
probably needs to be:
StorageDataMapIteratorOfMapOfPers* = NCollectionDataMapIterator....