From fc0ce9e4fa8449ef975cfd1e8421c8822b9dab60 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 24 Jul 2023 20:01:42 -0400 Subject: [PATCH] [TD]reduce number of tiles for svg hatching - reduce the size of the overlay area from 200% to an adjustable size with a default of 125%. --- src/Mod/TechDraw/App/Preferences.cpp | 16 +++++++++++++ src/Mod/TechDraw/App/Preferences.h | 2 ++ src/Mod/TechDraw/Gui/QGIFace.cpp | 35 ++++++++++++++-------------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/Mod/TechDraw/App/Preferences.cpp b/src/Mod/TechDraw/App/Preferences.cpp index 7278ee04db..a1792c53c5 100644 --- a/src/Mod/TechDraw/App/Preferences.cpp +++ b/src/Mod/TechDraw/App/Preferences.cpp @@ -303,6 +303,7 @@ double Preferences::GapASME() return factor; } +//! current setting for reporting progress of HLR/face finding bool Preferences::reportProgress() { return getPreferenceGroup("General")->GetBool("ReportProgress", false); @@ -318,11 +319,13 @@ void Preferences::lightOnDark(bool state) getPreferenceGroup("Colors")->SetBool("LightOnDark", state); } +//! current setting (on/off) for monochrome display bool Preferences::monochrome() { return getPreferenceGroup("Colors")->GetBool("Monochrome", false); } +//! set monochrome display on/off void Preferences::monochrome(bool state) { Base::Console().Message("Pref::useLightText - set to %d\n", state); @@ -336,6 +339,8 @@ App::Color Preferences::lightTextColor() return result; } +//! attempt to lighten the give color +// not currently used App::Color Preferences::lightenColor(App::Color orig) { // get component colours on [0, 255] @@ -366,6 +371,7 @@ App::Color Preferences::lightenColor(App::Color orig) return App::Color(redF, greenF, blueF, orig.a); } +//! color to use for monochrome display App::Color Preferences::getAccessibleColor(App::Color orig) { if (Preferences::lightOnDark() && Preferences::monochrome()) { @@ -377,12 +383,22 @@ App::Color Preferences::getAccessibleColor(App::Color orig) return orig; } +//! automatic correction of dimension references on/off bool Preferences::autoCorrectDimRefs() { return getPreferenceGroup("Dimensions")->GetBool("AutoCorrectRefs", true); } +//! number of times to clean the output edges from HLR int Preferences::scrubCount() { return getPreferenceGroup("General")->GetInt("ScrubCount", 0); } + +//! Returns the factor for the overlap of svg tiles when hatching faces +double Preferences::svgHatchFactor() +{ + double factor = getPreferenceGroup("Decorations")->GetFloat("SvgOverlapFactor", 1.25); + return factor; +} + diff --git a/src/Mod/TechDraw/App/Preferences.h b/src/Mod/TechDraw/App/Preferences.h index e4757e9348..0467599b6b 100644 --- a/src/Mod/TechDraw/App/Preferences.h +++ b/src/Mod/TechDraw/App/Preferences.h @@ -102,6 +102,8 @@ public: static bool autoCorrectDimRefs(); static int scrubCount(); + + static double svgHatchFactor(); }; }//end namespace TechDraw diff --git a/src/Mod/TechDraw/Gui/QGIFace.cpp b/src/Mod/TechDraw/Gui/QGIFace.cpp index bc04f0a38c..b09af8cf34 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.cpp +++ b/src/Mod/TechDraw/Gui/QGIFace.cpp @@ -102,7 +102,7 @@ QGIFace::QGIFace(int index) : QGIFace::~QGIFace() { - //nothing to do. every item is a child of QGIFace & will get removed/deleted when QGIF is deleted + delete m_sharedRender; } /// redraw this face @@ -527,16 +527,16 @@ void QGIFace::buildSvgHatch() // Base::Console().Message("QGIF::buildSvgHatch() - offset: %s\n", DrawUtil::formatVector(getHatchOffset()).c_str()); double wTile = SVGSIZEW * m_fillScale; double hTile = SVGSIZEH * m_fillScale; - double w = m_outline.boundingRect().width(); - double h = m_outline.boundingRect().height(); - //make the hatch tiled area big enough to handle rotations - double hatchOverlaySize = 2.0 * std::max(w, h); + double faceWidth = m_outline.boundingRect().width(); + double faceHeight = m_outline.boundingRect().height(); + double faceOverlaySize = Preferences::svgHatchFactor() * std::max(faceWidth, faceHeight); QPointF faceCenter = m_outline.boundingRect().center(); - double nw = ceil(hatchOverlaySize / wTile); - double nh = ceil(hatchOverlaySize / hTile); - w = nw * wTile; - h = nh * hTile; - m_svgHatchArea->setRect(0., 0., w,-h); + double tilesWide = ceil(faceOverlaySize / wTile); + double tilesHigh = ceil(faceOverlaySize / hTile); + + double overlayWidth = tilesWide * wTile; + double overlayHeight = tilesHigh * hTile; + m_svgHatchArea->setRect(0., 0., overlayWidth,-overlayHeight); m_svgHatchArea->centerAt(faceCenter); QByteArray before, after; before = QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT).toUtf8(); @@ -547,17 +547,17 @@ void QGIFace::buildSvgHatch() return; } long int tileCount = 0; - for (int iw = 0; iw < int(nw); iw++) { - for (int ih = 0; ih < int(nh); ih++) { + for (int iw = 0; iw < int(tilesWide); iw++) { + for (int ih = 0; ih < int(tilesHigh); ih++) { QGCustomSvg* tile = new QGCustomSvg(); tile->setScale(m_fillScale); tile->setSharedRenderer(m_sharedRender); tile->setParentItem(m_svgHatchArea); tile->setPos(iw*wTile + getHatchOffset().x, - -h + ih*hTile + getHatchOffset().y); + -overlayWidth + ih*hTile + getHatchOffset().y); tileCount++; if (tileCount > m_maxTile) { - Base::Console().Warning("SVG tile count exceeded: %ld\n", tileCount); + Base::Console().Warning("SVG tile count exceeded: %ld. Change hatch scale or raise limit.\n", tileCount); break; } } @@ -585,7 +585,7 @@ void QGIFace::buildPixHatch() double faceHeight = m_outline.boundingRect().height(); QRectF faceRect = m_outline.boundingRect(); QPointF faceCenter = faceRect.center(); - double hatchOverlaySize = 2.0 * std::max(faceWidth, faceHeight); + double hatchOverlaySize = Preferences::svgHatchFactor() * std::max(faceWidth, faceHeight); double numberWide = ceil(hatchOverlaySize / wTile); double numberHigh = ceil(hatchOverlaySize / hTile); double overlayWidth = numberWide * wTile; @@ -618,7 +618,7 @@ void QGIFace::buildPixHatch() pm = QPixmap::fromImage(imageIn); pm = pm.scaled(wTile, hTile); if (pm.isNull()) { - Base::Console().Error("QGIF::buildPixHatch - pm is null\n"); + Base::Console().Error("QGIF::buildPixHatch - pixmap is null\n"); return; } @@ -626,7 +626,6 @@ void QGIFace::buildPixHatch() QImage tileField(overlayWidth, overlayHeight, QImage::Format_ARGB32); QPointF fieldCenter(overlayWidth / 2.0, overlayHeight / 2.0); - //do we have to rotate the field before we clip it?? tileField.fill(Qt::transparent); QPainter painter2(&tileField); QPainter::RenderHints hints = painter2.renderHints(); @@ -646,7 +645,7 @@ void QGIFace::buildPixHatch() QRectF(0, 0, wTile, hTile)); //source rect tileCount++; if (tileCount > m_maxTile) { - Base::Console().Warning("Pixmap tile count exceeded: %ld\n", tileCount); + Base::Console().Warning("Pixmap tile count exceeded: %ld. Change hatch scale or raise limit.\n", tileCount); break; } }