New extension tool: cutomize format

This commit is contained in:
edi271
2022-02-16 08:54:19 +01:00
committed by WandererFan
parent 281e18a353
commit 2a30032c7d
6 changed files with 472 additions and 0 deletions

View File

@@ -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

View File

@@ -53,6 +53,7 @@
# include <Mod/TechDraw/App/DrawProjGroupItem.h>
# include <Mod/TechDraw/App/DrawProjGroup.h>
# include <Mod/TechDraw/App/DrawViewDimension.h>
# include <Mod/TechDraw/App/DrawViewBalloon.h>
# include <Mod/TechDraw/App/DrawDimHelper.h>
# include <Mod/TechDraw/App/LandmarkDimension.h>
# include <Mod/TechDraw/App/DrawPage.h>
@@ -69,6 +70,7 @@
#include "TaskLinkDim.h"
#include "TaskSelectLineAttributes.h"
#include "TaskCustomizeFormat.h"
/////////////////////////////
#include <Mod/TechDraw/App/DrawViewSection.h> // 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<Gui::SelectionObject> 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());
}

View File

@@ -66,6 +66,7 @@
<file>icons/TechDraw_ExtensionIncreaseDecimal.svg</file>
<file>icons/TechDraw_ExtensionDecreaseDecimal.svg</file>
<file>icons/TechDraw_ExtensionAreaAnnotation.svg</file>
<file>icons/TechDraw_ExtensionCustomizeFormat.svg</file>
<file>icons/TechDraw_LengthDimension.svg</file>
<file>icons/TechDraw_RadiusDimension.svg</file>
<file>icons/TechDraw_Balloon.svg</file>

View File

@@ -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 <cmath>
#include <BRepBndLib.hxx>
#include <Bnd_Box.hxx>
#endif // #ifndef _PreComp_
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <QButtonGroup>
#include <QStatusBar>
#include <QGraphicsScene>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/Selection.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
# include <Mod/TechDraw/App/DrawViewDimension.h>
# include <Mod/TechDraw/App/DrawViewBalloon.h>
# include <Mod/TechDraw/Gui/ui_TaskCustomizeFormat.h>
#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<TechDraw::DrawViewDimension*>(selectedObject);
isDimension = true;
std::string dimText = dim->FormatSpec.getStrValue();
dimRawValue = dim->getDimValue();
ui->leFormat->setText(Base::Tools::fromStdString(dimText));
}
else
{
auto balloon = dynamic_cast<TechDraw::DrawViewBalloon*>(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<QPushButton*>(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<TechDraw::DrawViewDimension*>(selectedObject);
dim->FormatSpec.setValue(formatString);
}
else
{
auto balloon = dynamic_cast<TechDraw::DrawViewBalloon*>(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 <Mod/TechDraw/Gui/moc_TaskCustomizeFormat.cpp>

View File

@@ -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 <App/DocumentObject.h>
#include <Base/Vector3D.h>
#include <Gui/TaskView/TaskView.h>
#include <Gui/TaskView/TaskDialog.h>
#include <Mod/TechDraw/App/Cosmetic.h>
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_TaskCustomizeFormat> 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

View File

@@ -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");