コード例 #1
0
ファイル: test.cpp プロジェクト: MogeiWang/nemosim
void
testNonContigousNeuronIndices(backend_t backend, unsigned n0, unsigned nstep)
{
	unsigned ncount = 1000;
	bool stdp = false;

	boost::scoped_ptr<nemo::Network> net0(createRing(ncount, 0, false, nstep));
	boost::scoped_ptr<nemo::Network> net1(createRing(ncount, n0, false, nstep));

	std::vector<unsigned> cycles0, cycles1;
	std::vector<unsigned> fired0, fired1;

	unsigned seconds = 2;
	nemo::Configuration conf = configuration(false, 1024, backend);

	runSimulation(net0.get(), conf, seconds, &cycles0, &fired0, stdp, std::vector<unsigned>(1, 0));
	runSimulation(net1.get(), conf, seconds, &cycles1, &fired1, stdp, std::vector<unsigned>(1, n0));

	/* The results should be the same, except firing indices
	 * should have the same offset. */
	BOOST_REQUIRE_EQUAL(cycles0.size(), cycles1.size());
	BOOST_REQUIRE_EQUAL(fired0.size(), seconds*ncount);
	BOOST_REQUIRE_EQUAL(fired1.size(), seconds*ncount);

	for(unsigned i = 0; i < cycles0.size(); ++i) {
		BOOST_REQUIRE_EQUAL(cycles0.at(i), cycles1.at(i));
		BOOST_REQUIRE_EQUAL(fired0.at(i), fired1.at(i) - n0);
	}

	//! \todo also add ring networks with different steps.
}
コード例 #2
0
ファイル: main.c プロジェクト: maddog0/Parallel-Project
int main(int argc, char** argv){
	int worldsize = 500;
	int players = 500;
	int numSteps = 10000;

	if (argc > 1){
		worldsize = (int)strtol(argv[1], NULL, 10);
	}
	if (argc > 2){
		players = (int)strtol(argv[2], NULL, 10);
		//check that the number of players can't exceed the size of the world 
		if (players > worldsize*worldsize){
			players = worldsize*worldsize;
		}
	}
	if (argc > 3){
		numSteps = (int)strtol(argv[3], NULL, 10);
	}
	int* world = calloc(worldsize*worldsize, sizeof(int));
	player* people;
	people = malloc(sizeof(player) * players);
	
	setupWorld(world, worldsize, people, players);
	runSimulation(world, worldsize, people, players, numSteps);
	

	free(world);
	free(people);
}
コード例 #3
0
ファイル: test.cpp プロジェクト: MogeiWang/nemosim
/* Run one simulation after another and make sure their firing output match
 * exactly */
void
compareSimulations(
		const nemo::Network* net1,
		const nemo::Configuration& conf1,
		const nemo::Network* net2,
		const nemo::Configuration& conf2,
		unsigned duration,
		bool stdp)
{
	std::cout << "Comparing " << conf1 << "\n"
	          << "      and " << conf2 << "\n";
	std::vector<unsigned> cycles1, cycles2, nidx1, nidx2;
	runSimulation(net1, conf1, duration, &cycles1, &nidx1, stdp);
	runSimulation(net2, conf2, duration, &cycles2, &nidx2, stdp);
	compareSimulationResults(cycles1, nidx1, cycles2, nidx2);
}
コード例 #4
0
int main(int argc, char **argv)
{
	srand(time(NULL));
	
	runSimulation();
	
	return 0;
}
コード例 #5
0
void IslandControl::simulate()
{
    randSeed = time(NULL);
    srand(randSeed);
    while(numberOfSims > 0)
    {
        resetSimulation();
        runSimulation();
        numberOfSims--;
    }
}
コード例 #6
0
ファイル: GLWindow.cpp プロジェクト: burakertekin/ClothSim
GLWindow::GLWindow(const QGLFormat _format, QWidget *_parent ) : QGLWidget( _format, _parent )

{
  m_rotate=false;
  // mouse rotation values set to 0
  m_spinXFace=0;
  m_spinYFace=0;
  //timer value set to 1
  m_timer_value = 1;
  runSimulation();
}
コード例 #7
0
ファイル: main.c プロジェクト: SamStudio8/Shipping
/**
 * Requests user input and calls the simulator.
 * 
 * @param argc
 * @param argv
 * @return Exit Code
 */
