Commit 67aa819e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD #224] new sync point added. You can now use waitRestored() AFTER your...

[ADD #224] new sync point added. You can now use waitRestored() AFTER your ready() call to ensure that the project loader finishes before you continue
parent b7c17488
......@@ -64,6 +64,8 @@ WModule::WModule():
m_isReady( new WConditionOneShot(), false ),
m_isReadyOrCrashed( new WConditionSet(), false ),
m_isRunning( new WCondition(), false ),
m_isLoadFinished( new WConditionOneShot(), false ),
m_restoreMode( false ),
m_readyProgress( boost::shared_ptr< WProgress >( new WProgress( "Initializing Module" ) ) ),
m_moduleState(),
m_localPath( WPathHelper::getSharePath() )
......@@ -618,3 +620,28 @@ std::string WModule::getDeprecationMessage() const
return deprecated();
}
void WModule::waitRestored()
{
if( m_restoreMode )
{
// this returns if the flag was set in the past since it uses a OneShot Condition.
m_isLoadFinished.wait();
// after load has finished, the module is not in restore mode anymore
m_restoreMode = false;
}
}
bool WModule::isRestoreNeeded() const
{
return m_restoreMode;
}
void WModule::setRestoreNeeded( bool restore )
{
m_restoreMode = restore;
}
void WModule::reportRestoreComplete()
{
m_isLoadFinished.set( true );
}
......@@ -244,11 +244,39 @@ public:
*/
const WBoolFlag& isRunning() const;
/**
* The container this module is associated with.
*
* \return the container.
*/
/**
* This method waits for the module to be restored completely. Use this instead of m_isLoadFinished->wait() as this is not properly defined
* when adding modules without using the project file loader.
*/
void waitRestored();
/**
* Check whether this module is in restore mode. This means that some loader is currently handling the module. You are allowed to ignore this
* flag. But be aware that the loader can set connections and properties even if you do not expect this.
*
* \return true if the module is currently being restored.
*/
bool isRestoreNeeded() const;
/**
* Change the restore mode. \see isRestoreNeeded for details.
*
* \note loaders need to set this flag before the module is associated with a container.
*
* \param restore the mode.
*/
void setRestoreNeeded( bool restore = true );
/**
* Called by loaders to tell the module that loading has been completed.
*/
void reportRestoreComplete();
/**
* The container this module is associated with.
*
* \return the container.
*/
boost::shared_ptr< WModuleContainer > getAssociatedContainer() const;
/**
......@@ -621,6 +649,16 @@ protected:
*/
WBoolFlag m_isRunning;
/**
* Flag to denote whether the module container and the project loader have finished their work. \see isLoadFinished.
*/
WBoolFlag m_isLoadFinished;
/**
* Flag denoting the current restore mode. \see setRestoreNeeded
*/
bool m_restoreMode;
/**
* Progress indicator for the "ready" state.
*/
......
......@@ -101,6 +101,9 @@ bool WModuleProjectFileCombiner::parse( std::string line, unsigned int lineNumbe
else
{
boost::shared_ptr< WModule > module = WModuleFactory::getModuleFactory()->create( proto );
// set restore mode
module->setRestoreNeeded();
m_modules.insert( ModuleID( string_utils::fromString< unsigned int >( matches[1] ), module ) );
}
}
......@@ -121,6 +124,9 @@ bool WModuleProjectFileCombiner::parse( std::string line, unsigned int lineNumbe
{
std::string parameter = std::string( matches[2] );
boost::shared_ptr< WModule > module = WModuleFactory::getModuleFactory()->create( proto );
// set restore mode
module->setRestoreNeeded();
if( parameter.empty() )
{
addError( "Data modules need an additional filename parameter. Skipping." );
......@@ -295,6 +301,12 @@ void WModuleProjectFileCombiner::apply()
}
}
// notify modules about the loaded set properties
for( std::map< unsigned int, boost::shared_ptr< WModule > >::iterator iter = m_modules.begin(); iter != m_modules.end(); ++iter )
{
( *iter ).second->reportRestoreComplete();
}
// clear all our lists (deref all contained pointers)
m_modules.clear();
m_connections.clear();
......
......@@ -409,6 +409,13 @@ void WMTemplate::moduleMain()
ready();
debugLog() << "Module is now ready.";
// After your module has signalled that it is ready, OpenWalnut allows the project loader to set the restored properties and connections. For
// you this means that your module now runs but WHILE running, the project loader might change properties and connections. Usually, this is
// no problem as you write interactive modules, handling these changes fast. But if you need to ensure that you do not continue your module
// until the project file loader has completely restored your module, you will need to call this:
waitRestored();
// This always returns if you manually add your module and no project file loader or something similar has to restore any values.
// Most probably, your module will be a module providing some kind of visual output. In this case, the WGEManagedGroupNode is very handy.
// It allows you to insert several nodes and transform them as the WGEGroupNode (from which WGEManagedGroupNode is derived from) is also
// an osg::MatrixTransform. The transformation feature comes in handy if you want to transform your whole geometry according to a dataset
......
Markdown is supported
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