From 32c9cda4b8b8aa4737aba6cbd11fce7bfa4d9532 Mon Sep 17 00:00:00 2001 From: Travis Hunter Date: Sat, 22 Apr 2023 16:29:08 -0600 Subject: [PATCH] adding doxygen comments --- gui/AnalysisWindow.cpp | 7 +- gui/AnalysisWindow.h | 11 +- gui/MainWindow.h | 1 + model/MotorCase.h | 11 +- model/MotorModel.cpp | 6 - model/MotorModel.h | 223 +++++++++++++++------ model/MotorModelDatabase.h | 37 +++- model/Rocket.cpp | 2 +- model/Rocket.h | 13 +- model/{Thrustcurve.cpp => ThrustCurve.cpp} | 14 +- model/{Thrustcurve.h => ThrustCurve.h} | 18 +- qtrocket.pro | 4 +- utils/RSEDatabaseLoader.cpp | 12 +- utils/ThrustCurveAPI.cpp | 7 +- 14 files changed, 250 insertions(+), 116 deletions(-) rename model/{Thrustcurve.cpp => ThrustCurve.cpp} (87%) rename model/{Thrustcurve.h => ThrustCurve.h} (83%) diff --git a/gui/AnalysisWindow.cpp b/gui/AnalysisWindow.cpp index bc8ffd2..9f7afe5 100644 --- a/gui/AnalysisWindow.cpp +++ b/gui/AnalysisWindow.cpp @@ -12,14 +12,9 @@ AnalysisWindow::AnalysisWindow(QWidget *parent) : this->hide(); this->show(); + std::shared_ptr rocket = QtRocket::getInstance()->getRocket(); const std::vector>>& res = rocket->getStates(); - /* - for(const auto& i : res) - { - std::cout << i.first << ": " << "(" << i.second[0] << ", " << i.second[1] << ", " << i.second[2] << ")\n"; - } - */ auto& plot = ui->plotWidget; plot->setInteraction(QCP::iRangeDrag, true); plot->setInteraction(QCP::iRangeZoom, true); diff --git a/gui/AnalysisWindow.h b/gui/AnalysisWindow.h index cab9953..7ff9411 100644 --- a/gui/AnalysisWindow.h +++ b/gui/AnalysisWindow.h @@ -18,14 +18,21 @@ class AnalysisWindow; /** * @brief The AnalysisWindow class. * - * The Analysis Windows class shows a plot of data. This allows visual inspection of - * data + * The Analysis Window class shows a plot of rocket state data. This allows visual inspection of + * flight data such as altitude vs. time. */ class AnalysisWindow : public QDialog { Q_OBJECT public: + /** + * @brief AnalysisWindow constructor. + * @param parent Parent widget + * + * @note The constructor will make a call to QtRocket and grab the current Rocket model + * and automatically plot altitude vs time + */ explicit AnalysisWindow(QWidget *parent = nullptr); ~AnalysisWindow(); diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 7eb286d..68c5be7 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -32,6 +32,7 @@ public: ~MainWindow(); private slots: + void on_actionAbout_triggered(); void on_testButton1_clicked(); diff --git a/model/MotorCase.h b/model/MotorCase.h index 887bd03..efa2afc 100644 --- a/model/MotorCase.h +++ b/model/MotorCase.h @@ -1,15 +1,6 @@ #ifndef MODEL_MOTORCASE_H #define MODEL_MOTORCASE_H -enum class MotorManufacturerEnum -{ - AEROTECH, - CESARONI, - LOKI, - AMW, - ESTES -}; - class MotorCase { public: @@ -20,4 +11,4 @@ private: }; -#endif // MODEL_MOTORCASE_H \ No newline at end of file +#endif // MODEL_MOTORCASE_H diff --git a/model/MotorModel.cpp b/model/MotorModel.cpp index 67496d6..2442a4d 100644 --- a/model/MotorModel.cpp +++ b/model/MotorModel.cpp @@ -9,9 +9,3 @@ MotorModel::~MotorModel() { } - -void MotorModel::setDataFromJsonString(const std::string& jsonString) -{ - -} - diff --git a/model/MotorModel.h b/model/MotorModel.h index 51168ec..00424f1 100644 --- a/model/MotorModel.h +++ b/model/MotorModel.h @@ -8,45 +8,98 @@ // 3rd party headers // For boost serialization. We're using boost::serialize to save -// and load Motor data to file -#include -#include +// and load Motor data to file. (CURRENTLY UNUSED) +//#include +//#include /// \endcond -// qtrocke theaders -#include "Thrustcurve.h" +// qtrocket theaders +#include "ThrustCurve.h" +/** + * @brief The MotorModel class + * + * The MotorModel class defines a structure that holds data relating to a hobby + * rocket motor such as the manufacturer, burn time, maximum thrust, propellant + * weight, etc. It also holds a ThrustCurve object that contains thrust sample data + * for that motor. + * + * There are several additional classes defined within the MotorModel class designed + * to encapsulate and define several pieces of motor related data as well. + */ class MotorModel { public: + /** + * @brief MotorModel constructor + */ MotorModel(); + /** + * @brief MotorModel copy constructor is defaulted + */ MotorModel(const MotorModel&) = default; + /** + * @brief MotorModel move constructor is defaulted + */ MotorModel(MotorModel&&) = default; ~MotorModel(); + /** + * @brief Copy assignment operator is defaulted + * @return Copy of MotorModel + */ MotorModel& operator=(const MotorModel&) = default; + + /** + * @brief Move assignment operator is defaulted + * @return Moved MotorModel + */ MotorModel& operator=(MotorModel&&) = default; - void setDataFromJsonString(const std::string& jsonString); - + /** + * @brief The AVAILABILITY enum class identifies whether a motor is + * out of production, or still available + */ enum class AVAILABILITY { - REGULAR, // available - OOP // Out of Production + REGULAR, /// available + OOP /// Out of Production }; + /** + * @brief The MOTORMANUFACTURER enum class identifies the motor + * manufacturer + */ + enum class MOTORMANUFACTURER + { + AEROTECH, + CESARONI, + LOKI, + AMW, + ESTES, + APOGEE, + UNKNOWN + }; + /** + * @brief The CERTORG enum class identifies the Certification Organization + * that certified the motor + */ enum class CERTORG { - AMRS, - CAR, - NAR, - TRA, - UNC, - UNK + AMRS, /// Australian Model Rocket Society + CAR, /// Canadian Association of Rocketry + NAR, /// National Association of Rocketry + TRA, /// Tripoli + UNC, /// Uncertified + UNK /// Unknown Certification }; + /** + * @brief The MOTORTYPE enum class identifies the motor type, either + * Single-Use, Reload, or Hybrid + */ enum class MOTORTYPE { SU, @@ -54,6 +107,11 @@ public: HYBRID }; + /** + * @brief The MotorAvailability struct wraps the AVAILABILITY enum and + * provides a helper function to return a string representation + * of the AVAILABILITY enum. + */ struct MotorAvailability { MotorAvailability(const AVAILABILITY& a) : availability(a) {} @@ -65,6 +123,10 @@ public: MotorAvailability& operator=(MotorAvailability&&) = default; AVAILABILITY availability{AVAILABILITY::REGULAR}; + /** + * @brief str Returns a string representation of AVAILABILITY enum + * @return string representation + */ std::string str() { if(availability == AVAILABILITY::REGULAR) @@ -74,6 +136,11 @@ public: } }; + /** + * @brief The CertOrg struct wraps the CERTORG enum and + * provides a helper function to return a string representation + * of the CERTORG enum. + */ struct CertOrg { CertOrg(const CERTORG& c) : org(c) {} @@ -85,6 +152,10 @@ public: CertOrg& operator=(CertOrg&&) = default; CERTORG org{CERTORG::UNC}; + /** + * @brief str Returns a string representation of CERTORG enum + * @return string representation + */ std::string str() { if(org == CERTORG::AMRS) @@ -102,6 +173,11 @@ public: } }; + /** + * @brief The MotorType struct wraps the MOTORTYPE enum and + * provides a helper function to return a string representation + * of the MOTORTYPE enum. + */ struct MotorType { MotorType(const MOTORTYPE& t) : type(t) {} @@ -113,6 +189,10 @@ public: MotorType& operator=(MotorType&&) = default; MOTORTYPE type; + /** + * @brief str Returns a string representation of MOTORTYPE enum + * @return string representation + */ std::string str() { if(type == MOTORTYPE::SU) @@ -124,60 +204,79 @@ public: } }; -// TODO: make these private. Public just for testing + /** + * @brief The MotorManufacturer struct wraps the MOTORMANUFACTURER enum and + * provides a helper function to return a string representation + * of the MOTORMANUFACTURER enum. + */ + struct MotorManufacturer + { + MotorManufacturer(const MOTORMANUFACTURER& m) : manufacturer(m) {} + MotorManufacturer() : manufacturer(MOTORMANUFACTURER::UNKNOWN) {} + MotorManufacturer(const MotorManufacturer&) = default; + MotorManufacturer(MotorManufacturer&&) = default; + + MotorManufacturer& operator=(const MotorManufacturer&) = default; + MotorManufacturer& operator=(MotorManufacturer&&) = default; + + MOTORMANUFACTURER manufacturer; + /** + * @brief str Returns a string representation of MOTORMANUFACTURER enum + * @return string representation + */ + std::string str() + { + switch(manufacturer) + { + case MOTORMANUFACTURER::AEROTECH: + return std::string("AeroTech"); + case MOTORMANUFACTURER::AMW: + return std::string("AMW"); + case MOTORMANUFACTURER::CESARONI: + return std::string("Cesaroni"); + case MOTORMANUFACTURER::ESTES: + return std::string("Estes"); + case MOTORMANUFACTURER::LOKI: + return std::string("Loki"); + case MOTORMANUFACTURER::APOGEE: + return std::string("Apogee"); + case MOTORMANUFACTURER::UNKNOWN: + default: + return std::string("Unknown"); + } + } + }; + +/// TODO: make these MotorModel members private. Public just for testing //private: - // Needed for boost serialize - friend class boost::serialization::access; - template - void serialize(Archive& ar, const unsigned int version); - MotorAvailability availability{AVAILABILITY::REGULAR}; - double avgThrust{0.0}; - double burnTime{0.0}; - CertOrg certOrg{CERTORG::UNC}; - std::string commonName{""}; + MotorAvailability availability{AVAILABILITY::REGULAR}; /// Motor Availability + double avgThrust{0.0}; /// Average thrust in Newtons + double burnTime{0.0}; /// Burn time in seconds + CertOrg certOrg{CERTORG::UNC}; /// The certification organization, defaults to Uncertified + std::string commonName{""}; /// Common name, e.g. A8 or J615 // int dataFiles - std::vector delays; // -1 delay means no ejection charge - std::string designation{""}; - double diameter{0}; - std::string impulseClass; // 'A', 'B', '1/2A', 'M', etc - std::string infoUrl{""}; - double length{0.0}; - std::string manufacturer{""}; + std::vector delays; /// 1000 delay means no ejection charge + std::string designation{""}; /// Other name, usually includes prop type, e.g. H110W + double diameter{0}; /// motor diameter in mm + std::string impulseClass; /// Motor letter, e.g. 'A', 'B', '1/2A', 'M', etc + std::string infoUrl{""}; /// TODO: ??? + double length{0.0}; /// motor length in mm + MotorManufacturer manufacturer{MOTORMANUFACTURER::UNKNOWN}; /// Motor Manufacturer - double maxThrust{0.0}; - std::string motorIdTC{""}; // 24 character hex string used by thrustcurve to ID a motor - std::string propType{""}; // black powder, etc - double propWeight{0.0}; - bool sparky{false}; - double totalImpulse{0.0}; - double totalWeight{0.0}; - MotorType type{MOTORTYPE::SU}; - std::string lastUpdated{""}; + double maxThrust{0.0}; /// Max thrust in Newtons + std::string motorIdTC{""}; /// 24 character hex string used by thrustcurve.org to ID a motor + std::string propType{""}; /// Propellant type, e.g. black powder + double propWeight{0.0}; /// Propellant weight in grams + bool sparky{false}; /// true if the motor is "sparky", false otherwise + double totalImpulse{0.0}; /// Total impulse in Newton-seconds + double totalWeight{0.0}; /// Total weight in grams + MotorType type{MOTORTYPE::SU}; /// Motor type, e.g. single-use, reload, or hybrid + std::string lastUpdated{""}; /// Date last updated on ThrustCurve.org // Thrust parameters - Thrustcurve thrust; + ThrustCurve thrust; /// The measured motor thrust curve - // Physical dimensions - }; -template -void MotorModel::serialize(Archive& ar, const unsigned int version) -{ - - ar & manufacturer; - ar & impulseClass; - ar & propType; - ar & sparky; - ar & totalImpulse; - ar & delays; - ar & burnTime; - ar & thrust; - ar & diameter; - ar & length; - ar & totalWeight; - ar & propWeight; -} - #endif // MODEL_MOTORMODEL_H diff --git a/model/MotorModelDatabase.h b/model/MotorModelDatabase.h index 8d0e19c..2588313 100644 --- a/model/MotorModelDatabase.h +++ b/model/MotorModelDatabase.h @@ -1,22 +1,49 @@ #ifndef MOTORMODELDATABASE_H #define MOTORMODELDATABASE_H +/// \cond +// C headers +// C++ headers #include +// 3rd party headers +/// \endcond + +// qtrocket headers #include "model/MotorModel.h" +/** + * @brief The MotorModelDatabase class provides a storage and search mechanism for + * MotorModels + */ class MotorModelDatabase { public: + /** + * @brief MotorModelDatabase constructor + */ MotorModelDatabase(); - std::vector findMotorsByManufacturer(const std::string& manu); + /** + * @brief MotorModelDatabase destructor is defaulted + */ + ~MotorModelDatabase() = default; + /** + * @brief findMotorsByManufacturer returns a vector of MotorModel from a given + * manufacturer + * @param manufacturer The manufacturer to search for + * @return vector of MotorModels from a given manufacturer + */ + std::vector findMotorsByManufacturer(const std::string& manufacturer); + + /** + * @brief findMotersByImpulseClass returns a vector of MotorModels with a given + * impulse class + * @param imClass Impulse class to search for + * @return vector of MotorModels with a given Impulse class + */ std::vector findMotersByImpulseClass(const std::string& imClass); - MotorModel getMotorByName(const std::string& name); - - std::vector> getThrustCurveByName(const std::string& motorName); - private: std::vector motors; diff --git a/model/Rocket.cpp b/model/Rocket.cpp index 180e1b9..883b7a7 100644 --- a/model/Rocket.cpp +++ b/model/Rocket.cpp @@ -36,7 +36,7 @@ double Rocket::getThrust(double t) return tc.getThrust(t); } -void Rocket::setThrustCurve(const Thrustcurve& curve) +void Rocket::setThrustCurve(const ThrustCurve& curve) { tc = curve; } diff --git a/model/Rocket.h b/model/Rocket.h index 066dc61..0cb7473 100644 --- a/model/Rocket.h +++ b/model/Rocket.h @@ -11,12 +11,19 @@ /// \endcond // qtrocket headers -#include "model/Thrustcurve.h" +#include "model/ThrustCurve.h" #include "sim/Propagator.h" +/** + * @brief The Rocket class holds all rocket components + * + */ class Rocket { public: + /** + * @brief Rocket class constructor + */ Rocket(); void launch(); @@ -31,7 +38,7 @@ public: double getDragCoefficient() const { return dragCoeff; } double getThrust(double t); - void setThrustCurve(const Thrustcurve& curve); + void setThrustCurve(const ThrustCurve& curve); bool terminateCondition(const std::pair>& cond); @@ -43,7 +50,7 @@ private: double dragCoeff; double mass; - Thrustcurve tc; + ThrustCurve tc; }; diff --git a/model/Thrustcurve.cpp b/model/ThrustCurve.cpp similarity index 87% rename from model/Thrustcurve.cpp rename to model/ThrustCurve.cpp index 70721a9..a5c4539 100644 --- a/model/Thrustcurve.cpp +++ b/model/ThrustCurve.cpp @@ -7,10 +7,10 @@ // 3rd party headers /// \endcond -#include "Thrustcurve.h" +#include "ThrustCurve.h" -Thrustcurve::Thrustcurve(std::vector>& tc) +ThrustCurve::ThrustCurve(std::vector>& tc) : thrustCurve(tc), maxTime(0.0), ignitionTime(0.0) @@ -23,16 +23,16 @@ Thrustcurve::Thrustcurve(std::vector>& tc) })->first; } -Thrustcurve::Thrustcurve() +ThrustCurve::ThrustCurve() { thrustCurve.emplace_back(0.0, 0.0); maxTime = 0.0; } -Thrustcurve::~Thrustcurve() +ThrustCurve::~ThrustCurve() {} -void Thrustcurve::setThrustCurveVector(const std::vector>& v) +void ThrustCurve::setThrustCurveVector(const std::vector>& v) { thrustCurve.clear(); thrustCurve.resize(v.size()); @@ -45,13 +45,13 @@ void Thrustcurve::setThrustCurveVector(const std::vectorfirst; } -void Thrustcurve::setIgnitionTime(double t) +void ThrustCurve::setIgnitionTime(double t) { ignitionTime = t; //maxTime += ignitionTime; } -double Thrustcurve::getThrust(double t) +double ThrustCurve::getThrust(double t) { // calculate t relative to the start time of the motor t -= ignitionTime; diff --git a/model/Thrustcurve.h b/model/ThrustCurve.h similarity index 83% rename from model/Thrustcurve.h rename to model/ThrustCurve.h index e0d28de..d0b0a5b 100644 --- a/model/Thrustcurve.h +++ b/model/ThrustCurve.h @@ -11,24 +11,24 @@ #include /// \endcond -class Thrustcurve +class ThrustCurve { public: /** * Constructor takes a vector of pairs. The first item a timestamp, * the second the thrust in newtons. */ - Thrustcurve(std::vector>& tc); + ThrustCurve(std::vector>& tc); /** * Default constructor. Will create an empty thrustcurve, always returning 0.0 * for all requested times. */ - Thrustcurve(); - Thrustcurve(const Thrustcurve&) = default; - Thrustcurve(Thrustcurve&&) = default; - ~Thrustcurve(); + ThrustCurve(); + ThrustCurve(const ThrustCurve&) = default; + ThrustCurve(ThrustCurve&&) = default; + ~ThrustCurve(); - Thrustcurve& operator=(const Thrustcurve& rhs) + ThrustCurve& operator=(const ThrustCurve& rhs) { if(this != &rhs) { @@ -39,7 +39,7 @@ public: return *this; } - Thrustcurve& operator=(Thrustcurve&& rhs) + ThrustCurve& operator=(ThrustCurve&& rhs) { thrustCurve = std::move(rhs.thrustCurve); maxTime = std::move(rhs.maxTime); @@ -76,7 +76,7 @@ private: }; template -void Thrustcurve::serialize(Archive& ar, const unsigned int version) +void ThrustCurve::serialize(Archive& ar, const unsigned int version) { ar & maxTime; ar & thrustCurve; diff --git a/qtrocket.pro b/qtrocket.pro index aeb25c4..02a5458 100644 --- a/qtrocket.pro +++ b/qtrocket.pro @@ -21,7 +21,7 @@ SOURCES += \ model/MotorModel.cpp \ model/MotorModelDatabase.cpp \ model/Rocket.cpp \ - model/Thrustcurve.cpp \ + model/ThrustCurve.cpp \ sim/ConstantGravityModel.cpp \ sim/GravityModel.cpp \ sim/Propagator.cpp \ @@ -51,7 +51,7 @@ HEADERS += \ model/MotorModel.h \ model/MotorModelDatabase.h \ model/Rocket.h \ - model/Thrustcurve.h \ + model/ThrustCurve.h \ sim/AtmosphericModel.h \ sim/ConstantAtmosphere.h \ sim/ConstantGravityModel.h \ diff --git a/utils/RSEDatabaseLoader.cpp b/utils/RSEDatabaseLoader.cpp index 09ea04c..80581b2 100644 --- a/utils/RSEDatabaseLoader.cpp +++ b/utils/RSEDatabaseLoader.cpp @@ -59,7 +59,17 @@ void RSEDatabaseLoader::buildAndAppendMotorModel(boost::property_tree::ptree& v) // infoUrl not present in RSE file mm.infoUrl = ""; mm.length = v.get(".len", 0.0); - mm.manufacturer = v.get(".mfg", ""); + { + std::string manufacturer = v.get(".mfg", ""); + MotorModel::MotorManufacturer manu(MotorModel::MOTORMANUFACTURER::UNKNOWN); + if(manufacturer == "Aerotech") + manu = MotorModel::MOTORMANUFACTURER::AEROTECH; + else if(manufacturer == "Animal Motor Works") + manu = MotorModel::MOTORMANUFACTURER::AMW; + else if(manufacturer == "Apogee") + manu = MotorModel::MOTORMANUFACTURER::APOGEE; + mm.manufacturer = manu; + } mm.maxThrust = v.get(".peakThrust", 0.0); mm.propWeight = v.get(".propWt", 0.0); mm.totalImpulse = v.get(".Itot", 0.0); diff --git a/utils/ThrustCurveAPI.cpp b/utils/ThrustCurveAPI.cpp index 8153085..800495c 100644 --- a/utils/ThrustCurveAPI.cpp +++ b/utils/ThrustCurveAPI.cpp @@ -34,8 +34,8 @@ MotorModel ThrustCurveAPI::getMotorData(const std::string& motorId) std::string res = curlConnection.get(endpoint.str(), extraHeaders); + /// TODO: fix this MotorModel mm; - mm.setDataFromJsonString(res); return mm; } @@ -165,7 +165,10 @@ std::vector ThrustCurveAPI::searchMotors(const SearchCriteria& c) mm.diameter = (*iter)["diameter"].asDouble(); mm.impulseClass = (*iter)["impulseClass"].asString(); mm.length = (*iter)["length"].asDouble(); - mm.manufacturer = (*iter)["manufacturer"].asString(); + std::string manu = (*iter)["manufacturer"].asString(); + if(manu == "AeroTech") + mm.manufacturer = MotorModel::MOTORMANUFACTURER::AEROTECH; + //mm.manufacturer = (*iter)["manufacturer"].asString(); mm.maxThrust = (*iter)["maxThrustN"].asDouble(); mm.motorIdTC = (*iter)["motorId"].asString(); mm.propType = (*iter)["propInfo"].asString();