From 8d1e1e4072cf409a57f7833bc93d4c0250e8bc76 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 10 Jan 2020 21:19:36 +0100 Subject: [PATCH] Gui: [skip ci] rename Location classes --- src/Gui/InputVector.h | 100 ++++++++++++++---------- src/Gui/Placement.h | 2 +- src/Gui/Transform.h | 2 +- src/Mod/Part/Gui/CommandSimple.cpp | 9 +-- src/Mod/Part/Gui/DlgPartBoxImp.cpp | 2 +- src/Mod/Part/Gui/DlgPartBoxImp.h | 2 +- src/Mod/Part/Gui/DlgPartCylinderImp.cpp | 14 +++- src/Mod/Part/Gui/DlgPartCylinderImp.h | 5 +- src/Mod/Part/Gui/DlgRevolution.h | 1 - 9 files changed, 81 insertions(+), 56 deletions(-) diff --git a/src/Gui/InputVector.h b/src/Gui/InputVector.h index 0eb23d2bed..c579e035a1 100644 --- a/src/Gui/InputVector.h +++ b/src/Gui/InputVector.h @@ -72,7 +72,7 @@ private: QComboBox *dValue; }; -/** This is the base dialog class that defines the interface for +/** This is the abstract base dialog class that defines the interface for * specifying a direction vector by the user. * @author Werner Mayer */ @@ -104,22 +104,22 @@ private: * The template argument can be the Ui interface class built by uic out of a * .ui file. * This class might be very useful for dialogs where a combo box is used to - * define a direction vector by the user. For such classes the programmer don't - * to write a subclass to implement the appropriate signals/slots. Instead it's - * possible to omit this further class and use LocationInterface parametrized + * define a direction vector by the user. For such classes the programmer doesn't + * have to write a subclass to implement the appropriate signals/slots. Instead it's + * possible to omit this further class and use LocationDialogUi parametrized * with the generated Ui class. * @author Werner Mayer */ template -class LocationInterface : public LocationDialog, public Ui +class LocationDialogUi : public LocationDialog, public Ui { public: - LocationInterface(QWidget* parent = 0, Qt::WindowFlags fl = 0) : LocationDialog(parent, fl) + LocationDialogUi(QWidget* parent = 0, Qt::WindowFlags fl = 0) : LocationDialog(parent, fl) { this->setupUi(this); this->retranslate(); } - virtual ~LocationInterface(){} + virtual ~LocationDialogUi(){} void retranslate() { @@ -149,6 +149,13 @@ public: } } + void setPosition(const Base::Vector3d& v) + { + this->xPos->setValue(v.x); + this->yPos->setValue(v.y); + this->zPos->setValue(v.z); + } + Base::Vector3d getPosition() const { return Base::Vector3d(this->xPos->value().getValue(), @@ -179,6 +186,33 @@ protected: } private: + void setDirection(const Base::Vector3d& dir) + { + if (dir.Length() < Base::Vector3d::epsilon()) { + return; + } + + // check if the user-defined direction is already there + for (int i=0; idirection->count()-1; i++) { + QVariant data = this->direction->itemData (i); + if (data.canConvert()) { + const Base::Vector3d val = data.value(); + if (val == dir) { + this->direction->setCurrentIndex(i); + return; + } + } + } + + // add a new item before the very last item + QString display = QString::fromLatin1("(%1,%2,%3)") + .arg(dir.x) + .arg(dir.y) + .arg(dir.z); + this->direction->insertItem(this->direction->count()-1, display, + QVariant::fromValue(dir)); + this->direction->setCurrentIndex(this->direction->count()-2); + } void directionActivated(int index) { // last item is selected to define direction by user @@ -192,49 +226,29 @@ private: return; } - // check if the user-defined direction is already there - for (int i=0; idirection->count()-1; i++) { - QVariant data = this->direction->itemData (i); - if (data.canConvert()) { - const Base::Vector3d val = data.value(); - if (val == dir) { - this->direction->setCurrentIndex(i); - return; - } - } - } - - // add a new item before the very last item - QString display = QString::fromLatin1("(%1,%2,%3)") - .arg(dir.x) - .arg(dir.y) - .arg(dir.z); - this->direction->insertItem(this->direction->count()-1, display, - QVariant::fromValue(dir)); - this->direction->setCurrentIndex(this->direction->count()-2); + setDirection(dir); } } } }; -/** This template class does basically the same as LocationInterface unless - * that the Ui class is used as composition not as further base class. - * This class acts as a small wrapper class around the UI_-generated classes - * by Qt for which the location interface is needed. This class can be used - * as composition in dialog-based classes without including the ui_-generated - * header file. The Ui_-class can simply be forward declared. +/** This template class does basically the same as LocationDialogUi unless + * that it doesn inherit from a widget but only from the UI_-generated class. + * Thus, this class can be used as composition in dialog-based classes without + * including the ui_-generated header file. The Ui_-class can simply be forward + * declared, then. * @author Werner Mayer */ template -class LocationInterfaceComp : public Ui +class LocationUi : public Ui { public: - LocationInterfaceComp(QDialog *dlg) + LocationUi(QDialog *dlg) { this->setupUi(dlg); this->retranslate(dlg); } - ~LocationInterfaceComp() + ~LocationUi() { } @@ -338,23 +352,23 @@ public: } }; -/** This template class is a subclass of LocationDialog using LocationInterfaceComp - * which implements the pure virtual method directionActivated(). +/** This template class is a subclass of LocationDialog using LocationUi + * and implements the pure virtual methods of its base class. * Other dialog-based classes can directly inherit from this class if the * location-interface is required. But note, in this case the ui_-header file - * needs to be included. If this should be avoided the class LocationInterfaceComp + * needs to be included. If this should be avoided the class LocationUi * must be used instead of whereas the Ui_-class can be forward declared. * @author Werner Mayer */ template -class LocationDialogComp : public LocationDialog +class LocationDialogImp : public LocationDialog { public: - LocationDialogComp(QWidget* parent = 0, Qt::WindowFlags fl = 0) + LocationDialogImp(QWidget* parent = 0, Qt::WindowFlags fl = 0) : LocationDialog(parent, fl), ui(this) { } - virtual ~LocationDialogComp() + virtual ~LocationDialogImp() { // no need to delete child widgets, Qt does it all for us } @@ -382,7 +396,7 @@ private: } protected: - LocationInterfaceComp ui; + LocationUi ui; }; } // namespace Gui diff --git a/src/Gui/Placement.h b/src/Gui/Placement.h index bac88324db..d7122d8aff 100644 --- a/src/Gui/Placement.h +++ b/src/Gui/Placement.h @@ -89,7 +89,7 @@ Q_SIGNALS: void directionChanged(); private: - typedef Gui::LocationInterfaceComp Ui_PlacementComp; + typedef Gui::LocationUi Ui_PlacementComp; typedef boost::signals2::connection Connection; Ui_PlacementComp* ui; QSignalMapper* signalMapper; diff --git a/src/Gui/Transform.h b/src/Gui/Transform.h index f73b1a9059..3c1ef3090e 100644 --- a/src/Gui/Transform.h +++ b/src/Gui/Transform.h @@ -96,7 +96,7 @@ Q_SIGNALS: void directionChanged(); private: - typedef Gui::LocationInterfaceComp Ui_TransformComp; + typedef Gui::LocationUi Ui_TransformComp; Ui_TransformComp* ui; Base::Placement pm; std::set selection; diff --git a/src/Mod/Part/Gui/CommandSimple.cpp b/src/Mod/Part/Gui/CommandSimple.cpp index 8cdc1ca85c..c9aab39b26 100644 --- a/src/Mod/Part/Gui/CommandSimple.cpp +++ b/src/Mod/Part/Gui/CommandSimple.cpp @@ -68,6 +68,7 @@ void CmdPartSimpleCylinder::activated(int iMsg) PartGui::DlgPartCylinderImp dlg(Gui::getMainWindow()); if (dlg.exec()== QDialog::Accepted) { Base::Vector3d dir = dlg.getDirection(); + Base::Vector3d pos = dlg.getPosition(); openCommand("Create Part Cylinder"); doCommand(Doc,"from FreeCAD import Base"); doCommand(Doc,"import Part"); @@ -75,11 +76,9 @@ void CmdPartSimpleCylinder::activated(int iMsg) ".Shape=Part.makeCylinder(%f,%f," "Base.Vector(%f,%f,%f)," "Base.Vector(%f,%f,%f))" - ,dlg.radius->value().getValue() - ,dlg.length->value().getValue() - ,dlg.xPos->value().getValue() - ,dlg.yPos->value().getValue() - ,dlg.zPos->value().getValue() + ,dlg.getRadius() + ,dlg.getLength() + ,pos.x,pos.y,pos.z ,dir.x,dir.y,dir.z); commitCommand(); updateActive(); diff --git a/src/Mod/Part/Gui/DlgPartBoxImp.cpp b/src/Mod/Part/Gui/DlgPartBoxImp.cpp index 594527f7db..ea1443253b 100644 --- a/src/Mod/Part/Gui/DlgPartBoxImp.cpp +++ b/src/Mod/Part/Gui/DlgPartBoxImp.cpp @@ -37,7 +37,7 @@ using namespace PartGui; * true to construct a modal dialog. */ DlgPartBoxImp::DlgPartBoxImp(QWidget* parent, Qt::WindowFlags fl) - : Gui::LocationInterface(parent, fl) + : Gui::LocationDialogUi(parent, fl) { } diff --git a/src/Mod/Part/Gui/DlgPartBoxImp.h b/src/Mod/Part/Gui/DlgPartBoxImp.h index cb6673825d..2ff4fd5b42 100644 --- a/src/Mod/Part/Gui/DlgPartBoxImp.h +++ b/src/Mod/Part/Gui/DlgPartBoxImp.h @@ -28,7 +28,7 @@ namespace PartGui { -class DlgPartBoxImp : public Gui::LocationInterface +class DlgPartBoxImp : public Gui::LocationDialogUi { Q_OBJECT diff --git a/src/Mod/Part/Gui/DlgPartCylinderImp.cpp b/src/Mod/Part/Gui/DlgPartCylinderImp.cpp index 306d876eeb..ce3053f479 100644 --- a/src/Mod/Part/Gui/DlgPartCylinderImp.cpp +++ b/src/Mod/Part/Gui/DlgPartCylinderImp.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" -#ifndef _PreComp_ +#ifndef _PreComp_ #endif #include "DlgPartCylinderImp.h" @@ -37,7 +37,7 @@ using namespace PartGui; * true to construct a modal dialog. */ DlgPartCylinderImp::DlgPartCylinderImp(QWidget* parent, Qt::WindowFlags fl) - : Gui::LocationInterface(parent, fl) + : Gui::LocationDialogUi(parent, fl) { } @@ -49,4 +49,14 @@ DlgPartCylinderImp::~DlgPartCylinderImp() // no need to delete child widgets, Qt does it all for us } +double DlgPartCylinderImp::getRadius() const +{ + return this->radius->value().getValue(); +} + +double DlgPartCylinderImp::getLength() const +{ + return this->length->value().getValue(); +} + #include "moc_DlgPartCylinderImp.cpp" diff --git a/src/Mod/Part/Gui/DlgPartCylinderImp.h b/src/Mod/Part/Gui/DlgPartCylinderImp.h index 2208254039..64660e933d 100644 --- a/src/Mod/Part/Gui/DlgPartCylinderImp.h +++ b/src/Mod/Part/Gui/DlgPartCylinderImp.h @@ -28,13 +28,16 @@ namespace PartGui { -class DlgPartCylinderImp : public Gui::LocationInterface +class DlgPartCylinderImp : public Gui::LocationDialogUi { Q_OBJECT public: DlgPartCylinderImp(QWidget* parent = 0, Qt::WindowFlags fl = 0); ~DlgPartCylinderImp(); + + double getRadius() const; + double getLength() const; }; } // namespace PartGui diff --git a/src/Mod/Part/Gui/DlgRevolution.h b/src/Mod/Part/Gui/DlgRevolution.h index 2c0fcbcb82..c05c98fa1e 100644 --- a/src/Mod/Part/Gui/DlgRevolution.h +++ b/src/Mod/Part/Gui/DlgRevolution.h @@ -76,7 +76,6 @@ private: void autoSolid(); private: - //typedef Gui::LocationInterfaceComp Ui_RevolutionComp; Ui_DlgRevolution* ui; class EdgeSelection; EdgeSelection* filter;