void CNodeMesh::startSimulation() { CLogInfo log; qint8 input_gates = 0; // Flag to keep track whether the simulation is started or not. bool simulation_started = false; // Create the message that will be sent. CMessageData *msg = static_cast<CMessageData *>(CDataFactory::instance().createData("message")); if(msg == nullptr) { log.setMsg("Could not create start message."); log.setSrc(CLogInfo::ESource::framework); log.setStatus(CLogInfo::EStatus::error); log.setTime(QDateTime::currentDateTime()); log.print(); emit simulationFinished(); return; } msg->setMessage("start"); QSharedPointer<CData> pmsg = QSharedPointer<CData>(msg); // Look for nodes without input gates and send them the start message. QMap<QString, QSharedPointer<CNode>>::iterator i; for(i = m_nodes.begin(); i != m_nodes.end(); ++i) { auto node = i.value(); input_gates = node->inputGatesSize(); // qDebug().nospace().noquote() // << "Message before"; if(input_gates == 0) { node->processData("", pmsg); // qDebug().nospace().noquote() // << "Message after"; simulation_started = true; } } if(!simulation_started) { log.setMsg("The simulation was not started because" "we could not figure out where to start."); log.setSrc(CLogInfo::ESource::framework); log.setStatus(CLogInfo::EStatus::warning); log.setTime(QDateTime::currentDateTime()); log.print(); emit simulationFinished(); } }
void CNodeMesh::onNodeProcessing(bool not_idle) { // bool simulation_finished = true; // // Check if all the nodes are done. // QMap<QString, QSharedPointer<CNode>>::iterator it = m_nodes.begin(); // while(it != m_nodes.end()) { // QSharedPointer<CNode> &node = it.value(); // if(node->isProcessing()) { // simulation_finished = false; // break; // } // ++it; // } // if(simulation_finished) { // emit simulationFinished(); // } if(not_idle) { // A node started processing something. m_nodes_processing++; } else { m_nodes_processing--; } if(m_nodes_processing == 0) { // There are no more nodes processing. emit simulationFinished(); } }
void SimTab::onButtonStart() { mSimThread = new simulationThread(mVpz); try { mCurrPackage->addDirectory("","output",vle::utils::PKG_SOURCE); std::string path = mCurrPackage->getOutputDir(vle::utils::PKG_SOURCE); mSimThread->setOutputPath(path.c_str()); mSimThread->load(); mSimThread->init(); mOutputs = mSimThread->getOutputs(); } catch(...) { qDebug() << "SimTab::onButtonStart() Error : " << mSimThread->getError(); delete mSimThread; mSimThread = 0; return; } clearResults(); mThread = new QThread(); mSimThread->moveToThread(mThread); connect(mThread, SIGNAL(started()), mSimThread, SLOT(run())); connect(mSimThread, SIGNAL(step()), this, SLOT(simulationGetStep())); connect(mSimThread, SIGNAL(end()), this, SLOT(simulationFinished())); mThread->start(); }
void DefaultSimSubpanel::onRunPressed() { //disable buttons and menu left->ui->runButton->setEnabled(false); right->ui->widSimStyle->setVisible(false); //delete custom plot delete left->customPlot; left->customPlot = new QCustomPlot(); showCustomPlot(false); portsToPlot.erase(portsToPlot.begin(), portsToPlot.end()); //delte simulation thread delete sim_process; sim_process = new DefaultSimSubpanelThread(); sim_process->init(mvpm, mpkg); //delete set delete thread; thread = new QThread(); //move to thread sim_process->moveToThread(thread); connect(thread, SIGNAL(started()), sim_process, SLOT(onStarted())); connect(sim_process, SIGNAL(simulationFinished()), this, SLOT(onSimulationFinished())); thread->start(); }
void SimPlot::simulationStart() { vle::vpz::Vpz *oldVpz; // NOTE - View list is loaded from disk using vle::Vpz // only because GVLE2::vleVpz does not support views // direct access yet. This must be changed in future. QString fileName = mVpz->getFilename(); oldVpz = new vle::vpz::Vpz(fileName.toStdString()); mSimThread = new simPlotThread(oldVpz); // Load and init the simulation into VLE try { if (mCurrPackage == 0) throw 0; mCurrPackage->addDirectory("","output",vle::utils::PKG_SOURCE); std::string path = mCurrPackage->getOutputDir(vle::utils::PKG_SOURCE); mSimThread->setOutputPath(path.c_str()); mSimThread->load(); mSimThread->init(); } catch (...) { mWidgetTab->progressBar(tr("Fatal Error")); QString logMessage; logMessage = tr("Project error:") + mSimThread->getError(); qDebug() << logMessage; log(logMessage); delete mSimThread; mSimThread = 0; return; } mSimDataValid = true; mStepCount = 0; QMap<QString, int>::iterator i; for (i = mViewLastRow.begin(); i != mViewLastRow.end(); ++i) i.value() = 1; for (int k = 0; k < mPlotSignals.count(); k++) mPlotSignals.at(k)->clear(); //ui->buttonGo->setIcon(*(new QIcon(":/icon/resources/control_pause_blue.png"))); QString expName = oldVpz->project().experiment().name().c_str(); mDuration = oldVpz->project().experiment().duration(); QString startMessage; startMessage = tr("Simulation started. "); startMessage += tr("Experiment name: ") + expName + " "; startMessage += QString(tr("Duration=%1")).arg(mDuration, 0, 'f', 4); log(startMessage); // Start the simulation thread mThread = new QThread(); mSimThread->moveToThread(mThread); connect(mThread, SIGNAL(started()), mSimThread, SLOT(run())); connect(mSimThread, SIGNAL(step()), this, SLOT(simulationGetStep())); connect(mSimThread, SIGNAL(end()), this, SLOT(simulationFinished())); mThread->start(); }
TimetableGenerateForm::TimetableGenerateForm(QWidget* parent): QDialog(parent) { setupUi(this); currentResultsTextEdit->setReadOnly(true); connect(startPushButton, SIGNAL(clicked()), this, SLOT(start())); connect(stopPushButton, SIGNAL(clicked()), this, SLOT(stop())); connect(writeResultsPushButton, SIGNAL(clicked()), this, SLOT(write())); connect(closePushButton, SIGNAL(clicked()), this, SLOT(closePressed())); connect(helpPushButton, SIGNAL(clicked()), this, SLOT(help())); connect(seeImpossiblePushButton, SIGNAL(clicked()), this, SLOT(seeImpossible())); connect(seeInitialOrderPushButton, SIGNAL(clicked()), this, SLOT(seeInitialOrder())); connect(writeHighestStagePushButton, SIGNAL(clicked()), this, SLOT(writeHighestStage())); connect(stopHighestPushButton, SIGNAL(clicked()), this, SLOT(stopHighest())); centerWidgetOnScreen(this); restoreFETDialogGeometry(this); simulation_running=false; startPushButton->setDefault(true); startPushButton->setEnabled(true); stopPushButton->setDisabled(true); stopHighestPushButton->setDisabled(true); closePushButton->setEnabled(true); writeResultsPushButton->setDisabled(true); writeHighestStagePushButton->setDisabled(true); seeImpossiblePushButton->setDisabled(true); seeInitialOrderPushButton->setDisabled(true); connect(&gen, SIGNAL(activityPlaced(int)), this, SLOT(activityPlaced(int))); connect(&gen, SIGNAL(simulationFinished()), this, SLOT(simulationFinished())); connect(&gen, SIGNAL(impossibleToSolve()), this, SLOT(impossibleToSolve())); }
void SimLog::simulationStart() { mSimThread = new simPlotThread(mVpz); // Load and init the simulation into VLE try { if (mCurrPackage == 0) throw 0; mCurrPackage->addDirectory("","output",vle::utils::PKG_SOURCE); std::string path = mCurrPackage->getOutputDir(vle::utils::PKG_SOURCE); mSimThread->setOutputPath(path.c_str()); mSimThread->load(); mSimThread->init(); mOutputs = mSimThread->getOutputs(); } catch (...) { mWidgetTab->progressBar(tr("Fatal Error")); QString logMessage; logMessage = tr("Project error:") + mSimThread->getError(); qDebug() << logMessage; log(logMessage); delete mSimThread; mSimThread = 0; return; } mSimDataValid = true; mStepCount = 0; QMap<QString, int>::iterator i; for (i = mViewLastRow.begin(); i != mViewLastRow.end(); ++i) i.value() = 1; //ui->buttonGo->setIcon(*(new QIcon(":/icon/resources/control_pause_blue.png"))); QString expName = mVpz->project().experiment().name().c_str(); mDuration = mVpz->project().experiment().duration(); QString startMessage; startMessage = tr("Simulation started. "); startMessage += tr("Experiment name: ") + expName + " "; startMessage += QString(tr("Duration=%1")).arg(mDuration, 0, 'f', 4); log(startMessage); // Start the simulation thread mThread = new QThread(); mSimThread->moveToThread(mThread); connect(mThread, SIGNAL(started()), mSimThread, SLOT(run())); connect(mSimThread, SIGNAL(step()), this, SLOT(simulationGetStep())); connect(mSimThread, SIGNAL(end()), this, SLOT(simulationFinished())); mThread->start(); }
void Mediator::handleDispatcher(int index){ int fd = socketManager->getConnectedFD(index); char messageIN[BUFFER_SIZE]; int rd = ioStream->readLine(fd, messageIN, BUFFER_SIZE); if (rd > 0){ cout << "[From Dispatcher...]\t" << messageIN << flush; vector<char*> tokens ; char* token = strtok(messageIN, "|"); while (token != NULL){ tokens.push_back(token); token = strtok(NULL, "|\n"); } if (strcmp(tokens[0],"setupEnv") == 0) setupEnv(tokens, fd); else if (strcmp(tokens[0], "disconnect")==0){ disconnect(tokens[1], fd); } else if (strcmp(tokens[0], "BG_putFile")==0){ BG_put_file(tokens[1], atol(tokens[2]), fd); } else if (strcmp(tokens[0], "BG_start") == 0){ BG_start(tokens[1], atol(tokens[2])); } else if (strcmp(tokens[0], "JOB_STOP") ==0 ){ // processList.stopAll(); // becomeFree(); stopSimulation("dispatcher"); becomeFree(); simulationFinished(); } else if (strcmp(tokens[0], "JOB_ABORT") ==0 ){ abortSimulation(); } else if (strcmp(tokens[0], "getTick\n") == 0){ getTick(fd); } else cout << "else?" << endl << flush; } else{ socketManager->closeByIndex(index); cout << "Dispatcher Closed" << endl << flush; } }
void PlanSimSubpanel::onRunPressed() { // disable buttons and menu left->ui->runButton->setEnabled(false); right->ui->widSimStyle->setVisible(false); // delete custom plot //delete left->customPlot; delete left->planView; //left->customPlot = new QCustomPlot(); left->planView = new SvgView(left->ui->stackPlot); left->planView->loadTemplate(); showCustomPlot(false); portsToPlot.erase(portsToPlot.begin(), portsToPlot.end()); // prepare new thread for simulation log_messages.clear(); index_message = 0; delete sim_process; sim_process = new PlanSimSubpanelThread(log_messages, debug, nbthreads, blockSize); sim_process->init(mvpz, mpkg); // delete set delete thread; thread = new QThread(); // move to thread timer.start(1000); sim_process->moveToThread(thread); connect(thread, SIGNAL(started()), sim_process, SLOT(onStarted())); connect(sim_process, SIGNAL(simulationFinished()), this, SLOT(onSimulationFinished())); thread->start(); }
void Mediator::handleUnix(int index){ int fd = socketManager->getConnectedFD(index); char messageIN[BUFFER_SIZE]; int rd = ioStream->readLine(fd, messageIN, BUFFER_SIZE); if (rd > 0){ //cout << "[From S.E ->]\t" << messageIN << flush; char* command = strtok(messageIN, "|"); if (strcmp(command,"sendTime") == 0){ sendTime(strtok(NULL, "|\n")); } else if (strcmp(command,"startTafficeGenerator") ==0){ //trafficControl(strtok(NULL, "|\n")); cout << "[?????] START traffic " << endl; } else if (strcmp(command,"simulationDone\n") == 0){ cout << "Coordinator receives the information from Simulation Engine about the simulation is down." << endl; simulationFinished(); } else if (strcmp(command,"stopTraffic") == 0){ //stopTraffic(strtok(NULL, "|\n")); cout << "[?????] STOP traffic " << endl; } else if (strcmp(command,"sendToGUI") == 0){ sendtoGUI(strtok(NULL, "|\n")); } else if (strcmp(command, "sendWarningtoGUI") == 0) { sendWarningtoGUI(strtok(NULL, "|\n")); } else cout << "Unknown Command\t" << command << endl << flush; } else{ socketManager->closeByIndex(index); } }
void TimetableGenerateMultipleForm::finished() { simulationFinished(); }