From dbbe07dc8110ca0b045222069c4f76a8c6457196 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 19 Mar 2016 20:49:03 +0100 Subject: [PATCH] refs #622, model set builder. Take own models and generate the set of models used in model matching. Normally configured via GUI. --- src/blackcore/modelsetbuilder.cpp | 52 +++++++++++++++++++++++++++++ src/blackcore/modelsetbuilder.h | 55 +++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/blackcore/modelsetbuilder.cpp create mode 100644 src/blackcore/modelsetbuilder.h diff --git a/src/blackcore/modelsetbuilder.cpp b/src/blackcore/modelsetbuilder.cpp new file mode 100644 index 000000000..2e7d1f2e9 --- /dev/null +++ b/src/blackcore/modelsetbuilder.cpp @@ -0,0 +1,52 @@ +/* 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 "modelsetbuilder.h" +#include "application.h" + +using namespace BlackMisc::Simulation; + +namespace BlackCore +{ + CModelSetBuilder::CModelSetBuilder(QObject *parent) : QObject(parent) + { + // void + } + + CAircraftModelList CModelSetBuilder::buildModelSet(const CAircraftModelList &models, Builder oprions, const CDistributorList &onlyByDistributors) const + { + if (models.isEmpty()) { return CAircraftModelList(); } + CAircraftModelList modelSet; + if (oprions.testFlag(FilterDistributos)) + { + modelSet = models.byDistributor(onlyByDistributors); + } + else + { + modelSet = models; + } + + if (oprions.testFlag(OnlyDbData)) + { + modelSet.removeObjectsWithoutDbKey(); + } + else if (oprions.testFlag(OnlyDbIcaoCodes)) + { + Q_ASSERT_X(sApp->hasWebDataServices(), Q_FUNC_INFO, "No web data services"); + const QStringList designators(sApp->getWebDataServices()->getAircraftIcaoCodes().allIcaoCodes()); + modelSet = modelSet.withAircraftDesignator(designators); + } + else + { + // without any information we can not use them + modelSet = modelSet.withKnownAircraftDesignator(); + } + return modelSet; + } +} diff --git a/src/blackcore/modelsetbuilder.h b/src/blackcore/modelsetbuilder.h new file mode 100644 index 000000000..87224733b --- /dev/null +++ b/src/blackcore/modelsetbuilder.h @@ -0,0 +1,55 @@ +/* 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 BLACKCORE_CMODELSETBUILDER_H +#define BLACKCORE_CMODELSETBUILDER_H + +#include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/simulation/distributorlist.h" +#include "blackcore/blackcoreexport.h" +#include + + +namespace BlackCore +{ + /*! + * Create model set (normally from own models) + */ + class BLACKCORE_EXPORT CModelSetBuilder : public QObject + { + Q_OBJECT + + public: + //! Builder flags + enum BuilderFlag + { + NoOptions = 0, + FilterDistributos = 1 << 0, + OnlyDbData = 1 << 1, + OnlyDbIcaoCodes = 1 << 2 + }; + Q_DECLARE_FLAGS(Builder, BuilderFlag) + + //! Constructor + CModelSetBuilder(QObject *parent = nullptr); + + //! Build a model set + BlackMisc::Simulation::CAircraftModelList buildModelSet( + const BlackMisc::Simulation::CAircraftModelList &models, Builder oprions, + const BlackMisc::Simulation::CDistributorList &onlyByDistributors = BlackMisc::Simulation::CDistributorList()) const; + }; +} // ns + +Q_DECLARE_METATYPE(BlackCore::CModelSetBuilder::BuilderFlag) +Q_DECLARE_METATYPE(BlackCore::CModelSetBuilder::Builder) +Q_DECLARE_OPERATORS_FOR_FLAGS(BlackCore::CModelSetBuilder::Builder) + +#endif // guard