ccPrimitiveFactoryDlg.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 "ccPrimitiveFactoryDlg.h"
  18. //local
  19. #include "mainwindow.h"
  20. #include "ccUtils.h"
  21. //qCC_db
  22. #include <ccGenericPrimitive.h>
  23. #include <ccPlane.h>
  24. #include <ccBox.h>
  25. #include <ccSphere.h>
  26. #include <ccCylinder.h>
  27. #include <ccCone.h>
  28. #include <ccTorus.h>
  29. #include <ccDish.h>
  30. #include <ccCoordinateSystem.h>
  31. //system
  32. #include <assert.h>
  33. ccPrimitiveFactoryDlg::ccPrimitiveFactoryDlg(MainWindow* win)
  34. : QDialog(win)
  35. , Ui::PrimitiveFactoryDlg()
  36. , m_win(win)
  37. {
  38. assert(m_win);
  39. setupUi(this);
  40. connect(createPushButton, &QAbstractButton::clicked, this, &ccPrimitiveFactoryDlg::createPrimitive);
  41. connect(closePushButton, &QAbstractButton::clicked, this, &QDialog::accept);
  42. connect(spherePosFromClipboardButton, &QPushButton::clicked, this, &ccPrimitiveFactoryDlg::setSpherePositionFromClipboard);
  43. connect(spherePosToOriginButton, &QPushButton::clicked, this, &ccPrimitiveFactoryDlg::setSpherePositionToOrigin);
  44. connect(csSetMatrixBasedOnSelectedObjectButton, &QPushButton::clicked, this, &ccPrimitiveFactoryDlg::setCoordinateSystemBasedOnSelectedObject);
  45. connect(csMatrixTextEdit, &QPlainTextEdit::textChanged, this, &ccPrimitiveFactoryDlg::onMatrixTextChange);
  46. connect(csClearMatrixButton, &QPushButton::clicked, this, &ccPrimitiveFactoryDlg::setCSMatrixToIdentity);
  47. setCSMatrixToIdentity();
  48. }
  49. void ccPrimitiveFactoryDlg::createPrimitive()
  50. {
  51. if (!m_win)
  52. return;
  53. ccGenericPrimitive* primitive = nullptr;
  54. switch(tabWidget->currentIndex())
  55. {
  56. //Plane
  57. case 0:
  58. {
  59. primitive = new ccPlane(static_cast<PointCoordinateType>(planeWidthDoubleSpinBox->value()),
  60. static_cast<PointCoordinateType>(planeHeightDoubleSpinBox->value()));
  61. }
  62. break;
  63. //Box
  64. case 1:
  65. {
  66. CCVector3 dims( static_cast<PointCoordinateType>(boxDxDoubleSpinBox->value()),
  67. static_cast<PointCoordinateType>(boxDyDoubleSpinBox->value()),
  68. static_cast<PointCoordinateType>(boxDzDoubleSpinBox->value()));
  69. primitive = new ccBox(dims);
  70. }
  71. break;
  72. //Sphere
  73. case 2:
  74. {
  75. ccGLMatrix transMat;
  76. transMat.setTranslation(CCVector3f(spherePosXDoubleSpinBox->value(), spherePosYDoubleSpinBox->value(), spherePosZDoubleSpinBox->value()));
  77. primitive = new ccSphere(static_cast<PointCoordinateType>(sphereRadiusDoubleSpinBox->value()), &transMat);
  78. }
  79. break;
  80. //Cylinder
  81. case 3:
  82. {
  83. primitive = new ccCylinder( static_cast<PointCoordinateType>(cylRadiusDoubleSpinBox->value()),
  84. static_cast<PointCoordinateType>(cylHeightDoubleSpinBox->value()));
  85. }
  86. break;
  87. //Cone
  88. case 4:
  89. {
  90. primitive = new ccCone( static_cast<PointCoordinateType>(coneBottomRadiusDoubleSpinBox->value()),
  91. static_cast<PointCoordinateType>(coneTopRadiusDoubleSpinBox->value()),
  92. static_cast<PointCoordinateType>(coneHeightDoubleSpinBox->value()),
  93. static_cast<PointCoordinateType>(snoutGroupBox->isChecked() ? coneXOffsetDoubleSpinBox->value() : 0),
  94. static_cast<PointCoordinateType>(snoutGroupBox->isChecked() ? coneYOffsetDoubleSpinBox->value() : 0));
  95. }
  96. break;
  97. //Torus
  98. case 5:
  99. {
  100. primitive = new ccTorus(static_cast<PointCoordinateType>(torusInsideRadiusDoubleSpinBox->value()),
  101. static_cast<PointCoordinateType>(torusOutsideRadiusDoubleSpinBox->value()),
  102. static_cast<PointCoordinateType>( CCCoreLib::DegreesToRadians( torusAngleDoubleSpinBox->value() ) ),
  103. torusRectGroupBox->isChecked(),
  104. static_cast<PointCoordinateType>(torusRectGroupBox->isChecked() ? torusRectSectionHeightDoubleSpinBox->value() : 0));
  105. }
  106. break;
  107. //Dish
  108. case 6:
  109. {
  110. primitive = new ccDish( static_cast<PointCoordinateType>(dishRadiusDoubleSpinBox->value()),
  111. static_cast<PointCoordinateType>(dishHeightDoubleSpinBox->value()),
  112. static_cast<PointCoordinateType>(dishEllipsoidGroupBox->isChecked() ? dishRadius2DoubleSpinBox->value() : 0));
  113. }
  114. break;
  115. case 7:
  116. {
  117. bool valid = false;
  118. ccGLMatrix mat = getCSMatrix(valid);
  119. if (!valid)
  120. {
  121. mat.toIdentity();
  122. }
  123. primitive = new ccCoordinateSystem(&mat);
  124. }
  125. break;
  126. }
  127. if (primitive)
  128. {
  129. primitive->setDrawingPrecision(precisionSpinBox->value());
  130. m_win->addToDB(primitive, true, true, true);
  131. }
  132. }
  133. void ccPrimitiveFactoryDlg::setSpherePositionFromClipboard()
  134. {
  135. CCVector3d vector;
  136. if (ccUtils::GetVectorFromClipboard(vector))
  137. {
  138. spherePosXDoubleSpinBox->setValue(vector.x);
  139. spherePosYDoubleSpinBox->setValue(vector.y);
  140. spherePosZDoubleSpinBox->setValue(vector.z);
  141. }
  142. }
  143. void ccPrimitiveFactoryDlg::setSpherePositionToOrigin()
  144. {
  145. spherePosXDoubleSpinBox->setValue(0);
  146. spherePosYDoubleSpinBox->setValue(0);
  147. spherePosZDoubleSpinBox->setValue(0);
  148. }
  149. void ccPrimitiveFactoryDlg::setCoordinateSystemBasedOnSelectedObject()
  150. {
  151. ccHObject::Container selectedEnt = m_win->getSelectedEntities();
  152. for (auto entity : selectedEnt)
  153. {
  154. csMatrixTextEdit->setPlainText(entity->getGLTransformationHistory().toString());
  155. }
  156. }
  157. void ccPrimitiveFactoryDlg::onMatrixTextChange()
  158. {
  159. bool valid = false;
  160. getCSMatrix(valid);
  161. if (valid)
  162. {
  163. ccLog::Print("Valid ccGLMatrix");
  164. }
  165. }
  166. void ccPrimitiveFactoryDlg::setCSMatrixToIdentity()
  167. {
  168. csMatrixTextEdit->blockSignals(true);
  169. csMatrixTextEdit->setPlainText("1.00000000 0.00000000 0.00000000 0.00000000\n0.00000000 1.00000000 0.00000000 0.00000000\n0.00000000 0.00000000 1.00000000 0.00000000\n0.00000000 0.00000000 0.00000000 1.00000000");
  170. csMatrixTextEdit->blockSignals(false);
  171. }
  172. ccGLMatrix ccPrimitiveFactoryDlg::getCSMatrix(bool& valid)
  173. {
  174. QString text = csMatrixTextEdit->toPlainText();
  175. if (text.contains("["))
  176. {
  177. //automatically remove anything between square brackets
  178. static const QRegExp squareBracketsFilter("\\[([^]]+)\\]");
  179. text.replace(squareBracketsFilter, "");
  180. csMatrixTextEdit->blockSignals(true);
  181. csMatrixTextEdit->setPlainText(text);
  182. csMatrixTextEdit->blockSignals(false);
  183. }
  184. ccGLMatrix mat = ccGLMatrix::FromString(text, valid);
  185. return mat;
  186. }