00001 /************************************************************************/ 00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00003 /* 1993-2002, thereinafter the Software */ 00004 /* */ 00005 /* The Software has been developped within the Siames Project. */ 00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00007 /* property rights */ 00008 /* */ 00009 /* The Software has been registered with the Agence pour la Protection */ 00010 /* des Programmes (APP) under registration number */ 00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00012 /* */ 00013 /* This file may be distributed under the terms of the Q Public License */ 00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00015 /* the file LICENSE.QPL included in the packaging of this file. */ 00016 /* */ 00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00018 /* Universite Rennes 1 for the software may use this file in */ 00019 /* acordance with that specific license */ 00020 /************************************************************************/ 00021 #include "OMKVisObjectExtension.h" 00022 #include "OMKTracer.h" 00023 #include "OMKParametersAccessor.inl" 00024 #include "OMKMultipleConfigurationParameter.h" 00025 #include "OMKVisBase.h" 00026 #include "OMKAddVisualObjectPrm.h" 00027 #include "OMKAddAnimatorPrm.h" 00028 //------------------------------------------------------------------------- 00029 using namespace OMK ; 00030 using namespace OMK::Vis ; 00031 using namespace OMK::Type ; 00032 //------------------------------------------------------------------------- 00033 REGISTER_EXTENSION_FACTORY( VisObjectExtension, "VisObject" ) ; 00034 //------------------------------------------------------------------------- 00035 VisObjectExtension::VisObjectExtension( ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension ) 00036 : OMK::ExtensionT< ExtensibleSimulatedObject >( owner, id, registerExtension ) 00037 { 00038 } 00039 //------------------------------------------------------------------------- 00040 VisObjectExtension::~VisObjectExtension() 00041 { 00042 } 00043 //------------------------------------------------------------------------- 00044 bool VisObjectExtension::loadObjectParameters( const ConfigurationParameterDescriptor * node ) 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 } 00132 //------------------------------------------------------------------------- 00133 00134 bool VisObjectExtension::loadAnimatorParameters( const Name& id, 00135 const ConfigurationParameterDescriptor* node, 00136 SimulatedObject* sender, 00137 const Name& visuNameTmp, 00138 const Name* visualObjectName ) 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 } 00184 00185 //-------------------------------------------------------------------------
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |