main.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006-2008 by Antonello Lobianco                         *
00003  *   antonello@regmas.org                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include <iostream>
00021 #include <string>
00022 
00023 #include "anyoption.h"
00024 
00025 
00026 #include <QApplication>
00027 
00028 
00029 #include "MainWindow.h"
00030 #include "ThreadManager.h"
00031 
00032 // HTML code for the home page of the doxygen-generated documentation (Reference Manual)...
00033 #include "../doc/referenceManual/mainPage.h"
00034 
00035 using namespace std;
00036 
00037 int main(int argc, char *argv[]){
00038 
00039     cout << endl;
00040     cout << "*******************************************************************" << endl;
00041     cout << "*** !! Welcome to RegMAS - Regional Multi Agent Simulator !! ***" << endl;
00042     cout << "***        For info & doc: http://www.regmas.org/doc                 ***" << endl;
00043     cout << "***            Compiled on: " << __DATE__ << " - " << __TIME__ << "                      ***" << endl;
00044     cout << "*******************************************************************" << endl<<endl;
00045 
00046     QDir dir;
00047     QString currentDir = dir.currentPath();
00048     QString inputFileName = "";
00049     QString scenarioName = "";
00050 
00051     /* 1. CREATE AN OBJECT */
00052     AnyOption *opt = new AnyOption();
00053 
00054     /* 2. SET PREFERENCES  */
00055     //opt->setVerbose(); /* print warnings about unknown options */
00056     //opt->autoUsagePrint(true); /* print usage for bad options */
00057 
00058     /* 3. SET THE USAGE/HELP   */
00059     opt->addUsage( "*** RegMAS - Regional Multi Agent Simulator ***" );
00060     opt->addUsage( "Usage: " );
00061     opt->addUsage( "" );
00062     opt->addUsage( " -h  --help         Prints this help " );
00063     opt->addUsage( " -c  --console          Run in console mode (no gui, default: false) " );
00064     opt->addUsage( " -i  --input_file [input_file_name] Input file (relative path, default: 'data/regmasInput.ods') " );
00065     opt->addUsage( " -s  --scenario [scenario_name] Scenario name (default: the first defined in the input file) " );
00066     opt->addUsage( "" );
00067     opt->addUsage( "Notes:");
00068     opt->addUsage( "    - input_file and scenario options have no effect in GUI mode;" );
00069     opt->addUsage( "    - the working directory is the base path relative to the input file." );
00070     opt->addUsage( "" );
00071     opt->addUsage( "Read installed documentation or browse it at http://www.regmas.org/doc." );
00072     opt->addUsage( "" );
00073 
00074     /* 4. SET THE OPTION STRINGS/CHARACTERS */
00075     opt->setFlag(  "help", 'h' );
00076     opt->setFlag(  "console", 'c' );
00077     opt->setOption(  "input_file", 'i' );
00078     opt->setOption(  "scenario", 's' );
00079 
00080     /* 5. PROCESS THE COMMANDLINE */
00081     opt->processCommandArgs( argc, argv );
00082 
00083     /* 6. GET THE VALUES */
00084     if( opt->getFlag( "help" ) || opt->getFlag( 'h' ) || opt->getArgc() >0 ) {
00085         opt->printUsage();
00086         delete opt;
00087         return EXIT_FAILURE;
00088     }
00089 
00090     if( opt->getValue( 'i' ) != NULL  || opt->getValue( "input_file" ) != NULL  ){
00091             QString tempdata(opt->getValue( 'i' ));
00092             inputFileName = currentDir + "/" + tempdata;
00093     }
00094     else {
00095             inputFileName = currentDir + "/data/regmasInput.ods";
00096     }
00097 
00098     if( opt->getValue( 's' ) != NULL  || opt->getValue( "scenario" ) != NULL  ){
00099             scenarioName = opt->getValue( 's' );
00100     }
00101 
00102     if( opt->getFlag( 'c' ) || opt->getFlag( "console" ) ){
00103         ThreadManager  modelMainThread;
00104         modelMainThread.runFromConsole(inputFileName,scenarioName);
00105     }
00106     else {
00107         QApplication app(argc, argv);
00108         MainWindow mainWin;
00109         mainWin.show();
00110         return app.exec();
00111     }
00112     delete opt;
00113 }