11 #include "mtl/envXMLWriter.h"
19 #include "vrfExtProtocol/objType.h"
20 #include "vrfExtProtocol/rangedObjType.h"
32 #include "vlutil/vlStringUtil.h"
33 #include "vlutil/vlFilename.h"
35 #include <boost/function.hpp>
36 #include <boost/lexical_cast.hpp>
56 static DtEnvValueSP findObjectElementByMatchType(
DtEnvironmentSP env,
const DtObjectType& objType);
57 static DtEnvValueSP findObjectElementByObjectType(
DtEnvironmentSP env,
const DtObjectType& objType);
80 static DtString GetObjectValue(DtEnvValueSP root)
82 return XmlBindingCharToMtl(root->value());
86 DtEnvValueSP root,
const DtString& paramName = DtString::nullString())
88 FindAndRemove(env, type, paramName, root);
89 DtEnvValueSP newElement = env->addObject(type, type, root);
90 if (paramName != DtString::nullString())
100 DtEnvValueSP newElement = AddElement(env,
vrfXml::Bool, root, name);
101 newElement->setValue(value ?
"True" :
"False");
108 DtEnvValueSP newElement = AddElement(env,
vrfXml::Real, root, name);
109 newElement->setValue(
DtString(value));
115 return env->addAttribute(name, value ?
"True" :
"False", root);
121 DtEnvValueSP newElement = AddElement(env,
vrfXml::String, root, name);
122 newElement->setValue(MtlBindingCharToXml(value));
128 DtEnvValueSP attr = env->getAttribute(name, root);
131 attr->setValue(MtlBindingCharToXml(value));
135 return attr = env->addAttribute(name, MtlBindingCharToXml(value), root);
138 static void setObjectType(
DtEnvironmentSP env, DtEnvValueSP root,
const DtObjectType& t)
143 static void setMatchType(
DtEnvironmentSP env, DtEnvValueSP root,
const DtObjectType& t)
153 static DtObjectType StringToObjectType(
const std::string& str)
155 if (str.length() == 0)
157 return DtObjectType::nullType();
160 char* p = (
char*)str.c_str();
161 DtObjectType objectType;
163 objectType[7] = ((int)strtol(p, &p, 0));
165 objectType[0] = ((int)strtol(p, &p, 0));
167 objectType[1] = ((int)strtol(p, &p, 0));
169 objectType[2] = ((int)strtol(p, &p, 0));
171 objectType[3] = ((int)strtol(p, &p, 0));
173 objectType[4] = ((int)strtol(p, &p, 0));
175 objectType[5] = ((int)strtol(p, &p, 0));
177 objectType[6] = ((int)strtol(p, &p, 0));
185 DtString objType = getAttribute(env, attributeName, root);
186 return StringToObjectType(objType.c_str());
190 bool fallbackOnMatchType =
true)
193 if (objectType == DtObjectType::nullType() && fallbackOnMatchType)
195 return getMatchType(env, root,
false);
202 bool fallbackOnObjectType =
true)
205 if (matchType == DtObjectType::nullType() && fallbackOnObjectType)
207 return getObjectType(env, root,
false);
214 const DtString& attributeName, DtEnvValueSP root);
218 return boost::lexical_cast<
double>(getAttribute(env, attributeName, root));
224 return strtoul(getAttribute(env, attributeName, root), &p, 0);
229 std::string attr = getAttribute(env, attributeName, root).c_str();
230 std::stringstream stringStream(attr);
232 stringStream >> asInt;
239 std::string stdStr = str.c_str();
240 std::transform(stdStr.begin(), stdStr.end(), stdStr.begin(), ::tolower);
241 std::istringstream is(stdStr);
243 is >> std::boolalpha >> b;
249 return ToBool(getAttribute(env, attributeName, root));
264 const DtEnvValueSP parentNode, DtTaitBryan& orientation)
266 orientation.setPsi(getDoubleAttribute(env,
vrfXml::Yaw, parentNode));
267 orientation.setTheta(getDoubleAttribute(env,
vrfXml::Pitch, parentNode));
268 orientation.setPhi(getDoubleAttribute(env,
vrfXml::Roll, parentNode));
272 double& x,
double& y,
double& z)
292 static void PopulateList(
300 static void CreateVariableBinding(
const DtString& bindingType,
308 DtEnvValueSP* root,
const DtFilename& searchPath);
313 DtEnvValueSP root,
const DtFilename& searchPath,
320 const DtString& dataSourceFilename,
bool showConsoleOutput =
true);
323 const DtString& type, DtEnvValueSP root);
355 DtEnvValueSP envValue,
bool traverseElements =
true)
358 attributeValue, envValue);
363 const DtString& attributeValue, DtEnvValueSP envValue,
364 bool traverseElements =
true);
374 static bool IsGroupedElement(
const DtString& rwName,
378 DtEnvValueSP parentNode,
const DtString& groupName,
379 bool createIfMissing =
true);
382 DtEnvValueSP parentNode,
const DtString& groupName);
392 DtEnvValueSP simObjectNode);
400 writer.writeFile(*env, filename);
405 const char quote(
'"');
407 if (output[0] == quote && output[output.size() - 1] == quote)
409 output.snipFront(quote);
410 output.snipBack(quote);
418 const DtRwVector* vec,
bool writeAsBodyPosition)
420 if (writeAsBodyPosition)
442 sprintf(buff,
"%X", number);