diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index 74d95361e6..8b4f57d911 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -57,7 +57,6 @@ #include "TaskRichAnno.h" #include "TaskSurfaceFinishSymbols.h" #include "TaskWeldingSymbol.h" -#include "TaskCosmeticCircle.h" #include "ViewProviderViewPart.h" #include "CommandHelpers.h" @@ -76,7 +75,6 @@ void execCenterLine(Gui::Command* cmd); void exec2LineCenterLine(Gui::Command* cmd); void exec2PointCenterLine(Gui::Command* cmd); void execLine2Points(Gui::Command* cmd); -void execCosmeticCircle(Gui::Command* cmd); //=========================================================================== // TechDraw_Leader @@ -1121,156 +1119,6 @@ void execLine2Points(Gui::Command* cmd) is3d)); } -//=========================================================================== -// TechDraw_CosmeticCircle -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawCosmeticCircle) - -CmdTechDrawCosmeticCircle::CmdTechDrawCosmeticCircle() - : Command("TechDraw_CosmeticCircle") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Cosmetic Circle"); - sToolTipText = QT_TR_NOOP("Adds a cosmetic circle to the current page"); - sWhatsThis = "TechDraw_CosmeticCircle"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_CosmeticCircle"; -} - -void CmdTechDrawCosmeticCircle::activated(int iMsg) -{ - Q_UNUSED(iMsg); - - Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); - if (dlg) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task in progress"), - QObject::tr("Close active task dialog and try again")); - return; - } - - execCosmeticCircle(this); - - updateActive(); - Gui::Selection().clearSelection(); -} - -bool CmdTechDrawCosmeticCircle::isActive() -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this, true); - return (havePage && haveView); -} - -void execCosmeticCircle(Gui::Command* cmd) -{ - TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd); - if (!page) { - return; - } - - std::vector selection = cmd->getSelection().getSelectionEx(); - TechDraw::DrawViewPart* baseFeat = nullptr; - std::vector subNames2D; - std::vector< std::pair > objs3D; - if (selection.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Selection is empty")); - return; - } - - for (auto& so: selection) { - if (so.getObject()->isDerivedFrom()) { - baseFeat = static_cast (so.getObject()); - subNames2D = so.getSubNames(); - } else if (so.getObject()->isDerivedFrom()) { - std::vector subNames3D = so.getSubNames(); - for (auto& sub3D: subNames3D) { - std::pair temp; - temp.first = static_cast(so.getObject()); - temp.second = sub3D; - objs3D.push_back(temp); - } - } else { - //garbage - } - } - - if (!baseFeat) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("You must select a base view for the circle")); - return; - } - - std::vector edgeNames; - std::vector vertexNames; - for (auto& s: subNames2D) { - std::string geomType = DrawUtil::getGeomTypeFromName(s); - if (geomType == "Vertex") { - vertexNames.push_back(s); - } else if (geomType == "Edge") { - edgeNames.push_back(s); - } - } - - //check if editing existing edge - if (!edgeNames.empty() && (edgeNames.size() == 1)) { - TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front()); - if (!ce - || !(ce->m_geometry->getGeomType() == GeomType::CIRCLE - || ce->m_geometry->getGeomType() == GeomType::ARCOFCIRCLE)) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Selection is not a cosmetic circle or a cosmetic arc of a circle")); - return; - } - - Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat, - edgeNames.front())); - return; - } - - std::vector points; - std::vector is3d; - //get the 2D points - if (!vertexNames.empty()) { - for (auto& v2d: vertexNames) { - int idx = DrawUtil::getIndexFromName(v2d); - TechDraw::VertexPtr v = baseFeat->getProjVertexByIndex(idx); - if (v) { - points.push_back(v->point()); - is3d.push_back(false); - } - } - } - //get the 3D points - if (!objs3D.empty()) { - for (auto& o3D: objs3D) { - int idx = DrawUtil::getIndexFromName(o3D.second); - Part::TopoShape s = o3D.first->Shape.getShape(); - TopoDS_Vertex v = TopoDS::Vertex(s.getSubShape(TopAbs_VERTEX, idx)); - Base::Vector3d p = DrawUtil::vertex2Vector(v); - points.push_back(p); - is3d.push_back(true); - } - } - - if (points.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Please select a center for the circle")); - return; - } - - bool centerIs3d = false; - if (!is3d.empty()) { - centerIs3d = is3d.front(); - } - - Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat, - points, - centerIs3d)); -} - //=========================================================================== // TechDraw_CosmeticEraser //=========================================================================== @@ -1680,7 +1528,6 @@ void CreateTechDrawCommandsAnnotate() rcCmdMgr.addCommand(new CmdTechDraw2LineCenterLine()); rcCmdMgr.addCommand(new CmdTechDraw2PointCenterLine()); rcCmdMgr.addCommand(new CmdTechDraw2PointCosmeticLine()); - rcCmdMgr.addCommand(new CmdTechDrawCosmeticCircle()); rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); rcCmdMgr.addCommand(new CmdTechDrawCosmeticEraser()); rcCmdMgr.addCommand(new CmdTechDrawDecorateLine()); diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp index 2cef5cad8c..587302a4c8 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp @@ -62,6 +62,7 @@ #include "DrawGuiUtil.h" #include "QGSPage.h" +#include "TaskCosmeticCircle.h" #include "TaskSelectLineAttributes.h" #include "ViewProviderBalloon.h" #include "ViewProviderDimension.h" @@ -842,6 +843,157 @@ bool CmdTechDrawExtensionVertexAtIntersection::isActive() return (havePage && haveView); } +//=========================================================================== +// TechDraw_CosmeticCircle +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawCosmeticCircle) + +CmdTechDrawCosmeticCircle::CmdTechDrawCosmeticCircle() + : Command("TechDraw_CosmeticCircle") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Cosmetic 1 Point Circle"); + sToolTipText = QT_TR_NOOP("Adds a cosmetic circle based on a selected centerpoint"); + sWhatsThis = "TechDraw_CosmeticCircle"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_CosmeticCircle"; +} + + + +bool CmdTechDrawCosmeticCircle::isActive() +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, true); + return (havePage && haveView); +} + +void execCosmeticCircleCenter(Gui::Command* cmd) +{ + TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd); + if (!page) { + return; + } + + std::vector selection = cmd->getSelection().getSelectionEx(); + TechDraw::DrawViewPart* baseFeat = nullptr; + std::vector subNames2D; + std::vector< std::pair > objs3D; + if (selection.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("Selection is empty.")); + return; + } + + for (auto& so: selection) { + if (so.getObject()->isDerivedFrom()) { + baseFeat = static_cast (so.getObject()); + subNames2D = so.getSubNames(); + } else if (so.getObject()->isDerivedFrom()) { + std::vector subNames3D = so.getSubNames(); + for (auto& sub3D: subNames3D) { + std::pair temp; + temp.first = static_cast(so.getObject()); + temp.second = sub3D; + objs3D.push_back(temp); + } + } else { + //garbage + } + } + + if (!baseFeat) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("You must select a base View for the circle.")); + return; + } + + std::vector edgeNames; + std::vector vertexNames; + for (auto& s: subNames2D) { + std::string geomType = DrawUtil::getGeomTypeFromName(s); + if (geomType == "Vertex") { + vertexNames.push_back(s); + } else if (geomType == "Edge") { + edgeNames.push_back(s); + } + } + + //check if editing existing edge + if (!edgeNames.empty() && (edgeNames.size() == 1)) { + TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front()); + if (!ce + || !(ce->m_geometry->getGeomType() == GeomType::CIRCLE + || ce->m_geometry->getGeomType() == GeomType::ARCOFCIRCLE)) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("Selection is not a Cosmetic Circle or a Cosmetic Arc of Circle.")); + return; + } + + Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat, + edgeNames.front())); + return; + } + + std::vector points; + std::vector is3d; + //get the 2D points + if (!vertexNames.empty()) { + for (auto& v2d: vertexNames) { + int idx = DrawUtil::getIndexFromName(v2d); + TechDraw::VertexPtr v = baseFeat->getProjVertexByIndex(idx); + if (v) { + points.push_back(v->point()); + is3d.push_back(false); + } + } + } + //get the 3D points + if (!objs3D.empty()) { + for (auto& o3D: objs3D) { + int idx = DrawUtil::getIndexFromName(o3D.second); + Part::TopoShape s = o3D.first->Shape.getShape(); + TopoDS_Vertex v = TopoDS::Vertex(s.getSubShape(TopAbs_VERTEX, idx)); + Base::Vector3d p = DrawUtil::vertex2Vector(v); + points.push_back(p); + is3d.push_back(true); + } + } + + if (points.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("Please select a center for the circle.")); + return; + } + + bool centerIs3d = false; + if (!is3d.empty()) { + centerIs3d = is3d.front(); + } + + Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat, + points, + centerIs3d)); +} +void CmdTechDrawCosmeticCircle::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + execCosmeticCircleCenter(this); + + updateActive(); + Gui::Selection().clearSelection(); +} + //=========================================================================== // TechDraw_ExtensionDrawCosmArc //=========================================================================== @@ -951,11 +1103,10 @@ CmdTechDrawExtensionDrawCosmCircle::CmdTechDrawExtensionDrawCosmCircle() { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Cosmetic Circle"); - sToolTipText = QT_TR_NOOP("Adds a cosmetic circle based on two selected vertices, where the " - "first is the ceneter point and the second is the radius"); + sMenuText = QT_TR_NOOP("Cosmetic 2 Point Circle"); + sToolTipText = QT_TR_NOOP("Adds a cosmetic circle based on two selected vertices, where the first is the center point and the second is the radius"); sWhatsThis = "TechDraw_ExtensionDrawCosmCircle"; - sStatusTip = sMenuText; + sStatusTip = sToolTipText; sPixmap = "TechDraw_ExtensionDrawCosmCircle"; } @@ -1014,8 +1165,8 @@ CmdTechDrawExtensionDrawCosmCircle3Points::CmdTechDrawExtensionDrawCosmCircle3Po { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Cosmetic Circle 3 Points"); - sToolTipText = QT_TR_NOOP("Adds a cosmetic circle to three selected vertices"); + sMenuText = QT_TR_NOOP("Cosmetic 3 Point Circle"); + sToolTipText = QT_TR_NOOP("Adds a cosmetic circle that passes through 3 selected perimeter points"); sWhatsThis = "TechDraw_ExtensionDrawCosmCircle3Points"; sStatusTip = sMenuText; sPixmap = "TechDraw_ExtensionDrawCosmCircle3Points"; @@ -1046,7 +1197,7 @@ CmdTechDrawExtensionDrawCirclesGroup::CmdTechDrawExtensionDrawCirclesGroup() { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Cosmetic Circle"); + sMenuText = QT_TR_NOOP("Cosmetic 1 Point Circle"); sToolTipText = QT_TR_NOOP("Adds a cosmetic circle based on two vertices, where the first selection is the centerpoint and the second is the radius"); sWhatsThis = "TechDraw_ExtensionDrawCirclesGroup"; sStatusTip = sMenuText; @@ -1065,15 +1216,18 @@ void CmdTechDrawExtensionDrawCirclesGroup::activated(int iMsg) auto pcAction = qobject_cast(_pcAction); pcAction->setIcon(pcAction->actions().at(iMsg)->icon()); switch (iMsg) { - case 0://draw cosmetic circle + case 0: // 1 Point Circle + execCosmeticCircleCenter(this); + break; + case 1: // 2 Point Circle execDrawCosmCircle(this); break; - case 1://draw cosmetic arc - execDrawCosmArc(this); - break; - case 2://draw cosmetic circle 3 points + case 2: // 3 Point Circle execDrawCosmCircle3Points(this); break; + case 3: // Cosmetic Arc + execDrawCosmArc(this); + break; default: Base::Console().message("CMD::CVGrp - invalid iMsg: %d\n", iMsg); }; @@ -1086,17 +1240,21 @@ Gui::Action* CmdTechDrawExtensionDrawCirclesGroup::createAction() applyCommandData(this->className(), pcAction); QAction* p1 = pcAction->addAction(QString()); - p1->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionDrawCosmCircle")); - p1->setObjectName(QStringLiteral("TechDraw_ExtensionDrawCosmCircle")); - p1->setWhatsThis(QStringLiteral("TechDraw_ExtensionDrawCosmCircle")); + p1->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_CosmeticCircle")); + p1->setObjectName(QStringLiteral("TechDraw_CosmeticCircle")); + p1->setWhatsThis(QStringLiteral("TechDraw_CosmeticCircle")); QAction* p2 = pcAction->addAction(QString()); - p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionDrawCosmArc")); - p2->setObjectName(QStringLiteral("TechDraw_ExtensionDrawCosmArc")); - p2->setWhatsThis(QStringLiteral("TechDraw_ExtensionDrawCosmArc")); + p2->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionDrawCosmCircle")); + p2->setObjectName(QStringLiteral("TechDraw_ExtensionDrawCosmCircle")); + p2->setWhatsThis(QStringLiteral("TechDraw_ExtensionDrawCosmCircle")); QAction* p3 = pcAction->addAction(QString()); p3->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionDrawCosmCircle3Points")); p3->setObjectName(QStringLiteral("TechDraw_ExtensionDrawCosmCircle3Points")); p3->setWhatsThis(QStringLiteral("TechDraw_ExtensionDrawCosmCircle3Points")); + QAction* p4 = pcAction->addAction(QString()); + p4->setIcon(Gui::BitmapFactory().iconFromTheme("TechDraw_ExtensionDrawCosmArc")); + p4->setObjectName(QStringLiteral("TechDraw_ExtensionDrawCosmArc")); + p4->setWhatsThis(QStringLiteral("TechDraw_ExtensionDrawCosmArc")); _pcAction = pcAction; languageChange(); @@ -1112,32 +1270,40 @@ void CmdTechDrawExtensionDrawCirclesGroup::languageChange() { Command::languageChange(); - if (!_pcAction) { + if (!_pcAction) { return; } auto pcAction = qobject_cast(_pcAction); QList action = pcAction->actions(); - QAction* arc1 = action[0]; - arc1->setText( - QApplication::translate("CmdTechDrawExtensionDrawCosmCircle", "Cosmetic Circle")); - arc1->setToolTip(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle", - "Adds a cosmetic circle based on two vertices, where " - "the first selection is the centerpoint and the second is the radius")); - arc1->setStatusTip(arc1->text()); - QAction* arc2 = action[1]; - arc2->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmArc", "Cosmetic Arc")); - arc2->setToolTip( - QApplication::translate("CmdTechDrawExtensionDrawCosmArc", - "Adds a cosmetic counter clockwise arc based on three vertices, " - "where the first selection is the center point and the second is the radius and start point.")); - arc2->setStatusTip(arc2->text()); - QAction* arc3 = action[2]; - arc3->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle3Points", - "Cosmetic 3 Point Circle")); - arc3->setToolTip(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle3Points", - "Adds a cosmetic circle to 3 selected vertices")); - arc3->setStatusTip(arc3->text()); + QAction* p1 = action[0]; + p1->setText(QApplication::translate("CmdTechDrawCosmeticCircle", + "Cosmetic 1 Point Circle")); + p1->setToolTip(QApplication::translate("CmdTechDrawCosmeticCircle", + "Adds a cosmetic circle based on a selected centerpoint")); + p1->setStatusTip(p1->text()); + + QAction* p2 = action[1]; + p2->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle", + "Cosmetic 2 Point Circle")); + p2->setToolTip(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle", + "Adds a cosmetic circle based on two vertices, where " + "the first selection is the centerpoint and the second is the radius")); + p2->setStatusTip(p2->text()); + + QAction* p3 = action[2]; + p3->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle3Points", + "Cosmetic 3 Point Circle")); + p3->setToolTip(QApplication::translate("CmdTechDrawExtensionDrawCosmCircle3Points", + "Adds a cosmetic circle that passes through 3 selected perimeter points")); + p3->setStatusTip(p3->text()); + + QAction* p4 = action[3]; + p4->setText(QApplication::translate("CmdTechDrawExtensionDrawCosmArc", "Cosmetic Arc")); + p4->setToolTip(QApplication::translate("CmdTechDrawExtensionDrawCosmArc", + "Adds a cosmetic counter clockwise arc based on three vertices, " + "where the first selection is the center point and the second is the radius and start point.")); + p4->setStatusTip(p4->text()); } bool CmdTechDrawExtensionDrawCirclesGroup::isActive() @@ -2138,6 +2304,7 @@ void CreateTechDrawCommandsExtensions() rcCmdMgr.addCommand(new CmdTechDrawExtensionHoleCircle()); rcCmdMgr.addCommand(new CmdTechDrawExtensionVertexAtIntersection()); rcCmdMgr.addCommand(new CmdTechDrawExtensionDrawCirclesGroup()); + rcCmdMgr.addCommand(new CmdTechDrawCosmeticCircle()); rcCmdMgr.addCommand(new CmdTechDrawExtensionDrawCosmCircle()); rcCmdMgr.addCommand(new CmdTechDrawExtensionDrawCosmArc()); rcCmdMgr.addCommand(new CmdTechDrawExtensionDrawCosmCircle3Points()); diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index d1f85bfaa5..1d33f24852 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -136,9 +136,10 @@ Gui::MenuItem* Workbench::setupMenuBar() const *toolcenter << "TechDraw_ExtensionVertexAtIntersection"; *toolcenter << "TechDraw_CommandAddOffsetVertex"; *toolcenter << "Separator"; + *toolcenter << "TechDraw_CosmeticCircle"; *toolcenter << "TechDraw_ExtensionDrawCosmCircle"; - *toolcenter << "TechDraw_ExtensionDrawCosmArc"; *toolcenter << "TechDraw_ExtensionDrawCosmCircle3Points"; + *toolcenter << "TechDraw_ExtensionDrawCosmArc"; *toolcenter << "TechDraw_ExtensionLineParallel"; *toolcenter << "TechDraw_ExtensionLinePerpendicular"; @@ -187,7 +188,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const *lines << "TechDraw_2LineCenterLine"; *lines << "TechDraw_2PointCenterLine"; *lines << "TechDraw_2PointCosmeticLine"; - *lines << "TechDraw_CosmeticCircle"; *lines << "Separator"; *lines << "TechDraw_DecorateLine"; *lines << "TechDraw_ShowAll"; @@ -397,7 +397,6 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *anno << "TechDraw_CosmeticVertexGroup"; *anno << "TechDraw_CenterLineGroup"; *anno << "TechDraw_2PointCosmeticLine"; - *anno << "TechDraw_CosmeticCircle"; *anno << "TechDraw_DecorateLine"; *anno << "TechDraw_ShowAll"; *anno << "TechDraw_WeldSymbol"; @@ -496,7 +495,6 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *anno << "TechDraw_CosmeticVertexGroup"; *anno << "TechDraw_CenterLineGroup"; *anno << "TechDraw_2PointCosmeticLine"; - *anno << "TechDraw_CosmeticCircle"; *anno << "TechDraw_DecorateLine"; *anno << "TechDraw_ShowAll"; *anno << "TechDraw_WeldSymbol";