ifcviewer: cache CoordinateOperation in sidecar (v10 -> v11)

Previously, applyCoordinateOperationToViewport — which pushes both
CoordinateOperation and ModelTransformation — was only called on
paths that required the IFC source to be loaded
(onLoadedFromStream and onDataSourceReady).  Sidecar-only loads
(loadDataSource off, or no .ifc/.rdb sibling) silently lost both
stages.

Cache the per-model georef + unit scales in the sidecar itself so
the IFC source isn't needed to apply them:

  SidecarData gains
    coordinate_operation_meters[16]  // column-major
    project_length_to_meters
    map_unit_to_meters
    has_coordinate_operation

  148 B fixed block written/read between instances and elements.
  SIDECAR_VERSION 10 -> 11; existing sidecars rebuild on next load.

  MainWindow::writeSidecarForModel populates the block from
  loader_->modelGeoref(mid) before writeSidecar.

  SceneLoader::applySidecarData restores it into the model's
  ModelGeoref + sets has_georef = true, so subsequent
  loader_->modelGeoref(mid) calls return the cached data without
  needing the IFC.

  MainWindow::onLoadedFromSidecar now calls
  applyCoordinateOperationToViewport(mid) directly — both
  CoordinateOperation and ModelTransformation land at sidecar-load
  time, no longer waiting on a possibly-never-arriving data source.

Edits to the IFC's IfcMapConversion don't invalidate the cache —
delete the .ifcview manually if the source's georef changes.  This
matches the existing cache-invalidation contract.

Tests: round-trip the new fields through the existing sidecar
fixture; assert SIDECAR_VERSION == 11.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-05-02 19:08:45 +10:00
parent e0e143bab5
commit 8ffdb8f0b9
5 changed files with 99 additions and 6 deletions
+20 -1
View File
@@ -53,7 +53,13 @@ static constexpr uint32_t SIDECAR_MAGIC = 0x49465657; // "IFVW"
// result. Sidecar serialises both; on load the transform is recomputed
// from placement_transformation + the ViewportWindow's current stage
// matrices, so v10 sidecars are reusable across .ifcfeds.
static constexpr uint32_t SIDECAR_VERSION = 10;
// v11 = SidecarData gains a per-model CoordinateOperation cache:
// coordinate_operation_meters[16] (column-major), unit scales, and a
// has_coordinate_operation flag. Lets sidecar-loaded models apply
// georef without re-parsing the IFC source. Edits to the IFC's
// IfcMapConversion do NOT invalidate the sidecar — delete the
// .ifcview manually if you change the source's georef parameters.
static constexpr uint32_t SIDECAR_VERSION = 11;
static constexpr uint32_t SIDECAR_ENDIAN = 0x01020304;
// Fixed-size element record. Strings are stored as (offset, length) pairs
@@ -83,6 +89,19 @@ struct SidecarData {
std::vector<MeshInfo> meshes; // indexed by local_mesh_id
std::vector<InstanceCpu> instances; // sorted by mesh_id
// CoordinateOperation cache (v11+). Mirrors ModelGeoref so a sidecar
// load can apply georef without re-parsing the IFC source.
// has_coordinate_operation == 0 means the model has no
// IfcMapConversion; the matrix is then the identity placeholder.
double coordinate_operation_meters[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
double project_length_to_meters = 1.0;
double map_unit_to_meters = 1.0;
uint32_t has_coordinate_operation = 0;
// Element tree metadata.
std::vector<PackedElementInfo> elements;
std::string string_table;