예제 #1
0
void ScriptEngineRemote::disconnected()
{
    logMessage("ScriptEngineRemote::disconnected()");

    m_server_socket->deleteLater();

    ScriptResult result;
    if (!command.isEmpty())
    {
        result = runPythonScript(command);
    }

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

    m_client_socket->connectToServer("agros2d-client");
    if (m_client_socket->waitForConnected(1000))
    {
        QTextStream out(m_client_socket);
        out << result.text;
        out.flush();
        m_client_socket->waitForBytesWritten();
    }
    else
    {
        displayError(QLocalSocket::ConnectionRefusedError);
    }

    delete m_client_socket;
}
예제 #2
0
void Terminal::doExecute()
{
    logMessage("Terminal::doExecute()");

    if (!txtCommand->text().isEmpty())
    {
        QSettings settings;
        QStringList list = settings.value("CommandDialog/RecentCommands").value<QStringList>();

        list.insert(0, txtCommand->text());

        // remove last item (over 50), empty strings and duplicates
        list.removeAll("");
        // list.removeDuplicates();
        while (list.count() > 50)
            list.removeAt(list.count()-1);

        txtCommand->model()->setStringList(list);
        settings.setValue("CommandDialog/RecentCommands", list);

        // command
        doPrintStdout(">>> " + txtCommand->text() + "\n", Qt::black);

        // execute command
        doWriteResult(runPythonScript(txtCommand->text()));
    }
    txtCommand->clear();
    txtCommand->setFocus();
}
예제 #3
0
bool ProblemDialog::save()
{
    logMessage("ProblemDialog::save()");

    // physical field type
    if (Util::scene()->problemInfo()->physicField() != ((PhysicField) cmbPhysicField->itemData(cmbPhysicField->currentIndex()).toInt()))
    {
        if (!this->m_isNewProblem)
        {
            if (Util::scene()->boundaries.count() != 1 || Util::scene()->materials.count() != 1)
            {
                if (QMessageBox::question(this, tr("Change physical field type"), tr("Are you sure change physical field type?"), tr("&Yes"), tr("&No")) == 1)
                    return false;
            }
        }

        if (Util::scene()->sceneSolution()->isSolved())
            Util::scene()->doClearSolution();

        m_problemInfo->setHermes(hermesFieldFactory((PhysicField) cmbPhysicField->itemData(cmbPhysicField->currentIndex()).toInt()));

        for (int i = 1; i < Util::scene()->boundaries.count(); i++)
        {
            Util::scene()->replaceBoundary(Util::scene()->boundaries[1]);
        }

        for (int i = 1; i < Util::scene()->materials.count(); i++)
        {
            Util::scene()->replaceMaterial(Util::scene()->materials[1]);
        }
    }
    else
    {
        m_problemInfo->setHermes(hermesFieldFactory((PhysicField) cmbPhysicField->itemData(cmbPhysicField->currentIndex()).toInt()));
    }

    // check values
    if ((ProblemType) cmbProblemType->itemData(cmbProblemType->currentIndex()).toInt() == ProblemType_Axisymmetric)
    {
        for (int i = 0; i<Util::scene()->nodes.count(); i++)
        {
            if (Util::scene()->nodes[i]->point.x < 0.0)
            {
                QMessageBox::warning(QApplication::activeWindow(), QObject::tr("Error"), tr("Some nodes are placed outside the permitted area (coordinate x must be positive)."));
                break;
            }
        }
    }
    if (cmbAnalysisType->itemData(cmbAnalysisType->currentIndex()).toInt() == AnalysisType_Harmonic)
    {
        if (txtFrequency->value() < 0)
        {
            QMessageBox::critical(this, tr("Error"), tr("Frequency cannot be negative."));
            return false;
        }
    }
    if (cmbAnalysisType->itemData(cmbAnalysisType->currentIndex()).toInt() == AnalysisType_Transient)
    {
        txtTransientTimeStep->evaluate(false);
        if (txtTransientTimeStep->number() <= 0.0)
        {
            QMessageBox::critical(this, tr("Error"), tr("Time step must be positive."));
            return false;
        }
        txtTransientTimeTotal->evaluate(false);
        if (txtTransientTimeTotal->number() <= 0.0)
        {
            QMessageBox::critical(this, tr("Error"), tr("Total time must be positive."));
            return false;
        }
        txtTransientTimeStep->evaluate(false);
        if (txtTransientTimeStep->number() > txtTransientTimeTotal->number())
        {
            QMessageBox::critical(this, tr("Error"), tr("Time step is greater then total time."));
            return false;
        }
    }

    // run and check startup script
    if (!txtStartupScript->toPlainText().isEmpty())
    {
        ScriptResult scriptResult = runPythonScript(txtStartupScript->toPlainText());
        if (scriptResult.isError)
        {
            QMessageBox::critical(QApplication::activeWindow(), QObject::tr("Error"), scriptResult.text);
            return false;
        }
    }

    // save properties
    m_problemInfo->name = txtName->text();
    m_problemInfo->date = dtmDate->date();

    m_problemInfo->problemType = (ProblemType) cmbProblemType->itemData(cmbProblemType->currentIndex()).toInt();
    m_problemInfo->numberOfRefinements = txtNumberOfRefinements->value();
    m_problemInfo->polynomialOrder = txtPolynomialOrder->value();
    m_problemInfo->meshType = (MeshType) cmbMeshType->itemData(cmbMeshType->currentIndex()).toInt();
    m_problemInfo->adaptivityType = (AdaptivityType) cmbAdaptivityType->itemData(cmbAdaptivityType->currentIndex()).toInt();
    m_problemInfo->adaptivitySteps = txtAdaptivitySteps->value();
    m_problemInfo->adaptivityTolerance = txtAdaptivityTolerance->value();

    m_problemInfo->frequency = txtFrequency->value();

    m_problemInfo->analysisType = (AnalysisType) cmbAnalysisType->itemData(cmbAnalysisType->currentIndex()).toInt();
    m_problemInfo->timeStep = txtTransientTimeStep->value();
    m_problemInfo->timeTotal = txtTransientTimeTotal->value();
    m_problemInfo->initialCondition = txtTransientInitialCondition->value();

    m_problemInfo->description = txtDescription->toPlainText();
    m_problemInfo->scriptStartup = txtStartupScript->toPlainText();

    m_problemInfo->linearityType = (LinearityType) cmbLinearityType->itemData(cmbLinearityType->currentIndex()).toInt();
    m_problemInfo->linearityNonlinearSteps = txtLinearityNonlinearitySteps->value();
    m_problemInfo->linearityNonlinearTolerance = txtLinearityNonlinearityTolerance->value();

    // matrix solver
    m_problemInfo->matrixSolver = (MatrixSolverType) cmbMatrixSolver->itemData(cmbMatrixSolver->currentIndex()).toInt();

    return true;
}