From 5def05d6b652a8cd033083f4e0d18f5f20146348 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 10 Sep 2019 23:48:08 +0200 Subject: [PATCH] Ref T717, UI for relative positions --- .../editors/relativeaircraftposition.cpp | 58 +++++++++++++ .../editors/relativeaircraftposition.h | 59 +++++++++++++ .../editors/relativeaircraftposition.ui | 83 +++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 src/blackgui/editors/relativeaircraftposition.cpp create mode 100644 src/blackgui/editors/relativeaircraftposition.h create mode 100644 src/blackgui/editors/relativeaircraftposition.ui diff --git a/src/blackgui/editors/relativeaircraftposition.cpp b/src/blackgui/editors/relativeaircraftposition.cpp new file mode 100644 index 000000000..1513a4956 --- /dev/null +++ b/src/blackgui/editors/relativeaircraftposition.cpp @@ -0,0 +1,58 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +#include "relativeaircraftposition.h" +#include "ui_relativeaircraftposition.h" + +using namespace BlackMisc::Geo; +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackGui +{ + namespace Editors + { + CRelativeAircraftPosition::CRelativeAircraftPosition(QWidget *parent) : + CForm(parent), + ui(new Ui::CRelativeAircraftPosition) + { + ui->setupUi(this); + } + + CRelativeAircraftPosition::~CRelativeAircraftPosition() + { } + + void CRelativeAircraftPosition::setReadOnly(bool readOnly) + { + ui->sb_Distance->setReadOnly(readOnly); + ui->sb_RelativeBearing->setReadOnly(readOnly); + } + + void CRelativeAircraftPosition::setDistance(const CLength &distance) + { + const int distMeters = distance.valueInteger(CLengthUnit::m()); + ui->sb_Distance->setValue(distMeters); + } + + CCoordinateGeodetic CRelativeAircraftPosition::getRelativeCoordinate(const CAngle &bearingOffset) const + { + if (m_originCoordinate.isNull()) { return CCoordinateGeodetic::null(); } + const CLength distance(ui->sb_Distance->value(), CLengthUnit::m()); + CAngle relBearing(ui->sb_RelativeBearing->value(), CAngleUnit::deg()); + if (!bearingOffset.isNull()) { relBearing += bearingOffset; } + return m_originCoordinate.calculatePosition(distance, relBearing); + } + + void CRelativeAircraftPosition::displayInfo(const CCoordinateGeodetic &relPos) + { + const CCoordinateGeodetic p = relPos.isNull() ? this->getRelativeCoordinate() : relPos; + ui->le_Info->setText( + QStringLiteral("%1 / %2").arg(m_originCoordinate.toQString(true), p.toQString(true)) + ); + } + } // ns +} // ns diff --git a/src/blackgui/editors/relativeaircraftposition.h b/src/blackgui/editors/relativeaircraftposition.h new file mode 100644 index 000000000..5ada94eea --- /dev/null +++ b/src/blackgui/editors/relativeaircraftposition.h @@ -0,0 +1,59 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_EDITORS_RELATIVEAIRCRAFTPOSITION_H +#define BLACKGUI_EDITORS_RELATIVEAIRCRAFTPOSITION_H + +#include +#include + +#include "blackmisc/geo/coordinategeodetic.h" +#include "blackgui/editors/form.h" + +namespace Ui { class CRelativeAircraftPosition; } +namespace BlackGui +{ + namespace Editors + { + //! Position relative to other aircraft + class CRelativeAircraftPosition : public CForm + { + Q_OBJECT + + public: + //! Constructor + explicit CRelativeAircraftPosition(QWidget *parent = nullptr); + + //! Destructor + virtual ~CRelativeAircraftPosition() override; + + //! \copydoc CForm::setReadOnly + virtual void setReadOnly(bool readOnly) override; + + //! Set origin coordinate + void setOriginCoordinate(const BlackMisc::Geo::CCoordinateGeodetic &originCoordinate) { m_originCoordinate = originCoordinate; } + + //! Set the distance + void setDistance(const BlackMisc::PhysicalQuantities::CLength &distance); + + //! Relative coordinate based on entered data + BlackMisc::Geo::CCoordinateGeodetic getRelativeCoordinate(const BlackMisc::PhysicalQuantities::CAngle &bearingOffset = BlackMisc::PhysicalQuantities::CAngle::null()) const; + + //! Display coordinate info + void displayInfo(const BlackMisc::Geo::CCoordinateGeodetic &relPos = BlackMisc::Geo::CCoordinateGeodetic::null()); + + private: + QScopedPointer ui; + BlackMisc::Geo::CCoordinateGeodetic m_originCoordinate; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/editors/relativeaircraftposition.ui b/src/blackgui/editors/relativeaircraftposition.ui new file mode 100644 index 000000000..b00259af6 --- /dev/null +++ b/src/blackgui/editors/relativeaircraftposition.ui @@ -0,0 +1,83 @@ + + + CRelativeAircraftPosition + + + + 0 + 0 + 298 + 24 + + + + Relative coordinate + + + + 1 + + + 1 + + + 1 + + + 1 + + + + + distance: + + + + + + + rel.bearing + + + + + + + deg. + + + 359 + + + + + + + m + + + 5 + + + 5000 + + + 10 + + + QAbstractSpinBox::DefaultStepType + + + + + + + true + + + + + + + +