ccScaleDlg.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: Daniel Girardeau-Montaut #
  15. //# #
  16. //##########################################################################
  17. #include "ccScaleDlg.h"
  18. #include "ui_scaleDlg.h"
  19. //semi persistent parameters
  20. static CCVector3d s_lastScales(1.0, 1.0, 1.0);
  21. static bool s_allAtOnce = true;
  22. static bool s_keepInPlace = false;
  23. static bool s_rescaleGlobalShift = true;
  24. ccScaleDlg::ccScaleDlg(QWidget* parent/*=nullptr*/)
  25. : QDialog(parent)
  26. , m_ui( new Ui::ScaleDialog )
  27. {
  28. m_ui->setupUi(this);
  29. connect(m_ui->sameForAllCheckBox, &QCheckBox::toggled, this, &ccScaleDlg::allDimsAtOnceToggled);
  30. connect(m_ui->fxSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &ccScaleDlg::fxUpdated);
  31. //restore semi-persistent parameters
  32. m_ui->sameForAllCheckBox->setChecked(s_allAtOnce);
  33. m_ui->keepInPlaceCheckBox->setChecked(s_keepInPlace);
  34. m_ui->rescaleGlobalShiftCheckBox->setChecked(s_rescaleGlobalShift);
  35. m_ui->fzSpinBox->setValue(s_lastScales.z);
  36. m_ui->fySpinBox->setValue(s_lastScales.y);
  37. m_ui->fxSpinBox->setValue(s_lastScales.x); //always last in case 'same for all' is checked!
  38. }
  39. ccScaleDlg::~ccScaleDlg()
  40. {
  41. delete m_ui;
  42. }
  43. void ccScaleDlg::saveState()
  44. {
  45. s_allAtOnce = m_ui->sameForAllCheckBox->isChecked();
  46. s_lastScales = getScales();
  47. s_keepInPlace = keepInPlace();
  48. s_rescaleGlobalShift = rescaleGlobalShift();
  49. }
  50. void ccScaleDlg::fxUpdated(double val)
  51. {
  52. if (m_ui->sameForAllCheckBox->isChecked())
  53. {
  54. m_ui->fySpinBox->setValue(val);
  55. m_ui->fzSpinBox->setValue(val);
  56. }
  57. }
  58. CCVector3d ccScaleDlg::getScales() const
  59. {
  60. return CCVector3d(
  61. m_ui->fxSpinBox->value(),
  62. m_ui->fySpinBox->value(),
  63. m_ui->fzSpinBox->value()
  64. );
  65. }
  66. bool ccScaleDlg::keepInPlace() const
  67. {
  68. return m_ui->keepInPlaceCheckBox->isChecked();
  69. }
  70. bool ccScaleDlg::rescaleGlobalShift() const
  71. {
  72. return m_ui->rescaleGlobalShiftCheckBox->isChecked();
  73. }
  74. void ccScaleDlg::allDimsAtOnceToggled(bool state)
  75. {
  76. if (state)
  77. {
  78. m_ui->fySpinBox->setValue(m_ui->fxSpinBox->value());
  79. m_ui->fzSpinBox->setValue(m_ui->fxSpinBox->value());
  80. }
  81. m_ui->fySpinBox->setEnabled(!state);
  82. m_ui->fzSpinBox->setEnabled(!state);
  83. }