Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
Signed-off-by: Dharini Dutia <[email protected]>
  • Loading branch information
quarkytale committed Dec 27, 2023
1 parent 6941c1c commit 121e539
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 146 deletions.
3 changes: 2 additions & 1 deletion src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Visual *_visual)
{
std::string scriptName = visualMaterial.ScriptName();

if ((scriptName.find("Gazebo/") == 0u)) {
if ((scriptName.find("Gazebo/") == 0u))
{
// \todo Add documentation page with warning
gzwarn << "Using an internal gazebo.material to parse " << scriptName
<< std::endl;
Expand Down
5 changes: 2 additions & 3 deletions src/rendering/MaterialParser/ConfigLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void ConfigLoader::loadMaterialFiles(ConfigLoader * c)
"gazebo.material");
std::ifstream in(installedConfig, std::ios::binary);
c->parseScript(in);

}
catch(std::filesystem::filesystem_error & e)
{
Expand All @@ -60,7 +59,7 @@ ConfigLoader::~ConfigLoader()

void ConfigLoader::clearScriptList()
{
for (auto i : m_scriptList) {
for (auto & i : m_scriptList) {
delete i.second;
}
m_scriptList.clear();
Expand All @@ -77,7 +76,7 @@ ConfigNode * ConfigLoader::getConfigScript(const std::string & name)
}
}

std::map < std::string, ConfigNode * > ConfigLoader::getAllConfigScripts()
std::map<std::string, ConfigNode *> ConfigLoader::getAllConfigScripts()
{
return m_scriptList;
}
Expand Down
229 changes: 118 additions & 111 deletions src/rendering/MaterialParser/ConfigLoader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,144 +19,151 @@
#ifndef RENDERING__MATERIALPARSER__CONFIGLOADER_HH_
#define RENDERING__MATERIALPARSER__CONFIGLOADER_HH_

#include <map>
#include <cassert>
#include <string>
#include <iostream>
#include <map>
#include <string>
#include <vector>

namespace gz
{
namespace sim
{
class ConfigNode;
namespace sim
{
class ConfigNode;

class ConfigLoader
{
class ConfigLoader
{
public:
static void loadMaterialFiles(ConfigLoader * c);
static void loadMaterialFiles(ConfigLoader * c);

ConfigLoader();
ConfigLoader();

~ConfigLoader();
~ConfigLoader();

std::string m_fileEnding;
std::string m_fileEnding;

// For a line like
// entity animals/dog
// {
// ...
// }
// The type is "entity" and the name is "animals/dog"
// Or if animal/dog was not there then name is ""
virtual ConfigNode * getConfigScript(const std::string & name);
// For a line like
// entity animals/dog
// {
// ...
// }
// The type is "entity" and the name is "animals/dog"
// Or if animal/dog was not there then name is ""
virtual ConfigNode * getConfigScript(const std::string & name);

virtual std::map < std::string, ConfigNode * > getAllConfigScripts();
virtual std::map<std::string, ConfigNode *> getAllConfigScripts();

virtual void parseScript(std::ifstream & stream);
virtual void parseScript(std::ifstream & stream);

protected:
float m_LoadOrder;
// like "*.object"
float m_LoadOrder;
// like "*.object"

std::map < std::string, ConfigNode * > m_scriptList;
std::map<std::string, ConfigNode *> m_scriptList;

enum Token
{
TOKEN_Text,
TOKEN_NewLine,
TOKEN_OpenBrace,
TOKEN_CloseBrace,
TOKEN_EOF,
};
enum Token
{
TOKEN_Text,
TOKEN_NewLine,
TOKEN_OpenBrace,
TOKEN_CloseBrace,
TOKEN_EOF,
};

Token tok, lastTok;
std::string tokVal, lastTokVal;
Token tok, lastTok;
std::string tokVal, lastTokVal;

void _parseNodes(std::ifstream & stream, ConfigNode * parent);
void _nextToken(std::ifstream & stream);
void _skipNewLines(std::ifstream & stream);
void _parseNodes(std::ifstream & stream, ConfigNode * parent);
void _nextToken(std::ifstream & stream);
void _skipNewLines(std::ifstream & stream);

virtual void clearScriptList();
};
virtual void clearScriptList();
};

class ConfigNode
{
class ConfigNode
{
public:
ConfigNode(ConfigNode * parent, const std::string & name = "untitled");
~ConfigNode();

inline void setName(const std::string & name)
{
this->m_name = name;
}

inline std::string & getName()
{
return m_name;
}

inline void addValue(const std::string & value)
{
m_values.push_back(value);
}

inline void clearValues()
{
m_values.clear();
}

inline std::vector < std::string > & getValues()
{
return m_values;
}

inline void getValuesInFloat(std::vector < float > & floatValues)
{
for (const auto & str : m_values) {
floatValues.push_back(std::stof(str));
}
}

inline const std::string & getValue(unsigned int index = 0)
{
assert(index < m_values.size());
return m_values[index];
}

ConfigNode * addChild(const std::string & name = "untitled", bool replaceExisting = false);
ConfigNode * findChild(const std::string & name, bool recursive = false);

inline std::vector < ConfigNode * > & getChildren()
{
return m_children;
}

inline ConfigNode * getChild(unsigned int index = 0)
{
assert(index < m_children.size());
return m_children[index];
}

void setParent(ConfigNode * newParent);

inline ConfigNode * getParent()
{
return m_parent;
}
explicit ConfigNode(ConfigNode * parent, const std::string & name = "untitled");

~ConfigNode();

inline void setName(const std::string & name)
{
this->m_name = name;
}

inline std::string & getName()
{
return m_name;
}

inline void addValue(const std::string & value)
{
m_values.push_back(value);
}

inline void clearValues()
{
m_values.clear();
}

inline std::vector<std::string> & getValues()
{
return m_values;
}

inline void getValuesInFloat(std::vector<float> & floatValues)
{
for (const auto & str : m_values) {
floatValues.push_back(std::stof(str));
}
}

inline const std::string & getValue(unsigned int index = 0)
{
assert(index < m_values.size());
return m_values[index];
}

ConfigNode * addChild(const std::string & name = "untitled", bool replaceExisting = false);

ConfigNode * findChild(const std::string & name, bool recursive = false);

inline std::vector<ConfigNode *> & getChildren()
{
return m_children;
}

inline ConfigNode * getChild(unsigned int index = 0)
{
assert(index < m_children.size());
return m_children[index];
}

void setParent(ConfigNode * newParent);

inline ConfigNode * getParent()
{
return m_parent;
}

private:
std::string m_name;
std::vector < std::string > m_values;
std::vector < ConfigNode * > m_children;
ConfigNode * m_parent;
std::string m_name;

std::vector<std::string> m_values;

std::vector<ConfigNode *> m_children;

ConfigNode * m_parent;

// The last child node's index found with a call to findChild()
int m_lastChildFound;

int m_lastChildFound; // The last child node's index found with a call to findChild()
std::vector<ConfigNode *> ::iterator _iter;

std::vector < ConfigNode * > ::iterator _iter;
bool _removeSelf;
};
} // namespace sim
bool _removeSelf;
};
} // namespace sim
} // namespace gz

#endif // RENDERING__MATERIALPARSER__CONFIGLOADER_HH_
12 changes: 6 additions & 6 deletions src/rendering/MaterialParser/MaterialParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*
*/

#include <cstddef>
#include <iostream>
#include <map>
#include <cstddef>
#include <string>
#include <vector>

Expand All @@ -42,10 +42,10 @@ void MaterialParser::Load()
MaterialParser::MaterialValues MaterialParser::GetMaterialValues(const std::string& material)
{
MaterialValues values;
std::map < std::string, ConfigNode * > scripts =
std::map<std::string, ConfigNode *> scripts =
this->configLoader.getAllConfigScripts();

std::map < std::string, ConfigNode * > ::iterator it;
std::map<std::string, ConfigNode *> ::iterator it;

for (it = scripts.begin(); it != scripts.end(); ++it) {
std::string name = it->first;
Expand All @@ -63,21 +63,21 @@ MaterialParser::MaterialValues MaterialParser::GetMaterialValues(const std::stri

ConfigNode * ambientNode = passNode->findChild("ambient");
if (ambientNode) {
std::vector < float > ambientValues;
std::vector<float> ambientValues;
ambientNode->getValuesInFloat(ambientValues);
values.ambient = gz::math::Color(ambientValues[0], ambientValues[1], ambientValues[2]);
}

ConfigNode * diffuseNode = passNode->findChild("diffuse");
if (diffuseNode) {
std::vector < float > diffuseValues;
std::vector<float> diffuseValues;
diffuseNode->getValuesInFloat(diffuseValues);
values.diffuse = gz::math::Color(diffuseValues[0], diffuseValues[1], diffuseValues[2]);
}

ConfigNode * specularNode = passNode->findChild("specular");
if (specularNode) {
std::vector < float > specularValues;
std::vector<float> specularValues;
specularNode->getValuesInFloat(specularValues);
// Using first four values for specular as Gazebo doesn't support shininess
values.specular = gz::math::Color
Expand Down
Loading

0 comments on commit 121e539

Please sign in to comment.