Skip to content

Commit

Permalink
Merge pull request #660 from azeey/azeey/11_to_main_20210809
Browse files Browse the repository at this point in the history
11 ➡️  main
  • Loading branch information
azeey authored Aug 9, 2021
2 parents 6251baa + b9e28a9 commit 22a968e
Show file tree
Hide file tree
Showing 30 changed files with 538 additions and 136 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ option(BUILD_SHARED_LIBS "Set this to true to generate shared libraries (recomme
#####################################
# Handle CFlags
unset (CMAKE_C_FLAGS_ALL CACHE)
unset (CMAKE_CXX_FLAGS CACHE)

# USE_HOST_CFLAGS (default TRUE)
# Will check building host machine for proper cflags
Expand Down
7 changes: 7 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ ABI was broken for `sdf::Element`, and restored on version 11.2.1.
+ std::optional<std::string> GetMaxValueAsString() const;
+ bool ValidateValue() const;

## libsdformat 9.4 to 9.5

### Additions

1. **sdf/Element.hh**
+ sdf::ElementPtr FindElement() const

## libsdformat 9.3 to 9.4

### Modifications
Expand Down
12 changes: 7 additions & 5 deletions cmake/DefaultCFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ endif()

#####################################
# Set all the global build flags
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_CXX_EXTENSIONS off)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINK_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_LINK_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_LINK_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_LINK_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_LINK_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CMAKE_LINK_FLAGS_${CMAKE_BUILD_TYPE_UPPERCASE}}")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -67,7 +67,9 @@ if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "GNU ")
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 7.0 or greater.")
endif ()
elseif ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang ")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC ")
if (MSVC_VERSION LESS 1914)
message(FATAL_ERROR "${PROJECT_NAME} requires VS 2017 or greater.")
Expand Down
29 changes: 28 additions & 1 deletion include/sdf/Element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ namespace sdf
/// \brief Shared pointer to an SDF Element
typedef std::shared_ptr<Element> ElementPtr;

/// \def ElementConstPtr
/// \brief Shared pointer to a const SDF Element
typedef std::shared_ptr<const Element> ElementConstPtr;

/// \def ElementWeakPtr
/// \brief Weak pointer to an SDF Element
typedef std::weak_ptr<Element> ElementWeakPtr;
Expand Down Expand Up @@ -375,14 +379,37 @@ namespace sdf
/// \brief Return a pointer to the child element with the provided name.
///
/// A new child element, with the provided name, is added to this element
/// if there is no existing child element.
/// if there is no existing child element. If this is not desired see \ref
/// FindElement
/// \remarks If there are multiple elements with the given tag, it returns
/// the first one.
/// \param[in] _name Name of the child element to retreive.
/// \return Pointer to the existing child element, or a new child
/// element if an existing child element did not exist.
public: ElementPtr GetElement(const std::string &_name);

/// \brief Return a pointer to the child element with the provided name.
///
/// Unlike \ref GetElement, this does not create a new child element if it
/// fails to find an existing element.
/// \remarks If there are multiple elements with the given tag, it returns
/// the first one.
/// \param[in] _name Name of the child element to retreive.
/// \return Pointer to the existing child element, or nullptr
/// if the child element was not found.
public: ElementPtr FindElement(const std::string &_name);

/// \brief Return a pointer to the child element with the provided name.
///
/// Unlike \ref GetElement, this does not create a new child element if it
/// fails to find an existing element.
/// \remarks If there are multiple elements with the given tag, it returns
/// the first one.
/// \param[in] _name Name of the child element to retreive.
/// \return Pointer to the existing child element, or nullptr
/// if the child element was not found.
public: ElementConstPtr FindElement(const std::string &_name) const;

/// \brief Add a named element.
/// \param[in] _name the name of the element to add.
/// \return A pointer to the newly created Element object.
Expand Down
122 changes: 88 additions & 34 deletions include/sdf/Param.hh
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ namespace sdf

/// \brief Private method to set the Element from a passed-in string.
/// \param[in] _value Value to set the parameter to.
/// \return True if the parameter was successfully set, false otherwise.
private: bool ValueFromString(const std::string &_value);

/// \brief Private data
Expand Down Expand Up @@ -326,8 +327,63 @@ namespace sdf

/// \brief This parameter's maximum allowed value
public: std::optional<ParamVariant> maxValue;

/// \brief Method used to set the Param from a passed-in string
/// \param[in] _typeName The data type of the value to set
/// \param[in] _valueStr The value as a string
/// \param[out] _valueToSet The value to set
/// \return True if the value was successfully set, false otherwise
public: bool SDFORMAT_VISIBLE ValueFromStringImpl(
const std::string &_typeName,
const std::string &_valueStr,
ParamVariant &_valueToSet) const;

/// \brief Data type to string mapping
/// \return The type as a string, empty string if unknown type
public: template<typename T>
std::string TypeToString() const;
};

///////////////////////////////////////////////
template<typename T>
std::string ParamPrivate::TypeToString() const
{
if constexpr (std::is_same_v<T, bool>)
return "bool";
else if constexpr (std::is_same_v<T, char>)
return "char";
else if constexpr (std::is_same_v<T, std::string>)
return "string";
else if constexpr (std::is_same_v<T, int>)
return "int";
else if constexpr (std::is_same_v<T, std::uint64_t>)
return "uint64_t";
else if constexpr (std::is_same_v<T, unsigned int>)
return "unsigned int";
else if constexpr (std::is_same_v<T, double>)
return "double";
else if constexpr (std::is_same_v<T, float>)
return "float";
else if constexpr (std::is_same_v<T, sdf::Time>)
return "time";
else if constexpr (std::is_same_v<T, ignition::math::Angle>)
return "angle";
else if constexpr (std::is_same_v<T, ignition::math::Color>)
return "color";
else if constexpr (std::is_same_v<T, ignition::math::Vector2i>)
return "vector2i";
else if constexpr (std::is_same_v<T, ignition::math::Vector2d>)
return "vector2d";
else if constexpr (std::is_same_v<T, ignition::math::Vector3d>)
return "vector3";
else if constexpr (std::is_same_v<T, ignition::math::Quaterniond>)
return "quaternion";
else if constexpr (std::is_same_v<T, ignition::math::Pose3d>)
return "pose";
else
return "";
}

///////////////////////////////////////////////
template<typename T>
void Param::SetUpdateFunc(T _updateFunc)
Expand Down Expand Up @@ -359,50 +415,48 @@ namespace sdf
template<typename T>
bool Param::Get(T &_value) const
{
try
T *value = std::get_if<T>(&this->dataPtr->value);
if (value)
{
if (typeid(T) == typeid(bool) && this->dataPtr->typeName == "string")
_value = *value;
}
else
{
std::string typeStr = this->dataPtr->TypeToString<T>();
if (typeStr.empty())
{
sdferr << "Unknown parameter type[" << typeid(T).name() << "]\n";
return false;
}

std::string valueStr = this->GetAsString();
ParamPrivate::ParamVariant pv;
bool success = this->dataPtr->ValueFromStringImpl(typeStr, valueStr, pv);

if (success)
{
_value = std::get<T>(pv);
}
else if (typeStr == "bool" && this->dataPtr->typeName == "string")
{
std::string strValue = std::get<std::string>(this->dataPtr->value);
std::transform(strValue.begin(), strValue.end(), strValue.begin(),
[](unsigned char c)
{
return static_cast<unsigned char>(std::tolower(c));
});
// this section for handling bool types is to keep backward behavior
// TODO(anyone) remove for Fortress. For more details:
// https://github.com/ignitionrobotics/sdformat/pull/638
valueStr = lowercase(valueStr);

std::stringstream tmp;
if (strValue == "true" || strValue == "1")
{
if (valueStr == "true" || valueStr == "1")
tmp << "1";
}
else
{
tmp << "0";
}

tmp >> _value;
return true;
}
else
{
T *value = std::get_if<T>(&this->dataPtr->value);
if (value)
_value = *value;
else
{
std::stringstream ss;
ss << ParamStreamer{this->dataPtr->value};
ss >> _value;
}
}
}
catch(...)
{
sdferr << "Unable to convert parameter["
<< this->dataPtr->key << "] "
<< "whose type is["
<< this->dataPtr->typeName << "], to "
<< "type[" << typeid(T).name() << "]\n";
return false;

return success;
}

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions sdf/1.6/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set (sdfs
actor.sdf
air_pressure.sdf
altimeter.sdf
atmosphere.sdf
audio_source.sdf
Expand All @@ -21,6 +22,7 @@ set (sdfs
imu.sdf
inertial.sdf
joint.sdf
lidar.sdf
light.sdf
light_state.sdf
link.sdf
Expand All @@ -32,6 +34,7 @@ set (sdfs
model.sdf
model_state.sdf
noise.sdf
particle_emitter.sdf
physics.sdf
plane_shape.sdf
plugin.sdf
Expand Down
4 changes: 4 additions & 0 deletions sdf/1.6/material.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
<description>Material glossiness in the range of [0-1], where 0 represents a rough surface and 1 represents a smooth surface. This is the inverse of a roughness map in a PBR metal workflow.</description>
</element>

<element name="environment_map" type="string" default="" required="0">
<description>Filename of the environment / reflection map, typically in the form of a cubemap</description>
</element>

<element name="ambient_occlusion_map" type="string" default="" required="0">
<description>Filename of the ambient occlusion map. The map defines the amount of ambient lighting on the surface.</description>
</element>
Expand Down
3 changes: 3 additions & 0 deletions sdf/1.7/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set (sdfs
actor.sdf
air_pressure.sdf
altimeter.sdf
atmosphere.sdf
audio_source.sdf
Expand All @@ -21,6 +22,7 @@ set (sdfs
imu.sdf
inertial.sdf
joint.sdf
lidar.sdf
light.sdf
light_state.sdf
link.sdf
Expand All @@ -32,6 +34,7 @@ set (sdfs
model.sdf
model_state.sdf
noise.sdf
particle_emitter.sdf
physics.sdf
plane_shape.sdf
plugin.sdf
Expand Down
4 changes: 4 additions & 0 deletions sdf/1.7/material.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
<description>Material glossiness in the range of [0-1], where 0 represents a rough surface and 1 represents a smooth surface. This is the inverse of a roughness map in a PBR metal workflow.</description>
</element>

<element name="environment_map" type="string" default="" required="0">
<description>Filename of the environment / reflection map, typically in the form of a cubemap</description>
</element>

<element name="ambient_occlusion_map" type="string" default="" required="0">
<description>Filename of the ambient occlusion map. The map defines the amount of ambient lighting on the surface.</description>
</element>
Expand Down
3 changes: 3 additions & 0 deletions sdf/1.8/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set (sdfs
actor.sdf
air_pressure.sdf
altimeter.sdf
atmosphere.sdf
audio_source.sdf
Expand All @@ -23,6 +24,7 @@ set (sdfs
imu.sdf
inertial.sdf
joint.sdf
lidar.sdf
light.sdf
light_state.sdf
link.sdf
Expand All @@ -34,6 +36,7 @@ set (sdfs
model.sdf
model_state.sdf
noise.sdf
particle_emitter.sdf
physics.sdf
plane_shape.sdf
plugin.sdf
Expand Down
4 changes: 4 additions & 0 deletions sdf/1.8/material.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
<description>Material glossiness in the range of [0-1], where 0 represents a rough surface and 1 represents a smooth surface. This is the inverse of a roughness map in a PBR metal workflow.</description>
</element>

<element name="environment_map" type="string" default="" required="0">
<description>Filename of the environment / reflection map, typically in the form of a cubemap</description>
</element>

<element name="ambient_occlusion_map" type="string" default="" required="0">
<description>Filename of the ambient occlusion map. The map defines the amount of ambient lighting on the surface.</description>
</element>
Expand Down
3 changes: 3 additions & 0 deletions sdf/1.9/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set (sdfs
actor.sdf
air_pressure.sdf
altimeter.sdf
atmosphere.sdf
audio_source.sdf
Expand All @@ -23,6 +24,7 @@ set (sdfs
imu.sdf
inertial.sdf
joint.sdf
lidar.sdf
light.sdf
light_state.sdf
link.sdf
Expand All @@ -34,6 +36,7 @@ set (sdfs
model.sdf
model_state.sdf
noise.sdf
particle_emitter.sdf
physics.sdf
plane_shape.sdf
plugin.sdf
Expand Down
4 changes: 4 additions & 0 deletions sdf/1.9/material.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
<description>Material glossiness in the range of [0-1], where 0 represents a rough surface and 1 represents a smooth surface. This is the inverse of a roughness map in a PBR metal workflow.</description>
</element>

<element name="environment_map" type="string" default="" required="0">
<description>Filename of the environment / reflection map, typically in the form of a cubemap</description>
</element>

<element name="ambient_occlusion_map" type="string" default="" required="0">
<description>Filename of the ambient occlusion map. The map defines the amount of ambient lighting on the surface.</description>
</element>
Expand Down
Loading

0 comments on commit 22a968e

Please sign in to comment.