GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/gepetto/gui/selection-event.hh Lines: 0 17 0.0 %
Date: 2024-04-14 11:13:22 Branches: 0 10 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
#ifndef GEPETTO_GUI_SELECTION_EVENT_HH
18
#define GEPETTO_GUI_SELECTION_EVENT_HH
19
20
#include <gepetto/gui/fwd.hh>
21
// This include must be include before any other Qt include for GLDEBUGPROC
22
#include <gepetto/viewer/node.h>
23
24
#include <QAtomicInt>
25
#include <QObject>
26
#include <QString>
27
#include <QVector3D>
28
29
namespace gepetto {
30
namespace gui {
31
class SelectionEvent : public QObject {
32
  Q_OBJECT
33
34
 public:
35
  enum Type { FromOsgWindow, FromBodyTree };
36
37
  SelectionEvent(const Type& t, NodePtr_t node = NodePtr_t(),
38
                 Qt::KeyboardModifiers modKey = Qt::NoModifier)
39
      : type_(t),
40
        node_(node),
41
        modKey_(modKey),
42
        hasIntersection_(false),
43
        c_(-1) {
44
    if (node) nodeName_ = QString::fromStdString(node->getID());
45
  }
46
47
  SelectionEvent(const Type& t, Qt::KeyboardModifiers modKey)
48
      : type_(t), modKey_(modKey), hasIntersection_(false), c_(-1) {}
49
50
  void setupIntersection(
51
      const osgUtil::LineSegmentIntersector::Intersection& it);
52
53
  const NodePtr_t& node() const { return node_; }
54
55
  void modKey(const Qt::KeyboardModifiers& m) { modKey_ = m; }
56
57
  /// Set this to the number of slots that will receive the event.
58
  /// \warning Not thread-safe
59
  void setCounter(int c) { c_ = c; }
60
61
 public slots:
62
  Type type() const { return type_; }
63
  QString nodeName() const { return nodeName_; }
64
  Qt::KeyboardModifiers modKey() const { return modKey_; }
65
66
  bool hasIntersection() { return hasIntersection_; }
67
  const unsigned int& primitiveIndex() const { return primitiveIndex_; }
68
  QVector3D normal(bool local) const {
69
    return (local ? localNormal_ : worldNormal_);
70
  }
71
  QVector3D point(bool local) const {
72
    return (local ? localPoint_ : worldPoint_);
73
  }
74
  /// User must call this in slots using SelectionEvent.
75
  /// This decreases the internal counter and destroys the object when it
76
  /// reaches zero.
77
  /// This is thread-safe.
78
  void done();
79
80
 private:
81
  Type type_;
82
  QString nodeName_;
83
  NodePtr_t node_;
84
  Qt::KeyboardModifiers modKey_;
85
86
  bool hasIntersection_;
87
  unsigned int primitiveIndex_;
88
  QVector3D localPoint_, localNormal_, worldPoint_, worldNormal_;
89
  QAtomicInt c_;
90
};
91
}  // namespace gui
92
}  // namespace gepetto
93
94
#endif  // GEPETTO_GUI_SELECTION_EVENT_HH