Skip to content

Commit

Permalink
[TD]Fix #4017 Crash on bad hatch scale
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Jul 19, 2019
1 parent 82dd7f0 commit 21efae3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/Mod/TechDraw/Gui/QGIFace.cpp
Expand Up @@ -517,6 +517,7 @@ void QGIFace::buildSvgHatch()
before.append(QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT));
after.append(QString::fromStdString(SVGCOLPREFIX + m_svgCol));
QByteArray colorXML = m_svgXML.replace(before,after);
long int tileCount = 0;
for (int iw = 0; iw < int(nw); iw++) {
for (int ih = 0; ih < int(nh); ih++) {
QGCustomSvg* tile = new QGCustomSvg();
Expand All @@ -525,6 +526,14 @@ void QGIFace::buildSvgHatch()
tile->setParentItem(m_rect);
tile->setPos(iw*wTile,-h + ih*hTile);
}
tileCount++;
if (tileCount > m_maxTile) {
Base::Console().Warning("SVG tile count exceeded: %ld\n",tileCount);
break;
}
}
if (tileCount > m_maxTile) {
break;
}
}
}
Expand Down Expand Up @@ -611,6 +620,10 @@ void QGIFace::getParameters(void)
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/PAT");

m_maxSeg = hGrp->GetInt("MaxSeg",10000l);

hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
m_maxTile = hGrp->GetInt("MaxSVGTile",10000l);
}


Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGIFace.h
Expand Up @@ -147,6 +147,7 @@ class QGIFace : public QGIPrimPath
std::vector<DashSpec> m_dashSpecs;
long int m_segCount;
long int m_maxSeg;
long int m_maxTile;


private:
Expand Down
10 changes: 8 additions & 2 deletions src/Mod/TechDraw/Gui/QGIViewPart.cpp
Expand Up @@ -386,7 +386,10 @@ void QGIViewPart::drawViewPart()
}
newFace->isHatched(true);
newFace->setFillMode(QGIFace::GeomHatchFill);
newFace->setHatchScale(fGeom->ScalePattern.getValue());
double hatchScale = fGeom->ScalePattern.getValue();
if (hatchScale > 0.0) {
newFace->setHatchScale(fGeom->ScalePattern.getValue());
}
newFace->setHatchFile(fGeom->FilePattern.getValue());
Gui::ViewProvider* gvp = QGIView::getViewProvider(fGeom);
ViewProviderGeomHatch* geomVp = dynamic_cast<ViewProviderGeomHatch*>(gvp);
Expand All @@ -404,7 +407,10 @@ void QGIViewPart::drawViewPart()
Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch);
ViewProviderHatch* hatchVp = dynamic_cast<ViewProviderHatch*>(gvp);
if (hatchVp != nullptr) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
double hatchScale = hatchVp->HatchScale.getValue();
if (hatchScale > 0.0) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
}
newFace->setHatchColor(hatchVp->HatchColor.getValue());
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/Mod/TechDraw/Gui/ViewProviderHatch.cpp
Expand Up @@ -47,8 +47,13 @@

using namespace TechDrawGui;

App::PropertyFloatConstraint::Constraints ViewProviderHatch::scaleRange = {Precision::Confusion(),
std::numeric_limits<double>::max(),
//scaleRange = {lowerLimit, upperLimit, stepSize}
//original range is far too broad for drawing. causes massive loop counts.
//App::PropertyFloatConstraint::Constraints ViewProviderHatch::scaleRange = {Precision::Confusion(),
// std::numeric_limits<double>::max(),
// pow(10,- Base::UnitsApi::getDecimals())};
App::PropertyFloatConstraint::Constraints ViewProviderHatch::scaleRange = {pow(10,- Base::UnitsApi::getDecimals()),
1000.0,
pow(10,- Base::UnitsApi::getDecimals())};


Expand Down Expand Up @@ -99,9 +104,11 @@ void ViewProviderHatch::onChanged(const App::Property* prop)
{
if ((prop == &HatchScale) ||
(prop == &HatchColor)) {
TechDraw::DrawViewPart* parent = getViewObject()->getSourceView();
if (parent) {
parent->requestPaint();
if (HatchScale.getValue() > 0.0) {
TechDraw::DrawViewPart* parent = getViewObject()->getSourceView();
if (parent) {
parent->requestPaint();
}
}
}
}
Expand Down

0 comments on commit 21efae3

Please sign in to comment.