ManipulationAttributesEditTab.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::MemoryX::PriorMemoryEditorPlugin
17 * @author Kai Welke (welke at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include <QMessageBox>
24 
26 #include <MemoryX/gui-plugins/PriorMemoryEditor/ui_ManipulationAttributesEditTab.h>
27 
32 
33 #include "GraspEditorDialog.h"
34 
35 
36 using namespace memoryx;
37 using namespace memoryx::EntityWrappers;
38 
40  : EntityAttributesEditTab(parent),
42  robotStateComponent(robotStateComponent)
43 {
44  ui->setupUi(this);
45 
46  // connect radiobuttons
47  connect(ui->rbManipulationFile, SIGNAL(toggled(bool)), this, SLOT(update()));
48  connect(ui->rbIVFiles, SIGNAL(toggled(bool)), this, SLOT(update()));
49  update();
50 
51  // init manipulation file dialog
52  manipulationFileDialog = new QFileDialog(parent);
53  manipulationFileDialog->setModal(true);
54  manipulationFileDialog->setFileMode(QFileDialog::ExistingFiles);
55  manipulationFileDialog->setNameFilter(tr("Manipulation Object XML (*.xml *.moxml)"));
56  connect(ui->btnSelectManipulationFile, SIGNAL(clicked()), manipulationFileDialog, SLOT(show()));
57  connect(manipulationFileDialog, SIGNAL(accepted()), this, SLOT(manipulationFileSelected()));
58  connect(ui->btnEditGrasps, SIGNAL(clicked()), this, SLOT(editGrasps()));
59 
60  // init visualization file dialog
61  visuFileDialog = new QFileDialog(parent);
62  visuFileDialog->setModal(true);
63  visuFileDialog->setFileMode(QFileDialog::ExistingFiles);
64  visuFileDialog->setNameFilter(tr("Inventor & VRML models (*.iv *.wrl)"));
65  connect(ui->btnSelectVisuFile, SIGNAL(clicked()), visuFileDialog, SLOT(show()));
66  connect(visuFileDialog, SIGNAL(accepted()), this, SLOT(visuFileSelected()));
67 
68  // init collision file dialog
69  collisionFileDialog = new QFileDialog(parent);
70  collisionFileDialog->setModal(true);
71  collisionFileDialog->setFileMode(QFileDialog::ExistingFiles);
72  collisionFileDialog->setNameFilter(tr("Inventor & VRML models (*.iv *.wrl)"));
73  connect(ui->btnSelectCollisionFile, SIGNAL(clicked()), collisionFileDialog, SLOT(show()));
74  connect(collisionFileDialog, SIGNAL(accepted()), this, SLOT(collisionFileSelected()));
75 }
76 
78 {
79  delete ui;
80 }
81 
83 {
84  ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(entity);
85 
86  SimoxObjectWrapperPtr simoxWrapper = objectClass->getWrapper<SimoxObjectWrapper>();
87 
88  // fill dialog (with simox wrapper attributes)
89  ui->rbManipulationFile->setChecked(true);
90  ui->editManipulationFile->setText(QString::fromStdString(simoxWrapper->getManipulationObjectFileName()));
91 
92  Eigen::Vector3f putdownOrientation = simoxWrapper->getPutdownOrientationRPY();
93  ui->editPutdownOrientationR->setText(QString::number(putdownOrientation(0)));
94  ui->editPutdownOrientationP->setText(QString::number(putdownOrientation(1)));
95  ui->editPutdownOrientationY->setText(QString::number(putdownOrientation(2)));
96 }
97 
98 
99 void ManipulationAttributesEditTab::updateEntity(const EntityPtr& entity, std::string filesDBName)
100 {
101  ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(entity);
102 
103  SimoxObjectWrapperPtr simoxWrapper = objectClass->getWrapper<SimoxObjectWrapper>();
104 
105  // update simox wrapper specific attributes
106  if (ui->rbManipulationFile->isChecked())
107  {
108  simoxWrapper->setAndStoreManipulationFile(ui->editManipulationFile->text().toStdString(), filesDBName);
109  }
110  else
111  {
112  simoxWrapper->setAndStoreModelIVFiles(ui->editVisuFile->text().toStdString(),
113  ui->editCollisionFile->text().toStdString(),
114  filesDBName);
115  }
116 
117  Eigen::Vector3f putdownOrientation;
118  putdownOrientation(0) = std::stof(ui->editPutdownOrientationR->text().toStdString());
119  putdownOrientation(1) = std::stof(ui->editPutdownOrientationP->text().toStdString());
120  putdownOrientation(2) = std::stof(ui->editPutdownOrientationY->text().toStdString());
121  simoxWrapper->setPutdownOrientationRPY(putdownOrientation);
122 }
123 
125 {
126  ui->editManipulationFile->setText(manipulationFileDialog->selectedFiles()[0]);
127 }
128 
130 {
131  ui->editVisuFile->setText(visuFileDialog->selectedFiles()[0]);
132 }
133 
135 {
136  ui->editCollisionFile->setText(collisionFileDialog->selectedFiles()[0]);
137 }
138 
140 {
141  if (ui->editManipulationFile->text().isEmpty())
142  {
143  QMessageBox msgBox;
144  msgBox.setText("Please select a manipulation file first.");
145  msgBox.setIcon(QMessageBox::Information);
146  msgBox.setStandardButtons(QMessageBox::Ok);
147  msgBox.setDefaultButton(QMessageBox::Ok);
148  msgBox.exec();
149  }
150  else
151  {
152  std::string robotFile("/usr/local/data/robots/ArmarIII/ArmarIII.xml");
153  std::string localRobot = "RobotAPI/robots/Armar3/ArmarIII.xml";
154  armarx::CMakePackageFinder finder("RobotAPI");
155  if (armarx::ArmarXDataPath::getAbsolutePath(localRobot, localRobot, {finder.getDataDir()}))
156  {
157  robotFile = localRobot;
158  }
159 
160  if (robotStateComponent)
161  {
162  for (auto package : robotStateComponent->getArmarXPackages())
163  {
164  auto path = robotStateComponent->getRobotFilename();
165  armarx::CMakePackageFinder finder(package);
166  if (finder.packageFound())
167  {
168  if (armarx::ArmarXDataPath::getAbsolutePath(path, path, {finder.getDataDir()}, false))
169  {
170  robotFile = path;
171  }
172 
173  }
174  }
175  }
176 
177 
178  std::string objectFile(ui->editManipulationFile->text().toStdString());
179  GraspEditorDialog* dialog = new GraspEditorDialog(objectFile, robotFile, this);
180  dialog->exec();
181  }
182 }
183 
185 {
186  // update controls of object visulization and collision model
187  const bool moFile = ui->rbManipulationFile->isChecked();
188  ui->editManipulationFile->setEnabled(moFile);
189  ui->lblManipulationFile->setEnabled(moFile);
190  ui->btnSelectManipulationFile->setEnabled(moFile);
191  ui->btnEditGrasps->setEnabled(moFile);
192 
193  ui->editVisuFile->setEnabled(!moFile);
194  ui->lblVisuFile->setEnabled(!moFile);
195  ui->btnSelectVisuFile->setEnabled(!moFile);
196 
197  ui->editCollisionFile->setEnabled(!moFile);
198  ui->lblCollisionFile->setEnabled(!moFile);
199  ui->btnSelectCollisionFile->setEnabled(!moFile);
200 
201 }
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:485
memoryx::ManipulationAttributesEditTab::update
void update()
Definition: ManipulationAttributesEditTab.cpp:184
GraspEditorDialog.h
memoryx::ManipulationAttributesEditTab::collisionFileSelected
void collisionFileSelected()
Definition: ManipulationAttributesEditTab.cpp:134
memoryx::ManipulationAttributesEditTab::ManipulationAttributesEditTab
ManipulationAttributesEditTab(armarx::RobotStateComponentInterfacePrx robotStateComponent, QWidget *parent=0)
Definition: ManipulationAttributesEditTab.cpp:39
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
ObjectClass.h
memoryx::ManipulationAttributesEditTab::updateGui
void updateGui(const EntityPtr &entity) override
Pure virtual method.
Definition: ManipulationAttributesEditTab.cpp:82
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::GraspEditorDialog
Definition: GraspEditorDialog.h:36
memoryx::ManipulationAttributesEditTab
This tab allows to change the simox attributes of an objectclass entity.
Definition: ManipulationAttributesEditTab.h:41
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:176
ManipulationAttributesEditTab.h
memoryx::ManipulationAttributesEditTab::updateEntity
void updateEntity(const EntityPtr &entity, std::string filesDBName) override
Pure virtual method.
Definition: ManipulationAttributesEditTab.cpp:99
memoryx::ManipulationAttributesEditTab::~ManipulationAttributesEditTab
~ManipulationAttributesEditTab() override
Definition: ManipulationAttributesEditTab.cpp:77
memoryx::EntityWrappers::SimoxObjectWrapper
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
Definition: SimoxObjectWrapper.h:46
memoryx::ManipulationAttributesEditTab::manipulationFileSelected
void manipulationFileSelected()
Definition: ManipulationAttributesEditTab.cpp:124
CMakePackageFinder.h
SimoxObjectWrapper.h
memoryx::EntityWrappers
Definition: AbstractEntityWrapper.cpp:28
memoryx::ManipulationAttributesEditTab::visuFileSelected
void visuFileSelected()
Definition: ManipulationAttributesEditTab.cpp:129
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::ArmarXDataPath::getAbsolutePath
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
Definition: ArmarXDataPath.cpp:111
memoryx::EntityAttributesEditTab
The entity edit dialog is a superclass for all edit dialogs used to set attributes of entites.
Definition: EntityAttributesEditTab.h:36
ArmarXDataPath.h
memoryx::ManipulationAttributesEditTab::editGrasps
void editGrasps()
Definition: ManipulationAttributesEditTab.cpp:139