24
#include "PreCompiled.h"
29
#include <Base/UnitsApi.h>
31
#include "InputVector.h"
32
#include "ui_InputVector.h"
33
#include "QuantitySpinBox.h"
38
LocationWidget::LocationWidget (QWidget * parent)
41
box = new QGridLayout();
43
xValue = new QuantitySpinBox(this);
44
xValue->setMinimum(-2.14748e+09);
45
xValue->setMaximum(2.14748e+09);
46
xLabel = new QLabel(this);
47
box->addWidget(xLabel, 0, 0, 1, 1);
48
box->addWidget(xValue, 0, 1, 1, 1);
50
yValue = new QuantitySpinBox(this);
51
yValue->setMinimum(-2.14748e+09);
52
yValue->setMaximum(2.14748e+09);
53
yLabel = new QLabel(this);
54
box->addWidget(yLabel, 1, 0, 1, 1);
55
box->addWidget(yValue, 1, 1, 1, 1);
57
zValue = new QuantitySpinBox(this);
58
zValue->setMinimum(-2.14748e+09);
59
zValue->setMaximum(2.14748e+09);
60
zLabel = new QLabel(this);
61
box->addWidget(zLabel, 2, 0, 1, 1);
62
box->addWidget(zValue, 2, 1, 1, 1);
64
dLabel = new QLabel(this);
65
dValue = new QComboBox(this);
66
dValue->setCurrentIndex(-1);
67
box->addWidget(dLabel, 3, 0, 1, 1);
68
box->addWidget(dValue, 3, 1, 1, 1);
70
xValue->setUnit(Base::Unit::Length);
71
yValue->setUnit(Base::Unit::Length);
72
zValue->setUnit(Base::Unit::Length);
74
auto gridLayout = new QGridLayout(this);
75
gridLayout->addLayout(box, 0, 0, 1, 2);
77
connect(dValue, qOverload<int>(&QComboBox::activated),
78
this, &LocationWidget::onDirectionActivated);
82
LocationWidget::~LocationWidget() = default;
84
QSize LocationWidget::sizeHint() const
89
void LocationWidget::changeEvent(QEvent* e)
91
if (e->type() == QEvent::LanguageChange) {
92
this->retranslateUi();
94
QWidget::changeEvent(e);
97
void LocationWidget::retranslateUi()
99
xLabel->setText(QApplication::translate("Gui::LocationWidget", "X:"));
100
yLabel->setText(QApplication::translate("Gui::LocationWidget", "Y:"));
101
zLabel->setText(QApplication::translate("Gui::LocationWidget", "Z:"));
102
dLabel->setText(QApplication::translate("Gui::LocationWidget", "Direction:"));
104
if (dValue->count() == 0) {
105
dValue->insertItems(0, QStringList()
106
<< QApplication::translate("Gui::LocationDialog", "X")
107
<< QApplication::translate("Gui::LocationDialog", "Y")
108
<< QApplication::translate("Gui::LocationDialog", "Z")
109
<< QApplication::translate("Gui::LocationDialog", "User defined...")
112
dValue->setCurrentIndex(2);
115
dValue->setItemData(0, QVariant::fromValue<Base::Vector3d>(Base::Vector3d(1,0,0)));
116
dValue->setItemData(1, QVariant::fromValue<Base::Vector3d>(Base::Vector3d(0,1,0)));
117
dValue->setItemData(2, QVariant::fromValue<Base::Vector3d>(Base::Vector3d(0,0,1)));
120
dValue->setItemText(0, QApplication::translate("Gui::LocationDialog", "X"));
121
dValue->setItemText(1, QApplication::translate("Gui::LocationDialog", "Y"));
122
dValue->setItemText(2, QApplication::translate("Gui::LocationDialog", "Z"));
123
dValue->setItemText(dValue->count()-1,
124
QApplication::translate("Gui::LocationDialog", "User defined..."));
128
Base::Vector3d LocationWidget::getPosition() const
130
return Base::Vector3d(this->xValue->value().getValue(),
131
this->yValue->value().getValue(),
132
this->zValue->value().getValue());
135
void LocationWidget::setPosition(const Base::Vector3d& v)
137
this->xValue->setValue(v.x);
138
this->yValue->setValue(v.y);
139
this->zValue->setValue(v.z);
142
void LocationWidget::setDirection(const Base::Vector3d& dir)
144
if (dir.Length() < Base::Vector3d::epsilon()) {
149
for (int i=0; i<dValue->count()-1; i++) {
150
QVariant data = dValue->itemData (i);
151
if (data.canConvert<Base::Vector3d>()) {
152
const auto val = data.value<Base::Vector3d>();
154
dValue->setCurrentIndex(i);
161
QString display = QString::fromLatin1("(%1,%2,%3)")
165
dValue->insertItem(dValue->count()-1, display,
166
QVariant::fromValue<Base::Vector3d>(dir));
167
dValue->setCurrentIndex(dValue->count()-2);
170
Base::Vector3d LocationWidget::getDirection() const
172
QVariant data = dValue->itemData (this->dValue->currentIndex());
173
if (data.canConvert<Base::Vector3d>()) {
174
return data.value<Base::Vector3d>();
177
return Base::Vector3d(0,0,1);
181
Base::Vector3d LocationWidget::getUserDirection(bool* ok) const
183
Gui::Dialog::Ui_InputVector iv;
184
QDialog dlg(const_cast<LocationWidget*>(this));
186
iv.vectorX->setDecimals(Base::UnitsApi::getDecimals());
187
iv.vectorY->setDecimals(Base::UnitsApi::getDecimals());
188
iv.vectorZ->setDecimals(Base::UnitsApi::getDecimals());
191
dir.x = iv.vectorX->value();
192
dir.y = iv.vectorY->value();
193
dir.z = iv.vectorZ->value();
203
void LocationWidget::onDirectionActivated(int index)
206
if (index+1 == dValue->count()) {
208
Base::Vector3d dir = this->getUserDirection(&ok);
210
if (dir.Length() < Base::Vector3d::epsilon()) {
211
QMessageBox::critical(this, LocationDialog::tr("Wrong direction"),
212
LocationDialog::tr("Direction must not be the null vector"));
223
LocationDialog::LocationDialog(QWidget* parent, Qt::WindowFlags fl)
224
: QDialog(parent, fl)
228
LocationDialog::~LocationDialog() = default;
230
Base::Vector3d LocationDialog::getUserDirection(bool* ok) const
232
Gui::Dialog::Ui_InputVector iv;
233
QDialog dlg(const_cast<LocationDialog*>(this));
235
iv.vectorX->setDecimals(Base::UnitsApi::getDecimals());
236
iv.vectorY->setDecimals(Base::UnitsApi::getDecimals());
237
iv.vectorZ->setDecimals(Base::UnitsApi::getDecimals());
240
dir.x = iv.vectorX->value();
241
dir.y = iv.vectorY->value();
242
dir.z = iv.vectorZ->value();
252
void LocationDialog::onDirectionActivated(int index)
254
directionActivated(index);
259
LocationDialogUiImp::~LocationDialogUiImp() = default;
261
Base::Vector3d LocationDialogUiImp::getDirection() const
263
return ui->getDirection();
266
Base::Vector3d LocationDialogUiImp::getPosition() const
268
return ui->getPosition();
271
void LocationDialogUiImp::changeEvent(QEvent *e)
273
if (e->type() == QEvent::LanguageChange) {
274
ui->retranslate(this);
277
QDialog::changeEvent(e);
281
void LocationDialogUiImp::directionActivated(int index)
283
ui->directionActivated(this,index);
286
#include "moc_InputVector.cpp"