Hydrostatics & Stability for boats in Alibre

From Gemini:

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

  1. Open Visual Studio and create a C++ Windows Desktop Wizard project (DLL).

  2. Import the Alibre Design Type Library (AlibreX.tlb).

  3. 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.

Ref:

Some Concept:

https://www.food4rhino.com/en/app/swordfish-3d

Principles-of-yacht-design

The question to you is what that looks like inside Alibre Design. I know how to port the functionality (if possible). Which commands are used in Alibre Design? Porting the entire FreeCAD workbench is not a simple task especially since Alibre APIs are limited.

If you want these features in particular.

Features

  • Areas curve
  • Hydrostatics
  • Load conditions definition
  • Tank capacity curve
  • Static sink and trim
  • GZ curve
  • RAOs

FreeCAD/freecad.ship: A FreeCAD workbench aiding in naval vessel design

Ship Workbench - FreeCAD Documentation

What I’ll likely do is create a bridge to and from FreeCAD Ship and Alibre Design, rather than a port.

Hi Stephen

1.-I do like entire FreeCad Ship Workbench as add on in AD V21 but in C++ and not in Python Language as you know.

2.-The seven points are important, but the first six are a priority, especially the GZ analysis, as tanks can have a free surface effect on stability.

To understand better I have a simple spreadsheet but I don’t know here how give to you the file that make the Free surface calculus as maximum effect.

1 Like

Hi Stephen.
I was able to get in touch with Jose Luis Cercós (Creator of FreeCAD Ship Workbench), and he replied as follows:
"Hi, Giovanni!

Of course it can be implemented in C++. Unfortunately, I think the speed improvement would be negligible.

The module isn’t slow because it’s written in Python; in fact, if you analyze it in detail, almost all the heavy lifting is done by FreeCAD itself, which is written in C++. It’s slow because it works with solids/volumes, rather than surfaces/sections (as is the case in other CAD programs).

Working with volumes has the advantage of being simple and, in theory, more accurate. That’s why I chose that approach.

Best regards!
Pepe"

Here is my reply to his message, which may also be relevant to you:

"Hello Mr. Pepe,

Thank you very much for your response. I’m very pleased.
You should evaluate the differences between surfaces/slices and solids/volumes. It’s possible that, for a project’s profile—which requires a great many calculations to achieve the optimal result—it would be best to start with a surface/slice-based C++ approach, and then refine and apply the solid/volume-based calculation also in C++. That would be great.

Best regards!

Giovanni"

1 Like

I am waiting for V29 release to continue any addon work. I realize you are not a v29 user, however my process is built for the latest Alibre Design versions.

After the release I need a week or two for review.