2025-10-13 16:15:18 +00:00
|
|
|
|
#include "ui/Menu/SimuRunMenu.h"
|
2025-10-28 08:12:14 +00:00
|
|
|
|
#include "ui/Layout/AddParamSetting.h"
|
2025-10-29 09:11:36 +00:00
|
|
|
|
#include "ui/DockWidget.h"
|
|
|
|
|
|
#include "ui/DockTitleBar.h"
|
|
|
|
|
|
#include "ui/MainWindow.h"
|
2025-10-13 16:15:18 +00:00
|
|
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
|
#include <QLabel>
|
2025-10-28 08:12:14 +00:00
|
|
|
|
#include <QGroupBox>
|
2025-10-13 16:15:18 +00:00
|
|
|
|
|
|
|
|
|
|
#include "workspace/WorkSpaceManager.h"
|
|
|
|
|
|
#include "workspace/WorkSpace.h"
|
|
|
|
|
|
#include "workspace/CommandManager.h"
|
2025-01-05 14:29:59 +00:00
|
|
|
|
|
|
|
|
|
|
SimuRunMenu::SimuRunMenu(QWidget *parent)
|
2025-10-28 08:12:14 +00:00
|
|
|
|
: QWidget(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pParam = NULL;
|
2025-10-29 09:11:36 +00:00
|
|
|
|
m_mainWindow = NULL;
|
2025-10-13 16:15:18 +00:00
|
|
|
|
|
2025-10-28 08:12:14 +00:00
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout(this);
|
|
|
|
|
|
layout->setContentsMargins(9, 0, 0, 0);
|
|
|
|
|
|
layout->setSpacing(6);
|
|
|
|
|
|
setLayout(layout);
|
2025-10-13 16:15:18 +00:00
|
|
|
|
|
|
|
|
|
|
// Refresh when workspace changes
|
|
|
|
|
|
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged,
|
|
|
|
|
|
this, &SimuRunMenu::OnWorkspaceChanged);
|
|
|
|
|
|
|
|
|
|
|
|
// Initial population
|
|
|
|
|
|
RefreshButtons();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimuRunMenu::~SimuRunMenu() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimuRunMenu::OnWorkspaceChanged(WorkSpace* ws) {
|
|
|
|
|
|
Q_UNUSED(ws);
|
|
|
|
|
|
RefreshButtons();
|
2025-01-05 14:29:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-13 16:15:18 +00:00
|
|
|
|
void SimuRunMenu::RefreshButtons() {
|
|
|
|
|
|
// Clear existing buttons
|
2025-10-28 08:12:14 +00:00
|
|
|
|
ClearAllBtn();
|
|
|
|
|
|
|
|
|
|
|
|
CreateMatlabParam();
|
|
|
|
|
|
CreateLine();
|
2025-10-13 16:15:18 +00:00
|
|
|
|
|
|
|
|
|
|
auto* ws = WorkSpaceManager::Get().GetCurrent();
|
2025-10-28 08:12:14 +00:00
|
|
|
|
if (!ws)
|
|
|
|
|
|
{
|
2025-10-13 16:15:18 +00:00
|
|
|
|
// Show hint when no workspace
|
2025-10-28 08:12:14 +00:00
|
|
|
|
if (auto* layout = qobject_cast<QHBoxLayout*>(this->layout())) {
|
2025-10-13 16:15:18 +00:00
|
|
|
|
auto* hint = new QLabel(tr("no workspace"), this);
|
|
|
|
|
|
layout->addWidget(hint);
|
|
|
|
|
|
}
|
2025-10-28 08:12:14 +00:00
|
|
|
|
|
|
|
|
|
|
CreateSpacer();
|
|
|
|
|
|
|
2025-10-13 16:15:18 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CommandManager mgr;
|
|
|
|
|
|
const auto items = mgr.ListCommands(ws);
|
2025-10-28 08:12:14 +00:00
|
|
|
|
if (items.empty())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (auto* layout = qobject_cast<QHBoxLayout*>(this->layout())) {
|
2025-10-13 16:15:18 +00:00
|
|
|
|
auto* hint = new QLabel(tr("no commands"), this);
|
|
|
|
|
|
layout->addWidget(hint);
|
|
|
|
|
|
}
|
2025-10-28 08:12:14 +00:00
|
|
|
|
|
|
|
|
|
|
CreateSpacer();
|
|
|
|
|
|
|
2025-10-13 16:15:18 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-10-28 08:12:14 +00:00
|
|
|
|
|
2025-10-13 16:15:18 +00:00
|
|
|
|
// Render all commands in a single group without trigger distinction
|
|
|
|
|
|
CreateGroup(tr("Commands"), items);
|
2025-10-28 08:12:14 +00:00
|
|
|
|
|
|
|
|
|
|
CreateSpacer();
|
2025-10-13 16:15:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimuRunMenu::CreateGroup(const QString& title,
|
|
|
|
|
|
const std::vector<Command>& items) {
|
2025-10-28 08:12:14 +00:00
|
|
|
|
auto* root = qobject_cast<QHBoxLayout*>(this->layout());
|
2025-10-13 16:15:18 +00:00
|
|
|
|
if (!root) return;
|
|
|
|
|
|
|
2025-10-28 08:12:14 +00:00
|
|
|
|
QGroupBox * groupBox = new QGroupBox;
|
|
|
|
|
|
QHBoxLayout * hGroupLayout = new QHBoxLayout;
|
|
|
|
|
|
hGroupLayout->setContentsMargins(10, 0, 10, 0);
|
|
|
|
|
|
groupBox->setTitle(title);
|
|
|
|
|
|
groupBox->setAlignment(Qt::AlignHCenter);
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& item : items) {
|
|
|
|
|
|
auto* btn = new QToolButton(this);
|
|
|
|
|
|
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|
|
|
|
|
btn->setText(item.name.isEmpty() ? tr("unnamed") : item.name);
|
|
|
|
|
|
btn->setIcon(QIcon(":/res/default/Command.png"));
|
|
|
|
|
|
QString tip = item.descript;
|
|
|
|
|
|
if (!item.program.isEmpty()) {
|
|
|
|
|
|
tip += QStringLiteral("\nprog: ") + item.program;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!item.path.isEmpty()) {
|
|
|
|
|
|
tip += QStringLiteral("\npath: ") + item.path;
|
|
|
|
|
|
}
|
|
|
|
|
|
btn->setToolTip(tip);
|
|
|
|
|
|
hGroupLayout->addWidget(btn);
|
|
|
|
|
|
|
|
|
|
|
|
connect(btn, &QToolButton::clicked, this, [name = item.name]() {
|
|
|
|
|
|
auto* wsCur = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
|
if (!wsCur) return;
|
|
|
|
|
|
CommandManager execMgr;
|
|
|
|
|
|
execMgr.ExecuteByName(wsCur, name);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
groupBox->setLayout(hGroupLayout);
|
|
|
|
|
|
root->addWidget(groupBox);
|
2025-10-13 16:15:18 +00:00
|
|
|
|
}
|
2025-10-28 08:12:14 +00:00
|
|
|
|
|
|
|
|
|
|
void SimuRunMenu::CreateMatlabParam()
|
|
|
|
|
|
{
|
|
|
|
|
|
QHBoxLayout* layout = qobject_cast<QHBoxLayout*>(this->layout());
|
|
|
|
|
|
if (!layout)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
QToolButton *pBtn = new QToolButton();
|
|
|
|
|
|
pBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
2025-10-29 09:11:36 +00:00
|
|
|
|
pBtn->setText(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
2025-10-28 08:12:14 +00:00
|
|
|
|
pBtn->setIcon(QIcon(":/res/default/menu_setting_restore.png"));
|
2025-10-29 09:11:36 +00:00
|
|
|
|
pBtn->setToolTip(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Matlab<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
2025-10-28 08:12:14 +00:00
|
|
|
|
|
|
|
|
|
|
connect(pBtn, SIGNAL(clicked()), this, SLOT(slotHandleMatlabParam()));
|
|
|
|
|
|
|
|
|
|
|
|
layout->addWidget(pBtn);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimuRunMenu::CreateLine()
|
|
|
|
|
|
{
|
|
|
|
|
|
QHBoxLayout* layout = qobject_cast<QHBoxLayout*>(this->layout());
|
|
|
|
|
|
if (!layout)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
QFrame *line = new QFrame(this);
|
|
|
|
|
|
line->setObjectName(QString::fromUtf8("line"));
|
|
|
|
|
|
line->setFrameShadow(QFrame::Plain);
|
|
|
|
|
|
line->setFrameShape(QFrame::VLine);
|
|
|
|
|
|
|
|
|
|
|
|
layout->addWidget(line);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimuRunMenu::CreateSpacer()
|
|
|
|
|
|
{
|
|
|
|
|
|
QHBoxLayout* layout = qobject_cast<QHBoxLayout*>(this->layout());
|
|
|
|
|
|
if (!layout)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
QSpacerItem *horizontalSpacer = new QSpacerItem(441, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
|
|
layout->addItem(horizontalSpacer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimuRunMenu::ClearAllBtn()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (auto* layout = qobject_cast<QHBoxLayout*>(this->layout()))
|
|
|
|
|
|
{
|
|
|
|
|
|
while (layout->count() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
QLayoutItem* item = layout->takeAt(0);
|
|
|
|
|
|
if (item)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (auto* w = item->widget())
|
|
|
|
|
|
{
|
|
|
|
|
|
w->deleteLater();
|
|
|
|
|
|
}
|
|
|
|
|
|
delete item;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimuRunMenu::slotHandleMatlabParam()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (WorkSpaceManager::Get().GetCurrent())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_pParam)
|
|
|
|
|
|
{
|
2025-10-29 09:11:36 +00:00
|
|
|
|
m_pParam = new DockWidget(m_mainWindow);
|
|
|
|
|
|
m_pParam->setAllowedAreas(Qt::NoDockWidgetArea);
|
|
|
|
|
|
|
|
|
|
|
|
DockTitleBar* titleBar = new DockTitleBar(m_pParam);
|
|
|
|
|
|
titleBar->SetFloatVisible(false);
|
|
|
|
|
|
titleBar->SetMaxVisible(false);
|
|
|
|
|
|
m_pParam->SetDockWidgetTitleBar(titleBar);
|
|
|
|
|
|
m_pParam->setWindowTitle(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
|
|
2025-10-28 08:12:14 +00:00
|
|
|
|
QString strDir = WorkSpaceManager::Get().GetCurrent()->GetDir();
|
2025-10-29 09:11:36 +00:00
|
|
|
|
AddParamSetting *pParam = new AddParamSetting(strDir);
|
|
|
|
|
|
m_pParam->setWidget(pParam);
|
|
|
|
|
|
|
|
|
|
|
|
m_pParam->resize(1000, 600);
|
2025-10-28 08:12:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 09:11:36 +00:00
|
|
|
|
m_pParam->setFloating(true);
|
2025-10-28 08:12:14 +00:00
|
|
|
|
m_pParam->show();
|
|
|
|
|
|
}
|
2025-10-29 09:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimuRunMenu::SetMainWindow(MainWindow* mainWindow)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_mainWindow = mainWindow;
|
2025-10-28 08:12:14 +00:00
|
|
|
|
}
|