diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index ab12af40a..c58c89141 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -11,6 +11,7 @@ #include "ui_dbmappingcomponent.h" #include "blackgui/components/dbautostashingcomponent.h" #include "blackgui/components/dbmodelmappingmodifycomponent.h" +#include "blackgui/components/modelmatchercomponent.h" #include "blackgui/guiapplication.h" #include "blackgui/guiutility.h" #include "blackgui/shortcut.h" @@ -68,7 +69,8 @@ namespace BlackGui connect(ui->comp_StashAircraft, &CDbStashComponent::modelsSuccessfullyPublished, this, &CDbMappingComponent::ps_onModelsSuccessfullyPublished); connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onModelSetCountChanged); - connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::tabIndexChanged); + connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::ps_tabIndexChanged); + connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, ui->comp_ModelMatcher , &CModelMatcherComponent::tabIndexChanged); // how to display forms ui->editor_AircraftIcao->setSelectOnly(); @@ -454,6 +456,30 @@ namespace BlackGui } } + void CDbMappingComponent::ps_tabIndexChanged(int index) + { + TabIndex ti = static_cast(index); + + switch (ti) + { + case CDbMappingComponent::TabOwnModelSet: + ui->frp_Editors->setVisible(true); + ui->editor_Model->setVisible(true); + this->resizeForSelect(); + break; + case CDbMappingComponent::TabModelMatcher: + ui->editor_Model->setVisible(false); + ui->frp_Editors->setVisible(false); + this->resizeForSelect(); + break; + default: + ui->frp_Editors->setVisible(true); + ui->editor_Model->setVisible(true); + break; + } + emit this->tabIndexChanged(index); + } + void CDbMappingComponent::ps_onModelsSuccessfullyPublished(const CAircraftModelList &models) { if (models.isEmpty()) { return; } diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 6f86d3def..4d7e3b3bb 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -52,11 +52,12 @@ namespace BlackGui //! Must match real tab index enum TabIndex { - NoValidTab = -1, - TabStash = 0, - TabOwnModels = 1, - TabOwnModelSet = 2, - TabVPilot = 3 + NoValidTab = -1, + TabStash = 0, + TabOwnModels = 1, + TabOwnModelSet = 2, + TabModelMatcher = 3, + TabVPilot = 4 }; //! Constructor @@ -180,6 +181,9 @@ namespace BlackGui //! Stashed models changed void ps_onStashedModelsChanged(); + //! Tab index changed + void ps_tabIndexChanged(int index); + //! Models have been published successfully void ps_onModelsSuccessfullyPublished(const BlackMisc::Simulation::CAircraftModelList &models); diff --git a/src/blackgui/components/dbmappingcomponent.ui b/src/blackgui/components/dbmappingcomponent.ui index 4d824ff5b..61659d244 100644 --- a/src/blackgui/components/dbmappingcomponent.ui +++ b/src/blackgui/components/dbmappingcomponent.ui @@ -164,6 +164,38 @@ + + + Model matcher + + + + 4 + + + 0 + + + 2 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + vPilot rules @@ -439,6 +471,12 @@
blackgui/components/dbownmodelscomponent.h
1 + + BlackGui::Components::CModelMatcherComponent + QFrame +
blackgui/components/modelmatchercomponent.h
+ 1 +
diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index e2d091983..c2456a225 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -40,7 +40,7 @@ namespace BlackGui connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked); connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked); connect(ui->pb_SaveAsSetForSimulator, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked); - connect(&this->m_modelSetLoader, &CModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged); + connect(&this->m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged); connect(ui->tvp_OwnModelSet, &CAircraftModelView::rowCountChanged, this, &CDbOwnModelSetComponent::ps_onRowCountChanged); connect(ui->tvp_OwnModelSet, &CAircraftModelView::jsonModelsForSimulatorLoaded, this, &CDbOwnModelSetComponent::ps_onJsonDataLoaded); @@ -120,18 +120,13 @@ namespace BlackGui CDbMappingComponentAware::setMappingComponent(component); if (component) { - connect(this->getMappingComponent(), &CDbMappingComponent::tabIndexChanged, this, &CDbOwnModelSetComponent::ps_tabChanged); + connect(this->getMappingComponent(), &CDbMappingComponent::tabIndexChanged, this, &CDbOwnModelSetComponent::ps_tabIndexChanged); } } - void CDbOwnModelSetComponent::ps_tabChanged(int index) + void CDbOwnModelSetComponent::ps_tabIndexChanged(int index) { - CDbMappingComponent::TabIndex ti = static_cast(index); - if (ti == CDbMappingComponent::TabOwnModelSet) - { - // myself - this->getMappingComponent()->resizeForSelect(); - } + Q_UNUSED(index); } void CDbOwnModelSetComponent::ps_buttonClicked() diff --git a/src/blackgui/components/dbownmodelsetcomponent.h b/src/blackgui/components/dbownmodelsetcomponent.h index 4a283532e..9a86428a3 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.h +++ b/src/blackgui/components/dbownmodelsetcomponent.h @@ -69,7 +69,7 @@ namespace BlackGui private slots: //! Tab has been changed - void ps_tabChanged(int index); + void ps_tabIndexChanged(int index); //! Button was clicked void ps_buttonClicked(); @@ -94,9 +94,9 @@ namespace BlackGui void setSimulator(const BlackMisc::Simulation::CSimulatorInfo &sim); QScopedPointer ui; - QScopedPointer m_modelSetDialog; - BlackMisc::Simulation::CSimulatorInfo m_simulator; - BlackMisc::Simulation::CModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this }; + QScopedPointer m_modelSetDialog; + BlackMisc::Simulation::CSimulatorInfo m_simulator; + BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this }; //! The menu for loading and handling own models for mapping tasks //! \note This is specific for that very component diff --git a/src/blackgui/components/modelmatchercomponent.cpp b/src/blackgui/components/modelmatchercomponent.cpp new file mode 100644 index 000000000..216231d1b --- /dev/null +++ b/src/blackgui/components/modelmatchercomponent.cpp @@ -0,0 +1,152 @@ +/* Copyright (C) 2016 + * 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 "modelmatchercomponent.h" +#include "guiapplication.h" +#include "guiutility.h" +#include "uppercasevalidator.h" +#include "ui_modelmatchercomponent.h" + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Simulation; +using namespace BlackMisc::Network; +using namespace BlackGui::Models; +using namespace BlackCore; + +namespace BlackGui +{ + namespace Components + { + CModelMatcherComponent::CModelMatcherComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CModelMatcherComponent) + { + Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); + Q_ASSERT_X(sGui->getWebDataServices(), Q_FUNC_INFO, "Missing web services"); + + ui->setupUi(this); + ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons); + ui->comp_AirlineSelector->withIcaoDescription(false); + ui->comp_AircraftSelector->withIcaoDescription(false); + ui->comp_LiverySelector->withLiveryDescription(false); + ui->tvp_ResultMessages->setMode(CStatusMessageListModel::Simplified); + + const CUpperCaseValidator *validator = new CUpperCaseValidator(this); + ui->le_ModelString->setValidator(validator); + ui->le_Manufacturer->setValidator(validator); + + connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CModelMatcherComponent::ps_simulatorChanged); + connect(ui->pb_Test, &QPushButton::pressed, this, &CModelMatcherComponent::ps_test); + connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CModelMatcherComponent::ps_webDataRed); + + const CSimulatorInfo sim(ui->comp_SimulatorSelector->getValue()); + this->m_modelSetLoader.changeSimulator(sim); + this->redisplay(); + } + + CModelMatcherComponent::~CModelMatcherComponent() + { } + + void CModelMatcherComponent::tabIndexChanged(int index) + { + if (index < 0) { return; } + QTabWidget *tw = CGuiUtility::parentTabWidget(this); + Q_ASSERT_X(tw, Q_FUNC_INFO, "Cannot find parent tab widget"); + const QWidget *tabWidget = tw->currentWidget(); + const QWidget *myselfTabWidget = this->parentWidget(); + if (tabWidget != myselfTabWidget) { return; } + this->redisplay(); + } + + void CModelMatcherComponent::ps_simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator) + { + Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); + this->m_modelSetLoader.changeSimulator(simulator); + this->m_matcher.setModelSet(this->m_modelSetLoader.getAircraftModels()); + this->redisplay(); + } + + void CModelMatcherComponent::ps_cacheChanged(CSimulatorInfo &simulator) + { + Q_UNUSED(simulator); + this->redisplay(); + } + + void CModelMatcherComponent::ps_test() + { + ui->te_Results->clear(); + CStatusMessageList msgs; + this->m_matcher.setDefaultModel(CModelMatcherComponent::defaultModel()); + CSimulatedAircraft remoteAircraft(createAircraft()); + const CAircraftModel matched = this->m_matcher.getClosestMatch(remoteAircraft, &msgs); + remoteAircraft.setModel(matched); + ui->te_Results->setText(remoteAircraft.toQString(true)); + ui->tvp_ResultMessages->updateContainer(msgs); + } + + void CModelMatcherComponent::ps_webDataRed(CEntityFlags::Entity entity, CEntityFlags::ReadState state, int number) + { + if (number > 0 && entity.testFlag(CEntityFlags::ModelEntity) && state == CEntityFlags::ReadFinished) + { + QStringList modelStrings(sGui->getWebDataServices()->getModelStrings()); + modelStrings.sort(); + ui->le_ModelString->setCompleter(new QCompleter(modelStrings, this)); + } + } + + void CModelMatcherComponent::redisplay() + { + const int c = this->m_modelSetLoader.getAircraftModelsCount(); + ui->le_ModelSetCount->setText(QString::number(c)); + } + + CSimulatedAircraft CModelMatcherComponent::createAircraft() const + { + const QString airline(ui->comp_AirlineSelector->getRawDesignator()); + const QString aircraft(ui->comp_AircraftSelector->getRawDesignator()); + const QString model(ui->le_ModelString->text().trimmed().toUpper()); + const QString combined(ui->comp_CombinedCode->getCombinedType()); + const QString manufacturer(ui->le_Manufacturer->text().trimmed().toUpper()); + + CCallsign cs("SWIFT"); + CSimulatedAircraft sa; + if (!model.isEmpty()) + { + const CAircraftModel m(model, CAircraftModel::TypeFsdData); + sa = CSimulatedAircraft(m); + } + sa.setCallsign(cs); + + if (!aircraft.isEmpty()) + { + CAircraftIcaoCode icao(aircraft, combined); + icao.setManufacturer(manufacturer); + sa.setAircraftIcaoCode(icao); + } + if (!airline.isEmpty()) + { + const CAirlineIcaoCode al(airline); + const CLivery l(CLivery::getStandardCode(al), al, "Standard"); + sa.setLivery(l); + } + return sa; + } + + CAircraftModel CModelMatcherComponent::defaultModel() const + { + // can somehow dynamilcally determine the models + const CAircraftIcaoCode icaoAircraft("B737", "L2J", "FooBar", "Dummy", "M", false, false, false, 1); + const CAirlineIcaoCode icaoAirline("Foo", "FooBar airlines", { "DE", "Germany" }, "FOO", true, true); + const CLivery livery(CLivery::getStandardCode(icaoAirline), icaoAirline, "Standard Foo airlines", "red", "blue", false); + const CAircraftModel model("default model", CAircraftModel::TypeOwnSimulatorModel, "dummy model", icaoAircraft, livery); + return model; + } + } // ns +} // ns diff --git a/src/blackgui/components/modelmatchercomponent.h b/src/blackgui/components/modelmatchercomponent.h new file mode 100644 index 000000000..bc4faa2c2 --- /dev/null +++ b/src/blackgui/components/modelmatchercomponent.h @@ -0,0 +1,78 @@ +/* Copyright (C) 2016 + * 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_COMPONENT_MODELMATCHERCOMPONENT_H +#define BLACKGUI_COMPONENT_MODELMATCHERCOMPONENT_H + +#include "blackgui/blackguiexport.h" +#include "blackmisc/simulation/aircraftmodelsetloader.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/simulation/aircraftmatcher.h" +#include "blackmisc/network/entityflags.h" + +#include +#include + +namespace Ui { class CModelMatcherComponent; } + +namespace BlackGui +{ + namespace Components + { + /*! + * Model matcher testing and configuration + */ + class BLACKGUI_EXPORT CModelMatcherComponent : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CModelMatcherComponent(QWidget *parent = nullptr); + + //! Destructor + ~CModelMatcherComponent(); + + public slots: + //! Tab where this is embedded has been changed + void tabIndexChanged(int index); + + private slots: + //! Simulator switched + void ps_simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); + + //! Cache changed + void ps_cacheChanged(BlackMisc::Simulation::CSimulatorInfo &simulator); + + //! Run the matcher + void ps_test(); + + //! Web data have been read + void ps_webDataRed(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); + + private: + //! Init + void redisplay(); + + //! Pseudo aircraft created from entries + BlackMisc::Simulation::CSimulatedAircraft createAircraft() const; + + //! Pseudo default aircraft + BlackMisc::Simulation::CAircraftModel defaultModel() const; + + QScopedPointer ui; + BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this }; + BlackMisc::Simulation::CAircraftMatcher m_matcher { BlackMisc::Simulation::CAircraftMatcher::All, this }; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/modelmatchercomponent.ui b/src/blackgui/components/modelmatchercomponent.ui new file mode 100644 index 000000000..e2f3a6026 --- /dev/null +++ b/src/blackgui/components/modelmatchercomponent.ui @@ -0,0 +1,250 @@ + + + CModelMatcherComponent + + + + 0 + 0 + 324 + 318 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 100 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + true + + + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 100 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Model: + + + + + + + Aircraft: + + + + + + + Airline: + + + + + + + model string + + + + + + + Simulator: + + + + + + + Combined: + + + + + + + Livery: + + + + + + + Run + + + + + + + true + + + + + + + Model set: + + + + + + + Manufacturer: + + + + + + + + + + + BlackGui::Components::CDbAirlineIcaoSelectorComponent + QFrame +
blackgui/components/dbairlineicaoselectorcomponent.h
+ 1 +
+ + BlackGui::Components::CDbLiverySelectorComponent + QFrame +
blackgui/components/dbliveryselectorcomponent.h
+ 1 +
+ + BlackGui::Components::CAircraftCombinedTypeSelector + QFrame +
blackgui/components/aircraftcombinedtypeselector.h
+ 1 +
+ + BlackGui::Components::CDbAircraftIcaoSelectorComponent + QFrame +
blackgui/components/dbaircrafticaoselectorcomponent.h
+ 1 +
+ + BlackGui::Components::CSimulatorSelector + QFrame +
blackgui/components/simulatorselector.h
+ 1 +
+ + BlackGui::Views::CStatusMessageView + QTableView +
blackgui/views/statusmessageview.h
+
+
+ + +