Created: 2007-06-29
Copyright: © 2007-2025 OPEN CASCADE SAS
Last Updated: 2025
This advanced sample demonstrates how to wrap Open CASCADE Technology (OCCT) classes for C# language, enabling seamless integration with .NET applications. The wrapper provides a uniform and transparent way to use OCCT functionality from within managed code environments.
- Complete OCCT Integration: Access to core OCCT classes and functionality
- Cross-Platform Support: Works on Windows and Linux
- Multiple .NET Targets: Support for .NET Framework, .NET Core, and .NET 5+
- Visual Controls: Ready-to-use WinForms and WPF viewer controls
- Comprehensive Examples: Sample applications demonstrating real-world usage
| Project | Description | Type |
|---|---|---|
| OCCwrapCSharp | Core wrapper library with C++ native interface | Native Library |
| OCCCSharp | .NET assembly with C# shadow classes | Managed Assembly |
| CSharpTest | Console application with test cases | Test Application |
| Project | Description | Framework |
|---|---|---|
| OCCWinForms | OCCT viewer control for WinForms | Windows Forms |
| OCCWpf | OCCT viewer control for WPF | WPF |
| ImportExport | Standard OCCT sample in C# | Windows Forms |
| ImportExportWPF | 3D viewer WPF integration sample | WPF |
-
Visual Studio (Windows) or .NET SDK (Linux)
- Windows: Visual Studio 2019 or later
- Linux: .NET 6.0 SDK or later
-
Open CASCADE Technology (OCCT)
- Version 7.6.0 or later recommended
- Built and installed on your system
-
SWIG (Simple Wrapper and Interface Generator)
- Version 4.0.0 or later
- Download from SWIG SourceForge
-
CMake
- Version 3.20 or later
- Download from CMake Official Site
-
Tcl/Tk (Optional, for advanced features)
- Version 8.6 or later
- Download from ActiveState
- Windows 10 or later (for WPF samples)
- OpenGL drivers with WGL_NV_DX_interop extension support
- Visual C++ Redistributables (latest version)
# Clone or extract the sample to your desired location
# Example: %CASROOT%/samples/csharp- Open CMake GUI
- Set source directory to your sample location
- Choose build directory
- Select generator (e.g., "Visual Studio 17 2022")
- Configure the following variables:
CMAKE_INSTALL_PREFIX # Installation directory
BUILD_dotNetFrameworkVersion # Target .NET version (default: net6.0)
OpenCASCADE_DIR # Path to OCCT installation
SWIG_EXECUTABLE # Path to swig.exe
TCL_INCLUDE_PATH # Tcl include directory (if needed)
WRAP_PRODUCTS # Enable OCCT Products wrapping (optional)mkdir build && cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/path/to/install \
-DOpenCASCADE_DIR=/path/to/occt \
-DSWIG_EXECUTABLE=/usr/bin/swig \
-DBUILD_dotNetFrameworkVersion=net6.0# Open solution in Visual Studio
# Build ALL_BUILD project
# Build INSTALL project to deploymake -j$(nproc)
make installWhen modifying wrapper interface files or adding new classes:
- Close Visual Studio (if open)
- Remove build artifacts:
rm -rf build/Wrappers
- Reconfigure and rebuild:
cmake --build build --target clean cmake --build build
- Check for unwrapped types (Windows):
cd build listbad.bat
# Console test
CSharpTest.bat [vc143] [x64] [Release]
# WinForms sample
ImportExport.bat [vc143] [x64] [Release]
# WPF sample
ImportExportWPF.bat [vc143] [x64] [Release]# Console test
./CSharpTest.shFor detailed instructions on extending the wrapper:
- See
OCCwrapCSharp/OCC2CSharp.txtfor C#-specific wrapping details - See
HowToWrap.txtfor general wrapping guidelines - Follow the existing patterns in interface files (
.ifiles)
// In your .i file
%{
#include <YourNewClass.hxx>
%}
WRAP_CLASS(YourNewClass)| Issue | Solution |
|---|---|
| SWIG errors | Check interface file syntax and dependencies |
| Missing types | Verify wrapping order and cyclic dependencies |
| Runtime errors | Ensure all DLLs are in the same directory |
| Build failures | Check OCCT and .NET SDK versions |
- Check the build output for specific error messages
- Run
listbad.batto identify unwrapped types - Verify all prerequisites are correctly installed
- Consult OCCT documentation for class-specific details
This software is furnished in accordance with the terms and conditions of the commercial license agreement with OPEN CASCADE SAS. See the license file for complete terms.
For questions or issues related to wrapping:
- Check existing interface files for similar patterns
- Refer to SWIG documentation for advanced features
- Test thoroughly with both Debug and Release configurations
Note: This wrapper provides a bridge between native OCCT libraries and the .NET ecosystem, enabling powerful CAD/CAM applications to be built using C# and other .NET languages.