mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T717, pitch bank heading form
This commit is contained in:
committed by
Mat Sutcliffe
parent
85a3a0ee99
commit
89ae47d426
224
src/blackgui/editors/pbhsform.cpp
Normal file
224
src/blackgui/editors/pbhsform.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
/* 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 "pbhsform.h"
|
||||
#include "ui_pbhsform.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include <QDoubleValidator>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Editors
|
||||
{
|
||||
CPbhsForm::CPbhsForm(QWidget *parent) :
|
||||
CForm(parent),
|
||||
ui(new Ui::CPbhsForm)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->le_Bank->setValidator(new QDoubleValidator(-180.0 + CAngleUnit::deg().getEpsilon(), 180.0, 3, ui->le_Bank));
|
||||
ui->le_Pitch->setValidator(new QDoubleValidator(-180.0 + CAngleUnit::deg().getEpsilon(), 180.0, 3, ui->le_Pitch));
|
||||
|
||||
connect(ui->hs_Bank, &QSlider::valueChanged, this, &CPbhsForm::bankSliderChanged);
|
||||
connect(ui->hs_Pitch, &QSlider::valueChanged, this, &CPbhsForm::pitchSliderChanged);
|
||||
connect(ui->hs_Heading, &QSlider::valueChanged, this, &CPbhsForm::headingSliderChanged);
|
||||
connect(ui->le_Bank, &QLineEdit::editingFinished, this, &CPbhsForm::bankEntered);
|
||||
connect(ui->le_Pitch, &QLineEdit::editingFinished, this, &CPbhsForm::pitchEntered);
|
||||
connect(ui->le_Heading, &QLineEdit::editingFinished, this, &CPbhsForm::headingEntered);
|
||||
connect(ui->tb_ResetBank, &QToolButton::clicked, this, &CPbhsForm::resetBank);
|
||||
connect(ui->tb_ResetPitch, &QToolButton::clicked, this, &CPbhsForm::resetPitch);
|
||||
connect(ui->tb_ResetHeading, &QToolButton::clicked, this, &CPbhsForm::resetHeading);
|
||||
connect(ui->pb_SetOwnAircraft, &QPushButton::released, this, &CPbhsForm::changeValues);
|
||||
}
|
||||
|
||||
CPbhsForm::~CPbhsForm()
|
||||
{ }
|
||||
|
||||
CAngle CPbhsForm::getBankAngle() const
|
||||
{
|
||||
return CAngle(getBankAngleDegrees(), CAngleUnit::deg());
|
||||
}
|
||||
|
||||
void CPbhsForm::setBankAngle(const CAngle &angle)
|
||||
{
|
||||
const int value = angle.valueInteger(CAngleUnit::deg());
|
||||
ui->le_Bank->setText(QString::number(value));
|
||||
ui->hs_Bank->setValue(value);
|
||||
}
|
||||
|
||||
double CPbhsForm::getBankAngleDegrees() const
|
||||
{
|
||||
const QString v(ui->le_Bank->text().replace(',', '.'));
|
||||
bool ok;
|
||||
double vd = v.toDouble(&ok);
|
||||
if (!ok) { vd = 0.0; }
|
||||
return CAngle::normalizeDegrees180(vd, RoundDigits);
|
||||
}
|
||||
|
||||
CAngle CPbhsForm::getPitchAngle() const
|
||||
{
|
||||
return CAngle(getPitchAngleDegrees(), CAngleUnit::deg());
|
||||
}
|
||||
|
||||
void CPbhsForm::setPitchAngle(const CAngle &angle)
|
||||
{
|
||||
const int value = angle.valueInteger(CAngleUnit::deg());
|
||||
ui->le_Pitch->setText(QString::number(value));
|
||||
ui->hs_Pitch->setValue(value);
|
||||
}
|
||||
|
||||
double CPbhsForm::getPitchAngleDegrees() const
|
||||
{
|
||||
const QString v(ui->le_Pitch->text().replace(',', '.'));
|
||||
bool ok;
|
||||
double vd = v.toDouble(&ok);
|
||||
if (!ok) { vd = 0.0; }
|
||||
return CAngle::normalizeDegrees180(vd, RoundDigits);
|
||||
}
|
||||
|
||||
CAngle CPbhsForm::getHeadingAngle() const
|
||||
{
|
||||
return CAngle(getHeadingAngleDegrees(), CAngleUnit::deg());
|
||||
}
|
||||
|
||||
CHeading CPbhsForm::getHeading() const
|
||||
{
|
||||
return CHeading(this->getHeadingAngle(), CHeading::True);
|
||||
}
|
||||
|
||||
void CPbhsForm::setHeadingAngle(const CAngle &angle)
|
||||
{
|
||||
const int value = angle.valueInteger(CAngleUnit::deg());
|
||||
ui->le_Heading->setText(QString::number(value));
|
||||
ui->hs_Heading->setValue(value);
|
||||
}
|
||||
|
||||
double CPbhsForm::getHeadingAngleDegrees() const
|
||||
{
|
||||
const QString v(ui->le_Heading->text().replace(',', '.'));
|
||||
bool ok;
|
||||
double vd = v.toDouble(&ok);
|
||||
if (!ok) { vd = 0.0; }
|
||||
return CAngle::normalizeDegrees180(vd, RoundDigits);
|
||||
}
|
||||
|
||||
CSpeed CPbhsForm::getGroundSpeed() const
|
||||
{
|
||||
const int gsKts = ui->sb_GsKts->value();
|
||||
return CSpeed(gsKts, CSpeedUnit::kts());
|
||||
}
|
||||
|
||||
void CPbhsForm::setSituation(const CAircraftSituation &situation)
|
||||
{
|
||||
this->setBankAngle(situation.getBank());
|
||||
this->setPitchAngle(situation.getPitch());
|
||||
this->setHeadingAngle(situation.getHeading());
|
||||
}
|
||||
|
||||
void CPbhsForm::updateSituation(CAircraftSituation &situation)
|
||||
{
|
||||
situation.setPitch(this->getPitchAngle());
|
||||
situation.setBank(this->getBankAngle());
|
||||
situation.setHeading(this->getHeading());
|
||||
situation.setGroundSpeed(this->getGroundSpeed());
|
||||
}
|
||||
|
||||
void CPbhsForm::setReadOnly(bool readOnly)
|
||||
{
|
||||
ui->le_Bank->setReadOnly(readOnly);
|
||||
ui->le_Heading->setReadOnly(readOnly);
|
||||
ui->le_Pitch->setReadOnly(readOnly);
|
||||
|
||||
ui->hs_Bank->setEnabled(!readOnly);
|
||||
ui->hs_Heading->setEnabled(!readOnly);
|
||||
ui->hs_Pitch->setEnabled(!readOnly);
|
||||
}
|
||||
|
||||
void CPbhsForm::showSetButton(bool visible)
|
||||
{
|
||||
ui->pb_SetOwnAircraft->setVisible(visible);
|
||||
}
|
||||
|
||||
void CPbhsForm::bankSliderChanged(int value)
|
||||
{
|
||||
const int angle = clampAngle(qRound(this->getBankAngleDegrees()));
|
||||
if (value == angle) { return; } // avoid roundtrips
|
||||
ui->le_Bank->setText(QString::number(value));
|
||||
}
|
||||
|
||||
void CPbhsForm::pitchSliderChanged(int value)
|
||||
{
|
||||
const int angle = clampAngle(qRound(this->getPitchAngleDegrees()));
|
||||
if (value == angle) { return; } // avoid roundtrips
|
||||
ui->le_Pitch->setText(QString::number(value));
|
||||
}
|
||||
|
||||
void CPbhsForm::headingSliderChanged(int value)
|
||||
{
|
||||
const int angle = clampAngle(qRound(this->getHeadingAngleDegrees()));
|
||||
if (value == angle) { return; } // avoid roundtrips
|
||||
ui->le_Heading->setText(QString::number(value));
|
||||
}
|
||||
|
||||
void CPbhsForm::bankEntered()
|
||||
{
|
||||
const double ad = this->getBankAngleDegrees();
|
||||
QString n = QString::number(ad, 'g', 3 + RoundDigits);
|
||||
if (ui->le_Pitch->validator()) { dotToLocaleDecimalPoint(n); }
|
||||
ui->le_Bank->setText(n);
|
||||
const int angle = clampAngle(qRound(ad));
|
||||
if (angle == ui->hs_Bank->value()) { return; } // avoid roundtrips
|
||||
ui->hs_Bank->setValue(angle);
|
||||
}
|
||||
|
||||
void CPbhsForm::resetBank()
|
||||
{
|
||||
ui->le_Bank->setText("0");
|
||||
ui->hs_Bank->setValue(0);
|
||||
}
|
||||
|
||||
void CPbhsForm::pitchEntered()
|
||||
{
|
||||
const double ad = this->getPitchAngleDegrees();
|
||||
QString n = QString::number(ad, 'g', 3 + RoundDigits);
|
||||
if (ui->le_Pitch->validator()) { dotToLocaleDecimalPoint(n); }
|
||||
ui->le_Pitch->setText(n);
|
||||
const int angle = clampAngle(qRound(ad));
|
||||
if (angle == ui->hs_Pitch->value()) { return; } // avoid roundtrips
|
||||
ui->hs_Pitch->setValue(angle);
|
||||
}
|
||||
|
||||
void CPbhsForm::resetPitch()
|
||||
{
|
||||
ui->le_Pitch->setText("0");
|
||||
ui->hs_Pitch->setValue(0);
|
||||
}
|
||||
|
||||
void CPbhsForm::headingEntered()
|
||||
{
|
||||
const double ad = this->getHeadingAngleDegrees();
|
||||
QString n = QString::number(ad, 'g', 3 + RoundDigits);
|
||||
if (ui->le_Heading->validator()) { dotToLocaleDecimalPoint(n); }
|
||||
ui->le_Heading->setText(n);
|
||||
const int angle = clampAngle(qRound(ad));
|
||||
if (angle == ui->hs_Heading->value()) { return; } // avoid roundtrips
|
||||
ui->hs_Heading->setValue(angle);
|
||||
}
|
||||
|
||||
void CPbhsForm::resetHeading()
|
||||
{
|
||||
ui->le_Heading->setText("0");
|
||||
ui->hs_Heading->setValue(0);
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
112
src/blackgui/editors/pbhsform.h
Normal file
112
src/blackgui/editors/pbhsform.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/* 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_PBHSFORM_H
|
||||
#define BLACKGUI_EDITORS_PBHSFORM_H
|
||||
|
||||
#include "form.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
#include "blackmisc/aviation/heading.h"
|
||||
#include "blackmisc/pq/angle.h"
|
||||
#include "blackmisc/pq/speed.h"
|
||||
#include <QFrame>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace Ui { class CPbhsForm; }
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Editors
|
||||
{
|
||||
//! Pitch, bank, heading and speed form
|
||||
class CPbhsForm : public CForm
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
explicit CPbhsForm(QWidget *parent = nullptr);
|
||||
|
||||
//! Dtor
|
||||
virtual ~CPbhsForm() override;
|
||||
|
||||
//! Get bank angle
|
||||
BlackMisc::PhysicalQuantities::CAngle getBankAngle() const;
|
||||
|
||||
//! Set bank angle
|
||||
void setBankAngle(const BlackMisc::PhysicalQuantities::CAngle &angle);
|
||||
|
||||
//! Get pitch angle
|
||||
BlackMisc::PhysicalQuantities::CAngle getPitchAngle() const;
|
||||
|
||||
//! Set pitch angle
|
||||
void setPitchAngle(const BlackMisc::PhysicalQuantities::CAngle &angle);
|
||||
|
||||
//! Get heading angle
|
||||
BlackMisc::PhysicalQuantities::CAngle getHeadingAngle() const;
|
||||
|
||||
//! Get heading
|
||||
BlackMisc::Aviation::CHeading getHeading() const;
|
||||
|
||||
//! Set heading angle
|
||||
void setHeadingAngle(const BlackMisc::PhysicalQuantities::CAngle &angle);
|
||||
|
||||
//! Get ground speed
|
||||
BlackMisc::PhysicalQuantities::CSpeed getGroundSpeed() const;
|
||||
|
||||
//! Set situation
|
||||
void setSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Update PBHs in situation
|
||||
void updateSituation(BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! \copydoc CForm::setReadOnly
|
||||
virtual void setReadOnly(bool readOnly) override;
|
||||
|
||||
//! Show the "SET" button
|
||||
void showSetButton(bool visible);
|
||||
|
||||
signals:
|
||||
//! Changed values
|
||||
void changeValues();
|
||||
|
||||
private:
|
||||
static constexpr int RoundDigits = 6; //!< rounding
|
||||
|
||||
//! Get bank angle
|
||||
double getBankAngleDegrees() const;
|
||||
|
||||
//! Get pitch angle
|
||||
double getPitchAngleDegrees() const;
|
||||
|
||||
//! Get heading angle
|
||||
double getHeadingAngleDegrees() const;
|
||||
|
||||
//! Values changed from UI @{
|
||||
void bankSliderChanged(int value);
|
||||
void pitchSliderChanged(int value);
|
||||
void headingSliderChanged(int value);
|
||||
void pressureSliderChanged(int value);
|
||||
void bankEntered();
|
||||
void resetBank();
|
||||
void pitchEntered();
|
||||
void resetPitch();
|
||||
void headingEntered();
|
||||
void resetHeading();
|
||||
void presetOwnAircraftSituation();
|
||||
//! @}
|
||||
|
||||
static int clampAngle(int in) { return qBound(-179, in, 180); }
|
||||
|
||||
QScopedPointer<Ui::CPbhsForm> ui;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
192
src/blackgui/editors/pbhsform.ui
Normal file
192
src/blackgui/editors/pbhsform.ui
Normal file
@@ -0,0 +1,192 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CPbhsForm</class>
|
||||
<widget class="QFrame" name="CPbhsForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>309</width>
|
||||
<height>116</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Pitch, bank, heading</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_Bank">
|
||||
<property name="text">
|
||||
<string>Bank (-179° to 180°):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="le_Bank">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>deg.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QToolButton" name="tb_ResetBank">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/cross-white.png</normaloff>:/diagona/icons/diagona/icons/cross-white.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QSlider" name="hs_Bank">
|
||||
<property name="minimum">
|
||||
<number>-179</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>180</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksAbove</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>25</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_Pitch">
|
||||
<property name="text">
|
||||
<string>Pitch (-179° to 180°):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="le_Pitch">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>deg.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QToolButton" name="tb_ResetPitch">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/cross-white.png</normaloff>:/diagona/icons/diagona/icons/cross-white.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QSlider" name="hs_Pitch">
|
||||
<property name="minimum">
|
||||
<number>-179</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>180</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksAbove</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>25</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lbl_Heading">
|
||||
<property name="text">
|
||||
<string>Heading (-179° to 180°):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="le_Heading">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QToolButton" name="tb_ResetHeading">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/cross-white.png</normaloff>:/diagona/icons/diagona/icons/cross-white.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QSlider" name="hs_Heading">
|
||||
<property name="minimum">
|
||||
<number>-179</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>180</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lbl_GsKts">
|
||||
<property name="text">
|
||||
<string>Ground speed (kts):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSpinBox" name="sb_GsKts">
|
||||
<property name="suffix">
|
||||
<string>kts</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>300</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3" alignment="Qt::AlignRight">
|
||||
<widget class="QPushButton" name="pb_SetOwnAircraft">
|
||||
<property name="text">
|
||||
<string>set</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>le_Bank</tabstop>
|
||||
<tabstop>tb_ResetBank</tabstop>
|
||||
<tabstop>hs_Bank</tabstop>
|
||||
<tabstop>le_Pitch</tabstop>
|
||||
<tabstop>tb_ResetPitch</tabstop>
|
||||
<tabstop>hs_Pitch</tabstop>
|
||||
<tabstop>le_Heading</tabstop>
|
||||
<tabstop>tb_ResetHeading</tabstop>
|
||||
<tabstop>hs_Heading</tabstop>
|
||||
<tabstop>sb_GsKts</tabstop>
|
||||
<tabstop>pb_SetOwnAircraft</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../blackmisc/blackmisc.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user