Skip to content

Commit

Permalink
change file format to use common and model specific parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkoves authored and TSC21 committed May 30, 2018
1 parent b4b7245 commit 376258d
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,48 @@ bool getSdfParam(sdf::ElementPtr sdf, const std::string& name, T& param, const T
template <typename T>
void model_param(const std::string& world_name, const std::string& model_name, const std::string& param, T& param_value)
{
TiXmlElement* e_param = nullptr;
TiXmlElement* e_param_tmp = nullptr;
std::string dbg_param;

TiXmlDocument doc(world_name + ".xml");
if (doc.LoadFile())
{
TiXmlHandle hDoc(&doc);
TiXmlHandle h_root(doc.RootElement());

TiXmlElement* e_model = h_root.FirstChild("model").Element();

TiXmlElement* pElem=hDoc.FirstChild( "options" ).FirstChild("model").Element();
for( pElem; pElem; pElem=pElem->NextSiblingElement("model"))
for( e_model; e_model; e_model=e_model->NextSiblingElement("model") )
{
TiXmlElement* pName = pElem->FirstChildElement("name");
if (pName && model_name.compare(pName->GetText()) == 0)
const char* attr_name = e_model->Attribute("name");
if (attr_name)
{
TiXmlElement* pValue = pElem->FirstChildElement(param);

if (pValue)
//specific
if (model_name.compare(attr_name) == 0)
{
std::istringstream iss(pValue->GetText());
iss >> param_value;

gzdbg << "get " << param << " " << param_value <<" for " << model_name << " model from " << doc.Value() << "\n";
e_param_tmp = e_model->FirstChildElement(param);
if (e_param_tmp)
{
e_param = e_param_tmp;
dbg_param = "";
}
break;
}
}
else
{
//common
e_param = e_model->FirstChildElement(param);
dbg_param = "common ";
}
}

if (e_param)
{
std::istringstream iss(e_param->GetText());
iss >> param_value;

gzdbg << model_name << " model: " << dbg_param << "parameter " << param << " = " << param_value << " from " << doc.Value() << "\n";
}
}

Expand Down

0 comments on commit 376258d

Please sign in to comment.