Skip to content

Commit

Permalink
[TD]fix Svg hatch on export
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Dec 17, 2019
1 parent b33e168 commit 57bfc2e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 37 deletions.
23 changes: 11 additions & 12 deletions src/Mod/TechDraw/Gui/QGIFace.cpp
Expand Up @@ -68,7 +68,8 @@ using namespace TechDrawGui;
using namespace TechDraw;

QGIFace::QGIFace(int index) :
projIndex(index)
projIndex(index),
m_hideSvgTiles(false)
{
m_segCount = 0;
// setFillMode(NoFill);
Expand Down Expand Up @@ -139,13 +140,16 @@ void QGIFace::draw()
m_fillStyleCurrent = m_styleNormal;
loadSvgHatch(m_fileSpec);
buildSvgHatch();
toggleSvg(true);
if (m_hideSvgTiles) {
m_rect->hide();
} else {
m_rect->show();
}
} else if ((ext.toUpper() == QString::fromUtf8("JPG")) ||
(ext.toUpper() == QString::fromUtf8("PNG")) ||
(ext.toUpper() == QString::fromUtf8("JPEG")) ||
(ext.toUpper() == QString::fromUtf8("BMP")) ) {
setFillMode(BitmapFill);
toggleSvg(false);
m_fillStyleCurrent = Qt::TexturePattern;
m_texture = textureFromBitmap(m_fileSpec);
m_brush.setTexture(m_texture);
Expand Down Expand Up @@ -195,7 +199,7 @@ void QGIFace::setDrawEdges(bool b) {
void QGIFace::setHatchFile(std::string fileSpec)
{
m_fileSpec = fileSpec;
}
}

void QGIFace::loadSvgHatch(std::string fileSpec)
{
Expand Down Expand Up @@ -546,7 +550,7 @@ void QGIFace::buildSvgHatch()

void QGIFace::clearSvg()
{
toggleSvg(false);
hideSvg(true);
}

//this isn't used currently
Expand Down Expand Up @@ -578,14 +582,9 @@ void QGIFace::setHatchScale(double s)
}

//QtSvg does not handle clipping, so we must be able to turn the hatching on/off
void QGIFace::toggleSvg(bool b)
void QGIFace::hideSvg(bool b)
{
if (b) {
m_rect->show();
} else {
m_rect->hide();
}
update();
m_hideSvgTiles = b;
}

QPixmap QGIFace::textureFromBitmap(std::string fileSpec)
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/TechDraw/Gui/QGIFace.h
Expand Up @@ -90,7 +90,7 @@ class QGIFace : public QGIPrimPath
void setHatchFile(std::string fileSpec);
void loadSvgHatch(std::string fileSpec);
void buildSvgHatch(void);
void toggleSvg(bool b);
void hideSvg(bool b);
void clearSvg(void);

//PAT fill parms & methods
Expand Down Expand Up @@ -141,6 +141,8 @@ class QGIFace : public QGIPrimPath
long int m_maxSeg;
long int m_maxTile;

bool m_hideSvgTiles;


private:
QPixmap m_texture; //
Expand Down
30 changes: 19 additions & 11 deletions src/Mod/TechDraw/Gui/QGIViewPart.cpp
Expand Up @@ -90,7 +90,8 @@ using namespace TechDrawGui;

const float lineScaleFactor = Rez::guiX(1.); // temp fiddle for devel

QGIViewPart::QGIViewPart()
QGIViewPart::QGIViewPart() :
m_isExporting(false)
{
setCacheMode(QGraphicsItem::NoCache);
setHandlesChildEvents(false);
Expand Down Expand Up @@ -508,17 +509,24 @@ void QGIViewPart::drawViewPart()
}
} else if (fHatch) {
if (!fHatch->HatchPattern.isEmpty()) {
newFace->isHatched(true);
newFace->setFillMode(QGIFace::FromFile);
newFace->setHatchFile(fHatch->HatchPattern.getValue());
Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch);
ViewProviderHatch* hatchVp = dynamic_cast<ViewProviderHatch*>(gvp);
if (hatchVp != nullptr) {
double hatchScale = hatchVp->HatchScale.getValue();
if (hatchScale > 0.0) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
if (getExporting()) {
newFace->hideSvg(true);
newFace->isHatched(false);
newFace->setFillMode(QGIFace::PlainFill);
} else {
newFace->hideSvg(false);
newFace->isHatched(true);
newFace->setFillMode(QGIFace::FromFile);
newFace->setHatchFile(fHatch->HatchPattern.getValue());
Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch);
ViewProviderHatch* hatchVp = dynamic_cast<ViewProviderHatch*>(gvp);
if (hatchVp != nullptr) {
double hatchScale = hatchVp->HatchScale.getValue();
if (hatchScale > 0.0) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
}
newFace->setHatchColor(hatchVp->HatchColor.getValue());
}
newFace->setHatchColor(hatchVp->HatchColor.getValue());
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/TechDraw/Gui/QGIViewPart.h
Expand Up @@ -90,6 +90,8 @@ class TechDrawGuiExport QGIViewPart : public QGIView
bool large_arc_flag, bool sweep_flag,
double x, double y,
double curx, double cury);
void setExporting(bool b) { m_isExporting = b; }
bool getExporting(void) { return m_isExporting; }

protected:
QPainterPath drawPainterPath(TechDraw::BaseGeom *baseGeom) const;
Expand All @@ -109,6 +111,8 @@ class TechDrawGuiExport QGIViewPart : public QGIView
bool formatGeomFromCosmetic(std::string cTag, QGIEdge* item);
bool formatGeomFromCenterLine(std::string cTag, QGIEdge* item);

bool m_isExporting;

private:
QList<QGraphicsItem*> deleteItems;
};
Expand Down
19 changes: 7 additions & 12 deletions src/Mod/TechDraw/Gui/QGVPage.cpp
Expand Up @@ -743,8 +743,8 @@ void QGVPage::refreshViews(void)
QList<QGraphicsItem*> qgiv;
//find only QGIV's
for (auto q: list) {
QString tileFamily = QString::fromUtf8("QGIV");
if (tileFamily == q->data(0).toString()) {
QString viewFamily = QString::fromUtf8("QGIV");
if (viewFamily == q->data(0).toString()) {
qgiv.push_back(q);
}
}
Expand All @@ -756,19 +756,14 @@ void QGVPage::refreshViews(void)
}
}

void QGVPage::toggleHatch(bool enable)
void QGVPage::setExporting(bool enable)
{
// Base::Console().Message("QGVP::setExporting(%d)\n", enable);
QList<QGraphicsItem*> sceneItems = scene()->items();
for (auto& qgi:sceneItems) {
QGIViewPart* qgiPart = dynamic_cast<QGIViewPart *>(qgi);
if(qgiPart) {
QList<QGraphicsItem*> partChildren = qgiPart->childItems();
int faceItemType = QGraphicsItem::UserType + 104;
for (auto& c:partChildren) {
if (c->type() == faceItemType) {
static_cast<QGIFace*>(c)->toggleSvg(enable);
}
}
qgiPart->setExporting(enable);
}
}
}
Expand Down Expand Up @@ -810,7 +805,7 @@ void QGVPage::saveSvg(QString filename)
bool saveState = m_vpPage->getFrameState();
m_vpPage->setFrameState(false);
m_vpPage->setTemplateMarkers(false);
toggleHatch(false);
setExporting(true);

// Here we temporarily hide the page template, because Qt would otherwise convert the SVG template
// texts into series of paths, making the later document edits practically unfeasible.
Expand Down Expand Up @@ -839,7 +834,7 @@ void QGVPage::saveSvg(QString filename)

m_vpPage->setFrameState(saveState);
m_vpPage->setTemplateMarkers(saveState);
toggleHatch(true);
setExporting(false);
if (templateVisible) {
svgTemplate->show();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/QGVPage.h
Expand Up @@ -110,7 +110,7 @@ class TechDrawGuiExport QGVPage : public QGraphicsView

TechDraw::DrawPage * getDrawPage();

void toggleHatch(bool enable);
void setExporting(bool enable);
virtual void refreshViews(void);


Expand Down

0 comments on commit 57bfc2e

Please sign in to comment.