License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / public-api / modeling / model.h
1 #ifndef __DALI_MODEL_H__
2 #define __DALI_MODEL_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21
22 // EXTERNAL INCLUDES
23 #include <boost/function.hpp>
24 #include <string>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/common/loading-state.h>
28 #include <dali/public-api/object/base-handle.h>
29 #include <dali/public-api/signals/dali-signal-v2.h>
30
31 namespace Dali DALI_IMPORT_API
32 {
33
34 class MeshActor;
35 class Animation;
36
37 namespace Internal DALI_INTERNAL
38 {
39 class Model;
40 }
41
42 /**
43  * @brief A handle to 3D model data loaded as a resource.
44  *
45  * Use ModelActorFactory::BuildActorTree() to create actors from this model.
46  * Use ModelActorFactory::BuildAnimation() to create animations on such actors.
47  */
48 class Model : public BaseHandle
49 {
50 public:
51
52   typedef SignalV2<void (Model)> ModelSignalV2; ///< Signal type
53   typedef SignalV2<void (Model,bool)> ModelSaveSignalV2; ///< Signal type for saving models
54
55   //Signal Names
56   static const char* const SIGNAL_MODEL_LOADING_FINISHED; ///< name "model-loading-finished"
57   static const char* const SIGNAL_MODEL_SAVING_FINISHED;  ///< name "model-saving-finished"
58
59 public:
60   /**
61    * @brief Create an uninitialized Model.
62    *
63    * This can be initialised with Model::New().  Calling member
64    * functions with an uninitialized Dali::Object is not allowed.
65    */
66   Model();
67
68   /**
69    * @brief Asynchronously load a model.
70    *
71    * Connect to SignalLoadingFinished() to determine when the model
72    * has finished loading.
73    *
74    * @param [in] url The url of the model data.
75    * @return A handle to a newly allocated Dali resource.
76    */
77   static Model New(const std::string& url);
78
79   /**
80    * @brief Downcast an Object handle to Model handle.
81    *
82    * If handle points to a Model object the downcast produces valid
83    * handle. If not the returned handle is left uninitialized.
84    *
85    * @param[in] handle to An object
86    * @return handle to an Model object or an uninitialized handle
87    */
88   static Model DownCast( BaseHandle handle );
89
90   /**
91    * @brief Virtual destructor.
92    *
93    * Dali::Object derived classes typically do not contain member data.
94    */
95   virtual ~Model();
96
97   /**
98    * @copydoc Dali::BaseHandle::operator=
99    */
100   using BaseHandle::operator=;
101
102   /**
103    * @brief Query whether the model data has loaded.
104    *
105    * The asynchronous loading begins when the Model object is created.
106    * After the Model object is discarded, the model data will be released from memory.
107    * @return The loading state, either Loading, Success or Failed.
108    */
109   LoadingState GetLoadingState();
110
111   /**
112    * @brief Emitted when the model data loads successfully or when the loading fails.
113    *
114    * @return A signal object to Connect() with.
115    */
116   ModelSignalV2& LoadingFinishedSignal();
117
118   /**
119    * @brief Emitted when the model data save request completes.
120    *
121    * @return A signal object to Connect() with.
122    */
123   ModelSaveSignalV2& SavingFinishedSignal();
124
125   /**
126    * @brief Get number of animations in the model.
127    *
128    * @pre The model has been loaded.
129    * @return The number of animations encoded in the model, or zero if the model
130    * hasn't finished loading.
131    */
132   size_t NumberOfAnimations() const;
133
134   /**
135    * @brief Get the index of a named animation map in the model.
136    *
137    * @param[in] animationName The name of the animation to find
138    * @param[out] animationIndex The index of the named animation if found
139    * @return true if the animation was foud, false if not found.
140    */
141   bool FindAnimation(const std::string& animationName, unsigned int& animationIndex);
142
143   /**
144    * @brief Write the model data to the standard output in textual format.
145    *
146    * Note - will assert if any part of the model is on the scene graph (i.e. if
147    * an actor has been created from this model)
148    */
149   void Write();
150
151   /**
152    * @brief Save a Dali representation of the mode data.
153    *
154    * Used for faster loading on subsequent uses.
155    * @param[in] url The resource url for the data
156    */
157   void Save(const std::string& url);
158
159 public: // Not intended for application developers
160
161   /**
162    * @brief This constructor is used by Dali New() methods.
163    *
164    * @param [in] model A pointer to a newly allocated Dali resource
165    */
166   explicit DALI_INTERNAL Model(Internal::Model* model);
167 };
168
169 } // namespace Dali
170
171 #endif // __DALI_MODEL_H__