1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 16:25:16 +03:00

Now the wizard is able to configure a simple 4CH plane

This commit is contained in:
bsongis 2014-03-13 15:51:54 +01:00
parent e0582cd398
commit 383475a6ed
7 changed files with 131 additions and 73 deletions

View file

@ -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; i<C9X_MAX_MIXERS; i++)
mixData[i].srcRaw.model = this;
for (int i=0; i<C9X_MAX_EXPOS; i++)
expoData[i].srcRaw.model = this;
swashRingData.collectiveSource.model = this;
return *this;
}
ExpoData * ModelData::insertInput(const int idx)
{
memmove(&expoData[idx+1], &expoData[idx], (C9X_MAX_EXPOS-(idx+1))*sizeof(ExpoData));
@ -972,7 +990,7 @@ bool ModelData::isempty()
return !used;
}
void ModelData::setDefaultMixes(GeneralSettings & settings)
void ModelData::setDefaultInputs(const GeneralSettings & settings)
{
if (IS_TARANIS(GetEepromInterface()->getBoard())) {
for (int i=0; i<NUM_STICKS; i++) {
@ -982,22 +1000,30 @@ void ModelData::setDefaultMixes(GeneralSettings & settings)
expo->srcRaw = 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; i<NUM_STICKS; i++) {
mixData[i].destCh = i+1;
mixData[i].srcRaw = RawSource(SOURCE_TYPE_STICK, i);
mixData[i].weight = 100;
}
}
}
void ModelData::setDefaultValues(unsigned int id, GeneralSettings & settings)
void ModelData::setDefaultMixes(const GeneralSettings & settings)
{
if (IS_TARANIS(GetEepromInterface()->getBoard())) {
setDefaultInputs(settings);
}
for (int i=0; i<NUM_STICKS; i++) {
MixData * mix = &mixData[i];
mix->destCh = 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;

View file

@ -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);

View file

@ -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;

View file

@ -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<WIZ_MAX_CHANNELS; i++ ) {
Channel ch = channel[i];
if (ch.sourceDlg > 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;
}
}

View file

@ -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:

View file

@ -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; j<WIZ_MAX_CHANNELS; j++)
CB->removeItem(0);
for (int i=0; i<WIZ_MAX_CHANNELS; i++)
{
if (wizDlg->mix.channel[i].sourceDlg < 0){
CB->addItem(tr("Channel ") + QString("%1").arg(i+1), i);
for (int i=0; i<WIZ_MAX_CHANNELS; i++) {
if (wizDlg->mix.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; i<WIZ_MAX_CHANNELS; i++)
{
if (wizDlg->mix.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; i<WIZ_MAX_CHANNELS; i++){
if (!(mix->channel[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 );

View file

@ -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;
};