~robot3d-team/robot3d/trunk

« back to all changes in this revision

Viewing changes to inc/srCore/xmlConfig.h

  • Committer: Anne van Rossum
  • Date: 2010-08-10 15:58:55 UTC
  • Revision ID: anne@gamix-20100810155855-kve7x2vwouagdij9
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * xmlConfig.h
 
3
 *
 
4
 * Parser for <config.xml> file which contains the configuration for the Robot3D
 
5
 * robot simulator. In the WITH_MOTES modus it can be used for simulating a WSN.
 
6
 *
 
7
 *  Created on: Nov 25, 2008
 
8
 *      Author: winkler
 
9
 */
 
10
 
 
11
#ifndef XMLPARSER_H_
 
12
#define XMLPARSER_H_
 
13
#include <xercesc/dom/DOM.hpp>
 
14
#include <xercesc/dom/DOMDocument.hpp>
 
15
#include <xercesc/dom/DOMDocumentType.hpp>
 
16
#include <xercesc/dom/DOMElement.hpp>
 
17
#include <xercesc/dom/DOMImplementation.hpp>
 
18
#include <xercesc/dom/DOMImplementationLS.hpp>
 
19
#include <xercesc/dom/DOMNodeIterator.hpp>
 
20
#include <xercesc/dom/DOMNodeList.hpp>
 
21
#include <xercesc/dom/DOMText.hpp>
 
22
 
 
23
#include <xercesc/parsers/XercesDOMParser.hpp>
 
24
#include <xercesc/util/XMLUni.hpp>
 
25
 
 
26
#include <osg/Geometry>
 
27
#include <osg/Matrix>
 
28
 
 
29
#include <dtUtil/matrixutil.h>
 
30
#include <srCore/organismTree.h>
 
31
 
 
32
#include <map>
 
33
 
 
34
#include <string>
 
35
#include <stdexcept>
 
36
#include <vector>
 
37
 
 
38
 
 
39
#include "export.h"
 
40
 
 
41
// Error codes
 
42
 
 
43
enum {
 
44
        ERROR_ARGS = 1,
 
45
                        ERROR_XERCES_INIT,
 
46
                        ERROR_PARSE,
 
47
                        ERROR_EMPTY_DOCUMENT
 
48
};
 
49
 
 
50
struct SensorInitData
 
51
{
 
52
        char* type;
 
53
        char* name;
 
54
        osg::Vec3f position;
 
55
        osg::Vec3f orientation;
 
56
        float apertureAngle;
 
57
        osg::Vec2f resolution;
 
58
        int bodyPart;
 
59
};
 
60
 
 
61
 
 
62
//make class for that to make sure releasing all the stuff:
 
63
struct RobotInitData
 
64
{
 
65
        char* name;
 
66
        char* type;
 
67
        osg::Vec3f pos;
 
68
        osg::Quat quat;
 
69
        int connectorStates;
 
70
        short stateTestFlags;
 
71
        std::vector<float> jointAngles;
 
72
        std::vector<SensorInitData> sensors;
 
73
};
 
74
 
 
75
struct ControllerInitData
 
76
{
 
77
        char* name;
 
78
        char* robot;
 
79
        char* type;
 
80
        char* parameter;
 
81
        osg::Vec3f pos;
 
82
#ifdef WITH_CONFIG_PARAMS
 
83
        std::map<std::string, std::string> paramMap;
 
84
#endif
 
85
};
 
86
 
 
87
 
 
88
struct Terminal
 
89
{
 
90
        char* id;
 
91
        RobotInitData robot;
 
92
        ControllerInitData controller;
 
93
};
 
94
 
 
95
struct OrganismInitData
 
96
{
 
97
        char* structure;
 
98
        osg::Vec3f pos;
 
99
        osg::Quat quat;
 
100
        std::vector<Terminal> terminals;
 
101
};
 
102
 
 
103
 
 
104
/**
 
105
 * A struct that stores name and path of plugins that can be loaded by Robot3D.
 
106
 */
 
107
struct PluginInitData
 
108
{
 
109
        char* name;
 
110
        char* path;
 
111
};
 
112
 
 
113
//! Class for reading and parsing the scene file
 
114
class ROBOT_EXPORT GetConfig
 
