[NUI.Scene3D] Make MotionData use Native API, instead of C#
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / ModelMotion / MotionValue.cs
1 /*
2  * Copyright(c) 2023 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 using System;
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using System.Collections.Generic;
22 using Tizen.NUI;
23
24 namespace Tizen.NUI.Scene3D
25 {
26     /// <summary>
27     /// This MotionValue be used for target value of each <see cref="MotionIndex"/>.
28     /// We can get and set MotionValue as 2 types : PropertyValue and KeyFrames.
29     ///
30     /// Each types will be cross-converted internally.
31     /// For example, when we set PropertyValue, we can get KeyFrames with 2 frames, and target value is set.
32     /// </summary>
33     /// <remarks>
34     /// The type of property should be matched with MotionIndex required.
35     /// </remarks>
36     [EditorBrowsable(EditorBrowsableState.Never)]
37     public class MotionValue : BaseHandle
38     {
39         /// <summary>
40         /// Determine whether current stored value is PropertyValue, or KeyFrames.
41         /// </summary>
42         [EditorBrowsable(EditorBrowsableState.Never)]
43         public enum ValueType
44         {
45             /// <summary>
46             /// Value is null, or invalid class.
47             /// </summary>
48             [EditorBrowsable(EditorBrowsableState.Never)]
49             Invalid = -1,
50
51             /// <summary>
52             /// Value is PropertyValue.
53             /// </summary>
54             [EditorBrowsable(EditorBrowsableState.Never)]
55             Property = 0,
56
57             /// <summary>
58             /// Value is KeyFrames.
59             /// </summary>
60             [EditorBrowsable(EditorBrowsableState.Never)]
61             KeyFrames,
62         }
63
64         /// <summary>
65         /// Create an initialized motion value with invalid.
66         /// </summary>
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public MotionValue() : this(Interop.MotionValue.MotionValueNew(), true)
69         {
70             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71         }
72
73         /// <summary>
74         /// Create an initialized motion value with PropertyValue.
75         /// </summary>
76         [EditorBrowsable(EditorBrowsableState.Never)]
77         public MotionValue(PropertyValue propertyValue) : this(Interop.MotionValue.MotionValueNewPropertyValue(PropertyValue.getCPtr(propertyValue)), true)
78         {
79             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80         }
81
82         /// <summary>
83         /// Create an initialized motion value with KeyFrames.
84         /// </summary>
85         [EditorBrowsable(EditorBrowsableState.Never)]
86         public MotionValue(KeyFrames keyFrames) : this(Interop.MotionValue.MotionValueNewKeyFrames(KeyFrames.getCPtr(keyFrames)), true)
87         {
88             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89         }
90
91         /// <summary>
92         /// Copy constructor.
93         /// </summary>
94         /// <param name="motionValue">Source object to copy.</param>
95         [EditorBrowsable(EditorBrowsableState.Never)]
96         public MotionValue(MotionValue motionValue) : this(Interop.MotionValue.NewMotionValue(MotionValue.getCPtr(motionValue)), true)
97         {
98             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99         }
100
101         /// <summary>
102         /// Assignment operator.
103         /// </summary>
104         /// <param name="motionValue">Source object to be assigned.</param>
105         /// <returns>Reference to this.</returns>
106         internal MotionValue Assign(MotionValue motionValue)
107         {
108             MotionValue ret = new MotionValue(Interop.MotionValue.MotionValueAssign(SwigCPtr, MotionValue.getCPtr(motionValue)), false);
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110             return ret;
111         }
112
113         internal MotionValue(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
114         {
115         }
116
117
118         /// <summary>
119         /// Get or set the value as PropertyValue type.
120         /// If ValueType is ValueType.KeyFrames, it will return last value of stored KeyFrames.
121         /// </summary>
122         [EditorBrowsable(EditorBrowsableState.Never)]
123         public PropertyValue PropertyValue
124         {
125             get
126             {
127                 return GetPropertyValue();
128             }
129             set
130             {
131                 SetPropertyValue(value);
132             }
133         }
134
135         /// <summary>
136         /// Get or set the value as KeyFrames type.
137         /// If ValueType is ValueType.PropertyValue, it will create new KeyFrames by stored PropertyValue.
138         /// </summary>
139         [EditorBrowsable(EditorBrowsableState.Never)]
140         public KeyFrames KeyFramesValue
141         {
142             get
143             {
144                 return GetKeyFrames();
145             }
146             set
147             {
148                 SetKeyFrames(value);
149             }
150         }
151
152         /// <summary>
153         /// Get the type of value what we set.
154         /// </summary>
155         [EditorBrowsable(EditorBrowsableState.Never)]
156         public ValueType Type
157         {
158             get
159             {
160                 return GetMotionValueType();
161             }
162         }
163
164         /// <summary>
165         /// Invalidate the value what we set.
166         /// </summary>
167         [EditorBrowsable(EditorBrowsableState.Never)]
168         public void Invalidate()
169         {
170             Interop.MotionValue.Clear(SwigCPtr);
171             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172         }
173
174         internal void SetPropertyValue(PropertyValue propertyValue)
175         {
176             Interop.MotionValue.SetValuePropertyValue(SwigCPtr, PropertyValue.getCPtr(propertyValue));
177             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178         }
179
180         internal PropertyValue GetPropertyValue()
181         {
182             IntPtr cPtr = Interop.MotionValue.GetPropertyValue(SwigCPtr);
183             PropertyValue ret = new PropertyValue(cPtr, true);
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185             return ret;
186         }
187         internal void SetKeyFrames(KeyFrames keyFrames)
188         {
189             Interop.MotionValue.SetValueKeyFrames(SwigCPtr, KeyFrames.getCPtr(keyFrames));
190             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191         }
192
193         internal KeyFrames GetKeyFrames()
194         {
195             IntPtr cPtr = Interop.MotionValue.GetKeyFrames(SwigCPtr);
196             KeyFrames ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as KeyFrames;
197             if (ret == null)
198             {
199                 // Register new animation into Registry.
200                 ret = new KeyFrames(cPtr, true);
201             }
202             else
203             {
204                 // We found matched NUI animation. Reduce cPtr reference count.
205                 HandleRef handle = new HandleRef(this, cPtr);
206                 Tizen.NUI.Interop.KeyFrames.DeleteKeyFrames(handle);
207                 handle = new HandleRef(null, IntPtr.Zero);
208             }
209             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210             return ret;
211         }
212
213         internal ValueType GetMotionValueType()
214         {
215             int ret = Interop.MotionValue.GetValueType(SwigCPtr);
216             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217             return (ValueType)ret;
218         }
219
220         /// <summary>
221         /// Release swigCPtr.
222         /// </summary>
223         // This will be public opened.
224         [EditorBrowsable(EditorBrowsableState.Never)]
225         protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
226         {
227             Interop.MotionValue.DeleteMotionValue(swigCPtr);
228         }
229     }
230 }