Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Hatch Export to SVG #224

Merged
merged 2 commits into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Mod/TechDraw/Gui/MDIViewPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,15 @@ void MDIViewPage::print(QPrinter* printer)
static_cast<void> (blockConnection(true)); // avoid to be notified by itself
Gui::Selection().clearSelection();

m_view->toggleEdit(false);
m_view->toggleMarkers(false);
m_view->scene()->update();

Gui::Selection().clearSelection();

m_view->scene()->render(&p, rect);

// Reset
m_view->toggleEdit(true);
m_view->toggleMarkers(true);
}


Expand Down Expand Up @@ -812,7 +812,7 @@ QPrinter::PageSize MDIViewPage::getPageSize(int w, int h) const
void MDIViewPage::setFrameState(bool state)
{
m_frameState = state;
m_view->toggleEdit(state);
m_view->toggleMarkers(state);
m_view->scene()->update();
}

Expand Down
11 changes: 11 additions & 0 deletions src/Mod/TechDraw/Gui/QGIFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ void QGIFace::setHatchColor(std::string c)
m_svgCol = c;
}

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

QRectF QGIFace::boundingRect() const
{
return shape().controlPointRect();
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGIFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class QGIFace : public QGIPrimPath
void setPath(const QPainterPath & path);
void buildHatch(void);
void setHatchColor(std::string c);
void toggleSvg(bool b);

protected:
bool load(QByteArray *svgBytes);
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGITemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TechDrawGuiExport QGITemplate : public QObject, public QGraphicsItemGroup
inline qreal getY() { return y() * -1; }

virtual void updateView(bool update = false);
std::vector<TemplateTextField *> getTestFields(void) { return textFields; };

virtual void draw() = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/QGIView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ QGIView::QGIView()
m_colCurrent = getNormalColor();
m_pen.setColor(m_colCurrent);

//Border/Label styling
m_font.setPointSize(5.0); //scene units (mm), not points

m_decorPen.setStyle(Qt::DashLine);
m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen"

Expand Down
34 changes: 18 additions & 16 deletions src/Mod/TechDraw/Gui/QGIViewPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ QVariant QGIViewPart::itemChange(GraphicsItemChange change, const QVariant &valu
return QGIView::itemChange(change, value);
}

//obs?
void QGIViewPart::tidy()
{
//Delete any leftover items
Expand Down Expand Up @@ -249,21 +250,6 @@ void QGIViewPart::updateView(bool update)
viewPart->ShowHiddenLines.isTouched() ||
viewPart->ShowSmoothLines.isTouched() ||
viewPart->ShowSeamLines.isTouched() ) {
// Remove all existing graphical representations (QGIxxxx) otherwise BRect only grows, never shrinks?
// is this where selection messes up?
prepareGeometryChange();
QList<QGraphicsItem*> items = childItems();
for(QList<QGraphicsItem*>::iterator it = items.begin(); it != items.end(); ++it) {
if (dynamic_cast<QGIEdge *> (*it) ||
dynamic_cast<QGIFace *>(*it) ||
dynamic_cast<QGIVertex *>(*it)) {
removeFromGroup(*it);
scene()->removeItem(*it);

// We store these and delete till later to prevent rendering crash ISSUE
deleteItems.append(*it);
}
}
draw();
} else if (update ||
viewPart->LineWidth.isTouched() ||
Expand Down Expand Up @@ -302,6 +288,7 @@ void QGIViewPart::drawViewPart()
float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor;

prepareGeometryChange();
removePrimitives(); //clean the slate

#if MOD_TECHDRAW_HANDLE_FACES
// Draw Faces
Expand Down Expand Up @@ -344,7 +331,7 @@ void QGIViewPart::drawViewPart()
if (showEdge) {
item = new QGIEdge(i);
addToGroup(item); //item is at scene(0,0), not group(0,0)
item->setPos(0.0,0.0);
item->setPos(0.0,0.0); //now at group(0,0)
item->setPath(drawPainterPath(*itEdge));
item->setStrokeWidth(lineWidth);
item->setZValue(ZVALUE::EDGE);
Expand Down Expand Up @@ -405,6 +392,21 @@ QGIFace* QGIViewPart::drawFace(TechDrawGeometry::Face* f, int idx)
return gFace;
}

//! Remove all existing QGIPrimPath items(Vertex,Edge,Face)
void QGIViewPart::removePrimitives()
{
QList<QGraphicsItem*> children = childItems();
for (auto& c:children) {
QGIPrimPath* prim = dynamic_cast<QGIPrimPath*>(c);
if (prim) {
removeFromGroup(prim);
scene()->removeItem(prim);
// deleteItems.append(prim); //pretty sure we could just delete here since not in scene anymore
delete prim;
}
}
}

// As called by arc of ellipse case:
// pathArc(path, geom->major, geom->minor, geom->angle, geom->largeArc, geom->cw,
// geom->endPnt.fX, geom->endPnt.fY,
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGIViewPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TechDrawGuiExport QGIViewPart : public QGIView

TechDraw::DrawHatch* faceIsHatched(int i,std::vector<TechDraw::DrawHatch*> hatchObjs) const;
void dumpPath(const char* text,QPainterPath path);
void removePrimitives(void);

private:
QList<QGraphicsItem*> deleteItems;
Expand Down
79 changes: 44 additions & 35 deletions src/Mod/TechDraw/Gui/QGVPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# include <QFileInfo>
# include <QFileDialog>
# include <QGLWidget>
//# include <QGraphicsScene>
# include <QGraphicsEffect>
# include <QMouseEvent>
# include <QPainter>
Expand Down Expand Up @@ -61,7 +60,9 @@


#include "QGIDrawingTemplate.h"
#include "QGITemplate.h"
#include "QGISVGTemplate.h"
#include "TemplateTextField.h"
#include "QGIViewCollection.h"
#include "QGIViewDimension.h"
#include "QGIProjGroup.h"
Expand All @@ -71,6 +72,7 @@
#include "QGIViewSymbol.h"
#include "QGIViewClip.h"
#include "QGIViewSpreadsheet.h"
#include "QGIFace.h"

#include "ZVALUE.h"
#include "ViewProviderPage.h"
Expand Down Expand Up @@ -101,9 +103,9 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene& s, QWidget *parent)
setCursor(QCursor(Qt::ArrowCursor));
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

m_backgroundItem = new QGraphicsRectItem();
m_backgroundItem->setCacheMode(QGraphicsItem::NoCache);
m_backgroundItem->setZValue(ZVALUE::BACKGROUND);
//m_backgroundItem = new QGraphicsRectItem();
//m_backgroundItem->setCacheMode(QGraphicsItem::NoCache);
//m_backgroundItem->setZValue(ZVALUE::BACKGROUND);
// scene()->addItem(m_backgroundItem); // TODO IF SEGFAULTS WITH DRAW ENABLE THIS (REDRAWS ARE SLOWER :s)

bkgBrush = new QBrush(QColor::fromRgb(70,70,70));
Expand All @@ -113,7 +115,7 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene& s, QWidget *parent)
QGVPage::~QGVPage()
{
delete bkgBrush;
delete m_backgroundItem;
//delete m_backgroundItem;
}

