2011-06-05 14:45:39 +00:00
/*
* Copyright (C) 2010-2011, Mathieu Labbe and IntRoLab - Universite de Sherbrooke
*
* This file is part of RTAB-Map.
*
* RTAB-Map is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RTAB-Map is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RTAB-Map. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui/QApplication>
#include <QtCore/QDir>
#include "utilite/UEventsManager.h"
#include "rtabmap/core/Rtabmap.h"
#include "rtabmap/gui/MainWindow.h"
#include <QtGui/QMessageBox>
#include "utilite/UObjDeletionThread.h"
#include "ObjDeletionHandler.h"
using namespace rtabmap ;
int main ( int argc , char * argv [])
{
/* Set logger type */
ULogger :: setType ( ULogger :: kTypeConsole );
2012-12-11 18:05:05 +00:00
ULogger :: setLevel ( ULogger :: kInfo ); // Disable log with level
2011-06-05 14:45:39 +00:00
ULOGGER_INFO ( "Program started..." );
/* Create tasks */
QApplication * app = new QApplication ( argc , argv );
MainWindow * mainWindow = new MainWindow ();
UEventsManager :: addHandler ( mainWindow );
/* Start thread's task */
mainWindow -> showNormal ();
2013-01-13 19:59:53 +00:00
Rtabmap * rtabmap = new Rtabmap ();
2013-01-10 20:29:01 +00:00
rtabmap -> start (); // start it not initialized... will be initialized by event from the gui
UEventsManager :: addHandler ( rtabmap );
2011-06-09 02:56:31 +00:00
2011-06-05 14:45:39 +00:00
// Now wait for application to finish
app -> connect ( app , SIGNAL ( lastWindowClosed () ),
app , SLOT ( quit () ) );
app -> exec (); // MUST be called by the Main Thread
/* Remove handlers */
UEventsManager :: removeHandler ( mainWindow );
UEventsManager :: removeHandler ( rtabmap );
ULOGGER_INFO ( "Killing threads..." );
2012-03-03 01:46:30 +00:00
rtabmap -> join ( true );
2011-06-05 14:45:39 +00:00
ULOGGER_INFO ( "Free memory..." );
delete mainWindow ;
2012-12-11 18:05:05 +00:00
2011-06-05 14:45:39 +00:00
//Since we can't put the Rtabmap object in the MainWindow class,
//we pop up a message box indicating that the rtabmap object
// is being deleted (saving data to the database)
QMessageBox * msg = new QMessageBox ( QMessageBox :: Information , QObject :: tr ( "RTAB-Map is closing..." ), QObject :: tr ( "The detector is saving the working memory to database (located in RTAB-Map's working directory)..." ), QMessageBox :: NoButton );
msg -> setEnabled ( false );
msg -> setIconPixmap ( QPixmap ( ":/images/RTAB-Map.ico" ));
msg -> setWindowIcon ( QIcon ( ":/images/RTAB-Map.ico" ));
msg -> show ();
2012-03-03 01:46:30 +00:00
UObjDeletionThread < Rtabmap > delThread ( rtabmap );
2011-06-05 14:45:39 +00:00
ObjDeletionHandler handler ( delThread . id (), app , SLOT ( quit ()));
UEventsManager :: addHandler ( & handler );
delThread . startDeletion ( 1 ); // make sure that app-exec() is called before the deletion of the object
app -> exec ();
delete msg ;
delete app ;
ULOGGER_INFO ( "All done! Closing..." );
return 0 ;
}