EditWidget.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // Include own headers
  2. #include "EditWidget.hpp"
  3. #include "../gui/ui_EditWidget.h"
  4. // Include modules
  5. #include "OSGWidget.hpp"
  6. #include "PickHandler.hpp"
  7. #include "TrackPointRenderer.hpp"
  8. // Include dependencies
  9. #include <QFileDialog>
  10. EditWidget::EditWidget(QWidget* parent): QWidget(parent), ui(new Ui::EditWidget) {
  11. ui->setupUi(this);
  12. ui->insertionToolButton->setCheckable(true);
  13. ui->insertionToolButton->setChecked(true);
  14. QObject::connect(ui->insertionToolButton, &QToolButton::clicked, this, [=](){ this->selectTool(InsertionTool); });
  15. ui->selectionToolButton->setCheckable(true);
  16. QObject::connect(ui->selectionToolButton, &QToolButton::clicked, this, [=](){ this->selectTool(SelectionTool); });
  17. // Modifiers
  18. QObject::connect(ui->normalModX, &QDoubleSpinBox::valueChanged, this, &EditWidget::updateNormalModifier);
  19. QObject::connect(ui->normalModY, &QDoubleSpinBox::valueChanged, this, &EditWidget::updateNormalModifier);
  20. QObject::connect(ui->normalModZ, &QDoubleSpinBox::valueChanged, this, &EditWidget::updateNormalModifier);
  21. QObject::connect(ui->modifierReset, &QPushButton::clicked, this, &EditWidget::resetNormalModifier);
  22. // OptiTrack settings
  23. QObject::connect(ui->optiTrackLength, &QDoubleSpinBox::valueChanged, this, &EditWidget::updateOptiTrackSettings);
  24. QObject::connect(ui->optiTrackRadius, &QDoubleSpinBox::valueChanged, this, &EditWidget::updateOptiTrackSettings);
  25. QObject::connect(ui->optiTrackLoadDefaults, &QPushButton::clicked, this, &EditWidget::resetOptiTrackSettings);
  26. // Export button
  27. QObject::connect(ui->exportButton, &QPushButton::clicked, this, &EditWidget::exportProject);
  28. }
  29. EditWidget::~EditWidget() {
  30. delete ui;
  31. }
  32. void EditWidget::updatePositions(osg::Vec3 point) {
  33. ui->anchorX->setText(QString::number(point.x()));
  34. ui->anchorY->setText(QString::number(point.y()));
  35. ui->anchorZ->setText(QString::number(point.z()));
  36. }
  37. void EditWidget::updateNormals(osg::Vec3 normal) {
  38. ui->normalX->setText(QString::number(normal.x()));
  39. ui->normalY->setText(QString::number(normal.y()));
  40. ui->normalZ->setText(QString::number(normal.z()));
  41. }
  42. void EditWidget::invalidatePositions() {
  43. ui->anchorX->setText("-");
  44. ui->anchorY->setText("-");
  45. ui->anchorZ->setText("-");
  46. ui->normalX->setText("-");
  47. ui->normalY->setText("-");
  48. ui->normalZ->setText("-");
  49. }
  50. ActiveTrackingSystem EditWidget::getSelectedTrackingSystem() {
  51. switch(ui->tabWidget->currentIndex()) {
  52. case 0: {
  53. return OptiTrack;
  54. }
  55. case 1: {
  56. return EMFTrack;
  57. }
  58. case 2: {
  59. return SteamVRTrack;
  60. }
  61. default: {
  62. return ActionPoints;
  63. }
  64. }
  65. }
  66. void EditWidget::setSelection(int id) {
  67. selectedPoint = id;
  68. switch(ui->tabWidget->currentIndex()) {
  69. case 0: {
  70. OptiTrackPoint* point = MainWindow::getInstance()->getStore()->getOptiTrackPoints()[id];
  71. updatePositions(point->getTranslation());
  72. updateNormals(point->getNormal());
  73. setNormalModifier(point->getNormalModifier());
  74. setOptiTrackSettings(point->getLength(), point->getRadius());
  75. break;
  76. }
  77. case 1: {
  78. break;
  79. }
  80. case 2: {
  81. break;
  82. }
  83. default: {
  84. break;
  85. }
  86. }
  87. }
  88. int EditWidget::getSelectedPoint() {
  89. return selectedPoint;
  90. }
  91. void EditWidget::showEvent(QShowEvent* event) {
  92. QWidget::showEvent(event);
  93. resetOptiTrackSettings();
  94. }
  95. void EditWidget::selectTool(Tool tool) {
  96. switch(tool) {
  97. case InsertionTool: {
  98. ui->insertionToolButton->setChecked(true);
  99. ui->selectionToolButton->setChecked(false);
  100. MainWindow::getInstance()->getOsgWidget()->getPicker()->setSelection(true);
  101. invalidatePositions();
  102. resetNormalModifier();
  103. resetOptiTrackSettings();
  104. selectedPoint = -1;
  105. break;
  106. }
  107. case SelectionTool: {
  108. ui->insertionToolButton->setChecked(false);
  109. ui->selectionToolButton->setChecked(true);
  110. MainWindow::getInstance()->getOsgWidget()->getPicker()->setSelection(false);
  111. break;
  112. }
  113. }
  114. }
  115. void EditWidget::updateNormalModifier() {
  116. osg::Vec3 modifier = osg::Vec3(ui->normalModX->value(), ui->normalModY->value(), ui->normalModZ->value());
  117. if (selectedPoint < 0) {
  118. MainWindow::getInstance()->getStore()->updateNormalModifier(modifier);
  119. MainWindow::getInstance()->getOsgWidget()->getPicker()->updateRenderer();
  120. } else {
  121. ActiveTrackingSystem activeTrackingSystem = getSelectedTrackingSystem();
  122. MainWindow::getInstance()->getStore()->getTrackPointById(selectedPoint, activeTrackingSystem)->updateNormalModifier(modifier);
  123. MainWindow::getInstance()->getOsgWidget()->getPointRenderer()->render(activeTrackingSystem);
  124. }
  125. }
  126. void EditWidget::resetNormalModifier() {
  127. osg::Vec3 modifier = osg::Vec3(0.0f, 0.0f, 0.0f);
  128. ui->normalModX->setValue(0.0f);
  129. ui->normalModY->setValue(0.0f);
  130. ui->normalModZ->setValue(0.0f);
  131. if (selectedPoint < 0) {
  132. MainWindow::getInstance()->getStore()->updateNormalModifier(modifier);
  133. MainWindow::getInstance()->getOsgWidget()->getPicker()->updateRenderer();
  134. } else {
  135. ActiveTrackingSystem activeTrackingSystem = getSelectedTrackingSystem();
  136. MainWindow::getInstance()->getStore()->getTrackPointById(selectedPoint, activeTrackingSystem)->updateNormalModifier(modifier);
  137. MainWindow::getInstance()->getOsgWidget()->getPointRenderer()->render(activeTrackingSystem);
  138. }
  139. }
  140. void EditWidget::setNormalModifier(osg::Vec3 normalModifier) {
  141. ui->normalModX->setValue(normalModifier.x());
  142. ui->normalModY->setValue(normalModifier.y());
  143. ui->normalModZ->setValue(normalModifier.z());
  144. }
  145. void EditWidget::updateOptiTrackSettings() {
  146. OptiTrackSettings settings = {ui->optiTrackLength->value(), ui->optiTrackRadius->value()};
  147. if (selectedPoint < 0) {
  148. MainWindow::getInstance()->getStore()->updateOptiTrackSettings(settings);
  149. MainWindow::getInstance()->getOsgWidget()->getPicker()->updateRenderer();
  150. } else {
  151. MainWindow::getInstance()->getStore()->getOptiTrackPoints()[selectedPoint]->updateOptiTrackSettings(settings);
  152. MainWindow::getInstance()->getOsgWidget()->getPointRenderer()->render(OptiTrack);
  153. }
  154. }
  155. void EditWidget::resetOptiTrackSettings() {
  156. OptiTrackSettings settings = {OPTITRACK_DEFAULT_LENGTH, OPTITRACK_DEFAULT_RADIUS};
  157. ui->optiTrackLength->setValue(OPTITRACK_DEFAULT_LENGTH);
  158. ui->optiTrackRadius->setValue(OPTITRACK_DEFAULT_RADIUS);
  159. if (selectedPoint < 0) {
  160. MainWindow::getInstance()->getStore()->updateOptiTrackSettings(settings);
  161. MainWindow::getInstance()->getOsgWidget()->getPicker()->updateRenderer();
  162. } else {
  163. MainWindow::getInstance()->getStore()->getOptiTrackPoints()[selectedPoint]->updateOptiTrackSettings(settings);
  164. MainWindow::getInstance()->getOsgWidget()->getPointRenderer()->render(OptiTrack);
  165. }
  166. }
  167. void EditWidget::setOptiTrackSettings(double length, double radius) {
  168. ui->optiTrackLength->setValue(length);
  169. ui->optiTrackRadius->setValue(radius);
  170. }
  171. void EditWidget::exportProject() {
  172. Qt::CheckState optiTrackSelected = ui->optiTrackCkeckbox->checkState();
  173. Qt::CheckState emfTrackSelected = ui->emfTrackCheckbox->checkState();
  174. Qt::CheckState steamVrTrackSelected = ui->steamVrCheckbox->checkState();
  175. ExportSettings settings = {optiTrackSelected == Qt::Checked, emfTrackSelected == Qt::Checked, steamVrTrackSelected == Qt::Checked};
  176. QString fileName = QFileDialog::getSaveFileName(this, tr("Export your TrackpointApp Project"), "", tr("3MF Files (*.3mf)"));
  177. std::string exportFile = fileName.toUtf8().constData();
  178. MainWindow::getInstance()->getStore()->exportProject(exportFile, settings);
  179. }