1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 17:55:19 +03:00

Data handling added. I have used the simplest possible channel class. An array with these channels are filled throughout the wizard, forming a simplistic mix table that can be passed on and inserted in the real mixer.

The simple mixer is fully functional for planes and multicopters.
I have to read up on how helicopters are controlled. Currently that part is done wrong since I have no idea about how to set up helicopter mixes.
This commit is contained in:
Kjell Kernen 2014-03-02 23:56:49 +01:00
parent 672e5f8088
commit 858c9193cb
5 changed files with 401 additions and 34 deletions

View file

@ -1,6 +1,47 @@
#include <QtGui>
#include "wizarddialog.h"
Channel::Channel()
{
clear();
}
void Channel::clear()
{
sourceDlg = -1;
input1 = UNDEFINED;
input2 = UNDEFINED;
weight1 = 0;
weight2 = 0;
}
bool Channel::isEmpty()
{
return sourceDlg < 0;
}
QString Channel::nameOf(Input input)
{
switch (input){
case THROTTLE: return "THR";
case RUDDER: return "RUD";
case ELEVATOR: return "ELE";
case AILERON: return "AIL";
case FLAP: return "FLP";
case AIRBREAK: return "AIR";
default: return "---";
}
}
QString Channel::print()
{
QString str;
str = QString("[%1, %2]").arg(nameOf(input1)).arg(weight1);
if ( input2 != UNDEFINED )
str += QString("[%1, %2]").arg(nameOf(input2)).arg(weight2);
return str;
}
WizardDialog::WizardDialog(QWidget *parent)
: QWizard(parent)
{
@ -16,6 +57,7 @@ WizardDialog::WizardDialog(QWidget *parent)
setPage(Page_Rudder, new RudderPage(this, "rudder",tr("Rudder"),tr("Does your model have a rudder?"), Page_Conclusion));
setPage(Page_Tails, new TailSelectionPage(this, "tails",tr("Tail Type"),tr("Select which type of tail your model is equiped with.")));
setPage(Page_Tail, new TailPage(this, "tail",tr("Tail"),tr("Select channels for tail control."), Page_Conclusion));
setPage(Page_Vtail, new VTailPage(this, "vtail",tr("V-Tail"),tr("Select channels for tail control."), Page_Conclusion));
setPage(Page_Simpletail, new SimpleTailPage(this, "simpletail",tr("Tail"),tr("Select elevator channel."), Page_Conclusion));
setPage(Page_Cyclic, new CyclicPage(this, "cyclic",tr("Cyclic"),tr("Which type of swash control is installed in your helicopter?"), Page_Gyro));
setPage(Page_Gyro, new GyroPage(this, "gyro",tr("Tail Gyro"),tr("Has your helicopter got an adjustable gyro for the tail?"), Page_Flybar));
@ -24,10 +66,9 @@ WizardDialog::WizardDialog(QWidget *parent)
setPage(Page_Helictrl, new HeliPage(this, "helictrl",tr("Helicopter"),tr("Select the controls for your helicopter"), Page_Conclusion));
setPage(Page_Multirotor, new MultirotorPage(this, "multirotor",tr("Multirotor"),tr("Select the control channels for your multirotor"), Page_Conclusion));
setPage(Page_Conclusion, new ConclusionPage(this, "conclusion",tr("Save Changes"),tr(
"Your model should now be set up. You now have to manually check the direction of each control surface and reverse the channels that "
"make controls move in the wrong direction.<br><br>Remove the propeller/propellers before you try to control your model for the first time.<br><br>"
"Manually check the direction of each control surface and reverse any channels that make controls move in the wrong direction. "
"Remove the propeller/propellers before you try to control your model for the first time.<br>"
"Please note that continuing removes all old model settings!"), -1));
setStartId(Page_Models);
#ifndef Q_WS_MAC
@ -58,6 +99,7 @@ void WizardDialog::showHelp()
case Page_Rudder: message = tr("TBD."); break;
case Page_Tails: message = tr("Select the tail type of your plane."); break;
case Page_Tail: message = tr("TBD."); break;
case Page_Vtail: message = tr("TBD."); break;
case Page_Simpletail: message = tr("TBD."); break;
case Page_Flybar: message = tr("TBD."); break;
case Page_Cyclic: message = tr("TBD."); break;
@ -65,17 +107,18 @@ void WizardDialog::showHelp()
case Page_Fblheli: message = tr("TBD."); break;
case Page_Helictrl: message = tr("TBD."); break;
case Page_Multirotor: message = tr("TBD."); break;
case Page_Conclusion: message = tr("TBD."); break;
case Page_Conclusion: message = tr("TBD."); break;
default: message = tr("Move on. Nothin to see here.");
}
QMessageBox::information(this, tr("Model Wizard Help"), message);
}
StandardPage::StandardPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
StandardPage::StandardPage(int currentPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage )
: QWizardPage()
{
pageCurrent = currentPage;
pageFollower = nextPage;
wizardDialog = dlg;
wizDlg = dlg;
setTitle(title);
setPixmap(QWizard::WatermarkPixmap, QPixmap(QString(":/images/wizard/") + image + QString(".png")));
@ -87,13 +130,59 @@ StandardPage::StandardPage(WizardDialog *dlg, QString image, QString title, QStr
setLayout(layout);
}
void StandardPage::populateCB( QComboBox *CB )
{
for (int j=0; j<MAX_CHANNELS; j++)
CB->removeItem(0);
for (int i=0; i<MAX_CHANNELS; i++)
{
if (wizDlg->channel[i].isEmpty()){
CB->addItem(tr("Channel ") + QString("%1").arg(i+1), i);
}
}
}
bool StandardPage::bookChannel(QString label, Input input1, int weight1, Input input2, int weight2 )
{
int index = label.right(1).toInt() - 1;
if (index<0 || index >= MAX_CHANNELS)
return false;
if (!wizDlg->channel[index].isEmpty())
return false;
wizDlg->channel[index].sourceDlg = pageCurrent;
wizDlg->channel[index].input1 = input1;
wizDlg->channel[index].input2 = input2;
wizDlg->channel[index].weight1 = weight1;
wizDlg->channel[index].weight2 = weight2;
return true;
}
void StandardPage::releaseChannels()
{
for (int i=0; i<MAX_CHANNELS; i++)
{
if (wizDlg->channel[i].sourceDlg == pageCurrent){
wizDlg->channel[i].clear();
}
}
}
void StandardPage::cleanupPage()
{
releaseChannels();
}
int StandardPage::nextId() const
{
return pageFollower;
}
ModelSelectionPage::ModelSelectionPage(WizardDialog *dlg, QString image, QString title, QString text)
: StandardPage(dlg, image, title, text)
: StandardPage(WizardDialog::Page_Models, dlg, image, title, text)
{
nameLineEdit = new QLineEdit;
planeRB = new QRadioButton(tr("Plane"));
@ -124,7 +213,7 @@ int ModelSelectionPage::nextId() const
}
WingtypeSelectionPage::WingtypeSelectionPage(WizardDialog *dlg, QString image, QString title, QString text)
: StandardPage(dlg, image, title, text)
: StandardPage(WizardDialog::Page_Wingtypes, dlg, image, title, text)
{
standardWingRB = new QRadioButton(tr("Standard Wing"));
standardWingRB->setChecked(true);
@ -144,7 +233,7 @@ int WingtypeSelectionPage::nextId() const
}
TailSelectionPage::TailSelectionPage(WizardDialog *dlg, QString image, QString title, QString text)
: StandardPage(dlg, image, title, text)
: StandardPage(WizardDialog::Page_Tails, dlg, image, title, text)
{
standardTailRB = new QRadioButton(tr("Elevator and Rudder"));
standardTailRB->setChecked(true);
@ -162,12 +251,14 @@ int TailSelectionPage::nextId() const
{
if (simpleTailRB->isChecked())
return WizardDialog::Page_Simpletail;
else if (vTailRB->isChecked())
return WizardDialog::Page_Vtail;
else
return WizardDialog::Page_Tail;
}
FlybarSelectionPage::FlybarSelectionPage(WizardDialog *dlg, QString image, QString title, QString text)
: StandardPage(dlg, image, title, text)
: StandardPage(WizardDialog::Page_Flybar, dlg, image, title, text)
{
flybarRB = new QRadioButton(tr("Has Flybar"));
flybarRB->setChecked(true);
@ -188,7 +279,7 @@ int FlybarSelectionPage::nextId() const
}
ThrottlePage::ThrottlePage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Throttle, dlg, image, title, text, nextPage)
{
motorRB = new QRadioButton(tr("Yes"));
noMotorRB = new QRadioButton(tr("No"));
@ -202,8 +293,17 @@ ThrottlePage::ThrottlePage(WizardDialog *dlg, QString image, QString title, QStr
l->addWidget(throttleCB);
}
void ThrottlePage::initializePage(){
populateCB(throttleCB);
}
bool ThrottlePage::validatePage() {
releaseChannels();
return bookChannel(throttleCB->currentText(), THROTTLE, 100 );
}
AileronsPage::AileronsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Ailerons, dlg, image, title, text, nextPage)
{
noAileronsRB = new QRadioButton(tr("No"));
oneAileronRB = new QRadioButton(tr("Yes, controlled by a single channel"));
@ -222,8 +322,25 @@ AileronsPage::AileronsPage(WizardDialog *dlg, QString image, QString title, QStr
l->addWidget(aileron2CB);
}
void AileronsPage::initializePage(){
populateCB(aileron1CB);
populateCB(aileron2CB);
}
bool AileronsPage::validatePage() {
releaseChannels();
if (noAileronsRB->isChecked()) {
return true;
}
if (oneAileronRB->isChecked()) {
return (bookChannel(aileron1CB->currentText(), AILERON, 100 ));
}
return( bookChannel(aileron1CB->currentText(), AILERON, 100 ) &&
bookChannel(aileron2CB->currentText(), AILERON, 100 ));
}
FlapsPage::FlapsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Flaps, dlg, image, title, text, nextPage)
{
noFlapsRB = new QRadioButton(tr("No"));
oneFlapRB = new QRadioButton(tr("Yes, controlled by a single channel"));
@ -242,8 +359,25 @@ FlapsPage::FlapsPage(WizardDialog *dlg, QString image, QString title, QString te
l->addWidget(flap2CB);
}
void FlapsPage::initializePage(){
populateCB(flap1CB);
populateCB(flap2CB);
}
bool FlapsPage::validatePage() {
releaseChannels();
if (noFlapsRB->isChecked()) {
return true;
}
if (oneFlapRB->isChecked()) {
return (bookChannel(flap1CB->currentText(), FLAP, 100 ));
}
return( bookChannel(flap1CB->currentText(), FLAP, 100 ) &&
bookChannel(flap2CB->currentText(), FLAP, 100 ));
}
AirbreaksPage::AirbreaksPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Airbrakes, dlg, image, title, text, nextPage)
{
noAirbreaksRB = new QRadioButton(tr("No"));
oneAirbreakRB = new QRadioButton(tr("Yes, controlled by a single channel"));
@ -262,8 +396,25 @@ AirbreaksPage::AirbreaksPage(WizardDialog *dlg, QString image, QString title, QS
l->addWidget(airbreak2CB);
}
void AirbreaksPage::initializePage(){
populateCB(airbreak1CB);
populateCB(airbreak2CB);
}
bool AirbreaksPage::validatePage() {
releaseChannels();
if (noAirbreaksRB->isChecked()) {
return true;
}
if (oneAirbreakRB->isChecked()) {
return (bookChannel(airbreak1CB->currentText(), AIRBREAK, 100 ));
}
return( bookChannel(airbreak1CB->currentText(), AIRBREAK, 100 ) &&
bookChannel(airbreak2CB->currentText(), AIRBREAK, 100 ));
}
BankPage::BankPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Bank, dlg, image, title, text, nextPage)
{
oneElevonChRB = new QRadioButton(tr("One"));
oneElevonChRB->setChecked(true);
@ -279,8 +430,23 @@ BankPage::BankPage(WizardDialog *dlg, QString image, QString title, QString text
l->addWidget(new QLabel(tr("Second Elevon Channel:")));
l->addWidget(elevon2CB);
}
void BankPage::initializePage(){
populateCB(elevon1CB);
populateCB(elevon2CB);
}
bool BankPage::validatePage() {
releaseChannels();
if (oneElevonChRB->isChecked()) {
return (bookChannel(elevon1CB->currentText(), AILERON, 100, ELEVATOR, 100 ));
}
return( bookChannel(elevon1CB->currentText(), AILERON, 100, ELEVATOR, 100 ) &&
bookChannel(elevon2CB->currentText(), AILERON, 100, ELEVATOR, 100 ));
}
RudderPage::RudderPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Rudder, dlg, image, title, text, nextPage)
{
noRudderRB = new QRadioButton(tr("No"));
noRudderRB->setChecked(true);
@ -294,8 +460,44 @@ RudderPage::RudderPage(WizardDialog *dlg, QString image, QString title, QString
l->addWidget(rudderCB);
}
void RudderPage::initializePage(){
populateCB(rudderCB);
}
bool RudderPage::validatePage() {
releaseChannels();
if (noRudderRB->isChecked())
return true;
return (bookChannel(rudderCB->currentText(), RUDDER, 100));
}
VTailPage::VTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(WizardDialog::Page_Tail, dlg, image, title, text, nextPage)
{
tail1CB = new QComboBox();
tail2CB = new QComboBox();
QLayout *l = layout();
l->addWidget(new QLabel(tr("First Tail Channel:")));
l->addWidget(tail1CB);
l->addWidget(new QLabel(tr("Second Tail Channel:")));
l->addWidget(tail2CB);
}
void VTailPage::initializePage(){
populateCB(tail1CB);
populateCB(tail2CB);
}
bool VTailPage::validatePage() {
releaseChannels();
return( bookChannel(tail1CB->currentText(), ELEVATOR, 100, RUDDER, 100 ) &&
bookChannel(tail2CB->currentText(), ELEVATOR, 100, RUDDER, 100 ));
}
TailPage::TailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Tail, dlg, image, title, text, nextPage)
{
elevatorCB = new QComboBox();
rudderCB = new QComboBox();
@ -307,8 +509,19 @@ TailPage::TailPage(WizardDialog *dlg, QString image, QString title, QString text
l->addWidget(elevatorCB);
}
void TailPage::initializePage(){
populateCB(elevatorCB);
populateCB(rudderCB);
}
bool TailPage::validatePage() {
releaseChannels();
return( bookChannel(elevatorCB->currentText(), ELEVATOR, 100 ) &&
bookChannel(rudderCB->currentText(), RUDDER, 100 ));
}
SimpleTailPage::SimpleTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Simpletail, dlg, image, title, text, nextPage)
{
elevatorCB = new QComboBox();
@ -317,8 +530,17 @@ SimpleTailPage::SimpleTailPage(WizardDialog *dlg, QString image, QString title,
l->addWidget(elevatorCB);
}
void SimpleTailPage::initializePage(){
populateCB(elevatorCB);
}
bool SimpleTailPage::validatePage() {
releaseChannels();
return( bookChannel(elevatorCB->currentText(), ELEVATOR, 100 ));
}
CyclicPage::CyclicPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Cyclic, dlg, image, title, text, nextPage)
{
cyclic90RB = new QRadioButton(tr("90"));
cyclic90RB->setChecked(true);
@ -333,8 +555,16 @@ CyclicPage::CyclicPage(WizardDialog *dlg, QString image, QString title, QString
l->addWidget(cyclic140RB);
}
void CyclicPage::initializePage(){
}
bool CyclicPage::validatePage() {
releaseChannels();
return true;
}
GyroPage::GyroPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Gyro, dlg, image, title, text, nextPage)
{
noGyroRB = new QRadioButton(tr("No"));
noGyroRB->setChecked(true);
@ -347,8 +577,16 @@ GyroPage::GyroPage(WizardDialog *dlg, QString image, QString title, QString text
l->addWidget(potGyroRB);
}
void GyroPage::initializePage(){
}
bool GyroPage::validatePage() {
releaseChannels();
return true;
}
FblPage::FblPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Fblheli, dlg, image, title, text, nextPage)
{
throttleCB = new QComboBox();
yawCB = new QComboBox();
@ -366,8 +604,23 @@ FblPage::FblPage(WizardDialog *dlg, QString image, QString title, QString text,
l->addWidget(rollCB);
}
void FblPage::initializePage(){
populateCB(throttleCB);
populateCB(yawCB);
populateCB(pitchCB);
populateCB(rollCB);
}
bool FblPage::validatePage() {
releaseChannels();
return( bookChannel(throttleCB->currentText(), THROTTLE, 100 ) &&
bookChannel(yawCB->currentText(), RUDDER, 100 ) &&
bookChannel(pitchCB->currentText(), ELEVATOR, 100 ) &&
bookChannel(rollCB->currentText(), AILERON, 100 ));
}
HeliPage::HeliPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Helictrl, dlg, image, title, text, nextPage)
{
throttleCB = new QComboBox();
yawCB = new QComboBox();
@ -385,8 +638,23 @@ HeliPage::HeliPage(WizardDialog *dlg, QString image, QString title, QString text
l->addWidget(rollCB);
}
void HeliPage::initializePage(){
populateCB(throttleCB);
populateCB(yawCB);
populateCB(pitchCB);
populateCB(rollCB);
}
bool HeliPage::validatePage() {
releaseChannels();
return( bookChannel(throttleCB->currentText(), THROTTLE, 100 ) &&
bookChannel(yawCB->currentText(), RUDDER, 100 ) &&
bookChannel(pitchCB->currentText(), ELEVATOR, 100 ) &&
bookChannel(rollCB->currentText(), AILERON, 100 ));
}
MultirotorPage::MultirotorPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Multirotor, dlg, image, title, text, nextPage)
{
throttleCB = new QComboBox();
yawCB = new QComboBox();
@ -404,13 +672,43 @@ MultirotorPage::MultirotorPage(WizardDialog *dlg, QString image, QString title,
l->addWidget(rollCB);
}
void MultirotorPage::initializePage(){
populateCB(throttleCB);
populateCB(yawCB);
populateCB(pitchCB);
populateCB(rollCB);
}
bool MultirotorPage::validatePage() {
releaseChannels();
return( bookChannel(throttleCB->currentText(), THROTTLE, 100 ) &&
bookChannel(yawCB->currentText(), RUDDER, 100 ) &&
bookChannel(pitchCB->currentText(), ELEVATOR, 100 ) &&
bookChannel(rollCB->currentText(), AILERON, 100 ));
}
ConclusionPage::ConclusionPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage)
: StandardPage(dlg, image, title, text, nextPage)
: StandardPage(WizardDialog::Page_Conclusion, dlg, image, title, text, nextPage)
{
textLabel = new QLabel();
proceedCB = new QCheckBox(tr("OK, I understand."));
registerField("evaluate.proceed*", proceedCB);
QLayout *l = layout();
l->addWidget(textLabel);
l->addWidget(proceedCB);
}
void ConclusionPage::initializePage(){
QString str;
for (int i=0; i<MAX_CHANNELS; i++){
if (!wizDlg->channel[i].isEmpty()){
str += QString(tr("Channel %1: ").arg(i+1));
str += wizDlg->channel[i].print();
str += QString("<br>");
}
}
textLabel->setText(str);
}