mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T111, added situation form supporting pitch/bank
This commit is contained in:
committed by
Mathew Sutcliffe
parent
bb13a32c7c
commit
c8a21629f1
165
src/blackgui/editors/situationform.cpp
Normal file
165
src/blackgui/editors/situationform.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/* Copyright (C) 2017
|
||||
* 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 and at http://www.swift-project.org/license.html. 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 "situationform.h"
|
||||
#include "ui_situationform.h"
|
||||
#include "blackmisc/pq/angle.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include <QDoubleValidator>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Editors
|
||||
{
|
||||
CSituationForm::CSituationForm(QWidget *parent) :
|
||||
CForm(parent),
|
||||
ui(new Ui::CSituationForm)
|
||||
{
|
||||
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, &CSituationForm::bankSliderChanged);
|
||||
connect(ui->hs_Pitch, &QSlider::valueChanged, this, &CSituationForm::pitchSliderChanged);
|
||||
connect(ui->le_Bank, &QLineEdit::editingFinished, this, &CSituationForm::bankEntered);
|
||||
connect(ui->le_Pitch, &QLineEdit::editingFinished, this, &CSituationForm::pitchEntered);
|
||||
connect(ui->tb_ResetBank, &QToolButton::clicked, this, &CSituationForm::resetBank);
|
||||
connect(ui->tb_ResetPitch, &QToolButton::clicked, this, &CSituationForm::resetPitch);
|
||||
connect(ui->pb_Set, &QPushButton::clicked, this, &CSituationForm::changeAircraftSituation);
|
||||
connect(ui->comp_Coordinate, &CCoordinateForm::changeCoordinate, this, &CSituationForm::changeAircraftSituation);
|
||||
}
|
||||
|
||||
CSituationForm::~CSituationForm()
|
||||
{ }
|
||||
|
||||
void CSituationForm::setSituation(const BlackMisc::Aviation::CAircraftSituation &situation)
|
||||
{
|
||||
ui->comp_Coordinate->setCoordinate(situation);
|
||||
}
|
||||
|
||||
CAircraftSituation CSituationForm::getSituation() const
|
||||
{
|
||||
CAircraftSituation s(ui->comp_Coordinate->getCoordinate());
|
||||
s.setBank(this->getBankAngle());
|
||||
s.setPitch(this->getPitchAngle());
|
||||
return s;
|
||||
}
|
||||
|
||||
CAngle CSituationForm::getBankAngle() const
|
||||
{
|
||||
return CAngle(getBankAngleDegrees(), CAngleUnit::deg());
|
||||
}
|
||||
|
||||
double CSituationForm::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 CSituationForm::getPitchAngle() const
|
||||
{
|
||||
return CAngle(getPitchAngleDegrees(), CAngleUnit::deg());
|
||||
}
|
||||
|
||||
double CSituationForm::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);
|
||||
}
|
||||
|
||||
void CSituationForm::setReadOnly(bool readonly)
|
||||
{
|
||||
ui->comp_Coordinate->setReadOnly(readonly);
|
||||
}
|
||||
|
||||
void CSituationForm::setSelectOnly()
|
||||
{
|
||||
this->setReadOnly(true);
|
||||
}
|
||||
|
||||
CStatusMessageList CSituationForm::validate(bool nested) const
|
||||
{
|
||||
CStatusMessageList ml;
|
||||
if (nested)
|
||||
{
|
||||
ml.push_back(ui->comp_Coordinate->validate(nested));
|
||||
}
|
||||
return ml;
|
||||
}
|
||||
|
||||
void CSituationForm::showSetButton(bool visible)
|
||||
{
|
||||
ui->pb_Set->setVisible(visible);
|
||||
}
|
||||
|
||||
int clampAngle(int in)
|
||||
{
|
||||
return qBound(-179, in, 180);
|
||||
}
|
||||
|
||||
void CSituationForm::bankSliderChanged(int value)
|
||||
{
|
||||
const int angle = clampAngle(qRound(this->getBankAngleDegrees()));
|
||||
if (value == angle) { return; } // avoid roundtrips
|
||||
ui->le_Bank->setText(QString::number(value));
|
||||
}
|
||||
|
||||
void CSituationForm::pitchSliderChanged(int value)
|
||||
{
|
||||
const int angle = clampAngle(qRound(this->getPitchAngleDegrees()));
|
||||
if (value == angle) { return; } // avoid roundtrips
|
||||
ui->le_Pitch->setText(QString::number(value));
|
||||
}
|
||||
|
||||
void CSituationForm::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 CSituationForm::resetBank()
|
||||
{
|
||||
ui->le_Bank->setText("0");
|
||||
ui->hs_Bank->setValue(0);
|
||||
}
|
||||
|
||||
void CSituationForm::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 CSituationForm::resetPitch()
|
||||
{
|
||||
ui->le_Pitch->setText("0");
|
||||
ui->hs_Pitch->setValue(0);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
88
src/blackgui/editors/situationform.h
Normal file
88
src/blackgui/editors/situationform.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* Copyright (C) 2017
|
||||
* 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 and at http://www.swift-project.org/license.html. 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_SITUATIONSFORM_H
|
||||
#define BLACKGUI_EDITORS_SITUATIONSFORM_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/editors/form.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include <QScopedPointer>
|
||||
|
||||
class QWidget;
|
||||
|
||||
namespace Ui { class CSituationForm; }
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Editors
|
||||
{
|
||||
/**
|
||||
* Selector / entry
|
||||
*/
|
||||
class BLACKGUI_EXPORT CSituationForm : public CForm
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CSituationForm(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CSituationForm();
|
||||
|
||||
//! Set the situation
|
||||
void setSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Get the situation
|
||||
BlackMisc::Aviation::CAircraftSituation getSituation() const;
|
||||
|
||||
//! \name Form class implementations
|
||||
//! @{
|
||||
virtual void setReadOnly(bool readonly) override;
|
||||
virtual void setSelectOnly() override;
|
||||
virtual BlackMisc::CStatusMessageList validate(bool nested = false) const override;
|
||||
//! @}
|
||||
|
||||
//! Set button visible
|
||||
void showSetButton(bool visible);
|
||||
|
||||
signals:
|
||||
//! Aircraft situation to be changed
|
||||
void changeAircraftSituation();
|
||||
|
||||
private:
|
||||
static constexpr int RoundDigits = 6;
|
||||
|
||||
//! Get bank angle
|
||||
BlackMisc::PhysicalQuantities::CAngle getBankAngle() const;
|
||||
|
||||
//! Get bank angle
|
||||
double getBankAngleDegrees() const;
|
||||
|
||||
//! Get pitch angle
|
||||
BlackMisc::PhysicalQuantities::CAngle getPitchAngle() const;
|
||||
|
||||
//! Get pitch angle
|
||||
double getPitchAngleDegrees() const;
|
||||
|
||||
void bankSliderChanged(int value);
|
||||
void pitchSliderChanged(int value);
|
||||
void bankEntered();
|
||||
void resetBank();
|
||||
void pitchEntered();
|
||||
void resetPitch();
|
||||
|
||||
QScopedPointer<Ui::CSituationForm> ui;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
#endif // guard
|
||||
200
src/blackgui/editors/situationform.ui
Normal file
200
src/blackgui/editors/situationform.ui
Normal file
@@ -0,0 +1,200 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CSituationForm</class>
|
||||
<widget class="QFrame" name="CSituationForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>386</width>
|
||||
<height>324</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_SituationForm">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_Situation">
|
||||
<property name="title">
|
||||
<string>Situation</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QFrame" name="comp_Situation">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gl_Situation" columnstretch="1,1,1,3">
|
||||
<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="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="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="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="1" column="0">
|
||||
<widget class="QLabel" name="lbl_Pitch">
|
||||
<property name="text">
|
||||
<string>Pitch (-179° to 180°):</string>
|
||||
</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="2" column="0">
|
||||
<spacer name="vs_Situation">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</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="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="2" column="3" alignment="Qt::AlignRight">
|
||||
<widget class="QPushButton" name="pb_Set">
|
||||
<property name="text">
|
||||
<string>set</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_Coordinate">
|
||||
<property name="title">
|
||||
<string>Coordinate</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="BlackGui::Editors::CCoordinateForm" name="comp_Coordinate">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BlackGui::Editors::CCoordinateForm</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/editors/coordinateform.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../blackmisc/blackmisc.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -39,7 +39,7 @@ namespace BlackSimPlugin
|
||||
connect(ui->cb_Simulating, &QCheckBox::released, this, &CSimulatorSwiftMonitorDialog::onSimulatorValuesChanged);
|
||||
|
||||
this->setSimulatorUiValues();
|
||||
ui->comp_Position->setCoordinate(m_simulator->getOwnAircraftSituation());
|
||||
ui->comp_Situation->setSituation(m_simulator->getOwnAircraftSituation());
|
||||
}
|
||||
|
||||
CSimulatorSwiftMonitorDialog::~CSimulatorSwiftMonitorDialog()
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tw_SwiftMonitorDialog">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tb_AircraftSituation">
|
||||
<attribute name="title">
|
||||
@@ -25,7 +25,7 @@
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="BlackGui::Components::CCoordinateSelector" name="comp_Position">
|
||||
<widget class="BlackGui::Editors::CSituationForm" name="editor_Situation">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
@@ -174,9 +174,9 @@
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CCoordinateSelector</class>
|
||||
<class>BlackGui::Editors::CSituationForm</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/components/coordinateselector.h</header>
|
||||
<header>blackgui/editors/situationform.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
||||
Reference in New Issue
Block a user