Browse Source

Add error handling (Closes #6)

Johannes Kreutz 2 years ago
parent
commit
e206f58b7c

+ 1 - 0
trackpoint-app/include/MainWindow.hpp

@@ -26,6 +26,7 @@ public:
   OSGWidget* getOsgWidget();
   ProjectStore* getStore();
   EditWidget* getEditWiget();
+  void showErrorMessage(std::string message, std::string title = "Error");
 
 protected:
   virtual void closeEvent(QCloseEvent *event);

+ 8 - 1
trackpoint-app/src/MainWindow.cpp

@@ -99,6 +99,13 @@ EditWidget* MainWindow::getEditWiget() {
   return editWidget;
 }
 
+void MainWindow::showErrorMessage(std::string message, std::string title) {
+  QMessageBox msg(this);
+  msg.setText(QString::fromUtf8(message.c_str()));
+  msg.setWindowTitle(QString::fromUtf8(title.c_str()));
+  msg.exec();
+}
+
 void MainWindow::closeEvent(QCloseEvent *event) {
   if (MainWindow::getInstance()->getStore()->isModified()) {
     if (!saveChangesPopup()) {
@@ -139,7 +146,7 @@ bool MainWindow::saveAs() {
   QString fileName = QFileDialog::getSaveFileName(this, tr("Save your TrackpointApp Project"), "", tr("TrackpointApp Projects (*.trackproj)"));
   std::string fileString = fileName.toUtf8().constData();
   if (!projectStore->saveProject(fileString)) {
-    // TODO: Show error popup
+    showErrorMessage("Something went wrong while saving the project. Please try again.", "Error saving project.");
     return false;
   }
   return true;

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

@@ -49,8 +49,7 @@ void ProjectStore::loadMesh(std::string meshFile) {
     render3MFMesh();
     MainWindow::getInstance()->renderView(Edit);
   } else {
-    // TODO: Show error popup
-    printf("Unsupported file type.\n");
+    MainWindow::getInstance()->showErrorMessage("Unsupported file type. Please use .stl or .3mf files.", "Error opening file.");
   }
 }
 
@@ -425,9 +424,7 @@ void ProjectStore::render3MFMesh() {
   Lib3MF::PMeshObjectIterator meshIterator = _project->GetMeshObjects();
   // Our use case supports just a single mesh per project
   if (meshIterator->Count() != 1) {
-    // TODO: Show error popup
-    printf("Not 1 mesh: %llu\n", meshIterator->Count());
-    return;
+    MainWindow::getInstance()->showErrorMessage("The input file contains more than one mesh. Currently, we don't support this case, so the first mesh will be used.", "Input file error.");
   }
   meshIterator->MoveNext();
   Lib3MF::PMeshObject mesh = meshIterator->GetCurrentMeshObject();
@@ -533,7 +530,7 @@ void ProjectStore::loadMetaData() {
   try {
     Lib3MF::PMetaData versionInformation = metaData->GetMetaDataByKey(META_NAMESPACE, "format");
   } catch (Lib3MF::ELib3MFException &e) {
-    // TODO: Alert not a TrackpointApp poject
+    MainWindow::getInstance()->showErrorMessage("This is not a valid TrackpointApp project.", "Error opening project file.");
   }
 
   Lib3MF::PMetaData optiTrackString;
@@ -549,7 +546,7 @@ void ProjectStore::loadMetaData() {
       _optiTrackPoints.push_back(optiTrackPoint);
     }
   } catch (Lib3MF::ELib3MFException &e) {
-    // TODO: Something is wrong with the file
+    MainWindow::getInstance()->showErrorMessage("Unable to load OptiTrack trackpoints.", "Error opening project file.");
   }
   Lib3MF::PMetaData emfTrackString;
   try {
@@ -564,7 +561,7 @@ void ProjectStore::loadMetaData() {
       _emfTrackPoints.push_back(emfTrackPoint);
     }
   } catch (Lib3MF::ELib3MFException &e) {
-    // TODO: Something is wrong with the file
+    MainWindow::getInstance()->showErrorMessage("Unable to load EMFTrack trackpoints.", "Error opening project file.");
   }
   Lib3MF::PMetaData steamVrTrackString;
   try {
@@ -579,7 +576,7 @@ void ProjectStore::loadMetaData() {
       _steamVrTrackPoints.push_back(steamVrTrackPoint);
     }
   } catch (Lib3MF::ELib3MFException &e) {
-    // TODO: Something is wrong with the file
+    MainWindow::getInstance()->showErrorMessage("Unable to load SteamVR trackpoints.", "Error opening project file.");
   }
   Lib3MF::PMetaData actionPointString;
   try {
@@ -594,7 +591,7 @@ void ProjectStore::loadMetaData() {
       _actionPoints.push_back(actionPoint);
     }
   } catch (Lib3MF::ELib3MFException &e) {
-    // TODO: Something is wrong with the file
+    MainWindow::getInstance()->showErrorMessage("Unable to load ActionPoints.", "Error opening project file.");
   }
   render3MFMesh();
   MainWindow::getInstance()->renderView(Edit);