31 #include <QApplication>
32 #include <QFileDialog>
33 #include <QSplashScreen>
34 #include <QtCore/QDir>
35 #include <QtCore/QSettings>
37 #include <boost/algorithm/string/predicate.hpp>
38 #include <boost/filesystem.hpp>
40 #include "WApplication.h"
41 #include "WMainWindow.h"
43 #include "WQtModuleConfig.h"
44 #include "controlPanel/WQtControlPanel.h"
45 #include "core/common/WConditionOneShot.h"
46 #include "core/common/WIOTools.h"
47 #include "core/common/WPathHelper.h"
48 #include "core/dataHandler/WDataHandler.h"
49 #include "core/dataHandler/WSubject.h"
50 #include "core/graphicsEngine/WGraphicsEngine.h"
51 #include "core/kernel/WKernel.h"
52 #include "core/kernel/WModuleContainer.h"
53 #include "core/kernel/WProjectFile.h"
54 #include "core/kernel/WROIManager.h"
55 #include "events/WLogEvent.h"
56 #include "events/WModuleAssocEvent.h"
57 #include "events/WModuleConnectEvent.h"
58 #include "events/WModuleCrashEvent.h"
59 #include "events/WModuleDisconnectEvent.h"
60 #include "events/WModuleReadyEvent.h"
61 #include "events/WModuleRemovedEvent.h"
62 #include "events/WRoiAssocEvent.h"
63 #include "events/WRoiRemoveEvent.h"
64 #include "events/WUpdateTextureSorterEvent.h"
70 WQtGui::WQtGui(
const boost::program_options::variables_map& options,
int argc,
char** argv )
72 m_optionsMap( options ),
73 m_loadDeferredOnce( true )
104 wlog::debug(
"OpenWalnut" ) <<
"Deferred loading of data and project files.";
106 bool useInputFileNameAsProject =
false;
110 std::vector< std::string > dataFileNames =
m_optionsMap[
"input"].as< std::vector< std::string > >();
111 useInputFileNameAsProject = ( dataFileNames.size() == 1
112 && ( boost::algorithm::ends_with( dataFileNames[0],
".owp" )
113 || boost::algorithm::ends_with( dataFileNames[0],
".owproj" ) ) );
114 if( !useInputFileNameAsProject )
116 m_kernel->loadDataSets( dataFileNames );
121 if(
m_optionsMap.count(
"project" ) || useInputFileNameAsProject )
123 std::string projectFileName;
124 if( useInputFileNameAsProject )
126 projectFileName =
m_optionsMap[
"input"].as< std::vector< std::string > >()[0];
130 projectFileName =
m_optionsMap[
"project"].as< std::string >();
140 wlog::error(
"GUI" ) <<
"Project file \"" <<
m_optionsMap[
"project"].as< std::string >() <<
"\" could not be loaded. Message: " <<
158 boost::filesystem::path walnutBin( QApplication::applicationDirPath().toStdString() );
165 if( QApplication::applicationDirPath().endsWith(
"/MacOS" ) )
168 WPathHelper::getPathHelper()->setBasePathsOSXBundle( walnutBin, boost::filesystem::path( QDir::homePath().toStdString() ) /
".OpenWalnut" );
172 WPathHelper::getPathHelper()->setBasePaths( walnutBin, boost::filesystem::path( QDir::homePath().toStdString() ) /
".OpenWalnut" );
176 WPathHelper::getPathHelper()->setBasePaths( walnutBin, boost::filesystem::path( QDir::homePath().toStdString() ) /
".OpenWalnut" );
179 QPixmap splashPixmap( QString::fromStdString( (
WPathHelper::getPathHelper()->getSharePath() /
"qtgui" /
"splash.png" ).
string() ) );
180 m_splash =
new QSplashScreen( splashPixmap );
189 LogLevel logLevel =
static_cast< LogLevel
>(
WQtGui::getSettings().value(
"qtgui/logLevel", LL_DEBUG ).toInt() );
193 wlog::debug(
"OpenWalnut" ) <<
"OpenWalnut binary path: " << walnutBin;
204 t_ModuleErrorSignalHandlerType func = boost::bind( &
WQtGui::moduleError,
this, boost::placeholders::_1, boost::placeholders::_2 );
205 m_kernel->getRootContainer()->addDefaultNotifier( WM_ERROR, func );
213 m_kernel->getRootContainer()->addDefaultNotifier( WM_ASSOCIATED, assocSignal );
217 m_kernel->getRootContainer()->addDefaultNotifier( WM_READY, readySignal );
221 m_kernel->getRootContainer()->addDefaultNotifier( WM_REMOVED, removedSignal );
226 boost::placeholders::_1,
227 boost::placeholders::_2 );
228 m_kernel->getRootContainer()->addDefaultNotifier( CONNECTION_ESTABLISHED, connectionEstablishedSignal );
233 boost::placeholders::_1,
234 boost::placeholders::_2 );
235 m_kernel->getRootContainer()->addDefaultNotifier( CONNECTION_CLOSED, connectionClosedSignal );
237 std::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > assocRoiSignal;
239 std::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > >(
240 new boost::function< void( osg::ref_ptr< WROI > ) > ( boost::bind( &
WQtGui::slotAddRoiToTree,
this, boost::placeholders::_1 ) ) );
241 m_kernel->getRoiManager()->addAddNotifier( assocRoiSignal );
243 std::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > removeRoiSignal;
245 std::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > >(
247 m_kernel->getRoiManager()->addRemoveNotifier( removeRoiSignal );
269 int qtRetCode = appl.exec();
345 if( in->isInputConnector() )
366 if( in->isInputConnector() )
Overloaded base class for our application that has initial handling of session data and catches uncau...
void setMyMainWidget(QWidget *widget)
store the main widget for error reporting and session management
Implements a WCondition, but can be fired only ONCE.
std::shared_ptr< WCondition > SPtr
Shared pointer type for WCondition.
boost::function0< void > t_ConditionNotifierType
Type used for signalling condition changes.
static std::shared_ptr< WSubject > getDefaultSubject()
Gets the subject with the ID SUBJECT_UNKNOWN.
Derived WDeferredCallEvent allowing result values in calls.
virtual const char * what() const
Returns the message string set on throw.
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
static WKernel * instance(std::shared_ptr< WGraphicsEngine > ge, std::shared_ptr< WUI > ui)
Returns pointer to the running kernel or a new if no kernel was there.
WBatchLoader::SPtr loadDataSetsSynchronously(std::vector< std::string > filenames, bool suppressColormaps=false)
Loads the specified files synchronously.
WBatchLoader::SPtr loadDataSets(std::vector< std::string > filenames, bool suppressColormaps=false)
Load specified datasets.
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
Represents a simple log message with some attributes.
LogLevel getLogLevel() const
This event is triggered when a new event is to be added to the log.
void setDefaultLogLevel(const LogLevel &level)
Set the default log-level used for log entries in default console-output.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
boost::signals2::connection subscribeSignal(LogEvent event, LogEntryCallback callback)
Subscribe to the specified signal.
This class contains the main window and the layout of the widgets within the window.
WQtControlPanel * getControlPanel()
Returns a pointer to the control panel object.
void setupGUI()
Set up all widgets menus an buttons in the main window.
WIconManager * getIconManager()
Return icon manager.
void asyncProjectLoad(std::string filename)
Loads a given project asynchronously.
boost::signals2::signal< void(std::vector< std::string >) > * getLoaderSignal()
Returns a pointer to a signal object which signals a list of filenames to load.
WQtNetworkEditor * getNetworkEditor()
Returns a pointer to the network editor object.
Event signalling a new module has been associated with the root container in the kernel.
Event signalling a module connection was established.
Event signalling a new module has been associated with the root container in the kernel.
Event signalling a module connection was closed.
Event signalling a new module has been associated with the root container in the kernel.
Event signalling a module was removed from the kernel root container.
static boost::filesystem::path getHomePath()
The path to the OW dir in the user's home.
static std::shared_ptr< WPathHelper > getPathHelper()
Returns instance of the path helper.
std::shared_ptr< WModule > getSelectedModule()
Returns the module currently selected in control panel.
virtual void slotAddDatasetOrModuleToTree(std::shared_ptr< WModule > module)
Slot gets called whenever a new module is added.
virtual std::shared_ptr< WModule > getSelectedModule()
returns a pointer to the selected module in the control panel
virtual int run()
Runs the GUI.
const boost::program_options::variables_map & getOptionMap() const
Returns the option map for the current instance of this GUI.
static QSettings & getSettings()
Returns the settings object.
static WMainWindow * getMainWindow()
Returns the current main window instance or NULL if not existent.
QSplashScreen * m_splash
The splash screen.
virtual ~WQtGui()
Default destructor.
virtual void slotRemoveDatasetOrModuleInTree(std::shared_ptr< WModule > module)
Slot gets called whenever a module has been removed from the root container.
virtual void slotRemoveRoiFromTree(osg::ref_ptr< WROI > roi)
Slot gets called whenever a ROI is removed.
virtual void slotActivateDatasetOrModuleInTree(std::shared_ptr< WModule > module)
Slot gets called whenever a module switches its state to "ready".
static WMainWindow * m_mainWindow
Main window containing all needed widgets.
bool m_loadDeferredOnce
If true, the next trigger of deferredLoad will actually do loading.
static WIconManager * getIconManager()
Get the icon manager of this gui instance.
static void execInGUIThreadAsync(boost::function< void(void) > functor, WCondition::SPtr notify=WCondition::SPtr())
Call a given function from within the GUI thread.
WQtGui(const boost::program_options::variables_map &options, int argc, char **argv)
Constructor.
boost::signals2::connection m_loggerConnection
The connection to the AddLog signal of the logger.
boost::signals2::signal< void(std::vector< std::string >) > * getLoadButtonSignal()
Getter functions for the signals provided by the gui.
virtual void slotConnectionEstablished(std::shared_ptr< WModuleConnector > in, std::shared_ptr< WModuleConnector > out)
Slot gets called whenever a connector pair got connected.
std::shared_ptr< WGraphicsEngine > m_ge
Graphics Engine instance.
static QSettings * m_settings
Object storing certain persistent application settings.
std::shared_ptr< WKernel > m_kernel
Kernel instance.
virtual void slotUpdateTextureSorter()
Slot gets called whenever we need to update the texture sorter.
virtual void slotConnectionClosed(std::shared_ptr< WModuleConnector > in, std::shared_ptr< WModuleConnector > out)
Slot gets called whenever a connector pair got disconnected.
void deferredLoad()
This is called by the GE when the osg was set-up correctly.
virtual WUIWidgetFactory::SPtr getWidgetFactory() const
Returns the widget factory of the UI.
QMutex m_deferredLoadMutex
This mutex protects the deferredLoad method from being called in parallel or twice.
const boost::program_options::variables_map & m_optionsMap
Map storing the program options.
WUIQtWidgetFactory::SPtr m_widgetFactory
The widget factory which handles WUI widget creation.
void slotAddLog(const WLogEntry &entry)
New log item added.
static void execInGUIThread(boost::function< void(void) > functor, WCondition::SPtr notify=WCondition::SPtr())
Call a given function from within the GUI thread.
void moduleError(std::shared_ptr< WModule > module, const WException &exception)
Called whenever a module crashes.
virtual void slotAddRoiToTree(osg::ref_ptr< WROI > roi)
Slot gets called whenever a new ROI is added.
static void initPathHelper()
This function initializes the path helper by loading the module path settings.
Event signalling a new ROI has been associated with the ROI manager in the kernel.
Event signalling a ROI has been removed from the ROI manager in the kernel.
void wait(bool requestFinish=false)
Wait for the thread to be finished.
This class prescribes the interface to the UI.
char ** m_argv
Command line arguments given.
WFlag< bool > m_isInitialized
Flag determining whether the UI is properly initialized.
int m_argc
Number of command line arguments given.
Event signalling a new module has been associated with the root container in the kernel.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
WStreamedLogger info(const std::string &source)
Logging an information message.
WStreamedLogger error(const std::string &source)
Logging an error message.