main.cpp
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2012:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include <signal.h>
00022 #include <QApplication>
00023 #include <QCoreApplication>
00024 #include <QTextCodec>
00025 #include <QTranslator>
00026 #include <QString>
00027 #include <QLocale>
00028 #include <QLibraryInfo>
00029 #include <QDebug>
00030 #include <iostream>
00031 #include <stdexcept>
00032 #include "MainWindow.h"
00033 #include "HelpViewer.h"
00034 #include "../transport/dashel_plugins/dashel-plugins.h"
00035 
00036 using namespace std;
00037 
00038 void usage(const char *execName)
00039 {
00040         cout << "Usage: " << execName << " (OPTIONS|TARGET)* " << endl;
00041         cout << "  where" << endl;
00042         cout << "OPTION is one of:" << endl;
00043         cout << " -h      this help" << endl;
00044         cout << " -ar     auto memory refresh enabled by default" << endl;
00045         cout << " -doc    show documentation instead of studio" << endl;
00046         cout << "TARGET is a Dashel target (the last one is always considered)" << endl;
00047 }
00048 
00053 int main(int argc, char *argv[])
00054 {
00055         bool autoRefresh(false);
00056         bool showDoc(false);
00057         QApplication app(argc, argv);
00058         Dashel::initPlugins();
00059         
00060         // Information used by QSettings with default constructor
00061         QCoreApplication::setOrganizationName("EPFL-LSRO-Mobots");
00062         QCoreApplication::setOrganizationDomain("mobots.epfl.ch");
00063         QCoreApplication::setApplicationName("Aseba Studio");
00064 
00065         QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
00066         QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
00067         
00068         // override dashel signal handling
00069         signal(SIGTERM, SIG_DFL);
00070         signal(SIGINT, SIG_DFL);
00071         
00072         QString commandLineTarget;
00073         for (int i = 1; i < argc; ++i)
00074         {
00075                 if (argv[i][0] != '-')
00076                 {
00077                         commandLineTarget = argv[i];
00078                         break;
00079                 }
00080                 else if (argv[i][1] != 0)
00081                 {
00082                         QString cmd(&(argv[i][1]));
00083                         if (cmd == "h")
00084                         {
00085                                 usage(argv[0]);
00086                                 return 0;
00087                         }
00088                         else if (cmd == "ar")
00089                         {
00090                                 autoRefresh = true;
00091                         }
00092                         else if (cmd == "doc")
00093                         {
00094                                 showDoc = true;
00095                         }
00096                 }
00097         }
00098 
00099         // translation files are loaded in DashelTarget.cpp
00100         QTranslator qtTranslator;
00101         app.installTranslator(&qtTranslator);
00102 
00103         QTranslator translator;
00104         app.installTranslator(&translator);
00105 
00106         QTranslator compilerTranslator;
00107         app.installTranslator(&compilerTranslator);
00108 
00109         if (showDoc)
00110         {
00111                 // directly show doc browser
00112                 Aseba::HelpViewer helpViewer;
00113                 helpViewer.setLanguage(QLocale::system().name());
00114                 helpViewer.show();
00115                 return app.exec();
00116         }
00117         else
00118         {
00119                 // start normal aseba studio
00120                 try
00121                 {
00122                         QVector<QTranslator*> translators;
00123                         translators.push_back(&qtTranslator);
00124                         translators.push_back(&translator);
00125                         translators.push_back(&compilerTranslator);
00126                         Aseba::MainWindow window(translators, commandLineTarget, autoRefresh);
00127                         window.show();
00128                         return app.exec();
00129                 }
00130                 catch (std::runtime_error e)
00131                 {
00132                         std::cerr << "Program terminated with runtime error: " << e.what() << std::endl;
00133                         return -1;
00134                 }
00135         }
00136 }
00137 
00138 


aseba
Author(s): Stéphane Magnenat
autogenerated on Thu Jan 2 2014 11:17:16