ccPointPickingGenericInterface.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "ccPointPickingGenericInterface.h"
  18. //Local
  19. #include "mainwindow.h"
  20. #include "db_tree/ccDBRoot.h"
  21. //common
  22. #include <ccPickingHub.h>
  23. //qCC_db
  24. #include <ccLog.h>
  25. #include <ccPointCloud.h>
  26. //qCCC_gl
  27. #include <ccGLWindowInterface.h>
  28. ccPointPickingGenericInterface::ccPointPickingGenericInterface(ccPickingHub* pickingHub, QWidget* parent/*=nullptr*/)
  29. : ccOverlayDialog(parent)
  30. , m_pickingHub(pickingHub)
  31. {
  32. assert(m_pickingHub);
  33. }
  34. bool ccPointPickingGenericInterface::linkWith(ccGLWindowInterface* win)
  35. {
  36. if (win == m_associatedWin)
  37. {
  38. //nothing to do
  39. return false;
  40. }
  41. ccGLWindowInterface* oldWin = m_associatedWin;
  42. //just in case
  43. if (m_pickingHub)
  44. {
  45. m_pickingHub->removeListener(this);
  46. }
  47. if (!ccOverlayDialog::linkWith(win))
  48. {
  49. return false;
  50. }
  51. //if the dialog is already linked to a window, we must disconnect the 'point picked' signal
  52. if (oldWin)
  53. {
  54. oldWin->signalEmitter()->disconnect(this);
  55. }
  56. return true;
  57. }
  58. bool ccPointPickingGenericInterface::start()
  59. {
  60. if (!m_pickingHub)
  61. {
  62. ccLog::Error("[Point picking] No associated display!");
  63. return false;
  64. }
  65. //activate "point picking mode" in associated GL window
  66. if (!m_pickingHub->addListener(this, true, true, ccGLWindowInterface::POINT_PICKING))
  67. {
  68. ccLog::Error("Picking mechanism already in use. Close the tool using it first.");
  69. return false;
  70. }
  71. //the user must not close this window!
  72. m_associatedWin->setUnclosable(true);
  73. m_associatedWin->redraw(true, false);
  74. ccOverlayDialog::start();
  75. return true;
  76. }
  77. void ccPointPickingGenericInterface::stop(bool state)
  78. {
  79. if (m_pickingHub)
  80. {
  81. //deactivate "point picking mode" in all GL windows
  82. m_pickingHub->removeListener(this);
  83. if ( m_associatedWin != nullptr )
  84. {
  85. m_associatedWin->setUnclosable(false);
  86. m_associatedWin->redraw(true, false);
  87. }
  88. }
  89. ccOverlayDialog::stop(state);
  90. }
  91. void ccPointPickingGenericInterface::onItemPicked(const PickedItem& pi)
  92. {
  93. if (m_processing && pi.entity)
  94. {
  95. processPickedPoint(pi);
  96. }
  97. }