2023-07-10 13:54:53 +00:00
|
|
|
#include "QskLevelingSensor.h"
|
|
|
|
#include <QskScaleTickmarks.h>
|
2023-07-17 08:24:36 +00:00
|
|
|
#include <QskFunctions.h>
|
2023-07-10 13:54:53 +00:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
template<typename T>
|
|
|
|
bool compareExchange(T& dst, const T& src)
|
|
|
|
{
|
|
|
|
if (dst != src)
|
|
|
|
{
|
|
|
|
dst = src;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
bool compareExchange<float>(float& dst, const float& src)
|
|
|
|
{
|
2023-07-17 08:24:36 +00:00
|
|
|
if (!qskFuzzyCompare(dst, src))
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
dst = src;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isAxis(const Qt::Axis axis) {
|
|
|
|
return axis == Qt::XAxis || axis == Qt::YAxis || axis == Qt::ZAxis;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
QSK_SUBCONTROL(QskLevelingSensor, OuterDisk)
|
|
|
|
QSK_SUBCONTROL(QskLevelingSensor, Horizon)
|
|
|
|
QSK_SUBCONTROL(QskLevelingSensor, TickmarksX)
|
|
|
|
QSK_SUBCONTROL(QskLevelingSensor, TickmarksXLabels)
|
|
|
|
QSK_SUBCONTROL(QskLevelingSensor, TickmarksY)
|
|
|
|
QSK_SUBCONTROL(QskLevelingSensor, TickmarksYLabels)
|
|
|
|
QSK_SUBCONTROL(QskLevelingSensor, TickmarksZ)
|
|
|
|
QSK_SUBCONTROL(QskLevelingSensor, TickmarksZLabels)
|
2023-07-10 13:54:53 +00:00
|
|
|
|
|
|
|
#define RETURN_IF_FALSE(expr) if(!(expr)) return;
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
QskLevelingSensor::QskLevelingSensor(QQuickItem* const parent)
|
2023-07-10 13:54:53 +00:00
|
|
|
: Inherited(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
void QskLevelingSensor::setRotation(const QVector3D& degree)
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
if (m_rotation != degree)
|
|
|
|
{
|
|
|
|
setRotation(Qt::XAxis, degree.x());
|
|
|
|
setRotation(Qt::YAxis, degree.y());
|
|
|
|
setRotation(Qt::ZAxis, degree.z());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
void QskLevelingSensor::setRotation(const Qt::Axis axis, const float degree)
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
RETURN_IF_FALSE(isAxis(axis));
|
|
|
|
|
|
|
|
if (compareExchange(m_rotation[axis], degree))
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
switch(axis)
|
|
|
|
{
|
|
|
|
case Qt::XAxis: Q_EMIT rotationXChanged(m_rotation[axis]); break;
|
|
|
|
case Qt::YAxis: Q_EMIT rotationYChanged(m_rotation[axis]); break;
|
|
|
|
case Qt::ZAxis: Q_EMIT rotationZChanged(m_rotation[axis]); break;
|
|
|
|
}
|
|
|
|
Q_EMIT rotationChanged(m_rotation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
void QskLevelingSensor::setTickmarks(const Qt::Axis axis, QskScaleTickmarks tickmarks)
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
RETURN_IF_FALSE(isAxis(axis));
|
|
|
|
|
|
|
|
m_tickmarks[axis] = std::move(tickmarks);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
void QskLevelingSensor::setTickmarksLabels(const Qt::Axis axis, TickmarksLabels labels)
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
RETURN_IF_FALSE(isAxis(axis));
|
|
|
|
|
|
|
|
m_tickmarksLabels[axis] = std::move(labels);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
void QskLevelingSensor::setAngle(const QVector3D& degree)
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
if (compareExchange(m_angle, degree))
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
Q_EMIT anglesChanged(m_angle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
void QskLevelingSensor::setAngle(const Qt::Axis axis, const float degree)
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
RETURN_IF_FALSE(isAxis(axis));
|
|
|
|
|
|
|
|
if (compareExchange(m_angle[axis], degree))
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
Q_EMIT anglesChanged(m_angle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
const QskScaleTickmarks& QskLevelingSensor::tickmarks(Qt::Axis axis) const
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
if (isAxis(axis))
|
|
|
|
{
|
|
|
|
return m_tickmarks[axis];
|
|
|
|
}
|
|
|
|
static const QskScaleTickmarks invalid;
|
|
|
|
return invalid;
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
const QskLevelingSensor::TickmarksLabels& QskLevelingSensor::tickmarkLabels(Qt::Axis axis) const
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
if (isAxis(axis))
|
|
|
|
{
|
|
|
|
return m_tickmarksLabels[axis];
|
|
|
|
}
|
2023-07-17 09:14:43 +00:00
|
|
|
static const QskLevelingSensor::TickmarksLabels invalid;
|
2023-07-10 13:54:53 +00:00
|
|
|
return invalid;
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
const QVector3D& QskLevelingSensor::angle() const noexcept
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
return m_angle;
|
|
|
|
}
|
|
|
|
|
2023-07-17 09:14:43 +00:00
|
|
|
const QVector3D& QskLevelingSensor::rotation() const noexcept
|
2023-07-10 13:54:53 +00:00
|
|
|
{
|
|
|
|
return m_rotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_QskLevelingSensor.cpp"
|