1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

LP-29 fix OSGGroup update logic

This commit is contained in:
Philippe Renon 2016-03-29 09:15:59 +02:00
parent 567b7f1040
commit 7c0e92fb1b
3 changed files with 40 additions and 22 deletions

View File

@ -70,6 +70,7 @@ public:
void setDirty(int mask) void setDirty(int mask)
{ {
// qDebug() << "DirtySupport::setDirty" << mask;
if (!dirtyFlags) { if (!dirtyFlags) {
osg::Node *node = self->hookNode(); osg::Node *node = self->hookNode();
if (node) { if (node) {
@ -97,7 +98,9 @@ public:
void update() void update()
{ {
// qDebug() << "DirtySupport::update";
if (dirtyFlags) { if (dirtyFlags) {
// qDebug() << "DirtySupport::update - updating...";
self->update(); self->update();
} }
clearDirty(); clearDirty();

View File

@ -56,7 +56,7 @@ public:
void appendChild(OSGNode *childNode) void appendChild(OSGNode *childNode)
{ {
cache[childNode] = childNode->node(); // qDebug() << "OSGGroup::appendChild" << childNode;
children.append(childNode); children.append(childNode);
connect(childNode, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onChildNodeChanged(osg::Node *)), Qt::UniqueConnection); connect(childNode, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onChildNodeChanged(osg::Node *)), Qt::UniqueConnection);
self->setDirty(Children); self->setDirty(Children);
@ -102,19 +102,23 @@ public:
QListIterator<OSGNode *> i(children); QListIterator<OSGNode *> i(children);
while (i.hasNext()) { while (i.hasNext()) {
OSGNode *childNode = i.next(); OSGNode *childNode = i.next();
if (index < group->getNumChildren()) { // qDebug() << "OSGGroup::updateChildren - child" << childNode;
updated |= group->replaceChild(group->getChild(index), childNode->node()); if (childNode->node()) {
} else { if (index < group->getNumChildren()) {
updated |= group->addChild(childNode->node()); updated |= group->replaceChild(group->getChild(index), childNode->node());
} else {
updated |= group->addChild(childNode->node());
}
cache.insert(childNode, childNode->node());
index++;
} }
index++;
} }
// removing eventual left overs // removing eventual left overs
if (index < group->getNumChildren()) { if (index < group->getNumChildren()) {
updated |= group->removeChild(index, group->getNumChildren() - index); updated |= group->removeChild(index, group->getNumChildren() - index);
} }
// if (updated) { // if (updated) {
self->emitNodeChanged(); // self->emitNodeChanged();
// } // }
} }
@ -149,27 +153,39 @@ public:
} }
private slots: private slots:
void onChildNodeChanged(osg::Node *node) void onChildNodeChanged(osg::Node *child)
{ {
qDebug() << "OSGGroup::onChildNodeChanged" << node; // qDebug() << "OSGGroup::onChildNodeChanged" << node;
osg::Group *group = static_cast<osg::Group *>(self->node()); osg::Group *group = static_cast<osg::Group *>(self->node());
if (!group) { if (!group) {
qWarning() << "OSGGroup::onChildNodeChanged - null group"; qWarning() << "OSGGroup::onChildNodeChanged - null group";
return; return;
} }
OSGNode *obj = qobject_cast<OSGNode *>(sender()); OSGNode *childNode = qobject_cast<OSGNode *>(sender());
if (obj) { // qDebug() << "OSGGroup::onChildNodeChanged - child node" << obj;
osg::Node *cacheNode = cache.value(obj, NULL); if (!childNode) {
if (cacheNode) { qWarning() << "OSGGroup::onChildNodeChanged - sender is not an OSGNode" << sender();
group->replaceChild(cacheNode, node); return;
} else {
// should not happen...
}
cache[obj] = node;
// emit self->nodeChanged(group.get());
} }
if (childNode->node() != child) {
qWarning() << "OSGGroup::onChildNodeChanged - child node is not valid" << childNode;
return;
}
bool updated = false;
osg::Node *current = cache.value(childNode, NULL);
if (current) {
updated |= group->replaceChild(current, child);
} else {
// should not happen...
qWarning() << "OSGGroup::onChildNodeChanged - child node is not a child" << childNode;
}
cache[childNode] = childNode->node();
// if (updated) {
// emit self->nodeChanged(group.get());
// }
} }
}; };

View File

@ -136,14 +136,14 @@ void OSGNode::emitNodeChanged()
void OSGNode::classBegin() void OSGNode::classBegin()
{ {
qDebug() << "OSGNode::classBegin" << this; // qDebug() << "OSGNode::classBegin" << this;
setNode(createNode()); setNode(createNode());
} }
void OSGNode::componentComplete() void OSGNode::componentComplete()
{ {
qDebug() << "OSGNode::componentComplete" << this; // qDebug() << "OSGNode::componentComplete" << this;
updateNode(); updateNode();
clearDirty(); clearDirty();
@ -151,7 +151,6 @@ void OSGNode::componentComplete()
if (!h->node.valid()) { if (!h->node.valid()) {
qWarning() << "OSGNode::componentComplete - node is not valid!" << this; qWarning() << "OSGNode::componentComplete - node is not valid!" << this;
} }
qDebug() << "OSGNode::componentComplete DONE" << this;
} }
} // namespace osgQtQuick } // namespace osgQtQuick