Cleaning up the property framework; removal of duplicate methods and incorrect assers
[platform/core/uifw/dali-core.git] / dali / internal / event / modeling / animatable-mesh-impl.cpp
index ae02fe5..1dc391a 100644 (file)
@@ -37,26 +37,18 @@ namespace Internal
 namespace
 {
 
-const std::string DEFAULT_PROPERTY_NAMES[] =
+const PropertyDetails DEFAULT_PROPERTY_DETAILS[] =
 {
-  "position",
-  "vertex-color",
-  "texture-coords"
+ // Name               Type            writable animatable constraint-input
+ { "position",       Property::VECTOR3, true,    true,   true  }, // POSITION
+ { "vertex-color",   Property::VECTOR4, true,    true,   true  }, // COLOR
+ { "texture-coords", Property::VECTOR2, true,    true,   true  }, // TEXTURE_COORDS
 };
-const int VERTEX_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_NAMES ) / sizeof( std::string );
 
-const Property::Type DEFAULT_PROPERTY_TYPES[ VERTEX_PROPERTY_COUNT ] =
-{
-  Property::VECTOR3,  // position
-  Property::VECTOR4,  // Color
-  Property::VECTOR2,  // Texture Coords
-};
+const int VERTEX_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_DETAILS ) / sizeof( DEFAULT_PROPERTY_DETAILS[0] );
 
 } // namespace
 
-AnimatableMesh::DefaultPropertyLookup* AnimatableMesh::mDefaultPropertyLookup = NULL;
-
-
 AnimatableMesh::AnimatableMesh(
   SceneGraph::UpdateManager& updateManager,
   SceneGraph::AnimatableMesh* sceneObject,
@@ -139,12 +131,13 @@ AnimatableMeshPtr AnimatableMesh::New(
 
 AnimatableMesh::~AnimatableMesh()
 {
-  DALI_ASSERT_DEBUG( mSceneObject != NULL );
-
   // Guard to allow handle destruction after Core has been destroyed
   if ( Stage::IsInstalled() )
   {
-    RemoveAnimatableMeshMessage( mUpdateManager, *mSceneObject );
+    if( mSceneObject )
+    {
+      RemoveAnimatableMeshMessage( mUpdateManager, *mSceneObject );
+    }
   }
 }
 
@@ -210,11 +203,6 @@ MeshIPtr AnimatableMesh::GetMesh()
 
 bool AnimatableMesh::Supports( Capability capability ) const
 {
-  return false;
-}
-
-bool AnimatableMesh::IsSceneObjectRemovable() const
-{
   return false; // The scene object is permanently "on stage" whilst this object is alive
 }
 
@@ -233,17 +221,15 @@ void AnimatableMesh::GetDefaultPropertyIndices( Property::IndexContainer& indice
   }
 }
 
-const std::string& AnimatableMesh::GetDefaultPropertyName( Property::Index index ) const
+const char* AnimatableMesh::GetDefaultPropertyName( Property::Index index ) const
 {
   if ( ( index >= 0 ) && ( index < mPropertyCount ) )
   {
-    return DEFAULT_PROPERTY_NAMES[index % VERTEX_PROPERTY_COUNT];
+    return DEFAULT_PROPERTY_DETAILS[index % VERTEX_PROPERTY_COUNT].name;
   }
   else
   {
-    // Index out-of-range... return empty string.
-    static const std::string INVALID_PROPERTY_NAME;
-    return INVALID_PROPERTY_NAME;
+    return NULL;
   }
 }
 
@@ -251,31 +237,39 @@ Property::Index AnimatableMesh::GetDefaultPropertyIndex(const std::string& name)
 {
   Property::Index index = Property::INVALID_INDEX;
 
-  // TODO: Property names should be modified to append the vertex index
-
+  // Look for name in default properties
+  for( int i = 0; i < VERTEX_PROPERTY_COUNT; ++i )
+  {
+    const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
+    if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
+    {
+      index = i;
+      break;
+    }
+  }
   return index;
 }
 
 bool AnimatableMesh::IsDefaultPropertyWritable(Property::Index index) const
 {
-  return true;
+  return DEFAULT_PROPERTY_DETAILS[ index % VERTEX_PROPERTY_COUNT ].writable;
 }
 
 bool AnimatableMesh::IsDefaultPropertyAnimatable(Property::Index index) const
 {
-  return true;
+  return DEFAULT_PROPERTY_DETAILS[ index % VERTEX_PROPERTY_COUNT ].animatable;
 }
 
 bool AnimatableMesh::IsDefaultPropertyAConstraintInput( Property::Index index ) const
 {
-  return true;
+  return DEFAULT_PROPERTY_DETAILS[ index % VERTEX_PROPERTY_COUNT ].constraintInput;
 }
 
 Property::Type AnimatableMesh::GetDefaultPropertyType(Property::Index index) const
 {
   if ( ( index >= 0 ) && ( index < mPropertyCount ) )
   {
-    return DEFAULT_PROPERTY_TYPES[index % VERTEX_PROPERTY_COUNT ];
+    return DEFAULT_PROPERTY_DETAILS[ index % VERTEX_PROPERTY_COUNT ].type;
   }
   else
   {
@@ -286,7 +280,7 @@ Property::Type AnimatableMesh::GetDefaultPropertyType(Property::Index index) con
 
 void AnimatableMesh::SetDefaultProperty( Property::Index index, const Property::Value& property )
 {
-  DALI_ASSERT_ALWAYS( ( index >= 0 ) && ( index < mPropertyCount ) );
+  DALI_ASSERT_ALWAYS( ( index < mPropertyCount ) && "Property index out of bounds" );
 
   int vertexProperty = index % VERTEX_PROPERTY_COUNT;
   int vertexIndex    = index / VERTEX_PROPERTY_COUNT;
@@ -307,14 +301,14 @@ void AnimatableMesh::SetDefaultProperty( Property::Index index, const Property::
       SetTextureCoords( vertexIndex, property.Get<Vector2>() );
       break;
     }
+    default:
+    {
+      // nothing to do
+      break;
+    }
   }
 }
 
-void AnimatableMesh::SetCustomProperty( Property::Index /*index*/, const CustomProperty& /*entry*/, const Property::Value& /*value*/ )
-{
-  DALI_ASSERT_ALWAYS( 0 && "AnimatableMesh does not support custom properties");
-}
-
 Property::Value AnimatableMesh::GetDefaultProperty(Property::Index index) const
 {
   Property::Value value;
@@ -338,16 +332,16 @@ Property::Value AnimatableMesh::GetDefaultProperty(Property::Index index) const
       value = GetCurrentTextureCoords(vertexIndex);
       break;
     }
+    default:
+    {
+      // nothing to do
+      break;
+    }
   }
 
   return value;
 }
 
-void AnimatableMesh::InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index )
-{
-  DALI_ASSERT_ALWAYS( 0 && "AnimatableMesh does not support custom properties" );
-}
-
 const SceneGraph::PropertyOwner* AnimatableMesh::GetSceneObject() const
 {
   return mSceneObject;