From 437a89e42ae52880e1d3ffc83acf3aa6bb03d147 Mon Sep 17 00:00:00 2001 From: Wanderer Fan Date: Thu, 3 Mar 2022 09:32:36 -0500 Subject: [PATCH] [TD]fix ScaleType change behaviour --- src/Mod/TechDraw/App/DrawProjGroup.cpp | 10 +++++----- src/Mod/TechDraw/App/DrawProjGroupItem.cpp | 2 +- src/Mod/TechDraw/App/DrawView.cpp | 23 +++++++++++++++++++--- src/Mod/TechDraw/App/DrawView.h | 1 + 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index ee2d7d6b6f..c1f4a9d30f 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -143,15 +143,15 @@ void DrawProjGroup::onChanged(const App::Property* prop) } if (prop == &ScaleType) { - double newScale = getScale(); if (ScaleType.isValue("Automatic")) { //Nothing in particular } else if (ScaleType.isValue("Page")) { - newScale = page->Scale.getValue(); + double newScale = page->Scale.getValue(); if(std::abs(getScale() - newScale) > FLT_EPSILON) { Scale.setValue(newScale); } } + updateChildrenScale(); } if (prop == &Rotation) { if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { @@ -1008,8 +1008,8 @@ void DrawProjGroup::updateChildrenScale(void) Base::Console().Log("PROBLEM - DPG::updateChildrenScale - non DPGI entry in Views! %s\n", getNameInDocument()); throw Base::TypeError("Error: projection in DPG list is not a DPGI!"); - } else if(view->Scale.getValue() != Scale.getValue()) { - view->Scale.setValue(Scale.getValue()); + } else { + view->Scale.setValue(getScale()); view->recomputeFeature(); } } @@ -1063,7 +1063,7 @@ void DrawProjGroup::updateViews(void) { auto view(dynamic_cast(it)); if (view == nullptr) { //if an element in Views is not a DPGI, something really bad has happened somewhere - Base::Console().Log("PROBLEM - DPG::updateChildrenScale - non DPGI entry in Views! %s\n", + Base::Console().Log("PROBLEM - DPG::updateViews - non DPGI entry in Views! %s\n", getNameInDocument()); throw Base::TypeError("Error: projection in DPG list is not a DPGI!"); } diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp index c88be8e089..c0bfbe6c30 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp @@ -325,7 +325,7 @@ double DrawProjGroupItem::getScale(void) const double result = 1.0; auto pgroup = getPGroup(); if (pgroup != nullptr) { - result = pgroup->Scale.getValue(); + result = pgroup->getScale(); if (!(result > 0.0)) { Base::Console().Log("DPGI - %s - bad scale found (%.3f) using 1.0\n",getNameInDocument(),Scale.getValue()); result = 1.0; //kludgy protective fix. autoscale sometimes serves up 0.0! diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 08bc499512..0ad06292b1 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -32,6 +32,7 @@ #include +#include #include #include #include @@ -87,6 +88,8 @@ DrawView::DrawView(void): Scale.setConstraints(&scaleRange); ADD_PROPERTY_TYPE(Caption, (""), group, App::Prop_Output, "Short text about the view"); + + setScaleAttribute(); } DrawView::~DrawView() @@ -148,7 +151,6 @@ void DrawView::onChanged(const App::Property* prop) if (page != nullptr) { if(std::abs(page->Scale.getValue() - getScale()) > FLT_EPSILON) { Scale.setValue(page->Scale.getValue()); - Scale.purgeTouched(); } } } else if ( ScaleType.isValue("Custom") ) { @@ -160,7 +162,6 @@ void DrawView::onChanged(const App::Property* prop) double newScale = autoScale(page->getPageWidth(),page->getPageHeight()); if(std::abs(newScale - getScale()) > FLT_EPSILON) { //stops onChanged/execute loop Scale.setValue(newScale); - Scale.purgeTouched(); } } } @@ -237,6 +238,7 @@ QRectF DrawView::getRect() const void DrawView::onDocumentRestored() { handleXYLock(); + setScaleAttribute(); DrawView::execute(); } /** @@ -409,10 +411,15 @@ void DrawView::setPosition(double x, double y, bool force) } } -//TODO: getScale is no longer needed and could revert to Scale.getValue double DrawView::getScale(void) const { auto result = Scale.getValue(); + if (ScaleType.isValue("Page")) { + auto page = findParentPage(); + if (page) { + result = page->Scale.getValue(); + } + } if (!(result > 0.0)) { result = 1.0; Base::Console().Log("DrawView - %s - bad scale found (%.3f) using 1.0\n",getNameInDocument(),Scale.getValue()); @@ -538,6 +545,16 @@ bool DrawView::keepUpdated(void) return result; } +void DrawView::setScaleAttribute() +{ + if (ScaleType.isValue("Page") || + ScaleType.isValue("Automatic")) { + Scale.setStatus(App::Property::ReadOnly,true); + } else { + Scale.setStatus(App::Property::ReadOnly, false); + } +} + int DrawView::prefScaleType(void) { Base::Reference hGrp = App::GetApplication().GetUserParameter() diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index 629bd7e4a9..ba0a2e903a 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -105,6 +105,7 @@ public: virtual bool showLock(void) const; std::vector getLeaders(void) const; + void setScaleAttribute(); protected: virtual void onChanged(const App::Property* prop) override;