Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkPropertyList.h"
00020
00021 #include "mitkProperties.h"
00022 #include "mitkStringProperty.h"
00023 #include "mitkVector.h"
00024
00025
00026 mitk::BaseProperty* mitk::PropertyList::GetProperty(const std::string& propertyKey) const
00027 {
00028 PropertyMap::const_iterator it;
00029
00030 it=m_Properties.find( propertyKey );
00031 if(it!=m_Properties.end() && it->second.second )
00032 return it->second.first;
00033 else
00034 return NULL;
00035 }
00036
00037
00038 void mitk::PropertyList::SetProperty(const std::string& propertyKey, BaseProperty* property)
00039 {
00040 if (!property) return;
00041
00042
00043
00044
00045 BaseProperty::Pointer tmpSmartPointerToProperty = property;
00046
00047 PropertyMap::iterator it( m_Properties.find( propertyKey ) );
00048
00049
00050 if( it != m_Properties.end() )
00051 {
00052
00053
00054 if( it->second.first == property)
00055 {
00056
00057 return;
00058 }
00059
00060
00061 if (it->second.first->Assignable( *property ))
00062 {
00063 bool changed = (it->second.first->GetValueAsString() != property->GetValueAsString());
00064 *(static_cast<BaseProperty*>(it->second.first.GetPointer())) = *property;
00065
00066 if(changed)
00067 this->Modified();
00068 return;
00069 }
00070
00071 if ( typeid( *(it->second.first.GetPointer()) ) != typeid( *property ) )
00072 {
00073
00074
00075 MITK_ERROR << "In " __FILE__ ", l." << __LINE__
00076 << ": Trying to set existing property to a property with different type."
00077 << " Use ReplaceProperty() instead."
00078 << std::endl;
00079 return;
00080 }
00081
00082
00083
00084 it->second.first = property;
00085 return;
00086 }
00087
00088
00089 PropertyMapElementType newProp;
00090 newProp.first = propertyKey;
00091 newProp.second = std::pair<BaseProperty::Pointer,bool>(property,true);
00092 m_Properties.insert ( newProp );
00093 this->Modified();
00094 }
00095
00096
00097 void mitk::PropertyList::ReplaceProperty(const std::string& propertyKey, BaseProperty* property)
00098 {
00099 if (!property) return;
00100
00101 PropertyMap::iterator it( m_Properties.find( propertyKey ) );
00102
00103
00104 if( it != m_Properties.end() )
00105 {
00106 it->second.first=NULL;
00107 m_Properties.erase(it);
00108 }
00109
00110
00111 PropertyMapElementType newProp;
00112 newProp.first = propertyKey;
00113 newProp.second = std::pair<BaseProperty::Pointer,bool>(property,true);
00114 m_Properties.insert ( newProp );
00115 Modified();
00116 }
00117
00118
00119 mitk::PropertyList::PropertyList()
00120 {
00121 }
00122
00123
00124 mitk::PropertyList::~PropertyList()
00125 {
00126 Clear();
00127 }
00128
00129
00133 unsigned long mitk::PropertyList::GetMTime() const
00134 {
00135 for ( PropertyMap::const_iterator it = m_Properties.begin() ;
00136 it != m_Properties.end();
00137 ++it )
00138 {
00139 if( it->second.first.IsNull() )
00140 {
00141 itkWarningMacro(<< "Property '" << it->first <<"' contains nothing (NULL).");
00142 continue;
00143 }
00144 if( Superclass::GetMTime() < it->second.first->GetMTime() )
00145 {
00146 Modified();
00147 break;
00148 }
00149 }
00150
00151 return Superclass::GetMTime();
00152 }
00153
00154
00155 bool mitk::PropertyList::DeleteProperty(const std::string& propertyKey)
00156 {
00157 PropertyMap::iterator it;
00158 it=m_Properties.find( propertyKey );
00159
00160 if(it!=m_Properties.end())
00161 {
00162 it->second.first=NULL;
00163 m_Properties.erase(it);
00164 Modified();
00165 return true;
00166 }
00167 return false;
00168 }
00169
00170
00171 mitk::PropertyList::Pointer mitk::PropertyList::Clone()
00172 {
00173 mitk::PropertyList::Pointer newPropertyList = PropertyList::New();
00174
00175
00176 newPropertyList->m_Properties = m_Properties;
00177
00178 return newPropertyList.GetPointer();
00179 }
00180
00181
00182 void mitk::PropertyList::Clear()
00183 {
00184 PropertyMap::iterator it = m_Properties.begin(), end = m_Properties.end();
00185 while(it!=end)
00186 {
00187 it->second.first = NULL;
00188 ++it;
00189 }
00190 m_Properties.clear();
00191 }
00192
00193 bool mitk::PropertyList::IsEnabled(const std::string& propertyKey)
00194 {
00195 PropertyMap::iterator it = m_Properties.find( propertyKey );
00196 if (it != m_Properties.end() && it->second.second)
00197 {
00198 return true;
00199 }
00200 else
00201 {
00202 return false;
00203 }
00204 }
00205
00206
00207 void mitk::PropertyList::SetEnabled(const std::string& propertyKey, bool enabled)
00208 {
00209 PropertyMap::iterator it = m_Properties.find( propertyKey );
00210 if (it != m_Properties.end() && it->second.second != enabled)
00211 {
00212 it->second.second = enabled;
00213 this->Modified();
00214 }
00215 }
00216
00217
00218 void mitk::PropertyList::ConcatenatePropertyList(PropertyList *pList, bool replace)
00219 {
00220 if (pList)
00221 {
00222 const PropertyMap* propertyMap = pList->GetMap();
00223
00224 for ( PropertyMap::const_iterator iter = propertyMap->begin();
00225 iter != propertyMap->end();
00226 ++iter )
00227 {
00228 const std::string key = iter->first;
00229 BaseProperty* value = iter->second.first;
00230 if (replace)
00231 {
00232 ReplaceProperty( key.c_str(), value );
00233 }
00234 else
00235 {
00236 SetProperty( key.c_str(), value );
00237 }
00238 }
00239 }
00240 }
00241
00242 bool mitk::PropertyList::GetBoolProperty(const char* propertyKey, bool& boolValue) const
00243 {
00244 BoolProperty *gp = dynamic_cast<BoolProperty*>( GetProperty(propertyKey) );
00245 if ( gp != NULL )
00246 {
00247 boolValue = gp->GetValue();
00248 return true;
00249 }
00250 return false;
00251
00252
00253 }
00254
00255
00256 bool mitk::PropertyList::GetIntProperty(const char* propertyKey, int &intValue) const
00257 {
00258 IntProperty *gp = dynamic_cast<IntProperty*>( GetProperty(propertyKey) );
00259 if ( gp != NULL )
00260 {
00261 intValue = gp->GetValue();
00262 return true;
00263 }
00264 return false;
00265
00266
00267 }
00268
00269
00270 bool mitk::PropertyList::GetFloatProperty(const char* propertyKey, float &floatValue) const
00271 {
00272 FloatProperty *gp = dynamic_cast<FloatProperty*>( GetProperty(propertyKey) );
00273 if ( gp != NULL )
00274 {
00275 floatValue = gp->GetValue();
00276 return true;
00277 }
00278 return false;
00279
00280
00281 }
00282
00283
00284 bool mitk::PropertyList::GetStringProperty(const char* propertyKey, std::string& stringValue) const
00285 {
00286 StringProperty* sp= dynamic_cast<StringProperty*>(GetProperty(propertyKey));
00287 if ( sp != NULL )
00288 {
00289 stringValue = sp->GetValue();
00290 return true;
00291 }
00292 return false;
00293 }
00294
00295
00296 void mitk::PropertyList::SetIntProperty(const char* propertyKey, int intValue)
00297 {
00298 SetProperty(propertyKey, mitk::IntProperty::New(intValue));
00299 }
00300
00301
00302 void mitk::PropertyList::SetBoolProperty( const char* propertyKey, bool boolValue)
00303 {
00304 SetProperty(propertyKey, mitk::BoolProperty::New(boolValue));
00305 }
00306
00307
00308 void mitk::PropertyList::SetFloatProperty( const char* propertyKey, float floatValue)
00309 {
00310 SetProperty(propertyKey, mitk::FloatProperty::New(floatValue));
00311 }
00312
00313
00314 void mitk::PropertyList::SetStringProperty( const char* propertyKey, const char* stringValue)
00315 {
00316 SetProperty(propertyKey, mitk::StringProperty::New(stringValue));
00317 }