2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUiEffects_ParserEffectParser.h
19 * @brief This file contains a declaration of EffectParser class
22 #ifndef _FUI_EFFECTS_INTERNAL_PARSER_EFFECTPARSER_H_
23 #define _FUI_EFFECTS_INTERNAL_PARSER_EFFECTPARSER_H_
28 #include <utils/FUiEffects_Utils.h>
29 #include <FUiEffects_ParserXMLParser.h>
30 #include <FUiEffects_PeElementSurface.h>
31 #include <FUiEffects_RuntimeEffectModel.h>
32 #include <FUiEffects_RuntimeRenderDataScene.h>
33 #include <FUiEffects_RuntimeModelSurface.h>
34 #include <FUiEffects_RuntimeGraphicalSurfaceNurbs.h>
35 #include <FUiEffects_PePointSurface.h>
36 #include <FUiEffects_PeSpringSurface.h>
37 #include <FUiEffects_PeRodSurface.h>
38 #include <FUiEffects_PeRodSurfaceNURBS.h>
39 #include <FUiEffects_RuntimeIEffectModelListener.h>
40 #include <FBaseDataType.h>
41 #include <unique_ptr.h>
43 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer {
49 * @brief This namespace contains classes that provide methods for parsing an effect file
50 * and building the effect
52 namespace Tizen { namespace Ui { namespace Effects { namespace _Parser
57 * @brief A static method only class that performs unzipping of an effect file,
58 * parsing of xml-files of the model and may create or not the model itself
67 * Handles an open-tag of an XML-element in a file being parsed by XMLParser
71 * @param [in] elementName - the name of the XML-element
72 * @exception E_OUT_OF_MEMORY Insufficient memory
73 * @remarks Can only be called from XMLParser and from friends
75 void StartElement(const char* pElementName);
78 * Handles an close-tag of an XML-element in a file being parsed by XMLParser
82 * @param[in] elementName the name of the XML-element
83 * @exception E_INVALID_STATE The instance buffers occurred to be in an invalid state
84 * @exception E_INVALID_ARG An unexpected argument passed
85 * @remarks Can only be called from XMLParser and from friends
87 void EndElement(const char* pElementName);
90 * Handles presence of an attribute in an XML-element
91 * in a file being parsed by XMLParser
95 * @param[in] attributeName - the name of the attribute of an XML-element
96 * @param[in] attributeValue - the value of the attribute of an XML-element
97 * @exception E_INVALID_STATE The instance buffers occurred to be in an invalid state
98 * @remarks Can only be called from XMLParser and from friends
100 void Attribute(const char* pAttributeName, const char* pAttributeValue);
103 * Unzips and checks content of an effect file, performs XML-parsing
104 * of the corresponding files
108 * @return A boolean result of both: effect file parsing and XML-parsing
109 * @param[in] path a full path to the input effect file (a zip-archive)
110 * @exception OUT_OF_MEMORY Insufficient memory
111 * @exception E_INVALID_ARG An invalid argument passed to the XmlParser instantiator
112 * @exception E_ALREADY_BOUND The passed parent doesn't match the current parent
113 * of a created XmlParser singleton object
114 * @exception E_OPERATION_FAILED Extraction of model files from an effect file hasn't finished successfully
116 static bool ParseEffectFile(const char* pEffectFilePath, const char* pModelFilesDirectoryPath);
119 * Performs unziping of an effect file, checks out its content,performs
120 * XML-parsing and constructs according to the effect file EffectInstance object
124 * @return A pointer to the constructed _EffectInstance or null if parsing failed
126 * @param[in] path - a full path to the input effect file (a zip-archive)
127 * @param[in] effectsManager a pointer to the object that should call this method
128 * @param[in] effectModelID an ID of the effect to be constructed
129 * @exception OUT_OF_MEMORY Insufficient memory
130 * @exception E_INVALID_ARG An invalid argument passed to the XmlParser instantiator
131 * @exception E_ALREADY_BOUND The passed parent doesn't match the current parent
132 * of a created XmlParser singleton object
133 * @exception E_OPERATION_FAILED Extraction of model files from an effect file hasn't finished successfully
134 * @exception E_PARSING_FAILED XML parsing hasn't been successful
135 * @exception E_KEY_NOT_FOUND Missing an attribute or an error model attributes
136 * @exception E_INVALID_CONDITION A member variable of effect parser was not initialized
137 * @exception E_INVALID_FORMAT An error in the logic of effect parser occurred
139 static result ParseEffectFileLoadModel(const char* pEffectFilePath, const char* pModelFilesDirectoryPath,
140 Tizen::Ui::Effects::_Runtime::IEffectModelListener* pEffectManager, long effectModelID,
141 Tizen::Ui::Effects::_Runtime::IEffectModelManager*& pEffectModel, Tizen::Ui::Effects::_Renderer::EffectRenderer*& pEffectRenderer, int& modelTimerTimeout);
145 * @brief class constructor
146 * @remarks accessible only from static methods and from friends
151 * @brief class destructor
152 * @remarks accessible only from static methods and from friends
156 // Hidden copy constructor
157 EffectParser(const EffectParser& rhs);
159 // Hidden assignment operator
160 EffectParser& operator=(const EffectParser& rhs);
162 // Container of attibutes of an xml element
163 typedef std::map<std::string, std::string> TypeXmlElementAttributes;
165 // type of an xml element containing its name and attributes
169 TypeXmlElementAttributes attributes;
174 unsigned int timerTimeout;
175 Tizen::Ui::Effects::_Utils::Vec3f ambientColor;
195 // Container of pointers to objects of ElementSurface
196 typedef std::vector<Tizen::Ui::Effects::_PhysicsEngine::ElementSurface*> TypePElementSurfaceCollection;
198 // Container of pointers to objects of UnitLight
199 typedef std::vector<Tizen::Ui::Effects::_Runtime::UnitLight*> TypePUnitLightCollection;
201 // Container of objects of XmlElement
202 typedef std::vector<XmlElement> TypeXmlElementCollection;
204 // Container that maps indices of PointSurfaceNurbs objects in the model file to indices of those in
205 // the appropriate container of this class
206 typedef std::map<std::pair<unsigned int,unsigned int>, unsigned int> TypeNurbsPointIndexDistributor;
208 // Container of pointers to objects of ModelSurface
209 typedef std::vector<Tizen::Ui::Effects::_Runtime::ModelSurface*> TypePModelSurfaceCollection;
211 bool ExtractModelFiles(const char* pPath);
212 void ClearModelFiles(void);
213 void ClearBuffers(void);
215 Tizen::Ui::Effects::_PhysicsEngine::PointSurface* FindPointSurfaceById(long pointId) const;
216 Tizen::Ui::Effects::_PhysicsEngine::PointSurfaceNurbs* FindPointSurfaceNurbsByIndices(unsigned int row, unsigned int col) const;
218 bool CreatePointLight(XmlElement&);
219 bool CreateSpotLight(XmlElement&);
220 bool CreateDirectionalLight(XmlElement&);
221 bool CreatePointSurface(XmlElement&);
222 bool CreateSpringSurface(XmlElement&);
223 bool CreateRodSurface(XmlElement&);
224 bool CreateRodSurfaceNurbs(XmlElement&);
225 bool CreateGraphicalSurface(XmlElement&);
226 bool CreatePointSurfaceNurbs(XmlElement&);
227 bool CreateGraphicalSurfaceKnot(XmlElement&);
228 bool PriorReadModelSurfaceData(void);
229 bool PriorReadGraphicalSurfaceData(void);
230 bool CreateModelSurface(XmlElement&);
231 bool CreateEffectModel(XmlElement&);
232 bool CreateGravityForce(XmlElement&);
233 bool ReadViewportData(XmlElement&);
234 bool PriorReadSceneData(void);
235 bool ReadManifestData(XmlElement&);
236 Tizen::Ui::Effects::_Utils::Vec3f StringHexToRgb(const std::string&);
240 static EffectParser* __pInstance;
241 std::unique_ptr<XmlParser> __pXmlParser;
243 std::string __currentModelFilesDirectoryPath;
244 static const std::string __MANIFEST_FILE_NAME;
245 static const std::string __SCENE_FILE_NAME;
246 static const std::string __SCRIPT_FILE_NAME;
248 TypeXmlElementCollection __elementBuffer;
249 TypeNurbsPointIndexDistributor __pointSurfaceNurbsIndices;
250 TypePElementSurfaceCollection __elementSurfaceBuffer;
251 TypePUnitLightCollection __unitLightBuffer;
252 std::unique_ptr<Tizen::Ui::Effects::_Runtime::GraphicalSurface> __pCurrentGraphicalSurface;
253 Tizen::Ui::Effects::_Utils::Vec3f __currentGravityForce;
254 float __currentGravityForceValue;
255 std::unique_ptr<Tizen::Ui::Effects::_Runtime::TypeKnots> __pCurrentVectorXBuffer;
256 std::unique_ptr<Tizen::Ui::Effects::_Runtime::TypeKnots> __pCurrentVectorYBuffer;
257 TypePModelSurfaceCollection __modelSurfaceBuffer;
259 int __lastSceneXMLElementIndex;
260 int __lastModelSurfaceXMLElementIndex;
261 int __lastGraphicalSurfaceXMLElementIndex;
262 std::unique_ptr<Tizen::Ui::Effects::_Runtime::EffectModel> __pCurrentEffectModel;
263 Tizen::Ui::Effects::_Runtime::IEffectModelListener* __pCurrentEffectManager; //agrigation pointer
265 long __currentEffectId;
266 Tizen::Ui::Effects::EffectType __currentModelBehaviourType;
267 Tizen::Ui::Effects::_Runtime::TypeTimeEffect __currentEffectDuration;
268 std::string __currentEffectInstanceName;
270 SceneData __currentSceneData;
271 ViewportData __currentViewportData;
273 float __currentModelSurfaceX;
274 float __currentModelSurfaceY;
275 unsigned int __currentGraphicalSurfaceDimCtrlX;
276 unsigned int __currentGraphicalSurfaceDimCtrlY;
278 bool __insideGraphicalSurface;
279 bool __rightAfterSceneStart;
280 bool __rightAfterModelSurfaceStart;
281 bool __rightAfterGraphicalSurfaceStart;
282 bool __insideVectorX;
283 bool __insideVectorY;
284 bool __buildingModelFailed;
285 bool __insideElementsPool;
288 } } } } // Tizen::Ui::Effects::_Parser
290 #endif // _FUI_EFFECTS_INTERNAL_PARSER_EFFECTPARSER_H_