From dffa7040b968e72f2c6a60107f9192efa13e4282 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 5 Jan 2022 19:27:34 -0500 Subject: [PATCH] [TD]combine @wmayer and edi271 changes re command extensions --- src/Mod/TechDraw/Gui/CommandExtensionDims.cpp | 6 +- src/Mod/TechDraw/Gui/CommandExtensionPack.cpp | 50 +++--- .../TechDraw/Gui/TaskSelectLineAttributes.cpp | 163 ++++++++++-------- .../TechDraw/Gui/TaskSelectLineAttributes.h | 43 ++--- .../TechDraw/Gui/TaskSelectLineAttributes.ui | 38 ++-- 5 files changed, 163 insertions(+), 137 deletions(-) diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index b436879208..7a8ada637b 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -78,6 +78,7 @@ using namespace TechDrawGui; using namespace TechDraw; using namespace std; +namespace TechDrawGui { //internal structures and sort functions struct dimVertex{ // save a dimension defining vertex and its point @@ -111,6 +112,7 @@ bool _checkSelAndObj(Gui::Command* cmd, std::vector& selection, TechDraw::DrawViewPart*& objFeat, std::string message); +} //=========================================================================== // TechDraw_ExtensionInsertDiameter @@ -2081,6 +2083,7 @@ bool CmdTechDrawExtensionCreateLengthArc::isActive(void) return (havePage && haveView); } +namespace TechDrawGui { //=========================================================================== // internal helper routines //=========================================================================== @@ -2196,6 +2199,7 @@ std::vector_getDimensions(std::vectorrequestPaint(); Gui::Command::commitCommand(); } +} DEF_STD_CMD_A(CmdTechDrawExtensionHoleCircle) @@ -168,7 +171,7 @@ CmdTechDrawExtensionHoleCircle::CmdTechDrawExtensionHoleCircle() sMenuText = QT_TR_NOOP("Draw bolt circle centerlines"); sToolTipText = QT_TR_NOOP("Draw the centerlines of a bolt circle\n\ - pick favoured line attributes\n\ - - select at least three cirles of a bolt circle\n\ + - select at least three circles of a bolt circle\n\ - click this button"); sWhatsThis = "TechDraw_ExtensionHoleCircle"; sStatusTip = sToolTipText; @@ -352,7 +355,7 @@ void CmdTechDrawExtensionCircleCenterLinesGroup::languageChange() arc2->setToolTip(QApplication::translate("TechDraw_Extension", "Draw the centerlines of a bolt circle\n\ - pick favoured line attributes\n\ - - select at least three cirles of a bolt circle\n\ + - select at least three circles of a bolt circle\n\ - click this buttone")); arc2->setStatusTip(arc2->toolTip()); } @@ -724,7 +727,7 @@ CmdTechDrawExtensionSelectLineAttributes::CmdTechDrawExtensionSelectLineAttribut void CmdTechDrawExtensionSelectLineAttributes::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::Control().showDialog(new TaskDlgSelectLineAttributes(& activeAttributes)); + Gui::Control().showDialog(new TaskDlgSelectLineAttributes(&_getActiveLineAttributes())); } bool CmdTechDrawExtensionSelectLineAttributes::isActive(void) @@ -1433,8 +1436,8 @@ void execExtendShortenLine(Gui::Command* cmd, bool extend){ Base::Vector3d P1 = genLine->points.at(1); if (baseGeo->cosmetic){ std::string uniTag = baseGeo->getCosmeticTag(); - int oldStyle; - float oldWeight; + int oldStyle = 1; + float oldWeight = 1.0f; App::Color oldColor; std::vector toDelete; toDelete.push_back(uniTag); @@ -1647,6 +1650,13 @@ bool CmdTechDrawExtendShortenLineGroup::isActive(void) //=========================================================================== // internal helper routines //=========================================================================== +namespace TechDrawGui { + +lineAttributes& _getActiveLineAttributes() +{ + static lineAttributes attributes; + return attributes; +} bool _checkSel(Gui::Command* cmd, std::vector& selection, @@ -1826,13 +1836,12 @@ void _intersectionCC(TechDraw::BaseGeom* geom1, TechDraw::BaseGeom* geom2, std:: } } -Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3){ - // Circle through 3 points, calculate center point - Base::Vector2d p12d(p1.x,p1.y); - Base::Vector2d p22d(p2.x,p2.y); - Base::Vector2d p32d(p3.x,p3.y); - Base::Vector2d centerPoint = Part::Geom2dCircle::getCircleCenter(p12d, p22d, p32d); - return Base::Vector3d(centerPoint.x, centerPoint.y, 0.0); +Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3) { + Base::Vector2d v1(p1.x, p1.y); + Base::Vector2d v2(p2.x, p2.y); + Base::Vector2d v3(p3.x, p3.y); + Base::Vector2d c = Part::Geom2dCircle::getCircleCenter(v1, v2, v3); + return Base::Vector3d(c.x, c.y, 0.0); } bool _circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C){ @@ -1909,16 +1918,16 @@ void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPar void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge) { // set line attributes of a cosmetic edge - cosEdge->m_format.m_style = int(activeAttributes.getStyle()+1); - cosEdge->m_format.m_weight = activeAttributes.getWidthValue(); - cosEdge->m_format.m_color = activeAttributes.getColorValue(); + cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); + cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue(); + cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue(); } void _setLineAttributes(TechDraw::CenterLine* cosEdge) { - // set line attributes of a centerline - cosEdge->m_format.m_style = int(activeAttributes.getStyle()+1); - cosEdge->m_format.m_weight = activeAttributes.getWidthValue(); - cosEdge->m_format.m_color = activeAttributes.getColorValue(); + // set line attributes of a cosmetic edge + cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); + cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue(); + cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue(); } void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight, App::Color color) { @@ -1927,6 +1936,7 @@ void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight cosEdge->m_format.m_weight = weight; cosEdge->m_format.m_color = color; } +} //------------------------------------------------------------------------------ void CreateTechDrawCommandsExtensions(void) diff --git a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.cpp b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.cpp index 02b9edae0f..2d3896e086 100644 --- a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.cpp +++ b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.cpp @@ -74,37 +74,61 @@ using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; +enum class EdgeStyle { + solid = 1, + dashed = 2, + dotted = 3, + dashdotted = 4 +}; + +enum class EdgeWidth { + small = 1, + middle = 2, + thick = 3 +}; + +enum class EdgeColor { + black = 1, + grey = 2, + red = 3, + green = 4, + blue = 5, + magenta = 6, + cyan = 7, + yellow = 8 +}; + //=========================================================================== // managing global line attributes //=========================================================================== -LineAttributes::LineAttributes(void) +lineAttributes::lineAttributes(void) { - style = dotted; - width = middle; - color = black; + style = int(EdgeStyle::dotted); + width = int(EdgeWidth::middle); + color = int(EdgeColor::black); } -void LineAttributes::setStyle(edgeStyle newStyle) +void lineAttributes::setStyle(int newStyle) { style = newStyle; } -void LineAttributes::setWidth(edgeWidth newWidth) +void lineAttributes::setWidth(int newWidth) { width = newWidth; } -float LineAttributes::getWidthValue(void) +float lineAttributes::getWidthValue(void) { - switch(width){ - case small: + switch(EdgeWidth(width)) { + case EdgeWidth::small: return 0.18f; break; - case middle: + case EdgeWidth::middle: return 0.35f; break; - case thick: + case EdgeWidth::thick: return 0.5f; break; default: @@ -112,36 +136,36 @@ float LineAttributes::getWidthValue(void) } } -void LineAttributes::setColor(edgeColor newColor) +void lineAttributes::setColor(int newColor) { color = newColor; } -App::Color LineAttributes::getColorValue(void) +App::Color lineAttributes::getColorValue(void) { - switch(color){ - case black: + switch(EdgeColor(color)) { + case EdgeColor::black: return App::Color(0.0,0.0,0.0); break; - case grey: + case EdgeColor::grey: return App::Color(0.7,0.7,0.7); break; - case red: + case EdgeColor::red: return App::Color(1.0,0.0,0.0); break; - case green: + case EdgeColor::green: return App::Color(0.0,1.0,0.0); break; - case blue: + case EdgeColor::blue: return App::Color(0.0,0.0,1.0); break; - case magenta: + case EdgeColor::magenta: return App::Color(1.0,0.0,1.0); break; - case cyan: + case EdgeColor::cyan: return App::Color(0.0,1.0,1.0); break; - case yellow: + case EdgeColor::yellow: return App::Color(1.0,1.0,0.0); break; default: @@ -169,10 +193,9 @@ dimAttributes activeDimAttributes; // container holding dimension attributes // TaskSelectLineAttributes //=========================================================================== -TaskSelectLineAttributes::TaskSelectLineAttributes(LineAttributes * ptActiveAttributes) : - ui(new Ui_TaskSelectLineAttributes), - activeAttributes(ptActiveAttributes) - +TaskSelectLineAttributes::TaskSelectLineAttributes(lineAttributes * ptActiveAttributes) : + activeAttributes(ptActiveAttributes), + ui(new Ui_TaskSelectLineAttributes) { ui->setupUi(this); @@ -202,64 +225,64 @@ void TaskSelectLineAttributes::changeEvent(QEvent *e) void TaskSelectLineAttributes::setUiEdit() { - setWindowTitle(QObject::tr("Select Line Attributes")); - LineAttributes::edgeStyle lineStyle = activeAttributes->getStyle(); - switch(lineStyle){ - case LineAttributes::solid: + setWindowTitle(tr("Select line attributes")); + int lineStyle = activeAttributes->getStyle(); + switch(EdgeStyle(lineStyle)) { + case EdgeStyle::solid: ui->rbSolid->setChecked(true); break; - case LineAttributes::dashed: + case EdgeStyle::dashed: ui->rbDashed->setChecked(true); break; - case LineAttributes::dotted: + case EdgeStyle::dotted: ui->rbDotted->setChecked(true); break; - case LineAttributes::dashdotted: + case EdgeStyle::dashdotted: ui->rbDashDotted->setChecked(true); break; default: ui->rbDashDotted->setChecked(true); } - LineAttributes::edgeWidth lineWidth = activeAttributes->getWidth(); - switch(lineWidth){ - case LineAttributes::small: + int lineWidth = activeAttributes->getWidth(); + switch(EdgeWidth(lineWidth)) { + case EdgeWidth::small: ui->rbThin->setChecked(true); break; - case LineAttributes::middle: + case EdgeWidth::middle: ui->rbMiddle->setChecked(true); break; - case LineAttributes::thick: + case EdgeWidth::thick: ui->rbThick->setChecked(true); break; default: ui->rbMiddle->setChecked(true); } - LineAttributes::edgeColor lineColor = activeAttributes->getColor(); - switch(lineColor){ - case LineAttributes::black: + int lineColor = activeAttributes->getColor(); + switch(EdgeColor(lineColor)) { + case EdgeColor::black: ui->rbBlack->setChecked(true); break; - case LineAttributes::grey: + case EdgeColor::grey: ui->rbGrey->setChecked(true); break; - case LineAttributes::red: + case EdgeColor::red: ui->rbRed->setChecked(true); break; - case LineAttributes::green: + case EdgeColor::green: ui->rbGreen->setChecked(true); break; - case LineAttributes::blue: + case EdgeColor::blue: ui->rbBlue->setChecked(true); break; - case LineAttributes::magenta: + case EdgeColor::magenta: ui->rbMagenta->setChecked(true); break; - case LineAttributes::cyan: + case EdgeColor::cyan: ui->rbCyan->setChecked(true); break; - case LineAttributes::yellow: + case EdgeColor::yellow: ui->rbYellow->setChecked(true); break; default: @@ -274,60 +297,60 @@ void TaskSelectLineAttributes::setUiEdit() bool TaskSelectLineAttributes::accept() { if (ui->rbSolid->isChecked()){ - activeAttributes->setStyle(LineAttributes::solid); + activeAttributes->setStyle(int(EdgeStyle::solid)); } else if (ui->rbDashed->isChecked()){ - activeAttributes->setStyle(LineAttributes::dashed); + activeAttributes->setStyle(int(EdgeStyle::dashed)); } else if (ui->rbDotted->isChecked()){ - activeAttributes->setStyle(LineAttributes::dotted); + activeAttributes->setStyle(int(EdgeStyle::dotted)); } else if (ui->rbDashDotted->isChecked()){ - activeAttributes->setStyle(LineAttributes::dashdotted); + activeAttributes->setStyle(int(EdgeStyle::dashdotted)); } else { - activeAttributes->setStyle(LineAttributes::dashdotted); + activeAttributes->setStyle(int(EdgeStyle::dashdotted)); } if (ui->rbThin->isChecked()){ - activeAttributes->setWidth(LineAttributes::small); + activeAttributes->setWidth(int(EdgeWidth::small)); } else if (ui->rbMiddle->isChecked()){ - activeAttributes->setWidth(LineAttributes::middle); + activeAttributes->setWidth(int(EdgeWidth::middle)); } else if (ui->rbThick->isChecked()){ - activeAttributes->setWidth(LineAttributes::thick); + activeAttributes->setWidth(int(EdgeWidth::thick)); } else { - activeAttributes->setWidth(LineAttributes::middle); + activeAttributes->setWidth(int(EdgeWidth::middle)); } if (ui->rbBlack->isChecked()){ - activeAttributes->setColor(LineAttributes::black); + activeAttributes->setColor(int(EdgeColor::black)); } else if (ui->rbGrey->isChecked()){ - activeAttributes->setColor(LineAttributes::grey); + activeAttributes->setColor(int(EdgeColor::grey)); } else if (ui->rbRed->isChecked()){ - activeAttributes->setColor(LineAttributes::red); + activeAttributes->setColor(int(EdgeColor::red)); } else if (ui->rbGreen->isChecked()){ - activeAttributes->setColor(LineAttributes::green); + activeAttributes->setColor(int(EdgeColor::green)); } else if (ui->rbBlue->isChecked()){ - activeAttributes->setColor(LineAttributes::blue); + activeAttributes->setColor(int(EdgeColor::blue)); } else if (ui->rbMagenta->isChecked()){ - activeAttributes->setColor(LineAttributes::magenta); + activeAttributes->setColor(int(EdgeColor::magenta)); } else if (ui->rbCyan->isChecked()){ - activeAttributes->setColor(LineAttributes::cyan); + activeAttributes->setColor(int(EdgeColor::cyan)); } else if (ui->rbYellow->isChecked()){ - activeAttributes->setColor(LineAttributes::yellow); + activeAttributes->setColor(int(EdgeColor::yellow)); } else { - activeAttributes->setColor(LineAttributes::black); + activeAttributes->setColor(int(EdgeColor::black)); } double cascadeSpacing = ui->sbSpacing->value(); @@ -338,16 +361,14 @@ bool TaskSelectLineAttributes::accept() bool TaskSelectLineAttributes::reject() { - //there's nothing to do. - Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); - return false; + return true; } //=========================================================================== // TaskDlgSelectLineAttributes //=========================================================================== -TaskDlgSelectLineAttributes::TaskDlgSelectLineAttributes(LineAttributes * ptActiveAttributes) +TaskDlgSelectLineAttributes::TaskDlgSelectLineAttributes(lineAttributes * ptActiveAttributes) : TaskDialog() { widget = new TaskSelectLineAttributes(ptActiveAttributes); @@ -388,4 +409,4 @@ bool TaskDlgSelectLineAttributes::reject() } -#include \ No newline at end of file +#include diff --git a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h index 67d2814073..9a114465e9 100644 --- a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h +++ b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h @@ -30,10 +30,6 @@ #include -#include - -class Ui_TaskSelectLineAttributes; - class dimAttributes { double cascadeSpacing; @@ -72,37 +68,33 @@ class QGIView; class QGIPrimPath; class MDIViewPage; class ViewProviderViewPart; +class Ui_TaskSelectLineAttributes; -class LineAttributes { - public: - enum edgeStyle{solid, dashed, dotted, dashdotted}; - enum edgeWidth{small, middle, thick }; - enum edgeColor{black, grey, red, green, blue, magenta, cyan, yellow}; - private: - edgeStyle style; - edgeWidth width; - edgeColor color; +class lineAttributes { + int style; + int width; + int color; - public: +public: - LineAttributes(void); - void setStyle(edgeStyle); - edgeStyle getStyle(void) {return style;} - void setWidth(edgeWidth); - edgeWidth getWidth(void) {return width;} + lineAttributes(void); + void setStyle(int); + int getStyle(void) const {return style;} + void setWidth(int); + int getWidth(void) const {return width;} float getWidthValue(void); - void setColor(edgeColor); - edgeColor getColor(void) {return color;} + void setColor(int); + int getColor(void) const {return color;} App::Color getColorValue(void); -}; // class LineAttributes +}; // class lineAttributes class TaskSelectLineAttributes : public QWidget { Q_OBJECT public: - TaskSelectLineAttributes(LineAttributes * ptActiveAttributes); + TaskSelectLineAttributes(lineAttributes * ptActiveAttributes); ~TaskSelectLineAttributes(); public Q_SLOTS: @@ -111,7 +103,6 @@ public: virtual bool accept(); virtual bool reject(); void updateTask(); - LineAttributes* activeAttributes; protected Q_SLOTS: @@ -121,8 +112,8 @@ protected: void setUiEdit(void); private: + lineAttributes* activeAttributes; std::unique_ptr ui; - }; // class TaskSelectLineAttributes class TaskDlgSelectLineAttributes : public Gui::TaskView::TaskDialog @@ -130,7 +121,7 @@ class TaskDlgSelectLineAttributes : public Gui::TaskView::TaskDialog Q_OBJECT public: - TaskDlgSelectLineAttributes(LineAttributes * ptActiveAttributes); + TaskDlgSelectLineAttributes(lineAttributes * ptActiveAttributes); ~TaskDlgSelectLineAttributes(); public: diff --git a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.ui b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.ui index 1a7ea304b3..61bac0205c 100644 --- a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.ui +++ b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.ui @@ -31,17 +31,17 @@ - Linestyles: + Line style: - Set Line style to solid + Set line style to solid - solid + Solid true @@ -54,7 +54,7 @@ - dashed + Dashed true @@ -67,7 +67,7 @@ - dotted + Dotted true @@ -80,7 +80,7 @@ - dashdot + Dashdot true @@ -100,14 +100,14 @@ - Lineswidth: + Line width: - thin 0,18 + Thin 0,18 true @@ -120,7 +120,7 @@ - middle 0,35 + Middle 0,35 true @@ -136,7 +136,7 @@ - thick 0,70 + Thick 0,70 true @@ -153,14 +153,14 @@ - Linecolors: + Line color: - black + Black true @@ -176,7 +176,7 @@ - blue + Blue true @@ -189,7 +189,7 @@ - grey + Grey true @@ -202,7 +202,7 @@ - magenta + Magenta true @@ -215,7 +215,7 @@ - red + Red true @@ -228,7 +228,7 @@ - cyan + Cyan true @@ -241,7 +241,7 @@ - green + Green true @@ -254,7 +254,7 @@ - yellow + Yellow true