From 8eedfcec496471cd9b1848c7aac31db6ff44320d Mon Sep 17 00:00:00 2001 From: m_thread Date: Wed, 18 Mar 2015 00:32:42 +0100 Subject: [PATCH] OP-1763 Added import functionality to the template dialog. Added new tab and gui with template selector widget to the export template dialog. Renamed dialog menu to export/import vehicle wizard settings. Added code to upload and save template data to board. --- .../pages/airframeinitialtuningpage.cpp | 3 +- .../plugins/setupwizard/setupwizardplugin.cpp | 4 +- .../vehicletemplateexportdialog.cpp | 74 +- .../setupwizard/vehicletemplateexportdialog.h | 6 +- .../vehicletemplateexportdialog.ui | 1055 +++++++++-------- .../vehicletemplateselectorwidget.cpp | 5 +- .../vehicletemplateselectorwidget.h | 3 +- 7 files changed, 659 insertions(+), 491 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp index 81ade3cca..87004a010 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/airframeinitialtuningpage.cpp @@ -47,7 +47,8 @@ AirframeInitialTuningPage::~AirframeInitialTuningPage() void AirframeInitialTuningPage::initializePage() { - const char* path; + const char *path; + switch (getWizard()->getVehicleType()) { case VehicleConfigurationSource::VEHICLE_FIXEDWING: path = VehicleTemplateExportDialog::EXPORT_FIXEDWING_NAME; diff --git a/ground/openpilotgcs/src/plugins/setupwizard/setupwizardplugin.cpp b/ground/openpilotgcs/src/plugins/setupwizard/setupwizardplugin.cpp index f6c5505b1..a23c02cf2 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/setupwizardplugin.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/setupwizardplugin.cpp @@ -59,7 +59,7 @@ bool SetupWizardPlugin::initialize(const QStringList & args, QString *errMsg) QList() << Core::Constants::C_GLOBAL_ID); cmd->setDefaultKeySequence(QKeySequence("Ctrl+V")); - cmd->action()->setText(tr("Vehicle Setup Wizard")); + cmd->action()->setText(tr("Vehicle Setup Wizard...")); connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(showSetupWizard())); Core::ModeManager::instance()->addAction(cmd, 1); @@ -71,7 +71,7 @@ bool SetupWizardPlugin::initialize(const QStringList & args, QString *errMsg) "SetupWizardPlugin.ExportJSon", QList() << Core::Constants::C_GLOBAL_ID); - cmd->action()->setText(tr("Export Wizard Vehicle Template")); + cmd->action()->setText(tr("Export/Import Wizard Vehicle Template...")); connect(cmd->action(), SIGNAL(triggered(bool)), this, SLOT(exportSettings())); Core::ModeManager::instance()->addAction(cmd, 1); diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp index 2563f961c..787ac6240 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.cpp @@ -37,12 +37,15 @@ #include #include #include +#include +#include #include "stabilizationsettings.h" #include "stabilizationsettingsbank1.h" #include "stabilizationsettingsbank2.h" #include "stabilizationsettingsbank3.h" #include "mixersettings.h" #include "ekfconfiguration.h" +#include const char *VehicleTemplateExportDialog::EXPORT_BASE_NAME = "../share/openpilotgcs/cloudconfig"; const char *VehicleTemplateExportDialog::EXPORT_FIXEDWING_NAME = "fixedwing"; @@ -61,12 +64,24 @@ VehicleTemplateExportDialog::VehicleTemplateExportDialog(QWidget *parent) : m_uavoManager = pm->getObject(); ui->Photo->setScene(new QGraphicsScene(this)); ui->Type->setText(setupVehicleType()); + ui->selectionWidget->setTemplateInfo(m_dir, m_type, m_subType); connect(ui->Name, SIGNAL(textChanged(QString)), this, SLOT(updateStatus())); connect(ui->Owner, SIGNAL(textChanged(QString)), this, SLOT(updateStatus())); connect(ui->ForumNick, SIGNAL(textChanged(QString)), this, SLOT(updateStatus())); connect(ui->Size, SIGNAL(textChanged(QString)), this, SLOT(updateStatus())); connect(ui->Weight, SIGNAL(textChanged(QString)), this, SLOT(updateStatus())); + + connect(ui->exportBtn, SIGNAL(clicked()), this, SLOT(exportTemplate())); + connect(ui->importBtn, SIGNAL(clicked()), this, SLOT(importTemplate())); + connect(ui->cancelBtn, SIGNAL(clicked()), this, SLOT(reject())); + connect(ui->cancelBtn_2, SIGNAL(clicked()), this, SLOT(reject())); + + TelemetryManager *telemManager = pm->getObject(); + ui->importBtn->setEnabled(telemManager->isConnected()); + + connect(telemManager, SIGNAL(connected()), this, SLOT(onAutoPilotConnect())); + connect(telemManager, SIGNAL(disconnected()), this, SLOT(onAutoPilotDisconnect())); } VehicleTemplateExportDialog::~VehicleTemplateExportDialog() @@ -85,85 +100,102 @@ QString VehicleTemplateExportDialog::setupVehicleType() case SystemSettings::AIRFRAMETYPE_FIXEDWING: m_type = VehicleConfigurationSource::VEHICLE_FIXEDWING; m_subType = VehicleConfigurationSource::FIXED_WING_AILERON; + m_dir = EXPORT_FIXEDWING_NAME; return tr("Fixed Wing - Aileron"); case SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON: m_type = VehicleConfigurationSource::VEHICLE_FIXEDWING; m_subType = VehicleConfigurationSource::FIXED_WING_ELEVON; + m_dir = EXPORT_FIXEDWING_NAME; return tr("Fixed Wing - Elevon"); case SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL: m_type = VehicleConfigurationSource::VEHICLE_FIXEDWING; m_subType = VehicleConfigurationSource::FIXED_WING_VTAIL; + m_dir = EXPORT_FIXEDWING_NAME; return tr("Fixed Wing - V-Tail"); case SystemSettings::AIRFRAMETYPE_HELICP: m_type = VehicleConfigurationSource::VEHICLE_HELI; m_subType = VehicleConfigurationSource::HELI_CCPM; + m_dir = EXPORT_HELI_NAME; return tr("Helicopter"); case SystemSettings::AIRFRAMETYPE_TRI: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_TRI_Y; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Tricopter"); case SystemSettings::AIRFRAMETYPE_QUADX: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_QUAD_X; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Quadrocopter X"); case SystemSettings::AIRFRAMETYPE_QUADP: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Quadrocopter +"); case SystemSettings::AIRFRAMETYPE_OCTOV: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO_V; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Octocopter V"); case SystemSettings::AIRFRAMETYPE_OCTOCOAXX: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Octocopter X8X"); case SystemSettings::AIRFRAMETYPE_OCTOCOAXP: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Octocopter X8+"); case SystemSettings::AIRFRAMETYPE_OCTO: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Octocopter +"); case SystemSettings::AIRFRAMETYPE_OCTOX: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_OCTO_X; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Octocopter X"); case SystemSettings::AIRFRAMETYPE_HEXAX: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_HEXA_X; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Hexacopter X"); case SystemSettings::AIRFRAMETYPE_HEXAH: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_HEXA_H; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Hexacopter H"); case SystemSettings::AIRFRAMETYPE_HEXACOAX: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Hexacopter Y6"); case SystemSettings::AIRFRAMETYPE_HEXA: m_type = VehicleConfigurationSource::VEHICLE_MULTI; m_subType = VehicleConfigurationSource::MULTI_ROTOR_HEXA; + m_dir = EXPORT_MULTI_NAME; return tr("Multirotor - Hexacopter +"); default: m_type = VehicleConfigurationSource::VEHICLE_UNKNOWN; + m_dir = ""; return tr("Unsupported"); } } @@ -178,7 +210,7 @@ QString VehicleTemplateExportDialog::fixFilenameString(QString input, int trunca .left(truncate); } -void VehicleTemplateExportDialog::accept() +void VehicleTemplateExportDialog::exportTemplate() { QJsonObject exportObject; @@ -257,6 +289,34 @@ void VehicleTemplateExportDialog::accept() } } +void VehicleTemplateExportDialog::importTemplate() +{ + QJsonObject *tmpl = ui->selectionWidget->selectedTemplate(); + + if (tmpl != NULL) { + QList updatedObjects; + m_uavoManager->fromJson(*tmpl, &updatedObjects); + UAVObjectUpdaterHelper helper; + foreach(UAVObject * object, updatedObjects) { + UAVDataObject *dataObj = dynamic_cast(object); + + if (dataObj != NULL && dataObj->isKnown()) { + helper.doObjectAndWait(dataObj); + + ObjectPersistence *objper = ObjectPersistence::GetInstance(m_uavoManager); + ObjectPersistence::DataFields data; + data.Operation = ObjectPersistence::OPERATION_SAVE; + data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT; + data.ObjectID = dataObj->getObjID(); + data.InstanceID = dataObj->getInstID(); + objper->setData(data); + + helper.doObjectAndWait(objper); + } + } + } +} + void VehicleTemplateExportDialog::importImage() { QString fileName = QFileDialog::getOpenFileName(this, tr("Import Image"), "", tr("Images (*.png *.jpg)")); @@ -269,6 +329,16 @@ void VehicleTemplateExportDialog::importImage() } } +void VehicleTemplateExportDialog::onAutoPilotConnect() +{ + ui->importBtn->setEnabled(true); +} + +void VehicleTemplateExportDialog::onAutoPilotDisconnect() +{ + ui->importBtn->setEnabled(false); +} + QString VehicleTemplateExportDialog::getTypeDirectory() { switch (m_type) { @@ -291,7 +361,7 @@ QString VehicleTemplateExportDialog::getTypeDirectory() void VehicleTemplateExportDialog::updateStatus() { - ui->acceptBtn->setEnabled(ui->Name->text().length() > 3 && ui->Owner->text().length() > 2 && + ui->exportBtn->setEnabled(ui->Name->text().length() > 3 && ui->Owner->text().length() > 2 && ui->ForumNick->text().length() > 2 && ui->Size->text().length() > 0 && ui->Weight->text().length() > 0); } diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h index 02bf48949..15de6b23b 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.h @@ -51,11 +51,14 @@ public: ~VehicleTemplateExportDialog(); public slots: - void accept(); + void exportTemplate(); + void importTemplate(); void updateStatus(); private slots: void importImage(); + void onAutoPilotConnect(); + void onAutoPilotDisconnect(); private: static const int IMAGE_SCALE_WIDTH = 500; @@ -64,6 +67,7 @@ private: UAVObjectManager *m_uavoManager; VehicleConfigurationSource::VEHICLE_TYPE m_type; VehicleConfigurationSource::VEHICLE_SUB_TYPE m_subType; + const char *m_dir; QPixmap m_image; QString fixFilenameString(QString input, int truncate = 100); diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.ui b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.ui index 7de829b28..68b51263f 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.ui +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateexportdialog.ui @@ -35,6 +35,570 @@ true + + + + 0 + + + + Export template + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Weight: + + + + + + + Size and angle + + + + + + + Battery: + + + + + + + Size of the vehicle in mm + + + + + + + Motor: + + + + + + + Name: + + + + + + + Servo: + + + + + + + Brand and name + + + + + + + Your name + + + + + + + Propeller: + + + + + + + Forum name: + + + + + + + Qt::Horizontal + + + + + + + The name of the vehicle, brand etc + + + + + + + Owner: + + + + + + + Brand, size and Kv + + + + + + + Size: + + + + + + + How many cells etc? + + + + + + + Controller: + + + + + + + false + + + background-color: rgba(255, 255, 255, 0); + + + false + + + true + + + + + + + ESC: + + + + + + + + None + + + + + CC + + + + + CC3D + + + + + Atom + + + + + Revolution + + + + + Nano + + + + + + + + Type: + + + + + + + Forum nickname + + + + + + + Brand and name + + + + + + + Weight in grams + + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Comment: + + + + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + Put comments here that don't fit in the categories above + + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Photo: + + + + + + + + 0 + 0 + + + + background-color: rgba(254, 254, 254, 0); + + + QFrame::NoFrame + + + QFrame::Sunken + + + + + 0 + 0 + 0 + + + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 8 + + + + Photo will be scaled to 500x500px + + + + + + + Select Image... + + + + + + + + + + + frame_4 + frame_3 + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + false + + + Export + + + + + + + + + + + Import template + + + + + + + 0 + 0 + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + false + + + Import + + + + + + + + + + @@ -56,490 +620,19 @@ 0 - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Plain - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Weight: - - - - - - - Size and angle - - - - - - - Battery: - - - - - - - Size of the vehicle in mm - - - - - - - Motor: - - - - - - - Name: - - - - - - - Servo: - - - - - - - Brand and name - - - - - - - Your name - - - - - - - Propeller: - - - - - - - Forum name: - - - - - - - Qt::Horizontal - - - - - - - The name of the vehicle, brand etc - - - - - - - Owner: - - - - - - - Brand, size and Kv - - - - - - - Size: - - - - - - - How many cells etc? - - - - - - - Controller: - - - - - - - false - - - background-color: rgba(255, 255, 255, 0); - - - false - - - true - - - - - - - ESC: - - - - - - - - None - - - - - CC - - - - - CC3D - - - - - Atom - - - - - Revolution - - - - - Nano - - - - - - - - Type: - - - - - - - Forum nickname - - - - - - - Brand and name - - - - - - - Weight in grams - - - - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Comment: - - - - - - - - 0 - 0 - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - - - Put comments here that don't fit in the categories above - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Photo: - - - - - - - - 0 - 0 - - - - background-color: rgba(254, 254, 254, 0); - - - QFrame::NoFrame - - - QFrame::Sunken - - - - - 0 - 0 - 0 - - - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 8 - - - - Photo will be scaled to 500x500px - - - - - - - Select Image... - - - - - - - - - - - frame_4 - frame_3 - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Cancel - - - - - - - false - - - Export - - - + + + VehicleTemplateSelectorWidget + QWidget +
vehicletemplateselectorwidget.h
+ 1 +
+
Type Name @@ -555,7 +648,7 @@ Controllers Comment ImportButton - acceptBtn + exportBtn cancelBtn Photo @@ -578,7 +671,7 @@ - acceptBtn + exportBtn clicked() VehicleTemplateExportDialog accept() diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateselectorwidget.cpp b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateselectorwidget.cpp index a3d3c0571..0f1016ccf 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateselectorwidget.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateselectorwidget.cpp @@ -54,9 +54,10 @@ VehicleTemplateSelectorWidget::~VehicleTemplateSelectorWidget() delete ui; } -void VehicleTemplateSelectorWidget::setTemplateInfo(QString path, int vehicleType, int vehicleSubType) { +void VehicleTemplateSelectorWidget::setTemplateInfo(QString path, int vehicleType, int vehicleSubType) +{ m_templateFolder = path; - m_vehicleType = vehicleType; + m_vehicleType = vehicleType; m_vehicleSubType = vehicleSubType; updateTemplates(); } diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateselectorwidget.h b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateselectorwidget.h index 4d0205847..a09796dce 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateselectorwidget.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicletemplateselectorwidget.h @@ -36,8 +36,7 @@ namespace Ui { class VehicleTemplateSelectorWidget; } -class VehicleTemplateSelectorWidget : public QWidget -{ +class VehicleTemplateSelectorWidget : public QWidget { Q_OBJECT public: