diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 78e72131d..6ffcf3df3 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -893,7 +893,7 @@ GeneralSettings::GeneralSettings() } -RawSource GeneralSettings::getDefaultSource(unsigned int channel) +RawSource GeneralSettings::getDefaultSource(unsigned int channel) const { unsigned int stick_index = chout_ar[4*templateSetup + channel] - 1; return RawSource(SOURCE_TYPE_STICK, stick_index); @@ -904,6 +904,24 @@ ModelData::ModelData() clear(); } +ModelData::ModelData(const ModelData & src) +{ + *this = src; +} + +ModelData & ModelData::operator = (const ModelData & src) +{ + memcpy(this, &src, sizeof(ModelData)); + + for (int i=0; igetBoard())) { for (int i=0; isrcRaw = settings.getDefaultSource(i); expo->weight = 100; strncpy(inputNames[i], expo->srcRaw.toString().toLatin1().constData(), sizeof(inputNames[i])-1); - MixData * mix = &mixData[i]; - mix->destCh = i+1; - mix->weight = 100; - mix->srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, i, this); } } - else { - for (int i=0; igetBoard())) { + setDefaultInputs(settings); + } + + for (int i=0; idestCh = i+1; + mix->weight = 100; + if (IS_TARANIS(GetEepromInterface()->getBoard())) { + mix->srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, i, this); + } + else { + mix->srcRaw = RawSource(SOURCE_TYPE_STICK, i); + } + } +} + +void ModelData::setDefaultValues(unsigned int id, const GeneralSettings & settings) { clear(); used = true; diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index f4a2bc7dc..60e85ab79 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -402,7 +402,7 @@ class GeneralSettings { public: GeneralSettings(); - RawSource getDefaultSource(unsigned int channel); + RawSource getDefaultSource(unsigned int channel) const; unsigned int version; unsigned int variant; @@ -891,6 +891,8 @@ class ScriptData { class ModelData { public: ModelData(); + ModelData(const ModelData & src); + ModelData & operator = (const ModelData & src); ExpoData * insertInput(const int idx); void removeInput(const int idx); @@ -950,8 +952,9 @@ class ModelData { void clear(); bool isempty(); - void setDefaultMixes(GeneralSettings & settings); - void setDefaultValues(unsigned int id, GeneralSettings & settings); + void setDefaultInputs(const GeneralSettings & settings); + void setDefaultMixes(const GeneralSettings & settings); + void setDefaultValues(unsigned int id, const GeneralSettings & settings); int getTrimValue(int phaseIdx, int trimIdx); void setTrimValue(int phaseIdx, int trimIdx, int value); diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 0405e6a12..659dda7fd 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -185,7 +185,7 @@ void MdiChild::wizardEdit() int row = ui->modelsList->currentRow(); if (row > 0) { checkAndInitModel(row); - WizardDialog * wizard = new WizardDialog(row, this); + WizardDialog * wizard = new WizardDialog(radioData.generalSettings, row, this); wizard->exec(); if (wizard->mix.complete /*TODO rather test the exec() result?*/) { radioData.models[row - 1] = wizard->mix; diff --git a/companion/src/wizarddata.cpp b/companion/src/wizarddata.cpp index 839350e52..b67adcb55 100644 --- a/companion/src/wizarddata.cpp +++ b/companion/src/wizarddata.cpp @@ -21,16 +21,17 @@ Channel::Channel() void Channel::clear() { - sourceDlg = -1; + page = Page_None; input1 = NOINPUT; input2 = NOINPUT; weight1 = 0; weight2 = 0; } -WizMix::WizMix(const unsigned int modelId): +WizMix::WizMix(const GeneralSettings & settings, const unsigned int modelId): complete(false), modelId(modelId), + settings(settings), vehicle(NOVEHICLE) { strcpy(name, " "); @@ -42,6 +43,7 @@ WizMix::operator ModelData() model.used = true; model.modelId = modelId; + model.setDefaultInputs(settings); // Safe copy model name strncpy(model.name, name, WIZ_MODEL_NAME_LENGTH); @@ -49,8 +51,17 @@ WizMix::operator ModelData() for (int i=0; i 0) { - //**** INSERT MIXER HERE **** + if (ch.page != Page_None) { + // qDebug() << "channel" << i << "page" << ch.page << ch.input1 << ch.input2; + MixData & mix = model.mixData[i]; + mix.destCh = i+1; + if (ch.input1 >= RUDDER && ch.input1 <= AILERON) { + if (IS_TARANIS(GetEepromInterface()->getBoard())) + mix.srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, ch.input1-1, &model); + else + mix.srcRaw = RawSource(SOURCE_TYPE_STICK, ch.input1-1); + } + mix.weight = ch.weight1; } } diff --git a/companion/src/wizarddata.h b/companion/src/wizarddata.h index 33620b230..bc190fdf6 100644 --- a/companion/src/wizarddata.h +++ b/companion/src/wizarddata.h @@ -25,9 +25,9 @@ enum Input { NOINPUT, - THROTTLE, RUDDER, ELEVATOR, + THROTTLE, AILERON, FLAP, AIRBREAK @@ -40,10 +40,33 @@ enum Vehicle { HELICOPTER }; +enum WizardPage { + Page_None = -1, + Page_Models, + Page_Throttle, + Page_Wingtypes, + Page_Ailerons, + Page_Flaps, + Page_Airbrakes, + Page_Bank, + Page_Rudder, + Page_Tails, + Page_Tail, + Page_Vtail, + Page_Simpletail, + Page_Cyclic, + Page_Gyro, + Page_Flybar, + Page_Fblheli, + Page_Helictrl, + Page_Multirotor, + Page_Conclusion +}; + class Channel { public: - int sourceDlg; // Originating dialog, only of interest for producer + WizardPage page; // Originating dialog, only of interest for producer Input input1; Input input2; int weight1; @@ -59,10 +82,11 @@ class WizMix bool complete; char name[WIZ_MODEL_NAME_LENGTH + 1]; unsigned int modelId; + const GeneralSettings & settings; Vehicle vehicle; Channel channel[WIZ_MAX_CHANNELS]; - explicit WizMix(const unsigned int modelId); + WizMix(const GeneralSettings & settings, const unsigned int modelId); operator ModelData(); private: diff --git a/companion/src/wizarddialog.cpp b/companion/src/wizarddialog.cpp index dc3ac05a0..eca7136e4 100644 --- a/companion/src/wizarddialog.cpp +++ b/companion/src/wizarddialog.cpp @@ -16,9 +16,9 @@ #include "wizarddialog.h" #include "wizarddata.h" -WizardDialog::WizardDialog(unsigned int modelId, QWidget *parent) +WizardDialog::WizardDialog(const GeneralSettings & settings, unsigned int modelId, QWidget *parent) : QWizard(parent), - mix(modelId) + mix(settings, modelId) { setWindowTitle(tr("Model Wizard")); @@ -122,7 +122,7 @@ void WizardDialog::showHelp() QMessageBox::information(this, tr("Model Wizard Help"), message); } -StandardPage::StandardPage(int currentPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage ) +StandardPage::StandardPage(WizardPage currentPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage ) : QWizardPage() { pageCurrent = currentPage; @@ -144,10 +144,9 @@ void StandardPage::populateCB( QComboBox *CB ) for (int j=0; jremoveItem(0); - for (int i=0; imix.channel[i].sourceDlg < 0){ - CB->addItem(tr("Channel ") + QString("%1").arg(i+1), i); + for (int i=0; imix.channel[i].page == Page_None) { + CB->addItem(tr("Channel %1").arg(i+1), i); } } } @@ -158,10 +157,10 @@ bool StandardPage::bookChannel(QString label, Input input1, int weight1, Input i if (index<0 || index >= WIZ_MAX_CHANNELS) return false; - if (!(wizDlg->mix.channel[index].sourceDlg < 0)) + if (wizDlg->mix.channel[index].page != Page_None) return false; - wizDlg->mix.channel[index].sourceDlg = pageCurrent; + wizDlg->mix.channel[index].page = pageCurrent; wizDlg->mix.channel[index].input1 = input1; wizDlg->mix.channel[index].input2 = input2; wizDlg->mix.channel[index].weight1 = weight1; @@ -174,7 +173,7 @@ void StandardPage::releaseChannels() { for (int i=0; imix.channel[i].sourceDlg == pageCurrent){ + if (wizDlg->mix.channel[i].page == pageCurrent){ wizDlg->mix.channel[i].clear(); } } @@ -191,7 +190,7 @@ int StandardPage::nextId() const } ModelSelectionPage::ModelSelectionPage(WizardDialog *dlg, QString image, QString title, QString text) - : StandardPage(WizardDialog::Page_Models, dlg, image, title, text) + : StandardPage(Page_Models, dlg, image, title, text) { nameLineEdit = new QLineEdit; planeRB = new QRadioButton(tr("Plane")); @@ -232,15 +231,15 @@ bool ModelSelectionPage::validatePage() int ModelSelectionPage::nextId() const { if (helicopterRB->isChecked()) - return WizardDialog::Page_Cyclic; + return Page_Cyclic; else if (multirotorRB->isChecked()) - return WizardDialog::Page_Multirotor; + return Page_Multirotor; else - return WizardDialog::Page_Throttle; + return Page_Throttle; } WingtypeSelectionPage::WingtypeSelectionPage(WizardDialog *dlg, QString image, QString title, QString text) - : StandardPage(WizardDialog::Page_Wingtypes, dlg, image, title, text) + : StandardPage(Page_Wingtypes, dlg, image, title, text) { standardWingRB = new QRadioButton(tr("Standard Wing")); standardWingRB->setChecked(true); @@ -254,13 +253,13 @@ WingtypeSelectionPage::WingtypeSelectionPage(WizardDialog *dlg, QString image, Q int WingtypeSelectionPage::nextId() const { if (deltaWingRB->isChecked()) - return WizardDialog::Page_Bank; + return Page_Bank; else - return WizardDialog::Page_Ailerons; + return Page_Ailerons; } TailSelectionPage::TailSelectionPage(WizardDialog *dlg, QString image, QString title, QString text) - : StandardPage(WizardDialog::Page_Tails, dlg, image, title, text) + : StandardPage(Page_Tails, dlg, image, title, text) { standardTailRB = new QRadioButton(tr("Elevator and Rudder")); standardTailRB->setChecked(true); @@ -277,15 +276,15 @@ TailSelectionPage::TailSelectionPage(WizardDialog *dlg, QString image, QString t int TailSelectionPage::nextId() const { if (simpleTailRB->isChecked()) - return WizardDialog::Page_Simpletail; + return Page_Simpletail; else if (vTailRB->isChecked()) - return WizardDialog::Page_Vtail; + return Page_Vtail; else - return WizardDialog::Page_Tail; + return Page_Tail; } FlybarSelectionPage::FlybarSelectionPage(WizardDialog *dlg, QString image, QString title, QString text) - : StandardPage(WizardDialog::Page_Flybar, dlg, image, title, text) + : StandardPage(Page_Flybar, dlg, image, title, text) { flybarRB = new QRadioButton(tr("Has Flybar")); flybarRB->setChecked(true); @@ -300,13 +299,13 @@ FlybarSelectionPage::FlybarSelectionPage(WizardDialog *dlg, QString image, QStri int FlybarSelectionPage::nextId() const { if (flybarRB->isChecked()) - return WizardDialog::Page_Helictrl; + return Page_Helictrl; else - return WizardDialog::Page_Fblheli; + return Page_Fblheli; } ThrottlePage::ThrottlePage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Throttle, dlg, image, title, text, nextPage) + : StandardPage(Page_Throttle, dlg, image, title, text, nextPage) { motorRB = new QRadioButton(tr("Yes")); noMotorRB = new QRadioButton(tr("No")); @@ -330,7 +329,7 @@ bool ThrottlePage::validatePage() { } AileronsPage::AileronsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Ailerons, dlg, image, title, text, nextPage) + : StandardPage(Page_Ailerons, dlg, image, title, text, nextPage) { noAileronsRB = new QRadioButton(tr("No")); oneAileronRB = new QRadioButton(tr("Yes, controlled by a single channel")); @@ -367,7 +366,7 @@ bool AileronsPage::validatePage() { } FlapsPage::FlapsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Flaps, dlg, image, title, text, nextPage) + : StandardPage(Page_Flaps, dlg, image, title, text, nextPage) { noFlapsRB = new QRadioButton(tr("No")); oneFlapRB = new QRadioButton(tr("Yes, controlled by a single channel")); @@ -404,7 +403,7 @@ bool FlapsPage::validatePage() { } AirbreaksPage::AirbreaksPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Airbrakes, dlg, image, title, text, nextPage) + : StandardPage(Page_Airbrakes, dlg, image, title, text, nextPage) { noAirbreaksRB = new QRadioButton(tr("No")); oneAirbreakRB = new QRadioButton(tr("Yes, controlled by a single channel")); @@ -441,7 +440,7 @@ bool AirbreaksPage::validatePage() { } BankPage::BankPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Bank, dlg, image, title, text, nextPage) + : StandardPage(Page_Bank, dlg, image, title, text, nextPage) { oneElevonChRB = new QRadioButton(tr("One")); oneElevonChRB->setChecked(true); @@ -473,7 +472,7 @@ bool BankPage::validatePage() { } RudderPage::RudderPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Rudder, dlg, image, title, text, nextPage) + : StandardPage(Page_Rudder, dlg, image, title, text, nextPage) { noRudderRB = new QRadioButton(tr("No")); noRudderRB->setChecked(true); @@ -500,7 +499,7 @@ bool RudderPage::validatePage() { } VTailPage::VTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Tail, dlg, image, title, text, nextPage) + : StandardPage(Page_Tail, dlg, image, title, text, nextPage) { tail1CB = new QComboBox(); tail2CB = new QComboBox(); @@ -524,7 +523,7 @@ bool VTailPage::validatePage() { } TailPage::TailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Tail, dlg, image, title, text, nextPage) + : StandardPage(Page_Tail, dlg, image, title, text, nextPage) { elevatorCB = new QComboBox(); rudderCB = new QComboBox(); @@ -548,7 +547,7 @@ bool TailPage::validatePage() { } SimpleTailPage::SimpleTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Simpletail, dlg, image, title, text, nextPage) + : StandardPage(Page_Simpletail, dlg, image, title, text, nextPage) { elevatorCB = new QComboBox(); @@ -567,7 +566,7 @@ bool SimpleTailPage::validatePage() { } CyclicPage::CyclicPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Cyclic, dlg, image, title, text, nextPage) + : StandardPage(Page_Cyclic, dlg, image, title, text, nextPage) { cyclic90RB = new QRadioButton(tr("90")); cyclic90RB->setChecked(true); @@ -591,7 +590,7 @@ bool CyclicPage::validatePage() { } GyroPage::GyroPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Gyro, dlg, image, title, text, nextPage) + : StandardPage(Page_Gyro, dlg, image, title, text, nextPage) { noGyroRB = new QRadioButton(tr("No")); noGyroRB->setChecked(true); @@ -613,7 +612,7 @@ bool GyroPage::validatePage() { } FblPage::FblPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Fblheli, dlg, image, title, text, nextPage) + : StandardPage(Page_Fblheli, dlg, image, title, text, nextPage) { throttleCB = new QComboBox(); yawCB = new QComboBox(); @@ -647,7 +646,7 @@ bool FblPage::validatePage() { } HeliPage::HeliPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Helictrl, dlg, image, title, text, nextPage) + : StandardPage(Page_Helictrl, dlg, image, title, text, nextPage) { throttleCB = new QComboBox(); yawCB = new QComboBox(); @@ -681,7 +680,7 @@ bool HeliPage::validatePage() { } MultirotorPage::MultirotorPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Multirotor, dlg, image, title, text, nextPage) + : StandardPage(Page_Multirotor, dlg, image, title, text, nextPage) { throttleCB = new QComboBox(); yawCB = new QComboBox(); @@ -715,7 +714,7 @@ bool MultirotorPage::validatePage() { } ConclusionPage::ConclusionPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage) - : StandardPage(WizardDialog::Page_Conclusion, dlg, image, title, text, nextPage) + : StandardPage(Page_Conclusion, dlg, image, title, text, nextPage) { textLabel = new QLabel(); proceedCB = new QCheckBox(tr("OK, I understand.")); @@ -780,7 +779,7 @@ QString WizardPrinter::print() str = QString(tr("Model Name: ")) + mix->name + "\n"; str += QString(tr("Model Type: ")) + vehicleName(mix->vehicle) + "\n"; for (int i=0; ichannel[i].sourceDlg < 0 )){ + if (mix->channel[i].page != Page_None) { Channel ch = mix->channel[i]; str += QString(tr("Channel %1: ").arg(i+1)); str += printChannel(ch.input1, ch.weight1, ch.input2, ch.weight2 ); diff --git a/companion/src/wizarddialog.h b/companion/src/wizarddialog.h index f8d3d9a89..a8b34dbd2 100644 --- a/companion/src/wizarddialog.h +++ b/companion/src/wizarddialog.h @@ -29,14 +29,9 @@ class WizardDialog : public QWizard { Q_OBJECT public: - enum { Page_Models, Page_Throttle, Page_Wingtypes, Page_Ailerons, Page_Flaps, - Page_Airbrakes, Page_Bank, Page_Rudder, Page_Tails, Page_Tail, - Page_Vtail, Page_Simpletail, Page_Cyclic, Page_Gyro, Page_Flybar, - Page_Fblheli, Page_Helictrl, Page_Multirotor, - Page_Conclusion }; WizMix mix; - WizardDialog(const unsigned int modelId, QWidget *parent = 0); + WizardDialog(const GeneralSettings & settings, const unsigned int modelId, QWidget *parent = 0); private slots: void showHelp(); @@ -46,7 +41,7 @@ class StandardPage: public QWizardPage { Q_OBJECT public: - StandardPage(int curPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); + StandardPage(WizardPage curPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1); WizardDialog *wizDlg; void populateCB( QComboBox *); bool bookChannel(QString label, Input input1, int weight1, Input input2=NOINPUT, int weight2=0 ); @@ -54,7 +49,7 @@ public: void cleanupPage(); private: QLabel *topLabel; - int pageCurrent; + WizardPage pageCurrent; int pageFollower; int nextId() const; };