From 4d712f44c220eac90c26afe4eb1c41b4f2f403c6 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Mon, 22 Dec 2025 12:52:55 +0100 Subject: [PATCH] PartDesign: Chamfer - migrate Size and Size2 for older files (#26137) * PartDesign: Chamfer - migrate Size and Size2 for older files * Apply suggestions from code review Co-authored-by: Chris Hennes --------- Co-authored-by: Chris Hennes --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 27 +++++++++++++++++++++++ src/Mod/PartDesign/App/FeatureChamfer.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index 47e6b5351e..fdec798ade 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -41,6 +41,8 @@ #include "FeatureChamfer.h" +#include + using namespace PartDesign; @@ -205,6 +207,8 @@ App::DocumentObjectExecReturn* Chamfer::execute() void Chamfer::Restore(Base::XMLReader& reader) { DressUp::Restore(reader); + + migrateFlippedProperties(reader); } void Chamfer::handleChangedPropertyType(Base::XMLReader& reader, const char* TypeName, App::Property* prop) @@ -220,6 +224,29 @@ void Chamfer::handleChangedPropertyType(Base::XMLReader& reader, const char* Typ } } +bool Chamfer::requiresSizeSwapping(const Base::XMLReader& reader) const +{ + return Base::getVersion(reader.ProgramVersion) < Base::Version::v1_0 + && (ChamferType.getValue() == 1 || ChamferType.getValue() == 2); +} + +void Chamfer::migrateFlippedProperties(const Base::XMLReader& reader) +{ + if (!requiresSizeSwapping(reader)) { + return; + } + + Base::Console().warning( + "The 'FlipDirection' property of the chamfer of %s is being adjusted to maintain" + "the same geometry in this FreeCAD version. If the re-saved file is later opened " + "in FreeCAD 0.21.x the chamfer result may differ due to the changed parameter " + "interpretation.\n", + getFullName() + ); + + FlipDirection.setValue(!FlipDirection.getValue()); +} + void Chamfer::onChanged(const App::Property* prop) { if (prop == &ChamferType) { diff --git a/src/Mod/PartDesign/App/FeatureChamfer.h b/src/Mod/PartDesign/App/FeatureChamfer.h index ccaca0f10f..a11f3637cb 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.h +++ b/src/Mod/PartDesign/App/FeatureChamfer.h @@ -70,6 +70,9 @@ protected: ) override; static const App::PropertyQuantityConstraint::Constraints floatSize; static const App::PropertyAngle::Constraints floatAngle; + + bool requiresSizeSwapping(const Base::XMLReader& reader) const; + void migrateFlippedProperties(const Base::XMLReader& reader); }; } // namespace PartDesign