Skip to content

Commit

Permalink
Reverting to PrintConfig with basic API
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth committed Oct 4, 2021
1 parent da860a1 commit 8fc5469
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 14 deletions.
40 changes: 29 additions & 11 deletions include/sdf/PrintConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,39 @@ namespace sdf
{
inline namespace SDF_VERSION_NAMESPACE
{
/// \enum PrintConfig
/// \brief The different types of available printing configuration.
enum class PrintConfig

/// This class contains configuration options for printing elements.
class SDFORMAT_VISIBLE PrintConfig
{
/// \brief Default config
DEFAULT,
/// \brief Default constructor. All options are set to false by default.
public: PrintConfig();

/// \brief Sets the option for printing pose rotations in degrees if true,
/// otherwise they will be printed as radians by default.
/// \param[in] _value Whether to print pose rotations in degrees.
public: void SetRotationInDegrees(bool _value);

/// \brief Gets the current option of whether pose rotations are printed in
/// degrees.
/// \return True if pose rotations are printed in degrees, false otherwise.
public: bool GetRotationInDegrees() const;

/// \brief Displays rotations in poses in degrees.
ROTATION_IN_DEGREES,
/// \brief Sets the option for printing pose rotation in degrees as well as
/// snapping the rotation to commonly used angles of 45 degrees along axes
/// with a tolerance of 0.01 degrees, with the exception of singularities,
/// if set to true, otherwise they will be printed as radians by default.
public: void SetRotationSnapToDegrees(bool _value);

/// \brief Displays rotations in poses in degrees as well as snaps to the 16
/// commonly used angles lying on the axes in intervals of 45 degrees with
/// a tolerance of 0.01 degrees, with the exception of singularities.
ROTATION_SNAP_TO_DEGREES
/// \brief Gets the current option of whether pose rotations are printed in
/// degrees as well as snapping them to commonly used angles.
/// \return True if pose rotations are to be printed in degrees, as well as
/// snapping to commonly used angles, false otherwise.
public: bool GetRotationSnapToDegrees() const;

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
};

}
}

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set (sources
Pbr.cc
Physics.cc
Plane.cc
PrintConfig.cc
Root.cc
Scene.cc
SDF.cc
Expand Down Expand Up @@ -134,6 +135,7 @@ if (BUILD_SDF_TEST)
Pbr_TEST.cc
Physics_TEST.cc
Plane_TEST.cc
PrintConfig_TEST.cc
Root_TEST.cc
Scene_TEST.cc
SemanticPose_TEST.cc
Expand Down
64 changes: 64 additions & 0 deletions src/PrintConfig.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "sdf/PrintConfig.hh"

namespace sdf
{
inline namespace SDF_VERSION_NAMESPACE
{
/////////////////////////////////////////////////
class PrintConfig::Implementation
{
public: bool rotationInDegrees = false;

public: bool rotationSnapToDegrees = false;
};

/////////////////////////////////////////////////
PrintConfig::PrintConfig()
: dataPtr(ignition::utils::MakeImpl<Implementation>())
{
}

/////////////////////////////////////////////////
void PrintConfig::SetRotationInDegrees(bool _value)
{
this->dataPtr->rotationInDegrees = _value;
}

/////////////////////////////////////////////////
bool PrintConfig::GetRotationInDegrees() const
{
return this->dataPtr->rotationInDegrees;
}

/////////////////////////////////////////////////
void PrintConfig::SetRotationSnapToDegrees(bool _value)
{
this->dataPtr->rotationSnapToDegrees = _value;
}

/////////////////////////////////////////////////
bool PrintConfig::GetRotationSnapToDegrees() const
{
return this->dataPtr->rotationSnapToDegrees;
}

/////////////////////////////////////////////////
}
}
54 changes: 54 additions & 0 deletions src/PrintConfig_TEST.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <gtest/gtest.h>

#include "sdf/PrintConfig.hh"

/////////////////////////////////////////////////
TEST(PrintConfig, Construction)
{
sdf::PrintConfig config;
EXPECT_FALSE(config.GetRotationInDegrees());
EXPECT_FALSE(config.GetRotationSnapToDegrees());
}

/////////////////////////////////////////////////
TEST(PrintConfig, RotationInDegrees)
{
sdf::PrintConfig config;
EXPECT_FALSE(config.GetRotationInDegrees());

config.SetRotationInDegrees(true);
EXPECT_TRUE(config.GetRotationInDegrees());

config.SetRotationInDegrees(false);
EXPECT_FALSE(config.GetRotationInDegrees());
}

/////////////////////////////////////////////////
TEST(PrintConfig, RotationSnapToDegrees)
{
sdf::PrintConfig config;
EXPECT_FALSE(config.GetRotationSnapToDegrees());

config.SetRotationSnapToDegrees(true);
EXPECT_TRUE(config.GetRotationSnapToDegrees());

config.SetRotationSnapToDegrees(false);
EXPECT_FALSE(config.GetRotationSnapToDegrees());
}
6 changes: 3 additions & 3 deletions src/SDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ void SDF::PrintValues(const PrintConfig &_config)
/////////////////////////////////////////////////
void SDF::PrintValues(const std::string &_option)
{
PrintConfig config = PrintConfig::DEFAULT;
PrintConfig config;
if (_option == "in_degrees")
config = PrintConfig::ROTATION_IN_DEGREES;
config.SetRotationInDegrees(true);
else if (_option == "snap_to_degrees")
config = PrintConfig::ROTATION_SNAP_TO_DEGREES;
config.SetRotationSnapToDegrees(true);

this->Root()->PrintValues("", config);
}
Expand Down

0 comments on commit 8fc5469

Please sign in to comment.