00001 00002 /************************************************************************/ 00003 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00004 /* 1993-2002, thereinafter the Software */ 00005 /* */ 00006 /* The Software has been developped within the Siames Project. */ 00007 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00008 /* property rights */ 00009 /* */ 00010 /* The Software has been registered with the Agence pour la Protection */ 00011 /* des Programmes (APP) under registration number */ 00012 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00013 /* */ 00014 /* This file may be distributed under the terms of the Q Public License */ 00015 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00016 /* the file LICENSE.QPL included in the packaging of this file. */ 00017 /* */ 00018 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00019 /* Universite Rennes 1 for the software may use this file in */ 00020 /* acordance with that specific license */ 00021 /************************************************************************/ 00022 00023 #include "OMKExtensibleSimulatedObject.h" 00024 #include "OMKExtension.h" 00025 #include "OMKIAttribute.h" 00026 #include "OMKMultipleConfigurationParameter.h" 00027 #include "OMKParametersAccessor.inl" 00028 #include <vector> 00029 #include <string> 00030 #include <iostream> 00031 00032 namespace OMK 00033 { 00034 namespace EventId 00035 { 00036 EventIdentifier CREATE_AND_ADD_EXTENSION( "Create_and_add_extension" ) ; 00037 } 00038 } 00039 using namespace OMK ; 00040 //----------------------------------------------------------------- 00041 00042 // Default constructor 00043 ExtensibleSimulatedObject::ExtensibleSimulatedObject( Controller& ctrl, const ObjectDescriptor& objectDescriptor ) 00044 : SimulatedObject( ctrl, objectDescriptor ), 00045 ExtensionManager(), 00046 _exitOnInitError( true ) 00047 { 00048 } 00049 00050 //----------------------------------------------------------------- 00051 00052 // Destructor 00053 ExtensibleSimulatedObject::~ExtensibleSimulatedObject() 00054 { 00055 } 00056 //----------------------------------------------------------------- 00057 void ExtensibleSimulatedObject::postConstruction() 00058 { 00059 // Retrieve the extension fields to create the extensions which defined a "Class" 00060 createExtensionsFromParameters( this, getObjectDescriptor().getExtensionsParameters() ) ; 00061 } 00062 //----------------------------------------------------------------- 00063 00064 // finish 00065 void ExtensibleSimulatedObject::finish() 00066 { 00067 // Destroy every extensions 00068 deleteExtensions() ; 00069 // Calls the ancestor 00070 SimulatedObject::finish() ; 00071 } 00072 //----------------------------------------------------------------- 00073 // Initialisation 00074 void ExtensibleSimulatedObject::init() 00075 { 00076 bool ok = true ; 00077 00078 // The configuration parameter node 00079 const ConfigurationParameterDescriptor* node = getConfigurationParameters() ; 00080 const ConfigurationParameterDescriptor* extensionsNode = getObjectDescriptor().getExtensionsParameters() ; 00081 //---Load Extension order if there is one 00082 loadOrder( extensionsNode, "LoadParametersOrder", _orderedExtensionsForLoadParameters ) ; 00083 00084 //---Load the user parameters 00085 // Load object parameters for the attributes 00086 for( AttributeStore::iterator i = _attributes.begin() ; i != _attributes.end(); i++ ) 00087 { 00088 OMTRACEID( OMK_DEBUG_OMK_ATTR, "Load configuration for " << OMK::debugMsg( i->second ) ) ; 00089 ok = i->second->loadParameters( node ) && ok ; 00090 } 00091 00092 //--- Load parameters for extensions 00093 ok = loadFromObjectParameters( node ) && ok ; 00094 00095 // Load object parameters for the object 00096 ok = loadParameters( node ) && ok ; 00097 00098 //--- Load parameters for extensions 00099 // In case Extension parameter create extensionNode 00100 extensionsNode = getObjectDescriptor().getExtensionsParameters() ; 00101 ok = loadFromExtensionsParameters( extensionsNode ) && ok ; 00102 00103 loadOrder( extensionsNode, "PreComputeOrder" , _orderedExtensionsForPreCompute ) ; 00104 loadOrder( extensionsNode, "PostComputeOrder" , _orderedExtensionsForPostCompute ) ; 00105 00106 if( !ok ) 00107 { // Not ok, display the following message and exit 00108 OMFATALERROR( "Error in ExtensibleSimulatedObject::init for " << debugMsg( this ) << std::endl 00109 << ">>> :-( Unable to initialize the object" ) ; 00110 } 00111 } 00112 //----------------------------------------------------------------- 00113 00114 void ExtensibleSimulatedObject::compute() 00115 { 00116 // to retrieve the inputs value 00117 computeInputs(); 00118 00119 // Call the extensions which work on inputs parameters 00120 preComputeExtension() ; 00121 00122 // To compute the behavior 00123 computeParameters(); 00124 00125 // Call the extensions which work on outputs parameters 00126 postComputeExtension() ; 00127 00128 // To set the outputs 00129 computeOutputs(); 00130 } 00131 00132 //----------------------------------------------------------------- 00133 00134 void ExtensibleSimulatedObject::computeInputs() 00135 { 00136 // Call the attribute which work with inputs 00137 for( AttributeStore::iterator i = _attributes.begin() ; i != _attributes.end(); i++ ) 00138 { 00139 i->second->getValueFromInput() ; 00140 } 00141 } 00142 00143 //----------------------------------------------------------------- 00144 00145 void ExtensibleSimulatedObject::computeParameters() 00146 { 00147 } 00148 //----------------------------------------------------------------- 00149 00150 void ExtensibleSimulatedObject::computeOutputs() 00151 { 00152 // Call the attribute which work with outputs 00153 for( AttributeStore::iterator i = _attributes.begin() ; i != _attributes.end(); i++ ) 00154 { 00155 i->second->setValueToOutput() ; 00156 i->second->resetUpdated() ; 00157 } 00158 } 00159 //----------------------------------------------------------------- 00160 bool ExtensibleSimulatedObject::loadParameters( const ConfigurationParameterDescriptor * node ) 00161 { 00162 return true ; 00163 } 00164 //----------------------------------------------------------------- 00165 void ExtensibleSimulatedObject::activateCreateExtensionByEvent( bool activate ) 00166 { 00167 if( activate ) 00168 { 00169 if( !_eventCreateAndAddExtensionListener ) 00170 { 00171 _eventCreateAndAddExtensionListener = new CreateAndAddExtensionEventListener 00172 ( *this, 00173 &ExtensibleSimulatedObject::processCreateAndAddExtension, 00174 EventId::CREATE_AND_ADD_EXTENSION ) ; 00175 } 00176 } 00177 else 00178 { 00179 delete _eventCreateAndAddExtensionListener ; 00180 _eventCreateAndAddExtensionListener = 0 ; 00181 } 00182 } 00183 //----------------------------------------------------------------- 00184 bool ExtensibleSimulatedObject::processCreateAndAddExtension( CreateAndAddExtensionEvent * event ) 00185 { 00186 const CreateAndAddExtensionPrm& value = event->value.getValue() ; 00187 createAndAddExtension( this, value.first, value.second ) ; 00188 return true ; 00189 } 00190 //----------------------------------------------------------------- 00191 IAttribute* ExtensibleSimulatedObject::getAttribute( const Name& id ) 00192 { 00193 AttributeStore::iterator i = _attributes.find( id ); 00194 return ( i == _attributes.end() ) ? 0 : i->second ; 00195 } 00196 //----------------------------------------------------------------- 00197 void ExtensibleSimulatedObject::addAttribute( IAttribute& attribute, bool createOutput ) 00198 { 00199 // Check for duplicate attribute 00200 AttributeStore::iterator i = _attributes.find( attribute.getId() ); 00201 if( i == _attributes.end() ) 00202 { 00203 // Initialise the owner of the attribute as itself 00204 attribute.setOwner( this, createOutput ) ; 00205 // It is a really new item, adds it in the main list 00206 _attributes[ attribute.getId() ] = &attribute ; 00207 } 00208 else 00209 { 00210 OMTRACEID( OMK_DEBUG_OMK_ATTR, 00211 "Error to add attribute to " << debugMsg( this ) << std::endl 00212 << ">>> :-( The attribute \"" << attribute.getId().getString() << "\" is a duplicate one" ) ; 00213 } 00214 } 00215 //----------------------------------------------------------------- 00216 void ExtensibleSimulatedObject::removeAttribute( const Name& id ) 00217 { 00218 // Look for the attribute 00219 AttributeStore::iterator i = _attributes.find( id ); 00220 if( i != _attributes.end() ) 00221 { 00222 _attributes.erase( i ) ; 00223 } 00224 else 00225 { 00226 OMTRACEID( OMK_DEBUG_OMK_ATTR, 00227 "Error to remove attribute to " << debugMsg( this ) << std::endl 00228 << ">>> :-( The attribute \"" << id.getString() << "\" cannot be find" ) ; 00229 } 00230 } 00231 //----------------------------------------------------------------- 00232
Documentation generated on Mon Jun 9 11:45:56 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |