ccEnvelopeExtractorDlg.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 "ccEnvelopeExtractorDlg.h"
  18. //CCCoreLib
  19. #include <CCPlatform.h>
  20. //qCC_gl
  21. #include <ccGLWindowInterface.h>
  22. //Qt
  23. #include <QCoreApplication>
  24. //system
  25. #include <assert.h>
  26. #if defined(CC_WINDOWS)
  27. #include <windows.h>
  28. #else
  29. #include <time.h>
  30. #include <unistd.h>
  31. #endif
  32. ccEnvelopeExtractorDlg::ccEnvelopeExtractorDlg(QWidget* parent/*=nullptr*/)
  33. : QDialog(parent, Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint)
  34. , Ui::EnvelopeExtractorDlg()
  35. , m_skipped(false)
  36. , m_glWindow(nullptr)
  37. {
  38. setupUi(this);
  39. }
  40. void ccEnvelopeExtractorDlg::init()
  41. {
  42. if (m_glWindow)
  43. {
  44. //already initialized
  45. assert(false);
  46. return;
  47. }
  48. connect(nextPushButton, &QAbstractButton::clicked, &m_loop, &QEventLoop::quit);
  49. connect(skipPushButton, &QAbstractButton::clicked, this, &ccEnvelopeExtractorDlg::onSkipButtonClicked);
  50. nextPushButton->setFocus();
  51. //create 3D window
  52. {
  53. QWidget* glWidget = nullptr;
  54. ccGLWindowInterface::Create(m_glWindow, glWidget, false, true);
  55. assert(m_glWindow && glWidget);
  56. ccGui::ParamStruct params = m_glWindow->getDisplayParameters();
  57. //black (text) & white (background) display by default
  58. params.backgroundCol = ccColor::white;
  59. params.textDefaultCol = ccColor::black;
  60. params.pointsDefaultCol = ccColor::black;
  61. params.drawBackgroundGradient = false;
  62. params.decimateMeshOnMove = false;
  63. params.displayCross = false;
  64. params.colorScaleUseShader = false;
  65. m_glWindow->setDisplayParameters(params, true);
  66. m_glWindow->setPerspectiveState(false, true);
  67. m_glWindow->setInteractionMode(ccGLWindowInterface::INTERACT_PAN | ccGLWindowInterface::INTERACT_ZOOM_CAMERA | ccGLWindowInterface::INTERACT_CLICKABLE_ITEMS);
  68. m_glWindow->setPickingMode(ccGLWindowInterface::NO_PICKING);
  69. m_glWindow->displayOverlayEntities(true, false);
  70. m_glWindow->setSunLight(true);
  71. m_glWindow->setCustomLight(false);
  72. viewFrame->setLayout(new QHBoxLayout);
  73. viewFrame->layout()->addWidget(glWidget);
  74. }
  75. }
  76. void ccEnvelopeExtractorDlg::zoomOn(const ccBBox& box)
  77. {
  78. if (!m_glWindow)
  79. return;
  80. double pixSize = std::max(box.getDiagVec().x / std::max(20, m_glWindow->glWidth() - 20), box.getDiagVec().y / std::max(20, m_glWindow->glHeight() - 20));
  81. CCVector3d C = box.getCenter();
  82. m_glWindow->setPivotPoint(C);
  83. m_glWindow->setCameraPos(C);
  84. m_glWindow->setCameraFocalToFitWidth(pixSize * m_glWindow->glWidth());
  85. }
  86. bool ccEnvelopeExtractorDlg::isSkipped() const
  87. {
  88. return skipPushButton->isChecked();
  89. }
  90. void ccEnvelopeExtractorDlg::addToDisplay(ccHObject* obj, bool noDependency/*=true*/)
  91. {
  92. if (m_glWindow && obj)
  93. {
  94. m_glWindow->addToOwnDB(obj,noDependency);
  95. }
  96. }
  97. void ccEnvelopeExtractorDlg::removFromDisplay(ccHObject* obj)
  98. {
  99. if (m_glWindow && obj)
  100. {
  101. m_glWindow->removeFromOwnDB(obj);
  102. }
  103. }
  104. void ccEnvelopeExtractorDlg::refresh()
  105. {
  106. if (m_skipped)
  107. return;
  108. if (m_glWindow)
  109. {
  110. m_glWindow->redraw();
  111. QCoreApplication::processEvents();
  112. }
  113. }
  114. void ccEnvelopeExtractorDlg::displayMessage(QString message, bool waitForUserConfirmation/*=false*/)
  115. {
  116. if (m_skipped)
  117. return;
  118. messageLabel->setText(message);
  119. if (waitForUserConfirmation)
  120. waitForUser(20);
  121. }
  122. void ccEnvelopeExtractorDlg::onSkipButtonClicked()
  123. {
  124. m_skipped = true;
  125. hide();
  126. QCoreApplication::processEvents();
  127. }
  128. void ccEnvelopeExtractorDlg::waitForUser(unsigned defaultDelay_ms/*=100*/)
  129. {
  130. if (m_skipped)
  131. return;
  132. if (autoCheckBox->isChecked())
  133. {
  134. //simply wait a pre-determined time
  135. #if defined(CC_WINDOWS)
  136. ::Sleep(defaultDelay_ms);
  137. #else
  138. usleep(defaultDelay_ms * 1000);
  139. #endif
  140. }
  141. else
  142. {
  143. setModal(true);
  144. //wait for the user to click on the 'Next' button
  145. m_loop.exec();
  146. setModal(false);
  147. //exec();
  148. }
  149. }