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