From 2a30032c7df755242040b4f88f25ead812b599cb Mon Sep 17 00:00:00 2001 From: edi271 Date: Wed, 16 Feb 2022 08:54:19 +0100 Subject: [PATCH] New extension tool: cutomize format --- src/Mod/TechDraw/Gui/CMakeLists.txt | 5 + src/Mod/TechDraw/Gui/CommandExtensionDims.cpp | 53 ++++ src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 1 + src/Mod/TechDraw/Gui/TaskCustomizeFormat.cpp | 283 ++++++++++++++++++ src/Mod/TechDraw/Gui/TaskCustomizeFormat.h | 127 ++++++++ src/Mod/TechDraw/Gui/Workbench.cpp | 3 + 6 files changed, 472 insertions(+) create mode 100644 src/Mod/TechDraw/Gui/TaskCustomizeFormat.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskCustomizeFormat.h diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 06d751d661..29d53830bf 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -68,6 +68,7 @@ set(TechDrawGui_UIC_SRCS TaskBalloon.ui TaskCosmeticLine.ui TaskSelectLineAttributes.ui + TaskCustomizeFormat.ui TaskCosVertex.ui TaskCenterLine.ui TaskDetail.ui @@ -189,6 +190,9 @@ SET(TechDrawGui_SRCS TaskSelectLineAttributes.ui TaskSelectLineAttributes.cpp TaskSelectLineAttributes.h + TaskCustomizeFormat.ui + TaskCustomizeFormat.cpp + TaskCustomizeFormat.h DrawGuiUtil.cpp DrawGuiUtil.h Rez.cpp @@ -383,6 +387,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskDetail.ui TaskCosmeticLine.ui TaskSelectLineAttributes.ui + TaskCustomizeFormat.ui TaskMoveView.ui TaskProjection.ui diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index 346423b268..2c876be7b7 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -53,6 +53,7 @@ # include # include # include +# include # include # include # include @@ -69,6 +70,7 @@ #include "TaskLinkDim.h" #include "TaskSelectLineAttributes.h" +#include "TaskCustomizeFormat.h" ///////////////////////////// #include // needed @@ -2216,6 +2218,56 @@ bool CmdTechDrawExtensionCreateLengthArc::isActive(void) return (havePage && haveView); } +//=========================================================================== +// TechDraw_ExtensionCustomizeFormat +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawExtensionCustomizeFormat) + +CmdTechDrawExtensionCustomizeFormat::CmdTechDrawExtensionCustomizeFormat() + : Command("TechDraw_ExtensionCustomizeFormat") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Customize format label"); + sToolTipText = QT_TR_NOOP("Select a dimension or a balloon\n\ + - click this tool\n\ + - edit the Format field, using the keyboard and/or the special buttons"); + sWhatsThis = "TechDraw_ExtensionCustomizeFormat"; + sStatusTip = sToolTipText; + sPixmap = "TechDraw_ExtensionCustomizeFormat"; +} + +void CmdTechDrawExtensionCustomizeFormat::activated(int iMsg) +{ + Q_UNUSED(iMsg); + Base::Console().Message("CustomizeFormat gestartet\n"); + std::vector selected; + if (!_checkSelection(this, selected, "TechDraw Customize Format")) + return; + auto object = selected[0].getObject(); + if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) || + object->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) + Gui::Control().showDialog(new TaskDlgCustomizeFormat(object)); + + /* + if (object->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) + Base::Console().Message("Bemaßung gewählt\n"); // ----------------------------------------- + if (object->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) + Base::Console().Message("Balloon gewählt\n"); // ----------------------------------------- + Gui::Control().showDialog(new TaskDlgCustomizeFormat(object)); + */ + + +} + +bool CmdTechDrawExtensionCustomizeFormat::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this); + return (havePage && haveView); +} + namespace TechDrawGui { //=========================================================================== // internal helper routines @@ -2368,4 +2420,5 @@ void CreateTechDrawCommandsExtensionDims(void) rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateHorizChamferDimension()); rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateVertChamferDimension()); rcCmdMgr.addCommand(new CmdTechDrawExtensionCreateLengthArc()); + rcCmdMgr.addCommand(new CmdTechDrawExtensionCustomizeFormat()); } diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index a827306e0e..020dab57ab 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -66,6 +66,7 @@ icons/TechDraw_ExtensionIncreaseDecimal.svg icons/TechDraw_ExtensionDecreaseDecimal.svg icons/TechDraw_ExtensionAreaAnnotation.svg + icons/TechDraw_ExtensionCustomizeFormat.svg icons/TechDraw_LengthDimension.svg icons/TechDraw_RadiusDimension.svg icons/TechDraw_Balloon.svg diff --git a/src/Mod/TechDraw/Gui/TaskCustomizeFormat.cpp b/src/Mod/TechDraw/Gui/TaskCustomizeFormat.cpp new file mode 100644 index 0000000000..3ab2e33677 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskCustomizeFormat.cpp @@ -0,0 +1,283 @@ +/*************************************************************************** + * Copyright (c) 2021 edi * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#include +#include +#include + +#endif // #ifndef _PreComp_ + +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +# include +# include +# include + +#include "DrawGuiStd.h" +#include "PreferencesGui.h" +#include "QGVPage.h" +#include "QGIView.h" +#include "QGIPrimPath.h" +#include "MDIViewPage.h" +#include "ViewProviderPage.h" +#include "ViewProviderViewPart.h" +#include "Rez.h" + +# include "TaskCustomizeFormat.h" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +//=========================================================================== +// TaskCustomizeFormat +//=========================================================================== + +TaskCustomizeFormat::TaskCustomizeFormat(App::DocumentObject * object) : + selectedObject(object), + isDimension(true), + dimRawValue(0.0), + ui(new Ui_TaskCustomizeFormat) +{ + + ui->setupUi(this); + + setUiEdit(); +} + +TaskCustomizeFormat::~TaskCustomizeFormat() +{ + +} + +void TaskCustomizeFormat::updateTask() +{ +// blockUpdate = true; + +// blockUpdate = false; +} + + +void TaskCustomizeFormat::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +void TaskCustomizeFormat::setUiEdit() +{ + setWindowTitle(tr("Customize Format")); + if (selectedObject->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) + { + auto dim = dynamic_cast(selectedObject); + isDimension = true; + std::string dimText = dim->FormatSpec.getStrValue(); + dimRawValue = dim->getDimValue(); + ui->leFormat->setText(Base::Tools::fromStdString(dimText)); + } + else + { + auto balloon = dynamic_cast(selectedObject); + isDimension = false; + std::string balloonText = balloon->Text.getStrValue(); + ui->leFormat->setText(Base::Tools::fromStdString(balloonText)); + } + // GD&T + connect(ui->pbA01, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA02, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA03, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA04, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA05, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA06, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA07, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA08, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA09, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA10, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA11, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA12, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA13, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbA14, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + // Modifiers + connect(ui->pbB01, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB02, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB03, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB04, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB05, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB06, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB07, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB08, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB09, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB10, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB11, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB12, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB13, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbB14, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + // Radius & Diameter + connect(ui->pbC01, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbC02, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbC03, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbC04, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbC05, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + // Angles + connect(ui->pbD01, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbD02, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbD03, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbD04, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + // Other + connect(ui->pbE01, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbE02, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbE03, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbE04, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbE05, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbE06, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbE07, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbE08, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbE09, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + // Greek Letters + connect(ui->pbF01, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbF02, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbF03, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbF04, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbF05, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbF06, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + connect(ui->pbF07, SIGNAL(clicked()), this, SLOT(onSymbolClicked())); + + connect(ui->leFormat, SIGNAL(textChanged(QString)), this, SLOT(onFormatChanged())); + onFormatChanged(); +} + +void TaskCustomizeFormat::onSymbolClicked() +{ + // Slot: a symbol PushButton has been clicked + QObject* senderObj(this->sender()); + QPushButton* pressedButton = dynamic_cast(senderObj); + QString pbText = pressedButton->text(); + ui->leFormat->insert(pbText); +} + +void TaskCustomizeFormat::onFormatChanged() +{ + // Slot: the LineEdit field has been changed + QString formatPreview = ui->leFormat->text(); + if (isDimension) + { + int size(80); + char buffer[size]; + std::string formatString = formatPreview.toUtf8().constData(); + size = sprintf(buffer,formatString.c_str(),dimRawValue); + formatPreview = QString::fromUtf8(buffer,size); + } + ui->lbShowPreview->setText(formatPreview); +} + +bool TaskCustomizeFormat::accept() +{ + // Slot: the OK button has been pressed + QString formatPreview = ui->leFormat->text(); + std::string formatString = formatPreview.toUtf8().constData(); + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Customize Format")); + if (isDimension) + { + auto dim = dynamic_cast(selectedObject); + dim->FormatSpec.setValue(formatString); + } + else + { + auto balloon = dynamic_cast(selectedObject); + balloon->Text.setValue(formatString); + } + Gui::Command::commitCommand(); + return true; +} + +bool TaskCustomizeFormat::reject() +{ + return true; +} + +//=========================================================================== +// TaskDlgCustomizeFormat +//=========================================================================== + +TaskDlgCustomizeFormat::TaskDlgCustomizeFormat(App::DocumentObject * object) + : TaskDialog() +{ + widget = new TaskCustomizeFormat(object); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_ExtensionCustomizeFormat"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgCustomizeFormat::~TaskDlgCustomizeFormat() +{ +} + +void TaskDlgCustomizeFormat::update() +{ +// widget->updateTask(); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgCustomizeFormat::open() +{ +} + +void TaskDlgCustomizeFormat::clicked(int) +{ +} + +bool TaskDlgCustomizeFormat::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgCustomizeFormat::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskCustomizeFormat.h b/src/Mod/TechDraw/Gui/TaskCustomizeFormat.h new file mode 100644 index 0000000000..eec40b09a3 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskCustomizeFormat.h @@ -0,0 +1,127 @@ +/*************************************************************************** + * Copyright (c) 2021 edi * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_TASKCUSTOMIZEFORMAT_H +#define TECHDRAWGUI_TASKCUSTOMIZEFORMAT_H + +#include +#include +#include +#include + +#include + +namespace App { +class DocumentObject; +} + +namespace TechDraw +{ +class DrawPage; +class DrawView; +class DrawViewPart; +class CosmeticEdge; +class LineFormat; +} + +namespace TechDraw +{ +class Face; +} + +namespace TechDrawGui +{ +class QGVPage; +class QGIView; +class QGIPrimPath; +class MDIViewPage; +class ViewProviderViewPart; +class Ui_TaskCustomizeFormat; + +class TaskCustomizeFormat : public QWidget +{ + Q_OBJECT + +public: + TaskCustomizeFormat(App::DocumentObject * object); + ~TaskCustomizeFormat(); + +public Q_SLOTS: + +public: + virtual bool accept(); + virtual bool reject(); + void updateTask(); + +private Q_SLOTS: + void onSymbolClicked(); + void onFormatChanged(); + +protected Q_SLOTS: + +protected: + void changeEvent(QEvent *e); + + void setUiEdit(void); + +private: + App::DocumentObject* selectedObject; + bool isDimension; + double dimRawValue; + std::unique_ptr ui; +}; // class TaskCustomizeFormat + +class TaskDlgCustomizeFormat : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgCustomizeFormat(App::DocumentObject * object); + ~TaskDlgCustomizeFormat(); + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual void helpRequested() { return;} + virtual bool isAllowedAlterDocument(void) const + { return false; } + void update(); + +protected: + +private: + TaskCustomizeFormat* widget; + + Gui::TaskView::TaskBox* taskbox; +}; // class TaskDlgCustomizeFormat + +} // namespace TechDrawGui + +#endif // #ifndef TECHDRAWGUI_TASKCUSTOMIZEFORMAT_H + diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 792de9b8b2..cd5a800842 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -106,6 +106,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *toolattrib << "TechDraw_ExtensionCascadeObliqueDimension"; *toolattrib << "Separator"; *toolattrib << "TechDraw_ExtensionAreaAnnotation"; + *toolattrib << "TechDraw_ExtensionCustomizeFormat"; // extension: centerlines and threading Gui::MenuItem* toolcenter = new Gui::MenuItem; @@ -280,6 +281,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const // *extattribs << "TechDraw_ExtensionCascadeVertDimension"; // *extattribs << "TechDraw_ExtensionCascadeObliqueDimension"; *extattribs << "TechDraw_ExtensionAreaAnnotation"; + *extattribs << "TechDraw_ExtensionCustomizeFormat"; Gui::ToolBarItem *extcenter = new Gui::ToolBarItem(root); extcenter->setCommand("TechDraw Centerlines"); @@ -418,6 +420,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const // *extattribs << "TechDraw_ExtensionCascadeVertDimension"; // *extattribs << "TechDraw_ExtensionCascadeObliqueDimension"; *extattribs << "TechDraw_ExtensionAreaAnnotation"; + *extattribs << "TechDraw_ExtensionCustomizeFormat"; Gui::ToolBarItem *extcenter = new Gui::ToolBarItem(root); extcenter->setCommand("TechDraw Centerlines");