DALi signals refactor to remove V2 naming
[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.h>
30
31 namespace Dali
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 DALI_IMPORT_API Model : public BaseHandle
49 {
50 public:
51
52   typedef Signal<void (Model)> ModelSignalType; ///< Signal type
53   typedef Signal<void (Model,bool)> ModelSaveSignalType; ///< 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 Destructor
92    *
93    * This is non-virtual since derived Handle types must not contain data or virtual methods.
94    */
95   ~Model();
96
97   /**
98    * @brief This copy constructor is required for (smart) pointer semantics.
99    *
100    * @param [in] handle A reference to the copied handle
101    */
102   Model(const Model& handle);
103
104   /**
105    * @brief This assignment operator is required for (smart) pointer semantics.
106    *
107    * @param [in] rhs  A reference to the copied handle
108    * @return A reference to this
109    */
110   Model& operator=(const Model& rhs);
111
112   /**
113    * @brief Query whether the model data has loaded.
114    *
115    * The asynchronous loading begins when the Model object is created.
116    * After the Model object is discarded, the model data will be released from memory.
117    * @return The loading state, either Loading, Success or Failed.
118    */
119   LoadingState GetLoadingState();
120
121   /**
122    * @brief Emitted when the model data loads successfully or when the loading fails.
123    *
124    * @return A signal object to Connect() with.
125    */
126   ModelSignalType& LoadingFinishedSignal();
127
128   /**
129    * @brief Emitted when the model data save request completes.
130    *
131    * @return A signal object to Connect() with.
132    */
133   ModelSaveSignalType& SavingFinishedSignal();
134
135   /**
136    * @brief Get number of animations in the model.
137    *
138    * @pre The model has been loaded.
139    * @return The number of animations encoded in the model, or zero if the model
140    * hasn't finished loading.
141    */
142   size_t NumberOfAnimations() const;
143
144   /**
145    * @brief Get the index of a named animation map in the model.
146    *
147    * @param[in] animationName The name of the animation to find
148    * @param[out] animationIndex The index of the named animation if found
149    * @return true if the animation was foud, false if not found.
150    */
151   bool FindAnimation(const std::string& animationName, unsigned int& animationIndex);
152
153   /**
154    * @brief Write the model data to the standard output in textual format.
155    *
156    * Note - will assert if any part of the model is on the scene graph (i.e. if
157    * an actor has been created from this model)
158    */
159   void Write();
160
161   /**
162    * @brief Save a Dali representation of the mode data.
163    *
164    * Used for faster loading on subsequent uses.
165    * @param[in] url The resource url for the data
166    */
167   void Save(const std::string& url);
168
169 public: // Not intended for application developers
170
171   /**
172    * @brief This constructor is used by Dali New() methods.
173    *
174    * @param [in] model A pointer to a newly allocated Dali resource
175    */
176   explicit DALI_INTERNAL Model(Internal::Model* model);
177 };
178
179 } // namespace Dali
180
181 #endif // __DALI_MODEL_H__