Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / libs / osgearth / osgQtQuick / OSGNode.cpp
blob7e78bb0bbd1d971d2299fa5879926ff1839d9dec
1 /**
2 ******************************************************************************
4 * @file OSGNode.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
6 * @addtogroup
7 * @{
8 * @addtogroup
9 * @{
10 * @brief
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "OSGNode.hpp"
30 #include "DirtySupport.hpp"
32 #include <osg/Node>
34 #include <QDebug>
36 namespace osgQtQuick {
37 class OSGNode;
39 struct OSGNode::Hidden : public QObject, public DirtySupport {
40 Q_OBJECT
42 friend class OSGNode;
44 private:
45 OSGNode *const self;
47 osg::ref_ptr<osg::Node> node;
49 bool complete;
51 public:
52 Hidden(OSGNode *self) : QObject(self), self(self), complete(false) /*, dirty(0)*/
55 osg::Node *nodeToUpdate() const
57 return self->node();
60 void update()
62 return self->updateNode();
65 bool acceptNode(osg::Node *aNode)
67 if (node == aNode) {
68 return false;
71 int flags = dirty();
72 if (flags) {
73 clearDirty();
75 node = aNode;
76 if (node) {
77 if (flags) {
78 setDirty(flags);
81 return true;
85 /* class OSGNode */
87 OSGNode::OSGNode(QObject *parent) : QObject(parent), QQmlParserStatus(), h(new Hidden(this))
90 OSGNode::~OSGNode()
92 delete h;
95 osg::Node *OSGNode::node() const
97 return h->node.get();
100 void OSGNode::setNode(osg::Node *node)
102 if (h->acceptNode(node)) {
103 emitNodeChanged();
107 bool OSGNode::isDirty(int mask) const
109 return h->isDirty(mask);
112 void OSGNode::setDirty(int mask)
114 h->setDirty(mask);
117 void OSGNode::clearDirty()
119 h->clearDirty();
122 osg::Node *OSGNode::createNode()
124 return NULL;
127 void OSGNode::updateNode()
130 void OSGNode::emitNodeChanged()
132 if (h->complete) {
133 emit nodeChanged(node());
137 void OSGNode::classBegin()
139 // qDebug() << "OSGNode::classBegin" << this;
141 setNode(createNode());
144 void OSGNode::componentComplete()
146 // qDebug() << "OSGNode::componentComplete" << this;
148 updateNode();
149 clearDirty();
150 h->complete = true;
151 if (!h->node.valid()) {
152 qWarning() << "OSGNode::componentComplete - node is not valid!" << this;
155 } // namespace osgQtQuick
157 #include "OSGNode.moc"