Back

C# Wrapper

What OCC C# Wrapper Is

The OCC C# Wrapper is a tool for wrapping Open CASCADE Technology (OCCT) C++ classes to C#, allowing their use within .NET applications. The C# interface reuses C++ DLLs and can call C++ methods through C# calls. The wrapping process generates a list of C# files that together form a single C# project interface. This results in a single DLL with modules that correspond to the wrapped OCCT classes.

Benefits of OCC C# Wrapper

  • True Cross-Platform Development: Ability to use the robust OCCT C++ CAD kernel on both Windows and Linux/Unix environments through .NET, enabling consistent application behavior across all platforms.
  • Seamless Integration: Easily integrate powerful 3D CAD capabilities into existing .NET applications with minimal effort.
  • Performance: Maintain the high performance of native C++ code while working in the .NET ecosystem.
  • Type Safety: Enjoy full IntelliSense support and compile-time type checking for OCCT operations.
  • Simplified Deployment: Distribute your application with a single wrapped DLL rather than dealing with complex native library dependencies.
  • Modern Development Experience: Use the latest .NET features and tooling while leveraging the industrial-strength OCCT kernel.
  • Plugin Architecture Support: Ideal for creating plugins that need CAD functionality for major applications on both Windows and Linux/Unix systems.

C# Wrapper Full Version

The full version of the C# wrapper is a complete package containing all the necessary scripts and files to generate C# files from a C++ OCCT project and build them into a single DLL. After purchasing the full version, you will have the freedom to update the generator based on your needs. The delivery includes the full source package, and you are free to use it in any application you are developing. Using the purchased scripts, it will be possible to generate wrappers for MacOS as well. The delivery also includes comprehensive instructions for adapting and extending the wrapping mechanism to fit your specific requirements.

Advanced Usage Scenarios

  • Custom CAD Applications: Build specialized CAD tools tailored to your industry’s unique requirements.
  • 3D Visualization Systems: Create sophisticated visualization solutions with full access to OCCT’s powerful rendering capabilities.
  • Engineering Analysis Software: Develop applications that combine CAD modeling with engineering analysis and simulation.
  • Cross-Platform Plugins: Develop plugins with consistent behavior across Windows, Linux, and MacOS environments.
  • Legacy System Integration: Connect modern .NET applications with existing CAD infrastructure and data formats.
  • Multi-Platform Enterprise Solutions: Deploy the same codebase across your entire organization regardless of operating system preferences.

C# Wrapper Code Sample


// Reading CAD FILES Sample:
using OCC.TCollection;
using OCC.DE;
using OCC.TDocStd;
using OCC.XCAFApp;
using OCC.STEPCAFControl;

// Load a container for each DE component
var aWrapper = DE_Wrapper.GlobalWrapper().Copy();
// Manually updating parameters for reading CAD files
TCollection_AsciiString thePath = new TCollection_AsciiString("");
DE_Provider? aProvider = null;
if (!aWrapper.FindProvider(thePath, true, aProvider).)
{
// Do something
}
// Modify string with parameters, described in the documentation:
DE_ConfigurationNode aConfig = aProvider.GetNode();
TCollection_AsciiString aParameters = aConfig.Save();
// https://dev.opencascade.org/doc/overview/html/occt_user_guides__de_wrapper.html
aConfig.Load(aParameters);

// Reading CAD file
TDocStd_Document? aDoc = null;
XCAFApp_Application anApp = XCAFApp_Application.GetApplication();
anApp.NewDocument(new TCollection_ExtendedString("BinXCAF"), aDoc);
if (!aProvider.Read(thePath, aDoc))
{
// Do something
}

// Sample to Read using original reader functionality
var aReader = new STEPCAFControl_Reader();
aReader.SetColorMode(true);
if (!aReader.Perform(thePath, aDoc))
{
// Do something
}

Technical Implementation Advantages

The OCC C# Wrapper provides a thoughtfully designed interoperability layer that offers several technical advantages:
  • Automatic memory management for OCCT objects through C# garbage collection
  • Efficient marshaling of complex data structures between managed and unmanaged code
  • Protection against common interoperability issues like memory leaks and dangling pointers
  • Preservation of OCCT’s object hierarchy and relationships in the C# wrapper
  • Support for callback mechanisms allowing C++ code to invoke .NET methods
  • Platform-independent code that works identically on Windows and Linux/Unix

C# Wrapper Overview in Visual Studio

The final result of the wrapping process is a single DLL that can be easily integrated into any C# project. Below is a simple example of how the wrapped DLL appears in the “VS Object Browser”:

Windows C# Support:

  • .NET Framework v3.5
  • .NET Framework v4.0
  • .NET Framework v4.5
  • .NET Framework v4.5.1
  • .NET Framework v4.5.2
  • .NET Framework v4.6
  • .NET Framework v4.6.1
  • .NET Framework v4.6.2
  • .NET Framework v4.7
  • .NET Framework v4.7.1
  • .NET Framework v4.7.2
  • .NET 6.0
  • .NET 7.0
  • .NET 8.0
  • .NET 9.0

Linux C# Support:

  • .NET 6.0
  • .NET 7.0
  • .NET 8.0
  • .NET 9.0

Do you have more questions?
We will do our best to answer your questions
stab-img
Backing your path to digital Future
Mobile version of the website is on development.  Please open the website on your desktop computer.
Or go to the old version of the website at old.opencascade.com
Follow Us: