修改matlab执行程序
This commit is contained in:
parent
b900683dbe
commit
5105c48f53
@ -9,7 +9,10 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
|
#include "../../common/RecourceHelper.h"
|
||||||
#include "../../workspace/WorkSpaceManager.h"
|
#include "../../workspace/WorkSpaceManager.h"
|
||||||
|
|
||||||
#include "SyntaxHighlighter.h"
|
#include "SyntaxHighlighter.h"
|
||||||
@ -32,25 +35,28 @@ CodeEdtUI::CodeEdtUI(QWidget *parent)
|
|||||||
|
|
||||||
setCentralWidget(editor);
|
setCentralWidget(editor);
|
||||||
|
|
||||||
// ´´½¨²Ëµ¥
|
|
||||||
QMenu* fileMenu = menuBar()->addMenu(tr("&file"));
|
|
||||||
QAction* openMainAction = new QAction(tr("&Import the template"), this);
|
|
||||||
/* QAction* openLDAction = new QAction(tr("&Import the LD template"), this);
|
|
||||||
QAction* openSeekerSimAction = new QAction(tr("&Import the SeekerSim template"), this);*/
|
|
||||||
QAction* saveAction = new QAction(tr("&save"), this);
|
|
||||||
fileMenu->addAction(openMainAction);
|
|
||||||
//fileMenu->addAction(openLDAction);
|
|
||||||
//fileMenu->addAction(openSeekerSimAction);
|
|
||||||
fileMenu->addAction(saveAction);
|
|
||||||
|
|
||||||
connect(openMainAction, &QAction::triggered, this, &CodeEdtUI::openMainFile);
|
InitBat();
|
||||||
/* connect(openLDAction, &QAction::triggered, this, &CodeEdtUI::openLDFile);
|
|
||||||
connect(openSeekerSimAction, &QAction::triggered, this, &CodeEdtUI::openSeekerSimFile);*/
|
|
||||||
|
|
||||||
connect(saveAction, &QAction::triggered, this, &CodeEdtUI::saveFile);
|
// // 创建菜单
|
||||||
|
// QMenu* fileMenu = menuBar()->addMenu(tr("&file"));
|
||||||
|
// QAction* openMainAction = new QAction(tr("&Import the template"), this);
|
||||||
|
///* QAction* openLDAction = new QAction(tr("&Import the LD template"), this);
|
||||||
|
// QAction* openSeekerSimAction = new QAction(tr("&Import the SeekerSim template"), this);*/
|
||||||
|
// QAction* saveAction = new QAction(tr("&save"), this);
|
||||||
|
// fileMenu->addAction(openMainAction);
|
||||||
|
// //fileMenu->addAction(openLDAction);
|
||||||
|
// //fileMenu->addAction(openSeekerSimAction);
|
||||||
|
// fileMenu->addAction(saveAction);
|
||||||
|
|
||||||
// ״̬À¸
|
// connect(openMainAction, &QAction::triggered, this, &CodeEdtUI::openMainFile);
|
||||||
statusBar();
|
///* connect(openLDAction, &QAction::triggered, this, &CodeEdtUI::openLDFile);
|
||||||
|
// connect(openSeekerSimAction, &QAction::triggered, this, &CodeEdtUI::openSeekerSimFile);*/
|
||||||
|
|
||||||
|
// connect(saveAction, &QAction::triggered, this, &CodeEdtUI::saveFile);
|
||||||
|
|
||||||
|
// // 状态栏
|
||||||
|
// statusBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeEdtUI::AttachDock(DockWidget* dockWidget)
|
void CodeEdtUI::AttachDock(DockWidget* dockWidget)
|
||||||
@ -70,12 +76,46 @@ void CodeEdtUI::AttachDock(DockWidget* dockWidget)
|
|||||||
dockWidget->SetDockWidgetTitleBar(dockTitleBar);
|
dockWidget->SetDockWidgetTitleBar(dockTitleBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeEdtUI::openMainFile() {
|
void CodeEdtUI::InitBat()
|
||||||
QString fileName = ""; //QFileDialog::getOpenFileName(this, "Open File", "", "Matlab Files (*.m)");
|
|
||||||
if (fileName.isEmpty())
|
|
||||||
{
|
{
|
||||||
fileName = QFileDialog::getOpenFileName(this, "Open File", "", "Matlab Files (*.m)");
|
{
|
||||||
|
QMenu* fileMenu = menuBar()->addMenu(tr("&bat"));
|
||||||
|
|
||||||
|
QDir dir(RecourceHelper::Get().GetBasePath() + "/bat");
|
||||||
|
QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
||||||
|
for (int i = 0; i < fileInfoList.size(); i++)
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo = fileInfoList[i];
|
||||||
|
QString strSuff = fileInfo.suffix();
|
||||||
|
strSuff = strSuff.toLower();
|
||||||
|
if (strSuff == "bat")
|
||||||
|
{
|
||||||
|
QAction* fileAction = new QAction(fileInfo.fileName(), this);
|
||||||
|
fileMenu->addAction(fileAction);
|
||||||
|
|
||||||
|
connect(fileAction, &QAction::triggered, this, &CodeEdtUI::openMainFile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QMenu* ctrlMenu = menuBar()->addMenu(tr("&Control"));
|
||||||
|
|
||||||
|
QAction* runAction = new QAction(tr("&Run"), this);
|
||||||
|
ctrlMenu->addAction(runAction);
|
||||||
|
|
||||||
|
QAction* saveAction = new QAction(tr("&Save"), this);
|
||||||
|
ctrlMenu->addAction(saveAction);
|
||||||
|
|
||||||
|
connect(runAction, &QAction::triggered, this, &CodeEdtUI::runFile);
|
||||||
|
connect(saveAction, &QAction::triggered, this, &CodeEdtUI::saveFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CodeEdtUI::openMainFile() {
|
||||||
|
|
||||||
|
QAction* fileAction = (QAction*)(sender());
|
||||||
|
QString fileName = RecourceHelper::Get().GetBasePath() + "/bat/" + fileAction->text(); //QFileDialog::getOpenFileName(this, "Open File", "", "Matlab Files (*.bat)");
|
||||||
|
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
@ -83,10 +123,13 @@ void CodeEdtUI::openMainFile() {
|
|||||||
editor->clear();
|
editor->clear();
|
||||||
|
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
|
in.setCodec("utf-8");
|
||||||
editor->setPlainText(in.readAll());
|
editor->setPlainText(in.readAll());
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_strCurOpenFile = fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeEdtUI::openLDFile()
|
void CodeEdtUI::openLDFile()
|
||||||
@ -133,12 +176,37 @@ void CodeEdtUI::openSeekerSimFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CodeEdtUI::runFile()
|
||||||
|
{
|
||||||
|
if (!m_strCurOpenFile.isEmpty())
|
||||||
|
{
|
||||||
|
saveFile();
|
||||||
|
|
||||||
|
// 创建QProcess对象
|
||||||
|
QProcess process;
|
||||||
|
|
||||||
|
// 启动批处理文件
|
||||||
|
process.start(m_strCurOpenFile);
|
||||||
|
|
||||||
|
// 等待过程完成
|
||||||
|
process.waitForFinished();
|
||||||
|
|
||||||
|
// 获取输出
|
||||||
|
QString output = process.readAllStandardOutput();
|
||||||
|
QString errorOutput = process.readAllStandardError();
|
||||||
|
|
||||||
|
// 打印输出
|
||||||
|
qDebug() << "Output:" << output;
|
||||||
|
qDebug() << "Error Output:" << errorOutput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CodeEdtUI::saveFile() {
|
void CodeEdtUI::saveFile() {
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, "Save File", "", "Matlab Files (*.m)");
|
if (!m_strCurOpenFile.isEmpty()) {
|
||||||
if (!fileName.isEmpty()) {
|
QFile file(m_strCurOpenFile);
|
||||||
QFile file(fileName);
|
|
||||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
QTextStream out(&file);
|
QTextStream out(&file);
|
||||||
|
out.setCodec("utf-8");
|
||||||
out << editor->toPlainText();
|
out << editor->toPlainText();
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,13 @@ public:
|
|||||||
CodeEdtUI(QWidget *parent = Q_NULLPTR);
|
CodeEdtUI(QWidget *parent = Q_NULLPTR);
|
||||||
void AttachDock(class DockWidget* dockWidget);
|
void AttachDock(class DockWidget* dockWidget);
|
||||||
|
|
||||||
|
void InitBat();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void openMainFile();
|
void openMainFile();
|
||||||
void openLDFile();
|
void openLDFile();
|
||||||
void openSeekerSimFile();
|
void openSeekerSimFile();
|
||||||
|
void runFile();
|
||||||
|
|
||||||
void saveFile();
|
void saveFile();
|
||||||
|
|
||||||
|
@ -214,9 +214,9 @@ void MainWindow::InitUI() {
|
|||||||
OsgViewer::Get().Initialize();
|
OsgViewer::Get().Initialize();
|
||||||
OsgViewer::Get().OnFrame();
|
OsgViewer::Get().OnFrame();
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
MatlabObject* mtlb = new MatlabObject;
|
// MatlabObject* mtlb = new MatlabObject;
|
||||||
mtlb->RunMatlabFile("D:\\DYT\\TestGUI\\TestGUI\\LDPlatformTest.m");
|
MatlabObject::GetInstance()->RunMatlabFile("");
|
||||||
#endif // 1
|
#endif // 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#include "MatlabObject.h"
|
#include "MatlabObject.h"
|
||||||
|
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <qDebug>
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
MatlabObject::MatlabObject(QObject *parent)
|
MatlabObject::MatlabObject(QObject *parent)
|
||||||
@ -15,6 +17,16 @@ MatlabObject::~MatlabObject()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MatlabObject* MatlabObject::m_pInstance = nullptr;
|
||||||
|
MatlabObject* MatlabObject::GetInstance()
|
||||||
|
{
|
||||||
|
if (!m_pInstance)
|
||||||
|
{
|
||||||
|
m_pInstance = new MatlabObject;
|
||||||
|
}
|
||||||
|
return m_pInstance;
|
||||||
|
}
|
||||||
|
|
||||||
void MatlabObject::RunMatlabFile(const QString& strFile)
|
void MatlabObject::RunMatlabFile(const QString& strFile)
|
||||||
{
|
{
|
||||||
QString strMatlabRun = QString("run('%1')").arg(strFile);
|
QString strMatlabRun = QString("run('%1')").arg(strFile);
|
||||||
@ -23,11 +35,27 @@ void MatlabObject::RunMatlabFile(const QString& strFile)
|
|||||||
std::string strRun = code->fromUnicode(strMatlabRun.toUtf8().data()).data();
|
std::string strRun = code->fromUnicode(strMatlabRun.toUtf8().data()).data();
|
||||||
|
|
||||||
Engine* ep;
|
Engine* ep;
|
||||||
if (!(ep = engOpen("\0"))) {
|
if (!(ep = engOpen(nullptr))) {
|
||||||
fprintf(stderr, "\nCan't start MATLAB engine\n");
|
fprintf(stderr, "\nCan't start MATLAB engine\n");
|
||||||
return; // EXIT_FAILURE;
|
return; // EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strFile.isEmpty())
|
||||||
|
{
|
||||||
|
engEvalString(ep, strRun.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*engEvalString(ep, "shu=666666;");
|
||||||
|
engEvalString(ep, "fileItgt1 = fopen('tgt1.txt', 'w');");
|
||||||
|
engEvalString(ep, "if fileItgt1 == -1");
|
||||||
|
engEvalString(ep, " error('ÎÞ·¨´ò¿ªÎļþ');");
|
||||||
|
engEvalString(ep, "end");
|
||||||
|
|
||||||
|
engEvalString(ep, "fprintf(fileItgt1, '%f ', shu);");
|
||||||
|
engEvalString(ep, "fprintf(fileItgt1, '\n');");
|
||||||
|
engEvalString(ep, "fclose(fileItgt1);");*/
|
||||||
|
|
||||||
engClose(ep);
|
engClose(ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,9 +10,13 @@ public:
|
|||||||
MatlabObject(QObject *parent=nullptr);
|
MatlabObject(QObject *parent=nullptr);
|
||||||
~MatlabObject();
|
~MatlabObject();
|
||||||
|
|
||||||
|
static MatlabObject* MatlabObject::GetInstance();
|
||||||
|
|
||||||
void RunMatlabFile(const QString& strFile);
|
void RunMatlabFile(const QString& strFile);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//std::u16string string2u16string(std::string& str);
|
//std::u16string string2u16string(std::string& str);
|
||||||
|
|
||||||
|
static MatlabObject* MatlabObject::m_pInstance;
|
||||||
};
|
};
|
||||||
|
@ -24,13 +24,14 @@ void ChartPlotMenu::InitMenu()
|
|||||||
connect(ui.toolButton, &QToolButton::clicked, this, [=] {
|
connect(ui.toolButton, &QToolButton::clicked, this, [=] {
|
||||||
if (WorkSpaceManager::Get().GetCurrent())
|
if (WorkSpaceManager::Get().GetCurrent())
|
||||||
{
|
{
|
||||||
MatlabObject mtlb;
|
|
||||||
QString strFile = WorkSpaceManager::Get().GetCurrent()->GetSimMatlab();
|
QString strFile = WorkSpaceManager::Get().GetCurrent()->GetSimMatlab();
|
||||||
if (!strFile.isEmpty())
|
if (!strFile.isEmpty())
|
||||||
{
|
{
|
||||||
strFile = RecourceHelper::Get().GetBasePath() + "/" + WorkSpaceManager::Get().GetCurrent()->GetSimMatlab();
|
strFile = RecourceHelper::Get().GetBasePath() + "/" + WorkSpaceManager::Get().GetCurrent()->GetSimMatlab();
|
||||||
|
|
||||||
mtlb.RunMatlabFile(strFile);
|
//MatlabObject::GetInstance()->RunMatlabFile("D:\\DYT\\TestGUI\\xierutest.m");
|
||||||
|
MatlabObject::GetInstance()->RunMatlabFile(strFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -21,5 +21,4 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ChartPlotMenuClass ui;
|
Ui::ChartPlotMenuClass ui;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -7933,6 +7933,26 @@ void QtWorkspacePropertyManagerPrivate::slotPropertyDestroyed(QtProperty* proper
|
|||||||
m_simMatlabToPropery[subProp] = 0;
|
m_simMatlabToPropery[subProp] = 0;
|
||||||
m_simMatlabToPropery.remove(property);
|
m_simMatlabToPropery.remove(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (QtProperty* subProp = m_matlabParamToPropery.value(property, nullptr)) {
|
||||||
|
m_matlabParamToPropery[subProp] = 0;
|
||||||
|
m_matlabParamToPropery.remove(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QtProperty* subProp = m_waveToPropery.value(property, nullptr)) {
|
||||||
|
m_waveToPropery[subProp] = 0;
|
||||||
|
m_waveToPropery.remove(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QtProperty* subProp = m_reportToPropery.value(property, nullptr)) {
|
||||||
|
m_reportToPropery[subProp] = 0;
|
||||||
|
m_reportToPropery.remove(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QtProperty* subProp = m_rdToPropery.value(property, nullptr)) {
|
||||||
|
m_rdToPropery[subProp] = 0;
|
||||||
|
m_rdToPropery.remove(property);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QtWorkspacePropertyManager::QtWorkspacePropertyManager(QObject* parent)
|
QtWorkspacePropertyManager::QtWorkspacePropertyManager(QObject* parent)
|
||||||
@ -8067,7 +8087,7 @@ void QtWorkspacePropertyManager::initializeProperty(QtProperty* property) {
|
|||||||
prop->setPropertyName(tr("MatlabParam"));
|
prop->setPropertyName(tr("MatlabParam"));
|
||||||
d_ptr->m_filesProperyManager->setValueOnly(prop, val.GetMatlabParam());
|
d_ptr->m_filesProperyManager->setValueOnly(prop, val.GetMatlabParam());
|
||||||
d_ptr->m_properyToMatlabParam[property] = prop;
|
d_ptr->m_properyToMatlabParam[property] = prop;
|
||||||
d_ptr->m_simMatlabToPropery[prop] = property;
|
d_ptr->m_matlabParamToPropery[prop] = property;
|
||||||
property->addSubProperty(prop);
|
property->addSubProperty(prop);
|
||||||
|
|
||||||
prop = d_ptr->m_filesProperyManager->addProperty();
|
prop = d_ptr->m_filesProperyManager->addProperty();
|
||||||
|
Loading…
Reference in New Issue
Block a user