115
{
 
116
public:
 
117
//      static GetConfig* Instance() {
 
118
//              if (!m_pInstance)
 
119
//                      m_pInstance = new GetConfig();
 
120
//              return m_pInstance;
 
121
//      }
 
122
        GetConfig();
 
123
        ~GetConfig();
 
124
        void readConfigFile(std::string) throw(std::runtime_error);
 
125
 
 
126
        std::vector<RobotInitData> getRobots() const {return robots;};
 
127
        std::vector<ControllerInitData> getControllers() const {return controllers;};
 
128
        std::vector<PluginInitData> getPlugins() const {return plugins;};
 
129
 
 
130
        char* getMap() const {return map;};
 
131
 
 
132
        bool getWithShadows() const {return withShadows;};
 
133
        bool getWithDetailedModels() const {return withDetailedModels;};
 
134
        bool getConnectorsAsJoints() const {return connectorsAsJoints;};
 
135
        bool getRobotsWithWheels() const  {return withWheels;};
 
136
        int  getCollisionGeometryDetails() const {return collisionGeometryDetails;};
 
137
 
 
138
        //   char *getOptionA() { return m_OptionA; };
 
139
        //   char *getOptionB() { return m_OptionB; };
 
140
 
 
141
private:
 
142
//      GetConfig();
 
143
//      static GetConfig* m_pInstance;
 
144
        
 
145
        void structureParser(char* structure);
 
146
        void processOrganismString(); // throw(std::runtime_error);
 
147
        void computePosQuat(std::string type, std::string lastType, int robot, int si, int lastSide, int rot, osg::Vec3f &pos, osg::Quat &quat);
 
148
        std::vector<osg::Matrix> getSideMatrix(float d);
 
149
        
 
150
        xercesc::XercesDOMParser *m_ConfigFileParser;
 
151
        bool withShadows, withDetailedModels, connectorsAsJoints, withWheels;
 
152
        int collisionGeometryDetails;
 
153
 
 
154
        char* map;
 
155
        OrganismInitData organism;
 
156
        std::vector<RobotInitData> robots;
 
157
        std::vector<ControllerInitData> controllers;
 
158
        std::vector<PluginInitData> plugins;
 
159
 
 
160
        // Internal class use only. Hold Xerces data in UTF-16 SMLCh type.
 
161
 
 
162
        XMLCh* TAG_scene;
 
163
        XMLCh* ATTR_activateShadows;
 
164
        XMLCh* ATTR_loadDetailedModels;
 
165
        XMLCh* ATTR_connectorsAsJoints;
 
166
        XMLCh* ATTR_withWheels;
 
167
        XMLCh* ATTR_collisionDetails;
 
168
        XMLCh* ATTR_map;
 
169
        XMLCh* ATTR_enableAudio;
 
170
 
 
171
#ifdef WITH_MOTES
 
172
        XMLCh* TAG_mote;
 
173
        XMLCh* ATTR_moteName;
 
174
        XMLCh* ATTR_moteType;
 
175
#endif
 
176
 
 
177
        XMLCh* TAG_organism;
 
178
        XMLCh* ATTR_org_structure;
 
179
        XMLCh* ATTR_org_x;
 
180
        XMLCh* ATTR_org_y;
 
181
        XMLCh* ATTR_org_z;
 
182
        XMLCh* ATTR_org_h;
 
183
        XMLCh* ATTR_org_p;
 
184
        XMLCh* ATTR_org_r;
 
185
        XMLCh* ATTR_org_quat_x;
 
186
        XMLCh* ATTR_org_quat_y;
 
187
        XMLCh* ATTR_org_quat_z;
 
188
        XMLCh* ATTR_org_quat_w;
 
189
        
 
190
        XMLCh* TAG_terminal;
 
191
        XMLCh* ATTR_termId;
 
192
        
 
193
        
 
194
        XMLCh* TAG_robot;
 
195
        XMLCh* ATTR_robotName;
 
196
        XMLCh* ATTR_robotType;
 
197
        XMLCh* ATTR_x;
 
198
        XMLCh* ATTR_y;
 
199
        XMLCh* ATTR_z;
 
200
        XMLCh* ATTR_h;
 
201
        XMLCh* ATTR_p;
 
202
        XMLCh* ATTR_r;
 
203
        XMLCh* ATTR_connected;
 
204
        XMLCh* ATTR_q0;
 
205
        XMLCh* ATTR_q1;
 
206
 
 
207
        XMLCh* TAG_sensor;
 
208
        XMLCh* ATTR_sensorName;
 
209
        XMLCh* ATTR_sensorType;
 
210
        XMLCh* ATTR_position_x;
 
211
        XMLCh* ATTR_position_y;
 
212
        XMLCh* ATTR_position_z;
 
213
        XMLCh* ATTR_orientation_x;
 
214
        XMLCh* ATTR_orientation_y;
 
215
        XMLCh* ATTR_orientation_z;
 
216
        XMLCh* ATTR_apertureAngle;
 
217
        XMLCh* ATTR_resolution_x;
 
218
        XMLCh* ATTR_resolution_y;
 
219
        XMLCh* ATTR_bodyPart;
 
220
 
 
221
        XMLCh* TAG_controller;
 
222
        XMLCh* ATTR_controllerName;
 
223
        XMLCh* ATTR_controllerType;
 
224
        XMLCh* ATTR_robotToControl;
 
225
        XMLCh* ATTR_controllerParameter;
 
226
 
 
227
        XMLCh* TAG_plugin;
 
228
        XMLCh* ATTR_pluginName;
 
229
        XMLCh* ATTR_pluginPath;
 
230
 
 
231
        XMLCh* TAG_param;
 
232
        XMLCh* ATTR_name;
 
233
        XMLCh* ATTR_value;
 
234
};
 
235
#endif /* XMLPARSER_H_ */
 
236