Merge "Making DALi core internals typesafe using guaranteed types; uint8_t, uint32_t...
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-impl.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/common/object-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <algorithm>
23
24 // INTERNAL INCLUDES
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/object/handle-devel.h>
27 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
28 #include <dali/internal/update/common/animatable-property.h>
29 #include <dali/internal/update/common/property-owner-messages.h>
30 #include <dali/internal/update/common/uniform-map.h>
31 #include <dali/internal/event/animation/constraint-impl.h>
32 #include <dali/internal/event/common/stage-impl.h>
33 #include <dali/internal/event/common/property-notification-impl.h>
34 #include <dali/internal/event/common/type-registry-impl.h>
35
36 using Dali::Internal::SceneGraph::AnimatableProperty;
37 using Dali::Internal::SceneGraph::PropertyBase;
38
39 namespace Dali
40 {
41
42 namespace Internal
43 {
44
45 namespace // unnamed namespace
46 {
47 const int SUPPORTED_CAPABILITIES = Dali::Handle::DYNAMIC_PROPERTIES;  // Object provides this capability
48 typedef Dali::Vector<Object::Observer*>::Iterator ObserverIter;
49 typedef Dali::Vector<Object::Observer*>::ConstIterator ConstObserverIter;
50
51 #if defined(DEBUG_ENABLED)
52 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_OBJECT" );
53 #endif
54
55
56 } // unnamed namespace
57
58 Object::Object()
59 : mEventThreadServices( *Stage::GetCurrent() ),
60   mTypeInfo( NULL ),
61   mConstraints( NULL ),
62   mPropertyNotifications( NULL )
63 {
64 }
65
66 void Object::AddObserver(Observer& observer)
67 {
68   // make sure an observer doesn't observe the same object twice
69   // otherwise it will get multiple calls to OnSceneObjectAdd(), OnSceneObjectRemove() and ObjectDestroyed()
70   DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer));
71
72   mObservers.PushBack( &observer );
73 }
74
75 void Object::RemoveObserver(Observer& observer)
76 {
77   // Find the observer...
78   const ConstObserverIter endIter =  mObservers.End();
79   for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
80   {
81     if( (*iter) == &observer)
82     {
83       mObservers.Erase( iter );
84       break;
85     }
86   }
87   DALI_ASSERT_DEBUG(endIter != mObservers.End());
88 }
89
90 void Object::OnSceneObjectAdd()
91 {
92   // Notification for observers
93   for( ConstObserverIter iter = mObservers.Begin(),  endIter =  mObservers.End(); iter != endIter; ++iter)
94   {
95     (*iter)->SceneObjectAdded(*this);
96   }
97
98   // enable property notifications in scene graph
99   EnablePropertyNotifications();
100 }
101
102 void Object::OnSceneObjectRemove()
103 {
104   // Notification for observers
105   for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter )
106   {
107     (*iter)->SceneObjectRemoved(*this);
108   }
109
110   // disable property notifications in scene graph
111   DisablePropertyNotifications();
112 }
113
114 int Object::GetPropertyComponentIndex( Property::Index index ) const
115 {
116   int componentIndex = Property::INVALID_COMPONENT_INDEX;
117
118   const TypeInfo* typeInfo( GetTypeInfo() );
119   if ( typeInfo )
120   {
121     componentIndex = typeInfo->GetComponentIndex(index);
122   }
123
124   // For animatable property, check whether it is registered already and register it if not yet.
125   if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) && ( NULL == RegisterAnimatableProperty(index) ) )
126   {
127     componentIndex = Property::INVALID_COMPONENT_INDEX;
128   }
129
130   return componentIndex;
131 }
132
133 bool Object::Supports( Capability capability ) const
134 {
135   return (capability & SUPPORTED_CAPABILITIES);
136 }
137
138 uint32_t Object::GetPropertyCount() const
139 {
140   uint32_t count = GetDefaultPropertyCount();
141
142   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Default Properties: %d\n", count );
143
144   const TypeInfo* typeInfo( GetTypeInfo() );
145   if ( typeInfo )
146   {
147     uint32_t manual( typeInfo->GetPropertyCount() );
148     count += manual;
149
150     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Manual Properties:  %d\n", manual );
151   }
152
153   uint32_t custom = static_cast<uint32_t>( mCustomProperties.Count() );
154   count += custom;
155   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Custom Properties:  %d\n", custom );
156
157   DALI_LOG_INFO( gLogFilter, Debug::Concise, "Total Properties:   %d\n", count );
158
159   return count;
160 }
161
162 std::string Object::GetPropertyName( Property::Index index ) const
163 {
164   DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index out of bounds" );
165
166   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
167   {
168     std::string string;
169
170     const char * propertyName = GetDefaultPropertyName( index );
171     if( propertyName )
172     {
173       string = propertyName;
174     }
175     return string;
176   }
177
178   if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
179     || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
180   {
181     const TypeInfo* typeInfo( GetTypeInfo() );
182     if ( typeInfo )
183     {
184       return typeInfo->GetPropertyName( index );
185     }
186     else
187     {
188       DALI_ASSERT_ALWAYS( ! "Property index is invalid" );
189     }
190   }
191
192   CustomPropertyMetadata* custom = FindCustomProperty( index );
193   if( custom )
194   {
195     return custom->name;
196   }
197   return "";
198 }
199
200 Property::Index Object::GetPropertyIndex(const std::string& name) const
201 {
202   Property::Index index = GetDefaultPropertyIndex( name );
203
204   if(index == Property::INVALID_INDEX)
205   {
206     const TypeInfo* typeInfo( GetTypeInfo() );
207     if ( typeInfo )
208     {
209       index = typeInfo->GetPropertyIndex( name );
210       if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
211       {
212         // check whether the animatable property is registered already, if not then register one.
213         if ( NULL == RegisterAnimatableProperty(index) )
214         {
215           index = Property::INVALID_INDEX;
216         }
217       }
218     }
219   }
220
221   if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
222   {
223     Property::Index count = PROPERTY_CUSTOM_START_INDEX;
224     const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
225     for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
226     {
227       CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
228       if ( custom->name == name )
229       {
230         if ( custom->childPropertyIndex != Property::INVALID_INDEX )
231         {
232           // If it is a child property, return the child property index
233           index = custom->childPropertyIndex;
234         }
235         else
236         {
237           index = count;
238         }
239         break;
240       }
241     }
242   }
243
244   return index;
245 }
246
247 Property::Index Object::GetPropertyIndex( Property::Index key ) const
248 {
249   Property::Index index = Property::INVALID_INDEX;
250
251   if( mCustomProperties.Count() > 0 )
252   {
253     Property::Index count = PROPERTY_CUSTOM_START_INDEX;
254     const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
255     for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
256     {
257       CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
258       if( custom->key == key )
259       {
260         if( custom->childPropertyIndex != Property::INVALID_INDEX )
261         {
262           // If it is a child property, return the child property index
263           index = custom->childPropertyIndex;
264         }
265         else
266         {
267           index = count;
268         }
269         break;
270       }
271     }
272   }
273
274   return index;
275 }
276
277 Property::Index Object::GetPropertyIndex( Property::Key key ) const
278 {
279   Property::Index index = Property::INVALID_INDEX;
280   if( key.type == Property::Key::INDEX )
281   {
282     index = GetPropertyIndex( key.indexKey );
283   }
284   else
285   {
286     index = GetPropertyIndex( key.stringKey );
287   }
288   return index;
289 }
290
291 bool Object::IsPropertyWritable( Property::Index index ) const
292 {
293   DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
294
295   bool writable = false;
296
297   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
298   {
299     writable = IsDefaultPropertyWritable( index );
300   }
301   else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
302   {
303     const TypeInfo* typeInfo( GetTypeInfo() );
304     if ( typeInfo )
305     {
306       writable = typeInfo->IsPropertyWritable( index );
307     }
308     else
309     {
310       DALI_ASSERT_ALWAYS( ! "Invalid property index" );
311     }
312   }
313   else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
314   {
315     // Type Registry scene-graph properties are writable.
316     writable = true;
317   }
318   else
319   {
320     CustomPropertyMetadata* custom = FindCustomProperty( index );
321     if( custom )
322     {
323       writable = custom->IsWritable();
324     }
325   }
326
327   return writable;
328 }
329
330 bool Object::IsPropertyAnimatable( Property::Index index ) const
331 {
332   DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
333
334   bool animatable = false;
335
336   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
337   {
338     animatable = IsDefaultPropertyAnimatable( index );
339   }
340   else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
341   {
342     // Type Registry event-thread only properties are not animatable.
343     animatable = false;
344   }
345   else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
346   {
347     // Type Registry scene-graph properties are animatable.
348     animatable = true;
349   }
350   else
351   {
352     CustomPropertyMetadata* custom = FindCustomProperty( index );
353     if( custom )
354     {
355       animatable = custom->IsAnimatable();
356     }
357   }
358
359   return animatable;
360 }
361
362 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
363 {
364   DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
365
366   bool isConstraintInput = false;
367
368   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
369   {
370     isConstraintInput = IsDefaultPropertyAConstraintInput( index );
371   }
372   else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
373   {
374     // Type Registry event-thread only properties cannot be used as an input to a constraint.
375     isConstraintInput = false;
376   }
377   else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
378   {
379     // scene graph properties can be used as input to a constraint.
380     isConstraintInput = true;
381   }
382   else
383   {
384     CustomPropertyMetadata* custom = FindCustomProperty( index );
385     if( custom )
386     {
387       // ... custom properties can be used as input to a constraint.
388       isConstraintInput = true;
389     }
390   }
391
392   return isConstraintInput;
393 }
394
395 Property::Type Object::GetPropertyType( Property::Index index ) const
396 {
397   DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
398
399   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
400   {
401     return GetDefaultPropertyType( index );
402   }
403
404   if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
405     || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
406   {
407     const TypeInfo* typeInfo( GetTypeInfo() );
408     if ( typeInfo )
409     {
410       return typeInfo->GetPropertyType( index );
411     }
412     else
413     {
414       DALI_ASSERT_ALWAYS( ! "Cannot find property index" );
415     }
416   }
417
418   CustomPropertyMetadata* custom = FindCustomProperty( index );
419   if( custom )
420   {
421     return custom->GetType();
422   }
423
424   return Property::NONE;
425 }
426
427 DevelHandle::PropertySetSignalType& Object::PropertySetSignal()
428 {
429   return mPropertySetSignal;
430 }
431
432 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
433 {
434   DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
435
436   bool propertySet( true );
437
438   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
439   {
440     SetDefaultProperty( index, propertyValue );
441   }
442   else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
443   {
444     const TypeInfo* typeInfo( GetTypeInfo() );
445     if ( typeInfo )
446     {
447       typeInfo->SetProperty( this, index, propertyValue );
448     }
449     else
450     {
451       DALI_LOG_ERROR("Cannot find property index\n");
452       propertySet = false;
453     }
454   }
455   else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
456   {
457     // check whether the animatable property is registered already, if not then register one.
458     AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
459     if(!animatableProperty)
460     {
461       DALI_LOG_ERROR("Cannot find property index\n");
462       propertySet = false;
463     }
464     else
465     {
466       // update the cached property value
467       animatableProperty->SetPropertyValue( propertyValue );
468
469       // set the scene graph property value
470       SetSceneGraphProperty( index, *animatableProperty, propertyValue );
471     }
472   }
473   else
474   {
475     CustomPropertyMetadata* custom = FindCustomProperty( index );
476
477     if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
478     {
479       if( !custom )
480       {
481         // If the child property is not registered yet, register it.
482         custom = new CustomPropertyMetadata( "", propertyValue, Property::READ_WRITE );
483         mCustomProperties.PushBack( custom );
484       }
485
486       custom->childPropertyIndex = index;
487
488       // Resolve name for the child property
489       Object* parent = GetParentObject();
490       if( parent )
491       {
492         const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
493         if( parentTypeInfo )
494         {
495           custom->name = parentTypeInfo->GetChildPropertyName( index );
496         }
497       }
498     }
499
500     if( custom )
501     {
502       if( custom->IsAnimatable() )
503       {
504         // update the cached property value
505         custom->SetPropertyValue( propertyValue );
506
507         // set the scene graph property value
508         SetSceneGraphProperty( index, *custom, propertyValue );
509       }
510       else if( custom->IsWritable() )
511       {
512         // update the cached property value
513         custom->SetPropertyValue( propertyValue );
514       }
515       else
516       {
517         // trying to set value on read only property is no-op
518         propertySet = false;
519       }
520     }
521     else
522     {
523       DALI_LOG_ERROR("Invalid property index\n");
524       propertySet = false;
525     }
526   }
527
528   // Let derived classes know that a property has been set
529   // TODO: We should not call this for read-only properties, SetDefaultProperty() && TypeInfo::SetProperty() should return a bool, which would be true if the property is set
530   if ( propertySet )
531   {
532     OnPropertySet( index, propertyValue );
533     Dali::Handle handle( this );
534     mPropertySetSignal.Emit( handle, index, propertyValue );
535   }
536 }
537
538 Property::Value Object::GetProperty(Property::Index index) const
539 {
540   DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
541
542   Property::Value value;
543
544   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
545   {
546     value = GetDefaultProperty( index );
547   }
548   else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
549   {
550     const TypeInfo* typeInfo( GetTypeInfo() );
551     if ( typeInfo )
552     {
553       value = typeInfo->GetProperty( this, index );
554     }
555     else
556     {
557       DALI_LOG_ERROR("Cannot find property index\n");
558     }
559   }
560   else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
561   {
562     // check whether the animatable property is registered already, if not then register one.
563     AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
564     if(!animatableProperty)
565     {
566       DALI_LOG_ERROR("Cannot find property index\n");
567     }
568     else
569     {
570       // get the cached animatable property value
571       value = animatableProperty->GetPropertyValue();
572     }
573   }
574   else if(mCustomProperties.Count() > 0)
575   {
576     CustomPropertyMetadata* custom = FindCustomProperty( index );
577     if(custom)
578     {
579       // get the cached custom property value
580       value = custom->GetPropertyValue();
581     }
582     else
583     {
584       DALI_LOG_ERROR("Invalid property index\n");
585     }
586   } // if custom
587
588   return value;
589 }
590
591 Property::Value Object::GetCurrentProperty( Property::Index index ) const
592 {
593   DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
594
595   Property::Value value;
596
597   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
598   {
599     value = GetDefaultPropertyCurrentValue( index );
600   }
601   else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
602   {
603     const TypeInfo* typeInfo( GetTypeInfo() );
604     if ( typeInfo )
605     {
606       value = typeInfo->GetProperty( this, index );
607     }
608     else
609     {
610       DALI_LOG_ERROR("Cannot find property index\n");
611     }
612   }
613   else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
614   {
615     // check whether the animatable property is registered already, if not then register one.
616     AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
617     if(!animatableProperty)
618     {
619       DALI_LOG_ERROR("Cannot find property index\n");
620     }
621     else
622     {
623       // get the animatable property value
624       value = GetCurrentPropertyValue( animatableProperty );
625     }
626   }
627   else if(mCustomProperties.Count() > 0)
628   {
629     CustomPropertyMetadata* custom = FindCustomProperty( index );
630     if(custom)
631     {
632       // get the custom property value
633       value = GetCurrentPropertyValue( custom );
634     }
635     else
636     {
637       DALI_LOG_ERROR("Invalid property index\n");
638     }
639   } // if custom
640
641   return value;
642 }
643
644 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
645 {
646   indices.Clear();
647
648   // Default Properties
649   GetDefaultPropertyIndices( indices );
650
651   // Manual Properties
652   const TypeInfo* typeInfo( GetTypeInfo() );
653   if ( typeInfo )
654   {
655     typeInfo->GetPropertyIndices( indices );
656   }
657
658   // Custom Properties
659   if ( mCustomProperties.Count() > 0 )
660   {
661     indices.Reserve( indices.Size() + mCustomProperties.Count() );
662
663     PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin();
664     const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End();
665     int i=0;
666     for ( ; iter != endIter; ++iter, ++i )
667     {
668       CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( *iter );
669       if ( custom->childPropertyIndex != Property::INVALID_INDEX )
670       {
671         // If it is a child property, add the child property index
672         indices.PushBack( custom->childPropertyIndex );
673       }
674       else
675       {
676         indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i );
677       }
678     }
679   }
680 }
681
682 bool Object::DoesCustomPropertyExist( Property::Index index )
683 {
684   auto metadata = FindCustomProperty( index );
685   return metadata != nullptr;
686 }
687
688 Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue) const
689 {
690   // Create a new property
691   Dali::Internal::OwnerPointer<PropertyBase> newProperty;
692
693   switch ( propertyValue.GetType() )
694   {
695     case Property::BOOLEAN:
696     {
697       newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
698       break;
699     }
700
701     case Property::INTEGER:
702     {
703       newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
704       break;
705     }
706
707     case Property::FLOAT:
708     {
709       newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
710       break;
711     }
712
713     case Property::VECTOR2:
714     {
715       newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
716       break;
717     }
718
719     case Property::VECTOR3:
720     {
721       newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
722       break;
723     }
724
725     case Property::VECTOR4:
726     {
727       newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
728       break;
729     }
730
731     case Property::MATRIX:
732     {
733       newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
734       break;
735     }
736
737     case Property::MATRIX3:
738     {
739       newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
740       break;
741     }
742
743     case Property::ROTATION:
744     {
745       newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
746       break;
747     }
748
749     case Property::RECTANGLE:
750     case Property::STRING:
751     case Property::ARRAY:
752     case Property::MAP:
753     case Property::EXTENTS:
754     case Property::NONE:
755     {
756       DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
757       break;
758     }
759   }
760
761   // get the scene property owner from derived class
762   const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
763   // we can only pass properties to scene graph side if there is a scene object
764   if( scenePropertyOwner )
765   {
766     // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
767     const PropertyBase* property = newProperty.Get();
768     if(index >= PROPERTY_CUSTOM_START_INDEX)
769     {
770       DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
771
772       mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue, property ) );
773     }
774     else
775     {
776       mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue, property ) );
777     }
778
779     // queue a message to add the property
780     InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty ); // Message takes ownership
781
782     return index;
783   }
784   else
785   {
786     // property was orphaned and killed so return invalid index
787     return Property::INVALID_INDEX;
788   }
789 }
790
791 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
792 {
793   return RegisterProperty( name, Property::INVALID_KEY, propertyValue, Property::ANIMATABLE );
794 }
795
796 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue )
797 {
798   return RegisterProperty( name, key, propertyValue, Property::ANIMATABLE );
799 }
800
801 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
802 {
803   return RegisterProperty( name, Property::INVALID_KEY, propertyValue, accessMode );
804 }
805
806 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode )
807 {
808   // If property with the required key already exists, then just set it.
809   Property::Index index = Property::INVALID_INDEX;
810   if( key != Property::INVALID_KEY ) // Try integer key first if it's valid
811   {
812     index = GetPropertyIndex( key );
813   }
814   if( index == Property::INVALID_INDEX ) // If it wasn't valid, or doesn't exist, try name
815   {
816     index = GetPropertyIndex( name );
817   }
818
819   if( index != Property::INVALID_INDEX ) // If there was a valid index found by either key, set it.
820   {
821     SetProperty( index, propertyValue );
822   }
823   else
824   {
825     // Otherwise register the property
826
827     if( Property::ANIMATABLE == accessMode )
828     {
829       index = RegisterSceneGraphProperty( name, key, PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() ), propertyValue );
830       AddUniformMapping( index, name );
831     }
832     else
833     {
834       // Add entry to the property lookup
835       index = PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() );
836
837       CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
838
839       // Resolve index for the child property
840       Object* parent = GetParentObject();
841       if( parent )
842       {
843         const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
844         if( parentTypeInfo )
845         {
846           Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
847           if( childPropertyIndex != Property::INVALID_INDEX )
848           {
849             customProperty->childPropertyIndex = childPropertyIndex;
850             index = childPropertyIndex;
851           }
852         }
853       }
854
855       mCustomProperties.PushBack( customProperty );
856     }
857   }
858
859   return index;
860 }
861
862 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
863                                                                 int componentIndex,
864                                                                 const Dali::PropertyCondition& condition)
865 {
866   if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
867   {
868     if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
869     {
870       DALI_ABORT( "Property notification added to event side only property." );
871     }
872     else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
873     {
874       // check whether the animatable property is registered already, if not then register one.
875       AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index );
876       DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
877     }
878     else if ( mCustomProperties.Count() > 0 )
879     {
880       CustomPropertyMetadata* custom = FindCustomProperty( index );
881       DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
882       DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
883     }
884   }
885
886   Dali::Handle self(this);
887   Property target( self, index );
888
889   PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
890   Dali::PropertyNotification propertyNotification(internal.Get());
891
892   if( !mPropertyNotifications )
893   {
894     mPropertyNotifications = new PropertyNotificationContainer;
895   }
896   mPropertyNotifications->push_back(propertyNotification);
897
898   return propertyNotification;
899 }
900
901 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
902 {
903   if( mPropertyNotifications )
904   {
905     PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
906     while(iter != mPropertyNotifications->end() )
907     {
908       if(*iter == propertyNotification)
909       {
910         mPropertyNotifications->erase(iter);
911         // As we can't ensure all references are removed, we can just disable
912         // the notification.
913         GetImplementation(propertyNotification).Disable();
914         return;
915       }
916       ++iter;
917     }
918   }
919 }
920
921 void Object::RemovePropertyNotifications()
922 {
923   if( mPropertyNotifications )
924   {
925     PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
926     while(iter != mPropertyNotifications->end() )
927     {
928       // As we can't ensure all references are removed, we can just disable
929       // the notification.
930       GetImplementation(*iter).Disable();
931       ++iter;
932     }
933
934     mPropertyNotifications->clear();
935   }
936 }
937
938 void Object::NotifyPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType )
939 {
940   if ( index < DEFAULT_PROPERTY_MAX_COUNT )
941   {
942     OnNotifyDefaultPropertyAnimation( animation, index, value, animationType );
943   }
944   else
945   {
946     PropertyMetadata* propertyMetadata = NULL;
947     if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
948     {
949       propertyMetadata = FindAnimatableProperty( index );
950     }
951     else
952     {
953       CustomPropertyMetadata* custom = FindCustomProperty( index );
954       if( custom && custom->IsAnimatable() )
955       {
956         propertyMetadata = custom;
957       }
958     }
959
960     if( propertyMetadata )
961     {
962       switch( animationType )
963       {
964         case Animation::TO:
965         case Animation::BETWEEN:
966         {
967           // Update the cached property value
968           propertyMetadata->SetPropertyValue( value );
969           break;
970         }
971         case Animation::BY:
972         {
973           // Adjust the cached property value
974           propertyMetadata->AdjustPropertyValueBy( value );
975           break;
976         }
977       }
978     }
979   }
980 }
981
982 void Object::EnablePropertyNotifications()
983 {
984   if( mPropertyNotifications )
985   {
986     PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
987     PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
988
989     for( ; iter != endIter; ++iter )
990     {
991       GetImplementation(*iter).Enable();
992     }
993   }
994 }
995
996 void Object::DisablePropertyNotifications()
997 {
998   if( mPropertyNotifications )
999   {
1000     PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
1001     PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
1002
1003     for( ; iter != endIter; ++iter )
1004     {
1005       GetImplementation(*iter).Disable();
1006     }
1007   }
1008 }
1009
1010 void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
1011 {
1012   // Get the address of the property if it's a scene property
1013   const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
1014
1015   // Check instead for newly registered properties
1016   if( propertyPtr == NULL )
1017   {
1018     PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex );
1019     if( animatable != NULL )
1020     {
1021       propertyPtr = animatable->GetSceneGraphProperty();
1022     }
1023   }
1024
1025   if( propertyPtr == NULL )
1026   {
1027     PropertyMetadata* custom = FindCustomProperty( propertyIndex );
1028     if( custom != NULL )
1029     {
1030       propertyPtr = custom->GetSceneGraphProperty();
1031     }
1032   }
1033
1034   if( propertyPtr != NULL )
1035   {
1036     const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner();
1037
1038     if( sceneObject != NULL )
1039     {
1040       OwnerPointer< SceneGraph::UniformPropertyMapping > map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
1041       // Message takes ownership of Uniform map (and will delete it after copy)
1042       AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map );
1043     }
1044     else
1045     {
1046       DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" );
1047     }
1048   }
1049 }
1050
1051 void Object::RemoveUniformMapping( const std::string& uniformName )
1052 {
1053   const SceneGraph::PropertyOwner* sceneObject = GetSceneObject();
1054   RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName);
1055 }
1056
1057 Property::Value Object::GetCurrentPropertyValue( const PropertyMetadata* entry ) const
1058 {
1059   Property::Value value;
1060
1061   DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
1062
1063   if( !entry->IsAnimatable() )
1064   {
1065     value = entry->GetPropertyValue();
1066   }
1067   else
1068   {
1069     BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
1070
1071     switch ( entry->GetType() )
1072     {
1073       case Property::BOOLEAN:
1074       {
1075         const AnimatableProperty<bool>* property = static_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
1076         DALI_ASSERT_DEBUG( NULL != property );
1077
1078         value = (*property)[ bufferIndex ];
1079         break;
1080       }
1081
1082       case Property::INTEGER:
1083       {
1084         const AnimatableProperty<int>* property = static_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
1085         DALI_ASSERT_DEBUG( NULL != property );
1086
1087         value = (*property)[ bufferIndex ];
1088         break;
1089       }
1090
1091       case Property::FLOAT:
1092       {
1093         const AnimatableProperty<float>* property = static_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
1094         DALI_ASSERT_DEBUG( NULL != property );
1095
1096         value = (*property)[ bufferIndex ];
1097         break;
1098       }
1099
1100       case Property::VECTOR2:
1101       {
1102         const AnimatableProperty<Vector2>* property = static_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
1103         DALI_ASSERT_DEBUG( NULL != property );
1104
1105         if(entry->componentIndex == 0)
1106         {
1107           value = (*property)[ bufferIndex ].x;
1108         }
1109         else if(entry->componentIndex == 1)
1110         {
1111           value = (*property)[ bufferIndex ].y;
1112         }
1113         else
1114         {
1115           value = (*property)[ bufferIndex ];
1116         }
1117         break;
1118       }
1119
1120       case Property::VECTOR3:
1121       {
1122         const AnimatableProperty<Vector3>* property = static_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
1123         DALI_ASSERT_DEBUG( NULL != property );
1124
1125         if(entry->componentIndex == 0)
1126         {
1127           value = (*property)[ bufferIndex ].x;
1128         }
1129         else if(entry->componentIndex == 1)
1130         {
1131           value = (*property)[ bufferIndex ].y;
1132         }
1133         else if(entry->componentIndex == 2)
1134         {
1135           value = (*property)[ bufferIndex ].z;
1136         }
1137         else
1138         {
1139           value = (*property)[ bufferIndex ];
1140         }
1141         break;
1142       }
1143
1144       case Property::VECTOR4:
1145       {
1146         const AnimatableProperty<Vector4>* property = static_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
1147         DALI_ASSERT_DEBUG( NULL != property );
1148
1149         if(entry->componentIndex == 0)
1150         {
1151           value = (*property)[ bufferIndex ].x;
1152         }
1153         else if(entry->componentIndex == 1)
1154         {
1155           value = (*property)[ bufferIndex ].y;
1156         }
1157         else if(entry->componentIndex == 2)
1158         {
1159           value = (*property)[ bufferIndex ].z;
1160         }
1161         else if(entry->componentIndex == 3)
1162         {
1163           value = (*property)[ bufferIndex ].w;
1164         }
1165         else
1166         {
1167           value = (*property)[ bufferIndex ];
1168         }
1169         break;
1170       }
1171
1172       case Property::MATRIX:
1173       {
1174         const AnimatableProperty<Matrix>* property = static_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
1175         DALI_ASSERT_DEBUG( NULL != property );
1176
1177         value = (*property)[ bufferIndex ];
1178         break;
1179       }
1180
1181       case Property::MATRIX3:
1182       {
1183         const AnimatableProperty<Matrix3>* property = static_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
1184         DALI_ASSERT_DEBUG( NULL != property );
1185
1186         value = (*property)[ bufferIndex ];
1187         break;
1188       }
1189
1190       case Property::ROTATION:
1191       {
1192         const AnimatableProperty<Quaternion>* property = static_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
1193         DALI_ASSERT_DEBUG( NULL != property );
1194
1195         value = (*property)[ bufferIndex ];
1196         break;
1197       }
1198
1199       default:
1200       {
1201         // unreachable code due to higher level logic
1202       }
1203     } // switch(type)
1204   } // if animatable
1205
1206   return value;
1207 }
1208
1209 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
1210 {
1211   switch ( entry.GetType() )
1212   {
1213     case Property::BOOLEAN:
1214     {
1215       const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
1216       DALI_ASSERT_DEBUG( NULL != property );
1217
1218       // property is being used in a separate thread; queue a message to set the property
1219       BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
1220       break;
1221     }
1222
1223     case Property::INTEGER:
1224     {
1225       const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
1226       DALI_ASSERT_DEBUG( NULL != property );
1227
1228       // property is being used in a separate thread; queue a message to set the property
1229       BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
1230       break;
1231     }
1232
1233     case Property::FLOAT:
1234     {
1235       const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1236       DALI_ASSERT_DEBUG( NULL != property );
1237
1238       // property is being used in a separate thread; queue a message to set the property
1239       BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
1240       break;
1241     }
1242
1243     case Property::VECTOR2:
1244     {
1245       const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1246       DALI_ASSERT_DEBUG( NULL != property );
1247
1248       // property is being used in a separate thread; queue a message to set the property
1249       if(entry.componentIndex == 0)
1250       {
1251         SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1252       }
1253       else if(entry.componentIndex == 1)
1254       {
1255         SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1256       }
1257       else
1258       {
1259         BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
1260       }
1261       break;
1262     }
1263
1264     case Property::VECTOR3:
1265     {
1266       const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1267       DALI_ASSERT_DEBUG( NULL != property );
1268
1269       // property is being used in a separate thread; queue a message to set the property
1270       if(entry.componentIndex == 0)
1271       {
1272         SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1273       }
1274       else if(entry.componentIndex == 1)
1275       {
1276         SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1277       }
1278       else if(entry.componentIndex == 2)
1279       {
1280         SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1281       }
1282       else
1283       {
1284         BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1285       }
1286
1287       break;
1288     }
1289
1290     case Property::VECTOR4:
1291     {
1292       const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1293       DALI_ASSERT_DEBUG( NULL != property );
1294
1295       // property is being used in a separate thread; queue a message to set the property
1296       if(entry.componentIndex == 0)
1297       {
1298         SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1299       }
1300       else if(entry.componentIndex == 1)
1301       {
1302         SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1303       }
1304       else if(entry.componentIndex == 2)
1305       {
1306         SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1307       }
1308       else if(entry.componentIndex == 3)
1309       {
1310         SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1311       }
1312       else
1313       {
1314         BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1315       }
1316       break;
1317     }
1318
1319     case Property::ROTATION:
1320     {
1321       const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1322       DALI_ASSERT_DEBUG( NULL != property );
1323
1324       // property is being used in a separate thread; queue a message to set the property
1325       BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1326       break;
1327     }
1328
1329     case Property::MATRIX:
1330     {
1331       const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1332       DALI_ASSERT_DEBUG( NULL != property );
1333
1334       // property is being used in a separate thread; queue a message to set the property
1335       BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1336       break;
1337     }
1338
1339     case Property::MATRIX3:
1340     {
1341       const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1342       DALI_ASSERT_DEBUG( NULL != property );
1343
1344       // property is being used in a separate thread; queue a message to set the property
1345       BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1346       break;
1347     }
1348
1349     default:
1350     {
1351       // non-animatable scene graph property, do nothing
1352     }
1353   }
1354 }
1355
1356 const TypeInfo* Object::GetTypeInfo() const
1357 {
1358   if ( !mTypeInfo )
1359   {
1360     // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1361     // especially as the type-info does not change during the life-time of an application
1362
1363     Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1364     if ( typeInfoHandle )
1365     {
1366       mTypeInfo = &GetImplementation( typeInfoHandle );
1367     }
1368   }
1369
1370   return mTypeInfo;
1371 }
1372
1373 void Object::ApplyConstraint( ConstraintBase& constraint )
1374 {
1375   if( !mConstraints )
1376   {
1377     mConstraints = new ConstraintContainer;
1378   }
1379   mConstraints->push_back( Dali::Constraint( &constraint ) );
1380 }
1381
1382 void Object::RemoveConstraint( ConstraintBase& constraint )
1383 {
1384   // NULL if the Constraint sources are destroyed before Constraint::Apply()
1385   if( mConstraints )
1386   {
1387     ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1388     if( it != mConstraints->end() )
1389     {
1390       mConstraints->erase( it );
1391     }
1392   }
1393 }
1394
1395 void Object::RemoveConstraints()
1396 {
1397   // guard against constraint sending messages during core destruction
1398   if( mConstraints && Stage::IsInstalled() )
1399   {
1400     // If we have nothing in the scene-graph, just clear constraint containers
1401     const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1402     if ( NULL != propertyOwner )
1403     {
1404       const ConstraintConstIter endIter = mConstraints->end();
1405       for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1406       {
1407         GetImplementation( *iter ).RemoveInternal();
1408       }
1409     }
1410
1411     delete mConstraints;
1412     mConstraints = NULL;
1413   }
1414 }
1415
1416 void Object::RemoveConstraints( uint32_t tag )
1417 {
1418   // guard against constraint sending messages during core destruction
1419   if( mConstraints && Stage::IsInstalled() )
1420   {
1421     ConstraintIter iter( mConstraints->begin() );
1422     while(iter != mConstraints->end() )
1423     {
1424       ConstraintBase& constraint = GetImplementation( *iter );
1425       if( constraint.GetTag() == tag )
1426       {
1427         GetImplementation( *iter ).RemoveInternal();
1428         iter = mConstraints->erase( iter );
1429       }
1430       else
1431       {
1432         ++iter;
1433       }
1434     }
1435
1436     if ( mConstraints->empty() )
1437     {
1438       delete mConstraints;
1439       mConstraints = NULL;
1440     }
1441   }
1442 }
1443
1444 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1445 {
1446   mTypeInfo = typeInfo;
1447 }
1448
1449 Object::~Object()
1450 {
1451   // Notification for observers
1452   for( ConstObserverIter iter = mObservers.Begin(), endIter =  mObservers.End(); iter != endIter; ++iter)
1453   {
1454     (*iter)->ObjectDestroyed(*this);
1455   }
1456
1457   delete mConstraints;
1458   delete mPropertyNotifications;
1459 }
1460
1461 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1462 {
1463   CustomPropertyMetadata* property( NULL );
1464   if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
1465   {
1466     for ( std::size_t arrayIndex = 0; arrayIndex < mCustomProperties.Count(); arrayIndex++ )
1467     {
1468       CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1469       if( custom->childPropertyIndex == index )
1470       {
1471         property = custom;
1472       }
1473     }
1474   }
1475   else
1476   {
1477     int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1478     if( arrayIndex >= 0 )
1479     {
1480       if( arrayIndex < static_cast<int>( mCustomProperties.Count() ) ) // we can only access the first 2 billion custom properties
1481       {
1482         property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1483       }
1484     }
1485   }
1486   return property;
1487 }
1488
1489 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1490 {
1491   const PropertyMetadataLookup::SizeType count = mAnimatableProperties.Count();
1492   for ( PropertyMetadataLookup::SizeType arrayIndex = 0; arrayIndex < count; ++arrayIndex )
1493   {
1494     AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1495     if( property->index == index )
1496     {
1497       return property;
1498     }
1499   }
1500   return NULL;
1501 }
1502
1503 AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
1504 {
1505   DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
1506                       && "Property index is out of bounds" );
1507
1508   // check whether the animatable property is registered already, if not then register one.
1509   AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1510   if( !animatableProperty )
1511   {
1512     const TypeInfo* typeInfo( GetTypeInfo() );
1513     if( typeInfo )
1514     {
1515       Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1516       if( basePropertyIndex == Property::INVALID_INDEX )
1517       {
1518         // If the property is not a component of a base property, register the whole property itself.
1519         const  std::string& propertyName = typeInfo->GetPropertyName(index);
1520         RegisterSceneGraphProperty(propertyName, Property::INVALID_KEY, index, typeInfo->GetPropertyDefaultValue(index));
1521         AddUniformMapping( index, propertyName );
1522       }
1523       else
1524       {
1525         // Since the property is a component of a base property, check whether the base property is registered.
1526         animatableProperty = FindAnimatableProperty( basePropertyIndex );
1527         if( !animatableProperty )
1528         {
1529           // If the base property is not registered yet, register the base property first.
1530           const  std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
1531
1532           if( Property::INVALID_INDEX != RegisterSceneGraphProperty( basePropertyName, Property::INVALID_KEY, basePropertyIndex, typeInfo->GetPropertyDefaultValue( basePropertyIndex ) ) )
1533           {
1534             animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1535             AddUniformMapping( basePropertyIndex, basePropertyName );
1536           }
1537         }
1538
1539         if(animatableProperty)
1540         {
1541           // Create the metadata for the property component.
1542           mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->value, animatableProperty->GetSceneGraphProperty() ) );
1543         }
1544       }
1545
1546       // The metadata has just been added and therefore should be in the end of the vector.
1547       animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1548     }
1549   }
1550
1551   return animatableProperty;
1552 }
1553
1554 void Object::ResolveChildProperties()
1555 {
1556   // Resolve index for the child property
1557   Object* parent = GetParentObject();
1558   if( parent )
1559   {
1560     const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
1561     if( parentTypeInfo )
1562     {
1563       // Go through each custom property
1564       const PropertyMetadataLookup::SizeType count = mCustomProperties.Count();
1565       for ( PropertyMetadataLookup::SizeType arrayIndex = 0; arrayIndex < count; ++arrayIndex )
1566       {
1567         CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1568
1569         if( customProperty->name == "" )
1570         {
1571           if( customProperty->childPropertyIndex != Property::INVALID_INDEX )
1572           {
1573             // Resolve name for any child property with no name
1574             customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex );
1575           }
1576         }
1577         else
1578         {
1579           Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
1580           if( childPropertyIndex != Property::INVALID_INDEX )
1581           {
1582             // Resolve index for any property with a name that matches the parent's child property name
1583             customProperty->childPropertyIndex = childPropertyIndex;
1584           }
1585         }
1586       }
1587     }
1588   }
1589 }
1590
1591 } // namespace Internal
1592
1593 } // namespace Dali