799 lines
31 KiB
C++
Executable File
799 lines
31 KiB
C++
Executable File
#include "mainwindow.h"
|
|
#include "./ui_mainwindow.h"
|
|
#include <QMenuBar>
|
|
#include <QMenu>
|
|
#include <QFileDialog>
|
|
#include <QInputDialog>
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QPushButton>
|
|
#include <QGridLayout>
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
#include <QMessageBox>
|
|
#include <QXmlStreamWriter>
|
|
#include <QDateTimeEdit>
|
|
#include <QRegularExpressionValidator>
|
|
#include <QGroupBox>
|
|
#include <QTableWidget>
|
|
#include <QHeaderView>
|
|
#include <QDesktopServices>
|
|
#include <QProgressBar>
|
|
#include "GenCode.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
this->resize(600, 800); // Set the window size to 800x600 pixels
|
|
this->setWindowTitle("XNWrapper");
|
|
setWindowIcon(QIcon(":/icon/XNWrapper.png")); // 设置窗口图标
|
|
// Create menu bar
|
|
QMenuBar *menuBar = this->menuBar();
|
|
|
|
// Create file menu
|
|
QMenu *fileMenu = menuBar->addMenu("Project");
|
|
fileMenu->setObjectName("ProjectMenu");
|
|
QAction *newAction = fileMenu->addAction("New");
|
|
newAction->setObjectName("newAction");
|
|
connect(newAction, &QAction::triggered, this, &MainWindow::onNewActionTriggered);
|
|
QAction *openAction = fileMenu->addAction("Open");
|
|
openAction->setObjectName("openAction");
|
|
connect(openAction, &QAction::triggered, this, &MainWindow::onOpenActionTriggered);
|
|
QAction *saveAction = fileMenu->addAction("Save");
|
|
saveAction->setObjectName("saveAction");
|
|
saveAction->setEnabled(false);
|
|
connect(saveAction, &QAction::triggered, this, &MainWindow::onSaveActionTriggered);
|
|
QAction *saveAsAction = fileMenu->addAction("Save As ...");
|
|
saveAsAction->setObjectName("saveAsAction");
|
|
saveAsAction->setEnabled(false);
|
|
connect(saveAsAction, &QAction::triggered, this, &MainWindow::onSaveAsActionTriggered);
|
|
|
|
// Create code menu
|
|
QMenu *codeMenu = menuBar->addMenu("Code");
|
|
codeMenu->setObjectName("CodeMenu");
|
|
QAction *genCodeAction = codeMenu->addAction("Generate Code");
|
|
genCodeAction->setEnabled(false);
|
|
genCodeAction->setObjectName("genCodeAction");
|
|
connect(genCodeAction, &QAction::triggered, this, &MainWindow::onGenCodeActionTriggered);
|
|
QAction *openCodePathAction = codeMenu->addAction("Open Code Path");
|
|
openCodePathAction->setEnabled(false);
|
|
openCodePathAction->setObjectName("openCodePathAction");
|
|
connect(openCodePathAction, &QAction::triggered, this,
|
|
&MainWindow::onOpenCodePathActionTriggered);
|
|
|
|
// Create help menu
|
|
QMenu *helpMenu = menuBar->addMenu("Help");
|
|
helpMenu->setObjectName("HelpMenu");
|
|
QMenu *languageMenu = helpMenu->addMenu("Language");
|
|
languageMenu->setObjectName("LanguageMenu");
|
|
QAction *englishAction = languageMenu->addAction("English");
|
|
QAction *chineseAction = languageMenu->addAction("中文");
|
|
|
|
// Connect actions to slots
|
|
connect(englishAction, &QAction::triggered, this, &MainWindow::onEnglishActionTriggered);
|
|
connect(chineseAction, &QAction::triggered, this, &MainWindow::onChineseActionTriggered);
|
|
|
|
// Create model info page
|
|
initialModelInfoPage();
|
|
|
|
//
|
|
QString configFilePath = QDir::currentPath() + "/config/XNWrapper.xml";
|
|
QFile configFile(configFilePath);
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QXmlStreamReader xmlReader(&configFile);
|
|
while (xmlReader.readNextStartElement()) {
|
|
if (xmlReader.name() == QLatin1String("Language")) {
|
|
quint32 indexLanguage = xmlReader.readElementText().toInt();
|
|
if (indexLanguage == 1) {
|
|
onChineseActionTriggered();
|
|
}
|
|
} else {
|
|
xmlReader.skipCurrentElement();
|
|
}
|
|
}
|
|
configFile.close();
|
|
}
|
|
}
|
|
|
|
void MainWindow::onNewActionTriggered()
|
|
{
|
|
QDialog *dialog = new QDialog(this);
|
|
dialog->setWindowTitle("New Project");
|
|
QVBoxLayout *dialogLayout = new QVBoxLayout(dialog);
|
|
QGridLayout *layout = new QGridLayout();
|
|
|
|
// First row: label and input
|
|
QLabel *label1 = new QLabel("Model Name:");
|
|
QLineEdit *input1 = new QLineEdit();
|
|
input1->setValidator(
|
|
new QRegularExpressionValidator(QRegularExpression("[a-zA-Z0-9_]+"), this));
|
|
layout->addWidget(label1, 0, 0);
|
|
layout->addWidget(input1, 0, 1, 1, 2);
|
|
|
|
// Second row: label, input, and button
|
|
QLabel *label2 = new QLabel("Project Path:");
|
|
QLineEdit *input2 = new QLineEdit();
|
|
QPushButton *button2 = new QPushButton("...");
|
|
layout->addWidget(label2, 1, 0);
|
|
layout->addWidget(input2, 1, 1);
|
|
layout->addWidget(button2, 1, 2);
|
|
|
|
// Third row: label, input, and button
|
|
QLabel *label3 = new QLabel("Code Path:");
|
|
QLineEdit *input3 = new QLineEdit();
|
|
QPushButton *button3 = new QPushButton("...");
|
|
layout->addWidget(label3, 2, 0);
|
|
layout->addWidget(input3, 2, 1);
|
|
layout->addWidget(button3, 2, 2);
|
|
|
|
// Connect buttons to their respective functions
|
|
connect(button2, &QPushButton::clicked, this, [=]() {
|
|
QString dir = QFileDialog::getExistingDirectory(
|
|
dialog, "Select Project Directory", QString(),
|
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
|
if (!dir.isEmpty()) {
|
|
input2->setText(dir);
|
|
input3->setText(dir);
|
|
}
|
|
});
|
|
|
|
connect(button3, &QPushButton::clicked, this, [=]() {
|
|
QString dir = QFileDialog::getExistingDirectory(
|
|
dialog, "Select Code Directory", input3->text(),
|
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
|
if (!dir.isEmpty()) {
|
|
input3->setText(dir);
|
|
}
|
|
});
|
|
|
|
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
|
buttonLayout->addStretch();
|
|
QPushButton *okButton = new QPushButton("OK");
|
|
QPushButton *cancelButton = new QPushButton("Cancel");
|
|
okButton->setFixedSize(100, 30);
|
|
cancelButton->setFixedSize(100, 30);
|
|
buttonLayout->addWidget(okButton);
|
|
buttonLayout->addWidget(cancelButton);
|
|
|
|
connect(okButton, &QPushButton::clicked, this, [=]() {
|
|
modelName = input1->text();
|
|
projectPath = input2->text();
|
|
codePath = input3->text();
|
|
dialog->accept();
|
|
createPrjFile();
|
|
});
|
|
|
|
connect(cancelButton, &QPushButton::clicked, this, [=]() { dialog->reject(); });
|
|
|
|
dialogLayout->addLayout(layout);
|
|
dialogLayout->addLayout(buttonLayout);
|
|
dialog->setLayout(dialogLayout);
|
|
dialog->exec();
|
|
}
|
|
|
|
void MainWindow::onOpenActionTriggered()
|
|
{
|
|
QString filePath =
|
|
QFileDialog::getOpenFileName(this, "Open File", QString(), "XN Project Files (*.xnprj)");
|
|
if (!filePath.isEmpty()) {
|
|
modelName =
|
|
QFileInfo(filePath).completeBaseName(); // Use completeBaseName to remove the suffix
|
|
projectPath = QFileInfo(filePath).absolutePath();
|
|
openProjectFile();
|
|
}
|
|
}
|
|
|
|
void MainWindow::onSaveActionTriggered()
|
|
{
|
|
QString filePath = QDir(projectPath).filePath(modelName + ".xnprj");
|
|
QFile projectFile(filePath);
|
|
if (projectFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
QXmlStreamWriter xmlWriter(&projectFile);
|
|
xmlWriter.setAutoFormatting(true);
|
|
xmlWriter.writeStartDocument();
|
|
xmlWriter.writeStartElement("Project");
|
|
xmlWriter.writeTextElement("Name", modelName);
|
|
xmlWriter.writeTextElement("CodePath", codePath);
|
|
QLineEdit *classNameLineEdit = findChild<QLineEdit *>("classNameLineEdit");
|
|
if (classNameLineEdit) {
|
|
xmlWriter.writeTextElement("ClassName", classNameLineEdit->text());
|
|
}
|
|
QLineEdit *authorLineEdit = findChild<QLineEdit *>("authorLineEdit");
|
|
if (authorLineEdit) {
|
|
xmlWriter.writeTextElement("Author", authorLineEdit->text());
|
|
}
|
|
QLineEdit *versionLineEdit = findChild<QLineEdit *>("versionLineEdit");
|
|
if (versionLineEdit) {
|
|
xmlWriter.writeTextElement("Version", versionLineEdit->text());
|
|
}
|
|
QLineEdit *descriptionLineEdit = findChild<QLineEdit *>("descriptionLineEdit");
|
|
if (descriptionLineEdit) {
|
|
xmlWriter.writeTextElement("Description", descriptionLineEdit->text());
|
|
}
|
|
QLineEdit *creationTimeLineEdit = findChild<QLineEdit *>("creationTimeLineEdit");
|
|
if (creationTimeLineEdit) {
|
|
xmlWriter.writeTextElement("CreateTime", creationTimeLineEdit->text());
|
|
}
|
|
QLineEdit *changeTimeLineEdit = findChild<QLineEdit *>("changeTimeLineEdit");
|
|
if (changeTimeLineEdit) {
|
|
xmlWriter.writeTextElement("ChangeTime", changeTimeLineEdit->text());
|
|
}
|
|
QLineEdit *frequencyLineEdit = findChild<QLineEdit *>("frequencyLineEdit");
|
|
QLineEdit *nodeLineEdit = findChild<QLineEdit *>("nodeLineEdit");
|
|
if (frequencyLineEdit && nodeLineEdit) {
|
|
xmlWriter.writeTextElement("Node",
|
|
frequencyLineEdit->text() + "-" + nodeLineEdit->text());
|
|
}
|
|
QLineEdit *priorityLineEdit = findChild<QLineEdit *>("priorityLineEdit");
|
|
if (priorityLineEdit) {
|
|
xmlWriter.writeTextElement("Priority", priorityLineEdit->text());
|
|
}
|
|
QLineEdit *dynamicLibPathLineEdit = findChild<QLineEdit *>("dynamicLibPathLineEdit");
|
|
if (dynamicLibPathLineEdit) {
|
|
xmlWriter.writeTextElement("MathPath", dynamicLibPathLineEdit->text());
|
|
}
|
|
QLineEdit *dataPackageHeaderLineEdit = findChild<QLineEdit *>("dataPackageHeaderLineEdit");
|
|
if (dataPackageHeaderLineEdit) {
|
|
xmlWriter.writeTextElement("MathHeaderPath", dataPackageHeaderLineEdit->text());
|
|
}
|
|
QLineEdit *dataPackageEntryPointLineEdit =
|
|
findChild<QLineEdit *>("dataPackageEntryPointLineEdit");
|
|
if (dataPackageEntryPointLineEdit) {
|
|
xmlWriter.writeTextElement("MathEntryPoint", dataPackageEntryPointLineEdit->text());
|
|
}
|
|
QLineEdit *dataPackageEntryParamLineEdit =
|
|
findChild<QLineEdit *>("dataPackageEntryParamLineEdit");
|
|
if (dataPackageEntryParamLineEdit) {
|
|
xmlWriter.writeTextElement("MathEntryParam", dataPackageEntryParamLineEdit->text());
|
|
}
|
|
xmlWriter.writeStartElement("CommandList");
|
|
QTableWidget *tableWidget = findChild<QTableWidget *>("commandTableWidget");
|
|
if (tableWidget) {
|
|
for (int row = 0; row < tableWidget->rowCount(); ++row) {
|
|
xmlWriter.writeStartElement("Command");
|
|
xmlWriter.writeAttribute("Name", tableWidget->item(row, 0)->text());
|
|
xmlWriter.writeAttribute("Description", tableWidget->item(row, 1)->text());
|
|
xmlWriter.writeAttribute("CallbackFunction", tableWidget->item(row, 2)->text());
|
|
xmlWriter.writeEndElement(); // Command
|
|
}
|
|
}
|
|
xmlWriter.writeEndElement(); // CommandList
|
|
xmlWriter.writeEndElement(); // Project
|
|
xmlWriter.writeEndDocument();
|
|
projectFile.close();
|
|
}
|
|
}
|
|
|
|
void MainWindow::onSaveAsActionTriggered()
|
|
{
|
|
QString filePath =
|
|
QFileDialog::getSaveFileName(this, "Save As", QString(), "XN Project Files (*.xnprj)");
|
|
if (!filePath.isEmpty()) {
|
|
projectPath = QFileInfo(filePath).absolutePath();
|
|
onSaveActionTriggered();
|
|
}
|
|
}
|
|
|
|
void MainWindow::onGenCodeActionTriggered()
|
|
{
|
|
GenCode genCode;
|
|
int ret = genCode.analyzePrjFile(projectPath + "/" + modelName + ".xnprj");
|
|
if (ret != 0) {
|
|
if (ret == -1) {
|
|
QMessageBox::warning(this, "Error", "Cannot find the project file.");
|
|
return;
|
|
}
|
|
if (ret & 1) {
|
|
QMessageBox::warning(this, "Error",
|
|
"Cannot find the model name element in the project file.");
|
|
return;
|
|
}
|
|
if (ret & 2) {
|
|
QMessageBox::warning(this, "Error",
|
|
"Cannot find the codePath element in the project file.");
|
|
return;
|
|
}
|
|
if (ret & 4) {
|
|
QMessageBox::warning(this, "Error",
|
|
"Cannot find the className element in the project file.");
|
|
return;
|
|
}
|
|
if (ret & 8) {
|
|
QMessageBox::warning(this, "Warning",
|
|
"The project file does not have the node element configured. "
|
|
"Please configure it in the model configuration file later.");
|
|
}
|
|
if (ret & 16) {
|
|
QMessageBox::warning(this, "Warning",
|
|
"The project file does not have the priority element configured. "
|
|
"Please configure it in the model configuration file later.");
|
|
}
|
|
if (ret & 64) {
|
|
QMessageBox::warning(
|
|
this, "Warning",
|
|
"The configuration of data package-related elements in the engineering file is "
|
|
"incomplete, which will result in the generation of incomplete code.");
|
|
}
|
|
}
|
|
|
|
genCode.genCMakeFile();
|
|
genCode.genGlobalFile();
|
|
genCode.genHeaderFile();
|
|
genCode.genPrivateHeaderFile();
|
|
genCode.genSourceFile();
|
|
genCode.genConfigFile();
|
|
|
|
QMessageBox::information(this, "Success", "Code generation completed successfully.");
|
|
}
|
|
|
|
void MainWindow::onOpenCodePathActionTriggered()
|
|
{
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(codePath));
|
|
}
|
|
|
|
void MainWindow::onAutoAcquireEntryPoint()
|
|
{
|
|
//TODO 使用nm命令获取动态库符号表
|
|
}
|
|
|
|
void MainWindow::onAutoAcquireEntryParam()
|
|
{
|
|
//TODO 使用nm命令获取动态库符号表
|
|
}
|
|
|
|
void MainWindow::initialModelInfoPage()
|
|
{
|
|
QWidget *centralWidget = new QWidget(this); // Create a central widget
|
|
setCentralWidget(centralWidget); // Set the central widget
|
|
centralWidget->setEnabled(false);
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget);
|
|
|
|
QWidget *modelInfoWidget = new QWidget();
|
|
QGridLayout *gridLayout = new QGridLayout(modelInfoWidget); // Set layout on the central widget
|
|
|
|
// Create label and line edit for Model Name
|
|
QLabel *modelNameLabel = new QLabel("Model Name:", this);
|
|
QLineEdit *modelNameLineEdit = new QLineEdit(this);
|
|
modelNameLineEdit->setObjectName("modelNameLineEdit");
|
|
modelNameLineEdit->setReadOnly(true); // Make line edit non-editable
|
|
|
|
// Add label and line edit to the grid layout
|
|
gridLayout->addWidget(modelNameLabel, 0, 0); // Row 0, Column 0
|
|
gridLayout->addWidget(modelNameLineEdit, 0, 1); // Row 0, Column 1
|
|
|
|
QLabel *classNameLabel = new QLabel("Class Name:", this);
|
|
QLineEdit *classNameLineEdit = new QLineEdit(this);
|
|
classNameLineEdit->setObjectName("classNameLineEdit");
|
|
gridLayout->addWidget(classNameLabel, 0, 2);
|
|
gridLayout->addWidget(classNameLineEdit, 0, 3);
|
|
|
|
QLabel *descriptionLabel = new QLabel("Description:", this);
|
|
QLineEdit *descriptionLineEdit = new QLineEdit(this);
|
|
descriptionLineEdit->setObjectName("descriptionLineEdit");
|
|
gridLayout->addWidget(descriptionLabel, 1, 0);
|
|
gridLayout->addWidget(descriptionLineEdit, 1, 1, 1, 3);
|
|
|
|
QLabel *authorLabel = new QLabel("Author:", this);
|
|
QLineEdit *authorLineEdit = new QLineEdit(this);
|
|
authorLineEdit->setObjectName("authorLineEdit");
|
|
gridLayout->addWidget(authorLabel, 2, 0);
|
|
gridLayout->addWidget(authorLineEdit, 2, 1);
|
|
|
|
QLabel *versionLabel = new QLabel("Version:", this);
|
|
QLineEdit *versionLineEdit = new QLineEdit(this);
|
|
versionLineEdit->setValidator(
|
|
new QRegularExpressionValidator(QRegularExpression("[a-zA-Z0-9_.-]+"), this));
|
|
versionLineEdit->setObjectName("versionLineEdit");
|
|
gridLayout->addWidget(versionLabel, 2, 2);
|
|
gridLayout->addWidget(versionLineEdit, 2, 3);
|
|
|
|
QLabel *creationTimeLabel = new QLabel("CreateTime:", this);
|
|
QLineEdit *creationTimeLineEdit = new QLineEdit(this);
|
|
creationTimeLineEdit->setReadOnly(true); // Make line edit non-editable
|
|
creationTimeLineEdit->setObjectName("creationTimeLineEdit");
|
|
QPushButton *creationTimeButton = new QPushButton("Select", this);
|
|
connect(creationTimeButton, &QPushButton::clicked, this, [=]() {
|
|
QDialog dateTimeDialog(this);
|
|
QVBoxLayout layout(&dateTimeDialog);
|
|
QDateTimeEdit *dateTimeEdit = new QDateTimeEdit(&dateTimeDialog);
|
|
dateTimeEdit->setCalendarPopup(true);
|
|
dateTimeEdit->setDateTime(QDateTime::currentDateTime());
|
|
layout.addWidget(dateTimeEdit);
|
|
QPushButton *okButton = new QPushButton("OK", &dateTimeDialog);
|
|
layout.addWidget(okButton);
|
|
connect(okButton, &QPushButton::clicked, &dateTimeDialog, &QDialog::accept);
|
|
if (dateTimeDialog.exec() == QDialog::Accepted) {
|
|
creationTimeLineEdit->setText(dateTimeEdit->dateTime().toString("yyyy-MM-dd HH:mm:ss"));
|
|
}
|
|
});
|
|
gridLayout->addWidget(creationTimeButton, 3, 3);
|
|
gridLayout->addWidget(creationTimeLabel, 3, 0);
|
|
gridLayout->addWidget(creationTimeLineEdit, 3, 1, 1, 2);
|
|
|
|
QLabel *changeTimeLabel = new QLabel("ChangeTime:", this);
|
|
QLineEdit *changeTimeLineEdit = new QLineEdit(this);
|
|
changeTimeLineEdit->setReadOnly(true); // Make line edit non-editable
|
|
changeTimeLineEdit->setObjectName("changeTimeLineEdit");
|
|
QPushButton *changeTimeButton = new QPushButton("Select", this);
|
|
connect(changeTimeButton, &QPushButton::clicked, this, [=]() {
|
|
QDialog dateTimeDialog(this);
|
|
QVBoxLayout layout(&dateTimeDialog);
|
|
QDateTimeEdit *dateTimeEdit = new QDateTimeEdit(&dateTimeDialog);
|
|
dateTimeEdit->setCalendarPopup(true);
|
|
dateTimeEdit->setDateTime(QDateTime::currentDateTime());
|
|
layout.addWidget(dateTimeEdit);
|
|
QPushButton *okButton = new QPushButton("OK", &dateTimeDialog);
|
|
layout.addWidget(okButton);
|
|
connect(okButton, &QPushButton::clicked, &dateTimeDialog, &QDialog::accept);
|
|
if (dateTimeDialog.exec() == QDialog::Accepted) {
|
|
changeTimeLineEdit->setText(dateTimeEdit->dateTime().toString("yyyy-MM-dd HH:mm:ss"));
|
|
}
|
|
});
|
|
gridLayout->addWidget(changeTimeButton, 4, 3);
|
|
gridLayout->addWidget(changeTimeLabel, 4, 0);
|
|
gridLayout->addWidget(changeTimeLineEdit, 4, 1, 1, 2);
|
|
|
|
QLabel *nodeNumberLabel = new QLabel("Node:", this);
|
|
QLineEdit *frequencyLineEdit = new QLineEdit(this);
|
|
frequencyLineEdit->setValidator(
|
|
new QRegularExpressionValidator(QRegularExpression("[0-5]"), this));
|
|
frequencyLineEdit->setObjectName("frequencyLineEdit");
|
|
QLineEdit *nodeLineEdit = new QLineEdit(this);
|
|
nodeLineEdit->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9]+"), this));
|
|
nodeLineEdit->setObjectName("nodeLineEdit");
|
|
gridLayout->addWidget(nodeNumberLabel, 5, 0);
|
|
gridLayout->addWidget(frequencyLineEdit, 5, 1);
|
|
gridLayout->addWidget(nodeLineEdit, 5, 2);
|
|
|
|
QLabel *priorityLabel = new QLabel("Priority:", this);
|
|
QLineEdit *priorityLineEdit = new QLineEdit(this);
|
|
priorityLineEdit->setValidator(
|
|
new QRegularExpressionValidator(QRegularExpression("[0-9]+"), this));
|
|
priorityLineEdit->setObjectName("priorityLineEdit");
|
|
gridLayout->addWidget(priorityLabel, 6, 0);
|
|
gridLayout->addWidget(priorityLineEdit, 6, 1, 1, 3);
|
|
|
|
QLabel *dynamicLibPathLabel = new QLabel("Data Package DLL:", this);
|
|
QLineEdit *dynamicLibPathLineEdit = new QLineEdit(this);
|
|
dynamicLibPathLineEdit->setObjectName("dynamicLibPathLineEdit");
|
|
QPushButton *dynamicLibPathButton = new QPushButton("...", this);
|
|
gridLayout->addWidget(dynamicLibPathLabel, 7, 0);
|
|
gridLayout->addWidget(dynamicLibPathLineEdit, 7, 1, 1, 2);
|
|
gridLayout->addWidget(dynamicLibPathButton, 7, 3);
|
|
connect(dynamicLibPathButton, &QPushButton::clicked, this, [=]() {
|
|
QString filePath =
|
|
QFileDialog::getOpenFileName(this, "Select Data Package DLL or SO File", projectPath,
|
|
"Dynamic Link Libraries (*.dll *.so);;All Files (*)");
|
|
if (!filePath.isEmpty()) {
|
|
dynamicLibPathLineEdit->setText(filePath);
|
|
}
|
|
});
|
|
|
|
QLabel *dataPackageHeaderLabel = new QLabel("Data Package Header:", this);
|
|
QLineEdit *dataPackageHeaderLineEdit = new QLineEdit(this);
|
|
dataPackageHeaderLineEdit->setObjectName("dataPackageHeaderLineEdit");
|
|
QPushButton *dataPackageHeaderButton = new QPushButton("...", this);
|
|
gridLayout->addWidget(dataPackageHeaderLabel, 8, 0);
|
|
gridLayout->addWidget(dataPackageHeaderLineEdit, 8, 1, 1, 2);
|
|
gridLayout->addWidget(dataPackageHeaderButton, 8, 3);
|
|
connect(dataPackageHeaderButton, &QPushButton::clicked, this, [=]() {
|
|
QString filePath =
|
|
QFileDialog::getOpenFileName(this, "Select Data Package Header File", projectPath,
|
|
"C++ Header File (*.h *.hpp);;All Files (*)");
|
|
if (!filePath.isEmpty()) {
|
|
dataPackageHeaderLineEdit->setText(filePath);
|
|
}
|
|
});
|
|
|
|
QLabel *dataPackageEntryPointLabel = new QLabel("Data Package Entry Point:", this);
|
|
QLineEdit *dataPackageEntryPointLineEdit = new QLineEdit(this);
|
|
dataPackageEntryPointLineEdit->setObjectName("dataPackageEntryPointLineEdit");
|
|
QPushButton *dataPackageEntryPointButton = new QPushButton("Auto Acquire", this);
|
|
gridLayout->addWidget(dataPackageEntryPointLabel, 9, 0);
|
|
gridLayout->addWidget(dataPackageEntryPointLineEdit, 9, 1, 1, 2);
|
|
gridLayout->addWidget(dataPackageEntryPointButton, 9, 3);
|
|
connect(dataPackageEntryPointButton, &QPushButton::clicked, this,
|
|
&MainWindow::onAutoAcquireEntryPoint);
|
|
|
|
QLabel *dataPackageEntryParamLabel = new QLabel("Data Package Entry Param:", this);
|
|
QLineEdit *dataPackageEntryParamLineEdit = new QLineEdit(this);
|
|
dataPackageEntryParamLineEdit->setObjectName("dataPackageEntryParamLineEdit");
|
|
QPushButton *dataPackageEntryParamButton = new QPushButton("Auto Acquire", this);
|
|
gridLayout->addWidget(dataPackageEntryParamLabel, 10, 0);
|
|
gridLayout->addWidget(dataPackageEntryParamLineEdit, 10, 1, 1, 2);
|
|
gridLayout->addWidget(dataPackageEntryParamButton, 10, 3);
|
|
connect(dataPackageEntryParamButton, &QPushButton::clicked, this,
|
|
&MainWindow::onAutoAcquireEntryParam);
|
|
|
|
mainLayout->addWidget(modelInfoWidget);
|
|
|
|
// 添加命令列表
|
|
initialCommandListPage();
|
|
|
|
// 添加保存、生成代码、打开代码路径按钮
|
|
initialQuickButton();
|
|
}
|
|
|
|
void MainWindow::initialCommandListPage()
|
|
{
|
|
QLayout *mainLayout = centralWidget()->layout();
|
|
QGroupBox *groupBox = new QGroupBox("Command List", this);
|
|
QHBoxLayout *groupLayout = new QHBoxLayout(groupBox);
|
|
QTableWidget *tableWidget = new QTableWidget(0, 3, this); // 0 rows, 2 columns
|
|
tableWidget->setObjectName("commandTableWidget");
|
|
tableWidget->horizontalHeader()->setStretchLastSection(true);
|
|
tableWidget->setHorizontalHeaderLabels(QStringList()
|
|
<< "Command" << "Description" << "Callback Function");
|
|
groupLayout->addWidget(tableWidget);
|
|
|
|
QVBoxLayout *buttonLayout = new QVBoxLayout();
|
|
QPushButton *addButton = new QPushButton("+", this);
|
|
QFont buttonFont = addButton->font();
|
|
buttonFont.setPointSize(16); // Set font size to 12
|
|
addButton->setFont(buttonFont);
|
|
addButton->setFixedSize(40, 40);
|
|
|
|
QPushButton *removeButton = new QPushButton("-", this);
|
|
removeButton->setFixedSize(40, 40);
|
|
removeButton->setFont(buttonFont);
|
|
buttonLayout->addWidget(addButton);
|
|
buttonLayout->addWidget(removeButton);
|
|
groupLayout->addLayout(buttonLayout);
|
|
|
|
connect(addButton, &QPushButton::clicked, this, [=]() {
|
|
int rowCount = tableWidget->rowCount();
|
|
tableWidget->insertRow(rowCount);
|
|
});
|
|
|
|
connect(removeButton, &QPushButton::clicked, this, [=]() {
|
|
int currentRow = tableWidget->currentRow();
|
|
if (currentRow >= 0) {
|
|
tableWidget->removeRow(currentRow);
|
|
}
|
|
});
|
|
mainLayout->addWidget(groupBox);
|
|
}
|
|
|
|
void MainWindow::initialDDSInfoPage()
|
|
{
|
|
QLayout *mainLayout = centralWidget()->layout();
|
|
QGroupBox *groupBox = new QGroupBox("DDS Info", this);
|
|
//TODO 添加DDS交互数据信息
|
|
}
|
|
|
|
void MainWindow::initialQuickButton()
|
|
{
|
|
QLayout *mainLayout = centralWidget()->layout();
|
|
QHBoxLayout *buttonLayout2 = new QHBoxLayout();
|
|
QPushButton *saveButton = new QPushButton("Save", this);
|
|
QPushButton *genCodeButton = new QPushButton("Generate Code", this);
|
|
QPushButton *openCodePathButton = new QPushButton("Open Code Path", this);
|
|
connect(saveButton, &QPushButton::clicked, this, &MainWindow::onSaveActionTriggered);
|
|
connect(genCodeButton, &QPushButton::clicked, this, &MainWindow::onGenCodeActionTriggered);
|
|
connect(openCodePathButton, &QPushButton::clicked, this,
|
|
&MainWindow::onOpenCodePathActionTriggered);
|
|
buttonLayout2->addWidget(saveButton);
|
|
buttonLayout2->addWidget(genCodeButton);
|
|
buttonLayout2->addWidget(openCodePathButton);
|
|
QWidget *buttonWidget = new QWidget();
|
|
buttonWidget->setLayout(buttonLayout2);
|
|
mainLayout->addWidget(buttonWidget);
|
|
}
|
|
|
|
void MainWindow::createPrjFile()
|
|
{
|
|
QString filePath = QDir(projectPath).filePath(modelName + ".xnprj");
|
|
QFileInfo checkFile(filePath);
|
|
if (checkFile.exists() && checkFile.isFile()) {
|
|
QMessageBox::StandardButton reply;
|
|
reply = QMessageBox::question(
|
|
this, "File Exists",
|
|
"The project file already exists. Do you want to open it or overwrite it?",
|
|
QMessageBox::Open | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
|
|
|
|
if (reply == QMessageBox::Cancel) {
|
|
return;
|
|
} else if (reply == QMessageBox::Open) {
|
|
openProjectFile();
|
|
return;
|
|
}
|
|
}
|
|
QFile projectFile(filePath);
|
|
if (projectFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
QXmlStreamWriter xmlWriter(&projectFile);
|
|
xmlWriter.setAutoFormatting(true);
|
|
xmlWriter.writeStartDocument();
|
|
xmlWriter.writeStartElement("Project");
|
|
xmlWriter.writeTextElement("Name", modelName);
|
|
xmlWriter.writeTextElement("CodePath", codePath);
|
|
xmlWriter.writeEndElement(); // Project
|
|
xmlWriter.writeEndDocument();
|
|
projectFile.close();
|
|
openProjectFile();
|
|
} else {
|
|
QMessageBox::warning(this, "Error", "Could not create project file.");
|
|
}
|
|
}
|
|
|
|
void MainWindow::openProjectFile()
|
|
{
|
|
QString filePath = QDir(projectPath).filePath(modelName + ".xnprj");
|
|
QFile projectFile(filePath);
|
|
if (projectFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QWidget *centralWidget = this->centralWidget();
|
|
centralWidget->setEnabled(true);
|
|
this->setWindowTitle("XNWrapper - " + modelName);
|
|
QAction *saveAction = findChild<QAction *>("saveAction");
|
|
if (saveAction) {
|
|
saveAction->setEnabled(true);
|
|
}
|
|
QAction *saveAsAction = findChild<QAction *>("saveAsAction");
|
|
if (saveAsAction) {
|
|
saveAsAction->setEnabled(true);
|
|
}
|
|
QAction *genCodeAction = findChild<QAction *>("genCodeAction");
|
|
if (genCodeAction) {
|
|
genCodeAction->setEnabled(true);
|
|
}
|
|
QAction *openCodePathAction = findChild<QAction *>("openCodePathAction");
|
|
if (openCodePathAction) {
|
|
openCodePathAction->setEnabled(true);
|
|
}
|
|
|
|
QXmlStreamReader xmlReader(&projectFile);
|
|
while (xmlReader.readNextStartElement()) {
|
|
if (xmlReader.name() == QLatin1String("Project")) {
|
|
while (xmlReader.readNextStartElement()) {
|
|
if (xmlReader.name() == QLatin1String("Name")) {
|
|
modelName = xmlReader.readElementText();
|
|
QLineEdit *modelNameLineEdit = findChild<QLineEdit *>("modelNameLineEdit");
|
|
if (modelNameLineEdit) {
|
|
modelNameLineEdit->setText(modelName);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("CodePath")) {
|
|
codePath = xmlReader.readElementText();
|
|
} else if (xmlReader.name() == QLatin1String("ClassName")) {
|
|
QString className = xmlReader.readElementText();
|
|
QLineEdit *classNameLineEdit = findChild<QLineEdit *>("classNameLineEdit");
|
|
if (classNameLineEdit) {
|
|
classNameLineEdit->setText(className);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("Author")) {
|
|
QString author = xmlReader.readElementText();
|
|
QLineEdit *authorLineEdit = findChild<QLineEdit *>("authorLineEdit");
|
|
if (authorLineEdit) {
|
|
authorLineEdit->setText(author);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("Version")) {
|
|
QString version = xmlReader.readElementText();
|
|
QLineEdit *versionLineEdit = findChild<QLineEdit *>("versionLineEdit");
|
|
if (versionLineEdit) {
|
|
versionLineEdit->setText(version);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("Description")) {
|
|
QString description = xmlReader.readElementText();
|
|
QLineEdit *descriptionLineEdit =
|
|
findChild<QLineEdit *>("descriptionLineEdit");
|
|
if (descriptionLineEdit) {
|
|
descriptionLineEdit->setText(description);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("CreateTime")) {
|
|
QString createTime = xmlReader.readElementText();
|
|
QLineEdit *createTimeLineEdit =
|
|
findChild<QLineEdit *>("creationTimeLineEdit");
|
|
if (createTimeLineEdit) {
|
|
createTimeLineEdit->setText(createTime);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("ChangeTime")) {
|
|
QString changeTime = xmlReader.readElementText();
|
|
QLineEdit *changeTimeLineEdit =
|
|
findChild<QLineEdit *>("changeTimeLineEdit");
|
|
if (changeTimeLineEdit) {
|
|
changeTimeLineEdit->setText(changeTime);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("Node")) {
|
|
QString node = xmlReader.readElementText();
|
|
QStringList nodeParts = node.split("-");
|
|
if (nodeParts.size() == 2) {
|
|
QLineEdit *frequencyLineEdit =
|
|
findChild<QLineEdit *>("frequencyLineEdit");
|
|
QLineEdit *nodeLineEdit = findChild<QLineEdit *>("nodeLineEdit");
|
|
if (frequencyLineEdit) {
|
|
frequencyLineEdit->setText(nodeParts[0]);
|
|
}
|
|
if (nodeLineEdit) {
|
|
nodeLineEdit->setText(nodeParts[1]);
|
|
}
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("Priority")) {
|
|
QString priority = xmlReader.readElementText();
|
|
QLineEdit *priorityLineEdit = findChild<QLineEdit *>("priorityLineEdit");
|
|
if (priorityLineEdit) {
|
|
priorityLineEdit->setText(priority);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("MathPath")) {
|
|
QString dynamicLibPath = xmlReader.readElementText();
|
|
QLineEdit *dynamicLibPathLineEdit =
|
|
findChild<QLineEdit *>("dynamicLibPathLineEdit");
|
|
if (dynamicLibPathLineEdit) {
|
|
dynamicLibPathLineEdit->setText(dynamicLibPath);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("MathHeaderPath")) {
|
|
QString dataPackageHeader = xmlReader.readElementText();
|
|
QLineEdit *dataPackageHeaderLineEdit =
|
|
findChild<QLineEdit *>("dataPackageHeaderLineEdit");
|
|
if (dataPackageHeaderLineEdit) {
|
|
dataPackageHeaderLineEdit->setText(dataPackageHeader);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("MathEntryPoint")) {
|
|
QString dataPackageEntryPoint = xmlReader.readElementText();
|
|
QLineEdit *dataPackageEntryPointLineEdit =
|
|
findChild<QLineEdit *>("dataPackageEntryPointLineEdit");
|
|
if (dataPackageEntryPointLineEdit) {
|
|
dataPackageEntryPointLineEdit->setText(dataPackageEntryPoint);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("MathEntryParam")) {
|
|
QString dataPackageEntryParam = xmlReader.readElementText();
|
|
QLineEdit *dataPackageEntryParamLineEdit =
|
|
findChild<QLineEdit *>("dataPackageEntryParamLineEdit");
|
|
if (dataPackageEntryParamLineEdit) {
|
|
dataPackageEntryParamLineEdit->setText(dataPackageEntryParam);
|
|
}
|
|
} else if (xmlReader.name() == QLatin1String("CommandList")) {
|
|
while (xmlReader.readNextStartElement()) {
|
|
if (xmlReader.name() == QLatin1String("Command")) {
|
|
QString command =
|
|
xmlReader.attributes().value(QLatin1String("Name")).toString();
|
|
QString description = xmlReader.attributes()
|
|
.value(QLatin1String("Description"))
|
|
.toString();
|
|
QString callbackFunction =
|
|
xmlReader.attributes()
|
|
.value(QLatin1String("CallbackFunction"))
|
|
.toString();
|
|
QTableWidget *tableWidget =
|
|
findChild<QTableWidget *>("commandTableWidget");
|
|
if (tableWidget) {
|
|
tableWidget->setRowCount(0);
|
|
int rowCount = tableWidget->rowCount();
|
|
tableWidget->insertRow(rowCount);
|
|
tableWidget->setItem(rowCount, 0,
|
|
new QTableWidgetItem(command));
|
|
tableWidget->setItem(rowCount, 1,
|
|
new QTableWidgetItem(description));
|
|
tableWidget->setItem(rowCount, 2,
|
|
new QTableWidgetItem(callbackFunction));
|
|
}
|
|
} else {
|
|
xmlReader.skipCurrentElement();
|
|
}
|
|
}
|
|
} else {
|
|
xmlReader.skipCurrentElement();
|
|
}
|
|
}
|
|
} else {
|
|
xmlReader.skipCurrentElement();
|
|
}
|
|
}
|
|
projectFile.close();
|
|
} else {
|
|
QMessageBox::warning(this, "Error", "Could not open project file.");
|
|
}
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::onEnglishActionTriggered()
|
|
{
|
|
}
|
|
|
|
void MainWindow::onChineseActionTriggered()
|
|
{
|
|
}
|