void cbGraphView::contentsMouseMoveEvent(QMouseEvent *e) { double x,y,dist; int xi,yi; xi=(int)(e->x()/(simulator->labCanvasWidth/(double)GRIDSIZE)); yi=(int)(e->y()/(simulator->labCanvasHeight/(double)GRIDSIZE)); if(xi>=0 && xi < GRIDSIZE && yi >=0 && yi < GRIDSIZE) { x=(xi+0.5)*simulator->Lab()->Width()/GRIDSIZE; y=(GRIDSIZE-yi-0.5)*simulator->Lab()->Height()/GRIDSIZE; dist = simulator->distGrid[xi][yi]; if(xi<GRIDSIZE/2) { distLabel->setPos(e->x()+10,e->y()); } else { distLabel->setPos(e->x()-200,e->y()); } distLabel->setText(QString("(%1,%2) -> dist=%3").arg(x).arg(y).arg(dist)); } else { distLabel->setText("Out of bounds"); } scene()->update(); }
/* * This program accepts the following command line options * -lab string: name of file with lab description (default, stdin); * -grid string: name of file with start position grid (default, stdin); * -log string: name of log file (default, server.log); * -nc real: compass noise coeficient (default, 0.0); * -nb real: beacon noise coeficient (default, 0.0); * -ni real: infrared noise coeficient (default, 0.0); * -nm real: motors noise coeficient (default, 0.0); * -st integer: simulation time, in number of cycle time units (default, 3000); * -ct integer: cycle time, in miliseconds (default, 75). */ int main(int argc, char *argv[]) { /* Copyright and wellcome message */ printf(" CiberRato 2014 Simulator\n Copyright (C) 2001-2014 Universidade de Aveiro\n"); fflush(stdout); /* extract option values */ char *labFilename = 0; char *gridFilename = 0; char *paramFilename = 0; char *logFilename = 0; int port = 6000; unsigned int timeout = 0; bool nogui = false; bool showGraph=false; int showGraphId=0; //cout << "Parse command line (First Pass) ..." int p=1; while (p < argc) { if (strcmp(argv[p], "-lab") == 0) { if (p+1 < argc) { labFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-grid") == 0) { if (p+1 < argc) { gridFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-log") == 0) { if (p+1 < argc) { logFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-param") == 0) { if (p+1 < argc) { paramFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-port") == 0) { if (p+1 < argc) { sscanf(argv[p+1], "%d", &port); p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-gps") == 0) { // wait until second pass of command line parsing p+=1; } else if (strcmp(argv[p], "-showactions") == 0) { // wait until second pass of command line parsing p+=1; } else if (strcmp(argv[p], "-showgraph") == 0) { if (p+1 < argc) { showGraph=true; sscanf(argv[p+1], "%d", &showGraphId); p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-nogui") == 0) { // wait until second pass of command line parsing p+=1; } else if (strcmp(argv[p], "-sync") == 0) { // wait until second pass of command line parsing if (p+1 < argc) { sscanf(argv[p+1], "%u", &timeout); p+=2; } else { p+=1; } } else { CommandLineError(); } } /* change parameteres object */ if (paramFilename) // a parameters file is given simulator.changeParameters(paramFilename); //cout << "Parse command line (Second Pass) ..." // The second pass of command line arguments overrides // parameters values that are defined in parameters file p=1; while (p < argc) { if (strcmp(argv[p], "-lab") == 0) { if (p+1 < argc) { labFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-grid") == 0) { if (p+1 < argc) { gridFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-log") == 0) { if (p+1 < argc) { logFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-param") == 0) { if (p+1 < argc) { paramFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-port") == 0) { if (p+1 < argc) { sscanf(argv[p+1], "%d", &port); p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-gps") == 0) { cbRobot::GPSOn = true; simulator.setGPS(true); p+=1; } else if (strcmp(argv[p], "-showactions") == 0) { cbRobot::showActions=true; p+=1; } else if (strcmp(argv[p], "-showgraph") == 0) { if (p+1 < argc) { showGraph=true; sscanf(argv[p+1], "%d", &showGraphId); p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-nogui") == 0) { nogui = true; p+=1; } else if (strcmp(argv[p], "-sync") == 0) { if (p+1 < argc) { // It will read 0 when receives bad input sscanf(argv[p+1], "%u", &timeout); p+=2; simulator.activateSyncMode(timeout); } else { p+=1; simulator.activateSyncMode(); } } else { CommandLineError(); } } //cout << " done.\n"; QApplication app(argc, argv, !nogui); setlocale(LC_ALL,"C"); QLocale::setDefault(QLocale::c()); /* change lab object */ if (labFilename) // a lab file is given simulator.changeLab(labFilename); /* change grid object */ if (gridFilename) // a grid file is given simulator.changeGrid(gridFilename); if(logFilename) simulator.setLogFilename(logFilename); simulator.setReceptionistAt(port); simulator.buildGraph(); simulator.setDistMaxFromGridToTarget(); if(showGraph) { simulator.showGraph(showGraphId); if(simulator.labView) simulator.labView->show(); } /* preparing the random generator */ #ifndef MicWindows srand(getpid()); #else srand(_getpid()); #endif /* THIS WAS A SPECIAL CHANGE FOR ACADEMIA VERAO */ simulator.setCollisions(false); /* start simulator timer */ simulator.startTimer(); cbSimulatorGUI * gui = NULL; if (!nogui) { gui = new cbSimulatorGUI(&simulator); simulator.setGUI(gui); //gui.setMaximumSize(gui.size()); //gui.setMinimumSize(gui.size()); gui->show(); } app.exec(); delete gui; return 0; }
/* * This program accepts the following command line options * -lab string: name of file with lab description (default, stdin); * -grid string: name of file with start position grid (default, stdin); * -log string: name of log file (default, server.log); * -nc real: compass noise coeficient (default, 0.0); * -nb real: beacon noise coeficient (default, 0.0); * -ni real: infrared noise coeficient (default, 0.0); * -nm real: motors noise coeficient (default, 0.0); * -st integer: simulation time, in number of cycle time units (default, 3000); * -ct integer: cycle time, in miliseconds (default, 75). */ int main(int argc, char *argv[]) { /* Copyright and wellcome message */ printf(" CiberRato 2012 Simulator\n Copyright (C) 2001-2012 Universidade de Aveiro\n"); fflush(stdout); /* extract option values */ char *labFilename = 0; char *gridFilename = 0; char *paramFilename = 0; char *logFilename = 0; int port = 6000; bool showGraph=false; int showGraphId=0; QApplication app(argc,argv); //cout << "Parse command line (First Pass) ..." int p=1; while (p < argc) { if (strcmp(argv[p], "-lab") == 0) { if (p+1 < argc) { labFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-grid") == 0) { if (p+1 < argc) { gridFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-log") == 0) { if (p+1 < argc) { logFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-param") == 0) { if (p+1 < argc) { paramFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-port") == 0) { if (p+1 < argc) { sscanf(argv[p+1], "%d", &port); p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-gps") == 0) { // wait until second pass of command line parsing p+=1; } else if (strcmp(argv[p], "-showactions") == 0) { // wait until second pass of command line parsing p+=1; } else if (strcmp(argv[p], "-showgraph") == 0) { if (p+1 < argc) { showGraph=true; sscanf(argv[p+1], "%d", &showGraphId); p+=2; } else CommandLineError(); } else { CommandLineError(); } } /* change parameteres object */ if (paramFilename) // a parameters file is given simulator.changeParameters(paramFilename); //cout << "Parse command line (Second Pass) ..." // The second pass of command line arguments overrides // parameters values that are defined in parameters file p=1; while (p < argc) { if (strcmp(argv[p], "-lab") == 0) { if (p+1 < argc) { labFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-grid") == 0) { if (p+1 < argc) { gridFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-log") == 0) { if (p+1 < argc) { logFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-param") == 0) { if (p+1 < argc) { paramFilename = argv[p+1]; p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-port") == 0) { if (p+1 < argc) { sscanf(argv[p+1], "%d", &port); p+=2; } else CommandLineError(); } else if (strcmp(argv[p], "-gps") == 0) { cbRobot::GPSOn = true; simulator.setGPS(true); p+=1; } else if (strcmp(argv[p], "-showactions") == 0) { cbRobot::showActions=true; p+=1; } else if (strcmp(argv[p], "-showgraph") == 0) { if (p+1 < argc) { showGraph=true; sscanf(argv[p+1], "%d", &showGraphId); p+=2; } else CommandLineError(); } else { CommandLineError(); } } //cout << " done.\n"; /* change lab object */ if (labFilename) // a lab file is given simulator.changeLab(labFilename); /* change grid object */ if (gridFilename) // a grid file is given simulator.changeGrid(gridFilename); if(logFilename) simulator.setLogFilename(logFilename); simulator.setReceptionistAt(port); simulator.buildGraph(); simulator.setDistMaxFromGridToTarget(); if(showGraph) { simulator.showGraph(showGraphId); if(simulator.labView) simulator.labView->show(); } /* preparing the random generator */ #ifndef MicWindows srand(getpid()); #else srand(_getpid()); #endif /* start simulator timer */ simulator.startTimer(); /* preparing ALARM timer */ cbSimulatorGUI gui(&simulator); simulator.setGUI(&gui); //gui.setMaximumSize(gui.size()); //gui.setMinimumSize(gui.size()); gui.show(); app.exec(); return 0; }