GCC Code Coverage Report


Directory: plugins/
File: plugins/coal/plugin.cc
Date: 2024-12-13 15:51:58
Exec Total Coverage
Lines: 0 46 0.0%
Branches: 0 129 0.0%

Line Branch Exec Source
1 // Copyright (c) 2019 CNRS
2 // Authors: Joseph Mirabel
3 //
4 //
5 // This file is part of hpp-gui
6 // hpp-gui is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // hpp-gui is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // hpp-gui If not, see
17 // <http://www.gnu.org/licenses/>.
18
19 #include <gepetto/viewer/window-manager.h>
20
21 #include <QAction>
22 #include <QFileDialog>
23 #include <QInputDialog>
24 #include <QToolBar>
25 #include <gepetto/gui/mainwindow.hh>
26 #include <gepetto/gui/osgwidget.hh>
27 #include <gepetto/gui/windows-manager.hh>
28 #include <node.hh>
29 #include <plugin.hh>
30
31 namespace hpp {
32 namespace gui {
33 using gepetto::gui::MainWindow;
34
35 void CoalPlugin::init() {
36 MainWindow* main = MainWindow::instance();
37 main->registerSlot("addBV", this);
38
39 // TODO add a way to add an action to body tree items.
40 QToolBar* toolBar = MainWindow::instance()->addToolBar("coal tools");
41 toolBar->setObjectName("coalplugin.toolbar");
42 QAction* openD = new QAction(QIcon::fromTheme("document-open"),
43 "Load a BVH model", toolBar);
44 toolBar->addAction(openD);
45 connect(openD, SIGNAL(triggered()), SLOT(openDialog()));
46 }
47
48 void CoalPlugin::addBV(QString name, QString filename, int splitMethod) const {
49 std::string _name(name.toStdString());
50
51 BVHDisplayPtr_t node(new BVHDisplay(filename.toStdString(), _name));
52 switch (splitMethod) {
53 default:
54 case 0:
55 node->init(coal::SPLIT_METHOD_MEAN);
56 break;
57 case 1:
58 node->init(coal::SPLIT_METHOD_MEDIAN);
59 break;
60 case 2:
61 node->init(coal::SPLIT_METHOD_BV_CENTER);
62 break;
63 }
64 MainWindow* main = MainWindow::instance();
65 main->osg()->insertNode(_name, node);
66 }
67
68 void CoalPlugin::openDialog() const {
69 bool ok;
70 QString filename = QFileDialog::getOpenFileName(NULL, "Select a mesh file");
71 if (filename.isNull()) return;
72 int splitMethod = QInputDialog::getInt(NULL, "Split method type",
73 "Split method type", 0, 0, 3, 1, &ok);
74 if (!ok) return;
75 QString name = QInputDialog::getText(NULL, "Node name", "Node name",
76 QLineEdit::Normal, "bvhmodel");
77 if (name.isNull()) return;
78
79 std::string filename_(filename.toStdString());
80 std::string name_(name.toStdString());
81 std::string mname_(name_ + "_mesh");
82
83 // Load mesh
84 MainWindow* main = MainWindow::instance();
85 if (!main->osg()->nodeExists(mname_) &&
86 !main->osg()->addMesh(mname_, filename_))
87 return;
88
89 std::string group;
90 if (main->osgWindows().empty()) {
91 group = "window";
92 main->osg()->createWindow(group);
93 } else {
94 group = main->osgWindows().first()->window()->getID();
95 }
96
97 addBV(name, filename, splitMethod);
98
99 main->osg()->addToGroup(name_, group);
100 main->osg()->addToGroup(mname_, group);
101 }
102
103 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
104 Q_EXPORT_PLUGIN2(coalplugin, CoalPlugin)
105 #endif
106
107 } // namespace gui
108 } // namespace hpp
109