int main(int argc, char** argv) {
    char infilename[50];
    char outfilename[50];
    double duration, tick;
    FILE *inputfr = NULL;
    FILE *outputfr = NULL;

    time_t ts = (time_t) malloc(sizeof(time_t));
    
    ship *head = malloc(sizeof(ship));
    head = NULL;

    while((inputfr = fopen(infilename, "r")) == NULL){
        printf("Input Filename: ");
        scanf("%s", &infilename);
    }
    
    processInput(inputfr, &head, &ts);
    
    if(head == NULL){
        printf("No ships were detected in your input file!");
        exit(1);
    }
    
    while((outputfr = fopen(outfilename, "w")) == NULL){
        printf("Output Filename: ");
        scanf("%s", &outfilename);
    }

    printf("Simulation Duration (Minutes): ");
    scanf("%lf", &duration);
        
    while(fmod(duration, tick) != 0){
        printf("Simulation Tick (Minutes, Factor of Duration): ");
        scanf("%lf", &tick);
    }
    
    fprintf(outputfr, "Ship Simulation Log (Sam Nicholls)\n"
            "Input File Path: %s\n"
            "Simulation Duration: %lf\n"
            "Simulation Timestep: %lf\n"
            "--------------------------------------", 
            infilename, duration, tick);
      
    //Execute simulation.
    runSimulation(outputfr, &head, ts, duration, tick);
    
    //Print and log summary.
    listShips(outputfr, head);

    return (EXIT_SUCCESS);
}
コード例 #8
0
float
NoAssociationSimulator::computePValue(float auc)
{
	if( m_numSamples == 0 || ( m_simulatedAuc.size( ) != m_numSamples ) )
	{
		runSimulation( );
	}

	std::vector<float>::iterator firstGreaterElement;
	firstGreaterElement = std::upper_bound( m_simulatedAuc.begin( ), m_simulatedAuc.end( ), auc );
	unsigned int numGreater = m_simulatedAuc.size( ) - ( firstGreaterElement - m_simulatedAuc.begin( ) );

	return numGreater / ( (float) m_simulatedAuc.size( ) );
}
コード例 #9
0
void SimulationMainWindow1D::createButtons(){
  
   QPushButton *runButton = new QPushButton("&Run", this);
   runButton->setGeometry(QRect(QPoint(10, 40), QSize(80, 30)));
   connect(runButton, SIGNAL(released()), this, SLOT(runSimulation()));
  
   QPushButton *pauseButton = new QPushButton("&Pause", this);
   pauseButton->setGeometry(QRect(QPoint(10, 80), QSize(80, 30)));
   connect(pauseButton, SIGNAL(clicked()), this, SLOT(pauseSimulation()));
  
   QPushButton *restartButton = new QPushButton("&Restart", this);
   restartButton->setGeometry(QRect(QPoint(10, 120), QSize(80, 30)));
   connect(restartButton, SIGNAL(clicked()), this, SLOT(restartSimulation()));

}
コード例 #10
0
ファイル: simul.cpp プロジェクト: w1ckedsick/ToyMachineSim
int main(int argc, char *argv[]){
    bool DEBUG = checkForOption(argv, argv + argc, "debug");
    bool LOG_EN = checkForOption(argv, argv + argc, "log");

    Memory mem = Memory();
    if (parseInput(mem, DEBUG)){
        std::cout << "There were errors during preparation process, simulation aborted" << std::endl;
        return 1;
    }
    runSimulation(mem, LOG_EN);
    if (DEBUG)
        mem.memoryDump();

    return 0;
}
コード例 #11
0
/**
 * @brief Run Solver Project
 *
 */
