GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/gui/dialog/dialogloadrobot.cc Lines: 5 39 12.8 %
Date: 2020-05-14 11:23:33 Branches: 12 110 10.9 %

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
#include "ui_dialogloadrobot.h"
19
20
#include <QDir>
21
#include <QMessageBox>
22
#include <QFileDialog>
23
24
namespace gepetto {
25
  namespace gui {
26



1
    QStringList DialogLoadRobot::rootJointTypes = QStringList () << "freeflyer" << "planar" << "anchor";
27
28
2
    QList <DialogLoadRobot::RobotDefinition> DialogLoadRobot::definitions =
29
2
      QList <DialogLoadRobot::RobotDefinition>()
30

2
      << DialogLoadRobot::RobotDefinition ();
31
32
    DialogLoadRobot::DialogLoadRobot(QWidget *parent) :
33
      QDialog(parent),
34
      ui_(new ::Ui::DialogLoadRobot)
35
    {
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()
48
    {
49
      delete ui_;
50
    }
51
52
    void DialogLoadRobot::addRobotDefinition(QString name, QString robotName, QString rootJointType, QString modelName, QString package, QString urdfSuffix, QString srdfSuffix)
53
    {
54
      definitions.append(RobotDefinition (name, robotName, rootJointType, modelName, package, urdfSuffix, srdfSuffix));
55
    }
56
57
    QList<DialogLoadRobot::RobotDefinition> DialogLoadRobot::getRobotDefinitions()
58
    {
59
      return definitions;
60
    }
61
62
    void DialogLoadRobot::accept()
63
    {
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(), QMessageBox::Ok, this).exec();
68
        return;
69
      }
70
      if (!d.exists(ui_->modelName->text () + ui_->urdfSuffix->text () + ".urdf")) {
71
        QMessageBox (QMessageBox::Warning, "File not found", d.absoluteFilePath(ui_->modelName->text () + ui_->urdfSuffix->text () + ".urdf"), QMessageBox::Ok, this).exec();
72
        return;
73
      }
74
      if (!QDir (ui_->meshDirectory->text ()).exists()) {
75
        QMessageBox (QMessageBox::Warning, "File not found", ui_->meshDirectory->text (), QMessageBox::Ok, this).exec();
76
        return;
77
      }*/
78
      selected_ = RobotDefinition (defs_->currentText() ,
79
          ui_->robotName->text(),
80
          ui_->rootJointType->currentText(),
81
          ui_->modelName->text(),
82
          ui_->packageName->text(),
83
          ui_->urdfSuffix->text(),
84
          ui_->srdfSuffix->text());
85
      done(QDialog::Accepted);
86
    }
87
88
    void DialogLoadRobot::robotSelect(int index)
89
    {
90
      QVariant v = defs_->itemData(index);
91
      if (v.canConvert <RobotDefinition>()) {
92
        RobotDefinition rd = v.value <RobotDefinition> ();
93
        ui_->robotName->setText(rd.robotName_);
94
        ui_->modelName->setText(rd.modelName_);
95
        if (rootJointTypes.contains(rd.rootJointType_))
96
          ui_->rootJointType->setCurrentIndex (rootJointTypes.indexOf(rd.rootJointType_));
97
        ui_->packageName->setText(rd.package_);
98
        ui_->urdfSuffix->setText(rd.urdfSuf_);
99
        ui_->srdfSuffix->setText(rd.srdfSuf_);
100
      }
101
    }
102
  } // namespace gui
103

3
} // namespace gepetto