152dafc8211eee3eab8a96796b812fcaea0e53e0
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / model-components / model-node.cpp
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 // CLASS HEADER
19 #include <dali-scene3d/public-api/model-components/model-node.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/actors/custom-actor.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-scene3d/internal/model-components/model-node-impl.h>
27
28 namespace Dali
29 {
30 namespace Scene3D
31 {
32 ModelNode ModelNode::New()
33 {
34   return Scene3D::Internal::ModelNode::New();
35 }
36
37 ModelNode::ModelNode()
38 {
39 }
40
41 ModelNode::ModelNode(const ModelNode& modelNode) = default;
42
43 ModelNode::ModelNode(ModelNode&& rhs) = default;
44
45 ModelNode::~ModelNode()
46 {
47 }
48
49 ModelNode& ModelNode::operator=(const ModelNode& handle) = default;
50
51 ModelNode& ModelNode::operator=(ModelNode&& rhs) = default;
52
53 ModelNode ModelNode::DownCast(BaseHandle handle)
54 {
55   ModelNode result;
56
57   CustomActor custom = Dali::CustomActor::DownCast(handle);
58   if(custom)
59   {
60     CustomActorImpl& customImpl = custom.GetImplementation();
61
62     Internal::ModelNode* impl = dynamic_cast<Internal::ModelNode*>(&customImpl);
63
64     if(impl)
65     {
66       result = ModelNode(customImpl.GetOwner());
67     }
68   }
69
70   return result;
71 }
72
73 ModelNode::ModelNode(Internal::ModelNode& implementation)
74 : CustomActor(implementation)
75 {
76 }
77
78 ModelNode::ModelNode(Dali::Internal::CustomActor* internal)
79 : CustomActor(internal)
80 {
81   // Can have a NULL pointer so we only need to check if the internal implementation is our class
82   // when there is a value.
83   if(internal)
84   {
85     DALI_ASSERT_DEBUG(dynamic_cast<Internal::ModelNode*>(&CustomActor(internal).GetImplementation()));
86   }
87 }
88
89 // Public Method
90
91 uint32_t ModelNode::GetModelPrimitiveCount() const
92 {
93   return Internal::GetImplementation(*this).GetModelPrimitiveCount();
94 }
95
96 void ModelNode::AddModelPrimitive(ModelPrimitive modelPrimitive)
97 {
98   Internal::GetImplementation(*this).AddModelPrimitive(modelPrimitive);
99 }
100
101 void ModelNode::RemoveModelPrimitive(Dali::Scene3D::ModelPrimitive modelPrimitive)
102 {
103   Internal::GetImplementation(*this).RemoveModelPrimitive(modelPrimitive);
104 }
105
106 void ModelNode::RemoveModelPrimitive(uint32_t index)
107 {
108   Internal::GetImplementation(*this).RemoveModelPrimitive(index);
109 }
110
111 ModelPrimitive ModelNode::GetModelPrimitive(uint32_t index) const
112 {
113   return Internal::GetImplementation(*this).GetModelPrimitive(index);
114 }
115
116 ModelNode ModelNode::FindChildModelNodeByName(std::string_view nodeName)
117 {
118   return Internal::GetImplementation(*this).FindChildModelNodeByName(nodeName);
119 }
120
121 } // namespace Scene3D
122
123 } // namespace Dali