From 9f29693df3378ce72d06332ad3efbe1509d5098e Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 8 Aug 2018 21:00:31 -0400 Subject: [PATCH] Fix Dimension update on DPG Scale Change --- src/Mod/TechDraw/App/DrawProjGroup.cpp | 66 ++++++++++------------ src/Mod/TechDraw/App/DrawProjGroupItem.cpp | 19 ++++--- src/Mod/TechDraw/App/DrawView.cpp | 3 +- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index c57917eed4..dee3798ccc 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -113,6 +113,26 @@ void DrawProjGroup::onChanged(const App::Property* prop) //Source has been changed to null! Why? What to do? } } + if (prop == &Scale) { + updateChildren(); + } + + if (prop == &ScaleType) { + double newScale = getScale(); + if (ScaleType.isValue("Automatic")) { + //Recalculate scale if Group is too big or too small! + newScale = calculateAutomaticScale(); + if(std::abs(getScale() - newScale) > FLT_EPSILON) { + Scale.setValue(newScale); + } + } else if (ScaleType.isValue("Page")) { + newScale = page->Scale.getValue(); + if(std::abs(getScale() - newScale) > FLT_EPSILON) { + Scale.setValue(newScale); + } + } + } + } if (isRestoring() && (prop == &CubeDirs)) { m_cube->setAllDirs(CubeDirs.getValues()); //override defaults from saved value if valid @@ -158,34 +178,8 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void) return DrawViewCollection::execute(); } - double newScale = getScale(); - if (ScaleType.isValue("Automatic")) { - //Recalculate scale if Group is too big or too small! - if (!checkFit(page)) { - newScale = calculateAutomaticScale(); - if(std::abs(getScale() - newScale) > FLT_EPSILON) { - Scale.setValue(newScale); - updateChildren(); - } - } - } else if (ScaleType.isValue("Page")) { //don't really need this any more. - newScale = page->Scale.getValue(); - if(std::abs(getScale() - newScale) > FLT_EPSILON) { - Scale.setValue(newScale); - updateChildren(); - } - } else if (ScaleType.isValue("Custom")) { - //don't have to do anything special - updateChildren(); - } - for (auto& item: getViewsAsDPGI()) { item->autoPosition(); - item->purgeTouched(); - } - - if (page != nullptr) { - page->requestPaint(); } return DrawViewCollection::execute(); @@ -200,7 +194,10 @@ short DrawProjGroup::mustExecute() const Scale.isTouched() || ScaleType.isTouched() || ProjectionType.isTouched() || - Anchor.isTouched(); + Anchor.isTouched() || + AutoDistribute.isTouched() || + spacingX.isTouched() || + spacingY.isTouched(); } if (result) return result; return TechDraw::DrawViewCollection::mustExecute(); @@ -399,11 +396,6 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType) FeatName.c_str() ) ); view = static_cast( docObj ); view->Source.setValues( Source.getValues() ); - if (ScaleType.isValue("Automatic")) { - view->ScaleType.setValue("Custom"); - } else { - view->ScaleType.setValue( ScaleType.getValue() ); - } view->Scale.setValue( getScale() ); view->Type.setValue( viewProjType ); view->Label.setValue( viewProjType ); @@ -536,6 +528,11 @@ Base::Vector3d DrawProjGroup::getXYPosition(const char *viewTypeCStr) position[3].x = -bigCol - xSpacing; position[3].y = 0.0; } + if (viewPtrs[4] && //Front + bboxes[4].IsValid()) { + position[4].x = 0.0; + position[4].y = 0.0; + } if (viewPtrs[5] && // R/L bboxes[5].IsValid() && bboxes[4].IsValid()) { @@ -714,15 +711,14 @@ void DrawProjGroup::makeViewBbs(DrawProjGroupItem *viewPtrs[10], } /*! - * tell children DPGIs that parent DPG has changed ?Scale? + * tell children DPGIs that parent DPG has changed Scale */ void DrawProjGroup::updateChildren(void) { for( const auto it : Views.getValues() ) { auto view( dynamic_cast(it) ); if( view ) { - view->recomputeFeature(); - view->purgeTouched(); + view->Scale.setValue(Scale.getValue()); } } } diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp index 544d62c013..2cd635e5a6 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp @@ -65,8 +65,9 @@ DrawProjGroupItem::DrawProjGroupItem(void) //projection group controls these Direction.setStatus(App::Property::ReadOnly,true); RotationVector.setStatus(App::Property::ReadOnly,true); - Scale.setStatus(App::Property::Hidden,true); - ScaleType.setStatus(App::Property::Hidden,true); + Scale.setStatus(App::Property::ReadOnly,true); + ScaleType.setValue("Custom"); + ScaleType.setStatus(App::Property::ReadOnly,true); } short DrawProjGroupItem::mustExecute() const @@ -75,7 +76,8 @@ short DrawProjGroupItem::mustExecute() const if (!isRestoring()) { result = (Direction.isTouched() || RotationVector.isTouched() || - Source.isTouched() ); + Source.isTouched() || + Scale.isTouched()); } if (result) { @@ -109,16 +111,19 @@ void DrawProjGroupItem::autoPosition() { auto pgroup = getPGroup(); Base::Vector3d newPos; - if (isAnchor()) { - X.setValue(0.0); - Y.setValue(0.0); - } else if ((pgroup != nullptr) && +// if (isAnchor()) { +// X.setValue(0.0); +// Y.setValue(0.0); +// } else + if ((pgroup != nullptr) && (pgroup->AutoDistribute.getValue()) && (!LockPosition.getValue())) { newPos = pgroup->getXYPosition(Type.getValueAsString()); X.setValue(newPos.x); Y.setValue(newPos.y); } + requestPaint(); + purgeTouched(); } void DrawProjGroupItem::onDocumentRestored() diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 0bae89c18d..7a81652f63 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -110,7 +110,8 @@ void DrawView::checkScale(void) void DrawView::onChanged(const App::Property* prop) { if (!isRestoring()) { - if (this->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { + if ((this->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) || + (this->isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId()))) { //do nothing. DPGI/DPG handles itself } else if (prop == &ScaleType) { auto page = findParentPage();