#include <OMKVisObjectExtension.h>
Inheritance diagram for OMK::Vis::VisObjectExtension:
Configuration loaders | |
See How to configure an extension ? for details. | |
virtual bool | loadObjectParameters (const ConfigurationParameterDescriptor *node) |
See How to create Visual Objects. | |
static bool | loadAnimatorParameters (const Name &id, const ConfigurationParameterDescriptor *node, SimulatedObject *sender, const Name &visName, const Name *visualObjectName) |
See How to create Animators. | |
Private Member Functions | |
DECLARE_EXTENSION_FACTORY (VisObjectExtension) | |
Factory and constructor/destructor. | |
Friends | |
class | VisBase |
This extension is automatically add to every visual object.
Definition at line 23 of file OMKVisObjectExtension.h.
OMK::Vis::VisObjectExtension::DECLARE_EXTENSION_FACTORY | ( | VisObjectExtension | ) | [private] |
Factory and constructor/destructor.
bool VisObjectExtension::loadObjectParameters | ( | const ConfigurationParameterDescriptor * | node | ) | [protected, virtual] |
See How to create Visual Objects.
Reimplemented from OMK::Extension.
Definition at line 44 of file OMKVisObjectExtension.cpp.
References OMK::ExtensionT< SimulatedObjectType >::_owner, OMK::Vis::VisBase::ADD_VISUAL_OBJECT_EVENT_ID, OMK::ParametersAccessor::get(), OMK::SimulatedObject::getName(), OMK::ConfigurationParameterDescriptor::getNumberOfSubItems(), OMK::ConfigurationParameterDescriptor::getSubDescriptorByName(), OMK::Type::AddVisualObjectPrm::getVisuName(), loadAnimatorParameters(), OMK::Type::AddVisualObjectPrm::loadParameters(), OMK_DEBUG_VIS_EXEC, OMTRACE, OMTRACEID, and OMK::Type::AddVisualObjectPrm::setObjectName().
00045 { 00046 // Retrieve the visual objects 00047 bool ok = true ; 00048 Name visuName ; 00049 const VisBase* visu = dynamic_cast< const VisBase* >( _owner ) ; 00050 if( visu ) 00051 { // The extension owner is the visuable object itself => retrieve its name 00052 visuName = visu->getName() ; 00053 } 00054 else 00055 { // The extension owner is not the visuable object => try to find the name in the object parameters 00056 ParametersAccessor::get( node, "VisuName", visuName ) ; 00057 } 00058 const ConfigurationParameterDescriptor * objectNode = node ? node->getSubDescriptorByName( "VisualObject" ) : 0 ; 00059 00060 if( objectNode ) 00061 { 00062 int nbItems = objectNode->getNumberOfSubItems() ; 00063 for( int i = 0 ; i < nbItems ; ++i ) 00064 { 00065 // Retrieve parameters sets for each visual object 00066 std::string id = static_cast<const MultipleConfigurationParameter *>( objectNode )->getNameOfSubDescriptor( i ) ; 00067 const ConfigurationParameterDescriptor * param = objectNode->getSubDescriptorByPosition( i ) ; 00068 AddVisualObjectPrm prm ; 00069 ok = prm.loadParameters( param, "", _owner ) && ok ; 00070 if( ok ) 00071 { 00072 // Fill the name of the object, it is the name of the node 00073 prm.setObjectName( id ) ; 00074 // Try to find the name of the visualisation 00075 visuName = prm.getVisuName() != Name() ? prm.getVisuName() : visuName ; 00076 00077 OMTRACEID( OMK_DEBUG_VIS_EXEC, "Sender \"" << _owner->getName().getString() << "\" (class " 00078 << _owner->getObjectDescriptor().getClass().getString() << ")" << std::endl 00079 << ">>> visualisation \"" << visuName << "\"" << std::endl 00080 << ">>> object name \"" << id << "\"" << std::endl 00081 << ">>> event \"" << prm << "\"" ) ; 00082 // sends the appropriate event to create the visual objects 00083 if( visuName != Name() ) 00084 { // A name was in arg or was found in parameters node 00085 // Send directly to the visualisation 00086 _owner->sendValuedEvent( visuName, VisBase::ADD_VISUAL_OBJECT_EVENT_ID, prm ) ; 00087 } 00088 else 00089 { // No name was found 00090 // Fire signal to any visualisation which listens 00091 // => each will creates its own visual object 00092 _owner->fireValuedSignal( VisBase::ADD_VISUAL_OBJECT_EVENT_ID, prm ) ; 00093 } 00094 } 00095 else 00096 { // Not ok, display the following message and exit 00097 OMTRACE( "Error for object \"" << _owner->getName().getString() << "\" (class " 00098 << _owner->getObjectDescriptor().getClass().getString() << ")" << std::endl 00099 << ">>> :-( Unable to load the visual object named \"" << id << "\"." ) ; 00100 } 00101 } 00102 } 00103 00104 // Read the parameters for animators 00105 const ConfigurationParameterDescriptor * animatorNode = node ? node->getSubDescriptorByName( "Animator" ) : 0 ; 00106 00107 if( animatorNode ) 00108 { 00109 int nbItems = animatorNode->getNumberOfSubItems() ; 00110 for( int i = 0 ; i < nbItems ; ++i ) 00111 { 00112 // Retrieve parameters sets for each animator 00113 std::string id = static_cast<const MultipleConfigurationParameter *>( animatorNode )->getNameOfSubDescriptor( i ) ; 00114 const ConfigurationParameterDescriptor * param = animatorNode->getSubDescriptorByPosition( i ) ; 00115 if( !loadAnimatorParameters( id, param, _owner, visuName, 0 ) && ok ) 00116 { // Not ok, display the following message and exit 00117 OMTRACE( "Error for object \"" << _owner->getName().getString() << "\" (class " 00118 << _owner->getObjectDescriptor().getClass().getString() << ")" << std::endl 00119 << ">>> :-( Unable to load the animator named \"" << id << "\"." << std::endl ) ; 00120 ok = false ; 00121 } 00122 } 00123 } 00124 else 00125 { 00126 OMTRACE( "Warning for sender \"" << _owner->getName().getString() << "\" (class " 00127 << _owner->getObjectDescriptor().getClass().getString() << ")" << std::endl 00128 << ">>> :-| No Animator to create !" << std::endl ) ; 00129 } 00130 return ok ; 00131 }
bool VisObjectExtension::loadAnimatorParameters | ( | const Name & | id, | |
const ConfigurationParameterDescriptor * | node, | |||
SimulatedObject * | sender, | |||
const Name & | visName, | |||
const Name * | visualObjectName | |||
) | [static, protected] |
Definition at line 134 of file OMKVisObjectExtension.cpp.
References OMK::Vis::VisBase::ADD_ANIMATOR_EVENT_ID, OMK::SimulatedObject::fireValuedSignal(), OMK::ObjectDescriptor::getClass(), OMK::SimulatedObject::getName(), OMK::SimulatedObject::getObjectDescriptor(), OMK::Name::getString(), OMK::Type::AddAnimatorPrm::getVisualObjectName(), OMK::Type::AddAnimatorPrm::getVisuName(), OMK::Type::AddAnimatorPrm::loadParameters(), OMASSERTM, OMK_DEBUG_VIS_EXEC, OMTRACEID, OMK::SimulatedObject::sendValuedEvent(), OMK::Type::AddAnimatorPrm::setObjectName(), and OMK::Type::AddAnimatorPrm::setVisualObjectName().
Referenced by loadObjectParameters(), and OMK::Vis::VisBase::processAddVisualObjectEvent().
00139 { 00140 OMASSERTM( sender, "Must be a valid pointer on a simulated object" ) ; 00141 // read parameters, if unable return false 00142 AddAnimatorPrm prm ; 00143 if( !prm.loadParameters( node, "", sender ) ) return false ; 00144 00145 prm.setObjectName( id ) ; 00146 if( visualObjectName ) 00147 { 00148 OMASSERTM( ( prm.getVisualObjectName() == *visualObjectName || prm.getVisualObjectName() == Name() ), 00149 "The visual object owner name must be egal or null" ) ; 00150 prm.setVisualObjectName( *visualObjectName ) ; 00151 } 00152 OMASSERTM( prm.getVisualObjectName() != Name(), 00153 "The visual object owner name cannot be null" ) ; 00154 00155 // Try to find the name of the visualisation 00156 // Try to find the name of the visualisation 00157 Name visuName( prm.getVisuName() != Name() ? prm.getVisuName() : visuNameTmp ) ; 00158 00159 OMTRACEID( OMK_DEBUG_VIS_EXEC, "Sender \"" << sender->getName().getString() << "\" (class " 00160 << sender->getObjectDescriptor().getClass().getString() << ")" << std::endl 00161 << ">>> visualisation \"" << visuName << "\"" << std::endl 00162 << ">>> object name \"" << id << "\"" << std::endl 00163 << ">>> event \"" << prm << "\"" << std::endl ) ; 00164 00165 // sends the appropriate event to create the visual objects 00166 if( visuName != Name() ) 00167 { // A name was in arg or was found in parameters node 00168 // Send directly to the visualisation 00169 sender->sendValuedEvent( visuName , VisBase::ADD_ANIMATOR_EVENT_ID, prm ) ; 00170 OMTRACEID( OMK_DEBUG_VIS_EXEC, "VisBase::loadAnimatorParameters" << std::endl 00171 << ">>> :-) Send the event to create the animator to \"" << visuName << "\" ok" << std::endl ) ; 00172 } 00173 else 00174 { // No name was found 00175 // Fire signal to any visualisation which listens 00176 // => each will creates its own visual object 00177 sender->fireValuedSignal( VisBase::ADD_ANIMATOR_EVENT_ID, prm ) ; 00178 OMTRACEID( OMK_DEBUG_VIS_EXEC, "VisBase::loadAnimatorParameters" << std::endl 00179 << ">>> :-) Fire the signal to create the animator ok" << std::endl ) ; 00180 } 00181 00182 return true ; 00183 }
friend class VisBase [friend] |
Definition at line 26 of file OMKVisObjectExtension.h.
Documentation generated on Mon Jun 9 11:46:05 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |