diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.cpp index 90d1e46a1..059ebe2ca 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.cpp @@ -36,6 +36,8 @@ #include namespace osgQtQuick { +// NOTE : these flags should not overlap with OSGGroup flags!!! +// TODO : find a better way... enum DirtyFlag {}; struct OSGBillboardNode::Hidden : public QObject { diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp index 50f5a6683..e6f6b6f64 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp @@ -38,7 +38,9 @@ #include namespace osgQtQuick { -enum DirtyFlag { Child = 1 << 0, Scene = 1 << 1, Position = 1 << 2, Clamp = 1 << 3 }; +// NOTE : these flags should not overlap with OSGGroup flags!!! +// TODO : find a better way... +enum DirtyFlag { Scene = 1 << 10, Position = 1 << 11, Clamp = 1 << 12 }; struct OSGGeoTransformNode::Hidden : public QObject { Q_OBJECT @@ -49,7 +51,6 @@ private: osg::ref_ptr transform; public: - OSGNode *childNode; OSGNode *sceneNode; float offset; @@ -59,7 +60,7 @@ public: QVector3D position; - Hidden(OSGGeoTransformNode *self) : QObject(self), self(self), childNode(NULL), sceneNode(NULL), offset(-1.0), clampToTerrain(false), intoTerrain(false) + Hidden(OSGGeoTransformNode *self) : QObject(self), self(self), sceneNode(NULL), offset(-1.0), clampToTerrain(false), intoTerrain(false) {} osg::Node *createNode() @@ -69,26 +70,6 @@ public: return transform; } - bool acceptChildNode(OSGNode *node) - { - qDebug() << "OSGGeoTransformNode::acceptChildNode" << node; - if (childNode == node) { - return false; - } - - if (childNode) { - disconnect(childNode); - } - - childNode = node; - - if (childNode) { - connect(childNode, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onChildNodeChanged(osg::Node *))); - } - - return true; - } - bool acceptSceneNode(OSGNode *node) { qDebug() << "OSGGeoTransformNode::acceptSceneNode" << node; @@ -109,29 +90,6 @@ public: return true; } - void updateChildNode() - { - qDebug() << "OSGGeoTransformNode::updateChildNode" << childNode; - bool updated = false; - if (transform->getNumChildren() == 0) { - if (childNode && childNode->node()) { - updated |= transform->addChild(childNode->node()); - } - } else { - if (childNode && childNode->node()) { - if (transform->getChild(0) != childNode->node()) { - updated |= transform->removeChild(0, 1); - updated |= transform->addChild(childNode->node()); - } - } else { - updated |= transform->removeChild(0, 1); - } - } - // if (updated) { - self->emitNodeChanged(); - // } - } - void updateSceneNode() { qDebug() << "OSGGeoTransformNode::updateSceneNode" << sceneNode; @@ -171,7 +129,7 @@ public: // get "size" of model // TODO this should be done once only... osg::ComputeBoundsVisitor cbv; - childNode->node()->accept(cbv); + transform->accept(cbv); const osg::BoundingBox & bbox = cbv.getBoundingBox(); offset = bbox.radius(); @@ -187,12 +145,6 @@ public: } private slots: - void onChildNodeChanged(osg::Node *node) - { - qDebug() << "OSGGeoTransformNode::onChildNodeChanged" << node; - updateChildNode(); - } - void onSceneNodeChanged(osg::Node *node) { qDebug() << "OSGGeoTransformNode::onSceneNodeChanged" << node; @@ -212,19 +164,6 @@ OSGGeoTransformNode::~OSGGeoTransformNode() delete h; } -OSGNode *OSGGeoTransformNode::childNode() const -{ - return h->childNode; -} - -void OSGGeoTransformNode::setChildNode(OSGNode *node) -{ - if (h->acceptChildNode(node)) { - setDirty(Child); - emit childNodeChanged(node); - } -} - OSGNode *OSGGeoTransformNode::sceneNode() const { return h->sceneNode; @@ -280,9 +219,6 @@ void OSGGeoTransformNode::updateNode() { Inherited::updateNode(); - if (isDirty(Child)) { - h->updateChildNode(); - } if (isDirty(Scene)) { h->updateSceneNode(); } diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.hpp index 788d6cd1e..3925d967c 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.hpp @@ -29,28 +29,23 @@ #define _H_OSGQTQUICK_GEOTRANSFORMNODE_H_ #include "Export.hpp" -#include "OSGNode.hpp" +#include "OSGGroup.hpp" #include -// TODO derive from OSGGroup... namespace osgQtQuick { -class OSGQTQUICK_EXPORT OSGGeoTransformNode : public OSGNode { - Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged) - Q_PROPERTY(osgQtQuick::OSGNode * sceneNode READ sceneNode WRITE setSceneNode NOTIFY sceneNodeChanged) +class OSGQTQUICK_EXPORT OSGGeoTransformNode : public OSGGroup { + Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *sceneNode READ sceneNode WRITE setSceneNode NOTIFY sceneNodeChanged) Q_PROPERTY(bool clampToTerrain READ clampToTerrain WRITE setClampToTerrain NOTIFY clampToTerrainChanged) Q_PROPERTY(bool intoTerrain READ intoTerrain NOTIFY intoTerrainChanged) Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) - typedef OSGNode Inherited; + typedef OSGGroup Inherited; public: OSGGeoTransformNode(QObject *parent = 0); virtual ~OSGGeoTransformNode(); - OSGNode *childNode() const; - void setChildNode(OSGNode *node); - OSGNode *sceneNode() const; void setSceneNode(OSGNode *node); @@ -63,13 +58,9 @@ public: void setPosition(QVector3D arg); signals: - void childNodeChanged(OSGNode *node); - void sceneNodeChanged(OSGNode *node); - void clampToTerrainChanged(bool arg); void intoTerrainChanged(bool arg); - void positionChanged(QVector3D arg); protected: diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.cpp index 8b958cd5f..d5fab2a31 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.cpp @@ -34,7 +34,9 @@ #include namespace osgQtQuick { -enum DirtyFlag { Child = 1 << 0, Scale = 1 << 1, Position = 1 << 2, Attitude = 1 << 3 }; +// NOTE : these flags should not overlap with OSGGroup flags!!! +// TODO : find a better way... +enum DirtyFlag { Scale = 1 << 10, Position = 1 << 11, Attitude = 1 << 12 }; struct OSGTransformNode::Hidden : public QObject { Q_OBJECT @@ -45,13 +47,11 @@ private: osg::ref_ptr transform; public: - OSGNode *childNode; - QVector3D scale; QVector3D attitude; QVector3D position; - Hidden(OSGTransformNode *self) : QObject(self), self(self), childNode(NULL) + Hidden(OSGTransformNode *self) : QObject(self), self(self) {} osg::Node *createNode() @@ -60,49 +60,6 @@ public: return transform; } - bool acceptChildNode(OSGNode *node) - { - qDebug() << "OSGTransformNode::acceptChildNode" << node; - if (childNode == node) { - return false; - } - - if (childNode) { - disconnect(childNode); - } - - childNode = node; - - if (childNode) { - connect(childNode, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onChildNodeChanged(osg::Node *))); - } - - return true; - } - - void updateChildNode() - { - qDebug() << "OSGTransformNode::updateChildNode" << childNode; - bool updated = false; - if (transform->getNumChildren() == 0) { - if (childNode && childNode->node()) { - updated |= transform->addChild(childNode->node()); - } - } else { - if (childNode && childNode->node()) { - if (transform->getChild(0) != childNode->node()) { - updated |= transform->removeChild(0, 1); - updated |= transform->addChild(childNode->node()); - } - } else { - updated |= transform->removeChild(0, 1); - } - } - // if (updated) { - self->emitNodeChanged(); - // } - } - void updateScale() { // qDebug() << "OSGTransformNode::updateScale" << scale; @@ -130,13 +87,6 @@ public: { transform->setPosition(osg::Vec3d(position.x(), position.y(), position.z())); } - -private slots: - void onChildNodeChanged(osg::Node *node) - { - qDebug() << "OSGTransformNode::onChildNodeChanged" << node; - updateChildNode(); - } }; /* class OSGTransformNode */ @@ -150,19 +100,6 @@ OSGTransformNode::~OSGTransformNode() delete h; } -OSGNode *OSGTransformNode::childNode() const -{ - return h->childNode; -} - -void OSGTransformNode::setChildNode(OSGNode *node) -{ - if (h->acceptChildNode(node)) { - setDirty(Child); - emit childNodeChanged(node); - } -} - QVector3D OSGTransformNode::scale() const { return h->scale; @@ -214,9 +151,6 @@ void OSGTransformNode::updateNode() { Inherited::updateNode(); - if (isDirty(Child)) { - h->updateChildNode(); - } if (isDirty(Scale)) { h->updateScale(); } diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.hpp index 992b70c48..086c73c29 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.hpp @@ -29,27 +29,22 @@ #define _H_OSGQTQUICK_TRANSFORMNODE_H_ #include "Export.hpp" -#include "OSGNode.hpp" +#include "OSGGroup.hpp" #include -// TODO derive from OSGGroup... namespace osgQtQuick { -class OSGQTQUICK_EXPORT OSGTransformNode : public OSGNode { - Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged) - Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged) +class OSGQTQUICK_EXPORT OSGTransformNode : public OSGGroup { + Q_OBJECT Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged) Q_PROPERTY(QVector3D attitude READ attitude WRITE setAttitude NOTIFY attitudeChanged) Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) - typedef OSGNode Inherited; + typedef OSGGroup Inherited; public: OSGTransformNode(QObject *parent = 0); virtual ~OSGTransformNode(); - OSGNode *childNode() const; - void setChildNode(OSGNode *node); - QVector3D scale() const; void setScale(QVector3D arg); @@ -60,8 +55,6 @@ public: void setPosition(QVector3D arg); signals: - void childNodeChanged(OSGNode *node); - void scaleChanged(QVector3D arg); void attitudeChanged(QVector3D arg); void positionChanged(QVector3D arg); diff --git a/ground/gcs/src/share/qml/model/ModelTerrainView.qml b/ground/gcs/src/share/qml/model/ModelTerrainView.qml index 70ad6961b..aac169efb 100644 --- a/ground/gcs/src/share/qml/model/ModelTerrainView.qml +++ b/ground/gcs/src/share/qml/model/ModelTerrainView.qml @@ -67,8 +67,8 @@ Item { OSGGeoTransformNode { id: modelNode - childNode: modelTransformNode sceneNode: terrainFileNode + children: [ modelTransformNode ] clampToTerrain: true @@ -77,7 +77,9 @@ Item { OSGTransformNode { id: modelTransformNode - childNode: modelFileNode + + children: [ modelFileNode ] + // model dimensions are in mm, scale to meters scale: Qt.vector3d(0.001, 0.001, 0.001) attitude: UAV.attitude() diff --git a/ground/gcs/src/share/qml/model/ModelView.qml b/ground/gcs/src/share/qml/model/ModelView.qml index 8e7bea6f9..4dbf9566a 100644 --- a/ground/gcs/src/share/qml/model/ModelView.qml +++ b/ground/gcs/src/share/qml/model/ModelView.qml @@ -60,7 +60,9 @@ Item { OSGTransformNode { id: transformNode - childNode: fileNode + + children: [ fileNode ] + attitude: UAV.attitude() }