ifcviewer: merge Federation classes into the lib

Move src/ifcviewer-full/Federation.{h,cpp} (and its tests) into
src/ifcviewer/ so the lib stays the single source of truth for the
federation data model.  Restores the original "agnostic lib usable
from ifcviewer-full and ifcviewer-minimal alike" framing.

Drop the unused per-model transform[16] / has_transform field — it
was round-trip-only with no UI to author it, and is being replaced
by an intent-based ModelTransform in the next commit.  No real
.ifcfed in the wild populated this field; old files still load
(unknown JSON keys ignored), they just lose the unused transform.

Replaces the pure-data-model Federation.{h,cpp} that was added a
few commits earlier — that file's structs and compose helpers
return as part of the merged Federation in commit 6.

ifcviewer-full's per-app tests dir is removed (test_federation was
the only one); BUILD_IFCVIEWER_TESTS now wires test_federation in
under src/ifcviewer/tests/, with the Qt6::Core/Gui/Test dependency
declared inline since unlike the other Tier-1 tests it has to pull
Qt in.  All 31 tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-05-01 14:41:41 +10:00
parent 540f3acf52
commit ecf0a5a4e1
8 changed files with 343 additions and 608 deletions
+72 -87
View File
@@ -17,100 +17,85 @@
* *
********************************************************************************/
// Federation-level transformation data model and compose helpers.
//
// A federation is the user's working scene, composed of one or more IFC
// models. Each model lives at:
//
// stage3 · stage4 · stage2 · placement_stage1
//
// where:
// - stage1 is per-mesh vertex rebasing (applied to the geometry buffers)
// - stage2 is the per-model georef matrix (immutable, derived from the IFC)
// - stage3 is the federation-wide false origin (mutable, this header)
// - stage4 is the per-model placement within the federation (mutable, this header)
//
// All composed matrices are in metres. The user-authored intent is stored
// in source units (model project unit / model map unit / federation unit) to
// preserve precision; conversion to metres happens in the compose helpers.
#ifndef FEDERATION_H
#define FEDERATION_H
#include <Eigen/Dense>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QDateTime>
#include <QVector3D>
#include <string>
#include <vector>
// Federation-wide settings persisted in .ifcfed.
struct FederationConfig {
// IfcSIUnit name ("METRE") or IfcConversionBasedUnit name ("foot", "inch", ...).
std::string unit_name = "METRE";
// SI prefix ("MILLI", "KILO", ...) — empty for unprefixed or for
// conversion-based units.
std::string unit_prefix = "";
};
// Stage 3 — the federation false origin. Authoring intent is "nominate this
// XYZ as the new origin, with optional Z-axis heading rotation". Composed as
// In-memory representation of an .ifcfed file (IFC federation).
//
// stage3 = R_z(rz_deg) · T(-xyz_in_metres)
// A federation is a named, ordered list of model sources plus an optional
// "home view" camera state. Source paths can be relative (resolved against
// the .ifcfed's directory) or absolute. Save() reserialises paths relative
// when they live under the federation file's directory tree, absolute
// otherwise — Save As recomputes against the new location.
//
// i.e. translate the federation so the nominated point lands at the origin,
// then rotate around the new origin. Translation is given in federation unit;
// rotation is in degrees.
struct FederationOrigin {
Eigen::Vector3d xyz = Eigen::Vector3d::Zero(); // federation unit
double rz_deg = 0.0; // degrees
// Round-trip-only fields today (no UI to edit, but preserved across load/
// save): per-model `visible`, future cloud `source.kind`s.
class Federation : public QObject {
Q_OBJECT
public:
struct HomeView {
QVector3D target;
float distance = 50.0f;
float yaw = 45.0f; // degrees
float pitch = 30.0f; // degrees
};
struct Model {
QString id; // stable, persisted
QString display_name;
QString source_kind = "local"; // future: "http", "speckle", ...
QString source_path; // resolved absolute when kind == "local"
bool visible = true;
};
explicit Federation(QObject* parent = nullptr);
// Round-trip
bool load(const QString& path, QStringList* warnings, QString* err);
bool save(const QString& path, QString* err);
// Mutations
void clear();
QString addModel(const QString& source_path,
const QString& display_name = QString());
void removeModel(const QString& fed_id);
void setHomeView(const HomeView& hv);
void clearHomeView();
// Accessors
const std::vector<Model>& models() const { return models_; }
const Model* findById(const QString& fed_id) const;
bool isDirty() const { return dirty_; }
void markClean();
QString filePath() const { return file_path_; }
QString name() const { return name_; }
bool hasHomeView() const { return has_home_view_; }
const HomeView& homeView() const { return home_view_; }
signals:
void dirtyChanged(bool dirty);
private:
void setDirty(bool d);
static QString generateId();
static bool isFederationPath(const QString& path);
QString file_path_;
QString name_;
QDateTime created_;
QDateTime modified_;
std::vector<Model> models_;
bool has_home_view_ = false;
HomeView home_view_;
bool dirty_ = false;
};
// Frame in which ModelTransform.a is expressed.
// ModelLocal — pre-stage2 model coordinates, in the model's project length unit
// ModelGlobal — post-stage2 model coordinates, in the model's map unit
enum class AFrame { ModelLocal, ModelGlobal };
// Stage 4 — the per-model placement within the federation. Authoring intent
// is "rotate the model around `pivot`, then translate so that point `a` lands
// at point `b`". Composed as
//
// R_local = R_z(rz) · R_y(ry) · R_x(rx) [intrinsic XYZ]
// R_at_pivot = T(pivot_m) · R_local · T(-pivot_m)
// stage4 = T(b_m - R_at_pivot · a_m) · R_at_pivot
//
// Numbers are stored in their original input unit (a in model project or map
// unit per a_frame, b/pivot in federation unit) so that the user's typed
// values round-trip without precision loss.
struct ModelTransform {
AFrame a_frame = AFrame::ModelGlobal;
Eigen::Vector3d a = Eigen::Vector3d::Zero(); // model project / map unit
Eigen::Vector3d b = Eigen::Vector3d::Zero(); // federation unit
Eigen::Vector3d rxyz_deg = Eigen::Vector3d::Zero(); // degrees, intrinsic XYZ
Eigen::Vector3d pivot = Eigen::Vector3d::Zero(); // federation unit
};
// Per-model unit scales captured at load time. project_length_to_meters
// comes from calculateUnitScale(file, "LENGTHUNIT"); map_unit_to_meters from
// siScaleFromNamedUnit(getMapUnit(file)) and falls back to the project length
// scale when the model has no MapUnit.
struct ModelUnits {
double project_length_to_meters = 1.0;
double map_unit_to_meters = 1.0;
};
// 1 federation_unit -> N metres. Cached at the call site if needed.
double federationUnitToMeters(const FederationConfig&);
// Compose stage 3 (federation false origin) into a 4x4 matrix in metres.
Eigen::Matrix4d composeFederationOrigin(const FederationOrigin&,
const FederationConfig&);
// Compose stage 4 (per-model placement within the federation) into a 4x4
// matrix in metres. `stage2_meters` is the model's georef matrix (e.g.
// helmertMetersFromParameters · inv(wcs_meters)) — needed to lift `a` into
// metres when a_frame == ModelLocal. Pass identity when stage 2 is disabled
// or absent.
Eigen::Matrix4d composeModelTransform(const ModelTransform&,
const FederationConfig& fed_cfg,
const ModelUnits& model_units,
const Eigen::Matrix4d& stage2_meters);
#endif // FEDERATION_H