96 lines
2.3 KiB
C++
96 lines
2.3 KiB
C++
|
|
/// \cond
|
|
// C headers
|
|
// C++ headers
|
|
#include <algorithm>
|
|
// 3rd party headers
|
|
/// \endcond
|
|
|
|
// qtrocket headers
|
|
#include "ThrustCurveMotorSelector.h"
|
|
#include "ui_ThrustCurveMotorSelector.h"
|
|
#include "QtRocket.h"
|
|
|
|
ThrustCurveMotorSelector::ThrustCurveMotorSelector(QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::ThrustCurveMotorSelector),
|
|
tcApi(new utils::ThrustCurveAPI)
|
|
{
|
|
ui->setupUi(this);
|
|
this->setWindowModality(Qt::NonModal);
|
|
this->hide();
|
|
this->show();
|
|
}
|
|
|
|
ThrustCurveMotorSelector::~ThrustCurveMotorSelector()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void ThrustCurveMotorSelector::on_getMetadata_clicked()
|
|
{
|
|
// When the user clicks "Get Metadata", we want to pull in Metadata from thrustcurve.org
|
|
// and populate the Manufacturer, Diameter, and Impulse Class combo boxes
|
|
|
|
utils::ThrustcurveMetadata metadata = tcApi->getMetadata();
|
|
|
|
for(const auto& i : metadata.diameters)
|
|
{
|
|
ui->diameter->addItem(QString::number(i));
|
|
}
|
|
|
|
for(const auto& i : metadata.manufacturers)
|
|
{
|
|
ui->manufacturer->addItem(QString::fromStdString(i.first));
|
|
}
|
|
for(const auto& i : metadata.impulseClasses)
|
|
{
|
|
ui->impulseClass->addItem(QString::fromStdString(i));
|
|
}
|
|
}
|
|
|
|
|
|
void ThrustCurveMotorSelector::on_searchButton_clicked()
|
|
{
|
|
|
|
//double diameter = ui->diameter->
|
|
|
|
std::string diameter = ui->diameter->currentText().toStdString();
|
|
std::string manufacturer = ui->manufacturer->currentText().toStdString();
|
|
std::string impulseClass = ui->impulseClass->currentText().toStdString();
|
|
|
|
utils::SearchCriteria c;
|
|
c.addCriteria("diameter", diameter);
|
|
c.addCriteria("manufacturer", manufacturer);
|
|
c.addCriteria("impulseClass", impulseClass);
|
|
|
|
std::vector<model::MotorModel> motors = tcApi->searchMotors(c);
|
|
std::copy(std::begin(motors), std::end(motors), std::back_inserter(motorModels));
|
|
|
|
for(const auto& i : motors)
|
|
{
|
|
ui->motorSelection->addItem(QString::fromStdString(i.commonName));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void ThrustCurveMotorSelector::on_setMotor_clicked()
|
|
{
|
|
//asdf
|
|
std::string commonName = ui->motorSelection->currentText().toStdString();
|
|
|
|
// get motor
|
|
|
|
model::MotorModel mm = *std::find_if(
|
|
std::begin(motorModels),
|
|
std::end(motorModels),
|
|
[&commonName](const auto& item)
|
|
{
|
|
return item.commonName == commonName;
|
|
});
|
|
|
|
QtRocket::getInstance()->getRocket()->setMotorModel(mm);
|
|
}
|
|
|