From 70b5c241d1e5ebded8378073e05afbcb7ff636cd Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 27 Oct 2016 10:13:23 -0400 Subject: [PATCH] AutoScaling Fixes for non-DVP objects --- src/Mod/TechDraw/App/DrawProjGroup.cpp | 25 ++++++------------- src/Mod/TechDraw/App/DrawUtil.cpp | 25 +++++++++++++++++++ src/Mod/TechDraw/App/DrawUtil.h | 1 + src/Mod/TechDraw/App/DrawView.cpp | 11 +++++--- src/Mod/TechDraw/App/DrawViewPart.cpp | 10 +++++++- src/Mod/TechDraw/Gui/TaskProjGroup.ui | 3 +++ .../TechDraw/Gui/ViewProviderProjGroup.cpp | 2 -- 7 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index 61d2dc087..fb3e9c989 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -35,6 +35,7 @@ #include #include +#include "DrawUtil.h" #include "DrawPage.h" #include "DrawProjGroupItem.h" #include "DrawProjGroup.h" @@ -134,6 +135,9 @@ double DrawProjGroup::calculateAutomaticScale() const arrangeViewPointers(viewPtrs); double width, height; minimumBbViews(viewPtrs, width, height); //get 1:1 bbxs + double bbFudge = 1.2; + width *= bbFudge; + height *= bbFudge; // C++ Standard says casting bool to int gives 0 or 1 int numVertSpaces = (viewPtrs[0] || viewPtrs[3] || viewPtrs[7]) + @@ -151,24 +155,9 @@ double DrawProjGroup::calculateAutomaticScale() const double scale_x = availableX / width; double scale_y = availableY / height; - double fudgeFactor = 0.90; - float working_scale = fudgeFactor * std::min(scale_x, scale_y); - - //which gives the largest scale for which the min_space requirements can be met, but we want a 'sensible' scale, rather than 0.28457239... - //eg if working_scale = 0.115, then we want to use 0.1, similarly 7.65 -> 5, and 76.5 -> 50 - - float exponent = std::floor(std::log10(working_scale)); //if working_scale = a * 10^b, what is b? - working_scale *= std::pow(10, -exponent); //now find what 'a' is. - - float valid_scales[2][8] = {{1.0, 1.25, 2.0, 2.5, 3.75, 5.0, 7.5, 10.0}, //equate to 1:10, 1:8, 1:5, 1:4, 3:8, 1:2, 3:4, 1:1 - {1.0, 1.5 , 2.0, 3.0, 4.0 , 5.0, 8.0, 10.0}}; //equate to 1:1, 3:2, 2:1, 3:1, 4:1, 5:1, 8:1, 10:1 - - int i = 7; - while (valid_scales[(exponent >= 0)][i] > working_scale) //choose closest value smaller than 'a' from list. - i -= 1; //choosing top list if exponent -ve, bottom list for +ve exponent - - //now have the appropriate scale, reapply the *10^b - double result = valid_scales[(exponent >= 0)][i] * pow(10, exponent); + double scaleFudge = 0.80; + float working_scale = scaleFudge * std::min(scale_x, scale_y); + double result = DrawUtil::sensibleScale(working_scale); return result; } diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 25a44dd47..ef887d0e3 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -137,6 +137,31 @@ bool DrawUtil::isZeroEdge(TopoDS_Edge e) return result; } +//based on Function provided by Joe Dowsett, 2014 +double DrawUtil::sensibleScale(double working_scale) +{ + double result = 1.0; + //which gives the largest scale for which the min_space requirements can be met, but we want a 'sensible' scale, rather than 0.28457239... + //eg if working_scale = 0.115, then we want to use 0.1, similarly 7.65 -> 5, and 76.5 -> 50 + + float exponent = std::floor(std::log10(working_scale)); //if working_scale = a * 10^b, what is b? + working_scale *= std::pow(10, -exponent); //now find what 'a' is. + + int choices = 10; + float valid_scales[2][choices] = + {{1.0, 1.25, 2.0, 2.5, 3.75, 5.0, 7.5, 10.0, 50.0, 100.0}, //equate to 1:10, 1:8, 1:5, 1:4, 3:8, 1:2, 3:4, 1:1 + // .1 .125 .375 .75 + {1.0, 1.5 , 2.0, 3.0, 4.0 , 5.0, 8.0, 10.0, 50.0, 100.0}}; //equate to 1:1, 3:2, 2:1, 3:1, 4:1, 5:1, 8:1, 10:1 + // 1.5:1 + int i = choices - 1; + while (valid_scales[(exponent >= 0)][i] > working_scale) //choose closest value smaller than 'a' from list. + i -= 1; //choosing top list if exponent -ve, bottom list for +ve exponent + + //now have the appropriate scale, reapply the *10^b + result = valid_scales[(exponent >= 0)][i] * pow(10, exponent); + return result; +} + //============================ // various debugging routines. void DrawUtil::dumpVertexes(const char* text, const TopoDS_Shape& s) diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 42484925e..83127edc1 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -42,6 +42,7 @@ class TechDrawExport DrawUtil { static std::string makeGeomName(std::string geomType, int index); static bool isSamePoint(TopoDS_Vertex v1, TopoDS_Vertex v2); static bool isZeroEdge(TopoDS_Edge e); + static double sensibleScale(double working_scale); //debugging routines static void dumpVertexes(const char* text, const TopoDS_Shape& s); static void dumpEdge(char* label, int i, TopoDS_Edge e); diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 250713cde..af06ae273 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -42,6 +42,7 @@ #include "DrawViewClip.h" #include "DrawProjGroup.h" #include "DrawProjGroupItem.h" +#include "DrawUtil.h" #include // generated from DrawViewPy.xml @@ -202,10 +203,14 @@ double DrawView::autoScale(double w, double h) const { double fudgeFactor = 0.90; QRectF viewBox = getRect(); - double xScale = w/viewBox.width(); - double yScale = h/viewBox.height(); - //find a standard scale that's close? 1:2, 1:10, 1:100...? + //have to unscale rect to determine new scale + double vbw = viewBox.width()/Scale.getValue(); + double vbh = viewBox.height()/Scale.getValue(); + double xScale = w/vbw; + double yScale = h/vbh; + //TODO: find a standard scale that's close? 1:2, 1:10, 1:100...? Logic in TaskProjGroup double newScale = fudgeFactor * std::min(xScale,yScale); + newScale = DrawUtil::sensibleScale(newScale); return newScale; } diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 6e1deede8..4a4ab5f51 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -736,7 +736,15 @@ double DrawViewPart::getBoxY(void) const QRectF DrawViewPart::getRect() const { - QRectF result(0.0,0.0,getBoxX(),getBoxY()); //this is from GO and is already scaled + double x = getBoxX(); + double y = getBoxY(); + QRectF result; + if (std::isinf(x) || std::isinf(y)) { + //geometry isn't created yet. return an arbitrary rect. + result = QRectF(0.0,0.0,100.0,100.0); + } else { + result = QRectF(0.0,0.0,getBoxX(),getBoxY()); //this is from GO and is already scaled + } return result; } diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.ui b/src/Mod/TechDraw/Gui/TaskProjGroup.ui index 9de1d99cb..c6dc2816a 100644 --- a/src/Mod/TechDraw/Gui/TaskProjGroup.ui +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.ui @@ -153,6 +153,9 @@ 1 + + 999 + 1 diff --git a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp index 7df742f97..2b20c452d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp @@ -29,7 +29,6 @@ # include #endif -/// Here the FreeCAD includes sorted by Base,App,Gui...... #include #include @@ -110,7 +109,6 @@ void ViewProviderProjGroup::updateData(const App::Property* prop) void ViewProviderProjGroup::onChanged(const App::Property *prop) { - Base::Console().Message("TRACE - VPPG::onChanged(%s) \n",prop->getName()); if (prop == &(getViewObject()->Scale)) { if (getViewObject()->ScaleType.isValue("Automatic")) { getMDIViewPage()->redraw1View(getViewObject());