diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 3185eb93fc..14d145c0df 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -54,7 +54,6 @@ #include #include #include -#include #include #include #include @@ -74,9 +73,9 @@ #include "TaskDetail.h" #include "TaskProjGroup.h" #include "TaskProjection.h" +#include "TaskSectionView.h" #include "ViewProviderPage.h" #include "ViewProviderViewPart.h" -#include "TaskSectionView.h" void execSimpleSection(Gui::Command* cmd); void execComplexSection(Gui::Command* cmd); @@ -91,16 +90,15 @@ using namespace TechDraw; DEF_STD_CMD_A(CmdTechDrawPageDefault) -CmdTechDrawPageDefault::CmdTechDrawPageDefault() - : Command("TechDraw_PageDefault") +CmdTechDrawPageDefault::CmdTechDrawPageDefault() : Command("TechDraw_PageDefault") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Default Page"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_PageDefault"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_PageDefault"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Default Page"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_PageDefault"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_PageDefault"; } void CmdTechDrawPageDefault::activated(int iMsg) @@ -116,38 +114,42 @@ void CmdTechDrawPageDefault::activated(int iMsg) if (tfi.isReadable()) { Gui::WaitCursor wc; openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page")); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawPage', '%s')", PageName.c_str()); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawSVGTemplate', '%s')", TemplateName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawPage', '%s')", + PageName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawSVGTemplate', '%s')", + TemplateName.c_str()); - doCommand(Doc, "App.activeDocument().%s.Template = '%s'", TemplateName.c_str(), templateFileName.toStdString().c_str()); - doCommand(Doc, "App.activeDocument().%s.Template = App.activeDocument().%s", PageName.c_str(), TemplateName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Template = '%s'", TemplateName.c_str(), + templateFileName.toStdString().c_str()); + doCommand(Doc, "App.activeDocument().%s.Template = App.activeDocument().%s", + PageName.c_str(), TemplateName.c_str()); updateActive(); commitCommand(); - TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); + TechDraw::DrawPage* fp = + dynamic_cast(getDocument()->getObject(PageName.c_str())); if (!fp) { throw Base::TypeError("CmdTechDrawPageDefault fp not found\n"); } - Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); + Gui::ViewProvider* vp = + Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); TechDrawGui::ViewProviderPage* dvp = dynamic_cast(vp); if (dvp) { dvp->show(); } else { - Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(), TemplateName.c_str()); + Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(), + TemplateName.c_str()); } - } else { - QMessageBox::critical(Gui::getMainWindow(), - QLatin1String("No template"), - QLatin1String("No default template found")); + } + else { + QMessageBox::critical(Gui::getMainWindow(), QLatin1String("No template"), + QLatin1String("No default template found")); } } -bool CmdTechDrawPageDefault::isActive() -{ - return hasActiveDocument(); -} +bool CmdTechDrawPageDefault::isActive() { return hasActiveDocument(); } //=========================================================================== // TechDraw_PageTemplate @@ -155,16 +157,15 @@ bool CmdTechDrawPageDefault::isActive() DEF_STD_CMD_A(CmdTechDrawPageTemplate) -CmdTechDrawPageTemplate::CmdTechDrawPageTemplate() - : Command("TechDraw_PageTemplate") +CmdTechDrawPageTemplate::CmdTechDrawPageTemplate() : Command("TechDraw_PageTemplate") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Page using Template"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_PageTemplate"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_PageTemplate"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Page using Template"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_PageTemplate"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_PageTemplate"; } void CmdTechDrawPageTemplate::activated(int iMsg) @@ -172,11 +173,10 @@ void CmdTechDrawPageTemplate::activated(int iMsg) Q_UNUSED(iMsg); QString work_dir = Gui::FileDialog::getWorkingDirectory(); QString templateDir = Preferences::defaultTemplateDir(); - QString templateFileName = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), - QString::fromUtf8(QT_TR_NOOP("Select a Template File")), - templateDir, - QString::fromUtf8(QT_TR_NOOP("Template (*.svg *.dxf)"))); - Gui::FileDialog::setWorkingDirectory(work_dir); // Don't overwrite WD with templateDir + QString templateFileName = Gui::FileDialog::getOpenFileName( + Gui::getMainWindow(), QString::fromUtf8(QT_TR_NOOP("Select a Template File")), templateDir, + QString::fromUtf8(QT_TR_NOOP("Template (*.svg *.dxf)"))); + Gui::FileDialog::setWorkingDirectory(work_dir);// Don't overwrite WD with templateDir if (templateFileName.isEmpty()) { return; @@ -189,45 +189,48 @@ void CmdTechDrawPageTemplate::activated(int iMsg) if (tfi.isReadable()) { Gui::WaitCursor wc; openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page")); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawPage', '%s')", PageName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawPage', '%s')", + PageName.c_str()); // Create the Template Object to attach to the page - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawSVGTemplate', '%s')", TemplateName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawSVGTemplate', '%s')", + TemplateName.c_str()); //why is "Template" property set twice? -wf // once to set DrawSVGTemplate.Template to OS template file name templateFileName = Base::Tools::escapeEncodeFilename(templateFileName); - doCommand(Doc, "App.activeDocument().%s.Template = \"%s\"", TemplateName.c_str(), templateFileName.toUtf8().constData()); + doCommand(Doc, "App.activeDocument().%s.Template = \"%s\"", TemplateName.c_str(), + templateFileName.toUtf8().constData()); // once to set Page.Template to DrawSVGTemplate.Name - doCommand(Doc, "App.activeDocument().%s.Template = App.activeDocument().%s", PageName.c_str(), TemplateName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Template = App.activeDocument().%s", + PageName.c_str(), TemplateName.c_str()); // consider renaming DrawSVGTemplate.Template property? updateActive(); commitCommand(); - TechDraw::DrawPage* fp = dynamic_cast(getDocument()->getObject(PageName.c_str())); + TechDraw::DrawPage* fp = + dynamic_cast(getDocument()->getObject(PageName.c_str())); if (!fp) { throw Base::TypeError("CmdTechDrawNewPagePick fp not found\n"); } - Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); + Gui::ViewProvider* vp = + Gui::Application::Instance->getDocument(getDocument())->getViewProvider(fp); TechDrawGui::ViewProviderPage* dvp = dynamic_cast(vp); if (dvp) { dvp->show(); } else { - Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(), TemplateName.c_str()); + Base::Console().Log("INFO - Template: %s for Page: %s NOT Found\n", PageName.c_str(), + TemplateName.c_str()); } } else { - QMessageBox::critical(Gui::getMainWindow(), - QLatin1String("No template"), - QLatin1String("Template file is invalid")); + QMessageBox::critical(Gui::getMainWindow(), QLatin1String("No template"), + QLatin1String("Template file is invalid")); } } -bool CmdTechDrawPageTemplate::isActive() -{ - return hasActiveDocument(); -} +bool CmdTechDrawPageTemplate::isActive() { return hasActiveDocument(); } //=========================================================================== // TechDraw_RedrawPage @@ -235,16 +238,15 @@ bool CmdTechDrawPageTemplate::isActive() DEF_STD_CMD_A(CmdTechDrawRedrawPage) -CmdTechDrawRedrawPage::CmdTechDrawRedrawPage() - : Command("TechDraw_RedrawPage") +CmdTechDrawRedrawPage::CmdTechDrawRedrawPage() : Command("TechDraw_RedrawPage") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Redraw Page"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_RedrawPage"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_RedrawPage"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Redraw Page"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_RedrawPage"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_RedrawPage"; } void CmdTechDrawRedrawPage::activated(int iMsg) @@ -272,16 +274,15 @@ bool CmdTechDrawRedrawPage::isActive() DEF_STD_CMD_A(CmdTechDrawPrintAll) -CmdTechDrawPrintAll::CmdTechDrawPrintAll() - : Command("TechDraw_PrintAll") +CmdTechDrawPrintAll::CmdTechDrawPrintAll() : Command("TechDraw_PrintAll") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Print All Pages"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_PrintAll"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_PrintAll"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Print All Pages"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_PrintAll"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_PrintAll"; } void CmdTechDrawPrintAll::activated(int iMsg) @@ -290,10 +291,7 @@ void CmdTechDrawPrintAll::activated(int iMsg) MDIViewPage::printAllPages(); } -bool CmdTechDrawPrintAll::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawPrintAll::isActive() { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_View @@ -301,16 +299,15 @@ bool CmdTechDrawPrintAll::isActive() DEF_STD_CMD_A(CmdTechDrawView) -CmdTechDrawView::CmdTechDrawView() - : Command("TechDraw_View") +CmdTechDrawView::CmdTechDrawView() : Command("TechDraw_View") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert View"); - sToolTipText = QT_TR_NOOP("Insert a View"); - sWhatsThis = "TechDraw_View"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_View"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert View"); + sToolTipText = QT_TR_NOOP("Insert a View"); + sWhatsThis = "TechDraw_View"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_View"; } void CmdTechDrawView::activated(int iMsg) @@ -328,21 +325,19 @@ void CmdTechDrawView::activated(int iMsg) std::vector xShapes; App::DocumentObject* partObj = nullptr; std::string faceName; - Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement; //mystery - bool single = false; //mystery - auto selection = getSelection().getSelectionEx(nullptr, - App::DocumentObject::getClassTypeId(), - resolve, - single); - for (auto& sel: selection) { + Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement;//mystery + bool single = false; //mystery + auto selection = getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), + resolve, single); + for (auto& sel : selection) { bool is_linked = false; auto obj = sel.getObject(); if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) { continue; } - if (obj->isDerivedFrom(App::LinkElement::getClassTypeId()) || - obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) || - obj->isDerivedFrom(App::Link::getClassTypeId()) ) { + if (obj->isDerivedFrom(App::LinkElement::getClassTypeId()) + || obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) + || obj->isDerivedFrom(App::Link::getClassTypeId())) { is_linked = true; } // If parent of the obj is a link to another document, we possibly need to treat non-link obj as linked, too @@ -355,9 +350,9 @@ void CmdTechDrawView::activated(int iMsg) continue; } // 2nd, do we really have a link to obj? - if (parent->isDerivedFrom(App::LinkElement::getClassTypeId()) || - parent->isDerivedFrom(App::LinkGroup::getClassTypeId()) || - parent->isDerivedFrom(App::Link::getClassTypeId())) { + if (parent->isDerivedFrom(App::LinkElement::getClassTypeId()) + || parent->isDerivedFrom(App::LinkGroup::getClassTypeId()) + || parent->isDerivedFrom(App::Link::getClassTypeId())) { // We have a link chain from this document to obj, and obj is in another document -> it's an XLink target is_linked = true; } @@ -384,10 +379,9 @@ void CmdTechDrawView::activated(int iMsg) } } - if (shapes.empty() && - xShapes.empty()) { + if (shapes.empty() && xShapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No Shapes, Groups or Links in this selection")); + QObject::tr("No Shapes, Groups or Links in this selection")); return; } @@ -396,8 +390,10 @@ void CmdTechDrawView::activated(int iMsg) Gui::WaitCursor wc; openCommand(QT_TRANSLATE_NOOP("Command", "Create view")); std::string FeatName = getUniqueObjectName("View"); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewPart', '%s')", FeatName.c_str()); - doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewPart', '%s')", + FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), + FeatName.c_str()); App::DocumentObject* docObj = getDocument()->getObject(FeatName.c_str()); TechDraw::DrawViewPart* dvp = dynamic_cast(docObj); @@ -407,15 +403,16 @@ void CmdTechDrawView::activated(int iMsg) dvp->Source.setValues(shapes); dvp->XSource.setValues(xShapes); if (!faceName.empty()) { - std::pair dirs = DrawGuiUtil::getProjDirFromFace(partObj, faceName); + std::pair dirs = + DrawGuiUtil::getProjDirFromFace(partObj, faceName); projDir = dirs.first; getDocument()->setStatus(App::Document::Status::SkipRecompute, true); - doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f, %.3f, %.3f)", + doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)", FeatName.c_str(), projDir.x, projDir.y, projDir.z); //do something clever with dirs.second; -// dvp->setXDir(dirs.second); - doCommand(Doc, "App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f, %.3f, %.3f)", - FeatName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); + // dvp->setXDir(dirs.second); + doCommand(Doc, "App.activeDocument().%s.XDirection = FreeCAD.Vector(%.12f, %.12f, %.12f)", + FeatName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); doCommand(Doc, "App.activeDocument().%s.recompute()", FeatName.c_str()); getDocument()->setStatus(App::Document::Status::SkipRecompute, false); } @@ -423,10 +420,10 @@ void CmdTechDrawView::activated(int iMsg) std::pair dirs = DrawGuiUtil::get3DDirAndRot(); projDir = dirs.first; getDocument()->setStatus(App::Document::Status::SkipRecompute, true); - doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f, %.3f, %.3f)", + doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)", FeatName.c_str(), projDir.x, projDir.y, projDir.z); - doCommand(Doc, "App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f, %.3f, %.3f)", - FeatName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); + doCommand(Doc, "App.activeDocument().%s.XDirection = FreeCAD.Vector(%.12f, %.12f, %.12f)", + FeatName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); // dvp->setXDir(dirs.second); getDocument()->setStatus(App::Document::Status::SkipRecompute, false); doCommand(Doc, "App.activeDocument().%s.recompute()", FeatName.c_str()); @@ -434,10 +431,7 @@ void CmdTechDrawView::activated(int iMsg) commitCommand(); } -bool CmdTechDrawView::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawView::isActive() { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_ActiveView @@ -445,16 +439,15 @@ bool CmdTechDrawView::isActive() DEF_STD_CMD_A(CmdTechDrawActiveView) -CmdTechDrawActiveView::CmdTechDrawActiveView() - : Command("TechDraw_ActiveView") +CmdTechDrawActiveView::CmdTechDrawActiveView() : Command("TechDraw_ActiveView") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Active View (3D View)"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ActiveView"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ActiveView"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Active View (3D View)"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ActiveView"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ActiveView"; } void CmdTechDrawActiveView::activated(int iMsg) @@ -468,10 +461,7 @@ void CmdTechDrawActiveView::activated(int iMsg) Gui::Control().showDialog(new TaskDlgActiveView(page)); } -bool CmdTechDrawActiveView::isActive() -{ - return DrawGuiUtil::needPage(this, true); -} +bool CmdTechDrawActiveView::isActive() { return DrawGuiUtil::needPage(this, true); } //=========================================================================== // TechDraw_SectionGroup @@ -479,30 +469,29 @@ bool CmdTechDrawActiveView::isActive() DEF_STD_CMD_ACL(CmdTechDrawSectionGroup) -CmdTechDrawSectionGroup::CmdTechDrawSectionGroup() - : Command("TechDraw_SectionGroup") +CmdTechDrawSectionGroup::CmdTechDrawSectionGroup() : Command("TechDraw_SectionGroup") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert a simple or complex Section View"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_SectionGroup"; - sStatusTip = sToolTipText; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert a simple or complex Section View"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_SectionGroup"; + sStatusTip = sToolTipText; } void CmdTechDrawSectionGroup::activated(int iMsg) { -// Base::Console().Message("CMD::SectionGrp - activated(%d)\n", iMsg); - Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + // Base::Console().Message("CMD::SectionGrp - activated(%d)\n", 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.")); + QObject::tr("Close active task dialog and try again.")); return; } Gui::ActionGroup* pcAction = qobject_cast(_pcAction); pcAction->setIcon(pcAction->actions().at(iMsg)->icon()); - switch(iMsg) { + switch (iMsg) { case 0: execSimpleSection(this); break; @@ -514,7 +503,7 @@ void CmdTechDrawSectionGroup::activated(int iMsg) }; } -Gui::Action * CmdTechDrawSectionGroup::createAction() +Gui::Action* CmdTechDrawSectionGroup::createAction() { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); @@ -554,7 +543,8 @@ void CmdTechDrawSectionGroup::languageChange() arc1->setStatusTip(arc1->toolTip()); QAction* arc2 = a[1]; arc2->setText(QApplication::translate("CmdTechDrawSectionGroup", "Complex Section")); - arc2->setToolTip(QApplication::translate("TechDraw_ComplexSection", "Insert complex Section View")); + arc2->setToolTip( + QApplication::translate("TechDraw_ComplexSection", "Insert complex Section View")); arc2->setStatusTip(arc2->toolTip()); } @@ -571,25 +561,24 @@ bool CmdTechDrawSectionGroup::isActive() DEF_STD_CMD_A(CmdTechDrawSectionView) -CmdTechDrawSectionView::CmdTechDrawSectionView() - : Command("TechDraw_SectionView") +CmdTechDrawSectionView::CmdTechDrawSectionView() : Command("TechDraw_SectionView") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Section View"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_SectionView"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_SectionView"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Section View"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_SectionView"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_SectionView"; } void CmdTechDrawSectionView::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + 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.")); + QObject::tr("Close active task dialog and try again.")); return; } @@ -614,16 +603,17 @@ void execSimpleSection(Gui::Command* cmd) return; } - std::vector baseObj = cmd->getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); + std::vector baseObj = + cmd->getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); if (baseObj.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 DrawViewPart object as Base.")); + QObject::tr("Select at least 1 DrawViewPart object as Base.")); return; } TechDraw::DrawViewPart* dvp = static_cast(*baseObj.begin()); Gui::Control().showDialog(new TaskDlgSectionView(dvp)); - cmd->updateActive(); //ok here since dialog doesn't call doc.recompute() + cmd->updateActive();//ok here since dialog doesn't call doc.recompute() cmd->commitCommand(); } @@ -633,35 +623,31 @@ void execSimpleSection(Gui::Command* cmd) DEF_STD_CMD_A(CmdTechDrawComplexSection) -CmdTechDrawComplexSection::CmdTechDrawComplexSection() - : Command("TechDraw_ComplexSection") +CmdTechDrawComplexSection::CmdTechDrawComplexSection() : Command("TechDraw_ComplexSection") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Complex Section"); - sToolTipText = QT_TR_NOOP("Insert a Complex Section"); - sWhatsThis = "TechDraw_ComplexSection"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ComplexSection"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Complex Section"); + sToolTipText = QT_TR_NOOP("Insert a Complex Section"); + sWhatsThis = "TechDraw_ComplexSection"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ComplexSection"; } void CmdTechDrawComplexSection::activated(int iMsg) { Q_UNUSED(iMsg); - Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + 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.")); + QObject::tr("Close active task dialog and try again.")); return; } execComplexSection(this); } -bool CmdTechDrawComplexSection::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawComplexSection::isActive() { return DrawGuiUtil::needPage(this); } //Complex Sections can be created without a baseView, so the gathering of input //for the dialog is more involved that simple section @@ -678,13 +664,11 @@ void execComplexSection(Gui::Command* cmd) std::vector xShapes; App::DocumentObject* profileObject(nullptr); std::vector profileSubs; - Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement; //mystery - bool single = false; //mystery - auto selection = cmd->getSelection().getSelectionEx(nullptr, - App::DocumentObject::getClassTypeId(), - resolve, - single); - for (auto& sel: selection) { + Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement;//mystery + bool single = false; //mystery + auto selection = cmd->getSelection().getSelectionEx( + nullptr, App::DocumentObject::getClassTypeId(), resolve, single); + for (auto& sel : selection) { bool is_linked = false; auto obj = sel.getObject(); if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) { @@ -701,9 +685,9 @@ void execComplexSection(Gui::Command* cmd) } continue; } - if (obj->isDerivedFrom(App::LinkElement::getClassTypeId()) || - obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) || - obj->isDerivedFrom(App::Link::getClassTypeId()) ) { + if (obj->isDerivedFrom(App::LinkElement::getClassTypeId()) + || obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) + || obj->isDerivedFrom(App::Link::getClassTypeId())) { is_linked = true; } // If parent of the obj is a link to another document, we possibly need to treat non-link obj as linked, too @@ -716,9 +700,9 @@ void execComplexSection(Gui::Command* cmd) continue; } // 2nd, do we really have a link to obj? - if (parent->isDerivedFrom(App::LinkElement::getClassTypeId()) || - parent->isDerivedFrom(App::LinkGroup::getClassTypeId()) || - parent->isDerivedFrom(App::Link::getClassTypeId())) { + if (parent->isDerivedFrom(App::LinkElement::getClassTypeId()) + || parent->isDerivedFrom(App::LinkGroup::getClassTypeId()) + || parent->isDerivedFrom(App::Link::getClassTypeId())) { // We have a link chain from this document to obj, and obj is in another document -> it's an XLink target is_linked = true; } @@ -732,33 +716,32 @@ void execComplexSection(Gui::Command* cmd) // skipped later. if (TechDraw::DrawComplexSection::isProfileObject(obj)) { profileObject = obj; - } else { + } + else { shapes.push_back(obj); } } if (!baseView) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("I do not know what base view to use.")); + QObject::tr("I do not know what base view to use.")); return; } - if (shapes.empty() && - xShapes.empty() && - !baseView) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + if (shapes.empty() && xShapes.empty() && !baseView) { + QMessageBox::warning( + Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("No Base View, Shapes, Groups or Links in this selection")); return; } if (!profileObject) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No profile object found in selection")); + QObject::tr("No profile object found in selection")); return; } - Gui::Control().showDialog(new TaskDlgComplexSection(page, baseView, - shapes, xShapes, - profileObject, profileSubs)); + Gui::Control().showDialog( + new TaskDlgComplexSection(page, baseView, shapes, xShapes, profileObject, profileSubs)); } //=========================================================================== @@ -767,16 +750,15 @@ void execComplexSection(Gui::Command* cmd) DEF_STD_CMD_A(CmdTechDrawDetailView) -CmdTechDrawDetailView::CmdTechDrawDetailView() - : Command("TechDraw_DetailView") +CmdTechDrawDetailView::CmdTechDrawDetailView() : Command("TechDraw_DetailView") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Detail View"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_DetailView"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_DetailView"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Detail View"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_DetailView"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_DetailView"; } void CmdTechDrawDetailView::activated(int iMsg) @@ -787,11 +769,11 @@ void CmdTechDrawDetailView::activated(int iMsg) return; } - std::vector baseObj = getSelection(). - getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); + std::vector baseObj = + getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); if (baseObj.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least 1 DrawViewPart object as Base.")); + QObject::tr("Select at least 1 DrawViewPart object as Base.")); return; } TechDraw::DrawViewPart* dvp = static_cast(*(baseObj.begin())); @@ -816,16 +798,15 @@ bool CmdTechDrawDetailView::isActive() DEF_STD_CMD_A(CmdTechDrawProjectionGroup) -CmdTechDrawProjectionGroup::CmdTechDrawProjectionGroup() - : Command("TechDraw_ProjectionGroup") +CmdTechDrawProjectionGroup::CmdTechDrawProjectionGroup() : Command("TechDraw_ProjectionGroup") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Projection Group"); - sToolTipText = QT_TR_NOOP("Insert multiple linked views of drawable object(s)"); - sWhatsThis = "TechDraw_ProjectionGroup"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ProjectionGroup"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Projection Group"); + sToolTipText = QT_TR_NOOP("Insert multiple linked views of drawable object(s)"); + sWhatsThis = "TechDraw_ProjectionGroup"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ProjectionGroup"; } void CmdTechDrawProjectionGroup::activated(int iMsg) @@ -836,8 +817,8 @@ void CmdTechDrawProjectionGroup::activated(int iMsg) return; } std::string PageName = page->getNameInDocument(); -// auto inlist = page->getInListEx(true); -// inlist.insert(page); + // auto inlist = page->getInListEx(true); + // inlist.insert(page); //set projection direction from selected Face //use first object with a face selected @@ -845,21 +826,19 @@ void CmdTechDrawProjectionGroup::activated(int iMsg) std::vector xShapes; App::DocumentObject* partObj = nullptr; std::string faceName; - Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement; //mystery - bool single = false; //mystery - auto selection = getSelection().getSelectionEx(nullptr, - App::DocumentObject::getClassTypeId(), - resolve, - single); - for (auto& sel: selection) { + Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement;//mystery + bool single = false; //mystery + auto selection = getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), + resolve, single); + for (auto& sel : selection) { bool is_linked = false; auto obj = sel.getObject(); if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) { continue; } - if (obj->isDerivedFrom(App::LinkElement::getClassTypeId()) || - obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) || - obj->isDerivedFrom(App::Link::getClassTypeId()) ) { + if (obj->isDerivedFrom(App::LinkElement::getClassTypeId()) + || obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) + || obj->isDerivedFrom(App::Link::getClassTypeId())) { is_linked = true; } // If parent of the obj is a link to another document, we possibly need to treat non-link obj as linked, too @@ -872,9 +851,9 @@ void CmdTechDrawProjectionGroup::activated(int iMsg) continue; } // 2nd, do we really have a link to obj? - if (parent->isDerivedFrom(App::LinkElement::getClassTypeId()) || - parent->isDerivedFrom(App::LinkGroup::getClassTypeId()) || - parent->isDerivedFrom(App::Link::getClassTypeId())) { + if (parent->isDerivedFrom(App::LinkElement::getClassTypeId()) + || parent->isDerivedFrom(App::LinkGroup::getClassTypeId()) + || parent->isDerivedFrom(App::Link::getClassTypeId())) { // We have a link chain from this document to obj, and obj is in another document -> it's an XLink target is_linked = true; } @@ -898,10 +877,9 @@ void CmdTechDrawProjectionGroup::activated(int iMsg) } } } - if (shapes.empty() && - xShapes.empty()) { + if (shapes.empty() && xShapes.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No Shapes, Groups or Links in this selection")); + QObject::tr("No Shapes, Groups or Links in this selection")); return; } @@ -912,9 +890,9 @@ void CmdTechDrawProjectionGroup::activated(int iMsg) std::string multiViewName = getUniqueObjectName("ProjGroup"); doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawProjGroup', '%s')", - multiViewName.c_str()); - doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", - PageName.c_str(), multiViewName.c_str()); + multiViewName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), + multiViewName.c_str()); App::DocumentObject* docObj = getDocument()->getObject(multiViewName.c_str()); auto multiView(static_cast(docObj)); @@ -923,25 +901,34 @@ void CmdTechDrawProjectionGroup::activated(int iMsg) doCommand(Doc, "App.activeDocument().%s.addProjection('Front')", multiViewName.c_str()); if (!faceName.empty()) { - std::pair dirs = DrawGuiUtil::getProjDirFromFace(partObj, faceName); + std::pair dirs = + DrawGuiUtil::getProjDirFromFace(partObj, faceName); getDocument()->setStatus(App::Document::Status::SkipRecompute, true); - doCommand(Doc, "App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f, %.3f, %.3f)", - multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z); - doCommand(Doc, "App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f, %.3f, %.3f)", - multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); - doCommand(Doc, "App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f, %.3f, %.3f)", - multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); + doCommand(Doc, + "App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)", + multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z); + doCommand( + Doc, + "App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.12f, %.12f, %.12f)", + multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); + doCommand(Doc, + "App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.12f, %.12f, %.12f)", + multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); getDocument()->setStatus(App::Document::Status::SkipRecompute, false); } else { std::pair dirs = DrawGuiUtil::get3DDirAndRot(); getDocument()->setStatus(App::Document::Status::SkipRecompute, true); - doCommand(Doc, "App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f, %.3f, %.3f)", - multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z); - doCommand(Doc, "App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f, %.3f, %.3f)", - multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); - doCommand(Doc, "App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f, %.3f, %.3f)", + doCommand(Doc, + "App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)", + multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z); + doCommand( + Doc, + "App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.12f, %.12f, %.12f)", multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); + doCommand(Doc, + "App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.12f, %.12f, %.12f)", + multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z); getDocument()->setStatus(App::Document::Status::SkipRecompute, false); } @@ -965,7 +952,8 @@ bool CmdTechDrawProjectionGroup::isActive() //! common checks of Selection for Dimension commands //non-empty selection, no more than maxObjs selected and at least 1 DrawingPage exists -bool _checkSelectionBalloon(Gui::Command* cmd, unsigned maxObjs) { +bool _checkSelectionBalloon(Gui::Command* cmd, unsigned maxObjs) +{ std::vector selection = cmd->getSelection().getSelectionEx(); if (selection.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), @@ -976,32 +964,34 @@ bool _checkSelectionBalloon(Gui::Command* cmd, unsigned maxObjs) { const std::vector SubNames = selection[0].getSubNames(); if (SubNames.size() > maxObjs) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), - QObject::tr("Too many objects selected")); + QObject::tr("Too many objects selected")); return false; } - std::vector pages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + std::vector pages = + cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); if (pages.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), - QObject::tr("Create a page first.")); + QObject::tr("Create a page first.")); return false; } return true; } -bool _checkDrawViewPartBalloon(Gui::Command* cmd) { +bool _checkDrawViewPartBalloon(Gui::Command* cmd) +{ std::vector selection = cmd->getSelection().getSelectionEx(); auto objFeat(dynamic_cast(selection[0].getObject())); if (!objFeat) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("Incorrect selection"), - QObject::tr("No View of a Part in selection.") ); + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("No View of a Part in selection.")); return false; } return true; } -bool _checkDirectPlacement(const QGIViewPart* viewPart, const std::vector& subNames, QPointF& placement) +bool _checkDirectPlacement(const QGIViewPart* viewPart, const std::vector& subNames, + QPointF& placement) { // Let's see, if we can help speed up the placement of the balloon: // As of now we support: @@ -1018,7 +1008,8 @@ bool _checkDirectPlacement(const QGIViewPart* viewPart, const std::vector(viewPart->getViewObject())->getProjVertexByIndex(index); + TechDraw::VertexPtr vertex = + static_cast(viewPart->getViewObject())->getProjVertexByIndex(index); if (vertex) { placement = viewPart->mapToScene(Rez::guiX(vertex->x()), Rez::guiX(vertex->y())); return true; @@ -1026,7 +1017,8 @@ bool _checkDirectPlacement(const QGIViewPart* viewPart, const std::vector(viewPart->getViewObject())->getGeomByIndex(index); + TechDraw::BaseGeomPtr geo = + static_cast(viewPart->getViewObject())->getGeomByIndex(index); if (geo) { Base::Vector3d midPoint(Rez::guiX(geo->getMidPoint())); placement = viewPart->mapToScene(midPoint.x, midPoint.y); @@ -1039,16 +1031,15 @@ bool _checkDirectPlacement(const QGIViewPart* viewPart, const std::vectorgetDocument(page->getDocument()); ViewProviderPage* pageVP = dynamic_cast(guiDoc->getViewProvider(page)); - ViewProviderViewPart* partVP = dynamic_cast(guiDoc->getViewProvider(objFeat)); + ViewProviderViewPart* partVP = + dynamic_cast(guiDoc->getViewProvider(objFeat)); if (pageVP && partVP) { QGVPage* viewPage = pageVP->getQGVPage(); @@ -1085,7 +1077,8 @@ void CmdTechDrawBalloon::activated(int iMsg) QGIViewPart* viewPart = dynamic_cast(partVP->getQView()); QPointF placement; - if (viewPart && _checkDirectPlacement(viewPart, selection[0].getSubNames(), placement)) { + if (viewPart + && _checkDirectPlacement(viewPart, selection[0].getSubNames(), placement)) { scenePage->createBalloon(placement, objFeat); } } @@ -1105,16 +1098,15 @@ bool CmdTechDrawBalloon::isActive() DEF_STD_CMD_A(CmdTechDrawClipGroup) -CmdTechDrawClipGroup::CmdTechDrawClipGroup() - : Command("TechDraw_ClipGroup") +CmdTechDrawClipGroup::CmdTechDrawClipGroup() : Command("TechDraw_ClipGroup") { // setting the - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Clip Group"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ClipGroup"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ClipGroup"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Clip Group"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ClipGroup"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ClipGroup"; } void CmdTechDrawClipGroup::activated(int iMsg) @@ -1128,16 +1120,15 @@ void CmdTechDrawClipGroup::activated(int iMsg) std::string FeatName = getUniqueObjectName("Clip"); openCommand(QT_TRANSLATE_NOOP("Command", "Create Clip")); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewClip', '%s')", FeatName.c_str()); - doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewClip', '%s')", + FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), + FeatName.c_str()); updateActive(); commitCommand(); } -bool CmdTechDrawClipGroup::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawClipGroup::isActive() { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_ClipGroupAdd @@ -1145,15 +1136,14 @@ bool CmdTechDrawClipGroup::isActive() DEF_STD_CMD_A(CmdTechDrawClipGroupAdd) -CmdTechDrawClipGroupAdd::CmdTechDrawClipGroupAdd() - : Command("TechDraw_ClipGroupAdd") +CmdTechDrawClipGroupAdd::CmdTechDrawClipGroupAdd() : Command("TechDraw_ClipGroupAdd") { - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add View to Clip Group"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ClipGroupAdd"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ClipGroupAdd"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add View to Clip Group"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ClipGroupAdd"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ClipGroupAdd"; } void CmdTechDrawClipGroupAdd::activated(int iMsg) @@ -1162,7 +1152,7 @@ void CmdTechDrawClipGroupAdd::activated(int iMsg) std::vector selection = getSelection().getSelectionEx(); if (selection.size() != 2) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select one Clip group and one View.")); + QObject::tr("Select one Clip group and one View.")); return; } @@ -1179,12 +1169,12 @@ void CmdTechDrawClipGroupAdd::activated(int iMsg) } if (!view) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one View to add to group.")); + QObject::tr("Select exactly one View to add to group.")); return; } if (!clip) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one Clip group.")); + QObject::tr("Select exactly one Clip group.")); return; } @@ -1193,7 +1183,7 @@ void CmdTechDrawClipGroupAdd::activated(int iMsg) if (pageClip != pageView) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Clip and View must be from same Page.")); + QObject::tr("Clip and View must be from same Page.")); return; } @@ -1203,7 +1193,8 @@ void CmdTechDrawClipGroupAdd::activated(int iMsg) openCommand(QT_TRANSLATE_NOOP("Command", "ClipGroupAdd")); doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = False", ViewName.c_str()); - doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", ClipName.c_str(), ViewName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", ClipName.c_str(), + ViewName.c_str()); doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = True", ViewName.c_str()); updateActive(); commitCommand(); @@ -1229,15 +1220,14 @@ bool CmdTechDrawClipGroupAdd::isActive() DEF_STD_CMD_A(CmdTechDrawClipGroupRemove) -CmdTechDrawClipGroupRemove::CmdTechDrawClipGroupRemove() - : Command("TechDraw_ClipGroupRemove") +CmdTechDrawClipGroupRemove::CmdTechDrawClipGroupRemove() : Command("TechDraw_ClipGroupRemove") { - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Remove View from Clip Group"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ClipGroupRemove"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ClipGroupRemove"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Remove View from Clip Group"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ClipGroupRemove"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ClipGroupRemove"; } void CmdTechDrawClipGroupRemove::activated(int iMsg) @@ -1245,9 +1235,8 @@ void CmdTechDrawClipGroupRemove::activated(int iMsg) Q_UNUSED(iMsg); auto dObj(getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId())); if (dObj.empty()) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("Wrong selection"), - QObject::tr("Select exactly one View to remove from Group.") ); + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one View to remove from Group.")); return; } @@ -1265,9 +1254,8 @@ void CmdTechDrawClipGroupRemove::activated(int iMsg) } if (!clip) { - QMessageBox::warning(Gui::getMainWindow(), - QObject::tr("Wrong selection"), - QObject::tr("View does not belong to a Clip") ); + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("View does not belong to a Clip")); return; } @@ -1276,7 +1264,8 @@ void CmdTechDrawClipGroupRemove::activated(int iMsg) openCommand(QT_TRANSLATE_NOOP("Command", "ClipGroupRemove")); doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = False", ViewName.c_str()); - doCommand(Doc, "App.activeDocument().%s.removeView(App.activeDocument().%s)", ClipName.c_str(), ViewName.c_str()); + doCommand(Doc, "App.activeDocument().%s.removeView(App.activeDocument().%s)", ClipName.c_str(), + ViewName.c_str()); doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = True", ViewName.c_str()); updateActive(); commitCommand(); @@ -1303,16 +1292,15 @@ bool CmdTechDrawClipGroupRemove::isActive() DEF_STD_CMD_A(CmdTechDrawSymbol) -CmdTechDrawSymbol::CmdTechDrawSymbol() - : Command("TechDraw_Symbol") +CmdTechDrawSymbol::CmdTechDrawSymbol() : Command("TechDraw_Symbol") { // setting the Gui eye-candy - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert SVG Symbol"); - sToolTipText = QT_TR_NOOP("Insert symbol from an SVG file"); - sWhatsThis = "TechDraw_Symbol"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_Symbol"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert SVG Symbol"); + sToolTipText = QT_TR_NOOP("Insert symbol from an SVG file"); + sWhatsThis = "TechDraw_Symbol"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_Symbol"; } void CmdTechDrawSymbol::activated(int iMsg) @@ -1325,32 +1313,29 @@ void CmdTechDrawSymbol::activated(int iMsg) std::string PageName = page->getNameInDocument(); // Reading an image - QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), - QObject::tr("Choose an SVG file to open"), QString(), - QString::fromLatin1("%1 (*.svg *.svgz);;%2 (*.*)"). - arg(QObject::tr("Scalable Vector Graphic"), - QObject::tr("All Files"))); + QString filename = Gui::FileDialog::getOpenFileName( + Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString(), + QString::fromLatin1("%1 (*.svg *.svgz);;%2 (*.*)") + .arg(QObject::tr("Scalable Vector Graphic"), QObject::tr("All Files"))); - if (!filename.isEmpty()) - { + if (!filename.isEmpty()) { std::string FeatName = getUniqueObjectName("Symbol"); filename = Base::Tools::escapeEncodeFilename(filename); openCommand(QT_TRANSLATE_NOOP("Command", "Create Symbol")); doCommand(Doc, "f = open(\"%s\", 'r')", (const char*)filename.toUtf8()); doCommand(Doc, "svg = f.read()"); doCommand(Doc, "f.close()"); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSymbol', '%s')", FeatName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSymbol', '%s')", + FeatName.c_str()); doCommand(Doc, "App.activeDocument().%s.Symbol = svg", FeatName.c_str()); - doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), + FeatName.c_str()); updateActive(); commitCommand(); } } -bool CmdTechDrawSymbol::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawSymbol::isActive() { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_DraftView @@ -1358,16 +1343,15 @@ bool CmdTechDrawSymbol::isActive() DEF_STD_CMD_A(CmdTechDrawDraftView) -CmdTechDrawDraftView::CmdTechDrawDraftView() - : Command("TechDraw_DraftView") +CmdTechDrawDraftView::CmdTechDrawDraftView() : Command("TechDraw_DraftView") { // setting the Gui eye-candy - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Draft Workbench Object"); - sToolTipText = QT_TR_NOOP("Insert a View of a Draft Workbench object"); - sWhatsThis = "TechDraw_NewDraft"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_DraftView"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Draft Workbench Object"); + sToolTipText = QT_TR_NOOP("Insert a View of a Draft Workbench object"); + sWhatsThis = "TechDraw_NewDraft"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_DraftView"; } void CmdTechDrawDraftView::activated(int iMsg) @@ -1379,36 +1363,35 @@ void CmdTechDrawDraftView::activated(int iMsg) } std::string PageName = page->getNameInDocument(); - std::vector objects = getSelection(). - getObjectsOfType(App::DocumentObject::getClassTypeId()); + std::vector objects = + getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); if (objects.empty()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select at least one object.")); + QObject::tr("Select at least one object.")); return; } std::pair dirs = DrawGuiUtil::get3DDirAndRot(); - for (std::vector::iterator it = objects.begin(); it != objects.end(); ++it) { + for (std::vector::iterator it = objects.begin(); it != objects.end(); + ++it) { std::string FeatName = getUniqueObjectName("DraftView"); std::string SourceName = (*it)->getNameInDocument(); openCommand(QT_TRANSLATE_NOOP("Command", "Create DraftView")); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewDraft', '%s')", FeatName.c_str()); - doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", - FeatName.c_str(), SourceName.c_str()); - doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", - PageName.c_str(), FeatName.c_str()); - doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f, %.3f, %.3f)", - FeatName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewDraft', '%s')", + FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(), + SourceName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), + FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)", + FeatName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z); updateActive(); commitCommand(); } } -bool CmdTechDrawDraftView::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawDraftView::isActive() { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_ArchView @@ -1416,16 +1399,15 @@ bool CmdTechDrawDraftView::isActive() DEF_STD_CMD_A(CmdTechDrawArchView) -CmdTechDrawArchView::CmdTechDrawArchView() - : Command("TechDraw_ArchView") +CmdTechDrawArchView::CmdTechDrawArchView() : Command("TechDraw_ArchView") { // setting the Gui eye-candy - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Arch Workbench Object"); - sToolTipText = QT_TR_NOOP("Insert a View of a Section Plane from Arch Workbench"); - sWhatsThis = "TechDraw_NewArch"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ArchView"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Arch Workbench Object"); + sToolTipText = QT_TR_NOOP("Insert a View of a Section Plane from Arch Workbench"); + sWhatsThis = "TechDraw_NewArch"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ArchView"; } void CmdTechDrawArchView::activated(int iMsg) @@ -1438,8 +1420,8 @@ void CmdTechDrawArchView::activated(int iMsg) std::string PageName = page->getNameInDocument(); - const std::vector objects = getSelection(). - getObjectsOfType(App::DocumentObject::getClassTypeId()); + const std::vector objects = + getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId()); App::DocumentObject* archObject = nullptr; int archCount = 0; for (auto& obj : objects) { @@ -1450,30 +1432,30 @@ void CmdTechDrawArchView::activated(int iMsg) } if (archCount > 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Please select only 1 Arch Section.")); + QObject::tr("Please select only 1 Arch Section.")); return; } if (!archObject) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("No Arch Sections in selection.")); + QObject::tr("No Arch Sections in selection.")); return; } std::string FeatName = getUniqueObjectName("ArchView"); std::string SourceName = archObject->getNameInDocument(); openCommand(QT_TRANSLATE_NOOP("Command", "Create ArchView")); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewArch', '%s')", FeatName.c_str()); - doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(), SourceName.c_str()); - doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewArch', '%s')", + FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(), + SourceName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), + FeatName.c_str()); updateActive(); commitCommand(); } -bool CmdTechDrawArchView::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawArchView::isActive() { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_SpreadsheetView @@ -1481,25 +1463,25 @@ bool CmdTechDrawArchView::isActive() DEF_STD_CMD_A(CmdTechDrawSpreadsheetView) -CmdTechDrawSpreadsheetView::CmdTechDrawSpreadsheetView() - : Command("TechDraw_SpreadsheetView") +CmdTechDrawSpreadsheetView::CmdTechDrawSpreadsheetView() : Command("TechDraw_SpreadsheetView") { // setting the - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Spreadsheet View"); - sToolTipText = QT_TR_NOOP("Insert View to a spreadsheet"); - sWhatsThis = "TechDraw_SpreadsheetView"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_SpreadsheetView"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Spreadsheet View"); + sToolTipText = QT_TR_NOOP("Insert View to a spreadsheet"); + sWhatsThis = "TechDraw_SpreadsheetView"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_SpreadsheetView"; } void CmdTechDrawSpreadsheetView::activated(int iMsg) { Q_UNUSED(iMsg); - const std::vector spreads = getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId()); + const std::vector spreads = + getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId()); if (spreads.size() != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one Spreadsheet object.")); + QObject::tr("Select exactly one Spreadsheet object.")); return; } std::string SpreadName = spreads.front()->getNameInDocument(); @@ -1512,9 +1494,12 @@ void CmdTechDrawSpreadsheetView::activated(int iMsg) openCommand(QT_TRANSLATE_NOOP("Command", "Create spreadsheet view")); std::string FeatName = getUniqueObjectName("Sheet"); - doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet', '%s')", FeatName.c_str()); - doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(), SpreadName.c_str()); - doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str()); + doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet', '%s')", + FeatName.c_str()); + doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(), + SpreadName.c_str()); + doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), + FeatName.c_str()); updateActive(); commitCommand(); } @@ -1541,15 +1526,14 @@ bool CmdTechDrawSpreadsheetView::isActive() DEF_STD_CMD_A(CmdTechDrawExportPageSVG) -CmdTechDrawExportPageSVG::CmdTechDrawExportPageSVG() - : Command("TechDraw_ExportPageSVG") +CmdTechDrawExportPageSVG::CmdTechDrawExportPageSVG() : Command("TechDraw_ExportPageSVG") { - sGroup = QT_TR_NOOP("File"); - sMenuText = QT_TR_NOOP("Export Page as SVG"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ExportPageSVG"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ExportPageSVG"; + sGroup = QT_TR_NOOP("File"); + sMenuText = QT_TR_NOOP("Export Page as SVG"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ExportPageSVG"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ExportPageSVG"; } void CmdTechDrawExportPageSVG::activated(int iMsg) @@ -1570,15 +1554,12 @@ void CmdTechDrawExportPageSVG::activated(int iMsg) } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Drawing View"), - QObject::tr("Open Drawing View before attempting export to SVG.")); + QObject::tr("Open Drawing View before attempting export to SVG.")); return; } } -bool CmdTechDrawExportPageSVG::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawExportPageSVG::isActive() { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_ExportPageDXF @@ -1586,15 +1567,14 @@ bool CmdTechDrawExportPageSVG::isActive() DEF_STD_CMD_A(CmdTechDrawExportPageDXF) -CmdTechDrawExportPageDXF::CmdTechDrawExportPageDXF() - : Command("TechDraw_ExportPageDXF") +CmdTechDrawExportPageDXF::CmdTechDrawExportPageDXF() : Command("TechDraw_ExportPageDXF") { - sGroup = QT_TR_NOOP("File"); - sMenuText = QT_TR_NOOP("Export Page as DXF"); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ExportPageDXF"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ExportPageDXF"; + sGroup = QT_TR_NOOP("File"); + sMenuText = QT_TR_NOOP("Export Page as DXF"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ExportPageDXF"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ExportPageDXF"; } void CmdTechDrawExportPageDXF::activated(int iMsg) @@ -1608,10 +1588,10 @@ void CmdTechDrawExportPageDXF::activated(int iMsg) std::vector views = page->Views.getValues(); for (auto& v : views) { if (v->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId())) { - QMessageBox::StandardButton rc = - QMessageBox::question(Gui::getMainWindow(), QObject::tr("Can not export selection"), - QObject::tr("Page contains DrawViewArch which will not be exported. Continue?"), - QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No)); + QMessageBox::StandardButton rc = QMessageBox::question( + Gui::getMainWindow(), QObject::tr("Can not export selection"), + QObject::tr("Page contains DrawViewArch which will not be exported. Continue?"), + QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No)); if (rc == QMessageBox::No) { return; } @@ -1621,12 +1601,11 @@ void CmdTechDrawExportPageDXF::activated(int iMsg) } } -//WF? allow more than one TD Page per Dxf file?? 1 TD page = 1 DXF file = 1 drawing? + //WF? allow more than one TD Page per Dxf file?? 1 TD page = 1 DXF file = 1 drawing? QString defaultDir; - QString fileName = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), - QString::fromUtf8(QT_TR_NOOP("Save DXF file")), - defaultDir, - QString::fromUtf8(QT_TR_NOOP("DXF (*.dxf)"))); + QString fileName = Gui::FileDialog::getSaveFileName( + Gui::getMainWindow(), QString::fromUtf8(QT_TR_NOOP("Save DXF file")), defaultDir, + QString::fromUtf8(QT_TR_NOOP("DXF (*.dxf)"))); if (fileName.isEmpty()) { return; @@ -1636,15 +1615,13 @@ void CmdTechDrawExportPageDXF::activated(int iMsg) openCommand(QT_TRANSLATE_NOOP("Command", "Save page to dxf")); doCommand(Doc, "import TechDraw"); fileName = Base::Tools::escapeEncodeFilename(fileName); - doCommand(Doc, "TechDraw.writeDXFPage(App.activeDocument().%s, u\"%s\")", PageName.c_str(), (const char*)fileName.toUtf8()); + doCommand(Doc, "TechDraw.writeDXFPage(App.activeDocument().%s, u\"%s\")", PageName.c_str(), + (const char*)fileName.toUtf8()); commitCommand(); } -bool CmdTechDrawExportPageDXF::isActive() -{ - return DrawGuiUtil::needPage(this); -} +bool CmdTechDrawExportPageDXF::isActive() { return DrawGuiUtil::needPage(this); } //=========================================================================== // TechDraw_ProjectShape @@ -1652,16 +1629,15 @@ bool CmdTechDrawExportPageDXF::isActive() DEF_STD_CMD_A(CmdTechDrawProjectShape) -CmdTechDrawProjectShape::CmdTechDrawProjectShape() - : Command("TechDraw_ProjectShape") +CmdTechDrawProjectShape::CmdTechDrawProjectShape() : Command("TechDraw_ProjectShape") { - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Project shape..."); - sToolTipText = sMenuText; - sWhatsThis = "TechDraw_ProjectShape"; - sStatusTip = sToolTipText; - sPixmap = "actions/TechDraw_ProjectShape"; + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Project shape..."); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_ProjectShape"; + sStatusTip = sToolTipText; + sPixmap = "actions/TechDraw_ProjectShape"; } void CmdTechDrawProjectShape::activated(int iMsg) @@ -1673,10 +1649,7 @@ void CmdTechDrawProjectShape::activated(int iMsg) } } -bool CmdTechDrawProjectShape::isActive() -{ - return true; -} +bool CmdTechDrawProjectShape::isActive() { return true; } void CreateTechDrawCommands() { diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index 60ddcb3e28..f3bf1cf857 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp @@ -23,17 +23,17 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include -# include -# include -# include +#include +#include +#include #endif #include @@ -47,9 +47,9 @@ #include #include #include -#include -#include #include +#include +#include #include #include #include @@ -58,8 +58,8 @@ #include #include -#include "DrawGuiUtil.h" #include "DlgPageChooser.h" +#include "DrawGuiUtil.h" #include "MDIViewPage.h" #include "QGSPage.h" #include "ViewProviderPage.h" @@ -84,10 +84,9 @@ void DrawGuiUtil::loadArrowBox(QComboBox* qcb) //=========================================================================== //find a page in Selection, Document or CurrentWindow. -TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, - bool findAny) +TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, bool findAny) { -// Base::Console().Message("DGU::findPage()\n"); + // Base::Console().Message("DGU::findPage()\n"); std::vector names; std::vector labels; auto docs = App::GetApplication().getDocuments(); @@ -110,7 +109,8 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), QObject::tr("No Drawing Pages available.")); return nullptr; - } else if (foundPageObjects.size() > 1) { + } + else if (foundPageObjects.size() > 1) { //multiple pages available, ask for help for (auto obj : foundPageObjects) { std::string name = obj->getNameInDocument(); @@ -124,15 +124,16 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, App::Document* doc = cmd->getDocument(); return static_cast(doc->getObject(selName.c_str())); } - } else { + } + else { //only 1 page found - return static_cast (foundPageObjects.front()); + return static_cast(foundPageObjects.front()); } } //check Selection for a page - std::vector selPages = cmd->getSelection(). - getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + std::vector selPages = + cmd->getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); if (selPages.empty()) { //no page in selection, try this document auto docPages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); @@ -141,7 +142,8 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), QObject::tr("No Drawing Pages in document.")); return nullptr; - } else if (docPages.size() > 1) { + } + else if (docPages.size() > 1) { //multiple pages in document, use active page if there is one Gui::MainWindow* w = Gui::getMainWindow(); Gui::MDIView* mv = w->activeWindow(); @@ -149,7 +151,8 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, if (mvp) { QGSPage* qp = mvp->getViewProviderPage()->getQGSPage(); return qp->getDrawPage(); - } else { + } + else { // none of pages in document is active, ask for help for (auto obj : docPages) { std::string name = obj->getNameInDocument(); @@ -165,11 +168,13 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, } return nullptr; } - } else { + } + else { //only 1 page in document - use it return static_cast(docPages.front()); } - } else if (selPages.size() > 1) { + } + else if (selPages.size() > 1) { //multiple pages in selection for (auto obj : selPages) { std::string name = obj->getNameInDocument(); @@ -196,7 +201,8 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj) { bool result = false; - App::PropertyPythonObject* proxy = dynamic_cast(obj->getPropertyByName("Proxy")); + App::PropertyPythonObject* proxy = + dynamic_cast(obj->getPropertyByName("Proxy")); if (proxy) { //if no proxy, can not be Draft obj @@ -217,7 +223,7 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj) } } catch (Py::Exception&) { - Base::PyException e; // extract the Python error text + Base::PyException e;// extract the Python error text e.ReportException(); result = false; } @@ -228,7 +234,8 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj) bool DrawGuiUtil::isArchObject(App::DocumentObject* obj) { bool result = false; - App::PropertyPythonObject* proxy = dynamic_cast(obj->getPropertyByName("Proxy")); + App::PropertyPythonObject* proxy = + dynamic_cast(obj->getPropertyByName("Proxy")); if (proxy) { //if no proxy, can not be Arch obj @@ -247,7 +254,7 @@ bool DrawGuiUtil::isArchObject(App::DocumentObject* obj) } } catch (Py::Exception&) { - Base::PyException e; // extract the Python error text + Base::PyException e;// extract the Python error text e.ReportException(); result = false; } @@ -258,7 +265,8 @@ bool DrawGuiUtil::isArchObject(App::DocumentObject* obj) bool DrawGuiUtil::isArchSection(App::DocumentObject* obj) { bool result = false; - App::PropertyPythonObject* proxy = dynamic_cast(obj->getPropertyByName("Proxy")); + App::PropertyPythonObject* proxy = + dynamic_cast(obj->getPropertyByName("Proxy")); if (proxy) { //if no proxy, can not be Arch obj @@ -277,7 +285,7 @@ bool DrawGuiUtil::isArchSection(App::DocumentObject* obj) } } catch (Py::Exception&) { - Base::PyException e; // extract the Python error text + Base::PyException e;// extract the Python error text e.ReportException(); result = false; } @@ -285,8 +293,7 @@ bool DrawGuiUtil::isArchSection(App::DocumentObject* obj) return result; } -bool DrawGuiUtil::needPage(Gui::Command* cmd, - bool findAny) +bool DrawGuiUtil::needPage(Gui::Command* cmd, bool findAny) { if (findAny) { //look for any page in any open document @@ -296,7 +303,8 @@ bool DrawGuiUtil::needPage(Gui::Command* cmd, if (docPages.empty()) { //this open document has no TD pages continue; - } else { + } + else { //found at least 1 page return true; } @@ -343,7 +351,8 @@ void DrawGuiUtil::dumpRectF(const char* text, const QRectF& r) double right = r.right(); double top = r.top(); double bottom = r.bottom(); - Base::Console().Message("Extents: L: %.3f, R: %.3f, T: %.3f, B: %.3f\n", left, right, top, bottom); + Base::Console().Message("Extents: L: %.3f, R: %.3f, T: %.3f, B: %.3f\n", left, right, top, + bottom); Base::Console().Message("Size: W: %.3f H: %.3f\n", r.width(), r.height()); Base::Console().Message("Centre: (%.3f, %.3f)\n", r.center().x(), r.center().y()); } @@ -357,13 +366,13 @@ void DrawGuiUtil::dumpPointF(const char* text, const QPointF& p) std::pair DrawGuiUtil::get3DDirAndRot() { std::pair result; - Base::Vector3d viewDir(0.0, -1.0, 0.0); //default to front - Base::Vector3d viewUp(0.0, 0.0, 1.0); //default to top - Base::Vector3d viewRight(1.0, 0.0, 0.0); //default to right + Base::Vector3d viewDir(0.0, -1.0, 0.0); //default to front + Base::Vector3d viewUp(0.0, 0.0, 1.0); //default to top + Base::Vector3d viewRight(1.0, 0.0, 0.0);//default to right std::list mdis = Gui::Application::Instance->activeDocument()->getMDIViews(); Gui::View3DInventor* view; Gui::View3DInventorViewer* viewer = nullptr; - for (auto& m : mdis) { //find the 3D viewer + for (auto& m : mdis) {//find the 3D viewer view = dynamic_cast(m); if (view) { viewer = view->getViewer(); @@ -375,12 +384,12 @@ std::pair DrawGuiUtil::get3DDirAndRot() return std::make_pair(viewDir, viewRight); } - SbVec3f dvec = viewer->getViewDirection(); + SbVec3f dvec = viewer->getViewDirection(); SbVec3f upvec = viewer->getUpDirection(); viewDir = Base::Vector3d(dvec[0], dvec[1], dvec[2]); - viewDir = viewDir * (-1.0); // Inventor dir is opposite TD projection dir - viewUp = Base::Vector3d(upvec[0], upvec[1], upvec[2]); + viewDir = viewDir * (-1.0);// Inventor dir is opposite TD projection dir + viewUp = Base::Vector3d(upvec[0], upvec[1], upvec[2]); // Base::Vector3d dirXup = viewDir.Cross(viewUp); Base::Vector3d right = viewUp.Cross(viewDir); @@ -389,12 +398,12 @@ std::pair DrawGuiUtil::get3DDirAndRot() return result; } -std::pair DrawGuiUtil::getProjDirFromFace(App::DocumentObject* obj, std::string faceName) +std::pair DrawGuiUtil::getProjDirFromFace(App::DocumentObject* obj, + std::string faceName) { std::pair d3Dirs = get3DDirAndRot(); - Base::Vector3d d3Up = (d3Dirs.first).Cross(d3Dirs.second); std::pair dirs; - dirs.first = Base::Vector3d(0.0, 0.0, 1.0); //set a default + dirs.first = Base::Vector3d(0.0, 0.0, 1.0);//set a default dirs.second = Base::Vector3d(1.0, 0.0, 0.0); Base::Vector3d projDir, rotVec; projDir = d3Dirs.first; @@ -421,7 +430,6 @@ std::pair DrawGuiUtil::getProjDirFromFace(App::D if (props.IsNormalDefined()) { gp_Dir vec = props.Normal(); projDir = Base::Vector3d(vec.X(), vec.Y(), vec.Z()); - rotVec = projDir.Cross(d3Up); if (orient != TopAbs_FORWARD) { projDir = projDir * (-1.0); }