1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

LP-29 refactoring and clean ups

This commit is contained in:
Philippe Renon 2016-03-21 21:56:50 +01:00
parent a124ddd5da
commit c16fc656aa
31 changed files with 110 additions and 78 deletions

View File

@ -83,7 +83,7 @@ public:
/* class OSGBackgroundNode */
OSGBackgroundNode::OSGBackgroundNode(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGBackgroundNode::OSGBackgroundNode(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGBackgroundNode::~OSGBackgroundNode()
@ -108,6 +108,8 @@ void OSGBackgroundNode::setImageFile(const QUrl &url)
void OSGBackgroundNode::update()
{
Inherited::update();
if (isDirty(URL)) {
h->updateURL();
}

View File

@ -40,6 +40,8 @@ namespace osgQtQuick {
class OSGQTQUICK_EXPORT OSGBackgroundNode : public OSGNode {
Q_OBJECT Q_PROPERTY(QUrl imageFile READ imageFile WRITE setImageFile NOTIFY imageFileChanged)
typedef OSGNode Inherited;
public:
OSGBackgroundNode(QObject *parent = 0);
virtual ~OSGBackgroundNode();
@ -50,11 +52,12 @@ public:
signals:
void imageFileChanged(const QUrl &url);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -27,8 +27,6 @@
#include "OSGCamera.hpp"
#include "OSGNode.hpp"
#include <osg/Camera>
#include <osg/Node>
@ -191,7 +189,7 @@ public:
/* class OSGCamera */
OSGCamera::OSGCamera(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGCamera::OSGCamera(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGCamera::~OSGCamera()
@ -254,6 +252,8 @@ void OSGCamera::setGraphicsContext(osg::GraphicsContext *gc)
void OSGCamera::update()
{
Inherited::update();
if (isDirty(ClearColor)) {
h->updateClearColor();
}

View File

@ -45,6 +45,8 @@ class OSGQTQUICK_EXPORT OSGCamera : public OSGNode {
Q_PROPERTY(qreal fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged)
Q_PROPERTY(bool logarithmicDepthBuffer READ logarithmicDepthBuffer WRITE setLogarithmicDepthBuffer NOTIFY logarithmicDepthBufferChanged)
typedef OSGNode Inherited;
friend class OSGViewport;
public:
@ -65,14 +67,15 @@ signals:
void fieldOfViewChanged(qreal arg);
void logarithmicDepthBufferChanged(bool enabled);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
osg::Camera *asCamera() const;
void setGraphicsContext(osg::GraphicsContext *gc);
virtual void update();
};
} // namespace osgQtQuick

View File

@ -146,7 +146,7 @@ private slots:
/* class OSGFileNode */
OSGFileNode::OSGFileNode(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGFileNode::OSGFileNode(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGFileNode::~OSGFileNode()
@ -199,6 +199,8 @@ void OSGFileNode::setOptimizeMode(OptimizeMode::Enum optimizeMode)
void OSGFileNode::update()
{
Inherited::update();
if (isDirty(Async)) {
// do nothing...
}

View File

@ -39,6 +39,7 @@ QT_END_NAMESPACE
namespace osgQtQuick {
class OSGQTQUICK_EXPORT OptimizeMode : public QObject {
Q_OBJECT
public:
enum Enum { None, Optimize, OptimizeAndCheck };
Q_ENUMS(Enum) // TODO switch to Q_ENUM once on Qt 5.5
@ -49,6 +50,8 @@ class OSGQTQUICK_EXPORT OSGFileNode : public OSGNode {
Q_PROPERTY(bool async READ async WRITE setAsync NOTIFY asyncChanged)
Q_PROPERTY(osgQtQuick::OptimizeMode::Enum optimizeMode READ optimizeMode WRITE setOptimizeMode NOTIFY optimizeModeChanged)
typedef OSGNode Inherited;
public:
OSGFileNode(QObject *parent = 0);
virtual ~OSGFileNode();
@ -67,11 +70,12 @@ signals:
void asyncChanged(const bool async);
void optimizeModeChanged(OptimizeMode::Enum);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -147,6 +147,7 @@ public:
// qDebug() << "OSGGeoTransformNode::updatePosition" << position;
osgEarth::MapNode *mapNode = NULL;
if (sceneNode && sceneNode->node()) {
mapNode = osgEarth::MapNode::findMapNode(sceneNode->node());
if (!mapNode) {
@ -199,7 +200,7 @@ private slots:
/* class OSGGeoTransformNode */
OSGGeoTransformNode::OSGGeoTransformNode(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGGeoTransformNode::OSGGeoTransformNode(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGGeoTransformNode::~OSGGeoTransformNode()
@ -269,6 +270,8 @@ void OSGGeoTransformNode::setPosition(QVector3D arg)
void OSGGeoTransformNode::update()
{
Inherited::update();
if (isDirty(Child)) {
h->updateChildNode();
}

View File

@ -41,12 +41,12 @@ class OSGQTQUICK_EXPORT OSGGeoTransformNode : public OSGNode {
Q_PROPERTY(osgQtQuick::OSGNode *modelData READ childNode WRITE setChildNode NOTIFY childNodeChanged)
// TODO rename to earthNode
Q_PROPERTY(osgQtQuick::OSGNode * sceneData 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;
public:
OSGGeoTransformNode(QObject *parent = 0);
virtual ~OSGGeoTransformNode();
@ -75,11 +75,12 @@ signals:
void positionChanged(QVector3D arg);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -161,7 +161,7 @@ private slots:
/* class OSGGGroupNode */
OSGGroup::OSGGroup(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGGroup::OSGGroup(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGGroup::~OSGGroup()
@ -181,6 +181,8 @@ QQmlListProperty<OSGNode> OSGGroup::children() const
void OSGGroup::update()
{
Inherited::update();
if (isDirty(Children)) {
h->updateGroupNode();
}

View File

@ -39,17 +39,20 @@ class OSGQTQUICK_EXPORT OSGGroup : public OSGNode {
Q_CLASSINFO("DefaultProperty", "children")
typedef OSGNode Inherited;
public:
explicit OSGGroup(QObject *parent = 0);
virtual ~OSGGroup();
QQmlListProperty<OSGNode> children() const;
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -129,21 +129,15 @@ void OSGNode::componentComplete()
qDebug() << "OSGNode::componentComplete" << this;
update();
clearDirty();
h->complete = h->node.valid();
if (!isComponentComplete()) {
qWarning() << "OSGNode::componentComplete - not complete !!!" << this;
h->complete = true;
if (!h->node.valid()) {
qWarning() << "OSGNode::componentComplete - node is not valid!" << this;
}
}
bool OSGNode::isComponentComplete()
{
return h->complete;
}
void OSGNode::emitNodeChanged()
{
if (isComponentComplete()) {
if (h->complete) {
emit nodeChanged(node());
}
}

View File

@ -61,6 +61,9 @@ public:
osg::Node *node() const;
void setNode(osg::Node *node);
signals:
void nodeChanged(osg::Node *node) const;
protected:
bool isDirty(int mask = 0xFFFF) const;
void setDirty(int mask = 0xFFFF);
@ -69,18 +72,13 @@ protected:
void classBegin();
void componentComplete();
bool isComponentComplete();
void emitNodeChanged();
signals:
void nodeChanged(osg::Node *node) const;
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -78,7 +78,7 @@ public:
// TODO turn into generic shape node...
// see http://trac.openscenegraph.org/projects/osg//wiki/Support/Tutorials/TransformsAndStates
OSGShapeNode::OSGShapeNode(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGShapeNode::OSGShapeNode(QObject *parent) : Inherited(parent), h(new Hidden(this))
{
setDirty(Type);
}
@ -105,6 +105,8 @@ void OSGShapeNode::setShapeType(ShapeType::Enum type)
void OSGShapeNode::update()
{
Inherited::update();
if (isDirty(Type)) {
h->updateNode();
}

View File

@ -42,6 +42,8 @@ public:
class OSGQTQUICK_EXPORT OSGShapeNode : public OSGNode {
Q_OBJECT Q_PROPERTY(osgQtQuick::ShapeType::Enum shapeType READ shapeType WRITE setShapeType NOTIFY shapeTypeChanged)
typedef OSGNode Inherited;
public:
OSGShapeNode(QObject *parent = 0);
virtual ~OSGShapeNode();
@ -52,11 +54,12 @@ public:
signals:
void shapeTypeChanged(ShapeType::Enum);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -223,7 +223,7 @@ private slots:
/* class OSGSkyNode */
OSGSkyNode::OSGSkyNode(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGSkyNode::OSGSkyNode(QObject *parent) : Inherited(parent), h(new Hidden(this))
{
setDirty(DateTime | Light);
}
@ -305,6 +305,8 @@ void OSGSkyNode::setMinimumAmbientLight(double ambient)
void OSGSkyNode::update()
{
Inherited::update();
if (isDirty(Scene)) {
h->updateSkyNode();
}

View File

@ -49,11 +49,12 @@ class OSGQTQUICK_EXPORT OSGSkyNode : public OSGNode {
// TODO rename to sceneNode
Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *sceneData READ sceneNode WRITE setSceneNode NOTIFY sceneNodeChanged)
Q_PROPERTY(osgQtQuick::OSGViewport * viewport READ viewport WRITE setViewport NOTIFY viewportChanged)
Q_PROPERTY(bool sunLightEnabled READ sunLightEnabled WRITE setSunLightEnabled NOTIFY sunLightEnabledChanged)
Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime NOTIFY dateTimeChanged)
Q_PROPERTY(double minimumAmbientLight READ minimumAmbientLight WRITE setMinimumAmbientLight NOTIFY minimumAmbientLightChanged)
typedef OSGNode Inherited;
public:
OSGSkyNode(QObject *parent = 0);
virtual ~OSGSkyNode();
@ -81,11 +82,12 @@ signals:
void dateTimeChanged(QDateTime arg);
void minimumAmbientLightChanged(double arg);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -90,7 +90,7 @@ public:
/* class OSGTextNode */
OSGTextNode::OSGTextNode(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGTextNode::OSGTextNode(QObject *parent) : Inherited(parent), h(new Hidden(this))
{
setDirty(Text | Color);
}
@ -130,6 +130,8 @@ void OSGTextNode::setColor(const QColor &color)
void OSGTextNode::update()
{
Inherited::update();
if (isDirty(Text)) {
h->updateText();
}

View File

@ -38,6 +38,8 @@ class OSGQTQUICK_EXPORT OSGTextNode : public OSGNode {
Q_OBJECT Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
typedef OSGNode Inherited;
public:
explicit OSGTextNode(QObject *parent = 0);
virtual ~OSGTextNode();
@ -52,11 +54,12 @@ signals:
void textChanged(const QString &text);
void colorChanged(const QColor &color);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -138,7 +138,7 @@ private slots:
/* class OSGTransformNode */
OSGTransformNode::OSGTransformNode(QObject *parent) : OSGNode(parent), h(new Hidden(this))
OSGTransformNode::OSGTransformNode(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGTransformNode::~OSGTransformNode()
@ -204,6 +204,8 @@ void OSGTransformNode::setPosition(QVector3D arg)
void OSGTransformNode::update()
{
Inherited::update();
if (isDirty(Child)) {
h->updateChildNode();
}

View File

@ -39,11 +39,12 @@ class OSGQTQUICK_EXPORT OSGTransformNode : public OSGNode {
Q_OBJECT
// TODO rename to childNode
Q_PROPERTY(osgQtQuick::OSGNode *modelData READ childNode WRITE setChildNode NOTIFY childNodeChanged)
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;
public:
OSGTransformNode(QObject *parent = 0);
virtual ~OSGTransformNode();
@ -67,11 +68,12 @@ signals:
void attitudeChanged(QVector3D arg);
void positionChanged(QVector3D arg);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -72,7 +72,7 @@
which will separate the clip plane calculations of the helicopter from those of the earth. *
TODO : add OSGView to handle multiple views for a given OSGViewport
*/
*/
/*
that's a typical error when working with high-resolution (retina)
@ -95,7 +95,7 @@
I think osgQt already handles this correctly, so you shouldn't have to
worry about this if you use the classes provided by osgQt ...
*/
*/
namespace osgQtQuick {
enum DirtyFlag { Scene = 1 << 0, Camera = 1 << 1 };

View File

@ -149,7 +149,8 @@ void OSGCameraManipulator::classBegin()
void OSGCameraManipulator::componentComplete()
{
qDebug() << "OSGCameraManipulator::componentComplete" << this;
h->updateSceneNode();
update();
clearDirty();
}
osgGA::CameraManipulator *OSGCameraManipulator::manipulator() const
@ -168,7 +169,9 @@ osgGA::CameraManipulator *OSGCameraManipulator::asCameraManipulator() const
}
void OSGCameraManipulator::update()
{}
{
h->updateSceneNode();
}
} // namespace osgQtQuick
#include "OSGCameraManipulator.moc"

View File

@ -69,11 +69,12 @@ protected:
osgGA::CameraManipulator *manipulator() const;
void setManipulator(osgGA::CameraManipulator *manipulator);
protected:
virtual void update();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -57,7 +57,7 @@ public:
/* class OSGEarthManipulator */
OSGEarthManipulator::OSGEarthManipulator(QObject *parent) : OSGCameraManipulator(parent), h(new Hidden(this))
OSGEarthManipulator::OSGEarthManipulator(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGEarthManipulator::~OSGEarthManipulator()

View File

@ -37,6 +37,8 @@ namespace osgQtQuick {
class OSGQTQUICK_EXPORT OSGEarthManipulator : public OSGCameraManipulator {
Q_OBJECT
typedef OSGCameraManipulator Inherited;
public:
explicit OSGEarthManipulator(QObject *parent = 0);
virtual ~OSGEarthManipulator();

View File

@ -203,7 +203,7 @@ void MyManipulator::updateCamera(osg::Camera & camera)
/* class OSGGeoTransformManipulator */
OSGGeoTransformManipulator::OSGGeoTransformManipulator(QObject *parent) : OSGCameraManipulator(parent), h(new Hidden(this))
OSGGeoTransformManipulator::OSGGeoTransformManipulator(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGGeoTransformManipulator::~OSGGeoTransformManipulator()
@ -258,18 +258,10 @@ void OSGGeoTransformManipulator::setPosition(QVector3D arg)
}
}
// TODO factorize up
void OSGGeoTransformManipulator::componentComplete()
{
OSGCameraManipulator::componentComplete();
qDebug() << "OSGGeoTransformManipulator::componentComplete" << this;
update();
clearDirty();
}
void OSGGeoTransformManipulator::update()
{
Inherited::update();
h->updatePosition();
h->updateAttitude();
h->updateManipulator();

View File

@ -41,6 +41,8 @@ class OSGQTQUICK_EXPORT OSGGeoTransformManipulator : public OSGCameraManipulator
Q_PROPERTY(bool clampToTerrain READ clampToTerrain WRITE setClampToTerrain NOTIFY clampToTerrainChanged)
Q_PROPERTY(bool intoTerrain READ intoTerrain NOTIFY intoTerrainChanged)
typedef OSGCameraManipulator Inherited;
public:
explicit OSGGeoTransformManipulator(QObject *parent = 0);
virtual ~OSGGeoTransformManipulator();
@ -62,9 +64,6 @@ signals:
void clampToTerrainChanged(bool arg);
void intoTerrainChanged(bool arg);
protected:
void componentComplete();
private:
struct Hidden;
Hidden *const h;

View File

@ -122,7 +122,7 @@ private slots:
/* class OSGNodeTrackerManipulator */
OSGNodeTrackerManipulator::OSGNodeTrackerManipulator(QObject *parent) : OSGCameraManipulator(parent), h(new Hidden(this))
OSGNodeTrackerManipulator::OSGNodeTrackerManipulator(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGNodeTrackerManipulator::~OSGNodeTrackerManipulator()
@ -156,11 +156,10 @@ void OSGNodeTrackerManipulator::setTrackerMode(TrackerMode::Enum mode)
}
}
void OSGNodeTrackerManipulator::componentComplete()
void OSGNodeTrackerManipulator::update()
{
OSGCameraManipulator::componentComplete();
Inherited::update();
qDebug() << "OSGNodeTrackerManipulator::componentComplete" << this;
h->updateTrackerMode();
h->updateTrackNode();
}

View File

@ -45,6 +45,8 @@ class OSGQTQUICK_EXPORT OSGNodeTrackerManipulator : public OSGCameraManipulator
Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *trackNode READ trackNode WRITE setTrackNode NOTIFY trackNodeChanged)
Q_PROPERTY(osgQtQuick::TrackerMode::Enum trackerMode READ trackerMode WRITE setTrackerMode NOTIFY trackerModeChanged)
typedef OSGCameraManipulator Inherited;
public:
explicit OSGNodeTrackerManipulator(QObject *parent = 0);
virtual ~OSGNodeTrackerManipulator();
@ -59,12 +61,11 @@ signals:
void trackNodeChanged(OSGNode *node);
void trackerModeChanged(TrackerMode::Enum);
protected:
void componentComplete();
private:
struct Hidden;
Hidden *const h;
virtual void update();
};
} // namespace osgQtQuick

View File

@ -57,7 +57,7 @@ public:
/* class OSGTrackballManipulator */
OSGTrackballManipulator::OSGTrackballManipulator(QObject *parent) : OSGCameraManipulator(parent), h(new Hidden(this))
OSGTrackballManipulator::OSGTrackballManipulator(QObject *parent) : Inherited(parent), h(new Hidden(this))
{}
OSGTrackballManipulator::~OSGTrackballManipulator()

View File

@ -37,6 +37,8 @@ namespace osgQtQuick {
class OSGQTQUICK_EXPORT OSGTrackballManipulator : public OSGCameraManipulator {
Q_OBJECT
typedef OSGCameraManipulator Inherited;
public:
explicit OSGTrackballManipulator(QObject *parent = 0);
virtual ~OSGTrackballManipulator();