Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / FUiEffects_RuntimeEffectModel.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiEffects_RuntimeEffectModel.h
19  * @brief       This is the header file for the EffectModel class.
20  */
21
22 #ifndef _FUI_EFFECTS_INTERNAL_RUNTIME_EFFECT_MODEL_H_
23 #define _FUI_EFFECTS_INTERNAL_RUNTIME_EFFECT_MODEL_H_
24
25 #include <unique_ptr.h>
26 #include <map>
27 #include <list>
28 #include <string>
29 #include <FUiEffectsTypes.h>
30 #include <FUiEffects_PeElementSurface.h>
31 #include "FUiEffects_RuntimeIScriptProcessing.h"
32 #include "FUiEffects_RuntimeScriptProcessing.h"
33 #include "FUiEffects_RuntimeIEffectModelListener.h"
34 #include "FUiEffects_RuntimeModel.h"
35 #include "FUiEffects_RuntimePropertyCast.h"
36 #include "FUiEffects_RuntimeRenderDataSurface.h"
37 #include "FUiEffects_RuntimeIEffectModelScript.h"
38 #include "FUiEffects_RuntimeIEffectModelManager.h"
39
40 namespace Tizen { namespace Ui { namespace Effects { namespace _Runtime
41 {
42
43 class GraphicalSurface;
44 class ModelSurface;
45 class UnitLight;
46
47 /**
48 * The map type for pointers to ElementSurface abstract class.
49 *
50 */
51 typedef std::map<long, ::Tizen::Ui::Effects::_PhysicsEngine::ElementSurface*> TypeMapElements;
52
53 /**
54 * The map type for pointers to GraphicalSurface abstract class.
55 *
56 */
57 typedef std::map<long, GraphicalSurface*> TypeMapGSurface;
58
59 /**
60 * The list type for pointers to model surfaces.
61 *
62 */
63 typedef std::list<ModelSurface*> TypeMSurfacesCollection;
64
65 /**
66 * The type for denoting the time in model runtime (seconds).
67 *
68 */
69 typedef float TypeTimeEffect;
70
71 struct ModelSurfacesCollectionDeleter
72 {
73         void operator()(TypeMSurfacesCollection* pMSurfacesCollection);
74 };
75
76 /**
77  * @class       EffectModel
78  * @brief       This class contains the collection of model surfaces, transmits events to relevant classes.
79  *
80  * @since 2.0
81  *
82  */
83 class EffectModel
84         : public IEffectModelScript
85         , public IEffectModelManager
86 {
87 public:
88         /**
89          * EffectModel class constructor
90          *
91          * @since 2.0
92          *
93          */
94         EffectModel(long effectID, const std::string& name, const char* pPathToScript, IEffectModelListener* pEMListener, ::Tizen::Ui::Effects::EffectType effectType, TypeTimeEffect effectDuration);
95
96         /**
97          * Class destructor
98          *
99          * @since 2.0
100          *
101          */
102         virtual ~EffectModel(void);
103
104         /**
105          * Adds a pointer to model surface into model surfaces collection
106          *
107          * @since 2.0
108          *
109          * @remarks             It is called from parser
110          */
111         void AddModelSurface(ModelSurface* pMSurface);
112
113         /**
114          * Links classes after creating effect by parser (constructs the elements map and render data collection)
115          *
116          * @since 2.0
117          *
118          * @remarks             It is called from up level (by parser or effects manager);
119          *                              after linking calls script function Initialize
120          */
121         void Construct(void);
122
123         /**
124          * Calls script function OnEffectStart, prepares effect to starting
125          *
126          * @since 2.0
127          *
128          * @remarks             For example, script function OnEffectStart fixes cover points for PTE effect
129          */
130         virtual int Start(const EffectsVector<float>& effectStartInfo);
131
132         /**
133          * Stops effect performing and initializes (if not breakdown)
134          *
135          * @since 2.0
136          *
137          * @remarks             Sends to up level about effect stop;
138          *                              it is called from up level in case of forced stop
139          */
140         virtual void Stop(bool isBreakdown, bool isInterruptedFromApplication);
141
142         /**
143          * Calculating effect's elements
144          *
145          * @since 2.0
146          *
147          * @remarks             It is called from up level by timer;
148          *                              calls script function OnEffectCalculate
149          *                              and after calls function Calculate of all model surfaces,
150          *                              and then, if effect is EFFECT_TYPE_INTERACTIVE,
151          *                              calls script function IsEffectFinished
152          */
153         virtual void Calculate(float dt);
154
155         virtual long GetId(void) const;
156         virtual std::string GetName(void) const;
157
158         /**
159          * Event touch pressed handler
160          *
161          * @since 2.0
162          *
163          * @remarks             It is called from up level by corresponding event handler,
164          *                              transmits event to script
165          */
166         virtual void FeedTouchPressEvent(const TouchEventScript &pos3);
167
168         /**
169          * Event touch moved handler
170          *
171          * @since 2.0
172          *
173          * @remarks             It is called from up level by corresponding event handler,
174          *                              transmits event to script
175          */
176         virtual void FeedTouchMoveEvent(const TouchEventScript &pos3);
177
178         /**
179          * Event touch released handler
180          *
181          * @since 2.0
182          *
183          * @remarks             It is called from up level by corresponding event handler,
184          *                              transmits event to script
185          */
186         virtual void FeedTouchReleaseEvent(const TouchEventScript &pos3);
187
188         /**
189          * Event touch double pressed handler
190          *
191          * @since 2.0
192          *
193          * @remarks             It is called from up level by corresponding event handler,
194          *                              transmits event to script
195          */
196         virtual void FeedTouchDoublePressEvent(const TouchEventScript &pos3);
197
198         /**
199          * Returns time passed from the effect beginning
200          *
201          * @since 2.0
202          *
203          */
204         virtual float GetCalculationPeriodForTimer(void) const;
205
206         /**
207          * Returns current effect state (see enumeration _EffectState)
208          *
209          * @since 2.0
210          *
211          */
212         virtual _EffectState GetState(void) const;
213
214         /**
215          * Returns effect behaviour type (see enumeration EffectType)
216          *
217          * @since 2.0
218          *
219          */
220         virtual EffectType GetType(void) const;
221
222         /**
223          * Returns the pointer to the collection of structure RenderData elements to up level (to renderer)
224          *
225          * @since 2.0
226          *
227          * @remarks             The size of this collection is equal to quantity of graphical surfaces;
228          *                              this function is called once from up level for renderer
229          */
230         virtual RenderDataScene* GetRenderingData(void) const;
231
232         /**
233          * Updates all graphical surfaces
234          *
235          * @since 2.0
236          *
237          * @remarks             It is called for updating graphical points based on physical points
238          */
239         virtual void UpdateGraphicalSurfaces(void);
240
241         /**
242          * Transmits event SetProperty for boolean values from script to class-inheritor of ElementSurface interface
243          *
244          * @since 2.0
245          *
246          * @remarks             Function is inherited from IEffectModelScript class
247          */
248         virtual bool ScriptSetProperty(long objID, ElementProperty property, bool value);
249
250         /**
251          * Transmits event SetProperty for lua_Number values (floating point or integer)
252          * from script to class-inheritor of ElementSurface interface
253          *
254          * @since 2.0
255          *
256          * @remarks             Function is inherited from IEffectModelScript class
257          */
258         virtual bool ScriptSetProperty(long objID, ElementProperty property, LUA_NUMBER value);
259
260         /**
261          * Transmits event SetProperty for Vec3f values from script to class-inheritor of ElementSurface interface
262          *
263          * @since 2.0
264          *
265          * @remarks             Function is inherited from IEffectModelScript class
266          */
267         virtual bool ScriptSetProperty(long objID, ElementProperty property, const Tizen::Ui::Effects::_Utils::Vec3f &value);
268
269         /**
270          * Transmits event SetPropertyGroup for some group of elements from script to specified model surface
271          *
272          * @since 2.0
273          *
274          */
275         virtual bool ScriptSetPropertyGroup(long objID, GroupElements group, ElementProperty property, LUA_NUMBER value);
276
277         /**
278          * Transmits event GetProperty from script to class-inheritor of ElementSurface interface
279          *
280          * @since 2.0
281          *
282          * @remarks             Function is inherited from IEffectModelScript class;
283          *                              if ID is equals 0, then the owner of property is EffectModel
284          */
285         virtual PropertyCast ScriptGetProperty(long objID, ElementProperty property) const;
286
287         /**
288          * Transmits event UpdateBitmap from script to up level (to class-inheritor of IEffectModelListener interface)
289          *
290          * @since 2.0
291          *
292          * @remarks             Function is inherited from IEffectModelScript class
293          */
294         virtual bool ScriptUpdateBitmap(long graphicalSurfaceID, long bitmapID);
295
296         /**
297          *      Transmits event GetNearestGPoint from script to corresponding graphical surface;
298          *      finds the vector of vectors of nearest points to specified point of graphical surface
299          *
300          *      since 3.0
301          *
302          */
303         virtual PropertyCast ScriptGetNearestPointsIds(long graphicalSurfaceID, Tizen::Ui::Effects::_Utils::Vec3f &position) const;
304
305         /**
306          * Transmits event RotateModelMatrix from script to corresponding graphical surface;
307          * rotates model matrix of corresponding graphical surface
308          *
309          * @since 2.0
310          *
311          */
312         virtual bool ScriptRotateSurface(long graphicalSurfaceID, float angle, _Axis axis, _Point point,
313                                                                          float ax, float ay, float az, float x0, float y0, float z0);
314
315         /**
316          * Transmits event ScaleModelMatrix from script to corresponding graphical surface;
317          * scales model matrix of corresponding graphical surface
318          *
319          * @since 2.0
320          *
321          */
322         virtual bool ScriptScaleSurface(long graphicalSurfaceID, float ax, float ay, float az, _Point point,
323                                                                         float x0, float y0, float z0);
324
325         /**
326          * Transmits event TranslateModelMatrix from script to corresponding graphical surface;
327          * translates model matrix of corresponding graphical surface
328          *
329          * @since 2.0
330          *
331          */
332         virtual bool ScriptMoveSurface(long graphicalSurfaceID, float x0, float y0, float z0);
333
334         /**
335          * Transmits event ResetModelMatrix from script to corresponding graphical surface;
336          * sets identity model matrix for corresponding graphical surface
337          *
338          * @since 2.0
339          *
340          */
341         virtual bool ScriptResetSurfaceTransformation(long graphicalSurfaceID);
342
343         /**
344          * Transmits event DistanceFromGround from script to corresponding model surface
345          *
346          * @since 2.0
347          *
348          */
349         virtual PropertyCast ScriptGetDistanceFromGround(long modelSurfaceID) const;
350
351         /**
352          * Transmits event SetModelMatrix from script to corresponding graphical surface;
353          * sets model matrix for corresponding graphical surface
354          *
355          * @since 2.0
356          *
357          */
358         virtual bool ScriptSetTransformationMatrix(long graphicalSurfaceID, const Tizen::Ui::Effects::_Utils::LuaMatrix4& luaMatrix4);
359
360         /**
361          * Adds new unit light to scene
362          *
363          * @since 2.0
364          *
365          * @remarks             Returns true if addition was succeeded and false otherwise
366          */
367         virtual bool ScriptAddUnitLight(UnitLight& unitLight);
368
369         /**
370          * Excludes specified unit light from scene with using unique name of it
371          *
372          * @since 2.0
373          *
374          * @remarks             Returns true if addition was succeeded and false otherwise
375          */
376         virtual bool ScriptRemoveUnitLight(const std::string& name);
377
378         /**
379          * Excludes all units light of specified type from scene
380          *
381          * @since 2.0
382          *
383          * @remarks             Returns true if addition was succeeded and false otherwise
384          */
385         virtual bool ScriptRemoveAllUnitsLightType(TypeUnitLight typeUnitLight);
386
387         /**
388          * Returns specified unit light with using unique name of it
389          *
390          * @since 2.0
391          *
392          */
393         virtual PropertyCast ScriptGetUnitLight(const std::string& name) const;
394
395         /**
396          * Sets ambient colour for scene
397          *
398          * @since 2.0
399          *
400          */
401         virtual void ScriptSetLightAmbientColour(const Tizen::Ui::Effects::_Utils::Vec3f& ambientColour);
402
403         /**
404          * Sets ambient colour for scene
405          *
406          * @since 2.0
407          *
408          */
409         virtual void ScriptSetLightAmbientColour(float red, float green, float blue);
410
411         /**
412          * Sets light intensity for scene
413          *
414          * @since 2.0
415          *
416          */
417         virtual void ScriptSetLightIntensity(float intensity);
418
419         /**
420          * Sets attenuation for units light on scene
421          *
422          * @since 2.0
423          *
424          */
425         virtual void ScriptSetLightAttenuation(float attenuation);
426
427         /**
428          * Returns ambient colour of scene
429          *
430          * @since 2.0
431          *
432          */
433         virtual const Tizen::Ui::Effects::_Utils::Vec3f& ScriptGetLightAmbientColour(void) const;
434
435         /**
436          * Returns light intensity of scene
437          *
438          * @since 2.0
439          *
440          */
441         virtual float ScriptGetLightIntensity(void) const;
442
443         /**
444          * Returns attenuation for units light on scene
445          *
446          * @since 2.0
447          *
448          */
449         virtual float ScriptGetLightAttenuation(void) const;
450
451 protected:
452
453 private:
454         /**
455          * Hidden copy constructor
456          *
457          * @since 2.0
458          *
459          */
460         EffectModel(const EffectModel& rhs);
461
462         /**
463          * Hidden assignment operator
464          *
465          * @since 2.0
466          *
467          */
468         EffectModel &operator=(const EffectModel& rhs);
469
470         /**
471          * Finds an element in elements map by index
472          *
473          * @since 2.0
474          *
475          * @remarks             If element with specified index not exists, the function returns false
476          */
477         bool FindElement(long objID, TypeMapElements::iterator& it) const;
478
479         /**
480          * Finds an element in graphical surfaces map by index
481          *
482          * @since 2.0
483          *
484          * @remarks             If graphical surface with specified index not exists, the function returns false
485          */
486         bool FindGraphicalSurface(long objID, TypeMapGSurface::iterator& it) const;
487
488         /**
489          * Initializes some class parameters and calls function Initialize from script
490          *
491          * @since 2.0
492          *
493          */
494         void InitEffectModel(void);
495
496         /**
497          * Initializes all effect parameters
498          *
499          * @since 2.0
500          *
501          * @remarks             Effect's initialization after finishing
502          */
503         void EffectInitialize(void);
504
505 private:
506
507         std::unique_ptr<IScriptProcessing> __pScript;                   /**< pointer to script processing (for performing some functions in scripts)*/
508
509         IEffectModelListener* __pEMListener;                                    /**< pointer to effect model listener (for sending events to up level)*/
510         _EffectState __state;                                                                   /**< current effect state*/
511         ::Tizen::Ui::Effects::EffectType __effectType;                  /**< effect behaviour type*/
512         EffectResultS __effectResult;                                                   /**< result of effect performing*/
513
514         std::unique_ptr<TypeMapElements> __pMapElements;                /**< elements map (for quick searching the element by index)*/
515         std::unique_ptr<TypeMapGSurface> __pMapGSurface;                /**< graphical surfaces map (for quick searching the graphical surface by index and access from effect model instance to graphical surface directly)*/
516
517         std::unique_ptr<TypeMSurfacesCollection, ModelSurfacesCollectionDeleter> __pMSurfacesCollection;        /**< model surfaces collection*/
518
519         const long __effectID;                                                                  /**< ID of effect (for sending event to up level with ID of effect which generates this event)*/
520         const std::string __name;
521
522         TypeTimeEffect __effectTimePassed;                                              /**< elapsed time from effect beginning (in seconds)*/
523         TypeTimeEffect __effectDuration;                                                /**< the effect duration (is needed for time based effect) (in seconds)*/
524
525         std::unique_ptr<RenderDataScene> __pRenderDataScene;    /**< a pointer to render data for scene */
526
527 }; // EffectModel
528
529 } } } } // Tizen::Ui::Effects::_Runtime
530
531 #endif //_FUI_EFFECTS_INTERNAL_RUNTIME_EFFECT_MODEL_H_