From 724b424d6090e6838ffb7668d4ea4dc8468f9093 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 25 Feb 2014 01:11:23 +0100 Subject: [PATCH] refs #146 , added methods to update from data file reader (e.g.) updateFromVatsimDataFileAircraft * updateFromVatsimDataFileStation * updateFromVatsimDataFileAircraft * Changed to 1 line comments //! where applicable --- src/blackmisc/avaircraftlist.cpp | 28 ++++++++++++++++++ src/blackmisc/avaircraftlist.h | 31 +++++++------------- src/blackmisc/avatcstationlist.cpp | 37 +++++++++++++++++++++++ src/blackmisc/avatcstationlist.h | 47 ++++++++++-------------------- 4 files changed, 90 insertions(+), 53 deletions(-) diff --git a/src/blackmisc/avaircraftlist.cpp b/src/blackmisc/avaircraftlist.cpp index 997f0e4c4..3b66a0f2a 100644 --- a/src/blackmisc/avaircraftlist.cpp +++ b/src/blackmisc/avaircraftlist.cpp @@ -4,8 +4,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "avaircraftlist.h" +#include "nwuser.h" #include "predicates.h" + using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Network; namespace BlackMisc { @@ -55,5 +58,30 @@ namespace BlackMisc }); } + /* + * Merge with aircraft + */ + int CAircraftList::updateFromVatsimDataFileAircraft(CAircraft &aircraftToBeUpdated) const + { + if (this->isEmpty()) return 0; + if (aircraftToBeUpdated.hasValidRealName() && aircraftToBeUpdated.hasValidId()) return 0; + + int c = 0; + for (auto i = this->begin(); i != this->end(); ++i) + { + CAircraft currentDataFileAircraft = *i; + if (currentDataFileAircraft.getCallsign() != aircraftToBeUpdated.getCallsign()) continue; + + CUser user = aircraftToBeUpdated.getPilot(); + if (!aircraftToBeUpdated.hasValidRealName()) user.setRealName(currentDataFileAircraft.getPilotRealname()); + if (!aircraftToBeUpdated.hasValidId()) user.setId(currentDataFileAircraft.getPilotId()); + aircraftToBeUpdated.setPilot(user); + c++; + } + + // normally 1 expected, as I should find + // only one online station for this booking + return c; + } } // namespace } // namespace diff --git a/src/blackmisc/avaircraftlist.h b/src/blackmisc/avaircraftlist.h index 7b0b1f8af..24ff61d5b 100644 --- a/src/blackmisc/avaircraftlist.h +++ b/src/blackmisc/avaircraftlist.h @@ -27,46 +27,35 @@ namespace BlackMisc class CAircraftList : public CSequence { public: - /*! - * \brief Default constructor. - */ + //! \brief Default constructor. CAircraftList(); - /*! - * \brief Construct from a base class object. - * \param other - */ + //! \brief Construct from a base class object. CAircraftList(const CSequence &other); - /*! - * \brief QVariant, required for DBus QVariant lists - * \return - */ + //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const { return QVariant::fromValue(*this); } - /*! - * \brief Find 0..n stations by callsign - * \param callsign - * \return - */ + //! \brief Find 0..n stations by callsign CAircraftList findByCallsign(const CCallsign &callsign) const; /*! * \brief Find 0..n stations within range of given coordinate - * \param coordinate - * \param range + * \param coordinate other position + * \param range within range of other position * \return */ CAircraftList findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const; - /*! - * \brief Register metadata - */ + //! \brief Register metadata static void registerMetadata(); + //! \brief Update aircraft with data from VATSIM data file + //! \remarks The list used needs to contain the VATSIM data file objects + int updateFromVatsimDataFileAircraft(CAircraft &aircraftToBeUpdated) const; }; } //namespace diff --git a/src/blackmisc/avatcstationlist.cpp b/src/blackmisc/avatcstationlist.cpp index 2df966feb..ce7c935a0 100644 --- a/src/blackmisc/avatcstationlist.cpp +++ b/src/blackmisc/avatcstationlist.cpp @@ -5,7 +5,9 @@ #include "avatcstationlist.h" #include "predicates.h" + using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Network; namespace BlackMisc { @@ -84,6 +86,7 @@ namespace BlackMisc { int c = 0; bookedAtcStation.setOnline(false); // reset + if (this->isEmpty()) return 0; for (auto i = this->begin(); i != this->end(); ++i) { @@ -157,5 +160,39 @@ namespace BlackMisc return c; } + + /* + * Merge with VATSIM data file + */ + int CAtcStationList::updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const + { + if (this->isEmpty()) return 0; + if (stationToBeUpdated.hasValidRealName() && stationToBeUpdated.hasValidId() && stationToBeUpdated.hasValidFrequency()) return 0; + + int c = 0; + for (auto i = this->begin(); i != this->end(); ++i) + { + CAtcStation currentDataFileStation = *i; + if (currentDataFileStation.getCallsign() != stationToBeUpdated.getCallsign()) continue; + + if (!stationToBeUpdated.hasValidRealName() || !stationToBeUpdated.hasValidId()) + { + CUser user = stationToBeUpdated.getController(); + if (!stationToBeUpdated.hasValidRealName()) user.setRealName(currentDataFileStation.getControllerRealName()); + if (!stationToBeUpdated.hasValidId()) user.setId(currentDataFileStation.getControllerId()); + stationToBeUpdated.setController(user); + } + + if (!stationToBeUpdated.hasValidFrequency()) + { + stationToBeUpdated.setFrequency(currentDataFileStation.getFrequency()); + } + c++; + } + + // normally 1 expected, as I should find + // only one online station for this booking + return c; + } } // namespace } // namespace diff --git a/src/blackmisc/avatcstationlist.h b/src/blackmisc/avatcstationlist.h index 44beeffd2..d652d16e6 100644 --- a/src/blackmisc/avatcstationlist.h +++ b/src/blackmisc/avatcstationlist.h @@ -22,62 +22,45 @@ namespace BlackMisc namespace Aviation { /*! - * Value object encapsulating a list of ATC stations. + * Value object for a list of ATC stations. */ class CAtcStationList : public CSequence { public: - /*! - * \brief Empty constructor. - */ + //! \brief Default constructor. CAtcStationList(); - /*! - * \brief Construct from a base class object. - * \param other - */ + //! \brief Construct from a base class object. CAtcStationList(const CSequence &other); - /*! - * \brief QVariant, required for DBus QVariant lists - * \return - */ + //! \copydoc CValueObject::toQVariant() virtual QVariant toQVariant() const { return QVariant::fromValue(*this); } - /*! - * \brief Find 0..n stations by callsign - */ + //! \brief Find 0..n stations by callsign CAtcStationList findByCallsign(const CCallsign &callsign) const; - /*! - * \brief Find 0..n stations within range of given coordinate - */ + //! \brief Find 0..n stations within range of given coordinate CAtcStationList findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const; - /*! - * \brief Find 0..n stations tune in frequency of COM unit (with 25kHt channel spacing - */ + //! \brief Find 0..n stations tune in frequency of COM unit (with 25kHt channel spacing CAtcStationList findIfComUnitTunedIn25KHz(const BlackMisc::Aviation::CComSystem &comUnit) const; - /*! - * \brief Update distances to coordinate, usually own aircraft's position - */ + //! \brief Update distances to coordinate, usually own aircraft's position void calculateDistancesToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position); - /*! - * \brief Register metadata - */ + //! \brief Register metadata static void registerMetadata(); - /*! - * \brief Merge with ATC station representing booking information - * \param bookedAtcStation - * \return - */ + //! \brief Merge with ATC station representing booking information + //! \remarks Can be used if the stored data in this list are online ATC stations int mergeWithBooking(CAtcStation &bookedAtcStation); + + //! \brief Merge with the data from the VATSIM data file + //! \remarks Can be used if the stored data in this list are VATSIM data file stations + int updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const; }; } //namespace