From af1b933e5cc58493ce4a89d4f133bed9cc58a5cb Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 11 Sep 2019 00:27:22 +0200 Subject: [PATCH] Ref T717, model browser --- .../components/modelbrowsercomponent.cpp | 182 ++++++++++ .../components/modelbrowsercomponent.h | 25 ++ .../components/modelbrowsercomponent.ui | 329 +++++++++++++++++- .../components/modelbrowserdialog.cpp | 14 + src/blackgui/components/modelbrowserdialog.h | 7 + src/blackgui/components/modelbrowserdialog.ui | 26 +- 6 files changed, 577 insertions(+), 6 deletions(-) diff --git a/src/blackgui/components/modelbrowsercomponent.cpp b/src/blackgui/components/modelbrowsercomponent.cpp index 048c52aec..ca692d05d 100644 --- a/src/blackgui/components/modelbrowsercomponent.cpp +++ b/src/blackgui/components/modelbrowsercomponent.cpp @@ -8,6 +8,22 @@ #include "modelbrowsercomponent.h" #include "ui_modelbrowsercomponent.h" +#include "blackgui/guiapplication.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextsimulator.h" +#include "blackmisc/aviation/heading.h" +#include "blackmisc/pq/angle.h" +#include "blackmisc/pq/speed.h" + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Simulation; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Geo; +using namespace BlackGui::Editors; +using namespace BlackGui::Views; +using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { @@ -18,11 +34,177 @@ namespace BlackGui ui(new Ui::CModelBrowserComponent) { ui->setupUi(this); + ui->tw_Tab->setCurrentIndex(0); + ui->tvp_AircraftModels->acceptClickSelection(false); + ui->tvp_AircraftModels->acceptDoubleClickSelection(true); + + const CLength relDistance(40.0, CLengthUnit::m()); + ui->editor_RelativePosition->setDistance(relDistance); + + connect(ui->pb_SetRelativePosition, &QPushButton::released, this, &CModelBrowserComponent::onSetRelativePosition, Qt::QueuedConnection); + connect(ui->pb_LoadModelSet, &QPushButton::released, this, &CModelBrowserComponent::loadModelSet, Qt::QueuedConnection); + connect(ui->pb_Display, &QPushButton::released, this, &CModelBrowserComponent::display, Qt::QueuedConnection); + connect(ui->pb_Parts, &QPushButton::released, this, &CModelBrowserComponent::selectTabParts); + connect(ui->pb_Remove, &QPushButton::released, this, &CModelBrowserComponent::remove, Qt::QueuedConnection); + connect(ui->editor_Coordinate, &CCoordinateForm::changedCoordinate, this, &CModelBrowserComponent::onSetAbsolutePosition, Qt::QueuedConnection); + connect(ui->editor_Pbh, &CPbhsForm::changeValues, this, &CModelBrowserComponent::onSetPBH, Qt::QueuedConnection); + connect(ui->editor_AircraftParts, &CAircraftPartsForm::changeAircraftParts, this, &CModelBrowserComponent::onSetParts, Qt::QueuedConnection); + connect(ui->tvp_AircraftModels, &CAircraftModelView::objectDoubleClicked, this, &CModelBrowserComponent::onModelDblClicked, Qt::QueuedConnection); + + connect(ui->cb_OverrideCG, &QCheckBox::clicked, this, &CModelBrowserComponent::onCGChecked); + connect(ui->cb_UseCG, &QCheckBox::clicked, this, &CModelBrowserComponent::onCGChecked); + + this->loadModelSet(); + this->onSetRelativePosition(); } CModelBrowserComponent::~CModelBrowserComponent() { // void } + + void CModelBrowserComponent::close() + { + this->remove(); + } + + void CModelBrowserComponent::onSetRelativePosition() + { + if (!this->hasContexts()) { return; } + const CAircraftSituation s = sGui->getIContextOwnAircraft()->getOwnAircraftSituation(); + ui->editor_RelativePosition->setOriginCoordinate(s); + const CCoordinateGeodetic rel = ui->editor_RelativePosition->getRelativeCoordinate(s.getHeading()); + ui->editor_RelativePosition->displayInfo(rel); + m_situation.setPosition(rel); + } + + void CModelBrowserComponent::onSetAbsolutePosition() + { + m_situation.setPosition(ui->editor_Coordinate->getCoordinate()); + } + + void CModelBrowserComponent::onSetPBH() + { + ui->cb_UsePBH->setChecked(true); + if (!this->hasContexts()) { return; } + this->updatePartsAndPBH(true, false); + } + + void CModelBrowserComponent::onSetParts() + { + ui->cb_UseParts->setChecked(true); + if (!this->hasContexts()) { return; } + this->updatePartsAndPBH(false, true); + } + + CAircraftParts CModelBrowserComponent::getParts() const + { + return ui->editor_AircraftParts->getAircraftPartsFromGui(); + } + + void CModelBrowserComponent::updatePartsAndPBH(bool setPbh, bool setParts) + { + if (!this->hasContexts()) { return; } + CAircraftParts parts = CAircraftParts::null(); + if (setParts) { parts = this->getParts(); } + + if (setPbh) + { + ui->editor_Pbh->updateSituation(m_situation); + } + else + { + m_situation.setZeroPBHandGs(); + } + + sGui->getISimulator()->testSendSituationAndParts(ISimulator::getTestCallsign(), m_situation, parts); + } + + void CModelBrowserComponent::onModelDblClicked(const CVariant &object) + { + Q_UNUSED(object); + this->display(); + } + + void CModelBrowserComponent::display() + { + if (!this->hasContexts()) { return; } + CAircraftModel model = ui->tvp_AircraftModels->selectedObject(); + if (!model.hasModelString()) { return; } + + this->remove(); // only 1 model at a time + + if (ui->cb_OverrideCG->isChecked()) + { + CLength cg; + cg.parseFromString(ui->le_CG->text(), CPqString::SeparatorBestGuess); + if (!cg.isNull()) { model.setCG(cg); } + } + else + { + ui->le_CG->setText(model.getCG().valueRoundedWithUnit(CLengthUnit::ft(), 1)); + } + + m_situation.setZeroPBHandGs(); + if (ui->cb_UsePBH->isChecked()) + { + ui->editor_Pbh->updateSituation(m_situation); + } + + if (ui->cb_UseParts->isChecked()) + { + const CAircraftParts parts = ui->editor_AircraftParts->getAircraftPartsFromGui(); + if (!parts.isNull()) { m_aircraft.setParts(parts); } + } + + m_aircraft.setModel(model); + m_aircraft.setCallsign(ISimulator::getTestCallsign()); + m_aircraft.setSituation(m_situation); + + ui->le_ModelInfo->setText(model.getModelStringAndDbKey()); + ui->le_Info->setText(m_situation.toQString(true)); + + sGui->getIContextSimulator()->testRemoteAircraft(m_aircraft, true); + } + + void CModelBrowserComponent::remove() + { + ui->le_ModelInfo->clear(); + ui->le_Info->clear(); + + if (!this->hasContexts()) { return; } + if (!m_aircraft.hasCallsign()) { return; } + sGui->getIContextSimulator()->testRemoteAircraft(m_aircraft, false); + m_aircraft = CSimulatedAircraft(); // reset + } + + void CModelBrowserComponent::loadModelSet() + { + if (!this->hasContexts()) { return; } + + const CAircraftModelList modelSet = sGui->getIContextSimulator()->getModelSet(); + ui->tvp_AircraftModels->updateContainerMaybeAsync(modelSet); + const QString sim = sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulatorInfo().toQString(true); + ui->lbl_ModelSetInfo->setText(QStringLiteral("'%1' model set with %2 models").arg(sim).arg(modelSet.sizeInt())); + } + + bool CModelBrowserComponent::hasContexts() const + { + if (!sGui || sGui->isShuttingDown()) { return false; } + if (!sGui->getIContextOwnAircraft()) { return false; } + if (!sGui->getIContextSimulator()) { return false; } + return true; + } + + void CModelBrowserComponent::selectTabParts() + { + ui->tw_Tab->setCurrentIndex(1); + } + + void CModelBrowserComponent::onCGChecked(bool checked) + { + if (ui->cb_OverrideCG->isChecked() != checked) { ui->cb_OverrideCG->setChecked(true); } + if (ui->cb_UseCG->isChecked() != checked) { ui->cb_UseCG->setChecked(true); } + } } // ns } // ns diff --git a/src/blackgui/components/modelbrowsercomponent.h b/src/blackgui/components/modelbrowsercomponent.h index 430b46853..61696b022 100644 --- a/src/blackgui/components/modelbrowsercomponent.h +++ b/src/blackgui/components/modelbrowsercomponent.h @@ -14,6 +14,10 @@ #include #include +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/aviation/aircraftsituation.h" +#include "blackmisc/variant.h" + namespace Ui { class CModelBrowserComponent; } namespace BlackGui { @@ -31,8 +35,29 @@ namespace BlackGui //! Destructor virtual ~CModelBrowserComponent() override; + //! Browser has been closed + void close(); + private: + void onSetRelativePosition(); + void onSetAbsolutePosition(); + void onSetPBH(); + void onSetParts(); + void onModelDblClicked(const BlackMisc::CVariant &object); + + BlackMisc::Aviation::CAircraftParts getParts() const; + + void display(); + void remove(); + void loadModelSet(); + bool hasContexts() const; + void selectTabParts(); + void onCGChecked(bool checked); + void updatePartsAndPBH(bool setPbh, bool setParts); + QScopedPointer ui; + BlackMisc::Aviation::CAircraftSituation m_situation; + BlackMisc::Simulation::CSimulatedAircraft m_aircraft; }; } // ns } // ns diff --git a/src/blackgui/components/modelbrowsercomponent.ui b/src/blackgui/components/modelbrowsercomponent.ui index 3a279f55a..aa75cbf4e 100644 --- a/src/blackgui/components/modelbrowsercomponent.ui +++ b/src/blackgui/components/modelbrowsercomponent.ui @@ -6,14 +6,339 @@ 0 0 - 640 - 480 + 343 + 523 Model browser + + + 3 + + + 3 + + + 3 + + + 3 + + + + + 0 + + + + Model and position + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + Model + + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Model set info + + + + + + + load model set + + + + + + + + + + + + + Use + + + + + + use parts + + + + + + + use PBH + + + + + + + use CG (vert.offset) + + + + + + + parts + + + + + + + + + + Relative position + + + + + + + + + set + + + + + + + + + + Absolute position + + + + + + + 0 + 100 + + + + + + + + + + + + PBH/Parts/CG + + + + + + PBH + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + Parts + + + + + + + 0 + 125 + + + + + + + + + + + CG/vertical offset + + + + + + + + + override CG + + + + + + + + + + + + + + + + + true + + + + + + + true + + + + + + + remove + + + + + + + display + + + + + + + + + + BlackGui::Editors::CRelativeAircraftPosition + QFrame +
blackgui/editors/relativeaircraftposition.h
+ 1 +
+ + BlackGui::Editors::CCoordinateForm + QFrame +
blackgui/editors/coordinateform.h
+ 1 +
+ + BlackGui::Views::CAircraftModelView + QTableView +
blackgui/views/aircraftmodelview.h
+
+ + BlackGui::Editors::CAircraftPartsForm + QFrame +
blackgui/editors/aircraftpartsform.h
+ 1 +
+ + BlackGui::Editors::CPbhsForm + QFrame +
blackgui/editors/pbhsform.h
+ 1 +
+
+ + tw_Tab + tvp_AircraftModels + pb_LoadModelSet + cb_UseParts + cb_UsePBH + cb_UseCG + pb_SetRelativePosition + le_Info + le_ModelInfo + pb_Remove + pb_Display + le_CG + cb_OverrideCG + diff --git a/src/blackgui/components/modelbrowserdialog.cpp b/src/blackgui/components/modelbrowserdialog.cpp index 3ade871aa..93502d505 100644 --- a/src/blackgui/components/modelbrowserdialog.cpp +++ b/src/blackgui/components/modelbrowserdialog.cpp @@ -8,6 +8,7 @@ #include "modelbrowserdialog.h" #include "ui_modelbrowserdialog.h" +#include "blackgui/guiapplication.h" namespace BlackGui { @@ -24,5 +25,18 @@ namespace BlackGui { // void; } + + bool CModelBrowserDialog::event(QEvent *event) + { + if (CGuiApplication::triggerShowHelp(this, event)) { return true; } + return QDialog::event(event); + } + + void CModelBrowserDialog::done(int r) + { + ui->comp_ModelBrowser->close(); + QDialog::done(r); + } + } // ns } // ns diff --git a/src/blackgui/components/modelbrowserdialog.h b/src/blackgui/components/modelbrowserdialog.h index dfaee9b42..b9bbd1ba8 100644 --- a/src/blackgui/components/modelbrowserdialog.h +++ b/src/blackgui/components/modelbrowserdialog.h @@ -32,6 +32,13 @@ namespace BlackGui //! Destructor virtual ~CModelBrowserDialog() override; + protected: + //! \copydoc QObject::event + virtual bool event(QEvent *event) override; + + //! \copydoc QDialog::closeEvent + virtual void done(int r) override; + private: QScopedPointer ui; }; diff --git a/src/blackgui/components/modelbrowserdialog.ui b/src/blackgui/components/modelbrowserdialog.ui index 00e62714b..b4ca3b9d4 100644 --- a/src/blackgui/components/modelbrowserdialog.ui +++ b/src/blackgui/components/modelbrowserdialog.ui @@ -6,14 +6,32 @@ 0 0 - 640 - 480 + 675 + 675 + + + 600 + 600 + + Model browser - + + + 4 + + + 4 + + + 4 + + + 4 + @@ -23,7 +41,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Close