Added QtRocket custome Motor Database format (xml)

This commit is contained in:
Travis Hunter 2023-05-04 16:31:51 -06:00
parent 47919b661f
commit 10c552e086
7 changed files with 104 additions and 6 deletions

View File

@ -83,6 +83,8 @@ QtRocket::QtRocket()
rocket.first =
std::make_shared<Rocket>();
motorDatabase = std::make_shared<utils::MotorModelDatabase>();
}
int QtRocket::run(int argc, char* argv[])
@ -105,5 +107,6 @@ void QtRocket::addMotorModels(std::vector<model::MotorModel>& m)
{
motorModels.push_back(i);
}
motorDatabase->addMotorModels(motorModels);
// TODO: Now clear any duplicates?
}

View File

@ -49,6 +49,10 @@ MainWindow::MainWindow(QtRocket* _qtRocket, QWidget *parent)
SLOT(onMenu_Edit_SimulationOptions_triggered()));
// Tools Menu Actions
connect(ui->actionSaveMotorDatabase,
SIGNAL(triggered()),
this,
SLOT(onMenu_Tools_SaveMotorDatabase()));
// Help Menu Actions
connect(ui->actionAbout,
@ -95,6 +99,11 @@ void MainWindow::onMenu_Help_About_triggered()
}
void MainWindow::onMenu_Tools_SaveMotorDatabase()
{
qtRocket->getMotorDatabase()->saveMotorDatabase("qtrocket_motors.qmd");
}
void MainWindow::onButton_calculateTrajectory_clicked()
{

View File

@ -51,6 +51,8 @@ private slots:
void onMenu_File_Quit_triggered();
void onMenu_Tools_SaveMotorDatabase();
private:
Ui::MainWindow* ui;
QtRocket* qtRocket;

View File

@ -253,6 +253,7 @@
<property name="title">
<string>Tools</string>
</property>
<addaction name="actionSaveMotorDatabase"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
@ -345,6 +346,11 @@
<string>Simulation Options</string>
</property>
</action>
<action name="actionSaveMotorDatabase">
<property name="text">
<string>Save Motor Database</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -134,7 +134,7 @@ public:
* @brief str Returns a string representation of AVAILABILITY enum
* @return string representation
*/
std::string str()
std::string str() const
{
if(availability == AVAILABILITY::REGULAR)
return std::string("regular");
@ -176,7 +176,7 @@ public:
* @brief str Returns a string representation of CERTORG enum
* @return string representation
*/
std::string str()
std::string str() const
{
if(org == CERTORG::AMRS)
return std::string("Austrialian Model Rocket Society Inc.");
@ -235,7 +235,7 @@ public:
* @brief str Returns a string representation of MOTORTYPE enum
* @return string representation
*/
std::string str()
std::string str() const
{
if(type == MOTORTYPE::SU)
return std::string("Single Use");
@ -253,10 +253,12 @@ public:
static MOTORTYPE toEnum(const std::string& name)
{
if(name == "SU" ||
name == "Single Use")
name == "Single Use" ||
name == "single-use")
return MOTORTYPE::SU;
else if(name == "reload" ||
name == "Reload")
name == "Reload" ||
name == "reloadable")
return MOTORTYPE::RELOAD;
else // It's a hybrid
return MOTORTYPE::HYBRID;
@ -284,7 +286,7 @@ public:
* @brief str Returns a string representation of MOTORMANUFACTURER enum
* @return string representation
*/
std::string str()
std::string str() const
{
switch(manufacturer)
{

View File

@ -5,6 +5,8 @@
// C headers
// C++ headers
// 3rd party headers
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
/// \endcond
// qtrocket project headers
@ -63,4 +65,75 @@ std::optional<model::MotorModel> MotorModelDatabase::getMotorModel(const std::st
}
}
void MotorModelDatabase::saveMotorDatabase(const std::string& filename)
{
/*
<MotorDatabase>
<version>1.0</version>
<MotorModels>
<model name="XYZ">
<totalWeight>10.0</totalWeight>
<totalImpulse>123.4</totalImpulse>
</model>
</MotorModels>
</MotorDatabase>
*/
namespace pt = boost::property_tree;
// top-level tree
pt::ptree tree;
tree.put("QtRocketMotorDatabase.<xmlattr>.version", "0.1");
for(const auto& i : motorModelMap)
{
pt::ptree motor;
const auto& m = i.second;
motor.put("<xmlattr>.name", m.data.commonName);
motor.put("availability", m.data.availability.str());
motor.put("avgThrust", m.data.avgThrust);
motor.put("burnTime", m.data.burnTime);
motor.put("certOrg", m.data.certOrg.str());
motor.put("commonName", m.data.commonName);
motor.put("designation", m.data.designation);
motor.put("diameter", m.data.diameter);
motor.put("impulseClass", m.data.impulseClass);
motor.put("infoUrl", m.data.infoUrl);
motor.put("length", m.data.length);
motor.put("manufacturer", m.data.manufacturer.str());
motor.put("maxThrust", m.data.maxThrust);
motor.put("motorIdTC", m.data.motorIdTC);
motor.put("propType", m.data.propType);
motor.put("sparky", m.data.sparky ? "true" : "false");
motor.put("totalImpulse", m.data.totalImpulse);
motor.put("totalWeight", m.data.totalWeight);
motor.put("type", m.data.type.str());
motor.put("lastUpdated", m.data.lastUpdated);
// thrust data
{
pt::ptree tc;
std::vector<std::pair<double, double>> thrust = m.getThrustCurve().getThrustCurveData();
for(const auto& j : thrust)
{
pt::ptree thrustNode;
thrustNode.put("<xmlattr>.time", j.first);
thrustNode.put("<xmlattr>.force", j.second);
tc.add_child("thrust", thrustNode);
}
motor.add_child("thrustCurve", tc);
}
tree.add_child("QtRocketMotorDatabase.MotorModels.motor", motor);
}
pt::xml_writer_settings<std::string> settings(' ', 2);
pt::write_xml(filename, tree, std::locale(), settings);
}
void MotorModelDatabase::loadMotorDatabase(const std::string& filename)
{
}
} // namespace utils

View File

@ -59,6 +59,9 @@ public:
* @return std::optional<model::MotorModel>
*/
std::optional<model::MotorModel> getMotorModel(const std::string& name);
void saveMotorDatabase(const std::string& filename);
void loadMotorDatabase(const std::string& filename);
private:
// The "database" is really just a map. :)