Commit ba7e1c19 authored by saubatn's avatar saubatn
Browse files

FIXED Bug 116.

           When selecting a monitor using the radio button, Qt did not remove the tab in the Monitor tabs widget.
           Now, when deleting the monitoring tab, it forces removing all tab, even when selected.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@927 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 94bfc877
......@@ -102,8 +102,6 @@ MMLComponent::MMLComponent(const QString & fileName) throw(AbortException) : Com
// ---------------------- destructor ----------------------------
MMLComponent::~MMLComponent() {
cout << "delete MMLComponent" << endl;
/*if (exportedMml!="")
remove(exportedMml.toStdString().c_str());
......
......@@ -67,7 +67,6 @@ MMLDisplay::MMLDisplay(MMLComponent* mmlManager):QObject()
MMLDisplay::~MMLDisplay()
{
cout << "delete MMLDisplay" << endl;
if (monitorDisplay)
delete monitorDisplay;
}
......
......@@ -37,5 +37,5 @@ MMLMonitorDisplay::MMLMonitorDisplay(Monitor* monitor,MMLComponent* manager):QOb
MMLMonitorDisplay::~MMLMonitorDisplay()
{
cout << "delete MMLMonitorDisplay (empty destructor)" << endl;
}
......@@ -54,9 +54,8 @@ Tabular::~Tabular()
{
if (table)
{
cout << "delete tabular" << endl;
// TODO : check why it crashed, see bug 116
delete table;
table = NULL;
}
}
......
......@@ -77,7 +77,12 @@ MonitoringDialog::MonitoringDialog(MonitoringGuiManager* guiManager, QWidget* pa
}
//--------------- Destructor ---------------------------------
MonitoringDialog::~MonitoringDialog(){}
MonitoringDialog::~MonitoringDialog(){
// unselect and clear the monitor tab's content.
// this allow not to encounter crash when closing the image
// see bug 116 : https://forge.imag.fr/tracker/index.php?func=detail&aid=116&group_id=184&atid=792
this->ui.monitorsTable->clearContents();
}
//--------------- init ---------------------------------
void MonitoringDialog::init()
......
......@@ -32,16 +32,16 @@
//--------------- Constructor ---------------------------------
MonitoringDriver::MonitoringDriver(MonitoringGuiManager* guiManager): QObject()
{
this->guiManager=guiManager;
timer = NULL; // not started yet
this->guiManager=guiManager;
timer = NULL; // not started yet
}
//--------------- Constructor ---------------------------------
MonitoringDriver::~MonitoringDriver()
{
stopTimer();
delete timer;
timer = NULL;
stopTimer();
delete timer;
timer = NULL;
}
//--------------- Constructor ---------------------------------
......@@ -58,7 +58,7 @@ void MonitoringDriver::init()
//--------------- Constructor ---------------------------------
void MonitoringDriver::play()
{
if ( !timer->isActive() ) {
if ( !timer->isActive() ) {
// timer wasn't active, action to be done = launch the timer
startTimer();
} else {
......@@ -70,19 +70,19 @@ void MonitoringDriver::play()
//--------------- Constructor ---------------------------------
void MonitoringDriver::startTimer()
{
timer->start();
timer->start();
}
//--------------- Constructor ---------------------------------
void MonitoringDriver::stopTimer()
{
timer->stop();
timer->stop();
}
//--------------- Constructor ---------------------------------
bool MonitoringDriver::isTimerActive()
{
return timer->isActive();
return timer->isActive();
}
......
......@@ -33,149 +33,157 @@
//--------------- Constructor ---------------------------------
MonitoringGuiManager::MonitoringGuiManager()
{
Q_INIT_RESOURCE(MonitoringGuiIcons);
driver=new MonitoringDriver(this);
dialog=new MonitoringDialog(this);
monitoringManager=NULL;
driver->init();
dialog->init();
dialog->show();
lastRefreshTime=0;
Q_INIT_RESOURCE(MonitoringGuiIcons);
driver=new MonitoringDriver(this);
dialog=new MonitoringDialog(this);
monitoringManager=NULL;
driver->init();
dialog->init();
dialog->show();
lastRefreshTime=0;
}
//--------------- Destructor ---------------------------------
MonitoringGuiManager::~MonitoringGuiManager()
{
std::cout << "delete MonitoringGuiManager" << std::endl;
if (driver)
delete driver;
if (dialog)
delete dialog;
if (monitoringManager)
delete monitoringManager;
Q_CLEANUP_RESOURCE(MonitoringGuiIcons);
if (driver)
{
delete driver;
driver = NULL;
}
if (dialog)
{
delete dialog;
dialog = NULL;
}
if (monitoringManager)
{
delete monitoringManager;
monitoringManager = NULL;
}
Q_CLEANUP_RESOURCE(MonitoringGuiIcons);
}
//--------------- getDialog ---------------------------------
MonitoringDialog* MonitoringGuiManager::getDialog()
{
return dialog;
return dialog;
}
//--------------- getDriver ---------------------------------
MonitoringDriver* MonitoringGuiManager::getDriver()
{
return driver;
return driver;
}
//--------------- getMonitoringManager ---------------------------------
MonitoringManager* MonitoringGuiManager::getMonitoringManager()
{
return monitoringManager;
return monitoringManager;
}
//--------------- doOneStep ---------------------------------
bool MonitoringGuiManager::doOneStep()
{
if (monitoringManager->checkStop()){
QMessageBox::information(dialog,tr("Simulation finished"),tr("The simulation is finished (Stopping Criterion reached)."),QMessageBox::Ok);
driver->stopTimer();
return false;
}
else{
// As this method is called by a timer, it could happen that the motor
// has not finished one step of computation when the timer starts
// the method again. This results in a strange state.
// waitingForFinish act as a flag to say "wait, wait, we are
// already computing a step, we can't do many at the same time,
// take your chance next time".
// That allows the timer to be regulated by the motor computation time.
static bool waitingToFinish = false;
if (waitingToFinish) {
return false; // bye bye, we are too busy at the moment, we haven't done anything
}
waitingToFinish = true;
// if t is ok, play it
// update cursor
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
// show the progress
//TODO
// do simulation steps until the next refresh time is reached
monitoringManager->doMove();
// update cursor
QApplication::restoreOverrideCursor();
//emit changed only if we have to refresh
if (monitoringManager->getCurrentTime()>=lastRefreshTime+monitoringManager->getRefresh()){
emit changed();
lastRefreshTime=monitoringManager->getCurrentTime();
if (monitoringManager->checkStop()) {
QMessageBox::information(dialog,tr("Simulation finished"),tr("The simulation is finished (Stopping Criterion reached)."),QMessageBox::Ok);
driver->stopTimer();
return false;
}
else {
// As this method is called by a timer, it could happen that the motor
// has not finished one step of computation when the timer starts
// the method again. This results in a strange state.
// waitingForFinish act as a flag to say "wait, wait, we are
// already computing a step, we can't do many at the same time,
// take your chance next time".
// That allows the timer to be regulated by the motor computation time.
static bool waitingToFinish = false;
if (waitingToFinish) {
return false; // bye bye, we are too busy at the moment, we haven't done anything
}
waitingToFinish = true;
// if t is ok, play it
// update cursor
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
// show the progress
//TODO
// do simulation steps until the next refresh time is reached
monitoringManager->doMove();
// update cursor
QApplication::restoreOverrideCursor();
//emit changed only if we have to refresh
if (monitoringManager->getCurrentTime()>=lastRefreshTime+monitoringManager->getRefresh()) {
emit changed();
lastRefreshTime=monitoringManager->getCurrentTime();
}
// release the flag, so that next time this method is called,
// a new step could be computed
waitingToFinish = false;
// update view
dialog->updateSimulation();;
return true; // bye bye, we have done one step
}
// release the flag, so that next time this method is called,
// a new step could be computed
waitingToFinish = false;
// update view
dialog->updateSimulation();;
return true; // bye bye, we have done one step
}
}
//--------------- simulate ---------------------------------
void MonitoringGuiManager::simulate()
{
if (!driver->isTimerActive()) {
// timer wasn't active, action to be done = launch the timer
driver->startTimer();
} else {
// timer is active, action to be done = play one step
doOneStep();
}
if (!driver->isTimerActive()) {
// timer wasn't active, action to be done = launch the timer
driver->startTimer();
} else {
// timer is active, action to be done = play one step
doOneStep();
}
}
//--------------- simulateOneStep ---------------------------------
void MonitoringGuiManager::simulateOneStep()
{
// force one step to be done
if (!monitoringManager->checkStop()){
while (!doOneStep())
;
}else{
doOneStep(); // just to have the message box
}
// force one step to be done
if (!monitoringManager->checkStop()) {
while (!doOneStep())
;
} else {
doOneStep(); // just to have the message box
}
}
//--------------- pause ---------------------------------
void MonitoringGuiManager::pause()
{
driver->stopTimer();
driver->stopTimer();
}
//--------------- rewind ---------------------------------
void MonitoringGuiManager::rewind()
{
pause();
monitoringManager->rewind();
lastRefreshTime=0;
emit changed();
dialog->updateSimulation();
pause();
monitoringManager->rewind();
lastRefreshTime=0;
emit changed();
dialog->updateSimulation();
}
//--------------- reload ---------------------------------
void MonitoringGuiManager::reload()
{
pause();
monitoringManager->reload(false);
lastRefreshTime=0;
emit reconnectPml();
dialog->updateAll();
pause();
monitoringManager->reload(false);
lastRefreshTime=0;
emit reconnectPml();
dialog->updateAll();
}
......@@ -183,64 +191,64 @@ void MonitoringGuiManager::reload()
//--------------- loadMmlInFile ---------------------------------
bool MonitoringGuiManager::loadMmlInFile(QString fileName)
{
if (monitoringManager){
delete monitoringManager;
}
monitoringManager=MonitoringManagerFactory::createManager(fileName.toStdString().c_str());
monitoringManager->init();
dialog->updateAll();
// TODO add case when loading fails (wrong mml file)
return true;
if (monitoringManager) {
delete monitoringManager;
}
monitoringManager=MonitoringManagerFactory::createManager(fileName.toStdString().c_str());
monitoringManager->init();
dialog->updateAll();
// TODO add case when loading fails (wrong mml file)
return true;
}
//--------------- saveMmlOutFile ---------------------------------
bool MonitoringGuiManager::saveMmlOutFile(QString fileName)
{
monitoringManager->writeOutput(fileName.toUtf8().constData());
return true;
monitoringManager->writeOutput(fileName.toUtf8().constData());
return true;
}
//--------------- saveCsvFile ---------------------------------
bool MonitoringGuiManager::saveCsvFile(QString fileName)
{
monitoringManager->writeCsv(fileName.toUtf8().constData());
return true;
monitoringManager->writeCsv(fileName.toUtf8().constData());
return true;
}
//--------------- saveMmlInFile ---------------------------------
bool MonitoringGuiManager::saveMmlInFile(QString fileName)
{
monitoringManager->saveMmlIn(fileName.toUtf8().constData());
return true;
monitoringManager->saveMmlIn(fileName.toUtf8().constData());
return true;
}
//--------------- updateDt ---------------------------------
void MonitoringGuiManager::updateDt(double dt)
{
monitoringManager->setDt(dt);
monitoringManager->setDt(dt);
}
//--------------- updateRefresh ---------------------------------
void MonitoringGuiManager::updateRefresh(double refresh)
{
monitoringManager->setRefresh(refresh);
monitoringManager->setRefresh(refresh);
}
//--------------- updatePml ---------------------------------
void MonitoringGuiManager::updatePml(QString fileName)
{
monitoringManager->setPmlFileName(fileName.toUtf8().constData());
monitoringManager->setPmlFileName(fileName.toUtf8().constData());
}
//--------------- updateLml ---------------------------------
void MonitoringGuiManager::updateLml(QString fileName)
{
monitoringManager->setLmlFileName(fileName.toUtf8().constData());
monitoringManager->setLmlFileName(fileName.toUtf8().constData());
}
......
......@@ -414,7 +414,7 @@ void MonitoringManager::saveMmlIn(const char* fileName) {
map[""].schema = ""; //TODO use correct path of XML Schema (what about an URL?), this would be great: one could validate the file before instanciating/unmarshalling
ofstream ofs(fileName);
mml::monitoringIn(ofs, *mmlIn, map);
mml::monitoringIn(ofs, *mmlIn, map);
}
// -------------------- simulate --------------------
......@@ -486,7 +486,7 @@ void MonitoringManager::buildLoads() {
delete lml;
lml = NULL;
}
// building loads if present
if (isLmlPresent()) {
this->lml=new Loads(lmlFileName.c_str());
......@@ -495,7 +495,7 @@ void MonitoringManager::buildLoads() {
else {
this->lmlFileName="";
this->lml=NULL;
ownLml = false;
ownLml = false;
}
}
......@@ -552,7 +552,7 @@ void MonitoringManager::buildPmlAndSimulatorfromPml() {
// -------------------- buildPmlAndSimulatorfromSimulator --------------------
void MonitoringManager::buildPmlAndSimulatorfromSimulator() {
std::string simulatorFile = "";
// relative or absolute path
if (mmlIn->simulatorFile().get()[0] != '/')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment