From 66bb5cf56fa5d21f1ec5d685dbc0d0f4641bd76c Mon Sep 17 00:00:00 2001 From: Marcos Wagner Date: Mon, 19 Jul 2021 16:05:51 -0300 Subject: [PATCH] Model command structure update Signed-off-by: Marcos Wagner --- CMakeLists.txt | 4 +- model/src/CMakeLists.txt | 40 --------------- model/src/cmd/CMakeLists.txt | 58 --------------------- src/CMakeLists.txt | 10 ++++ {model/src => src}/ModelCommandAPI_TEST.cc | 11 ++-- src/cmd/CMakeLists.txt | 59 ++++++++++++++++++++++ {model/src => src}/cmd/ModelCommandAPI.cc | 9 ++-- {model/src => src}/cmd/ModelCommandAPI.hh | 0 {model/src => src}/cmd/cmdmodel.rb.in | 17 ++++--- {model/src => src}/cmd/ignmodel.yaml.in | 0 10 files changed, 93 insertions(+), 115 deletions(-) delete mode 100644 model/src/CMakeLists.txt delete mode 100644 model/src/cmd/CMakeLists.txt rename {model/src => src}/ModelCommandAPI_TEST.cc (97%) rename {model/src => src}/cmd/ModelCommandAPI.cc (98%) rename {model/src => src}/cmd/ModelCommandAPI.hh (100%) rename {model/src => src}/cmd/cmdmodel.rb.in (90%) rename {model/src => src}/cmd/ignmodel.yaml.in (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7fd85ddc6..028af75f64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,9 +149,7 @@ set(IGNITION_GAZEBO_GUI_PLUGIN_INSTALL_DIR #============================================================================ # Configure the build #============================================================================ -ign_configure_build(QUIT_IF_BUILD_ERRORS - COMPONENTS model -) +ign_configure_build(QUIT_IF_BUILD_ERRORS) add_subdirectory(examples) diff --git a/model/src/CMakeLists.txt b/model/src/CMakeLists.txt deleted file mode 100644 index 4ae6bff0de..0000000000 --- a/model/src/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -ign_get_libsources_and_unittests(sources gtest_sources) -list(APPEND sources cmd/ModelCommandAPI.cc) - -ign_add_component(model SOURCES ${sources} GET_TARGET_NAME model_lib_target) - - -if (MSVC) - # Warning #4251 is the "dll-interface" warning that tells you when types used - # by a class are not being exported. These generated source files have private - # members that don't get exported, so they trigger this warning. However, the - # warning is not important since those members do not need to be interfaced - # with. - set_source_files_properties(${sources} ${gtest_sources} COMPILE_FLAGS "/wd4251 /wd4146") -endif() - -# Unit tests -ign_build_tests( - TYPE "UNIT" - SOURCES ${gtest_sources} - LIB_DEPS ${EXTRA_TEST_LIB_DEPS} - TEST_LIST model_tests -) - -if(TARGET UNIT_ModelCommandAPI_TEST) - - set(IGN_CONFIG_PATH "${CMAKE_BINARY_DIR}/model/test/lib/ruby/ignition") - target_compile_definitions(UNIT_ModelCommandAPI_TEST PRIVATE - "IGN_PATH=\"${IGNITION-TOOLS_BINARY_DIRS}\"") - - target_compile_definitions(UNIT_ModelCommandAPI_TEST PRIVATE - "PROJECT_SOURCE_PATH=\"${PROJECT_SOURCE_DIR}\"") - - set_tests_properties(UNIT_ModelCommandAPI_TEST PROPERTIES - ENVIRONMENT "IGN_CONFIG_PATH=${IGN_CONFIG_PATH}" - ) -endif() - -if(NOT WIN32) - add_subdirectory(cmd) -endif() diff --git a/model/src/cmd/CMakeLists.txt b/model/src/cmd/CMakeLists.txt deleted file mode 100644 index e0c2838aef..0000000000 --- a/model/src/cmd/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -#=============================================================================== -# Used for the installed version. -# Generate the ruby script that gets installed. -# Note that the major version of the library is included in the name. -set(cmd_model_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmdmodel${PROJECT_VERSION_MAJOR}.rb") -set(cmd_model_script_configured "${cmd_model_script_generated}.configured") - -# Set the model_library_location variable to the relative path to the library file -# within the install directory structure. -set(model_library_location "../../../${CMAKE_INSTALL_LIBDIR}/$") - -configure_file( - "cmdmodel.rb.in" - "${cmd_model_script_configured}" - @ONLY) - -file(GENERATE - OUTPUT "${cmd_model_script_generated}" - INPUT "${cmd_model_script_configured}") - -install(FILES ${cmd_model_script_generated} DESTINATION lib/ruby/ignition) - -# Used for the installed version. -set(ign_model_ruby_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmdmodel${PROJECT_VERSION_MAJOR}") - -set(ignmodel_configured "${CMAKE_CURRENT_BINARY_DIR}/ignmodel${PROJECT_VERSION_MAJOR}.yaml") -configure_file( - "ignmodel.yaml.in" - ${ignmodel_configured}) - -install(FILES ${ignmodel_configured} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/ignition/) - -#=============================================================================== -# Generate the ruby script for internal testing. -# Note that the major version of the library is included in the name. -set(cmd_model_ruby_test_dir "${CMAKE_BINARY_DIR}/model/test/lib/ruby/ignition") -set(cmd_model_script_generated_test "${cmd_model_ruby_test_dir}/cmdmodel${PROJECT_VERSION_MAJOR}.rb") -set(cmd_model_script_configured_test "${cmd_model_script_generated_test}.configured") - -# Set the model_library_location variable to the full path of the library file -# within the build directory -set(model_library_location "$") - -configure_file( - "cmdmodel.rb.in" - "${cmd_model_script_configured_test}" - @ONLY) - -file(GENERATE - OUTPUT "${cmd_model_script_generated_test}" - INPUT "${cmd_model_script_configured_test}") - -# Used for internal testing. -set(ign_model_ruby_path "${cmd_model_script_generated_test}") - -configure_file( - "ignmodel.yaml.in" - "${cmd_model_ruby_test_dir}/ignmodel${PROJECT_VERSION_MAJOR}.yaml") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3521cf28b..27777aba49 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,7 @@ set(gui_sources PARENT_SCOPE ) +ign_add_component(model SOURCES cmd/ModelCommandAPI.cc GET_TARGET_NAME model_lib_target) ign_add_component(ign SOURCES ign.cc GET_TARGET_NAME ign_lib_target) target_link_libraries(${ign_lib_target} PRIVATE @@ -59,6 +60,7 @@ set (sources Util.cc View.cc World.cc + cmd/ModelCommandAPI.cc ${PROTO_PRIVATE_SRC} ${network_sources} ) @@ -74,6 +76,7 @@ set (gtest_sources ign_TEST.cc Link_TEST.cc Model_TEST.cc + ModelCommandAPI_TEST.cc SdfEntityCreator_TEST.cc SdfGenerator_TEST.cc Server_TEST.cc @@ -164,6 +167,13 @@ if(TARGET UNIT_ign_TEST) ENVIRONMENT "${_env_vars}") endif() +if(TARGET UNIT_ModelCommandAPI_TEST) + + target_compile_definitions(UNIT_ModelCommandAPI_TEST PRIVATE + "IGN_PATH=\"${IGNITION-TOOLS_BINARY_DIRS}\"") + +endif() + if(NOT WIN32) add_subdirectory(cmd) endif() diff --git a/model/src/ModelCommandAPI_TEST.cc b/src/ModelCommandAPI_TEST.cc similarity index 97% rename from model/src/ModelCommandAPI_TEST.cc rename to src/ModelCommandAPI_TEST.cc index 735f13cbae..ca4d7c01e7 100644 --- a/model/src/ModelCommandAPI_TEST.cc +++ b/src/ModelCommandAPI_TEST.cc @@ -24,6 +24,7 @@ #include #include "ignition/gazebo/Server.hh" +#include "ignition/gazebo/test_config.hh" // NOLINT(build/include) static const std::string kIgnModelCommand(std::string(IGN_PATH) + "/ign model "); @@ -40,8 +41,8 @@ void ReplaceNegativeZeroValues(std::string &_text) size_t pos = 0; while ((pos = _text.find(neg_zero, pos)) != std::string::npos) { - _text.replace(pos, neg_zero.length(), zero); - pos += zero.length(); + _text.replace(pos, neg_zero.length(), zero); + pos += zero.length(); } } @@ -114,7 +115,8 @@ TEST(ModelCommandAPI, Commands) ReplaceNegativeZeroValues(output); const std::string expectedOutput = "\nRequesting state for world [diff_drive]...\n\n" - "Name: vehicle_blue\n" + "Model: [8]\n" + " - Name: vehicle_blue\n" " - Pose: \n" " [0.000000 | 2.000000 | 0.325000]\n" " [0.000000 | 0.000000 | 0.000000]\n" @@ -191,7 +193,8 @@ TEST(ModelCommandAPI, Commands) ReplaceNegativeZeroValues(output); const std::string expectedOutput = "\nRequesting state for world [diff_drive]...\n\n" - "Name: vehicle_blue\n" + "Model: [8]\n" + " - Name: vehicle_blue\n" " - Pose: \n" " [0.000000 | 2.000000 | 0.325000]\n" " [0.000000 | 0.000000 | 0.000000]\n\n"; diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index c82f1d776a..dba0388bdb 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -36,6 +36,38 @@ install( FILES DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/ignition/) +#=============================================================================== +# Used for the installed model command version. +# Generate the ruby script that gets installed. +# Note that the major version of the library is included in the name. +set(cmd_model_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmdmodel${PROJECT_VERSION_MAJOR}.rb") +set(cmd_model_script_configured "${cmd_model_script_generated}.configured") + +# Set the model_library_location variable to the relative path to the library file +# within the install directory structure. +set(model_library_location "../../../${CMAKE_INSTALL_LIBDIR}/$") + +configure_file( + "cmdmodel.rb.in" + "${cmd_model_script_configured}" + @ONLY) +file(GENERATE + OUTPUT "${cmd_model_script_generated}" + INPUT "${cmd_model_script_configured}") + +install(FILES ${cmd_model_script_generated} DESTINATION lib/ruby/ignition) + +# Used for the installed version. +set(ign_model_ruby_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmdmodel${PROJECT_VERSION_MAJOR}") + +set(ignmodel_configured "${CMAKE_CURRENT_BINARY_DIR}/ignmodel${PROJECT_VERSION_MAJOR}.yaml") +configure_file( + "ignmodel.yaml.in" + ${ignmodel_configured}) + +install(FILES ${ignmodel_configured} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/ignition/) + + #=============================================================================== # Generate the ruby script for internal testing. # Note that the major version of the library is included in the name. @@ -66,3 +98,30 @@ set(ign_library_path configure_file( "${IGN_DESIGNATION}.yaml.in" "${CMAKE_BINARY_DIR}/test/conf/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY) + +#=============================================================================== +# Generate the ruby script for internal testing. +# Note that the major version of the library is included in the name. +set(cmd_model_ruby_test_dir "${CMAKE_BINARY_DIR}/model/test/lib/ruby/ignition") +set(cmd_model_script_generated_test "${cmd_model_ruby_test_dir}/cmdmodel${PROJECT_VERSION_MAJOR}.rb") +set(cmd_model_script_configured_test "${cmd_model_script_generated_test}.configured") + +# Set the model_library_location variable to the full path of the library file +# within the build directory +set(model_library_location "$") + +configure_file( + "cmdmodel.rb.in" + "${cmd_model_script_configured_test}" + @ONLY) + +file(GENERATE + OUTPUT "${cmd_model_script_generated_test}" + INPUT "${cmd_model_script_configured_test}") + +# Used for internal testing. +set(ign_model_ruby_path "${cmd_model_script_generated_test}") + +configure_file( + "ignmodel.yaml.in" + "${cmd_model_ruby_test_dir}/ignmodel${PROJECT_VERSION_MAJOR}.yaml") diff --git a/model/src/cmd/ModelCommandAPI.cc b/src/cmd/ModelCommandAPI.cc similarity index 98% rename from model/src/cmd/ModelCommandAPI.cc rename to src/cmd/ModelCommandAPI.cc index 19f9b88677..630e73a9ab 100644 --- a/model/src/cmd/ModelCommandAPI.cc +++ b/src/cmd/ModelCommandAPI.cc @@ -78,7 +78,7 @@ std::string getWorldName() // \brief Set the state of a ECM instance with a world snapshot. // \param _ecm ECM instance to be populated. // \return boolean indicating if it was able to populate the ECM. -bool PopulateECM(ignition::gazebo::EntityComponentManager &_ecm) +bool populateECM(ignition::gazebo::EntityComponentManager &_ecm) { const std::string world = getWorldName(); if (world.empty()) @@ -143,7 +143,8 @@ void printPose(const uint64_t _entity, + std::to_string(poseComp->Data().Pitch()) + " | " + std::to_string(poseComp->Data().Yaw()) + "]"; - std::cout << "Name: " << nameComp->Data() << std::endl + std::cout << "Model: [" << _entity << "]" << std::endl + << " - Name: " << nameComp->Data() << std::endl << " - Pose: " << poseInfo << std::endl << std::endl; } } @@ -304,7 +305,7 @@ void printJoints(const uint64_t entity, extern "C" IGNITION_GAZEBO_VISIBLE void cmdModelList() { ignition::gazebo::EntityComponentManager ecm{}; - if(!PopulateECM(ecm)) + if(!populateECM(ecm)) { return; } @@ -347,7 +348,7 @@ extern "C" IGNITION_GAZEBO_VISIBLE void cmdModelInfo( // Get arguments ignition::gazebo::EntityComponentManager ecm{}; - if(!PopulateECM(ecm)) + if(!populateECM(ecm)) return; // Get the desired model entity. diff --git a/model/src/cmd/ModelCommandAPI.hh b/src/cmd/ModelCommandAPI.hh similarity index 100% rename from model/src/cmd/ModelCommandAPI.hh rename to src/cmd/ModelCommandAPI.hh diff --git a/model/src/cmd/cmdmodel.rb.in b/src/cmd/cmdmodel.rb.in similarity index 90% rename from model/src/cmd/cmdmodel.rb.in rename to src/cmd/cmdmodel.rb.in index 1843654069..967c679c3b 100644 --- a/model/src/cmd/cmdmodel.rb.in +++ b/src/cmd/cmdmodel.rb.in @@ -47,13 +47,18 @@ COMMANDS = { 'model' => " If no arg is passed all links are printed \n"\ " Requires the -m option \n"\ " \n"\ + " E.g. to get information about the \n"\ + " caster link in the diff_drive world, run: \n"\ + " ign model -m vehicle_blue -l caster \n"\ + " \n"\ " -j [--joint] arg Select a joint to show its properties. \n"\ " If no arg is passed all joints are printed \n"\ " Requires the -m option \n"\ " \n"\ " E.g. to get information about the \n"\ - " box_link in the shapes world, run: \n"\ - " ign model -m box -l box_link \n\n"+ + " caster_wheel joint in the diff_drive \n"\ + " world, run: \n"\ + " ign model -m vehicle_blue -j caster_wheel \n\n"+ COMMON_OPTIONS } @@ -77,7 +82,7 @@ class Cmd opt_parser = OptionParser.new do |opts| opts.banner = usage - + opts.on('-h', '--help') do puts usage exit @@ -124,8 +129,8 @@ class Cmd options end # parse() - - + + def execute(args) options = parse(args) @@ -159,7 +164,7 @@ class Cmd Importer.cmdModelInfo(options['model'], options['pose'], options['link'], options['link_name'], options['joint'], options['joint_name']) - else + else puts 'Command error: I do not have an implementation for '\ "command [ign #{options['command']}]." end diff --git a/model/src/cmd/ignmodel.yaml.in b/src/cmd/ignmodel.yaml.in similarity index 100% rename from model/src/cmd/ignmodel.yaml.in rename to src/cmd/ignmodel.yaml.in