Fix X7 R9M power line not enabled (#5973)
[opentx.git] / companion / src / modeledit / modeledit.cpp
blob59fb408c440708faa5a60f40c9c8bbd1b64511e9
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "modeledit.h"
22 #include "helpers.h"
23 #include "ui_modeledit.h"
24 #include "setup.h"
25 #include "heli.h"
26 #include "flightmodes.h"
27 #include "inputs.h"
28 #include "mixes.h"
29 #include "channels.h"
30 #include "curves.h"
31 #include "verticalscrollarea.h"
32 #include "logicalswitches.h"
33 #include "customfunctions.h"
34 #include "telemetry.h"
35 #include "appdata.h"
37 ModelEdit::ModelEdit(QWidget * parent, RadioData & radioData, int modelId, Firmware * firmware) :
38 QDialog(parent),
39 ui(new Ui::ModelEdit),
40 modelId(modelId),
41 radioData(radioData),
42 firmware(firmware)
44 Stopwatch s1("ModelEdit");
45 gStopwatch.report("ModelEdit start constructor");
47 ui->setupUi(this);
48 setWindowIcon(CompanionIcon("edit.png"));
49 restoreGeometry(g.modelEditGeo());
50 ui->pushButton->setIcon(CompanionIcon("simulate.png"));
51 SetupPanel * setupPanel = new SetupPanel(this, radioData.models[modelId], radioData.generalSettings, firmware);
52 addTab(setupPanel, tr("Setup"));
53 if (firmware->getCapability(Heli))
54 addTab(new HeliPanel(this, radioData.models[modelId], radioData.generalSettings, firmware), tr("Heli"));
55 addTab(new FlightModesPanel(this, radioData.models[modelId], radioData.generalSettings, firmware), tr("Flight Modes"));
56 addTab(new InputsPanel(this, radioData.models[modelId], radioData.generalSettings, firmware), tr("Inputs"));
57 s1.report("inputs");
58 addTab(new MixesPanel(this, radioData.models[modelId], radioData.generalSettings, firmware), tr("Mixes"));
59 s1.report("Mixes");
60 Channels * chnPanel = new Channels(this, radioData.models[modelId], radioData.generalSettings, firmware);
61 addTab(chnPanel, tr("Outputs"));
62 s1.report("Outputs");
63 addTab(new Curves(this, radioData.models[modelId], radioData.generalSettings, firmware), tr("Curves"));
64 addTab(new LogicalSwitchesPanel(this, radioData.models[modelId], radioData.generalSettings, firmware), tr("Logical Switches"));
65 s1.report("LS");
66 addTab(new CustomFunctionsPanel(this, &radioData.models[modelId], radioData.generalSettings, firmware), tr("Special Functions"));
67 s1.report("CF");
68 if (firmware->getCapability(Telemetry) & TM_HASTELEMETRY)
69 addTab(new TelemetryPanel(this, radioData.models[modelId], radioData.generalSettings, firmware), tr("Telemetry"));
71 onTabIndexChanged(ui->tabWidget->currentIndex()); // make sure to trigger update on default tab panel
73 connect(setupPanel, &SetupPanel::extendedLimitsToggled, chnPanel, &Channels::refreshExtendedLimits);
74 connect(ui->tabWidget, &QTabWidget::currentChanged, this, &ModelEdit::onTabIndexChanged);
75 connect(ui->pushButton, &QPushButton::clicked, this, &ModelEdit::launchSimulation);
77 s1.report("end");
78 gStopwatch.report("ModelEdit end constructor");
81 ModelEdit::~ModelEdit()
83 delete ui;
86 void ModelEdit::closeEvent(QCloseEvent *event)
88 g.modelEditGeo( saveGeometry() );
91 void ModelEdit::addTab(GenericPanel *panel, QString text)
93 panels << panel;
94 QWidget * widget = new QWidget(ui->tabWidget);
95 QVBoxLayout *baseLayout = new QVBoxLayout(widget);
96 VerticalScrollArea * area = new VerticalScrollArea(widget, panel);
97 baseLayout->addWidget(area);
98 ui->tabWidget->addTab(widget, text);
99 connect(panel, &GenericPanel::modified, this, &ModelEdit::modified);
102 void ModelEdit::onTabIndexChanged(int index)
104 if (index < panels.size())
105 panels.at(index)->update();
108 void ModelEdit::launchSimulation()
110 startSimulation(this, radioData, modelId);