File size: 5,043 Bytes
68ce2fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
/*
Author(s): Anton Deguet
Created on: 2026-02-20
(C) Copyright 2026 Johns Hopkins University (JHU), All Rights Reserved.
--- begin cisst license - do not edit ---
This software is provided "as is" under an open source license, with
no warranty. The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.
--- end cisst license ---
*/
#include <cisstMultiTask/mtsCommandLineOptionsQt.h>
#if CISST_HAS_QTNODES
#include <cisstMultiTask/mtsComponentViewerQt.h>
#endif
#include <cisstMultiTask/mtsCollectorFactoryQtWidget.h>
#include <cisstMultiTask/mtsManagerLocal.h>
#include <cisstCommon/cmnQt.h>
#include <cisstCommon/cmnPath.h>
#include <cisstCommon/cmnLoggerQtWidget.h>
#include <QApplication>
#include <QFileInfo>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTabWidget>
#include <iostream>
#include <string>
mtsCommandLineOptionsQt::mtsCommandLineOptionsQt(const std::string & options):
mtsCommandLineOptions(options)
{
if (options.find('D') != std::string::npos) {
this->AddOptionNoValue("D", "dark-mode",
"replaces the default Qt palette with darker colors");
}
if (options.find('S') != std::string::npos) {
this->AddOptionOneValue("S", "qt-style",
"Qt style, use this option with a random name to see available styles",
cmnCommandLineOptions::OPTIONAL_OPTION, &QtStyle);
}
#if CISST_HAS_QTNODES
if (options.find('M') != std::string::npos) {
this->AddOptionNoValue("M", "component-viewer",
"start the component viewer");
}
#endif
if (options.find('W') != std::string::npos) {
this->AddOptionNoValue("W", "logger",
"show the logger widget to dynamically change log levels for all classes");
}
}
void mtsCommandLineOptionsQt::Apply(void)
{
mtsCommandLineOptions::Apply();
cmnQt::QApplicationExitsOnCtrlC();
if (this->IsSet("dark-mode")) {
cmnQt::SetDarkMode();
}
if (this->IsSet("qt-style")) {
std::string errorMessage = cmnQt::SetStyle(QtStyle);
if (errorMessage != "") {
std::cerr << errorMessage << std::endl;
}
}
#if CISST_HAS_QTNODES
bool showViewer = this->IsSet("component-viewer");
#else
bool showViewer = false;
#endif
bool showCollection = !CollectionConfig.empty();
bool showLogger = this->IsSet("logger");
int showCount = (showViewer ? 1 : 0) + (showCollection ? 1 : 0) + (showLogger ? 1 : 0);
if (showCount > 0) {
mtsManagerLocal * componentManager = mtsManagerLocal::GetInstance();
QString qAppName = qApp->applicationName();
if (qAppName.isEmpty()) {
qAppName = QFileInfo(qApp->applicationFilePath()).baseName();
}
std::string appName = qAppName.toStdString();
QWidget * systemWindow = nullptr;
QTabWidget * tabWidget = nullptr;
if (showCount > 1) {
tabWidget = new QTabWidget();
systemWindow = tabWidget;
} else {
systemWindow = new QWidget();
new QVBoxLayout(systemWindow);
systemWindow->layout()->setContentsMargins(0, 0, 0, 0);
}
systemWindow->setWindowTitle(QString::fromStdString(appName + " System"));
if (showCollection) {
mtsCollectorFactoryQtWidget * collectorWidget = new mtsCollectorFactoryQtWidget("collectors-GUI");
componentManager->AddComponent(collectorWidget);
componentManager->Connect(collectorWidget->GetName(), "Collector", "collectors", "Control");
QWidget * collectorWrapper = new QWidget();
QHBoxLayout * collectorLayout = new QHBoxLayout(collectorWrapper);
collectorLayout->addWidget(collectorWidget);
collectorLayout->addStretch();
if (tabWidget) {
tabWidget->addTab(collectorWrapper, "Collection");
} else {
systemWindow->layout()->addWidget(collectorWrapper);
}
}
#if CISST_HAS_QTNODES
if (showViewer) {
mtsComponentViewerQt * viewer = new mtsComponentViewerQt("ComponentViewer");
componentManager->AddComponent(viewer);
if (tabWidget) {
tabWidget->addTab(viewer, "Graph");
} else {
systemWindow->layout()->addWidget(viewer);
}
}
#endif
if (showLogger) {
cmnLoggerQtWidget * loggerWidget = new cmnLoggerQtWidget(nullptr);
if (tabWidget) {
tabWidget->addTab(loggerWidget->GetWidget(), "Logger");
} else {
systemWindow->layout()->addWidget(loggerWidget->GetWidget());
}
}
systemWindow->show();
}
}
|