diff --git a/src/Mod/TechDraw/App/EdgeWalker.h b/src/Mod/TechDraw/App/EdgeWalker.h index 4dcc5b502c..1500fc0740 100644 --- a/src/Mod/TechDraw/App/EdgeWalker.h +++ b/src/Mod/TechDraw/App/EdgeWalker.h @@ -28,6 +28,8 @@ #ifndef TECHDRAW_EDGEWALKER_H #define TECHDRAW_EDGEWALKER_H +#include + #include #include #include @@ -72,7 +74,7 @@ typedef > planar_embedding_t; -class WalkerEdge +class TechDrawExport WalkerEdge { public: static bool weCompare(WalkerEdge i, WalkerEdge j); @@ -85,7 +87,7 @@ public: int idx; }; -class ewWire +class TechDrawExport ewWire { public: bool isEqual(ewWire w); @@ -96,7 +98,7 @@ public: int size(void); }; -class ewWireList +class TechDrawExport ewWireList { public: ewWireList removeDuplicateWires(); @@ -108,7 +110,7 @@ public: -class edgeVisitor : public boost::planar_face_traversal_visitor +class TechDrawExport edgeVisitor : public boost::planar_face_traversal_visitor { public: template @@ -124,7 +126,7 @@ private: TechDraw::graph m_g; }; -class incidenceItem +class TechDrawExport incidenceItem { public: incidenceItem() {iEdge = 0; angle = 0.0;} @@ -137,7 +139,7 @@ public: edge_t eDesc; }; -class embedItem +class TechDrawExport embedItem { public: embedItem(); @@ -152,7 +154,7 @@ public: }; -class EdgeWalker +class TechDrawExport EdgeWalker { public: EdgeWalker(void); diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColors.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColors.ui index ca3d8624bb..030457aefb 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColors.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColors.ui @@ -7,7 +7,7 @@ 0 0 440 - 342 + 368 @@ -49,115 +49,6 @@ - - - - - true - - - - Normal - - - - - - - Normal line color - - - - 0 - 0 - 0 - - - - NormalColor - - - Mod/TechDraw/Colors - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - true - - - - Hidden Line - - - - - - - Hidden line color - - - - 0 - 0 - 0 - - - - HiddenColor - - - Mod/TechDraw/Colors - - - - - - - - true - - - - Preselected - - - - - - - Preselection color - - - - 255 - 255 - 0 - - - - PreSelectColor - - - Mod/TechDraw/Colors - - - @@ -170,38 +61,6 @@ - - - - Section face color - - - - 211 - 211 - 211 - - - - CutSurfaceColor - - - Mod/TechDraw/Colors - - - - - - - - true - - - - Selected - - - @@ -222,62 +81,10 @@ - - + + - Section Line - - - - - - - Section line color - - - - 0 - 0 - 0 - - - - SectionColor - - - /Mod/TechDraw/Decorations - - - - - - - - true - - - - Background - - - - - - - Background color around pages - - - - 211 - 211 - 211 - - - - Background - - - /Mod/TechDraw/Colors + Vertex @@ -313,13 +120,58 @@ - - - - Dimension + + + + Section line color + + + + 0 + 0 + 0 + + + + SectionColor + + + /Mod/TechDraw/Decorations + + + + Section Line + + + + + + + + true + + + + Normal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -340,22 +192,22 @@ - - + + true - Geometric Hatch + Background - - + + - Geometric hatch pattern color + Normal line color @@ -365,17 +217,82 @@ - GeomHatch + NormalColor + + + Mod/TechDraw/Colors + + + + + + + Preselection color + + + + 255 + 255 + 0 + + + + PreSelectColor + + + Mod/TechDraw/Colors + + + + + + + Background color around pages + + + + 211 + 211 + 211 + + + + Background /Mod/TechDraw/Colors - - + + + + + true + + - Centerline + Preselected + + + + + + + Hidden line color + + + + 0 + 0 + 0 + + + + HiddenColor + + + Mod/TechDraw/Colors @@ -399,17 +316,42 @@ - - + + + + + true + + - Vertex + Selected - - + + - Color of vertices in views + Face color (if not transparent) + + + + 255 + 255 + 255 + + + + FaceColor + + + /Mod/TechDraw/Colors + + + + + + + Geometric hatch pattern color @@ -419,14 +361,26 @@ - VertexColor + GeomHatch - Mod/TechDraw/Decorations + /Mod/TechDraw/Colors - + + + + + true + + + + Hidden Line + + + + @@ -453,23 +407,37 @@ - - + + - Face color (if not transparent) + Color of vertices in views - 255 - 255 - 255 + 0 + 0 + 0 - FaceColor + VertexColor - /Mod/TechDraw/Colors + Mod/TechDraw/Decorations + + + + + + + Dimension + + + + + + + Centerline @@ -485,18 +453,6 @@ - - - - - true - - - - Leaderline - - - @@ -517,6 +473,50 @@ + + + + Section face color + + + + 211 + 211 + 211 + + + + CutSurfaceColor + + + Mod/TechDraw/Colors + + + + + + + + true + + + + Geometric Hatch + + + + + + + + true + + + + Leaderline + + + @@ -534,6 +534,30 @@ + + + + Grid Color + + + + + + + + 0 + 0 + 0 + + + + gridColor + + + /Mod/TechDraw/Colors + + + @@ -548,7 +572,7 @@ - <html><head/><body><p><span style=" font-weight:600;">Note:</span> Items in <span style=" font-style:italic;">italics</span> are default values for new objects. They have no effect on existing objects.</p></body></html> + <html><head/><body><p><span style=" font-weight:600;">Note:</span> Items in <span style=" font-style:italic;">italics</span> are default values for new objects. They have no effect on existing objects.</p></body></html> true diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColorsImp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColorsImp.cpp index a2b04f073a..a121738e19 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColorsImp.cpp +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawColorsImp.cpp @@ -61,6 +61,7 @@ void DlgPrefsTechDrawColorsImp::saveSettings() ui->pcbVertexColor->onSave(); ui->pcbMarkup->onSave(); ui->pcbHighlight->onSave(); + ui->pcb_Grid->onSave(); } void DlgPrefsTechDrawColorsImp::loadSettings() @@ -81,6 +82,7 @@ void DlgPrefsTechDrawColorsImp::loadSettings() ui->pcbVertexColor->onRestore(); ui->pcbMarkup->onRestore(); ui->pcbHighlight->onRestore(); + ui->pcb_Grid->onRestore(); } /** diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawGeneral.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawGeneral.ui index 36aaad1b98..6461b3553e 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawGeneral.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawGeneral.ui @@ -6,8 +6,8 @@ 0 0 - 440 - 581 + 499 + 776 @@ -275,9 +275,7 @@ for ProjectionGroups Font for labels - - 10 - + LabelFont @@ -788,6 +786,76 @@ for ProjectionGroups + + + + Grid + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 10 + + + gridSpacing + + + /Mod/TechDraw/General + + + + + + + Show Grid + + + true + + + showGrid + + + /Mod/TechDraw/General + + + + + + + + true + + + + Grid Spacing + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + @@ -797,26 +865,13 @@ for ProjectionGroups - <html><head/><body><p><span style=" font-weight:600;">Note:</span> Items in <span style=" font-style:italic;">italics</span> are default values for new objects. They have no effect on existing objects.</p></body></html> + <html><head/><body><p><span style=" font-weight:600;">Note:</span> Items in <span style=" font-style:italic;">italics</span> are default values for new objects. They have no effect on existing objects.</p></body></html> true - - - - Qt::Vertical - - - - 20 - 19 - - - - @@ -835,6 +890,11 @@ for ProjectionGroups Gui::FileChooser
Gui/PrefWidgets.h
+ + Gui::PrefSpinBox + QSpinBox +
Gui/PrefWidgets.h
+
Gui::PrefCheckBox QCheckBox diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawGeneralImp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawGeneralImp.cpp index 3eeb076a0c..ccb7068a69 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawGeneralImp.cpp +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawGeneralImp.cpp @@ -71,6 +71,8 @@ void DlgPrefsTechDrawGeneralImp::saveSettings() ui->pfc_Welding->onSave(); ui->pfc_FilePattern->onSave(); ui->le_NamePattern->onSave(); + ui->cb_ShowGrid->onSave(); + ui->psb_GridSpacing->onSave(); } void DlgPrefsTechDrawGeneralImp::loadSettings() @@ -106,6 +108,8 @@ void DlgPrefsTechDrawGeneralImp::loadSettings() ui->pfc_Welding->onRestore(); ui->pfc_FilePattern->onRestore(); ui->le_NamePattern->onRestore(); + ui->cb_ShowGrid->onRestore(); + ui->psb_GridSpacing->onRestore(); } /** diff --git a/src/Mod/TechDraw/Gui/PreferencesGui.cpp b/src/Mod/TechDraw/Gui/PreferencesGui.cpp index 52cedba0b3..a5e4f34526 100644 --- a/src/Mod/TechDraw/Gui/PreferencesGui.cpp +++ b/src/Mod/TechDraw/Gui/PreferencesGui.cpp @@ -211,3 +211,36 @@ QString PreferencesGui::weldingDirectory() return qSymbolDir; } + +App::Color PreferencesGui::gridColor() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")-> + GetGroup("Mod/TechDraw/Colors"); + App::Color result; + result.setPackedValue(hGrp->GetUnsigned("gridColor", 0x000000FF)); //#000000 black + return result; +} + +QColor PreferencesGui::gridQColor() +{ + return PreferencesGui::gridColor().asValue(); +} + +int PreferencesGui::gridSpacing() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")-> + GetGroup("Mod/TechDraw/General"); + int spacing = hGrp->GetInt("gridSpacing", 10); + return spacing; +} + +bool PreferencesGui::showGrid() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")-> + GetGroup("Mod/TechDraw/General"); + bool show = hGrp->GetInt("showGrid", true); + return show; +} diff --git a/src/Mod/TechDraw/Gui/PreferencesGui.h b/src/Mod/TechDraw/Gui/PreferencesGui.h index 51848218a7..b0197eb700 100644 --- a/src/Mod/TechDraw/Gui/PreferencesGui.h +++ b/src/Mod/TechDraw/Gui/PreferencesGui.h @@ -63,6 +63,11 @@ static int mattingStyle(); static QString weldingDirectory(); +static bool showGrid(); +static App::Color gridColor(); +static QColor gridQColor(); +static int gridSpacing(); + }; } //end namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 09471c0f3b..b0fb37b54d 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -90,6 +90,7 @@ #include #include "Rez.h" +#include "PreferencesGui.h" #include "QGIDrawingTemplate.h" #include "QGITemplate.h" #include "QGISVGTemplate.h" @@ -134,7 +135,8 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) drawBkg(true), m_vpPage(0), balloonPlacing(false), - panningActive(false) + panningActive(false), + m_showGrid(false) { assert(vp); m_vpPage = vp; @@ -1306,5 +1308,47 @@ void QGVPage::resetCursor() { viewport()->setCursor(Qt::ArrowCursor); } +void QGVPage::drawForeground(QPainter *painter, const QRectF &rect) +{ + Q_UNUSED(rect); + if (m_showGrid) { + QPen gridPen(PreferencesGui::gridQColor()); + QPen savePen = painter->pen(); + painter->setPen(gridPen); + painter->drawPath(m_gridPath); + painter->setPen(savePen); + } +} + +void QGVPage::makeGrid(int gridWidth, int gridHeight, int gridStep) +{ + QPainterPath grid; + int width = Rez::guiX(gridWidth); + int height = Rez::guiX(gridHeight); + int step = Rez::guiX(gridStep); + int horizStart = 0; + int vPos = 0; + int rows = (height / step) + 1; + //draw horizontal lines + for (int i = 0; i < rows; i++) { + vPos = i * step; + QPoint start (horizStart, -vPos); + QPoint end (width, -vPos); + grid.moveTo(start); + grid.lineTo(end); + } + //draw vertical lines + int vertStart = 0; + int cols = (width / step) + 1; + int hPos = 0; + for (int i = 0; i < cols; i++) { + hPos = i * step; + QPoint start(hPos, -vertStart); + QPoint end(hPos, -height); + grid.moveTo(start); + grid.lineTo(end); + } + m_gridPath = grid; +} #include diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 427d87a4f6..ae8fc5221f 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -23,12 +23,18 @@ #ifndef TECHDRAWGUI_QGVIEW_H #define TECHDRAWGUI_QGVIEW_H +#include + #include #include #include class QTemporaryFile; +namespace App { +class DocumentObject; +} + namespace TechDraw { class DrawView; class DrawViewPart; @@ -122,6 +128,9 @@ public: void saveSvg(QString filename); void postProcessXml(QTemporaryFile& tempFile, QString filename, QString pagename); + void makeGrid(int width, int height, int step); + void showGrid(bool state) {m_showGrid = state;} + void updateViewport(void) {viewport()->repaint();} public Q_SLOTS: void setHighQualityAntialiasing(bool highQualityAntialiasing); @@ -150,6 +159,7 @@ protected: void activateCursor(QCursor cursor); void resetCursor(); + virtual void drawForeground(QPainter *painter, const QRectF &rect) override; private: RendererType m_renderer; @@ -172,6 +182,9 @@ private: QPoint panOrigin; bool panningActive; + + bool m_showGrid; + QPainterPath m_gridPath; }; } // namespace diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.h b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.h index b778363843..b0224470cb 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.h +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.h @@ -25,6 +25,8 @@ #ifndef TECHDRAWGUI_VIEWPROVIDERVIEW_H #define TECHDRAWGUI_VIEWPROVIDERVIEW_H +#include + #include #include diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index d89636a3f9..ffa4b87b63 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -82,9 +82,12 @@ ViewProviderPage::ViewProviderPage() m_graphicsView(nullptr) { sPixmap = "TechDraw_TreePage"; - static const char *group = "Base"; + static const char *group = "Grid"; ADD_PROPERTY_TYPE(ShowFrames ,(true),group,App::Prop_None,"NonGui! Show or hide View frames and Labels on this Page"); + ADD_PROPERTY_TYPE(ShowGrid ,(PreferencesGui::showGrid()),group,App::Prop_None,"Show or hide a grid on this Page"); + ADD_PROPERTY_TYPE(GridSpacing, (PreferencesGui::gridSpacing()), group, (App::PropertyType)(App::Prop_None), + "Grid line spacing in mm"); ShowFrames.setStatus(App::Property::Hidden,true); Visibility.setStatus(App::Property::Hidden,true); @@ -300,6 +303,8 @@ bool ViewProviderPage::showMDIViewPage() m_mdiView->redrawAllViews(); m_mdiView->fixOrphans(true); } + setGrid(); + return true; } @@ -382,11 +387,11 @@ MDIViewPage* ViewProviderPage::getMDIViewPage() const void ViewProviderPage::onChanged(const App::Property *prop) { -// if (prop == &(getDrawPage()->Template)) { -// if (m_mdiView) { -// m_mdiView->updateTemplate(); -// } -// } + if (prop == &(ShowGrid)) { + setGrid(); + } else if (prop == &(GridSpacing)) { + setGrid(); + } Gui::ViewProviderDocumentObject::onChanged(prop); } @@ -492,3 +497,28 @@ Gui::MDIView *ViewProviderPage::getMDIView() const const_cast(this)->showMDIViewPage(); return m_mdiView.data(); } + +void ViewProviderPage::setGrid(void) +{ + TechDraw::DrawPage* dp = getDrawPage(); + if (!dp) { + return; + } + int pageWidth = 298; + int pageHeight = 215; + int gridStep = GridSpacing.getValue() > 0 ? GridSpacing.getValue() : 10; + if (dp) { + pageWidth = dp->getPageWidth(); + pageHeight = dp->getPageHeight(); + } + QGVPage* widget = getGraphicsView(); + if (widget) { + if (ShowGrid.getValue()) { + widget->showGrid(true); + widget->makeGrid(pageWidth, pageHeight, gridStep); + } else { + widget->showGrid(false); + } + widget->updateViewport(); + } +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.h b/src/Mod/TechDraw/Gui/ViewProviderPage.h index 895f92f740..438fe9e060 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.h +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.h @@ -25,6 +25,8 @@ #ifndef DRAWINGGUI_VIEWPROVIDERPAGE_H #define DRAWINGGUI_VIEWPROVIDERPAGE_H +#include + #include #include @@ -50,6 +52,8 @@ public: virtual ~ViewProviderPage(); App::PropertyBool ShowFrames; + App::PropertyBool ShowGrid; + App::PropertyInteger GridSpacing; virtual void attach(App::DocumentObject *) override; virtual void setDisplayMode(const char* ModeName) override; @@ -94,6 +98,7 @@ public: QGVPage *getGraphicsView() { return m_graphicsView; } void setGraphicsView(QGVPage* gv); virtual bool canDelete(App::DocumentObject* obj) const override; + void setGrid(void); protected: bool setEdit(int ModNum) override; @@ -103,6 +108,9 @@ private: bool m_docReady; std::string m_pageName; QGVPage* m_graphicsView; + bool m_showGrid; + int m_gridStep; + }; } // namespace TechDrawGui