Merge "Combine Internal::ProxyObject & Internal::Object" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / modeling / model-impl.h
1 #ifndef __DALI_INTERNAL_MODEL_H__
2 #define __DALI_INTERNAL_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 // INTERNAL INCLUDES
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/modeling/material.h>
25 #include <dali/public-api/modeling/model.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/internal/event/modeling/model-data-impl.h>
28 #include <dali/internal/event/resources/resource-ticket.h>
29 #include <dali/internal/event/resources/resource-ticket-observer.h>
30 #include <dali/internal/event/resources/resource-client.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37 class ModelData;
38 class Model;
39 class ResourceClient;
40 typedef IntrusivePtr<Model> ModelPtr;
41
42 /**
43  * Encapsulates a Dali 3D model/scene.
44  */
45 class Model : public BaseObject, public ResourceTicketObserver
46 {
47 public:
48   /**
49    * Create a model from the given filename
50    * @param[in] name The filename of the model.
51    * @return A smart-pointer to a newly allocated model
52    */
53   static ModelPtr New(const std::string& name);
54
55 public: // From ResourceTicketObserver
56   /**
57    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingFailed()
58    */
59   virtual void ResourceLoadingFailed(const ResourceTicket& ticket);
60
61   /**
62    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingSucceeded()
63    */
64   virtual void ResourceLoadingSucceeded(const ResourceTicket& ticket);
65
66   /**
67    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceUploaded()
68    */
69   virtual void ResourceUploaded(const ResourceTicket& ticket);
70
71   /**
72    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceSavingFailed()
73    */
74   virtual void ResourceSavingFailed(const ResourceTicket& ticket);
75
76   /**
77    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceSavingSucceeded()
78    */
79   virtual void ResourceSavingSucceeded(const ResourceTicket& ticket);
80
81
82 public: // Query methods from external model
83   /**
84    * @copydoc Dali::Model::GetLoadingState()
85    */
86   LoadingState GetLoadingState()
87   {
88     return mTicket->GetLoadingState();
89   }
90
91   /**
92    * @copydoc Dali::Model::LoadingFinishedSignal()
93    */
94   Dali::Model::ModelSignalType& LoadingFinishedSignal()
95   {
96     return mLoadingFinished;
97   };
98
99   /**
100    * @copydoc Dali::Model::SavingFinishedSignal()
101    */
102   Dali::Model::ModelSaveSignalType& SavingFinishedSignal()
103   {
104     return mSavingFinished;
105   };
106
107   /**
108    * Connects a callback function with the object's signals.
109    * @param[in] object The object providing the signal.
110    * @param[in] tracker Used to disconnect the signal.
111    * @param[in] signalName The signal to connect to.
112    * @param[in] functor A newly allocated FunctorDelegate.
113    * @return True if the signal was connected.
114    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
115    */
116   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
117
118   /**
119    * returns the Id used for lookups
120    * @return the unique ID of the image data resource
121    */
122   ResourceId GetResourceId() const;
123
124   /**
125    * @copydoc Dali::Model::NumberOfAnimations().
126    */
127   unsigned int NumberOfAnimations() const;
128
129   /**
130    * @copydoc Dali::Model::FindAnimation().
131    */
132   bool FindAnimation(const std::string& animationName, unsigned int & animationIndex);
133
134   /**
135    * @copydoc Dali::Model::Write()
136    */
137   void Write();
138
139   /**
140    * @copydoc Dali::Model::Save()
141    */
142   void Save(const std::string& url);
143
144 public:
145   /**
146    * Accessor for internal classes only.
147    * @return The model data, or NULL if not loaded yet
148    */
149   Internal::ModelDataPtr GetModelData() const;
150
151 private:
152
153   /**
154    * Constructor
155    * @param[in] name The filename of the model.
156    * @return          None.
157    */
158   Model(const std::string& name);
159
160   /**
161    * A reference counted object may only be deleted by calling Unreference()
162    */
163   virtual ~Model();
164
165 private:
166
167   ResourceTicketPtr mTicket;
168
169   Dali::Model::ModelSignalType     mLoadingFinished;
170   Dali::Model::ModelSaveSignalType mSavingFinished;
171
172   ResourceClient* mResourceClient;
173 };
174
175 } // namespace Internal
176
177 // Helpers for public-api forwarding methods
178 inline Internal::Model& GetImplementation(Dali::Model& model)
179 {
180   DALI_ASSERT_ALWAYS( model && "Model handle is empty" );
181
182   BaseObject& handle = model.GetBaseObject();
183
184   return static_cast<Internal::Model&>(handle);
185 }
186
187 inline const Internal::Model& GetImplementation(const Dali::Model& model)
188 {
189   DALI_ASSERT_ALWAYS( model && "Model handle is empty" );
190
191   const BaseObject& handle = model.GetBaseObject();
192
193   return static_cast<const Internal::Model&>(handle);
194 }
195
196 } // namespace Dali
197
198 #endif // __DALI_INTERNAL_MODEL_H__