11 #include <ui_globalShiftAndScaleAboutDlg.h>
12 #include <ui_globalShiftAndScaleDlg.h>
21 #include <QPushButton>
22 #include <QStringList>
23 #include <QTextStream>
45 m_activeInfoIndex(-1),
47 m_originalDiagonal(Dg),
48 m_localPoint(0, 0, 0),
49 m_localDiagonal(-1.0),
50 m_reversedMode(false) {
69 m_activeInfoIndex(-1),
71 m_originalDiagonal(Dg),
74 m_reversedMode(true) {
96 m_ui->shiftX->setDecimals(precision);
97 m_ui->shiftY->setDecimals(precision);
98 m_ui->shiftZ->setDecimals(precision);
108 m_ui =
new Ui_GlobalShiftAndScaleDlg;
113 m_ui->shiftX->setRange(-1.0e12, 1.0e12);
114 m_ui->shiftY->setRange(-1.0e12, 1.0e12);
115 m_ui->shiftZ->setRange(-1.0e12, 1.0e12);
119 connect(
m_ui->loadComboBox, SIGNAL(currentIndexChanged(
int)),
this,
121 connect(
m_ui->moreInfoToolButton, SIGNAL(clicked()),
this,
123 connect(
m_ui->buttonBox, SIGNAL(clicked(QAbstractButton*)),
this,
124 SLOT(
onClick(QAbstractButton*)));
125 connect(
m_ui->shiftX, SIGNAL(valueChanged(
double)),
this,
127 connect(
m_ui->shiftY, SIGNAL(valueChanged(
double)),
this,
129 connect(
m_ui->shiftZ, SIGNAL(valueChanged(
double)),
this,
131 connect(
m_ui->scaleSpinBox, SIGNAL(valueChanged(
double)),
this,
133 connect(
m_ui->keepGlobalPosCheckBox, SIGNAL(toggled(
bool)),
this,
139 Ui_GlobalShiftAndScaleAboutDlg uiDlg;
153 if (!file.open(QFile::Text | QFile::ReadOnly))
return false;
157 QTextStream stream(&file);
158 unsigned lineNumber = 0;
162 QString line = stream.readLine();
163 if (line.isEmpty())
break;
166 if (line.startsWith(
"//"))
continue;
170 if (tokens.size() != 5) {
173 QString(
"[ecvShiftAndScaleCloudDlg::loadInfoFromFile] File "
174 "'%1' is malformed (5 items expected per line)")
184 info.
name = tokens[0].trimmed();
185 info.
shift.
x = tokens[1].toDouble(&ok);
187 info.
shift.
y = tokens[2].toDouble(&ok);
189 info.
shift.
z = tokens[3].toDouble(&ok);
191 info.
scale = tokens[4].toDouble(&ok);
198 "loadInfoFromFile] File '%1' is malformed "
199 "(wrong item type encountered on line %2)")
208 }
catch (
const std::bad_alloc&) {
211 QString(
"[ecvShiftAndScaleCloudDlg::loadInfoFromFile] Not "
212 "enough memory to read file '%1'")
234 qint64 ai =
static_cast<qint64
>(
a * 100.0);
235 qint64 bi =
static_cast<qint64
>(b * 100.0);
248 m_ui->xOriginLabel->setText(QString(
"x = %1").arg(P.
x, 0,
'f'));
251 : QString(
"color: purple;"));
252 m_ui->yOriginLabel->setText(QString(
"y = %1").arg(P.
y, 0,
'f'));
255 : QString(
"color: purple;"));
256 m_ui->zOriginLabel->setText(QString(
"z = %1").arg(P.
z, 0,
'f'));
259 : QString(
"color: purple;"));
261 m_ui->diagOriginLabel->setText(QString(
"diagonal = %1").arg(diag, 0,
'f'));
264 : QString(
"color: purple;"));
276 double maxCoord = std::max(fabs(localPoint.
x), fabs(localPoint.
y));
277 maxCoord = std::max(fabs(localPoint.
z), maxCoord);
278 int digitsBeforeDec =
static_cast<int>(
floor(log10(maxCoord))) + 1;
279 int prec = std::max(0, 8 - digitsBeforeDec);
281 m_ui->xDestLabel->setText(
282 QString(
"x = %1").arg(localPoint.
x, 0,
'f', prec));
283 m_ui->xDestLabel->setStyleSheet(
285 ? QString(
"color: red;")
287 m_ui->yDestLabel->setText(
288 QString(
"y = %1").arg(localPoint.
y, 0,
'f', prec));
289 m_ui->yDestLabel->setStyleSheet(
291 ? QString(
"color: red;")
293 m_ui->zDestLabel->setText(
294 QString(
"z = %1").arg(localPoint.
z, 0,
'f', prec));
295 m_ui->zDestLabel->setStyleSheet(
297 ? QString(
"color: red;")
300 m_ui->diagDestLabel->setText(
301 QString(
"diagonal = %1").arg(localDiagonal, 0,
'f', prec));
302 m_ui->diagDestLabel->setStyleSheet(
304 ? QString(
"color: red;")
309 m_ui->shiftX->setValue(shift.
x);
310 m_ui->shiftY->setValue(shift.
y);
311 m_ui->shiftZ->setValue(shift.
z);
316 m_ui->shiftZ->value());
320 m_ui->scaleSpinBox->setValue(scale);
324 return m_ui->scaleSpinBox->value();
328 m_ui->diagOriginLabel->setVisible(state);
329 m_ui->diagDestLabel->setVisible(state);
334 m_ui->buttonBox->button(QDialogButtonBox::YesToAll)->setVisible(state);
338 m_ui->buttonBox->button(QDialogButtonBox::Yes)->setVisible(state);
342 m_ui->buttonBox->button(QDialogButtonBox::No)->setVisible(state);
346 m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setVisible(state);
350 m_ui->warningLabel->setVisible(state);
354 m_ui->titleFrame->setVisible(state);
358 m_ui->keepGlobalPosCheckBox->setVisible(state);
362 m_ui->preserveShiftOnSaveCheckBox->setVisible(state);
366 return m_ui->preserveShiftOnSaveCheckBox->isChecked();
370 m_ui->preserveShiftOnSaveCheckBox->setChecked(state);
374 return m_ui->keepGlobalPosCheckBox->isChecked();
378 m_ui->keepGlobalPosCheckBox->setChecked(state);
383 m_ui->smallCubeFrame->setLineWidth(state ? 2 : 1);
384 m_ui->bigCubeFrame->setLineWidth(state ? 1 : 2);
392 (button ==
m_ui->buttonBox->button(QDialogButtonBox::YesToAll));
393 m_cancel = (button ==
m_ui->buttonBox->button(QDialogButtonBox::Cancel));
397 if (index < 0 || index >=
static_cast<int>(
m_defaultInfos.size()))
return;
413 if (index >= 0 && index <
static_cast<int>(
m_defaultInfos.size())) {
414 m_ui->loadComboBox->setCurrentIndex(index);
422 }
catch (
const std::bad_alloc&) {
434 const std::vector<ecvGlobalShiftManager::ShiftInfo>& infos) {
Vector3Tpl< double > CCVector3d
Double 3D Vector.
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool NeedShift(const CCVector3d &P)
Returns whether a particular point (coordinates) is too big or not.
static bool NeedRescale(double d)
Returns whether a particular dimension (e.g. diagonal) is too big or not.
bool preserveShiftOnSave() const
Returns whether the global shift should be preserved or not.
void showApplyButton(bool state)
Whether to show the 'Apply' button or not.
void init()
Initialization routine.
ecvShiftAndScaleCloudDlg(const CCVector3d &Pg, double Dg=0, QWidget *parent=0)
Default constructor.
void setPreserveShiftOnSave(bool state)
Sets whether the global shift should be preserved or not.
void showNoButton(bool state)
Whether to show the 'No' button or not.
void setScale(double scale)
Sets displayed scale.
bool loadInfoFromFile(QString filename)
Tries to load ShiftInfo data from a (text) file.
CCVector3d getShift() const
Returns shift.
void onGlobalPosCheckBoxToggled(bool)
Slot called when the 'Keep global position' checkbox is toggled.
void setShift(const CCVector3d &shift)
Sets displayed shift.
void setKeepGlobalPos(bool state)
Sets whether the global position should be preserved or not.
void setCurrentProfile(int index)
Sets the current combo-box entry (profile)
virtual ~ecvShiftAndScaleCloudDlg()
Destructor.
void showWarning(bool state)
Whether to show or not the warning about non pertinent shift information.
int addShiftInfo(const ecvGlobalShiftManager::ShiftInfo &info)
Adds shift info to the combox.
bool m_applyAll
Whether shift should be applied to all files.
CCVector3d m_localPoint
Local coordinate system point (reversed mode only)
void showApplyAllButton(bool state)
Whether to show the 'Apply all' button or not.
bool m_cancel
Whether the user has clicked on Cancel or not.
void showKeepGlobalPosCheckbox(bool state)
Whether to show or not the 'Keep global position' checkbox.
void showScaleItems(bool state)
Whether to show dialog items related to scale.
std::vector< ecvGlobalShiftManager::ShiftInfo > m_defaultInfos
Default infos (typically loaded from the global_shift_list.txt' file)
void onLoadIndexChanged(int)
Slot called when the 'loadComboBox' index changes.
void updateGlobalAndLocalSystems()
Updates info on the global and local coordinate systems.
double m_originalDiagonal
Original coordinate system diagonal.
void showCancelButton(bool state)
Whether to show the 'Cancel' button or not.
void showTitle(bool state)
Whether to show or not the title.
bool addFileInfo()
Adds information from default file (if any)
void displayMoreInfo()
Displays more info about global shift mechanism.
void setShiftFieldsPrecision(int precision)
Sets the Shift fields (X, Y and Z) precision (default should be 2)
bool keepGlobalPos() const
Returns whether the global position should be preserved or not.
double m_localDiagonal
Local coordinate system diagonal (reversed mode only)
void onClick(QAbstractButton *button)
Analyzes the clicked button.
bool m_reversedMode
Whether the reverse mode is active or not.
void showPreserveShiftOnSave(bool state)
Whether to show or not the 'Preserve shift on save' checkbox.
double getScale() const
Returns scale.
bool getInfo(size_t index, ecvGlobalShiftManager::ShiftInfo &info) const
Returns a given input info.
Ui_GlobalShiftAndScaleDlg * m_ui
Associated UI.
void updateLocalSystem()
Updates info on the local coordinate system.
CCVector3d m_originalPoint
Original coordinate system point.
void updateGlobalSystem()
Updates info on the global coordinate system.
static QString s_defaultGlobalShiftListFilename("global_shift_list.txt")
bool AlmostEq(double a, double b)
constexpr Qt::SplitBehavior SkipEmptyParts
MiniVec< float, N > floor(const MiniVec< float, N > &a)