コード例 #1
0
ファイル: agros_solver.cpp プロジェクト: fmach/agros2d
void AgrosSolver::runSuite()
{
    // log stdout
    if (m_enableLog)
         m_log = new LogStdOut();

    // silent mode
    setSilentMode(true);

    connect(currentPythonEngineAgros(), SIGNAL(pythonShowMessage(QString)), this, SLOT(stdOut(QString)));
    connect(currentPythonEngineAgros(), SIGNAL(pythonShowHtml(QString)), this, SLOT(stdHtml(QString)));

    QString testSuite = QString("from test_suite.scenario import run_suite; run_suite(test_suite.test_%1)").arg(m_suiteName);
    qDebug() << testSuite;

    bool successfulRun= currentPythonEngineAgros()->runScript(testSuite);

    if (successfulRun)
    {
        Agros2D::scene()->clear();
        Agros2D::clear();
        QApplication::exit(0);
    }
    else
    {
        ErrorResult result = currentPythonEngineAgros()->parseError();
        Agros2D::log()->printMessage(tr("Scripting Engine"), tr("%1\nLine: %2\nStacktrace:\n%3\n").
                                  arg(result.error()).
                                  arg(result.line()).
                                  arg(result.traceback()));

        QApplication::exit(-1);
    }
}
コード例 #2
0
ファイル: remotecontrol.cpp プロジェクト: dcm3c/agros2d
void ScriptEngineRemoteLocal::disconnected()
{
    m_server_socket->deleteLater();

    if (!m_command.isEmpty())
    {
        bool successfulRun = currentPythonEngineAgros()->runScript(m_command);
    }

    m_client_socket = new QLocalSocket();
    connect(m_client_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(displayError(QLocalSocket::LocalSocketError)));

    m_client_socket->connectToServer(clientName());
    if (m_client_socket->waitForConnected(1000))
    {
        ErrorResult result = currentPythonEngineAgros()->parseError();

        QTextStream out(m_client_socket);
        out << result.error();
        out.flush();
        m_client_socket->waitForBytesWritten();
    }
    else
    {
        displayError(QLocalSocket::ConnectionRefusedError);
    }

    delete m_client_socket;
}
コード例 #3
0
ファイル: pythonlabagros.cpp プロジェクト: karban/field
void pyCloseDocument()
{
    Util::scene()->clear();
    // sceneView()->doDefaultValues();
    Util::scene()->invalidate();

    currentPythonEngineAgros()->sceneViewPreprocessor()->actSceneModePreprocessor->trigger();

    currentPythonEngineAgros()->sceneViewPreprocessor()->doZoomBestFit();
    currentPythonEngineAgros()->sceneViewPost3D()->doZoomBestFit();
}
コード例 #4
0
ファイル: pythonlabagros.cpp プロジェクト: karban/field
void PyProblem::solve()
{
    Util::scene()->invalidate();

    // trigger preprocessor
    currentPythonEngineAgros()->sceneViewPreprocessor()->actSceneModePreprocessor->trigger();

    Util::problem()->solve();
    if (Util::problem()->isSolved())
    {
        // trigger postprocessor
        currentPythonEngineAgros()->sceneViewPost3D()->actSceneModePost3D->trigger();
    }
}
コード例 #5
0
ファイル: agros_solver.cpp プロジェクト: fmach/agros2d
void AgrosSolver::printTestSuites()
{
    QStringList list = currentPythonEngineAgros()->testSuiteScenarios();

    foreach (QString test, list)
    {
        std::cout << test.remove("test_").toStdString() << std::endl;
    }
コード例 #6
0
ファイル: agros_solver.cpp プロジェクト: pkropik/agros2d
void AgrosSolver::runScript()
{
    // log stdout
    if (m_enableLog)
         m_log = new LogStdOut();

    if (!QFile::exists(m_fileName))
    {
        Agros2D::log()->printMessage(tr("Scripting Engine"), tr("Python script '%1' not found").arg(m_fileName));
        QApplication::exit(-1);
    }

    QTime time;
    time.start();

    // silent mode
    setSilentMode(true);

    connect(currentPythonEngineAgros(), SIGNAL(pythonShowMessage(QString)), this, SLOT(stdOut(QString)));
    connect(currentPythonEngineAgros(), SIGNAL(pythonShowHtml(QString)), this, SLOT(stdHtml(QString)));

    bool successfulRun= currentPythonEngineAgros()->runScript(readFileContent(m_fileName), m_fileName);

    if (successfulRun)
    {
        Agros2D::log()->printMessage(tr("Solver"), tr("Problem was solved in %1").arg(milisecondsToTime(time.elapsed()).toString("mm:ss.zzz")));

        Agros2D::scene()->clear();
        Agros2D::clear();
        QApplication::exit(0);
    }
    else
    {
        ErrorResult result = currentPythonEngineAgros()->parseError();
        Agros2D::log()->printMessage(tr("Scripting Engine"), tr("%1\nLine: %2\nStacktrace:\n%3\n").
                                  arg(result.error()).
                                  arg(result.line()).
                                  arg(result.traceback()));

        QApplication::exit(-1);
    }
}
コード例 #7
0
ファイル: pyproblem.cpp プロジェクト: LeiDai/agros2d
void PyProblem::clearSolution()
{
    if (!Agros2D::problem()->isSolved())
        throw logic_error(QObject::tr("Problem is not solved.").toStdString());

    Agros2D::problem()->clearSolution();
    Agros2D::scene()->invalidate();

    if (!silentMode())
        currentPythonEngineAgros()->sceneViewPreprocessor()->actSceneModePreprocessor->trigger();
}
コード例 #8
0
ファイル: problemdialog.cpp プロジェクト: karban/field
void ProblemWidget::startupScriptChanged()
{
    lblStartupScriptError->clear();

    // run and check startup script
    if (!txtStartupScript->toPlainText().isEmpty())
    {
        ScriptResult scriptResult = currentPythonEngineAgros()->runScript(txtStartupScript->toPlainText());
        if (scriptResult.isError)
            lblStartupScriptError->setText(QObject::tr("Error: %1").arg(scriptResult.text));
    }
}
コード例 #9
0
ファイル: pythonengine_agros.cpp プロジェクト: dcm3c/agros2d
void PythonEngineAgros::materialValues(const QString &function, double from, double to,
                                       QVector<double> *keys, QVector<double> *values, int count)
{
    if (function.isEmpty())
        return;

    // function
    bool succesfulRun = runExpression(function);
    if (!succesfulRun)
    {
        ErrorResult result = currentPythonEngineAgros()->parseError();
        qDebug() << "Function: " << result.error();
    }

    // prepare keys
    double step = (to - from) / (count - 1);
    QString keysVector = "[";
    for (int i = 0; i < count; i++)
    {
        double key = from + i * step;
        keys->append(key);

        if (i == 0)
            keysVector += QString("%1").arg(key + EPS_ZERO);
        else if (i == (count - 1))
            keysVector += QString(", %1]").arg(key - EPS_ZERO);
        else
            keysVector += QString(", %1").arg(key);
    }

    // run expression
    runExpression(QString("agros2d_material_values = agros2d_material_eval(%1)").arg(keysVector));

    // extract values
    PyObject *result = PyDict_GetItemString(m_dict, "agros2d_material_values");
    if (result)
    {
        Py_INCREF(result);
        for (int i = 0; i < count; i++)
            values->append(PyFloat_AsDouble(PyList_GetItem(result, i)));
        Py_XDECREF(result);
    }

    // remove variables
    runExpression("del agros2d_material; del agros2d_material_values");

    // error during execution
    if (keys->size() != values->size())
    {
        keys->clear();
        values->clear();
    }
}
コード例 #10
0
ファイル: problemdialog.cpp プロジェクト: karban/field
void ProblemWidget::changedWithClear()
{
    // run and check startup script
    if (!txtStartupScript->toPlainText().isEmpty())
    {
        ScriptResult scriptResult = currentPythonEngineAgros()->runScript(txtStartupScript->toPlainText());
        if (scriptResult.isError)
            return;
    }

    // save properties
    Util::problem()->config()->blockSignals(true);

    // script
    Util::problem()->config()->setStartupScript(txtStartupScript->toPlainText());

    Util::problem()->config()->blockSignals(false);
    Util::problem()->config()->refresh();

    emit changed();
}
コード例 #11
0
ファイル: pyproblem.cpp プロジェクト: LeiDai/agros2d
void PyProblem::refresh()
{
    Agros2D::scene()->invalidate();
    currentPythonEngineAgros()->postHermes()->refresh();
}