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