void MainWindow::on_actionRun_Project_triggered()
{
    if (!_isMultizoneProject)
    {
        if (_userConfigValuesSolver.isEmpty())
            return;
        // Checking if RESTART_SOL is enabled
       if ( (_userConfigValuesSolver.contains("RESTART_SOL")) &&
            (QString::compare(_userConfigValuesSolver.value("RESTART_SOL"),"NO") != StrEqual) )
        {
                _userConfigValuesSolver.insert("RESTART_SOL","NO");
                _status_NeedToBeSaved = true;
        }
    }
    runSimulation();
}
コード例 #12
0
ファイル: Main.cpp プロジェクト: kevinzhang2012/AI
int main(int argc, char *argv[]) {	
	char gridFileName[80];
	if (argc == 3){
		strcpy(gridFileName, argv[1]);
        
		if (!strcmp(argv[2], "EUCLIDEAN")){
			HEURISTIC = EUCLIDEAN;			
			cout << "Heuristics = EUCLIDEAN" << endl;
		}
		else if (!strcmp(argv[2], "MANHATTAN")){
			HEURISTIC = MANHATTAN;
			cout << "Heuristics = MANHATTAN" << endl;
		}	
	} else {
		cout << "missing parameters:  gridworld heuristic" << endl;
	}
	
	int graphDriver = 0,graphMode = 0;
 	
	//initgraph(&graphDriver, &graphMode, "", 1440, 900); // Start Window
 	//initgraph(&graphDriver, &graphMode, "", 1280, 1024); // Start Window
	
   initgraph(&graphDriver, &graphMode, "", 1360, 768); // Start Window - LAPTOP SCREEN
	//initgraph(&graphDriver, &graphMode, "", 1920, 1080); // Start Window - Full-HD
	
	BACKGROUND_COLOUR = WHITE;
	LINE_COLOUR = GREEN;
	
	GRIDWORLD_ROWS = 0; //7; //6; //duplicated in GridWorld
   GRIDWORLD_COLS = 0; //15;//13; //duplicated in GridWorld
	SHOW_MAP_DETAILS=false;

   try{
		runSimulation(gridFileName);
   }
	
   catch(...){
    	cout << "Exception caught!\n";
   }
	
	cout << "----<< The End.>>----" << endl;
	
	return 0;
} 
コード例 #13
0
ファイル: cs2123p4.c プロジェクト: gopoomemsl/Portfolio
/********************************* main ****************************************
int main (int argc, char *argv[])
Purpose:
	This the main functions of the program, it calls the command switch 
	processing function to register the alternative choosen and wether 
	verbose mode has been choosen or not, it creates the LinkedList and 
	Simulation, calls the appropriate functions to populate both, then 
	calls the function to run the simulation and to free all of our allocs.
Parameters:
	I	int argc		Number of command line argument.
	I	char *argv[]	Command line arguments.
Returns:
	Functionally:
		Integer representing the success of the operation or error encountered.
		0 - normal
		900 - command line argument syntax error
		903 - algorithm error (see message for details)
		503 - bad input
Notes: 
*******************************************************************************/
int main(int argc, char *argv[])
{
	//command switches
	int bVerbose;
	char cRunType;
	processCommandSwitches(argc, argv, &bVerbose, &cRunType);
	
	//create the simulation
	LinkedList list;
	Simulation sim;
	list = newListFromInput();
	sim = newSim(list, bVerbose, cRunType);

	//run the simulation and terminate
	runSimulation(sim, TIME_LIMIT);
	freeSim(sim);
	fclose(pInputFile);
	return 0;	
}
コード例 #14
0
void * buttonEvents(void *vargp){
    int x=-1,y=-1;
    XEvent event;
    fu_arg *args = (fu_arg *) vargp;

    XGrabPointer(args->ui_params->dis, args->ui_params->win, False, ButtonPressMask, GrabModeAsync,
         GrabModeAsync, None, None, CurrentTime);
	
    XSelectInput(args->ui_params->dis, args->ui_params->win, ButtonPressMask | ButtonReleaseMask);
    /*sleep para esperar que a janela principal seja desenhada.*/
    sleep(5);
    while(*(args->ui_params->button_event)){
    XNextEvent(args->ui_params->dis,&event);
	    switch(event.type){
	    case ButtonPress:
	        switch(event.xbutton.button){
	        	case Button1:
	        		x=event.xbutton.x;
	        		y=event.xbutton.y;
	        		if(x > 10 && x < 110 && y > 90 && y < 120){
			        	if(play)
			        		pauseSimulation(args ->ui_params);
			        	else
			        		runSimulation(args ->ui_params);
			        }
			        if(x > 10 && x < 110 && y > 140 && y < 170){
			        	pauseSimulation(args -> ui_params);
						printf("\e[H\e[2J");
			        	pushMemoryToFile(getFile("w"), &(*args->aux), args->insertionID);
						printf("Done!!");
						printf("\n\n\n");
						sleep(2);
						/*runSimulation(args->ui_params);*/
			        }
	        	break;
	        }
	        break;
	    default:
	        break;
	    }
	}
コード例 #15
0
void Simulation::run() {
	int userChoice;
	while (userChoice = menu.displayMenu(MAIN_MENU)) {
		switch (userChoice) {
		case 1: // Run with current options
			loadSimulation();
			runSimulation();
		case 2: // View current options
			displayCurrentOptions();
			break;
		case 3: // Change current options
			changeOptions();
			break;
		case 4: // Randomize Options
			randomizeOptions();	
			break;
		default:
			return;
		}	
	}
}
コード例 #16
0
void SimulationMainWindow2D::createActions(){

   exitAct = new QAction(tr("E&xit"), this);
   exitAct->setShortcuts(QKeySequence::Quit);
   exitAct->setStatusTip(tr("Exit the application"));
   connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

   aboutAct = new QAction(tr("&About"), this);
   aboutAct->setStatusTip(tr("Show the application's About box"));
   connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

   aboutQtAct = new QAction(tr("About &Qt"), this);
   aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
   connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
   connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(aboutQt()));

   alignmentGroup = new QActionGroup(this);
   //alignmentGroup->addAction(leftAlignAct);
   //alignmentGroup->addAction(rightAlignAct);
   //alignmentGroup->addAction(justifyAct);
   //alignmentGroup->addAction(centerAct);
   //leftAlignAct->setChecked(true);

   runAct = new QAction(tr("&Run"), this);
   runAct->setShortcut(tr("Ctrl+Alt+R"));
   runAct->setStatusTip(tr("Running the simulation"));
   connect(runAct, SIGNAL(triggered()), this, SLOT(runSimulation()));

   pauseAct = new QAction(tr("&Pause"), this);
   pauseAct->setShortcut(tr("Ctrl+Alt+P"));
   pauseAct->setStatusTip(tr("Pause the simulation"));
   connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseSimulation()));

   restartAct = new QAction(tr("&Restart"), this);
   restartAct->setShortcut(tr("Ctrl+Alt+N"));
   restartAct->setStatusTip(tr("Restart the simulation"));
   connect(restartAct, SIGNAL(triggered()), this, SLOT(restartSimulation()));

}
コード例 #17
0
ファイル: main.cpp プロジェクト: benbasha/assigment1
int main() {

    CyberDNS cyberDNS;

    runSimulation(cyberDNS);
}
コード例 #18
0
void SimulationMainWindow1D::createActions(){
  
   exitAct = new QAction(tr("E&xit"), this);
   exitAct->setShortcuts(QKeySequence::Quit);
   exitAct->setStatusTip(tr("Exit the application"));
   connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
  
   aboutAct = new QAction(tr("&About"), this);
   aboutAct->setStatusTip(tr("Show the application's About box"));
   connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
  
   aboutQtAct = new QAction(tr("About &Qt"), this);
   aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
   connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
   connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(aboutQt()));

   // Simulation menu actions 
   runAct = new QAction(tr("&Run"), this);
   runAct->setShortcut(tr("Ctrl+Alt+R"));
   runAct->setStatusTip(tr("Running the simulation"));
   connect(runAct, SIGNAL(triggered()), this, SLOT(runSimulation()));
  
   pauseAct = new QAction(tr("&Pause"), this);
   pauseAct->setShortcut(tr("Ctrl+Alt+P"));
   pauseAct->setStatusTip(tr("Pause the simulation"));
   connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseSimulation()));
  
   restartAct = new QAction(tr("&Restart"), this);
   restartAct->setShortcut(tr("Ctrl+Alt+N"));
   restartAct->setStatusTip(tr("Restart the simulation"));
   connect(restartAct, SIGNAL(triggered()), this, SLOT(restartSimulation()));
  
   // Input manu actions
   gridSizeAct = new QAction(tr("&Grid Size"), this);
   connect(gridSizeAct, SIGNAL(triggered()), this, SLOT(setGridSize()));
  
   toleranceAct = new QAction(tr("&Error Tolerance"), this);
   connect(toleranceAct, SIGNAL(triggered()), this, SLOT(setTolerance()));

   delaySecAct = new QAction(tr("&Animation Delay"), this);
   connect(delaySecAct, SIGNAL(triggered()), this, SLOT(setDelaySec()));
  
   realizationTimeStepAct = new QAction(tr("&Realization Time Step"), this);
   connect(realizationTimeStepAct, SIGNAL(triggered()),
           this, SLOT(setRealizationTimeStep()));
  
   // Setting the initial condition
   setICSinAct = new QAction(tr("&Sin"), this);
   setICSinAct->setCheckable(true);
   connect(setICSinAct, SIGNAL(triggered()), this, SLOT(setICSin()));

   setICStepAct = new QAction(tr("&Step"), this);
   setICStepAct->setCheckable(true);
   connect(setICStepAct, SIGNAL(triggered()), this, SLOT(setICStep()));

   setICRndNoiseAct = new QAction(tr("&Random Noise"), this);
   setICRndNoiseAct->setCheckable(true);
   connect(setICRndNoiseAct, SIGNAL(triggered()), this, SLOT(setICRndNoise()));

   icGroup = new QActionGroup(this);
   icGroup->addAction(setICSinAct);
   icGroup->addAction(setICStepAct);
   icGroup->addAction(setICRndNoiseAct);
   setICSinAct->setChecked(true);
  
   // Setting main solver
   setLaxFriedrichsAct = new QAction(tr("Lax-FriedRichs Scheme"), this);
   setLaxFriedrichsAct->setCheckable(true);
   connect(setLaxFriedrichsAct, SIGNAL(triggered()), this,
            SLOT(setLaxFriedrichsScheme()));

   setRK4Act = new QAction(tr("RK4 Scheme"), this);
   setRK4Act->setCheckable(true);
   connect(setRK4Act, SIGNAL(triggered()), this,SLOT(setRK4Scheme()));

   setMacCormackAct = new QAction(tr("MacCormack Scheme"), this);
   setMacCormackAct->setCheckable(true);
   connect(setMacCormackAct, SIGNAL(triggered()), this,
            SLOT(setMacCormackScheme()));

   setForwardEulerAct = new QAction(tr("Forward Euler Scheme"), this);
   setForwardEulerAct->setCheckable(true);
   connect(setForwardEulerAct, SIGNAL(triggered()), this,
            SLOT(setForwardEulerScheme()));
  
   setKurganovTadmor2000Act = new QAction(tr("Kurganov-Tadmor Scheme"), this);
   setKurganovTadmor2000Act->setCheckable(true);
   connect(setKurganovTadmor2000Act, SIGNAL(triggered()), this,
            SLOT(setKurganovTadmor2000Scheme()));

   setRK4KurganovTadmor2000Act = 
           new QAction(tr("RK4 Kurganov-Tadmor Scheme"), this);
   setRK4KurganovTadmor2000Act->setCheckable(true);
   connect(setRK4KurganovTadmor2000Act, SIGNAL(triggered()), this,
            SLOT(setRK4KurganovTadmor2000Scheme()));

   setKurganovTadmor2ndOrder2000Act = 
           new QAction(tr("2nd Order Kurganov-Tadmor Scheme"), this);
   setKurganovTadmor2ndOrder2000Act->setCheckable(true);
   connect(setKurganovTadmor2ndOrder2000Act, SIGNAL(triggered()), this,
            SLOT(setKurganovTadmor2ndOrder2000Scheme()));
 
   solverGroup = new QActionGroup(this);
   solverGroup->addAction(setMacCormackAct);
   solverGroup->addAction(setForwardEulerAct);
   solverGroup->addAction(setLaxFriedrichsAct);
   solverGroup->addAction(setKurganovTadmor2000Act);
   solverGroup->addAction(setRK4KurganovTadmor2000Act);
   solverGroup->addAction(setKurganovTadmor2ndOrder2000Act);
   solverGroup->addAction(setRK4Act);
   setRK4Act->setChecked(true);
 
   // Setting flux solver
   setMUSCLSAct = new QAction(tr("MUSCL Scheme"), this);
   setMUSCLSAct->setCheckable(true);
   connect(setMUSCLSAct, SIGNAL(triggered()), this, SLOT(setMUSCLSScheme()));

   setLinearReconstructionAct = 
             new QAction(tr("Linear Reconstruction Scheme"), this);
   setLinearReconstructionAct->setCheckable(true);
   connect(setLinearReconstructionAct, SIGNAL(triggered()), this,
             SLOT(setLinearReconstructionScheme()));

   setPiecewiseParabolicReconstructionAct = 
             new QAction(tr("Piecewise Parabolic Reconstruction Scheme"), this);
   setPiecewiseParabolicReconstructionAct->setCheckable(true);
   connect(setPiecewiseParabolicReconstructionAct, SIGNAL(triggered()), this,
             SLOT(setPiecewiseParabolicReconstructionScheme()));

   fluxGroup = new QActionGroup(this);
   fluxGroup->addAction(setMUSCLSAct);
   fluxGroup->addAction(setPiecewiseParabolicReconstructionAct);
   fluxGroup->addAction(setLinearReconstructionAct);
   setLinearReconstructionAct->setChecked(true);
 
}
コード例 #19
0
ファイル: MainWindow.cpp プロジェクト: Rahjou/OpenStudio
 void MainWindow::filesAddCheckedToQueue()
 {
   runSimulation();
 }
