Forráskód Böngészése

Fix action point identifiers (Closes #20)

Johannes Kreutz 2 éve
szülő
commit
02dae834de

+ 1 - 1
trackpoint-app/include/EditWidget.hpp

@@ -24,6 +24,7 @@ public:
   void setSelection(int id);
   int getSelectedPoint();
   void updateTrackpointCount();
+  void resetActionPointSettings();
 
 protected:
   virtual void showEvent(QShowEvent* event);
@@ -42,7 +43,6 @@ private slots:
   void resetSteamVRTrackSettings();
   void setSteamVRTrackSettings(double length);
   void updateActionPointSettings(QString input);
-  void resetActionPointSettings();
   void setActionPointSettings(std::string identifier);
   void deleteCurrentTrackPoint();
   void exportProject();

+ 1 - 1
trackpoint-app/include/ProjectStore.hpp

@@ -67,7 +67,7 @@ public:
   // Return Action point settings
   ActionPointSettings getActionPointSettings();
   // Check if an identifier is already in use
-  bool actionPointIdentifierInUse(std::string candidate);
+  unsigned int actionPointIdentifierInUse(std::string candidate, int current);
 
 private:
   bool _projectLoaded;

+ 6 - 5
trackpoint-app/src/EditWidget.cpp

@@ -283,7 +283,7 @@ void EditWidget::setSteamVRTrackSettings(double length) {
 
 void EditWidget::updateActionPointSettings(QString qinput) {
   std::string input = qinput.toUtf8().constData();
-  if (MainWindow::getInstance()->getStore()->actionPointIdentifierInUse(input)) {
+  if (MainWindow::getInstance()->getStore()->actionPointIdentifierInUse(input, selectedPoint) > 0) {
     ui->actionPointDoubleIdentifier->setVisible(true);
   } else {
     ui->actionPointDoubleIdentifier->setVisible(false);
@@ -304,11 +304,12 @@ void EditWidget::resetActionPointSettings() {
   while (true) {
     candidate = "point";
     candidate += std::to_string(iterator);
-    bool result = MainWindow::getInstance()->getStore()->actionPointIdentifierInUse(candidate);
-    if (!result) {
+    unsigned int result = MainWindow::getInstance()->getStore()->actionPointIdentifierInUse(candidate, selectedPoint);
+    if (result == 0) {
       settings = {candidate};
       break;
     }
+    iterator++;
   }
   ui->actionPointIdentifier->setText(QString::fromStdString(candidate));
   if (selectedPoint < 0) {
@@ -319,11 +320,11 @@ void EditWidget::resetActionPointSettings() {
 }
 
 void EditWidget::setActionPointSettings(std::string identifier) {
-  if (MainWindow::getInstance()->getStore()->actionPointIdentifierInUse(identifier)) {
+  ui->actionPointIdentifier->setText(QString::fromStdString(identifier));
+  if (MainWindow::getInstance()->getStore()->actionPointIdentifierInUse(identifier, selectedPoint) > 0) {
     ui->actionPointDoubleIdentifier->setVisible(true);
   } else {
     ui->actionPointDoubleIdentifier->setVisible(false);
-    ui->actionPointIdentifier->setText(QString::fromStdString(identifier));
   }
 }
 

+ 4 - 1
trackpoint-app/src/PickHandler.cpp

@@ -207,7 +207,10 @@ void PickHandler::setVisibility(bool mode) {
 void PickHandler::addPoint(osg::Vec3 point, osg::Vec3 normal) {
   ActiveTrackingSystem activeTrackingSystem = MainWindow::getInstance()->getEditWiget()->getSelectedTrackingSystem();
   MainWindow::getInstance()->getStore()->addTrackPoint(point, normal, activeTrackingSystem);
-  _osgWidget->getPointRenderer()->render(MainWindow::getInstance()->getEditWiget()->getSelectedTrackingSystem());
+  _osgWidget->getPointRenderer()->render(activeTrackingSystem);
+  if (activeTrackingSystem == ActionPoints) {
+    MainWindow::getInstance()->getEditWiget()->resetActionPointSettings();
+  }
 }
 
 void PickHandler::invalidateTrackPointColors() {

+ 7 - 4
trackpoint-app/src/ProjectStore.cpp

@@ -276,13 +276,16 @@ ActionPointSettings ProjectStore::getActionPointSettings() {
   return _actionPointSettings;
 }
 
-bool ProjectStore::actionPointIdentifierInUse(std::string candidate) {
+unsigned int ProjectStore::actionPointIdentifierInUse(std::string candidate, int current) {
+  unsigned int count = 0;
+  int i = 0;
   for (ActionPoint* actionPoint: _actionPoints) {
-    if (candidate.compare(actionPoint->getIdentifier()) != 0) {
-      return true;
+    if (i != current && candidate.compare(actionPoint->getIdentifier()) == 0) {
+      count++;
     }
+    i++;
   }
-  return false;
+  return count;
 }
 
 void ProjectStore::load3mfLib() {