void QGVPage::drawBackground(QPainter *p, const QRectF &)
Expand Down Expand Up @@ -465,10 +467,10 @@ void QGVPage::setHighQualityAntialiasing(bool highQualityAntialiasing)

void QGVPage::setViewBackground(bool enable)
{
if (!m_backgroundItem)
return;
// if (!m_backgroundItem)
// return;

m_backgroundItem->setVisible(enable);
// m_backgroundItem->setVisible(enable);
}

void QGVPage::setViewOutline(bool enable)
Expand All @@ -479,46 +481,49 @@ void QGVPage::setViewOutline(bool enable)
m_outlineItem->setVisible(enable);
}

void QGVPage::toggleEdit(bool enable)
void QGVPage::toggleMarkers(bool enable)
{
// TODO: needs fiddling to handle items that don't inherit QGIViewPart: Annotation, Symbol, Templates, Edges, Faces, Vertices,...
QList<QGraphicsItem*> list = scene()->items();

for (QList<QGraphicsItem*>::iterator it = list.begin(); it != list.end(); ++it) {
QGIView *itemView = dynamic_cast<QGIView *>(*it);
if(itemView) {
QGIViewPart *viewPart = dynamic_cast<QGIViewPart *>(*it);
itemView->setSelected(false);
itemView->toggleBorder(enable);
QGIViewPart *viewPart = dynamic_cast<QGIViewPart *>(*it);
if(viewPart) {
viewPart->toggleCache(enable);
viewPart->toggleCosmeticLines(enable);
viewPart->toggleVertices(enable);
viewPart->toggleBorder(enable);
setViewBackground(enable);
} else {
itemView->toggleBorder(enable);
}
//itemView->updateView(true);
}

int textItemType = QGraphicsItem::UserType + 160;
QGraphicsItem*item = dynamic_cast<QGraphicsItem*>(*it);
if(item) {
//item->setCacheMode((enable) ? QGraphicsItem::DeviceCoordinateCache : QGraphicsItem::NoCache);
item->setCacheMode((enable) ? QGraphicsItem::NoCache : QGraphicsItem::NoCache);
item->update();
if (item->type() == textItemType) { //TODO: move this into SVGTemplate or TemplateTextField
QGISVGTemplate* itemTemplate = dynamic_cast<QGISVGTemplate*> (*it);
if (itemTemplate) {
std::vector<TemplateTextField *> textFields = itemTemplate->getTestFields();
for (auto& t:textFields) {
if (enable) {
item->show();
t->show();
} else {
item->hide();
t->hide();
}
}
}
}
}

void QGVPage::toggleHatch(bool 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) {
QGIFace* f = dynamic_cast<QGIFace*>(c);
f->toggleSvg(enable);
}
}
}
}
scene()->update();
update();
viewport()->repaint();
}

