GCC Code Coverage Report


Directory: ./
File: src/gui/dialog/dialogloadrobot.cc
Date: 2024-12-20 15:53:58
Exec Total Coverage
Lines: 0 30 0.0%
Branches: 0 64 0.0%

Line Branch Exec Source
1 // Copyright (c) 2015-2018, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16
17 #include "gepetto/gui/dialog/dialogloadrobot.hh"
18
19 #include <QDir>
20 #include <QFileDialog>
21 #include <QMessageBox>
22
23 #include "ui_dialogloadrobot.h"
24
25 namespace gepetto {
26 namespace gui {
27 QStringList DialogLoadRobot::rootJointTypes = QStringList() << "freeflyer"
28 << "planar"
29 << "anchor";
30
31 QList<DialogLoadRobot::RobotDefinition> DialogLoadRobot::definitions =
32 QList<DialogLoadRobot::RobotDefinition>()
33 << DialogLoadRobot::RobotDefinition();
34
35 DialogLoadRobot::DialogLoadRobot(QWidget *parent)
36 : QDialog(parent), ui_(new ::Ui::DialogLoadRobot) {
37 ui_->setupUi(this);
38 ui_->groupBox_details->setVisible(false);
39
40 ui_->rootJointType->addItems(rootJointTypes);
41 defs_ = ui_->comboBox_defs;
42
43 foreach (RobotDefinition r, definitions) {
44 defs_->addItem(r.name_, QVariant::fromValue(r));
45 }
46 }
47
48 DialogLoadRobot::~DialogLoadRobot() { delete ui_; }
49
50 void DialogLoadRobot::addRobotDefinition(QString name, QString robotName,
51 QString rootJointType,
52 QString modelName, QString package,
53 QString urdfSuffix,
54 QString srdfSuffix) {
55 definitions.append(RobotDefinition(name, robotName, rootJointType, modelName,
56 package, urdfSuffix, srdfSuffix));
57 }
58
59 QList<DialogLoadRobot::RobotDefinition> DialogLoadRobot::getRobotDefinitions() {
60 return definitions;
61 }
62
63 void DialogLoadRobot::accept() {
64 /* TODO use the urdfParser::getFilename to check if the package exists
65 QDir d (ui_->packagePath->text ());
66 if (!d.cd("urdf")) {
67 QMessageBox (QMessageBox::Warning, "Directory not found", d.absolutePath(),
68 QMessageBox::Ok, this).exec(); return;
69 }
70 if (!d.exists(ui_->modelName->text () + ui_->urdfSuffix->text () + ".urdf")) {
71 QMessageBox (QMessageBox::Warning, "File not found",
72 d.absoluteFilePath(ui_->modelName->text () + ui_->urdfSuffix->text () +
73 ".urdf"), QMessageBox::Ok, this).exec(); return;
74 }
75 if (!QDir (ui_->meshDirectory->text ()).exists()) {
76 QMessageBox (QMessageBox::Warning, "File not found",
77 ui_->meshDirectory->text (), QMessageBox::Ok, this).exec(); return;
78 }*/
79 selected_ = RobotDefinition(defs_->currentText(), ui_->robotName->text(),
80 ui_->rootJointType->currentText(),
81 ui_->modelName->text(), ui_->packageName->text(),
82 ui_->urdfSuffix->text(), ui_->srdfSuffix->text());
83 done(QDialog::Accepted);
84 }
85
86 void DialogLoadRobot::robotSelect(int index) {
87 QVariant v = defs_->itemData(index);
88 if (v.canConvert<RobotDefinition>()) {
89 RobotDefinition rd = v.value<RobotDefinition>();
90 ui_->robotName->setText(rd.robotName_);
91 ui_->modelName->setText(rd.modelName_);
92 if (rootJointTypes.contains(rd.rootJointType_))
93 ui_->rootJointType->setCurrentIndex(
94 rootJointTypes.indexOf(rd.rootJointType_));
95 ui_->packageName->setText(rd.package_);
96 ui_->urdfSuffix->setText(rd.urdfSuf_);
97 ui_->srdfSuffix->setText(rd.srdfSuf_);
98 }
99 }
100 } // namespace gui
101 } // namespace gepetto
102