Exemplo n.º 1
0
void PythonLabAgros::doCreatePythonFromModel()
{
    txtEditor->setPlainText(createPythonFromModel());
}
Exemplo n.º 2
0
void PythonEditorAgrosDialog::doCreatePythonFromModel()
{
    StartupScript_Type type = actStartupScriptVariables->isChecked() ? StartupScript_Variable : StartupScript_Value;
    txtEditor->setPlainText(createPythonFromModel(type));
}
Exemplo n.º 3
0
QString ReportDialog::replaceTemplates(const QString &source)
{
    logMessage("ReportDialog::()replaceTemplates");

    QString destination = source;

    // stylesheet
    destination.replace("[StyleSheet]", "./style.css", Qt::CaseSensitive);

    // problem name
    destination.replace("[Report.Label]", "<h1>" + Util::scene()->problemInfo()->name + "</h1>", Qt::CaseSensitive);

    // description
    if (chkDescription->isChecked())
    {
        destination.replace("[Description.Label]", "<h2>" + tr("Description") + "</h2>", Qt::CaseSensitive);
        destination.replace("[Description]", "<p>" + Util::scene()->problemInfo()->description + "</p>", Qt::CaseSensitive);
    }
    else
    {
        destination.remove("[Description.Label]", Qt::CaseSensitive);
        destination.remove("[Description]", Qt::CaseSensitive);
    }

    // problem information
    if (chkProblemInformation->isChecked())
    {
        destination.replace("[ProblemInformation.Label]", "<h2>" + tr("Problem Information") + "</h2>", Qt::CaseSensitive);
        destination.replace("[ProblemInformation.Name]", "<table><tr><td>" + tr("Name:") + "</td><td>" + Util::scene()->problemInfo()->name + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[ProblemInformation.Date]", "<tr><td>" + tr("Date:") + "</td><td>" + Util::scene()->problemInfo()->date.toString("dd.MM.yyyy") + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[ProblemInformation.FileName]", "<tr><td>" + tr("Filename:") + "</td><td>" + QFileInfo(Util::scene()->problemInfo()->fileName).fileName() + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[ProblemInformation.ProblemType]", "<tr><td>" + tr("Problem type:") + "</td><td>" + problemTypeString(Util::scene()->problemInfo()->problemType) + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[ProblemInformation.PhysicField]", "<tr><td>" + tr("Physic field:") + "</td><td>" + physicFieldString(Util::scene()->problemInfo()->physicField()) + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[ProblemInformation.AnalysisType]", "<tr><td>" + tr("Analysis type:") + "</td><td>" + analysisTypeString(Util::scene()->problemInfo()->analysisType) + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[ProblemInformation.NumberOfRefinements]", "<tr><td>" + tr("Number of refinements:") + "</td><td>" + QString::number(Util::scene()->problemInfo()->numberOfRefinements) + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[ProblemInformation.PolynomialOrder]", "<tr><td>" + tr("Polynomial order:") + "</td><td>" + QString::number(Util::scene()->problemInfo()->polynomialOrder) + "</td></tr></table>", Qt::CaseSensitive);

        if (Util::scene()->problemInfo()->adaptivityType != AdaptivityType_None && chkProblemInformation->isChecked())
        {
            destination.replace("[ProblemInformation.AdaptivityType]", "<table><tr><td>" + tr("Adaptivity type:") + "</td><td>" + adaptivityTypeString(Util::scene()->problemInfo()->adaptivityType) + "</td></tr>", Qt::CaseSensitive);
            destination.replace("[ProblemInformation.AdaptivitySteps]", "<tr><td>" + tr("Adaptivity steps:") + "</td><td>" + QString::number(Util::scene()->problemInfo()->adaptivitySteps) + "</td></tr>", Qt::CaseSensitive);
            destination.replace("[ProblemInformation.AdaptivityTolerance]", "<tr><td>" + tr("Adaptivity tolerance:") + "</td><td>" + QString::number(Util::scene()->problemInfo()->adaptivityTolerance) + "</td></tr></table>", Qt::CaseSensitive);
            destination.replace("[ProblemInformation.MaxDOFs]", "<tr><td>" + tr("Maximum DOFs:") + "</td><td>" + QString::number(Util::config()->maxDofs) + "</td></tr></table>", Qt::CaseSensitive);
        }
        else
        {
            // remove empty tags
            QString tag [4] = {"[ProblemInformation.AdaptivityType]", "[ProblemInformation.AdaptivitySteps]",
                               "[ProblemInformation.AdaptivityTolerance]", "[ProblemInformation.MaxDOFs]"};

            for (int i = 0; i < 3; i++)
            {
                destination.remove(tag[i].toUtf8(), Qt::CaseSensitive);
            }
        }

        if ((Util::scene()->problemInfo()->hermes()->hasHarmonic() || Util::scene()->problemInfo()->analysisType == AnalysisType_Transient) && chkProblemInformation->isChecked())
        {
            destination.replace("[ProblemInformation.Frequency]", "<table><tr><td>" + tr("Adaptivity type:") + "</td><td>" + QString::number(Util::scene()->problemInfo()->frequency) + "</td></tr>", Qt::CaseSensitive);
            destination.replace("[ProblemInformation.TimeStep]", "<tr><td>" + tr("Adaptivity type:") + "</td><td>" + QString::number(Util::scene()->problemInfo()->timeStep.number) + "</td></tr>", Qt::CaseSensitive);
            destination.replace("[ProblemInformation.TimeTotal]", "<tr><td>" + tr("Adaptivity type:") + "</td><td>" + QString::number(Util::scene()->problemInfo()->timeTotal.number) + "</td></tr>", Qt::CaseSensitive);
            destination.replace("[ProblemInformation.InititalCondition]", "<tr><td>" + tr("Adaptivity type:") + "</td><td>" + QString::number(Util::scene()->problemInfo()->initialCondition.number) + "</td></tr></table>", Qt::CaseSensitive);
        }
        else
        {
            // remove empty tags
            QString tag [4] = {"[ProblemInformation.Frequency]", "[ProblemInformation.TimeStep]",
                               "[ProblemInformation.TimeTotal]", "[ProblemInformation.InititalCondition]",};

            for (int i = 0; i < 4; i++)
            {
                destination.remove(tag[i].toUtf8(), Qt::CaseSensitive);
            }
        }
    }
    else
    {
        // remove empty tags
        QString tag [17] = {"[ProblemInformation.Label]", "[ProblemInformation.Name]",
                           "[ProblemInformation.Date]", "[ProblemInformation.FileName]",
                           "[ProblemInformation.ProblemType]", "[ProblemInformation.PhysicField]",
                           "[ProblemInformation.AnalysisType]", "[ProblemInformation.NumberOfRefinements]",
                           "[ProblemInformation.PolynomialOrder]", "[ProblemInformation.AdaptivityType]",
                           "[ProblemInformation.AdaptivityType]", "[ProblemInformation.AdaptivitySteps]",
                           "[ProblemInformation.AdaptivityTolerance]", "[ProblemInformation.Frequency]",
                           "[ProblemInformation.TimeStep]", "[ProblemInformation.TimeTotal]",
                           "[ProblemInformation.InititalCondition]"};

        for (int i = 0; i < 16; i++)
        {
            destination.remove(tag[i].toUtf8(), Qt::CaseSensitive);
        }
    }

    // startup script
    if (chkStartupScript->isChecked())
    {
        destination.replace("[StartupScript.Label]", "<h2>" + tr("Startup Script") + "</h2>", Qt::CaseSensitive);
        destination.replace("[StartupScript]", "<pre>" + Util::scene()->problemInfo()->scriptStartup + "</pre>", Qt::CaseSensitive);
    }
    else
    {
        destination.remove("[StartupScript.Label]", Qt::CaseSensitive);
        destination.remove("[StartupScript]", Qt::CaseSensitive);
    }

    // physical properties
    if (chkPhysicalProperties->isChecked())
    {
        destination.replace("[PhysicalProperties.Label]", "<h2>" + tr("Physical Properties") + "</h2>", Qt::CaseSensitive);
        destination.replace("[Materials.Label]", "<h3>" + tr("Materials") + "</h3>", Qt::CaseSensitive);
        destination.replace("[Materials]", htmlMaterials(), Qt::CaseSensitive);
        destination.replace("[Boundaries.Label]", "<h3>" + tr("Boundaris conditions") + "</h3>", Qt::CaseSensitive);
        destination.replace("[Boundaries]", htmlBoundaries(), Qt::CaseSensitive);
    }
    else
    {
        // remove empty tags
        QString tag [5] = {"[PhysicalProperties.Label]", "[Materials.Label]",
                           "[Materials]", "[Boundaries.Label]", "[Boundaries]"};

        for (int i = 0; i < 5; i++)
        {
            destination.remove(tag[i].toUtf8(), Qt::CaseSensitive);
        }
    }

    // geometry
    if (chkGeometry->isChecked())
    {
        destination.replace("[Geometry.Label]", "<h2>" + tr("Geometry") + "</h2>", Qt::CaseSensitive);
        destination.replace("[Geometry.Nodes.Label]", "<h3>" + tr("Nodes") + "</h3>", Qt::CaseSensitive);
        destination.replace("[Geometry.Nodes]", htmlGeometryNodes(), Qt::CaseSensitive);
        destination.replace("[Geometry.Edges.Label]", "<h3>" + tr("Edges") + "</h3>", Qt::CaseSensitive);
        destination.replace("[Geometry.Edges]", htmlGeometryEdges(), Qt::CaseSensitive);
        destination.replace("[Geometry.Labels.Label]", "<h3>" + tr("Labels") + "</h3>", Qt::CaseSensitive);
        destination.replace("[Geometry.Labels]", htmlGeometryLabels(), Qt::CaseSensitive);
    }
    else
    {
        // remove empty tags
        QString tag [7] = {"[Geometry.Label]", "[Geometry.Nodes.Label]",
                           "[Geometry.Nodes]", "[Geometry.Edges.Label]",
                           "[Geometry.Edges]", "[Geometry.Labels.Label]", "[Geometry.Labels]"};

        for (int i = 0; i < 7; i++)
        {
            destination.remove(tag[i].toUtf8(), Qt::CaseSensitive);
        }
    }

    // solver
    if (chkMeshAndSolution->isChecked())
    {
        QTime time;
        time = milisecondsToTime(Util::scene()->sceneSolution()->timeElapsed());

        destination.replace("[MeshAndSolver.Label]", "<h2>" + tr("Mesh and Solution") + "</h2>", Qt::CaseSensitive);
        destination.replace("[Solver.Label]", "<h3>" + tr("Solver information") + "</h3>", Qt::CaseSensitive);
        destination.replace("[Solver.Nodes]", "<table><tr><td>" + tr("Nodes:") + "</td><td>" + QString::number(Util::scene()->sceneSolution()->meshInitial()->get_num_nodes()) + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[Solver.Elements]", "<tr><td>" + tr("Elements:") + "</td><td>" + QString::number(Util::scene()->sceneSolution()->meshInitial()->get_num_active_elements()) + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[Solver.DOFs]", "<tr><td>" + tr("DOFs:") + "</td><td>" + QString::number(Util::scene()->sceneSolution()->sln()->get_num_dofs()) + "</td></tr>", Qt::CaseSensitive);
        destination.replace("[Solver.TimeElapsed]", "<tr><td>" + tr("Elapsed time:") + "</td><td>" + time.toString("mm:ss.zzz") + " s</td></tr></table>", Qt::CaseSensitive);

        if (Util::scene()->problemInfo()->adaptivityType != AdaptivityType_None)
        {
            destination.replace("[Solver.AdaptiveError]", "<table><tr><td>" + tr("Adaptive error:") + "</td><td>" + QString::number(Util::scene()->sceneSolution()->adaptiveError(), 'f', 3)  + "</td></tr>", Qt::CaseSensitive);
            destination.replace("[Solver.AdaptiveSteps]", "<tr><td>" + tr("Adaptive steps:") + "</td><td>" + QString::number(Util::scene()->sceneSolution()->adaptiveSteps()) + "</td></tr></table>", Qt::CaseSensitive);
        }
        else
        {


            // remove empty tags
            QString tag [2] = {"[Solver.AdaptiveError]", "[Solver.AdaptiveSteps]"};

            for (int i = 0; i < 2; i++)
            {
                destination.remove(tag[i].toUtf8(), Qt::CaseSensitive);
            }
        }
    }
    else
    {
        // remove empty tags
        QString tag [8] = {"[MeshAndSolver.Label]", "[Solver.Label]",
                           "[Solver.Nodes]", "[Solver.Elements]",
                           "[Solver.DOFs]", "[Solver.TimeElapsed]",
                           "[Solver.AdaptiveError]", "[Solver.AdaptiveSteps]"};

        for (int i = 0; i < 8; i++)
        {
            destination.remove(tag[i].toUtf8(), Qt::CaseSensitive);
        }
    }

    // script
    if (chkScript->isChecked())
    {
        destination.replace("[Script.Label]", "<h2>" + tr("Script") + "</h2>", Qt::CaseSensitive);
        destination.replace("[Script]", "<pre>" + createPythonFromModel() + "</pre>", Qt::CaseSensitive);
    }
    else
    {
        destination.remove("[Script.Label]", Qt::CaseSensitive);
        destination.remove("[Script]", Qt::CaseSensitive);
    }

    // footer
    destination.replace("[Report.Footer]", "<p id=\"footer\">" + tr("Computed by Agros2D (<a href=\"http://agros2d.org/\">http://agros2d.org/</a>)") + "</p>");

    // figures
    if (chkFigureGeometry->isChecked())
        destination.replace("[Figure.Geometry]", htmlFigure("geometry.png", tr("Geometry")), Qt::CaseSensitive);
    else
        destination.remove("[Figure.Geometry]", Qt::CaseSensitive);

    if (chkFigureMesh->isChecked())
        destination.replace("[Figure.Mesh]", htmlFigure("mesh.png", tr("Mesh")), Qt::CaseSensitive);
    else
        destination.remove("[Figure.Mesh]", Qt::CaseSensitive);

    if (chkFigureOrder->isChecked())
            destination.replace("[Figure.Order]", htmlFigure("order.png", tr("Polynomial order")), Qt::CaseSensitive);
    else
        destination.remove("[Figure.Order]", Qt::CaseSensitive);

    if (chkFigureScalarView->isChecked())
        destination.replace("[Figure.ScalarView]", htmlFigure("scalarview.png", tr("ScalarView: ") + physicFieldVariableString(Util::scene()->problemInfo()->hermes()->scalarPhysicFieldVariable())), Qt::CaseSensitive);
    else
        destination.remove("[Figure.ScalarView]", Qt::CaseSensitive);

    if (chkFigureContourView->isChecked())
        destination.replace("[Figure.ContourView]", htmlFigure("contourview.png", tr("ContourView: ") + physicFieldVariableString(Util::scene()->problemInfo()->hermes()->contourPhysicFieldVariable())), Qt::CaseSensitive);
    else
        destination.remove("[Figure.ContourView]", Qt::CaseSensitive);

    if (chkFigureVectorView->isChecked())
        destination.replace("[Figure.VectorView]", htmlFigure("vectorview.png", tr("VectorView: ") + physicFieldVariableString(Util::scene()->problemInfo()->hermes()->vectorPhysicFieldVariable())), Qt::CaseSensitive);
    else
        destination.remove("[Figure.VectorView]", Qt::CaseSensitive);

    return destination;
}