From 2d22c8f4afa9984b237e0208c6904a6b24e7b18a Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sat, 26 Aug 2023 20:02:28 +0200 Subject: [PATCH] PD: Keep Length and Offset in sync for LinearPattern As Length and Offset represents the same concept in different way it is useful to keep them in sync when it is possible. Update to one of them will update the other with approperiate value. This behaviour behaviour works only if both properties are not coming from expression engine - those will stay not touched. --- src/Mod/PartDesign/App/FeatureLinearPattern.cpp | 12 +++++++++++- .../PartDesign/Gui/TaskLinearPatternParameters.cpp | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp index 7826abf175..2ba1df02a2 100644 --- a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp +++ b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp @@ -238,11 +238,21 @@ void LinearPattern::handleChangedPropertyType(Base::XMLReader& reader, const cha void LinearPattern::onChanged(const App::Property* prop) { + auto mode = static_cast(Mode.getValue()); + if (prop == &Mode) { - auto mode = static_cast(Mode.getValue()); setReadWriteStatusForMode(mode); } + // Keep Length in sync with Offset + if (mode == LinearPatternMode::offset && prop == &Offset && !Length.testStatus(App::Property::Status::Immutable)) { + Length.setValue(Offset.getValue() * (Occurrences.getValue() - 1)); + } + + if (mode == LinearPatternMode::length && prop == &Length && !Offset.testStatus(App::Property::Status::Immutable)) { + Offset.setValue(Length.getValue() / (Occurrences.getValue() - 1)); + } + Transformed::onChanged(prop); } diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index 8ed53aac18..b0e6c13d64 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -198,7 +198,6 @@ void TaskLinearPatternParameters::setupUI() } adaptVisibilityToMode(); - updateUI(); connectSignals(); } @@ -241,6 +240,8 @@ void TaskLinearPatternParameters::adaptVisibilityToMode() ui->lengthWrapper->setVisible(mode == PartDesign::LinearPatternMode::length); ui->offsetWrapper->setVisible(mode == PartDesign::LinearPatternMode::offset); + + updateUI(); } void TaskLinearPatternParameters::onUpdateViewTimer()