ccOrderChoiceDlg.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #include "ccOrderChoiceDlg.h"
  18. //common
  19. #include <ccQtHelpers.h>
  20. //qCC_plugins
  21. #include <ccMainAppInterface.h>
  22. //qCC_db
  23. #include <ccHObject.h>
  24. //Qt
  25. #include <QMainWindow>
  26. //ui template
  27. #include <ui_roleChoiceDlg.h>
  28. ccOrderChoiceDlg::ccOrderChoiceDlg( ccHObject* firstEntity,
  29. QString firstRole,
  30. ccHObject* secondEntity,
  31. QString secondRole,
  32. ccMainAppInterface* app/*=nullptr*/)
  33. : QDialog(app ? app->getMainWindow() : nullptr, Qt::Tool)
  34. , m_gui(new Ui_RoleChoiceDialog)
  35. , m_app(app)
  36. , m_firstEnt(firstEntity)
  37. , m_secondEnt(secondEntity)
  38. , m_useInputOrder(true)
  39. {
  40. m_gui->setupUi(this);
  41. connect(m_gui->swapButton, &QAbstractButton::clicked, this, &ccOrderChoiceDlg::swap);
  42. m_gui->firstlabel->setText(firstRole);
  43. m_gui->secondlabel->setText(secondRole);
  44. ccQtHelpers::SetButtonColor(m_gui->firstColorButton, Qt::red);
  45. ccQtHelpers::SetButtonColor(m_gui->secondColorButton, Qt::yellow);
  46. setColorsAndLabels();
  47. }
  48. ccOrderChoiceDlg::~ccOrderChoiceDlg()
  49. {
  50. if (m_firstEnt)
  51. {
  52. m_firstEnt->enableTempColor(false);
  53. m_firstEnt->prepareDisplayForRefresh_recursive();
  54. }
  55. if (m_secondEnt)
  56. {
  57. m_secondEnt->enableTempColor(false);
  58. m_secondEnt->prepareDisplayForRefresh_recursive();
  59. }
  60. if (m_app)
  61. {
  62. m_app->refreshAll();
  63. }
  64. if (m_gui)
  65. {
  66. delete m_gui;
  67. m_gui = nullptr;
  68. }
  69. }
  70. ccHObject* ccOrderChoiceDlg::getFirstEntity()
  71. {
  72. return m_useInputOrder ? m_firstEnt : m_secondEnt;
  73. }
  74. ccHObject* ccOrderChoiceDlg::getSecondEntity()
  75. {
  76. return m_useInputOrder ? m_secondEnt : m_firstEnt;
  77. }
  78. void ccOrderChoiceDlg::setColorsAndLabels()
  79. {
  80. ccHObject* o1 = getFirstEntity();
  81. if (o1)
  82. {
  83. m_gui->firstLineEdit->setText(o1->getName());
  84. o1->setEnabled(true);
  85. o1->setVisible(true);
  86. o1->setTempColor(ccColor::red);
  87. o1->prepareDisplayForRefresh_recursive();
  88. }
  89. else
  90. {
  91. m_gui->firstLineEdit->setText("No entity!");
  92. }
  93. ccHObject* o2 = getSecondEntity();
  94. if (o2)
  95. {
  96. m_gui->secondLineEdit->setText(o2->getName());
  97. o2->setEnabled(true);
  98. o2->setVisible(true);
  99. o2->setTempColor(ccColor::yellow);
  100. o2->prepareDisplayForRefresh_recursive();
  101. }
  102. else
  103. {
  104. m_gui->secondLineEdit->setText("No entity!");
  105. }
  106. if (m_app)
  107. m_app->refreshAll();
  108. }
  109. void ccOrderChoiceDlg::swap()
  110. {
  111. m_useInputOrder = !m_useInputOrder;
  112. setColorsAndLabels();
  113. }