mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-28 11:21:30 +00:00
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:
co-authored by
Claude Opus 4.8
parent
c22351f63a
commit
2c0140afb9
@@ -8,6 +8,9 @@
|
||||
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopoDS_Wire.hxx>
|
||||
#include <cereal/cereal.hpp>
|
||||
#include <cereal/types/vector.hpp>
|
||||
#include <cereal/types/string.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
@@ -20,6 +23,11 @@ enum class BooleanMode { New, Add, Cut, Intersect };
|
||||
|
||||
enum class ExtrudeEnd { Blind, Symmetric, TwoSided, ThroughAll, UpToFace, UpToVertex };
|
||||
|
||||
// Serialize a TopoDS_Shape to/from a BRep string (declared before CadFeature so its
|
||||
// inline cereal save()/load() can resolve these non-dependent calls).
|
||||
std::string brep_to_string(const TopoDS_Shape& s);
|
||||
TopoDS_Shape brep_from_string(const std::string& d);
|
||||
|
||||
struct CadFeature {
|
||||
CadFeatureType type{CadFeatureType::Sketch};
|
||||
std::string name;
|
||||
@@ -181,8 +189,56 @@ struct CadFeature {
|
||||
bool cut_flip{false}; // flip the normal => swaps which side is "upper"
|
||||
bool cut_keep_upper{true}; // keep the +normal half
|
||||
bool cut_keep_lower{false}; // keep the -normal half (both => split into two bodies)
|
||||
|
||||
template<class Archive>
|
||||
void save(Archive& ar) const {
|
||||
std::string brep = (type == CadFeatureType::Import) ? brep_to_string(imported_solid) : std::string();
|
||||
ar(type, name, enabled, shape, plane, width, height, radius,
|
||||
profile, entities, constraints, entity_constraints, imported_regions,
|
||||
import_offset, import_scale_x, import_scale_y, import_on_face, import_face_body,
|
||||
sketch_ref, distance, symmetric, mode, extrude_end, distance2, taper_deg, flip,
|
||||
up_to_face, extrude_src_face, up_to_point, target_body,
|
||||
dressup_size, face_group, dressup_edge,
|
||||
hole_diameter, hole_depth, hole_through, hole_x, hole_y,
|
||||
thread_radius, thread_pitch, thread_height, thread_depth, thread_internal, thread_x, thread_y,
|
||||
shell_thickness, shell_face,
|
||||
draft_face, draft_angle,
|
||||
revolve_angle, revolve_axis,
|
||||
sweep_path_ref, loft_profile_refs, loft_ruled,
|
||||
pattern_circular, pattern_count, pattern_spacing, pattern_dir, pattern_angle,
|
||||
plane_base, plane_offset, plane_angle_tilt, plane_axis,
|
||||
bool_tool_body, bool_keep_tool, bool_tolerance, bool_target_face, bool_tool_face,
|
||||
cut_offset, cut_flip, cut_keep_upper, cut_keep_lower,
|
||||
brep);
|
||||
}
|
||||
template<class Archive>
|
||||
void load(Archive& ar) {
|
||||
std::string brep;
|
||||
ar(type, name, enabled, shape, plane, width, height, radius,
|
||||
profile, entities, constraints, entity_constraints, imported_regions,
|
||||
import_offset, import_scale_x, import_scale_y, import_on_face, import_face_body,
|
||||
sketch_ref, distance, symmetric, mode, extrude_end, distance2, taper_deg, flip,
|
||||
up_to_face, extrude_src_face, up_to_point, target_body,
|
||||
dressup_size, face_group, dressup_edge,
|
||||
hole_diameter, hole_depth, hole_through, hole_x, hole_y,
|
||||
thread_radius, thread_pitch, thread_height, thread_depth, thread_internal, thread_x, thread_y,
|
||||
shell_thickness, shell_face,
|
||||
draft_face, draft_angle,
|
||||
revolve_angle, revolve_axis,
|
||||
sweep_path_ref, loft_profile_refs, loft_ruled,
|
||||
pattern_circular, pattern_count, pattern_spacing, pattern_dir, pattern_angle,
|
||||
plane_base, plane_offset, plane_angle_tilt, plane_axis,
|
||||
bool_tool_body, bool_keep_tool, bool_tolerance, bool_target_face, bool_tool_face,
|
||||
cut_offset, cut_flip, cut_keep_upper, cut_keep_lower,
|
||||
brep);
|
||||
imported_solid = brep_from_string(brep);
|
||||
}
|
||||
};
|
||||
|
||||
// Serialize a TopoDS_Shape to/from a BRep string for cereal persistence.
|
||||
std::string brep_to_string(const TopoDS_Shape& s);
|
||||
TopoDS_Shape brep_from_string(const std::string& d);
|
||||
|
||||
// One independent solid in a multi-body document.
|
||||
struct CadBody {
|
||||
TopoDS_Shape shape;
|
||||
@@ -279,6 +335,10 @@ public:
|
||||
void clear();
|
||||
bool recompute(); // replay features -> body + display_mesh; false on error
|
||||
|
||||
static constexpr uint32_t SNAPORCA_CAD_RECIPE_VERSION = 1;
|
||||
std::string serialize_recipe() const;
|
||||
bool deserialize_recipe(const std::string& blob);
|
||||
|
||||
// Undo/redo of the feature recipe (Onshape-style Ctrl+Z). The caller marks a
|
||||
// user-action boundary by calling checkpoint() BEFORE the mutation(s) for that
|
||||
// action (add/delete/move/replace, or a direct features edit). undo()/redo() then
|
||||
|
||||
Reference in New Issue
Block a user