GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/gui/dialog/dialogloadrobot.cc Lines: 0 30 0.0 %
Date: 2024-04-14 11:13:22 Branches: 0 70 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 =
28
    QStringList() << "freeflyer" << "planar" << "anchor";
29
30
QList<DialogLoadRobot::RobotDefinition> DialogLoadRobot::definitions =
31
    QList<DialogLoadRobot::RobotDefinition>()
32
    << DialogLoadRobot::RobotDefinition();
33
34
DialogLoadRobot::DialogLoadRobot(QWidget *parent)
35
    : QDialog(parent), ui_(new ::Ui::DialogLoadRobot) {
36
  ui_->setupUi(this);
37
  ui_->groupBox_details->setVisible(false);
38
39
  ui_->rootJointType->addItems(rootJointTypes);
40
  defs_ = ui_->comboBox_defs;
41
42
  foreach (RobotDefinition r, definitions) {
43
    defs_->addItem(r.name_, QVariant::fromValue(r));
44
  }
45
}
46
47
DialogLoadRobot::~DialogLoadRobot() { delete ui_; }
48
49
void DialogLoadRobot::addRobotDefinition(QString name, QString robotName,
50
                                         QString rootJointType,
51
                                         QString modelName, QString package,
52
                                         QString urdfSuffix,
53
                                         QString srdfSuffix) {
54
  definitions.append(RobotDefinition(name, robotName, rootJointType, modelName,
55
                                     package, urdfSuffix, srdfSuffix));
56
}
57
58
QList<DialogLoadRobot::RobotDefinition> DialogLoadRobot::getRobotDefinitions() {
59
  return definitions;
60
}
61
62
void DialogLoadRobot::accept() {
63
  /* TODO use the urdfParser::getFilename to check if the package exists
64
  QDir d (ui_->packagePath->text ());
65
  if (!d.cd("urdf")) {
66
    QMessageBox (QMessageBox::Warning, "Directory not found", d.absolutePath(),
67
  QMessageBox::Ok, this).exec(); return;
68
  }
69
  if (!d.exists(ui_->modelName->text () + ui_->urdfSuffix->text () + ".urdf")) {
70
    QMessageBox (QMessageBox::Warning, "File not found",
71
  d.absoluteFilePath(ui_->modelName->text () + ui_->urdfSuffix->text () +
72
  ".urdf"), QMessageBox::Ok, this).exec(); return;
73
  }
74
  if (!QDir (ui_->meshDirectory->text ()).exists()) {
75
    QMessageBox (QMessageBox::Warning, "File not found",
76
  ui_->meshDirectory->text (), QMessageBox::Ok, this).exec(); return;
77
  }*/
78
  selected_ = RobotDefinition(defs_->currentText(), ui_->robotName->text(),
79
                              ui_->rootJointType->currentText(),
80
                              ui_->modelName->text(), ui_->packageName->text(),
81
                              ui_->urdfSuffix->text(), ui_->srdfSuffix->text());
82
  done(QDialog::Accepted);
83
}
84
85
void DialogLoadRobot::robotSelect(int index) {
86
  QVariant v = defs_->itemData(index);
87
  if (v.canConvert<RobotDefinition>()) {
88
    RobotDefinition rd = v.value<RobotDefinition>();
89
    ui_->robotName->setText(rd.robotName_);
90
    ui_->modelName->setText(rd.modelName_);
91
    if (rootJointTypes.contains(rd.rootJointType_))
92
      ui_->rootJointType->setCurrentIndex(
93
          rootJointTypes.indexOf(rd.rootJointType_));
94
    ui_->packageName->setText(rd.package_);
95
    ui_->urdfSuffix->setText(rd.urdfSuf_);
96
    ui_->srdfSuffix->setText(rd.srdfSuf_);
97
  }
98
}
99
}  // namespace gui
100
}  // namespace gepetto