コード例 #20
0
ファイル: main.c プロジェクト: kroq-gar78/BigGraphAnalysis
int main(int argc, char **argv) {

    // define defaults
    arguments.outfile = "";
    arguments.directed = false;
    arguments.action = 0;
    arguments.type = 0;
    arguments.infectiousProbability = -1;
    arguments.contactChance = -1;
    arguments.kVal = -1;
    arguments.infectiousPeriod = -1;
    arguments.simulDuration = -1;
    arguments.weighted = false;

    //printf("%c %c %f %f %d %d %d", arguments.action, arguments.type, arguments.infectiousProbability,  arguments.contactChance, arguments.kVal, arguments.infectiousPeriod, arguments.simulDuration);

    argp_parse(&argp, argc, argv, 0, 0, &arguments);

    // TODO: see how to use argp to do this
	/*if (argc != 2) {
		fprintf(stderr, "Usage: %s <graphFile>\n", argv[0]);
		fprintf(stderr, "<graphFile>: Name of graph to test\n");
		exit(1);
	}*/

	clock_t t1, t2;
	t1 = clock();

    readGraph(arguments.graph_path, arguments.directed, arguments.weighted);

	t1 = clock() - t1; // Done reading
	t2 = clock();

    char *temp = (char *)malloc(strlen(arguments.graph_path)+1);
	strcpy(temp, arguments.graph_path);

	char *tok = strtok(temp, "/");

	if ((tok = strtok(NULL, "/")) != NULL) {
		tok = strtok(tok, ".");
	} else {
		tok = strtok((char *)arguments.graph_path, ".");
	}

	char choice = arguments.action;
    if (choice == 0) {
        printf("[a]nalyze graph or [r]un simulation: ");
        scanf("%c", &choice);
    }

	if (choice == 'a')
		graphStats(tok);
	else
		runSimulation(tok);

	free(temp);
	free(graph);

	t2 = clock() - t2; // Done processing

	printf("\nGraph Read Runtime: %lu clicks (%.3f seconds)\n", t1, (((float)t1)/CLOCKS_PER_SEC));
	printf("Graph Process Runtime: %lu clicks (%.3f seconds)\n", t2, (((float)t2)/CLOCKS_PER_SEC));
	printf("Total Runtime: %lu clicks (%.3f seconds)\n", t1+t2, (((float)t1+t2)/CLOCKS_PER_SEC));

	return 0;
}
コード例 #21
0
DMMainWindow::DMMainWindow(QWidget * parent) : QMainWindow(parent), ui(new Ui::DMMainWindow)
{
	// qt init
	Q_INIT_RESOURCE(icons);
	ui->setupUi(this);
	this->setParent(parent);

	// logger init
	log_updater = new GuiLogSink();
	connect(log_updater, SIGNAL(newLogLine(QString)), SLOT(newLogLine(QString)), Qt::QueuedConnection);
#if defined DEBUG || _DEBUG
	DM::Log::init(log_updater,DM::Debug);
#else
	DM::Log::init(log_updater,DM::Standard);
#endif
	// add log export to file
	QString logfilepath = QDir::tempPath() + "/dynamind" 
		+ QDateTime::currentDateTime().toString("_yyMMdd_hhmmss_zzz")+".log";
	if(QFile::exists(logfilepath))
		QFile::remove(logfilepath);

	outputFile = new ofstream(logfilepath.toStdString().c_str());
	DM::Log::addLogSink(new DM::OStreamLogSink(*outputFile));
	DM::Logger() << "logfile: " << logfilepath;

	// init python env
	DM::PythonEnv *env = DM::PythonEnv::getInstance();
	env->addPythonPath(QApplication::applicationDirPath().toStdString());
	env->addOverWriteStdCout();

	// init simulation, we only use one instance
	this->simulation = new GUISimulation(parent, ui->tabWidget_4);
	simulationThread = NULL;
	simulationThreadWrapper = NULL;

	this->simulation->registerModulesFromDefaultLocation();
	this->simulation->registerModulesFromSettings();
	createModuleListView();

	connect( ui->actionRun, SIGNAL( triggered() ), this, SLOT( runSimulation() ), Qt::DirectConnection );
	connect( ui->actionPreferences, SIGNAL ( triggered() ), this, SLOT(preferences() ), Qt::DirectConnection );
	connect(ui->actionSave, SIGNAL(triggered()), this , SLOT(saveSimulation()), Qt::DirectConnection);
	connect(ui->actionSaveAs, SIGNAL(triggered()), this , SLOT(saveAsSimulation()), Qt::DirectConnection);
	connect(ui->actionOpen, SIGNAL(triggered()), this , SLOT(loadSimulation()), Qt::DirectConnection);
	connect(ui->actionNew, SIGNAL(triggered()), this , SLOT(clearSimulation()), Qt::DirectConnection);
	connect(ui->actionReload_Modules, SIGNAL(triggered()), this , SLOT(ReloadModules()), Qt::DirectConnection);
	connect(ui->actionUpdate, SIGNAL(triggered()), this , SLOT(updateSimulation()), Qt::DirectConnection);
	connect(ui->actionReset, SIGNAL(triggered()), this , SLOT(resetSimulation()), Qt::DirectConnection);
	connect(ui->actionCancel, SIGNAL(triggered()), this, SLOT(cancelSimulation()), Qt::DirectConnection);
	connect(ui->actionCancel, SIGNAL(triggered()), this, SLOT(cancelSimulation()), Qt::DirectConnection);
	connect(ui->actionShow_Help, SIGNAL(triggered()), this, SLOT(showHelp()), Qt::DirectConnection);

	QStringList args = QCoreApplication::arguments();
	if (args.size() == 2) {
		this->clearSimulation();
		this->getSimulation()->currentDocument = args[1];
		simulation->loadSimulation(args[1].toStdString());
	}

	ui->actionCancel->setEnabled(false);

	// load from qsettings
	QSettings settings;
	DM::DBConnectorConfig cfg = DM::DBConnector::getInstance()->getConfig();
	qulonglong v = settings.value("cacheBlockwritingSize", -1).toULongLong();
	if (v != (qulonglong)-1)
		cfg.cacheBlockwritingSize = v;

	v = settings.value("queryStackSize", -1).toULongLong();
	if (v != (qulonglong)-1)
		cfg.queryStackSize = v;

	int i = settings.value("peterDatastream", -1).toInt();
	if (i != -1)
		cfg.peterDatastream = (bool)i;
}