Skip to content

Latest commit

 

History

History

README.md

Open CASCADE Technology C# Wrapper Sample

License .NET Platform

Created: 2007-06-29
Copyright: © 2007-2025 OPEN CASCADE SAS
Last Updated: 2025

Overview

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.

🚀 Features

  • 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 Structure

Core Libraries

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

Windows-Specific Components

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

🛠️ Prerequisites

Required Components

  1. Visual Studio (Windows) or .NET SDK (Linux)

    • Windows: Visual Studio 2019 or later
    • Linux: .NET 6.0 SDK or later
  2. Open CASCADE Technology (OCCT)

    • Version 7.6.0 or later recommended
    • Built and installed on your system
  3. SWIG (Simple Wrapper and Interface Generator)

  4. CMake

  5. Tcl/Tk (Optional, for advanced features)

Windows-Specific Requirements

  • Windows 10 or later (for WPF samples)
  • OpenGL drivers with WGL_NV_DX_interop extension support
  • Visual C++ Redistributables (latest version)

📦 Installation & Configuration

Step 1: Environment Setup

# Clone or extract the sample to your desired location
# Example: %CASROOT%/samples/csharp

Step 2: CMake Configuration

Windows (using CMake GUI)

  1. Open CMake GUI
  2. Set source directory to your sample location
  3. Choose build directory
  4. Select generator (e.g., "Visual Studio 17 2022")
  5. 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)

Linux (using command line)

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

Step 3: Build and Install

Windows

# Open solution in Visual Studio
# Build ALL_BUILD project
# Build INSTALL project to deploy

Linux

make -j$(nproc)
make install

🔄 Regenerating Wrappers

When modifying wrapper interface files or adding new classes:

  1. Close Visual Studio (if open)
  2. Remove build artifacts:
    rm -rf build/Wrappers
  3. Reconfigure and rebuild:
    cmake --build build --target clean
    cmake --build build
  4. Check for unwrapped types (Windows):
    cd build
    listbad.bat

🧪 Running Samples

Windows

# Console test
CSharpTest.bat [vc143] [x64] [Release]

# WinForms sample
ImportExport.bat [vc143] [x64] [Release]

# WPF sample  
ImportExportWPF.bat [vc143] [x64] [Release]

Linux

# Console test
./CSharpTest.sh

📚 Adding New Classes

For detailed instructions on extending the wrapper:

  1. See OCCwrapCSharp/OCC2CSharp.txt for C#-specific wrapping details
  2. See HowToWrap.txt for general wrapping guidelines
  3. Follow the existing patterns in interface files (.i files)

Basic Wrapping Example

// In your .i file
%{
#include <YourNewClass.hxx>
%}

WRAP_CLASS(YourNewClass)

🐛 Troubleshooting

Common Issues

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

Getting Help

  1. Check the build output for specific error messages
  2. Run listbad.bat to identify unwrapped types
  3. Verify all prerequisites are correctly installed
  4. Consult OCCT documentation for class-specific details

📄 License

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.

🤝 Contributing

For questions or issues related to wrapping:

  1. Check existing interface files for similar patterns
  2. Refer to SWIG documentation for advanced features
  3. 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.