2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
20 using System.Globalization;
22 namespace Tizen.NUI.Binding
24 //Internal used, will never open
25 [EditorBrowsable(EditorBrowsableState.Never)]
26 public class RotationTypeConverter : TypeConverter
28 //Internal used, will never open
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public override object ConvertFromInvariantString(string value)
32 // public Rotation(Radian radian(float), Vector3 vector3)
33 // Default: <View Orientation="45.0,12,13,0" />
34 // Orientation="D:23, 0, 0, 1"
35 // Orientation="R:23, 0, 0, 1"
38 string[] parts = value.Split(TypeConverter.UnifiedDelimiter);
39 if (parts.Length == 4)
41 bool useDefault = true;
43 string[] head = parts[0].Trim().Split(':');
47 string radianOrDegree = head[0].Trim().ToUpperInvariant();
48 if (radianOrDegree == "D" || radianOrDegree == "DEGREE")
50 // Orientation="D:23, 0, 0, 1"
51 var degree = new Degree(Single.Parse(head[1].Trim(), CultureInfo.InvariantCulture));
52 radian = new Radian(degree);
55 else if (radianOrDegree == "R" || radianOrDegree == "RADIAN")
57 // Orientation="R:23, 0, 0, 1"
58 radian = new Radian(Single.Parse(head[1].Trim(), CultureInfo.InvariantCulture));
62 throw new InvalidOperationException($"Cannot convert the first parameter \"{value}\" into Radian of {typeof(Rotation)}");
68 // Default: <View Orientation="45.0,12,13,0" />
69 radian = new Radian(Single.Parse(parts[0].Trim(), CultureInfo.InvariantCulture));
72 Vector3 vector3 = new Vector3(Single.Parse(parts[1].Trim(), CultureInfo.InvariantCulture),
73 Single.Parse(parts[2].Trim(), CultureInfo.InvariantCulture),
74 Single.Parse(parts[3].Trim(), CultureInfo.InvariantCulture));
75 var ret = new Rotation(radian, vector3);
82 throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(Rotation)}");
85 //Internal used, will never open
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public override string ConvertToString(object value)
89 Rotation rotation = value as Rotation;
90 return rotation?.ToString();