2020-09-13 20:44:45 +08:00
|
|
|
#include "mode.h"
|
|
|
|
|
2022-04-04 05:34:18 +08:00
|
|
|
#include "Generator/generator.h"
|
|
|
|
#include "VNA/vna.h"
|
|
|
|
#include "SpectrumAnalyzer/spectrumanalyzer.h"
|
|
|
|
#include "CustomWidgets/informationbox.h"
|
|
|
|
|
2021-10-21 19:00:34 +08:00
|
|
|
#include "ui_main.h"
|
|
|
|
|
2020-09-13 20:44:45 +08:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSettings>
|
2020-11-12 02:13:53 +08:00
|
|
|
#include <QDebug>
|
2021-04-13 02:15:38 +08:00
|
|
|
#include <QFileDialog>
|
2022-04-04 05:34:18 +08:00
|
|
|
#include <QInputDialog>
|
2020-09-13 20:44:45 +08:00
|
|
|
|
|
|
|
Mode* Mode::activeMode = nullptr;
|
2022-04-04 05:34:18 +08:00
|
|
|
//QButtonGroup* Mode::modeButtonGroup = nullptr;
|
2020-09-13 20:44:45 +08:00
|
|
|
|
2022-04-04 05:34:18 +08:00
|
|
|
Mode::Mode(AppWindow *window, QString name, QString SCPIname)
|
2020-11-01 06:03:34 +08:00
|
|
|
: QObject(window),
|
2022-04-04 05:34:18 +08:00
|
|
|
SCPINode(SCPIname),
|
2020-11-01 06:03:34 +08:00
|
|
|
window(window),
|
2020-09-13 20:44:45 +08:00
|
|
|
name(name),
|
|
|
|
central(nullptr)
|
2022-04-04 05:34:18 +08:00
|
|
|
{
|
|
|
|
window->getSCPI()->add(this);
|
|
|
|
}
|
2020-09-13 20:44:45 +08:00
|
|
|
|
2022-04-04 05:34:18 +08:00
|
|
|
Mode::~Mode()
|
|
|
|
{
|
|
|
|
window->getSCPI()->remove(this);
|
|
|
|
if(activeMode == this) {
|
|
|
|
deactivate();
|
|
|
|
}
|
2022-07-03 23:22:50 +08:00
|
|
|
window->getCentral()->removeWidget(central);
|
|
|
|
delete central;
|
2022-04-22 19:04:36 +08:00
|
|
|
for(auto d : docks) {
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
for(auto t : toolbars) {
|
|
|
|
delete t;
|
|
|
|
}
|
2020-09-13 20:44:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mode::activate()
|
|
|
|
{
|
|
|
|
if(activeMode == this) {
|
|
|
|
// already active;
|
|
|
|
return;
|
|
|
|
} else if(activeMode) {
|
|
|
|
activeMode->deactivate();
|
|
|
|
}
|
|
|
|
|
2020-11-12 02:13:53 +08:00
|
|
|
qDebug() << "Activating mode" << name;
|
2020-09-13 20:44:45 +08:00
|
|
|
// show all mode specific GUI elements
|
|
|
|
for(auto t : toolbars) {
|
|
|
|
t->show();
|
|
|
|
window->getUi()->menuToolbars->addAction(t->toggleViewAction());
|
|
|
|
}
|
|
|
|
for(auto d : docks) {
|
|
|
|
d->show();
|
|
|
|
window->getUi()->menuDocks->addAction(d->toggleViewAction());
|
|
|
|
}
|
|
|
|
for(auto a : actions) {
|
|
|
|
a->setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSettings settings;
|
2022-07-03 23:22:50 +08:00
|
|
|
window->getCentral()->setCurrentWidget(central);
|
2020-09-13 20:44:45 +08:00
|
|
|
// restore dock and toolbar positions
|
|
|
|
window->restoreState(settings.value("windowState_"+name).toByteArray());
|
|
|
|
|
|
|
|
// restore visibility of toolbars and docks
|
2020-09-17 21:51:20 +08:00
|
|
|
for(auto d : docks) {
|
2020-09-13 20:44:45 +08:00
|
|
|
bool hidden = settings.value("dock_"+name+"_"+d->windowTitle(), d->isHidden()).toBool();
|
|
|
|
if(hidden) {
|
|
|
|
d->hide();
|
|
|
|
} else {
|
|
|
|
d->show();
|
|
|
|
}
|
|
|
|
}
|
2020-09-17 21:51:20 +08:00
|
|
|
for(auto t : toolbars) {
|
2020-09-13 20:44:45 +08:00
|
|
|
bool hidden = settings.value("toolbar_"+name+"_"+t->windowTitle(), t->isHidden()).toBool();
|
|
|
|
if(hidden) {
|
|
|
|
t->hide();
|
|
|
|
} else {
|
|
|
|
t->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
activeMode = this;
|
|
|
|
|
|
|
|
if(window->getDevice()) {
|
|
|
|
initializeDevice();
|
|
|
|
}
|
2022-01-22 05:33:58 +08:00
|
|
|
|
|
|
|
emit statusbarMessage(statusbarMsg);
|
2020-09-13 20:44:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mode::deactivate()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
// save dock/toolbar visibility
|
2020-09-17 21:51:20 +08:00
|
|
|
for(auto d : docks) {
|
2020-09-13 20:44:45 +08:00
|
|
|
settings.setValue("dock_"+name+"_"+d->windowTitle(), d->isHidden());
|
|
|
|
}
|
2020-09-17 21:51:20 +08:00
|
|
|
for(auto t : toolbars) {
|
2020-09-13 20:44:45 +08:00
|
|
|
settings.setValue("toolbar_"+name+"_"+t->windowTitle(), t->isHidden());
|
|
|
|
}
|
|
|
|
settings.setValue("windowState_"+name, window->saveState());
|
|
|
|
|
|
|
|
// hide all mode specific GUI elements
|
|
|
|
for(auto t : toolbars) {
|
|
|
|
t->hide();
|
|
|
|
window->getUi()->menuToolbars->removeAction(t->toggleViewAction());
|
|
|
|
}
|
|
|
|
for(auto d : docks) {
|
|
|
|
d->hide();
|
|
|
|
window->getUi()->menuDocks->removeAction(d->toggleViewAction());
|
|
|
|
}
|
|
|
|
for(auto a : actions) {
|
|
|
|
a->setVisible(false);
|
|
|
|
}
|
|
|
|
|
2020-11-12 02:13:53 +08:00
|
|
|
qDebug() << "Deactivated mode" << name;
|
2022-04-04 05:34:18 +08:00
|
|
|
if(window->getDevice()) {
|
|
|
|
window->getDevice()->SetIdle();
|
|
|
|
}
|
2020-09-13 20:44:45 +08:00
|
|
|
activeMode = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mode *Mode::getActiveMode()
|
|
|
|
{
|
|
|
|
return activeMode;
|
|
|
|
}
|
|
|
|
|
2022-04-04 05:34:18 +08:00
|
|
|
QString Mode::TypeToName(Mode::Type t)
|
|
|
|
{
|
|
|
|
switch(t) {
|
|
|
|
case Type::VNA: return "Vector Network Analyzer";
|
|
|
|
case Type::SG: return "Signal Generator";
|
|
|
|
case Type::SA: return "Spectrum Analyzer";
|
|
|
|
default: return "Invalid";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Mode::Type Mode::TypeFromName(QString s)
|
|
|
|
{
|
|
|
|
for(unsigned int i=0;i<(int)Type::Last;i++) {
|
|
|
|
if(s == TypeToName((Type) i)) {
|
|
|
|
return (Type) i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Type::Last;
|
|
|
|
}
|
|
|
|
|
2021-04-13 02:15:38 +08:00
|
|
|
void Mode::saveSreenshot()
|
|
|
|
{
|
|
|
|
auto filename = QFileDialog::getSaveFileName(nullptr, "Save plot image", "", "PNG image files (*.png)", nullptr, QFileDialog::DontUseNativeDialog);
|
|
|
|
if(filename.isEmpty()) {
|
|
|
|
// aborted selection
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(filename.endsWith(".png")) {
|
|
|
|
filename.chop(4);
|
|
|
|
}
|
|
|
|
filename += ".png";
|
|
|
|
central->grab().save(filename);
|
|
|
|
}
|
|
|
|
|
2022-04-04 05:34:18 +08:00
|
|
|
Mode *Mode::createNew(AppWindow *window, QString name, Mode::Type t)
|
|
|
|
{
|
|
|
|
switch(t) {
|
|
|
|
case Type::VNA: return new VNA(window, name);
|
|
|
|
case Type::SG: return new Generator(window, name);
|
|
|
|
case Type::SA: return new SpectrumAnalyzer(window, name);
|
|
|
|
default: return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-13 20:44:45 +08:00
|
|
|
void Mode::finalize(QWidget *centralWidget)
|
|
|
|
{
|
|
|
|
central = centralWidget;
|
2022-07-03 23:22:50 +08:00
|
|
|
window->getCentral()->addWidget(central);
|
2020-09-17 21:51:20 +08:00
|
|
|
// Set ObjectName for toolbars and docks
|
|
|
|
for(auto d : docks) {
|
|
|
|
d->setObjectName(d->windowTitle()+name);
|
|
|
|
}
|
|
|
|
for(auto t : toolbars) {
|
|
|
|
t->setObjectName(t->windowTitle()+name);
|
|
|
|
}
|
2020-09-13 20:44:45 +08:00
|
|
|
// hide all mode specific GUI elements
|
|
|
|
for(auto t : toolbars) {
|
|
|
|
t->hide();
|
|
|
|
}
|
|
|
|
for(auto d : docks) {
|
|
|
|
d->hide();
|
|
|
|
}
|
|
|
|
for(auto a : actions) {
|
|
|
|
a->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-22 05:33:58 +08:00
|
|
|
void Mode::setStatusbarMessage(QString msg)
|
|
|
|
{
|
|
|
|
statusbarMsg = msg;
|
|
|
|
if(this == activeMode) {
|
|
|
|
emit statusbarMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-13 20:44:45 +08:00
|
|
|
QString Mode::getName() const
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
2022-04-04 05:34:18 +08:00
|
|
|
|
|
|
|
void Mode::setName(const QString &value)
|
|
|
|
{
|
|
|
|
name = value;
|
|
|
|
}
|
|
|
|
|
2022-06-24 10:46:12 +08:00
|
|
|
void Mode::updateGraphColors()
|
|
|
|
{
|
|
|
|
if ((getType() == Type::SA) || getType() == Type::VNA) {
|
|
|
|
for (auto p : TracePlot::getPlots()) {
|
|
|
|
p->updateGraphColors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|