GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/gui/dialog/dialogloadenvironment.cc Lines: 4 35 11.4 %
Date: 2020-05-14 11:23:33 Branches: 5 84 6.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/dialogloadenvironment.hh"
18
#include "ui_dialogloadenvironment.h"
19
20
#include <QDir>
21
#include <QMessageBox>
22
#include <QFileDialog>
23
24
namespace gepetto {
25
  namespace gui {
26
2
    QList <DialogLoadEnvironment::EnvironmentDefinition> DialogLoadEnvironment::definitions =
27
2
      QList <DialogLoadEnvironment::EnvironmentDefinition>()
28

2
      << DialogLoadEnvironment::EnvironmentDefinition ();
29
30
    DialogLoadEnvironment::DialogLoadEnvironment(QWidget *parent) :
31
      QDialog(parent),
32
      ui_(new ::Ui::DialogLoadEnvironment)
33
    {
34
      ui_->setupUi(this);
35
      ui_->groupBox_details->setVisible (false);
36
      defs_  = ui_->comboBox_defs;
37
      defs_->setFocus();
38
39
      foreach (EnvironmentDefinition r, definitions) {
40
        defs_->addItem(r.name_, QVariant::fromValue(r));
41
      }
42
    }
43
44
    DialogLoadEnvironment::~DialogLoadEnvironment()
45
    {
46
      delete ui_;
47
    }
48
49
    void DialogLoadEnvironment::addEnvironmentDefinition(QString name, QString envName, QString package, QString urdfFilename, QString urdfSuffix, QString srdfSuffix)
50
    {
51
      definitions.append(EnvironmentDefinition (name, envName, package, urdfFilename, urdfSuffix, srdfSuffix));
52
    }
53
54
    QList<DialogLoadEnvironment::EnvironmentDefinition> DialogLoadEnvironment::getEnvironmentDefinitions()
55
    {
56
      return definitions;
57
    }
58
59
    void DialogLoadEnvironment::accept()
60
    {
61
      /* TODO use the urdfParser::getFilename to check if the package exists
62
      QDir d (ui_->packagePath->text ());
63
      if (!d.cd("urdf")) {
64
        QMessageBox (QMessageBox::Warning, "Directory not found", d.absolutePath(), QMessageBox::Ok, this).exec();
65
        return;
66
      }
67
      if (!d.exists(ui_->urdfFilename->text () + ".urdf")) {
68
        QMessageBox (QMessageBox::Warning, "File not found", d.absoluteFilePath(ui_->urdfFilename->text() + ".urdf"), QMessageBox::Ok, this).exec();
69
        return;
70
      }
71
      if (!QDir (ui_->meshDirectory->text ()).exists()) {
72
        QMessageBox (QMessageBox::Warning, "File not found", ui_->meshDirectory->text (), QMessageBox::Ok, this).exec();
73
        return;
74
      }*/
75
      selected_ = EnvironmentDefinition (defs_->currentText() ,
76
          ui_->envName->text(),
77
          ui_->packageName->text(),
78
          ui_->urdfFilename->text(),
79
	  ui_->urdfSuffix->text(),
80
	  ui_->srdfSuffix->text());
81
      done(QDialog::Accepted);
82
    }
83
84
    void DialogLoadEnvironment::envSelect(int index)
85
    {
86
      QVariant v = defs_->itemData(index);
87
      if (v.canConvert <EnvironmentDefinition>()) {
88
        EnvironmentDefinition rd = v.value <EnvironmentDefinition> ();
89
        ui_->envName->setText(rd.envName_);
90
        ui_->packageName->setText(rd.package_);
91
        ui_->urdfFilename->setText(rd.urdfFilename_);
92
	ui_->urdfSuffix->setText(rd.urdfSuf_);
93
	ui_->srdfSuffix->setText(rd.srdfSuf_);
94
      }
95
    }
96
  } // namespace gui
97

3
} // namespace gepetto