修复求解器多参数无法启动的问题
parent
97798acba5
commit
b4c4e7e064
|
@ -37,19 +37,27 @@
|
|||
#include <QDebug>
|
||||
#include "PythonModule/PyAgent.h"
|
||||
|
||||
namespace SolverControl
|
||||
{
|
||||
namespace SolverControl {
|
||||
|
||||
SolverControlBase::SolverControlBase(GUI::MainWindow *mainwindow, ConfigOption::SolverInfo *solver, ModelData::ModelDataBase *m, bool sonly)
|
||||
: _mainWindow(mainwindow), _solver(solver), _model(m), _solveOnly(sonly)
|
||||
SolverControlBase::SolverControlBase(GUI::MainWindow* mainwindow,
|
||||
ConfigOption::SolverInfo* solver,
|
||||
ModelData::ModelDataBase* m, bool sonly)
|
||||
: _mainWindow(mainwindow)
|
||||
, _solver(solver)
|
||||
, _model(m)
|
||||
, _solveOnly(sonly)
|
||||
{
|
||||
connect(&_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readSolverOutput()));
|
||||
connect(this, SIGNAL(sendMessage(QString)), _mainWindow, SIGNAL(printMessageToMessageWindow(QString)));
|
||||
connect(this, SIGNAL(solverStarted(QWidget *)), _mainWindow, SIGNAL(addProcessBarSig(QWidget *)));
|
||||
connect(this, SIGNAL(sendMessage(QString)), _mainWindow,
|
||||
SIGNAL(printMessageToMessageWindow(QString)));
|
||||
connect(this, SIGNAL(solverStarted(QWidget*)), _mainWindow,
|
||||
SIGNAL(addProcessBarSig(QWidget*)));
|
||||
connect(_mainWindow, SIGNAL(stopSolve(QWidget*)), this, SLOT(stopSolver(QWidget*)));
|
||||
connect(&_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus)));
|
||||
connect(&_process, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
||||
SLOT(processFinished(int, QProcess::ExitStatus)));
|
||||
connect(this, SIGNAL(processFinish(int)), _mainWindow, SIGNAL(processFinished(int)));
|
||||
connect(this, SIGNAL(openRealTime(Post::RealTimeWindowBase *, int)), _mainWindow, SIGNAL(openRealTimeWindowSig(Post::RealTimeWindowBase *, int)));
|
||||
connect(this, SIGNAL(openRealTime(Post::RealTimeWindowBase*, int)), _mainWindow,
|
||||
SIGNAL(openRealTimeWindowSig(Post::RealTimeWindowBase*, int)));
|
||||
}
|
||||
SolverControlBase::~SolverControlBase()
|
||||
{
|
||||
|
@ -69,15 +77,14 @@ namespace SolverControl
|
|||
QFileInfo info(solverPath);
|
||||
int id = _model->getID();
|
||||
|
||||
if ((!info.exists()) || (!info.isFile()))
|
||||
{
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("Solver Path Error! Solve Path : %1").arg(solverPath));
|
||||
if((!info.exists()) || (!info.isFile())) {
|
||||
QMessageBox::warning(nullptr, tr("Warning"),
|
||||
tr("Solver Path Error! Solve Path : %1").arg(solverPath));
|
||||
emit processFinish(id);
|
||||
return;
|
||||
}
|
||||
bool ok = preProcess();
|
||||
if (!ok)
|
||||
{
|
||||
if(!ok) {
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("Input file write failed !"));
|
||||
emit processFinish(id);
|
||||
return;
|
||||
|
@ -87,11 +94,9 @@ namespace SolverControl
|
|||
|
||||
QString startPath = _model->getPath();
|
||||
|
||||
if (_solver->getType() == ConfigOption::SelfDevelop)
|
||||
{
|
||||
if(_solver->getType() == ConfigOption::SelfDevelop) {
|
||||
QDir dir(startPath);
|
||||
if (dir.exists() && (!startPath.isEmpty()))
|
||||
{
|
||||
if(dir.exists() && (!startPath.isEmpty())) {
|
||||
oldDir = QDir::currentPath();
|
||||
QDir::setCurrent(startPath);
|
||||
}
|
||||
|
@ -104,8 +109,7 @@ namespace SolverControl
|
|||
regExp.setMinimal(true);
|
||||
// int pos = regExp.indexIn(args);
|
||||
QStringList variables = regExp.capturedTexts();
|
||||
for (int i = 0; i < variables.size(); ++i)
|
||||
{
|
||||
for(int i = 0; i < variables.size(); ++i) {
|
||||
QString variable = variables.at(i);
|
||||
QString va = variable.remove("%");
|
||||
if(va.toLower() == "modelpath")
|
||||
|
@ -122,23 +126,21 @@ namespace SolverControl
|
|||
// startProcess = startProcess + " " + _args;
|
||||
// qDebug() << startProcess;
|
||||
|
||||
_process.start(solverPath, QStringList(args));
|
||||
_process.start(solverPath, args.split(" ", QString::SkipEmptyParts));
|
||||
|
||||
emit solverStarted(_processBar);
|
||||
|
||||
ModelData::ModelDataBaseExtend *extend = dynamic_cast<ModelData::ModelDataBaseExtend *>(_model);
|
||||
if (extend != nullptr && !_solveOnly)
|
||||
{
|
||||
ModelData::ModelDataBaseExtend* extend =
|
||||
dynamic_cast<ModelData::ModelDataBaseExtend*>(_model);
|
||||
if(extend != nullptr && !_solveOnly) {
|
||||
QList<ConfigOption::PostCurve*> curves = extend->getMonitorCurves();
|
||||
if (curves.size() > 0)
|
||||
{
|
||||
if(curves.size() > 0) {
|
||||
int id = _model->getID();
|
||||
Post::RealTimeWindowBase* w = new Post::RealTimeWindowBase(_mainWindow, id);
|
||||
emit openRealTime(w, id);
|
||||
}
|
||||
}
|
||||
if (_solver->getType() == ConfigOption::SelfDevelop)
|
||||
{
|
||||
if(_solver->getType() == ConfigOption::SelfDevelop) {
|
||||
if(!oldDir.isEmpty())
|
||||
QDir::setCurrent(oldDir);
|
||||
}
|
||||
|
@ -150,8 +152,7 @@ namespace SolverControl
|
|||
// qDebug() << process;
|
||||
QRegExp rx(process);
|
||||
int pos = _outputBuffer.indexOf(rx);
|
||||
if (pos > -1 && _processBar != nullptr)
|
||||
{
|
||||
if(pos > -1 && _processBar != nullptr) {
|
||||
QString s = rx.cap(1);
|
||||
_processBar->setProcess(s.toInt());
|
||||
}
|
||||
|
@ -167,8 +168,7 @@ namespace SolverControl
|
|||
if(_model != nullptr)
|
||||
id = _model->getID();
|
||||
emit removeSolver(id);
|
||||
if (!_processFinished)
|
||||
{
|
||||
if(!_processFinished) {
|
||||
_process.kill();
|
||||
}
|
||||
_processBar = nullptr;
|
||||
|
@ -177,8 +177,7 @@ namespace SolverControl
|
|||
|
||||
void SolverControlBase::stopSolver()
|
||||
{
|
||||
if (!_processFinished)
|
||||
{
|
||||
if(!_processFinished) {
|
||||
_process.kill();
|
||||
}
|
||||
}
|
||||
|
@ -187,14 +186,13 @@ namespace SolverControl
|
|||
{
|
||||
QString solverPath = _solver->getExePath();
|
||||
QFileInfo info(solverPath);
|
||||
if ((!info.exists()) || (!info.isFile()))
|
||||
{
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("Solver Path Error! Solve Path : %1").arg(solverPath));
|
||||
if((!info.exists()) || (!info.isFile())) {
|
||||
QMessageBox::warning(nullptr, tr("Warning"),
|
||||
tr("Solver Path Error! Solve Path : %1").arg(solverPath));
|
||||
return;
|
||||
}
|
||||
bool ok = preProcess();
|
||||
if (!ok)
|
||||
{
|
||||
if(!ok) {
|
||||
QMessageBox::warning(nullptr, tr("Warning"), tr("Input file write failed !"));
|
||||
return;
|
||||
}
|
||||
|
@ -203,11 +201,9 @@ namespace SolverControl
|
|||
|
||||
QString startPath = _model->getPath();
|
||||
|
||||
if (_solver->getType() == ConfigOption::SelfDevelop)
|
||||
{
|
||||
if(_solver->getType() == ConfigOption::SelfDevelop) {
|
||||
QDir dir(startPath);
|
||||
if (dir.exists() && (!startPath.isEmpty()))
|
||||
{
|
||||
if(dir.exists() && (!startPath.isEmpty())) {
|
||||
oldDir = QDir::currentPath();
|
||||
QDir::setCurrent(startPath);
|
||||
}
|
||||
|
@ -220,8 +216,7 @@ namespace SolverControl
|
|||
regExp.setMinimal(true);
|
||||
// int pos = regExp.indexIn(args);
|
||||
QStringList variables = regExp.capturedTexts();
|
||||
for (int i = 0; i < variables.size(); ++i)
|
||||
{
|
||||
for(int i = 0; i < variables.size(); ++i) {
|
||||
QString variable = variables.at(i);
|
||||
QString va = variable.remove("%");
|
||||
if(va.toLower() == "modelpath")
|
||||
|
@ -244,19 +239,17 @@ namespace SolverControl
|
|||
|
||||
emit solverStarted(_processBar);
|
||||
|
||||
ModelData::ModelDataBaseExtend *extend = dynamic_cast<ModelData::ModelDataBaseExtend *>(_model);
|
||||
if (extend != nullptr && !_solveOnly)
|
||||
{
|
||||
ModelData::ModelDataBaseExtend* extend =
|
||||
dynamic_cast<ModelData::ModelDataBaseExtend*>(_model);
|
||||
if(extend != nullptr && !_solveOnly) {
|
||||
QList<ConfigOption::PostCurve*> curves = extend->getMonitorCurves();
|
||||
if (curves.size() > 0)
|
||||
{
|
||||
if(curves.size() > 0) {
|
||||
int id = _model->getID();
|
||||
Post::RealTimeWindowBase* w = new Post::RealTimeWindowBase(_mainWindow, id);
|
||||
emit openRealTime(w, id);
|
||||
}
|
||||
}
|
||||
if (_solver->getType() == ConfigOption::SelfDevelop)
|
||||
{
|
||||
if(_solver->getType() == ConfigOption::SelfDevelop) {
|
||||
if(!oldDir.isEmpty())
|
||||
QDir::setCurrent(oldDir);
|
||||
}
|
||||
|
@ -289,8 +282,7 @@ namespace SolverControl
|
|||
id = _model->getID();
|
||||
emit processFinish(id);
|
||||
|
||||
switch (exitStatus)
|
||||
{
|
||||
switch(exitStatus) {
|
||||
case QProcess::NormalExit:
|
||||
emit sendMessage("************************************");
|
||||
emit sendMessage("***** Solving process finished *****");
|
||||
|
@ -308,8 +300,7 @@ namespace SolverControl
|
|||
emit sendMessage("***********************************");
|
||||
break;
|
||||
}
|
||||
if (_processBar != nullptr)
|
||||
{
|
||||
if(_processBar != nullptr) {
|
||||
if(_processBar->isBusy())
|
||||
_processBar->setProcessRange(0, 100);
|
||||
_processBar->setProcess(100);
|
||||
|
@ -323,14 +314,11 @@ namespace SolverControl
|
|||
if(_solveOnly)
|
||||
return true;
|
||||
bool istemp = _solver->isWriteTemplate();
|
||||
if (istemp)
|
||||
{
|
||||
if(istemp) {
|
||||
QString te = _solver->getTemplate();
|
||||
QString path = _model->getPath();
|
||||
return IO::SolverIO::replaceTemplate(te, path, _model);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QString format = _solver->getInputFormat();
|
||||
return IO::SolverIO::writeInpFile(format, _model);
|
||||
}
|
||||
|
@ -346,4 +334,4 @@ namespace SolverControl
|
|||
return IO::SolverIO::transformFile(trans, path);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace SolverControl
|
||||
|
|
Loading…
Reference in New Issue