Mirror CAD persistence (K1+K2+G1) from snaporca-cad onto mainline OrcaSlicer

Dual-fork mandate: port the parametric-recipe 3MF persistence from
snaporca-cad commits ed19eac+147e1c4 so a saved project reopens with the
editable CAD feature tree, not just the baked mesh.

Shared kernel/format/GUI (identical to snaporca-cad):
- CadDocument serialize_recipe/deserialize_recipe (cereal BinaryArchive,
  versioned) + CadFeature split save/load + imported_solid<->BRep string.
- Model::cad_recipe carried through 3MF zip entry Metadata/SnapOrca_cad.bin
  (writer + binary-verbatim reader branch).
- DesignPanel on_commit() stamps the recipe; on_tab_shown() rehydrates a
  loaded project via load_recipe() (deserialize -> feed_bodies + refresh_tree).

Mainline-only adapters (no snaporca-cad counterpart — Catch2 v3 vs v2):
- tests/libslic3r/test_caddocument.cpp: <catch2/catch_all.hpp> +
  `using Catch::Approx;` (v3 scopes Approx under Catch::).
- tests/libslic3r/CMakeLists.txt: register test_caddocument.cpp (the
  original CAD port had left it out of the test build).

Verified on behemoth (snaporca-deps toolchain): libslic3r_tests clean;
[CadDocument] 17/18 (only the pre-existing tangent-to-circle SIGABRT fails,
identical to snaporca-tkz); K1 serialize round-trip + version-reject pass
(13 assertions); new [3mf] "CAD recipe blob survives a 3mf save/load cycle"
passes byte-for-byte; orca-slicer GUI links clean (186/186, DesignPanel.cpp
compiled). Interactive :10 click-through pending (no Design-tab automation).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVzKmX6Y1aEteit1HTXG4Q
This commit is contained in:
Tommaso Bianchi
2026-06-28 17:05:44 +02:00
co-authored by Claude Opus 4.8
parent c22351f63a
commit 2c0140afb9
10 changed files with 280 additions and 1 deletions
+30
View File
@@ -2652,6 +2652,29 @@ int DesignPanel::tree_icon_for(CadFeatureType t)
void DesignPanel::on_tab_shown()
{
if (m_viewport) m_viewport->refresh_bed();
// Rehydrate the parametric model from a freshly loaded project (the 3MF carried the
// recipe in Metadata/SnapOrca_cad.bin). Only when nothing is in progress here, so we
// never clobber an active design when the user just toggles back to the Design tab.
if (m_doc.features.empty()) {
if (Plater* plater = wxGetApp().plater()) {
const std::string& blob = plater->model().cad_recipe;
if (!blob.empty()) load_recipe(blob);
}
}
}
void DesignPanel::load_recipe(const std::string& blob)
{
if (blob.empty()) return;
if (!m_doc.deserialize_recipe(blob)) {
m_status->SetLabel(_L("Could not restore the CAD model from this project"));
return;
}
m_feature_counter = int(m_doc.features.size());
feed_bodies(); // push the restored bodies into the viewport
refresh_tree(); // rebuild the feature tree from the restored recipe
set_status_ok();
}
void DesignPanel::refresh_tree()
@@ -4526,6 +4549,13 @@ void DesignPanel::on_commit()
obj_list->load_mesh_object(m_disp_pick_mesh, "Design Body");
}
// Persist the editable parametric recipe alongside the committed meshes so the
// saved 3MF reopens with the full feature tree, not just the baked solid. An empty
// doc clears it, keeping non-CAD projects clean.
if (Plater* plater = wxGetApp().plater())
plater->model().cad_recipe =
m_doc.features.empty() ? std::string() : m_doc.serialize_recipe();
if (wxGetApp().mainframe != nullptr)
wxGetApp().mainframe->select_tab(size_t(MainFrame::tp3DEditor));
}