Esempio n. 1
0
Sim::Sim()
    : sim::Sim(), _arena(0)
{
#if ODE == 1
    DBG("Using ODE");
    sim::ode::World *w = new sim::ode::World();

    setWorld(w);

    w->setCFM(.0001);
    w->setERP(0.8);
    w->setStepType(sim::ode::World::STEP_TYPE_QUICK);
    w->setAutoDisable(0.01, 0.01, 5, 0.);

    w->setContactApprox1(true);
    w->setContactApprox2(true);
    w->setContactBounce(0.1, 0.1);
#else
    DBG("Using Bullet");
    sim::bullet::World *w = new sim::bullet::World();
    setWorld(w);
#endif

    setTimeStep(sim::Time::fromMs(5));
    setTimeSubSteps(2);

    pauseSimulation();
    setSimulateReal(false);

    _povray = 0;

    createArena();
    createRobots();
}
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;
	    }
	}
Esempio n. 3
0
MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
{
  ui->setupUi(this);

  newDebug = NULL;
  newAgent = NULL;
  newEnvironment = NULL;
  newBeep = NULL;

  started = false;
  paused = false;

  scene = new QGraphicsScene(this);
  ui->graphicsView->setScene(scene);
  setCentralWidget(ui->graphicsView);

  //automatically trigger updates for now
  timer = new QTimer(this);
  connect(timer, SIGNAL(timeout()), this, SLOT(timeToStep()));
  timer->start(10);

  //connect menus to their corresponding slots
  connect(ui->actionStep,SIGNAL(triggered()),this,SLOT(timeToStep()));
  connect(ui->actionAgent_2, SIGNAL(triggered()), this, SLOT(createNewAgentWindow()));
  connect(ui->actionAdd_Environment, SIGNAL(triggered()), this, SLOT(createNewEnvironmentWindow()));
  connect(ui->actionStart, SIGNAL(triggered()), this, SLOT(startSimulation()));
  connect(ui->actionCreate_New_Beep, SIGNAL(triggered()), this, SLOT(createNewBeepTypeWindow()));
  connect(ui->actionPause, SIGNAL(triggered()), this, SLOT(pauseSimulation()));
  connect(ui->actionContinue, SIGNAL(triggered()), this, SLOT(unPauseSimulation()));


  /*for(int i = 5; i < 26; i++)
    for(int j = 15; j < 26; j++)
      pointTemps.push_back(std::make_pair (std::make_pair (i,j), 100));*/

  /*QGraphicsEllipseItem *tempEllipse = new QGraphicsEllipseItem();
  for(unsigned i = 0; i < 2; i++){
    Robot tempRobot = Robot();
    tempRobot.setBody(tempEllipse);
    robots.push_back(tempRobot);
  }

  for(unsigned i = 0; i<robots.size(); i++){
    robots[i].updateDrawPosition(scene);
  }*/
  reDraw();
}
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()));

}
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()));

}
Esempio n. 6
0
void Mediator::handleCommand(int index){
	
	int fd = socketManager->getConnectedFD(index);
	char messageIN[BUFFER_SIZE];
	int rd = ioStream->readLine(fd, messageIN, BUFFER_SIZE);
	if (rd > 0){
		cout << "[From Command...]\t" << messageIN  << flush;
		char* command = strtok(messageIN, "|");
		if (strcmp(command,"init") ==0){
			char* ip   = strtok(NULL, "|\n");
			int	  cmd_port  = atoi(strtok(NULL, "|\n"));
			int   data_port = atoi(strtok(NULL, "|\n"));
			int   time_port = atoi(strtok(NULL, "|\n"));
			int   info_port = atoi(strtok(NULL, "|\n"));
			initClient(ip, fd, cmd_port, data_port, time_port, info_port);
		}
		else if (strcmp(command,"putfile") ==0){
			long fileSize = 0;
			char* filename = strtok(NULL, "|");
			sscanf(strtok(NULL, "|\n"), "%d", &fileSize);
			int data_fd = clientList.getActiveClient()->data_fd;
			putfile(filename, fileSize, fd, data_fd);
		}
		else if (strcmp(command,"startSimulation") == 0){
			char* command = strtok(NULL, "|\n");
			int timePort;
			sscanf(strtok(NULL, "|\n"), "%d", &timePort);
			startSimulation(command, false);
		}
		else if (strcmp(command,"pauseSimulation") == 0){
			pauseSimulation(strtok(NULL, "|\n"));
		}
		else if (strcmp(command,"stopSimulation") == 0){
			stopSimulation(strtok(NULL, "|\n"));
		}
		else if (strcmp(command,"resumeSimulation") == 0){
			resumeSimulation(strtok(NULL, "|\n"));
		}
		else if (strcmp(command,"abortSimulation") == 0){
			abortSimulation();
		}
		else if (strcmp(command, "getResults\n") == 0){
			getResults();
		}
/*
		else if (strcmp(command, "getFileList\n") == 0){
			getFileList();
		}
*/
		else if (strcmp(command, "getFile") == 0){
			getFile(strtok(NULL, "|\n"));
		}

		else if (strcmp(command, "reconnect") == 0){
			reconnect(strtok(NULL, "\n"), fd);			
		}
		else if (strcmp(command, "sendtoSE") == 0){
			sendtoSE("From GUI : ", strtok(NULL, "|"));
		}
		else if (strcmp(command, "console") == 0){
			commandConsole(strtok(NULL, "\n"), fd);
		}
		else if (strcmp(command, "init_remote") == 0){
			initRemote(strtok(NULL, "\n"), fd);
		}
		else
			cout << "else??\n" << flush;
	}
	else{
		if (currentSession == 0){
			abortSimulation(); 
		}else{
			closeClient();
		}
	}
}
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);
 
}