chore(cpn): move wizard to subdir (#6564)

This commit is contained in:
ikkemaniac
2025-09-01 14:19:37 +10:00
committed by GitHub
parent f141229222
commit 7230b26dc3
7 changed files with 40 additions and 3 deletions
+37
View File
@@ -0,0 +1,37 @@
project(wizard)
set(${PROJECT_NAME}_NAMES
wizarddata
wizarddialog
)
AddHeadersSources()
# AUTOMOC does not detect so manually process
set(${PROJECT_NAME}_MOC
wizarddata.h
wizarddialog.h
)
qt_wrap_cpp(${PROJECT_NAME}_SRCS
${${PROJECT_NAME}_MOC}
)
add_library(${PROJECT_NAME}
${${PROJECT_NAME}_HDRS}
${${PROJECT_NAME}_SRCS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
${CPN_COMMON_LIB}
)
target_include_directories(${PROJECT_NAME}
PRIVATE
"${CMAKE_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
PUBLIC
"${CMAKE_CURRENT_LIST_DIR}"
)
+145
View File
@@ -0,0 +1,145 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <string.h>
#include "eeprominterface.h"
#include "wizarddata.h"
Channel::Channel()
{
clear();
}
void Channel::clear()
{
page = Page_None;
prebooked = false;
input1 = NO_INPUT;
input2 = NO_INPUT;
weight1 = 0;
weight2 = 0;
}
WizMix::WizMix(const GeneralSettings & settings, unsigned int modelId, const ModelData & modelData):
complete(false),
modelId(modelId),
settings(settings),
originalModelData(modelData),
vehicle(NOVEHICLE)
{
memset(name, 0, sizeof(name));
memcpy(name, originalModelData.name, sizeof(name) - 1);
name[sizeof(name) - 1] = '\0';
}
void WizMix::maxMixSwitch(char *name, MixData &mix, int channel, int sw, int weight)
{
memset(mix.name, 0, sizeof(mix.name));
strncpy(mix.name, name, sizeof(mix.name)-1);
mix.destCh = channel;
mix.srcRaw = RawSource(SOURCE_TYPE_MAX);
mix.swtch = RawSwitch(SWITCH_TYPE_SWITCH, sw + 1);
mix.weight = weight;
}
void WizMix::addMix(ModelData &model, Input input, int weight, int channel, int & mixIndex)
{
if (input != NO_INPUT) {
if (input >= RUDDER_INPUT && input <= AILERONS_INPUT) {
MixData & mix = model.mixData[mixIndex++];
mix.destCh = channel + 1;
mix.srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, settings.getDefaultChannel(input - 1) + 1);
mix.weight = weight;
}
else if (input==FLAPS_INPUT){
// There ought to be some kind of constants for switches somewhere...
maxMixSwitch((char *)tr("FlapUp").toLatin1().data(), model.mixData[mixIndex++], channel+1, SWITCH_SA0 - 1, weight);
maxMixSwitch((char *)tr("FlapDn").toLatin1().data(), model.mixData[mixIndex++], channel+1, SWITCH_SA2 - 1, -weight);
}
else if (input==AIRBRAKES_INPUT){
maxMixSwitch((char *)tr("ArbkOf").toLatin1().data(), model.mixData[mixIndex++], channel+1, SWITCH_SE0 - 1, -weight);
maxMixSwitch((char *)tr("ArbkOn").toLatin1().data(), model.mixData[mixIndex++], channel+1, SWITCH_SE2 - 1, weight);
}
}
}
WizMix::operator ModelData()
{
int throttleChannel = -1;
ModelData model;
model.labels[0] = '\0';
model.used = true;
model.moduleData[0].modelId = modelId;
model.setDefaultInputs(settings);
model.setDefaultFunctionSwitches(Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches));
int mixIndex = 0;
int timerIndex = 0;
memset(model.name, 0, sizeof(model.name));
memcpy(model.name, name, sizeof(model.name) - 1);
model.name[sizeof(model.name) - 1] = '\0';
// Add the channel mixes
for (int i=0; i<WIZ_MAX_CHANNELS; i++ )
{
Channel ch = channel[i];
addMix(model, ch.input1, ch.weight1, i, mixIndex);
addMix(model, ch.input2, ch.weight2, i, mixIndex);
if (ch.input1 == THROTTLE_INPUT || ch.input2 == THROTTLE_INPUT) {
throttleChannel++;
if (options[THROTTLE_CUT_OPTION]) {
// Add the Throttle Cut option
MixData & mix = model.mixData[mixIndex++];
mix.destCh = i+1;
mix.srcRaw = RawSource(SOURCE_TYPE_MAX);
mix.weight = -100;
mix.swtch.type = SWITCH_TYPE_SWITCH;
mix.swtch.index = SWITCH_SF0;
mix.mltpx = MLTPX_REP;
memset(mix.name, 0, sizeof(mix.name));
strncpy(mix.name, WizMix::tr("Cut").toLatin1().data(), MIXDATA_NAME_LEN);
}
}
}
// Add the Flight Timer option
if (options[FLIGHT_TIMER_OPTION] && throttleChannel >= 0){
memset(model.timers[timerIndex].name, 0, sizeof(model.timers[timerIndex].name));
strncpy(model.timers[timerIndex].name, WizMix::tr("Flt").toLatin1().data(), sizeof(model.timers[timerIndex].name)-1);
model.timers[timerIndex].mode = TimerData::TIMERMODE_START;
timerIndex++;
}
// Add the Throttle Timer option
if (options[THROTTLE_TIMER_OPTION] && throttleChannel >= 0){
memset(model.timers[timerIndex].name, 0, sizeof(model.timers[timerIndex].name));
strncpy(model.timers[timerIndex].name, WizMix::tr("Thr").toLatin1().data(), sizeof(model.timers[timerIndex].name)-1);
model.timers[timerIndex].mode = TimerData::TIMERMODE_THR;
timerIndex++;
}
return model;
}
+114
View File
@@ -0,0 +1,114 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include "eeprominterface.h"
#include <QtCore>
#define WIZ_MAX_CHANNELS 8
enum Input {
NO_INPUT,
RUDDER_INPUT,
ELEVATOR_INPUT,
THROTTLE_INPUT,
AILERONS_INPUT,
FLAPS_INPUT,
AIRBRAKES_INPUT
};
enum Vehicle {
NOVEHICLE,
PLANE,
MULTICOPTER,
HELICOPTER
};
#define WIZ_MAX_OPTIONS 3
enum Options {
FLIGHT_TIMER_OPTION,
THROTTLE_CUT_OPTION,
THROTTLE_TIMER_OPTION
};
enum WizardPage {
Page_None = -1,
Page_Models,
Page_Throttle,
Page_Wingtypes,
Page_Ailerons,
Page_Flaps,
Page_Airbrakes,
Page_Elevons,
Page_Rudder,
Page_Tails,
Page_Tail,
Page_Vtail,
Page_Simpletail,
Page_Cyclic,
Page_Gyro,
Page_Flybar,
Page_Fblheli,
Page_Helictrl,
Page_Multirotor,
Page_Options,
Page_Conclusion
};
class Channel
{
public:
WizardPage page; // Originating dialog, only of interest for producer
bool prebooked; // Temporary lock variable
Input input1;
Input input2;
int weight1;
int weight2;
Channel();
void clear();
};
class WizMix : public QObject
{
Q_OBJECT
public:
bool complete;
char name[MODEL_NAME_LEN + 1];
unsigned int modelId;
const GeneralSettings & settings;
const ModelData & originalModelData;
Vehicle vehicle;
Channel channel[WIZ_MAX_CHANNELS];
bool options[WIZ_MAX_OPTIONS];
WizMix(const GeneralSettings & settings, unsigned int modelId, const ModelData & modelData);
operator ModelData();
private:
WizMix();
void addMix(ModelData & model, Input input, int weight, int channel, int & mixerIndex);
void maxMixSwitch(char *name, MixData &mix, int destCh, int sw, int weight);
};
File diff suppressed because it is too large Load Diff
+372
View File
@@ -0,0 +1,372 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <QtWidgets>
#include "wizarddata.h"
class WizardDialog : public QWizard
{
Q_OBJECT
public:
WizMix mix;
WizardDialog(const GeneralSettings & settings, const unsigned int modelId, const ModelData & modelData, QWidget *parent = 0);
const GeneralSettings & settings;
private slots:
void showHelp();
};
class StandardPage: public QWizardPage
{
Q_OBJECT
public:
StandardPage(WizardPage curPage, WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
WizardDialog *wizDlg;
protected:
void releaseBookings();
void releasePreBookings();
void initializePage();
void cleanupPage();
int getDefaultChannel(const Input input);
int nextFreeChannel(int channel = 0);
void populateCB(QComboBox * cb, int preferred=-1);
bool bookChannel(QComboBox * cb, Input input1, int weight1, Input input2=NO_INPUT, int weight2=0);
int totalChannelsAvailable();
private:
QLabel *topLabel;
WizardPage pageCurrent;
int pageFollower;
int nextId() const;
};
class ModelSelectionPage: public StandardPage
{
Q_OBJECT
public:
ModelSelectionPage(WizardDialog *dlg, QString image, QString title, QString text);
private:
QLineEdit *nameLineEdit;
QRadioButton *planeRB;
QRadioButton *multirotorRB;
QRadioButton *helicopterRB;
void initializePage();
bool validatePage();
int nextId() const;
};
class WingtypeSelectionPage: public StandardPage
{
Q_OBJECT
public:
WingtypeSelectionPage(WizardDialog *dlg, QString image, QString title, QString text);
private:
QRadioButton *deltaWingRB;
QRadioButton *standardWingRB;
int nextId() const;
};
class TailSelectionPage: public StandardPage
{
Q_OBJECT
public:
TailSelectionPage(WizardDialog *dlg, QString image, QString title, QString text);
private:
QRadioButton *vTailRB;
QRadioButton *standardTailRB;
QRadioButton *simpleTailRB;
int nextId() const;
};
class FlybarSelectionPage: public StandardPage
{
Q_OBJECT
public:
FlybarSelectionPage(WizardDialog *dlg, QString image, QString title, QString text);
private:
QRadioButton *flybarRB;
QRadioButton *noFlybarRB;
int nextId() const;
};
class ThrottlePage: public StandardPage
{
Q_OBJECT
public:
ThrottlePage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
protected slots:
void onMotorStateChanged(bool toggled);
private:
QRadioButton *motorRB;
QRadioButton *noMotorRB;
QComboBox *throttleCB;
};
class AileronsPage: public StandardPage
{
Q_OBJECT
public:
AileronsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
protected slots:
void noAileronChannel();
void oneAileronChannel();
void twoAileronChannels();
private:
QRadioButton *oneAileronRB;
QRadioButton *twoAileronsRB;
QRadioButton *noAileronsRB;
QComboBox *aileron1CB;
QComboBox *aileron2CB;
};
class FlapsPage: public StandardPage
{
Q_OBJECT
public:
FlapsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
protected slots:
void noFlapChannel();
void oneFlapChannel();
void twoFlapChannels();
private:
QRadioButton *oneFlapRB;
QRadioButton *twoFlapsRB;
QRadioButton *noFlapsRB;
QComboBox *flap1CB;
QComboBox *flap2CB;
};
class AirbrakesPage: public StandardPage
{
Q_OBJECT
public:
AirbrakesPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
protected slots:
void noAirbrakeChannel();
void oneAirbrakeChannel();
void twoAirbrakeChannels();
private:
QRadioButton *oneAirbrakeRB;
QRadioButton *twoAirbrakesRB;
QRadioButton *noAirbrakesRB;
QComboBox *airbrake1CB;
QComboBox *airbrake2CB;
};
class ElevonsPage: public StandardPage
{
Q_OBJECT
public:
ElevonsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QComboBox *elevon1CB;
QComboBox *elevon2CB;
};
class RudderPage: public StandardPage
{
Q_OBJECT
public:
RudderPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
protected slots:
void noRudder();
void hasRudder();
private:
QRadioButton *noRudderRB;
QRadioButton *hasRudderRB;
QComboBox *rudderCB;
};
class TailPage: public StandardPage
{
Q_OBJECT
public:
TailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
void cleanupPage();
bool validatePage();
private:
QComboBox *elevatorCB;
QComboBox *rudderCB;
QLayout *l;
QLabel *errorMessage;
};
class VTailPage: public StandardPage
{
Q_OBJECT
public:
VTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QComboBox *tail1CB;
QComboBox *tail2CB;
};
class SimpleTailPage: public StandardPage
{
Q_OBJECT
public:
SimpleTailPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QComboBox *elevatorCB;
};
class CyclicPage: public StandardPage
{
Q_OBJECT
public:
CyclicPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QRadioButton *cyclic90RB;
QRadioButton *cyclic120RB;
QRadioButton *cyclic120XRB;
QRadioButton *cyclic140RB;
};
class GyroPage: public StandardPage
{
Q_OBJECT
public:
GyroPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QRadioButton *noGyroRB;
QRadioButton *switchGyroRB;
QRadioButton *potGyroRB;
};
class FblPage: public StandardPage
{
Q_OBJECT
public:
FblPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QComboBox *throttleCB;
QComboBox *yawCB;
QComboBox *pitchCB;
QComboBox *rollCB;
};
class HeliPage: public StandardPage
{
Q_OBJECT
public:
HeliPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QComboBox *throttleCB;
QComboBox *yawCB;
QComboBox *pitchCB;
QComboBox *rollCB;
};
class MultirotorPage: public StandardPage
{
Q_OBJECT
public:
MultirotorPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QComboBox *throttleCB;
QComboBox *yawCB;
QComboBox *pitchCB;
QComboBox *rollCB;
};
class OptionsPage: public StandardPage
{
Q_OBJECT
public:
OptionsPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QCheckBox *throttleCutRB;
QCheckBox *flightTimerRB;
QCheckBox *throttleTimerRB;
};
class ConclusionPage: public StandardPage
{
Q_OBJECT
public:
ConclusionPage(WizardDialog *dlg, QString image, QString title, QString text, int nextPage=-1);
void initializePage();
bool validatePage();
private:
QCheckBox *proceedCB;
QLabel *textLabel;
};
class WizardPrinter:QObject
{
Q_OBJECT
public:
WizardPrinter( WizMix * );
QString print();
private:
WizMix *mix;
QString inputName( Input );
QString vehicleName( Vehicle );
QString printChannel( Input, int, Input, int );
};