void QGVPage::saveSvg(QString filename)
Expand All @@ -545,7 +550,7 @@ void QGVPage::saveSvg(QString filename)
// postprocess generated file to mult all font-size attrib by 2.835 to get pts?
// duplicate all textItems and only show the appropriate one for screen/print vs export?

// TODO: Was svgGen.setResolution(25.4000508); // mm/inch?? docs say this is DPI
// TODO: Was svgGen.setResolution(25.4000508); // mm/inch?? docs say this is DPI //really "user space units/inch"?
svgGen.setResolution(25); // mm/inch?? docs say this is DPI

//svgGen.setResolution(600); // resulting page is ~12.5x9mm
Expand All @@ -555,8 +560,10 @@ void QGVPage::saveSvg(QString filename)

Gui::Selection().clearSelection();

toggleEdit(false); //fiddle cache, cosmetic lines, vertices, etc
toggleMarkers(false); //fiddle cache, vertices, frames, etc
toggleHatch(false);
scene()->update();
viewport()->repaint();

Gui::Selection().clearSelection();
QPainter p;
Expand All @@ -565,8 +572,10 @@ void QGVPage::saveSvg(QString filename)
scene()->render(&p);
p.end();

toggleEdit(true);
toggleMarkers(true);
toggleHatch(true);
scene()->update();
viewport()->repaint();
}


Expand Down
3 changes: 2 additions & 1 deletion src/Mod/TechDraw/Gui/QGVPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class TechDrawGuiExport QGVPage : public QGraphicsView

TechDraw::DrawPage * getDrawPage();

void toggleEdit(bool enable);
void toggleMarkers(bool enable);
void toggleHatch(bool enable);

/// Renders the page to SVG with filename.
void saveSvg(QString filename);
Expand Down