FFSM++ 1.1.0
French Forest Sector Model ++
Loading...
Searching...
No Matches
main.cpp File Reference
#include <iostream>
#include <string>
#include "anyoption.h"
#include <QApplication>
#include "Sandbox.h"
#include "MainWindow.h"
#include "ThreadManager.h"
#include "../doc/referenceManual/mainPage.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 39 of file main.cpp.

39 {
40 #ifdef __GNUC__
41 #ifndef __MINGW32__
42 // I can't use this automatic runtime error, as ADOL-C, for some reasons, has some places that explicitally create inf or nan
43 //feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); // to enable runtime error of division by zero (only in linux, not on MinGw)
44 #endif
45 #endif
46
47 cout << endl;
48 cout << "*******************************************************************" << endl;
49 cout << "*** !! Welcome to FFSM - The Forest Sector Simulator !! ***" << endl;
50 cout << "*** For info & doc: http://www.ffsm-project.org/doc ***" << endl;
51 cout << "*** Full compiled on: " << __DATE__ << " - " << __TIME__ << " ***" << endl;
52 cout << "*******************************************************************" << endl<<endl;
53
54 // Running "simple testing" that can be done at this early time
55 Sandbox TEST;
56 int debug=0;
57 TEST.basicTest(); // normally this is an empty function, used only to place temporary in-developmentr tests
58 //TEST.runSimpleTests();
59 // TEST.testIpopt();
60 //debug = TEST.testAdolc();
61 //cout << "Early debug value: " << debug << endl;
62
63
64 QDir dir;
65 QString currentDir = dir.currentPath();
66 // it's ok to leave the current directory (relative as where we are starting the application) rather than the application
67 // path (relative to where ffsm is). This influence only the command line, where the -i option is always realtive to the local
68 // position we are calling it from.
69
70
71 QString inputFileName = "";
72 QString scenarioName = "";
73
74
75 // 1. CREATE AN OBJECT
76 AnyOption *opt = new AnyOption();
77
78
79 // 2. SET PREFERENCES
80 //opt->setVerbose(); // print warnings about unknown options
81 //opt->autoUsagePrint(true); // print usage for bad options
82
83 // 3. SET THE USAGE/HELP
84 opt->addUsage( "*** FFSM - Forest Sector Simulator ***" );
85 opt->addUsage( "Usage: " );
86 opt->addUsage( "" );
87 opt->addUsage( " -h --help Prints this help " );
88 opt->addUsage( " -c --console Run in console mode (no gui, default: false) " );
89 opt->addUsage( " -i --input_file [input_file_name] Input file (relative path, default: 'data/ffsmInput.ods') " );
90 opt->addUsage( " -s --scenario [scenario_name] Scenario name (default: the first defined in the input file) " );
91 opt->addUsage( "" );
92 opt->addUsage( "Notes:");
93 opt->addUsage( " - input_file and scenario options have no effect in GUI mode;" );
94 opt->addUsage( " - the working directory is the base path relative to the input file." );
95 opt->addUsage( "" );
96 opt->addUsage( "Read installed documentation or browse it at http://www.ffsm-project.org/doc." );
97 opt->addUsage( "" );
98
99 // 4. SET THE OPTION STRINGS/CHARACTERS
100 opt->setFlag( "help", 'h' );
101 opt->setFlag( "console", 'c' );
102 opt->setOption( "input_file", 'i' );
103 opt->setOption( "scenario", 's' );
104
105 // 5. PROCESS THE COMMANDLINE
106 opt->processCommandArgs( argc, argv );
107
108 // 6. GET THE VALUES
109 if( opt->getFlag( "help" ) || opt->getFlag( 'h' ) || opt->getArgc() >0 ) {
110 opt->printUsage();
111 delete opt;
112 return EXIT_FAILURE;
113 }
114
115 if( opt->getValue( 'i' ) != NULL || opt->getValue( "input_file" ) != NULL ){
116 QString tempdata(opt->getValue( 'i' ));
117 inputFileName = currentDir + "/" + tempdata;
118 }
119 else {
120 inputFileName = currentDir + "/data/ffsmInput.ods";
121 }
122
123 if( opt->getValue( 's' ) != NULL || opt->getValue( "scenario" ) != NULL ){
124 scenarioName = opt->getValue( 's' );
125 }
126
127 if( opt->getFlag( 'c' ) || opt->getFlag( "console" ) ){
128 ThreadManager modelMainThread;
129 modelMainThread.runFromConsole(inputFileName,scenarioName);
130 }
131 else {
132 QApplication app(argc, argv);
133 MainWindow mainWin;
134 mainWin.show();
135 return app.exec();
136 }
137 delete opt;
138}
bool getFlag(const char *_option)
void setOption(const char *opt_string)
void processCommandArgs()
void setFlag(const char *opt_string)
char * getValue(const char *_option)
void printUsage()
int getArgc()
void addUsage(const char *line)
Main GUI interface.
Definition MainWindow.h:50
void basicTest()
Simple tests that doesn't require anything else (are encapsulated) and so they can be run at the begi...
Definition Sandbox.cpp:132
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
void runFromConsole(QString inputFileName_h, QString scenarioName_h)
Re-draw the map making it to fit (with the right proportions) to the widget.
Here is the call graph for this function: