示例#1
0
文件: main.cpp 项目: LeiDai/agros2d
int main(int argc, char *argv[])
{
    try
    {
        // command line info
        TCLAP::CmdLine cmd("Agros2D solver", ' ', versionString().toStdString());

        TCLAP::SwitchArg logArg("l", "enable-log", "Enable log", false);
        TCLAP::SwitchArg remoteArg("r", "remote-server", "Run remote server", false);
        TCLAP::ValueArg<std::string> problemArg("p", "problem", "Solve problem", false, "", "string");
        TCLAP::ValueArg<std::string> scriptArg("s", "script", "Solve script", false, "", "string");
        TCLAP::ValueArg<std::string> testArg("t", "test", "Run tests", false, "list", "string");

        cmd.add(logArg);
        cmd.add(remoteArg);
        cmd.add(problemArg);
        cmd.add(scriptArg);
        cmd.add(testArg);

        // parse the argv array.
        cmd.parse(argc, argv);

        CleanExit cleanExit;
        AgrosSolver a(argc, argv);

        // enable log
        a.setEnableLog(logArg.getValue());

        // run remote server
        if (remoteArg.getValue())
        {
            a.runRemoteServer();
            return a.exec();
        }

        if (!problemArg.getValue().empty())
        {
            if (QFile::exists(QString::fromStdString(problemArg.getValue())))
            {
                QFileInfo info(QString::fromStdString(problemArg.getValue()));
                if (info.suffix() == "a2d")
                {
                    a.setFileName(QString::fromStdString(problemArg.getValue()));
                    QTimer::singleShot(0, &a, SLOT(solveProblem()));
                    return a.exec();
                }
                else
                {
                    std::cout << QObject::tr("Unknown suffix.").toStdString() << std::endl;
                    return 1;
                }
            }
        }
        else if (!scriptArg.getValue().empty())
        {
            if (QFile::exists(QString::fromStdString(scriptArg.getValue())))
            {
                QFileInfo info(QString::fromStdString(scriptArg.getValue()));
                if (info.suffix() == "py")
                {
                    a.setFileName(QString::fromStdString(scriptArg.getValue()));
                    QTimer::singleShot(0, &a, SLOT(runScript()));
                    return a.exec();
                }
                else
                {
                    std::cout << QObject::tr("Unknown suffix.").toStdString() << std::endl;
                    return 1;
                }
            }
        }
        else if (!testArg.getValue().empty())
        {
            if (QString::fromStdString(testArg.getValue()) == "list")
            {
                QTimer::singleShot(0, &a, SLOT(printTestSuites()));
            }
            else
            {
                a.setScriptSuite(QString::fromStdString(testArg.getValue()));
                QTimer::singleShot(0, &a, SLOT(runSuite()));
            }
            return a.exec();
        }
        else
        {
            return 1;
        }
    }
    catch (TCLAP::ArgException &e)
    {
        std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
        return 1;
    }
}
示例#2
0
文件: main.cpp 项目: fmach/agros2d
int main(int argc, char *argv[])
{
    try
    {
        // command line info
        TCLAP::CmdLine cmd("Agros2D", ' ', versionString().toStdString());

        TCLAP::SwitchArg remoteArg("r", "remote-server", "Run remote server", false);
        TCLAP::ValueArg<std::string> problemArg("p", "problem", "Open problem", false, "", "string");
        TCLAP::ValueArg<std::string> scriptArg("s", "script", "Open script", false, "", "string");
        TCLAP::SwitchArg executeArg("x", "execute", "Execute problem or script", false);

        cmd.add(remoteArg);
        cmd.add(problemArg);
        cmd.add(scriptArg);
        cmd.add(executeArg);

        // parse the argv array.
        cmd.parse(argc, argv);

        CleanExit cleanExit;
        AgrosApplication a(argc, argv);
        // setting gui style
        setGUIStyle(Agros2D::configComputer()->value(Config::Config_GUIStyle).toString());
        // language
        setLocale(Agros2D::configComputer()->value(Config::Config_Locale).toString());
        a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));

        // init indicator (ubuntu - unity, windows - overlay icon, macosx - ???)
        Indicator::init();

        MainWindow w;

        // run remote server
        if (remoteArg.getValue())
        {
            a.runRemoteServer();
        }

        if (!problemArg.getValue().empty())
        {
            if (QFile::exists(QString::fromStdString(problemArg.getValue())))
            {
                QFileInfo info(QString::fromStdString(problemArg.getValue()));
                if (info.suffix() == "a2d")
                {
                    w.setStartupProblemFilename(QString::fromStdString(problemArg.getValue()));

                    if (executeArg.getValue())
                        w.setStartupExecute(true);
                }
                else
                {
                    std::cout << QObject::tr("Unknown suffix.").toStdString() << std::endl;
                }
            }
        }
        else if (!scriptArg.getValue().empty())
        {
            if (QFile::exists(QString::fromStdString(scriptArg.getValue())))
            {
                QFileInfo info(QString::fromStdString(scriptArg.getValue()));
                if (info.suffix() == "py")
                {
                    w.setStartupScriptFilename(QString::fromStdString(scriptArg.getValue()));

                    if (executeArg.getValue())
                        w.setStartupExecute(true);
                }
                else
                {
                    std::cout << QObject::tr("Unknown suffix.").toStdString() << std::endl;
                }
            }
        }

        w.show();

        return a.exec();
    }
    catch (TCLAP::ArgException &e)
    {
        std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
        return 1;
    }    
}