ImportDialogController.cpp
Go to the documentation of this file.
2 #include <QFile>
3 #include <QFileDialog>
4 #include <QMessageBox>
5 
6 namespace armarx
7 {
9  {
10  ARMARX_INFO << "RobotTrajectoryDesigner: ExportDialogController on init";
11  }
12 
14  {
15  ARMARX_INFO << "RobotTrajectoryDesigner: ExportDialogController on connect";
16  }
17 
19  {
20 
21  ARMARX_INFO << "RobotTrajectoryDesigner: ExportDialogController on disconnect";
22  }
23 
25  {
26  ARMARX_INFO << "RobotTrajectoryDesigner: ExportDialogController on exit";
27  }
28 
30  {
33  }
34 
36  {
37  if (environment == NULL)
38  {
39  return;
40  }
41  QFileDialog dialog(0);
42  dialog.setFileMode(QFileDialog::ExistingFiles);
43  dialog.setAcceptMode(QFileDialog::AcceptOpen);
44  dialog.setNameFilter(tr("XML (*.xml)"));
45  QStringList fileNames;
46  if (dialog.exec())
47  {
48  fileNames = dialog.selectedFiles();
49  }
50  if (fileNames.length() > 1)
51  {
52  QMessageBox* toManyFilesSelected = new QMessageBox;
53  toManyFilesSelected->setWindowTitle(QString::fromStdString("Information"));
54  toManyFilesSelected->setText(QString::fromStdString("To many files selected.\nAs default the first file was taken."));
55  toManyFilesSelected->exec();
56  }
57  if (!fileNames.empty())
58  {
59  try
60  {
61  MMMImporterPtr mmmImporter = std::make_shared<MMMImporter>(environment);
62  std::vector<DesignerTrajectoryPtr> trajectories = mmmImporter->importTrajectory(fileNames[0].toStdString());
63  if (!trajectories.empty())
64  {
65  for (DesignerTrajectoryPtr trajectory : trajectories)
66  {
67  emit import(trajectory);
68  }
69  }
70  else
71  {
72  helpExceptionMessageBox("Import failed.");
73  }
74  }
75  catch (InvalidArgumentException e)
76  {
77  helpExceptionMessageBox(e.reason);
78  }
79  catch (std::exception e)
80  {
81  helpExceptionMessageBox("Could not import MMM file");
82  }
83  }
84  }
85 
87  {
88  this->environment = environment;
89  }
90 
91  void ImportDialogController::helpExceptionMessageBox(std::string errorMessage)
92  {
93  QMessageBox* errorMessageBox = new QMessageBox;
94  errorMessageBox->setWindowTitle(QString::fromStdString("Error Message"));
95  errorMessageBox->setText(QString::fromStdString(errorMessage));
96  errorMessageBox->exec();
97  }
98 }
ImportDialogController.h
armarx::ImportDialogController::onExitComponent
void onExitComponent() override
Definition: ImportDialogController.cpp:24
armarx::ImportDialogController::onConnectComponent
void onConnectComponent() override
Definition: ImportDialogController.cpp:13
armarx::EnvironmentPtr
std::shared_ptr< Environment > EnvironmentPtr
Definition: Environment.h:29
armarx::ImportDialogController::onInitComponent
void onInitComponent() override
Definition: ImportDialogController.cpp:8
armarx::MMMImporterPtr
std::shared_ptr< MMMImporter > MMMImporterPtr
Definition: MMMImporter.h:48
armarx::ImportDialogController::open
void open()
Opens an import dialog.
Definition: ImportDialogController.cpp:35
armarx::ImportDialogController::ImportDialogController
ImportDialogController()
Creates a new ImportDialogController and assigns a designer importer to handle.
Definition: ImportDialogController.cpp:29
armarx::ImportDialogController::environmentChanged
void environmentChanged(EnvironmentPtr environment)
Set the enviroment.
Definition: ImportDialogController.cpp:86
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::DesignerTrajectoryPtr
std::shared_ptr< DesignerTrajectory > DesignerTrajectoryPtr
Definition: DesignerTrajectory.h:165
armarx::ImportDialogController::onDisconnectComponent
void onDisconnectComponent() override
Definition: ImportDialogController.cpp:18
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28