UTC tests; PropertyValue, Vector2/3/4, Matrix
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-value.cpp
index 2d91f3e..695956d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,9 @@
 // CLASS HEADER
 #include <dali/public-api/object/property-value.h>
 
+// EXTERNAL INCLUDES
+#include <ostream>
+
 // INTERNAL INCLUDES
 #include <dali/public-api/object/any.h>
 #include <dali/public-api/math/angle-axis.h>
@@ -296,7 +299,18 @@ Property::Value::Value(const Value& value)
 
     case Property::ROTATION:
     {
-      mImpl = new Impl( value.Get<Quaternion>() );
+      // Orientations have two representations
+      DALI_ASSERT_DEBUG( typeid(Quaternion) == value.mImpl->mValue.GetType() ||
+                         typeid(AngleAxis)  == value.mImpl->mValue.GetType() );
+
+      if ( typeid(Quaternion) == value.mImpl->mValue.GetType() )
+      {
+        mImpl = new Impl( value.Get<Quaternion>() );
+      }
+      else
+      {
+        mImpl = new Impl( value.Get<AngleAxis>() );
+      }
       break;
     }
 
@@ -393,7 +407,7 @@ Property::Value::Value(Type type)
 
     case Property::ROTATION:
     {
-      mImpl = new Impl( Quaternion(0.f, Vector4::YAXIS) );
+      mImpl = new Impl( Quaternion( Radian(0.f), Vector3::YAXIS) );
       break;
     }
 
@@ -498,7 +512,18 @@ Property::Value& Property::Value::operator=(const Property::Value& value)
 
     case Property::ROTATION:
     {
-      mImpl->mValue = value.Get<Quaternion>();
+      // Orientations have two representations
+      DALI_ASSERT_DEBUG( typeid(Quaternion) == value.mImpl->mValue.GetType() ||
+                         typeid(AngleAxis)  == value.mImpl->mValue.GetType() );
+
+      if ( typeid(Quaternion) == value.mImpl->mValue.GetType() )
+      {
+        mImpl = new Impl( value.Get<Quaternion>() );
+      }
+      else
+      {
+        mImpl = new Impl( value.Get<AngleAxis>() );
+      }
       break;
     }
 
@@ -628,9 +653,7 @@ void Property::Value::Get(AngleAxis& angleAxisValue) const
   {
     Quaternion quaternion = AnyCast<Quaternion>(mImpl->mValue);
 
-    Radian angleRadians(0.0f);
-    quaternion.ToAxisAngle( angleAxisValue.axis, angleRadians );
-    angleAxisValue.angle = angleRadians;
+    quaternion.ToAxisAngle( angleAxisValue.axis, angleAxisValue.angle );
   }
   else
   {
@@ -975,5 +998,108 @@ int Property::Value::GetSize() const
   return ret;
 }
 
+std::ostream& operator<< (std::ostream& stream, const Property::Value& value )
+{
+
+  const Property::Value::Impl& impl( *value.mImpl );
+
+  switch( impl.mType )
+  {
+    case Dali::Property::STRING:
+    {
+      stream <<  AnyCast<std::string>(impl.mValue).c_str();
+      break;
+    }
+    case Dali::Property::VECTOR2:
+    {
+      stream << AnyCast<Vector2>(impl.mValue);
+      break;
+    }
+    case Dali::Property::VECTOR3:
+    {
+      stream << AnyCast<Vector3>(impl.mValue);
+      break;
+    }
+    case Dali::Property::VECTOR4:
+    {
+      stream << AnyCast<Vector4>(impl.mValue);
+      break;
+    }
+    case Dali::Property::MATRIX:
+    {
+      stream << AnyCast<Matrix>(impl.mValue);
+      break;
+    }
+    case Dali::Property::BOOLEAN:
+    {
+      stream << AnyCast<bool>(impl.mValue);
+      break;
+    }
+    case Dali::Property::FLOAT:
+    {
+      stream << AnyCast<float>(impl.mValue);
+      break;
+    }
+    case Dali::Property::INTEGER:
+    {
+       stream << AnyCast<int>(impl.mValue);
+       break;
+    }
+    case Dali::Property::UNSIGNED_INTEGER:
+    {
+      stream << AnyCast<unsigned int>(impl.mValue);
+      break;
+    }
+    case Dali::Property::RECTANGLE:
+    {
+      Dali::Rect<int> rect; // Propery Value rectangles are currently integer based
+      value.Get( rect );
+      stream << rect;
+      break;
+    }
+    case Dali::Property::MATRIX3:
+    {
+      stream << AnyCast<Matrix3>(impl.mValue);
+      break;
+    }
+    case Dali::Property::ROTATION:
+    {
+      // @todo this may change to Quaternion
+      Dali::Quaternion q;
+      value.Get( q );
+      Dali::Vector4 v4 = q.EulerAngles();
+      stream << v4;
+      break;
+    }
+
+    case Dali::Property::ARRAY:
+    {
+      // @todo Need to think about the best way to support array
+      // E.g Do we want to create a JSON style array like:
+      // [ {"property-name-0":"property-value-0", "property-name-1":"property-value-1"} ]
+      stream << "ARRAY unsupported";
+      break;
+    }
+    case Dali::Property::MAP:
+    {
+      Dali::Property::Map map;
+      value.Get( map );
+      stream << "Map containing " << map.Count() << " elements";
+      break;
+    }
+    case Dali::Property::TYPE_COUNT:
+    {
+      stream << "unsupported TYPE_COUNT";
+      break;
+    }
+    default:
+    {
+      stream << "unsupported type = " << value.GetType();
+      break;
+    }
+  }
+  return stream;
+}
+
 
 } // namespace Dali