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 
24 
25 #include <QMessageBox>
26 
29 
30 #include "GraspEditorDialog.h"
31 #include <MemoryX/gui-plugins/PriorMemoryEditor/ui_ManipulationAttributesEditTab.h>
34 
35 
36 using namespace memoryx;
37 using namespace memoryx::EntityWrappers;
38 
40  armarx::RobotStateComponentInterfacePrx robotStateComponent,
41  QWidget* parent) :
44  robotStateComponent(robotStateComponent)
45 {
46  ui->setupUi(this);
47 
48  // connect radiobuttons
49  connect(ui->rbManipulationFile, SIGNAL(toggled(bool)), this, SLOT(update()));
50  connect(ui->rbIVFiles, SIGNAL(toggled(bool)), this, SLOT(update()));
51  update();
52 
53  // init manipulation file dialog
54  manipulationFileDialog = new QFileDialog(parent);
55  manipulationFileDialog->setModal(true);
56  manipulationFileDialog->setFileMode(QFileDialog::ExistingFiles);
57  manipulationFileDialog->setNameFilter(tr("Manipulation Object XML (*.xml *.moxml)"));
58  connect(ui->btnSelectManipulationFile, SIGNAL(clicked()), manipulationFileDialog, SLOT(show()));
59  connect(manipulationFileDialog, SIGNAL(accepted()), this, SLOT(manipulationFileSelected()));
60  connect(ui->btnEditGrasps, SIGNAL(clicked()), this, SLOT(editGrasps()));
61 
62  // init visualization file dialog
63  visuFileDialog = new QFileDialog(parent);
64  visuFileDialog->setModal(true);
65  visuFileDialog->setFileMode(QFileDialog::ExistingFiles);
66  visuFileDialog->setNameFilter(tr("Inventor & VRML models (*.iv *.wrl)"));
67  connect(ui->btnSelectVisuFile, SIGNAL(clicked()), visuFileDialog, SLOT(show()));
68  connect(visuFileDialog, SIGNAL(accepted()), this, SLOT(visuFileSelected()));
69 
70  // init collision file dialog
71  collisionFileDialog = new QFileDialog(parent);
72  collisionFileDialog->setModal(true);
73  collisionFileDialog->setFileMode(QFileDialog::ExistingFiles);
74  collisionFileDialog->setNameFilter(tr("Inventor & VRML models (*.iv *.wrl)"));
75  connect(ui->btnSelectCollisionFile, SIGNAL(clicked()), collisionFileDialog, SLOT(show()));
76  connect(collisionFileDialog, SIGNAL(accepted()), this, SLOT(collisionFileSelected()));
77 }
78 
80 {
81  delete ui;
82 }
83 
84 void
86 {
87  ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(entity);
88 
89  SimoxObjectWrapperPtr simoxWrapper = objectClass->getWrapper<SimoxObjectWrapper>();
90 
91  // fill dialog (with simox wrapper attributes)
92  ui->rbManipulationFile->setChecked(true);
93  ui->editManipulationFile->setText(
94  QString::fromStdString(simoxWrapper->getManipulationObjectFileName()));
95 
96  Eigen::Vector3f putdownOrientation = simoxWrapper->getPutdownOrientationRPY();
97  ui->editPutdownOrientationR->setText(QString::number(putdownOrientation(0)));
98  ui->editPutdownOrientationP->setText(QString::number(putdownOrientation(1)));
99  ui->editPutdownOrientationY->setText(QString::number(putdownOrientation(2)));
100 }
101 
102 void
103 ManipulationAttributesEditTab::updateEntity(const EntityPtr& entity, std::string filesDBName)
104 {
105  ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(entity);
106 
107  SimoxObjectWrapperPtr simoxWrapper = objectClass->getWrapper<SimoxObjectWrapper>();
108 
109  // update simox wrapper specific attributes
110  if (ui->rbManipulationFile->isChecked())
111  {
112  simoxWrapper->setAndStoreManipulationFile(ui->editManipulationFile->text().toStdString(),
113  filesDBName);
114  }
115  else
116  {
117  simoxWrapper->setAndStoreModelIVFiles(ui->editVisuFile->text().toStdString(),
118  ui->editCollisionFile->text().toStdString(),
119  filesDBName);
120  }
121 
122  Eigen::Vector3f putdownOrientation;
123  putdownOrientation(0) = std::stof(ui->editPutdownOrientationR->text().toStdString());
124  putdownOrientation(1) = std::stof(ui->editPutdownOrientationP->text().toStdString());
125  putdownOrientation(2) = std::stof(ui->editPutdownOrientationY->text().toStdString());
126  simoxWrapper->setPutdownOrientationRPY(putdownOrientation);
127 }
128 
129 void
131 {
132  ui->editManipulationFile->setText(manipulationFileDialog->selectedFiles()[0]);
133 }
134 
135 void
137 {
138  ui->editVisuFile->setText(visuFileDialog->selectedFiles()[0]);
139 }
140 
141 void
143 {
144  ui->editCollisionFile->setText(collisionFileDialog->selectedFiles()[0]);
145 }
146 
147 void
149 {
150  if (ui->editManipulationFile->text().isEmpty())
151  {
152  QMessageBox msgBox;
153  msgBox.setText("Please select a manipulation file first.");
154  msgBox.setIcon(QMessageBox::Information);
155  msgBox.setStandardButtons(QMessageBox::Ok);
156  msgBox.setDefaultButton(QMessageBox::Ok);
157  msgBox.exec();
158  }
159  else
160  {
161  std::string robotFile("/usr/local/data/robots/ArmarIII/ArmarIII.xml");
162  std::string localRobot = "RobotAPI/robots/Armar3/ArmarIII.xml";
163  armarx::CMakePackageFinder finder("RobotAPI");
164  if (armarx::ArmarXDataPath::getAbsolutePath(localRobot, localRobot, {finder.getDataDir()}))
165  {
166  robotFile = localRobot;
167  }
168 
169  if (robotStateComponent)
170  {
171  for (auto package : robotStateComponent->getArmarXPackages())
172  {
173  auto path = robotStateComponent->getRobotFilename();
174  armarx::CMakePackageFinder finder(package);
175  if (finder.packageFound())
176  {
178  path, path, {finder.getDataDir()}, false))
179  {
180  robotFile = path;
181  }
182  }
183  }
184  }
185 
186 
187  std::string objectFile(ui->editManipulationFile->text().toStdString());
188  GraspEditorDialog* dialog = new GraspEditorDialog(objectFile, robotFile, this);
189  dialog->exec();
190  }
191 }
192 
193 void
195 {
196  // update controls of object visulization and collision model
197  const bool moFile = ui->rbManipulationFile->isChecked();
198  ui->editManipulationFile->setEnabled(moFile);
199  ui->lblManipulationFile->setEnabled(moFile);
200  ui->btnSelectManipulationFile->setEnabled(moFile);
201  ui->btnEditGrasps->setEnabled(moFile);
202 
203  ui->editVisuFile->setEnabled(!moFile);
204  ui->lblVisuFile->setEnabled(!moFile);
205  ui->btnSelectVisuFile->setEnabled(!moFile);
206 
207  ui->editCollisionFile->setEnabled(!moFile);
208  ui->lblCollisionFile->setEnabled(!moFile);
209  ui->btnSelectCollisionFile->setEnabled(!moFile);
210 }
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:511
memoryx::ManipulationAttributesEditTab::update
void update()
Definition: ManipulationAttributesEditTab.cpp:194
GraspEditorDialog.h
memoryx::ManipulationAttributesEditTab::collisionFileSelected
void collisionFileSelected()
Definition: ManipulationAttributesEditTab.cpp:142
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:52
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
ObjectClass.h
memoryx::ManipulationAttributesEditTab::updateGui
void updateGui(const EntityPtr &entity) override
Pure virtual method.
Definition: ManipulationAttributesEditTab.cpp:85
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::GraspEditorDialog
Definition: GraspEditorDialog.h:38
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:194
ManipulationAttributesEditTab.h
memoryx::ManipulationAttributesEditTab::updateEntity
void updateEntity(const EntityPtr &entity, std::string filesDBName) override
Pure virtual method.
Definition: ManipulationAttributesEditTab.cpp:103
memoryx::ManipulationAttributesEditTab::~ManipulationAttributesEditTab
~ManipulationAttributesEditTab() override
Definition: ManipulationAttributesEditTab.cpp:79
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:130
CMakePackageFinder.h
SimoxObjectWrapper.h
memoryx::EntityWrappers
Definition: AbstractEntityWrapper.cpp:30
memoryx::ManipulationAttributesEditTab::visuFileSelected
void visuFileSelected()
Definition: ManipulationAttributesEditTab.cpp:136
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:109
memoryx::EntityAttributesEditTab
The entity edit dialog is a superclass for all edit dialogs used to set attributes of entites.
Definition: EntityAttributesEditTab.h:37
ArmarXDataPath.h
memoryx::ManipulationAttributesEditTab::editGrasps
void editGrasps()
Definition: ManipulationAttributesEditTab.cpp:148