This Sketch tool for Part & 2D Drawing WorkSpaces will be essential for generating structural sections from a lines and curves (spline) . Currently, it is not parametric as show in the pic, which means that changes to the base curve are not reflected in the offset curve. This results in a significant loss of time during the design process.
Translate the source code from the FreeCAD Ship Workbench into C++ so that it can be used as an add-on in Alibre Design Version 21
Translating the FreeCAD Ship Workbench into a C++ add-on for Alibre Design is a significant undertaking. The two programs use entirely different architectures, APIs, and programming languages for their extensions.
The FreeCAD Ship Workbench is primarily written in Python and relies on the OpenCASCADE (OCCT) kernel. Alibre Design is a Windows-native application built on the ACIS kernel, and its API is exposed via COM (Component Object Model), typically accessed using C++ or C#.
Here is the strategic roadmap for this porting project.
1. Architecture Comparison
Before writing code, you must account for the fundamental differences in how these systems handle data:
Feature
FreeCAD Ship Workbench
Alibre Design (v21)
Primary Language
Python
C++ / C# (.NET)
Geometry Kernel
OpenCASCADE (OCCT)
Spatial ACIS
API Style
Script-heavy / Modular
COM-based / Event-driven
UI Framework
Qt (PySide)
Windows Forms / WPF
2. Core Translation Challenges
Geometry Kernel Mismatch
The Ship Workbench uses OCCT functions for hydrostatic calculations and hull generation (like Part.BRep objects). Alibre uses ACIS.
The Problem: You cannot simply copy-paste logic that involves topological naming or face filtering.
The Solution: You will need to rewrite the geometry creation logic using the IADPartSession and IADDesignSession interfaces in the Alibre API.
Hydrostatic Logic
The Ship Workbench performs calculations for displacement, center of buoyancy, and transverse stability.
The Port: Since these are mathematical/physical formulas, the logic translates well to C++. However, you must implement your own “slicing” algorithm (integrating cross-sectional areas) because you won’t have the specific FreeCAD Ship module helpers.
3. Step-by-Step Porting Guide
Phase A: Setting up the C++ Project
Open Visual Studio and create a C++ Windows Desktop Wizard project (DLL).
Import the Alibre Design Type Library (AlibreX.tlb).
Implement the IADAddOn interface so Alibre recognizes your DLL as an active add-on.
Phase B: Translating Python to C++
You will need to manually map Python logic to C++ COM calls.
FreeCAD (Python) Example:
Python
# Creating a point
p = FreeCAD.Vector(0, 0, 0)
Alibre (C++ COM) equivalent:
C++
// Using smart pointers from the Alibre Type Library
IADDesignSessionPtr pSession = pTargetApp->ActiveSession;
IADDesignContextPtr pContext = pSession->DesignContext;
// Geometry creation requires moving through the Alibre API hierarchy
Phase C: UI Implementation
FreeCAD uses .ui files (Qt). For Alibre v21, you should:
Create a Docking Pane or a modal dialog using the Win32 API or MFC.
Alternatively, wrap a C# UserControl into your C++ project to make UI design easier.
4. Critical Technical Considerations
The Ship Outline: In FreeCAD, ship hulls are often generated via “Lofts.” In Alibre C++, you will use IADLoftFeature.
Units: FreeCAD is unit-agnostic internally (usually mm), while Alibre handles units strictly through its IADDesignSession settings. Ensure your C++ math accounts for this.
Performance: One advantage of this move is speed. C++ will handle the iterative hydrostatic slicing significantly faster than the original Python implementation.
5. Recommended Tools
OpenCASCADE: Since the Ship Workbench logic is built for OCCT, you might consider linking the OCCT C++ libraries into your Alibre Add-on to handle the “heavy lifting” of the ship-specific math before passing the final coordinates to Alibre.
Alibre SDK Documentation: Found in the \API\ folder of your Alibre installation directory. Use the AlibreX.chm file as your primary reference.
This is a high-level architectural shift. I recommend starting with porting a single calculation (like Displacement) before attempting to port the hull generation tools.