EnvironmentController.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <QFileDialog>
6#include <QMessageBox>
7
8#include <VirtualRobot/XML/RobotIO.h>
9
14
15#include "../KinematicSolver.h"
16
17namespace armarx
18{
19 void
21 {
22 environment = std::make_shared<Environment>();
23 ARMARX_INFO << "RobotTrajectoryDesigner: EnvironmentController on init";
24 }
25
26 void
28 {
29 ARMARX_INFO << "RobotTrajectoryDesigner: EnvironmentController on connect";
30 }
31
32 void
34 {
35 ARMARX_INFO << "RobotTrajectoryDesigner: EnvironmentController on disconnect";
36 }
37
38 void
40 {
41 ARMARX_INFO << "RobotTrajectoryDesigner: EnvironmentController on exit";
42 }
43
44 void
46 {
47 std::string robotFile = "/RobotAPI/robots/Armar3/ArmarIII.xml";
48 CMakePackageFinder finder("RobotAPI");
49
50 if (finder.packageFound())
51 {
52 environment->setRobot(
53 VirtualRobot::RobotIO::loadRobot(finder.getDataDir() + robotFile));
54 }
55 else
56 {
57 ARMARX_WARNING << "ArmarX Package RobotAPI has not been found!";
58 }
59 emit environmentChanged(environment);
60 }
61
62 void
64 {
65 environment->setRobot(VirtualRobot::RobotIO::loadRobot(robotFileName));
66 emit environmentChanged(environment);
67 }
68
74
75 void
77 {
78 QMessageBox::StandardButton reply;
79 reply = QMessageBox::question(
80 0,
81 "Select robot",
82 "If you change the robot all trajectories are lost.\nDo you want to change?",
83 QMessageBox::Yes | QMessageBox::No);
84 if (reply == QMessageBox::No)
85 {
86 return;
87 }
88 QFileDialog dialog(0);
89 dialog.setFileMode(QFileDialog::ExistingFiles);
90 dialog.setAcceptMode(QFileDialog::AcceptOpen);
91 dialog.setNameFilter(tr("XML (*.xml)"));
92 QStringList fileNames;
93
94 if (dialog.exec())
95 {
96 fileNames = dialog.selectedFiles();
97 }
98 if (fileNames.length() > 1)
99 {
100 QMessageBox* toManyFilesSelected = new QMessageBox;
101 toManyFilesSelected->setWindowTitle(QString::fromStdString("Information"));
102 toManyFilesSelected->setText(QString::fromStdString(
103 "To many files selected.\nAs default the first file was taken."));
104 toManyFilesSelected->exec();
105 }
106 if (!fileNames.empty())
107 {
108 try
109 {
111 VirtualRobot::RobotIO::loadRobot(fileNames[0].toStdString());
112 environment->setRobot(robot);
113 emit environmentChanged(environment);
115 KinematicSolver::getInstance(NULL, robot);
116 }
117 catch (std::exception& e)
118 {
119 QMessageBox* selectRobotFailed = new QMessageBox;
120 selectRobotFailed->setWindowTitle(QString::fromStdString("Error Message"));
121 selectRobotFailed->setText(
122 QString::fromStdString("The selected file is not a robot xml file."));
123 selectRobotFailed->exec();
124 }
125 }
126 }
127} // namespace armarx
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
bool packageFound() const
Returns whether or not this package was found with cmake.
void environmentChanged(EnvironmentPtr environment)
notifies all controller that the environment has changed
void loadRobotFromProxy(std::string robotFileName)
loads the robot from proxy
void openRobotFileDialog()
open a file dialog to select a robot
void loadArmar3()
loads first armar3 in the application
static std::shared_ptr< KinematicSolver > getInstance(VirtualRobot::ScenePtr scenario, VirtualRobot::RobotPtr robot)
SINGLETON-FEATURES///////////////////////////////////////////////////////////////////////////////////...
static void reset()
reset Destroys the current instance of KinematicSolver that a new one can be created via call of getI...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.