From fe8b17ec18418331ef8a90fc771846d3144cee5f Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Tue, 17 Dec 2024 18:56:55 +0900 Subject: [PATCH 01/13] temporary commit Signed-off-by: TaikiYamada4 --- .../src/validators/validator_template.cpp | 10 ++++++++-- .../src/validators/validator_template.hpp | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp b/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp index c444a046..3806fc41 100644 --- a/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp +++ b/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include "validator_template.hpp" +#include "lanelet2_map_validator/utils.hpp" namespace lanelet::autoware::validation { @@ -25,9 +26,14 @@ lanelet::validation::Issues ValidatorTemplate::operator()(const lanelet::Lanelet { lanelet::validation::Issues issues; - // Remove this line and write down how to append issues - (void)map; + lanelet::autoware::validation::appendIssues( + issues, checkFunction(map)); return issues; } + +lanelet::validation::Issues ValidatorTemplate::checkFunction(const lanelet::LaneletMap & map){ + lanelet::validation::Issues issues; + return issues; +} } // namespace lanelet::autoware::validation diff --git a/map/autoware_lanelet2_map_validator/src/validators/validator_template.hpp b/map/autoware_lanelet2_map_validator/src/validators/validator_template.hpp index 1b4507ab..d5dc9c7e 100644 --- a/map/autoware_lanelet2_map_validator/src/validators/validator_template.hpp +++ b/map/autoware_lanelet2_map_validator/src/validators/validator_template.hpp @@ -29,6 +29,7 @@ class ValidatorTemplate : public lanelet::validation::MapValidator lanelet::validation::Issues operator()(const lanelet::LaneletMap & map) override; private: + lanelet::validation::Issues checkFunction(const lanelet::LaneletMap & map); }; } // namespace lanelet::autoware::validation From 7c3db06347c494227f5cfdc86da21881194d0b5c Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Wed, 18 Dec 2024 14:21:06 +0900 Subject: [PATCH 02/13] Added python script Signed-off-by: TaikiYamada4 --- .../src/create_new_validator.py | 54 +++++++++++++++++++ .../validators/test_validator_template.cpp | 47 ++++++++++++++++ .../src/validators/validator_template.cpp | 3 ++ 3 files changed, 104 insertions(+) create mode 100644 map/autoware_lanelet2_map_validator/src/create_new_validator.py create mode 100644 map/autoware_lanelet2_map_validator/src/validators/test_validator_template.cpp diff --git a/map/autoware_lanelet2_map_validator/src/create_new_validator.py b/map/autoware_lanelet2_map_validator/src/create_new_validator.py new file mode 100644 index 00000000..dfef49f5 --- /dev/null +++ b/map/autoware_lanelet2_map_validator/src/create_new_validator.py @@ -0,0 +1,54 @@ +import shutil +import os + +def create_files(base_directory, category_name, code_name, class_name, validator_name, check_function_name): + # Define directories + template_directory = os.path.join(base_directory, 'src') + src_directory = os.path.join(base_directory, 'src/validators', category_name) + include_directory = os.path.join(base_directory, 'src/include/lanelet2_map_validator/validators', category_name) + docs_directory = os.path.join(base_directory, 'docs', category_name) + test_directory = os.path.join(base_directory, 'test/src') + + # Define source and destination file paths + cpp_template = os.path.join(template_directory,'validator_template.cpp') + hpp_template = os.path.join(template_directory,'validator_template.hpp') + test_template = os.path.join(template_directory, 'test_validator_template.cpp') + cpp_new = os.path.join(src_directory, f'{code_name}.cpp') + hpp_new = os.path.join(include_directory, f'{code_name}.hpp') + test_new = os.path.join(test_directory, f'test_{code_name}.cpp') + + # Copy template files + shutil.copy(cpp_template, cpp_new) + shutil.copy(hpp_template, hpp_new) + shutil.copy(test_template, test_new) + + # Replace class name in the new files + for file_path in [cpp_new, hpp_new, test_new]: + with open(file_path, 'r') as file: + content = file.read() + # Replace the class name + content = content.replace('ValidatorTemplate', class_name) + content = content.replace('mapping.validator.template', validator_name) + content = content.replace('checkFunction', check_function_name) + content = content.replace( + 'validator_template.hpp' + 'lanelet2_map_validator/validators/' + category_name + '/' + code_name + '.hpp' + ) + content = content.replace( + 'VALIDATORS__VALIDATOR_TEMPLATE_HPP_' + 'LANELET2_MAP_VALIDATOR__VALIDATORS__' + category_name.upper() + '__' + code_name.upper() + '_HPP_' + ) + with open(file_path, 'w') as file: + file.write(content) + +if __name__ == "__main__": + # User-defined parameters + directory_path = "./" # Replace with package directory path + category_name = "category" + code_name = "enter_code_name" # + class_name = "EnterClassNameValidator" + validator_name = "mapping.enter.validator_name" + check_function_name = "enter_function_name" + + create_files(directory_path, category_name, code_name, class_name, validator_name, check_function_name) + print("Process complete.") diff --git a/map/autoware_lanelet2_map_validator/src/validators/test_validator_template.cpp b/map/autoware_lanelet2_map_validator/src/validators/test_validator_template.cpp new file mode 100644 index 00000000..051e1dff --- /dev/null +++ b/map/autoware_lanelet2_map_validator/src/validators/test_validator_template.cpp @@ -0,0 +1,47 @@ +// Copyright 2024 Autoware 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 "validator_template.hpp" +#include "map_validation_tester.hpp" + +#include +#include + +class TestValidatorTemplate : public MapValidationTester +{ +private: +}; + +TEST_F(TestValidatorTemplate, ValidatorAvailability) // NOLINT for gtest +{ + std::string expected_validator_name = + lanelet::autoware::validation::ValidatorTemplate::name(); + + lanelet::validation::Strings validators = + lanelet::validation::availabeChecks(expected_validator_name); // cspell:disable-line + + const uint32_t expected_validator_num = 1; + EXPECT_EQ(expected_validator_num, validators.size()); + EXPECT_EQ(expected_validator_name, validators[0]); +} + +TEST_F(TestValidatorTemplate, SampleMap) // NOLINT for gtest +{ + load_target_map("sample_map.osm"); + + lanelet::autoware::validation::ValidatorTemplate checker; + const auto & issues = checker(*map_); + + EXPECT_EQ(issues.size(), 0); +} diff --git a/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp b/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp index 3806fc41..aecbe4e6 100644 --- a/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp +++ b/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp @@ -34,6 +34,9 @@ lanelet::validation::Issues ValidatorTemplate::operator()(const lanelet::Lanelet lanelet::validation::Issues ValidatorTemplate::checkFunction(const lanelet::LaneletMap & map){ lanelet::validation::Issues issues; + + (void)map; + return issues; } } // namespace lanelet::autoware::validation From d1d30bcc3d96895d325ce5bf4416dc4b65627b52 Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Wed, 18 Dec 2024 16:26:41 +0900 Subject: [PATCH 03/13] Finished except docs Signed-off-by: TaikiYamada4 --- .../src/create_new_validator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 map/autoware_lanelet2_map_validator/src/create_new_validator.py diff --git a/map/autoware_lanelet2_map_validator/src/create_new_validator.py b/map/autoware_lanelet2_map_validator/src/create_new_validator.py old mode 100644 new mode 100755 index dfef49f5..92b46676 --- a/map/autoware_lanelet2_map_validator/src/create_new_validator.py +++ b/map/autoware_lanelet2_map_validator/src/create_new_validator.py @@ -3,7 +3,7 @@ def create_files(base_directory, category_name, code_name, class_name, validator_name, check_function_name): # Define directories - template_directory = os.path.join(base_directory, 'src') + template_directory = os.path.join(base_directory, 'src/validators') src_directory = os.path.join(base_directory, 'src/validators', category_name) include_directory = os.path.join(base_directory, 'src/include/lanelet2_map_validator/validators', category_name) docs_directory = os.path.join(base_directory, 'docs', category_name) @@ -31,11 +31,11 @@ def create_files(base_directory, category_name, code_name, class_name, validator content = content.replace('mapping.validator.template', validator_name) content = content.replace('checkFunction', check_function_name) content = content.replace( - 'validator_template.hpp' + 'validator_template.hpp', 'lanelet2_map_validator/validators/' + category_name + '/' + code_name + '.hpp' ) content = content.replace( - 'VALIDATORS__VALIDATOR_TEMPLATE_HPP_' + 'VALIDATORS__VALIDATOR_TEMPLATE_HPP_', 'LANELET2_MAP_VALIDATOR__VALIDATORS__' + category_name.upper() + '__' + code_name.upper() + '_HPP_' ) with open(file_path, 'w') as file: @@ -44,7 +44,7 @@ def create_files(base_directory, category_name, code_name, class_name, validator if __name__ == "__main__": # User-defined parameters directory_path = "./" # Replace with package directory path - category_name = "category" + category_name = "stop_line" code_name = "enter_code_name" # class_name = "EnterClassNameValidator" validator_name = "mapping.enter.validator_name" From da7975ed3c407819c1c6610173734713655b21fa Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Wed, 18 Dec 2024 16:57:55 +0900 Subject: [PATCH 04/13] Added documents related stuff Signed-off-by: TaikiYamada4 --- .../src/create_new_validator.py | 76 +++++++++++-------- .../src/validators/validator_template.md | 18 +++++ 2 files changed, 64 insertions(+), 30 deletions(-) create mode 100644 map/autoware_lanelet2_map_validator/src/validators/validator_template.md diff --git a/map/autoware_lanelet2_map_validator/src/create_new_validator.py b/map/autoware_lanelet2_map_validator/src/create_new_validator.py index 92b46676..221694ac 100755 --- a/map/autoware_lanelet2_map_validator/src/create_new_validator.py +++ b/map/autoware_lanelet2_map_validator/src/create_new_validator.py @@ -1,54 +1,70 @@ -import shutil import os +import shutil -def create_files(base_directory, category_name, code_name, class_name, validator_name, check_function_name): + +def create_files( + base_directory, category_name, code_name, class_name, validator_name, check_function_name +): # Define directories - template_directory = os.path.join(base_directory, 'src/validators') - src_directory = os.path.join(base_directory, 'src/validators', category_name) - include_directory = os.path.join(base_directory, 'src/include/lanelet2_map_validator/validators', category_name) - docs_directory = os.path.join(base_directory, 'docs', category_name) - test_directory = os.path.join(base_directory, 'test/src') - + template_directory = os.path.join(base_directory, "src/validators") + src_directory = os.path.join(base_directory, "src/validators", category_name) + include_directory = os.path.join( + base_directory, "src/include/lanelet2_map_validator/validators", category_name + ) + docs_directory = os.path.join(base_directory, "docs", category_name) + test_directory = os.path.join(base_directory, "test/src") + # Define source and destination file paths - cpp_template = os.path.join(template_directory,'validator_template.cpp') - hpp_template = os.path.join(template_directory,'validator_template.hpp') - test_template = os.path.join(template_directory, 'test_validator_template.cpp') - cpp_new = os.path.join(src_directory, f'{code_name}.cpp') - hpp_new = os.path.join(include_directory, f'{code_name}.hpp') - test_new = os.path.join(test_directory, f'test_{code_name}.cpp') - + cpp_template = os.path.join(template_directory, "validator_template.cpp") + hpp_template = os.path.join(template_directory, "validator_template.hpp") + test_template = os.path.join(template_directory, "test_validator_template.cpp") + docs_template = os.path.join(template_directory, "validator_template.md") + cpp_new = os.path.join(src_directory, f"{code_name}.cpp") + hpp_new = os.path.join(include_directory, f"{code_name}.hpp") + test_new = os.path.join(test_directory, f"test_{code_name}.cpp") + docs_new = os.path.join(docs_directory, f"{code_name}.md") + # Copy template files shutil.copy(cpp_template, cpp_new) shutil.copy(hpp_template, hpp_new) shutil.copy(test_template, test_new) - + shutil.copy(docs_template, docs_new) + # Replace class name in the new files - for file_path in [cpp_new, hpp_new, test_new]: - with open(file_path, 'r') as file: + for file_path in [cpp_new, hpp_new, test_new, docs_new]: + with open(file_path, "r") as file: content = file.read() # Replace the class name - content = content.replace('ValidatorTemplate', class_name) - content = content.replace('mapping.validator.template', validator_name) - content = content.replace('checkFunction', check_function_name) + content = content.replace("ValidatorTemplate", class_name) + content = content.replace("mapping.validator.template", validator_name) + content = content.replace("checkFunction", check_function_name) + content = content.replace("- validator_template", "- " + code_name) content = content.replace( - 'validator_template.hpp', - 'lanelet2_map_validator/validators/' + category_name + '/' + code_name + '.hpp' + "validator_template.hpp", + "lanelet2_map_validator/validators/" + category_name + "/" + code_name + ".hpp", ) content = content.replace( - 'VALIDATORS__VALIDATOR_TEMPLATE_HPP_', - 'LANELET2_MAP_VALIDATOR__VALIDATORS__' + category_name.upper() + '__' + code_name.upper() + '_HPP_' + "VALIDATORS__VALIDATOR_TEMPLATE_HPP_", + "LANELET2_MAP_VALIDATOR__VALIDATORS__" + + category_name.upper() + + "__" + + code_name.upper() + + "_HPP_", ) - with open(file_path, 'w') as file: + with open(file_path, "w") as file: file.write(content) + if __name__ == "__main__": # User-defined parameters directory_path = "./" # Replace with package directory path - category_name = "stop_line" - code_name = "enter_code_name" # + category_name = "category" + code_name = "enter_code_name" # class_name = "EnterClassNameValidator" validator_name = "mapping.enter.validator_name" check_function_name = "enter_function_name" - - create_files(directory_path, category_name, code_name, class_name, validator_name, check_function_name) + + create_files( + directory_path, category_name, code_name, class_name, validator_name, check_function_name + ) print("Process complete.") diff --git a/map/autoware_lanelet2_map_validator/src/validators/validator_template.md b/map/autoware_lanelet2_map_validator/src/validators/validator_template.md new file mode 100644 index 00000000..3585f68e --- /dev/null +++ b/map/autoware_lanelet2_map_validator/src/validators/validator_template.md @@ -0,0 +1,18 @@ +# validator_template + +## Validator name + +mapping.validator.template + +## Feature + +Feature explaination here. + +| Issue Code | Message | Severity | Description | Approach | +| ---------- | ------- | -------- | ----------- | -------- | +| | | | | | + +## Related source codes + +- validator_template.cpp +- validator_template.hpp From b80544e0279ae16d1b98efb5f93b163efb4ede32 Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Wed, 18 Dec 2024 17:01:56 +0900 Subject: [PATCH 05/13] Moved stuff to templates Signed-off-by: TaikiYamada4 --- .../{src => templates}/create_new_validator.py | 0 .../validators => templates}/test_validator_template.cpp | 5 ++--- .../{src/validators => templates}/validator_template.cpp | 7 ++++--- .../{src/validators => templates}/validator_template.hpp | 6 +++--- .../{src/validators => templates}/validator_template.md | 0 5 files changed, 9 insertions(+), 9 deletions(-) rename map/autoware_lanelet2_map_validator/{src => templates}/create_new_validator.py (100%) rename map/autoware_lanelet2_map_validator/{src/validators => templates}/test_validator_template.cpp (93%) rename map/autoware_lanelet2_map_validator/{src/validators => templates}/validator_template.cpp (91%) rename map/autoware_lanelet2_map_validator/{src/validators => templates}/validator_template.hpp (82%) rename map/autoware_lanelet2_map_validator/{src/validators => templates}/validator_template.md (100%) diff --git a/map/autoware_lanelet2_map_validator/src/create_new_validator.py b/map/autoware_lanelet2_map_validator/templates/create_new_validator.py similarity index 100% rename from map/autoware_lanelet2_map_validator/src/create_new_validator.py rename to map/autoware_lanelet2_map_validator/templates/create_new_validator.py diff --git a/map/autoware_lanelet2_map_validator/src/validators/test_validator_template.cpp b/map/autoware_lanelet2_map_validator/templates/test_validator_template.cpp similarity index 93% rename from map/autoware_lanelet2_map_validator/src/validators/test_validator_template.cpp rename to map/autoware_lanelet2_map_validator/templates/test_validator_template.cpp index 051e1dff..c38c1627 100644 --- a/map/autoware_lanelet2_map_validator/src/validators/test_validator_template.cpp +++ b/map/autoware_lanelet2_map_validator/templates/test_validator_template.cpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "validator_template.hpp" #include "map_validation_tester.hpp" +#include "validator_template.hpp" #include #include @@ -25,8 +25,7 @@ class TestValidatorTemplate : public MapValidationTester TEST_F(TestValidatorTemplate, ValidatorAvailability) // NOLINT for gtest { - std::string expected_validator_name = - lanelet::autoware::validation::ValidatorTemplate::name(); + std::string expected_validator_name = lanelet::autoware::validation::ValidatorTemplate::name(); lanelet::validation::Strings validators = lanelet::validation::availabeChecks(expected_validator_name); // cspell:disable-line diff --git a/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp b/map/autoware_lanelet2_map_validator/templates/validator_template.cpp similarity index 91% rename from map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp rename to map/autoware_lanelet2_map_validator/templates/validator_template.cpp index aecbe4e6..5ed7ad65 100644 --- a/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp +++ b/map/autoware_lanelet2_map_validator/templates/validator_template.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include "validator_template.hpp" + #include "lanelet2_map_validator/utils.hpp" namespace lanelet::autoware::validation @@ -26,13 +27,13 @@ lanelet::validation::Issues ValidatorTemplate::operator()(const lanelet::Lanelet { lanelet::validation::Issues issues; - lanelet::autoware::validation::appendIssues( - issues, checkFunction(map)); + lanelet::autoware::validation::appendIssues(issues, checkFunction(map)); return issues; } -lanelet::validation::Issues ValidatorTemplate::checkFunction(const lanelet::LaneletMap & map){ +lanelet::validation::Issues ValidatorTemplate::checkFunction(const lanelet::LaneletMap & map) +{ lanelet::validation::Issues issues; (void)map; diff --git a/map/autoware_lanelet2_map_validator/src/validators/validator_template.hpp b/map/autoware_lanelet2_map_validator/templates/validator_template.hpp similarity index 82% rename from map/autoware_lanelet2_map_validator/src/validators/validator_template.hpp rename to map/autoware_lanelet2_map_validator/templates/validator_template.hpp index d5dc9c7e..af2507a9 100644 --- a/map/autoware_lanelet2_map_validator/src/validators/validator_template.hpp +++ b/map/autoware_lanelet2_map_validator/templates/validator_template.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef VALIDATORS__VALIDATOR_TEMPLATE_HPP_ -#define VALIDATORS__VALIDATOR_TEMPLATE_HPP_ +#ifndef MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATES__VALIDATOR_TEMPLATE_HPP_ +#define MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATES__VALIDATOR_TEMPLATE_HPP_ #include #include @@ -33,4 +33,4 @@ class ValidatorTemplate : public lanelet::validation::MapValidator }; } // namespace lanelet::autoware::validation -#endif // VALIDATORS__VALIDATOR_TEMPLATE_HPP_ +#endif // MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATES__VALIDATOR_TEMPLATE_HPP_ diff --git a/map/autoware_lanelet2_map_validator/src/validators/validator_template.md b/map/autoware_lanelet2_map_validator/templates/validator_template.md similarity index 100% rename from map/autoware_lanelet2_map_validator/src/validators/validator_template.md rename to map/autoware_lanelet2_map_validator/templates/validator_template.md From 619d8d1c527c31f1534f31bb4ca0e9c825a1c547 Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Wed, 18 Dec 2024 17:16:17 +0900 Subject: [PATCH 06/13] Revised files to suit the current directory Signed-off-by: TaikiYamada4 --- .../create_new_validator.py | 14 ++++++++++---- .../test_validator_template.cpp | 0 .../{templates => template}/validator_template.cpp | 0 .../{templates => template}/validator_template.hpp | 6 +++--- .../{templates => template}/validator_template.md | 0 5 files changed, 13 insertions(+), 7 deletions(-) rename map/autoware_lanelet2_map_validator/{templates => template}/create_new_validator.py (86%) rename map/autoware_lanelet2_map_validator/{templates => template}/test_validator_template.cpp (100%) rename map/autoware_lanelet2_map_validator/{templates => template}/validator_template.cpp (100%) rename map/autoware_lanelet2_map_validator/{templates => template}/validator_template.hpp (82%) rename map/autoware_lanelet2_map_validator/{templates => template}/validator_template.md (100%) diff --git a/map/autoware_lanelet2_map_validator/templates/create_new_validator.py b/map/autoware_lanelet2_map_validator/template/create_new_validator.py similarity index 86% rename from map/autoware_lanelet2_map_validator/templates/create_new_validator.py rename to map/autoware_lanelet2_map_validator/template/create_new_validator.py index 221694ac..f5dc3735 100755 --- a/map/autoware_lanelet2_map_validator/templates/create_new_validator.py +++ b/map/autoware_lanelet2_map_validator/template/create_new_validator.py @@ -6,7 +6,7 @@ def create_files( base_directory, category_name, code_name, class_name, validator_name, check_function_name ): # Define directories - template_directory = os.path.join(base_directory, "src/validators") + template_directory = os.path.join(base_directory, "template") src_directory = os.path.join(base_directory, "src/validators", category_name) include_directory = os.path.join( base_directory, "src/include/lanelet2_map_validator/validators", category_name @@ -30,6 +30,13 @@ def create_files( shutil.copy(test_template, test_new) shutil.copy(docs_template, docs_new) + # This is only for documents!! + with open(docs_new, "r") as file: + content = file.read() + content = content.replace("validator_template", code_name) + with open(docs_new, "w") as file: + file.write(content) + # Replace class name in the new files for file_path in [cpp_new, hpp_new, test_new, docs_new]: with open(file_path, "r") as file: @@ -38,13 +45,12 @@ def create_files( content = content.replace("ValidatorTemplate", class_name) content = content.replace("mapping.validator.template", validator_name) content = content.replace("checkFunction", check_function_name) - content = content.replace("- validator_template", "- " + code_name) content = content.replace( "validator_template.hpp", "lanelet2_map_validator/validators/" + category_name + "/" + code_name + ".hpp", ) content = content.replace( - "VALIDATORS__VALIDATOR_TEMPLATE_HPP_", + "MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATES__VALIDATOR_TEMPLATE_HPP_", "LANELET2_MAP_VALIDATOR__VALIDATORS__" + category_name.upper() + "__" @@ -58,7 +64,7 @@ def create_files( if __name__ == "__main__": # User-defined parameters directory_path = "./" # Replace with package directory path - category_name = "category" + category_name = "stop_line" code_name = "enter_code_name" # class_name = "EnterClassNameValidator" validator_name = "mapping.enter.validator_name" diff --git a/map/autoware_lanelet2_map_validator/templates/test_validator_template.cpp b/map/autoware_lanelet2_map_validator/template/test_validator_template.cpp similarity index 100% rename from map/autoware_lanelet2_map_validator/templates/test_validator_template.cpp rename to map/autoware_lanelet2_map_validator/template/test_validator_template.cpp diff --git a/map/autoware_lanelet2_map_validator/templates/validator_template.cpp b/map/autoware_lanelet2_map_validator/template/validator_template.cpp similarity index 100% rename from map/autoware_lanelet2_map_validator/templates/validator_template.cpp rename to map/autoware_lanelet2_map_validator/template/validator_template.cpp diff --git a/map/autoware_lanelet2_map_validator/templates/validator_template.hpp b/map/autoware_lanelet2_map_validator/template/validator_template.hpp similarity index 82% rename from map/autoware_lanelet2_map_validator/templates/validator_template.hpp rename to map/autoware_lanelet2_map_validator/template/validator_template.hpp index af2507a9..25b37e25 100644 --- a/map/autoware_lanelet2_map_validator/templates/validator_template.hpp +++ b/map/autoware_lanelet2_map_validator/template/validator_template.hpp @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATES__VALIDATOR_TEMPLATE_HPP_ -#define MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATES__VALIDATOR_TEMPLATE_HPP_ +#ifndef MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATE__VALIDATOR_TEMPLATE_HPP_ +#define MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATE__VALIDATOR_TEMPLATE_HPP_ #include #include @@ -33,4 +33,4 @@ class ValidatorTemplate : public lanelet::validation::MapValidator }; } // namespace lanelet::autoware::validation -#endif // MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATES__VALIDATOR_TEMPLATE_HPP_ +#endif // MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATE__VALIDATOR_TEMPLATE_HPP_ diff --git a/map/autoware_lanelet2_map_validator/templates/validator_template.md b/map/autoware_lanelet2_map_validator/template/validator_template.md similarity index 100% rename from map/autoware_lanelet2_map_validator/templates/validator_template.md rename to map/autoware_lanelet2_map_validator/template/validator_template.md From 4b08fe6576bce3bdd185e5af0130420141755ece Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Thu, 19 Dec 2024 12:07:21 +0900 Subject: [PATCH 07/13] Added arguments Signed-off-by: TaikiYamada4 --- .../template/create_new_validator.py | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/map/autoware_lanelet2_map_validator/template/create_new_validator.py b/map/autoware_lanelet2_map_validator/template/create_new_validator.py index f5dc3735..ab4dac9a 100755 --- a/map/autoware_lanelet2_map_validator/template/create_new_validator.py +++ b/map/autoware_lanelet2_map_validator/template/create_new_validator.py @@ -1,3 +1,4 @@ +import argparse import os import shutil @@ -62,13 +63,42 @@ def create_files( if __name__ == "__main__": + # Arguments + parser = argparse.ArgumentParser(description="Generate files for a new validator.") + parser.add_argument( + "--base_directory", default="./", help="Path to the autoware_lanelet2_map_validator package" + ) + parser.add_argument( + "--category_name", default="enter_category", help="Category name of the validator" + ) + parser.add_argument( + "--code_name", + default="enter_code_name", + help="Code name for the validator files (e.g. code_name.cpp, code_name.hpp)", + ) + parser.add_argument( + "--class_name", default="EnterClassNameValidator", help="Class name for the validator" + ) + parser.add_argument( + "--validator_name", + default="mapping.category.something", + help="Full validator name (e. g. mapping.category.something)", + ) + parser.add_argument( + "--check_function_name", + default="enter_function_name", + help="Check function name for the validator", + ) + + args = parser.parse_args() + # User-defined parameters - directory_path = "./" # Replace with package directory path - category_name = "stop_line" - code_name = "enter_code_name" # - class_name = "EnterClassNameValidator" - validator_name = "mapping.enter.validator_name" - check_function_name = "enter_function_name" + directory_path = args.base_directory # Replace with package directory path + category_name = args.category_name + code_name = args.code_name + class_name = args.class_name + validator_name = args.validator_name + check_function_name = args.check_function_name create_files( directory_path, category_name, code_name, class_name, validator_name, check_function_name From d4f0fd4dc270013398a8078d8f30757b83711f14 Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Thu, 19 Dec 2024 12:23:23 +0900 Subject: [PATCH 08/13] Added prints Signed-off-by: TaikiYamada4 --- .../template/create_new_validator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/map/autoware_lanelet2_map_validator/template/create_new_validator.py b/map/autoware_lanelet2_map_validator/template/create_new_validator.py index ab4dac9a..90bec7f6 100755 --- a/map/autoware_lanelet2_map_validator/template/create_new_validator.py +++ b/map/autoware_lanelet2_map_validator/template/create_new_validator.py @@ -21,9 +21,13 @@ def create_files( test_template = os.path.join(template_directory, "test_validator_template.cpp") docs_template = os.path.join(template_directory, "validator_template.md") cpp_new = os.path.join(src_directory, f"{code_name}.cpp") + print("Create " + cpp_new) hpp_new = os.path.join(include_directory, f"{code_name}.hpp") + print("Create " + hpp_new) test_new = os.path.join(test_directory, f"test_{code_name}.cpp") + print("Create " + test_new) docs_new = os.path.join(docs_directory, f"{code_name}.md") + print("Create " + docs_new) # Copy template files shutil.copy(cpp_template, cpp_new) From 39fcda669a11625ec9d053e0abfe4521e4826520 Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Fri, 20 Dec 2024 11:47:48 +0900 Subject: [PATCH 09/13] added #include to test code Signed-off-by: TaikiYamada4 --- .../template/test_validator_template.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/map/autoware_lanelet2_map_validator/template/test_validator_template.cpp b/map/autoware_lanelet2_map_validator/template/test_validator_template.cpp index c38c1627..23a4000a 100644 --- a/map/autoware_lanelet2_map_validator/template/test_validator_template.cpp +++ b/map/autoware_lanelet2_map_validator/template/test_validator_template.cpp @@ -18,6 +18,8 @@ #include #include +#include + class TestValidatorTemplate : public MapValidationTester { private: From d0762ecaaff6c6d2b2550a4e71dcf178cb78ca20 Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Thu, 26 Dec 2024 14:41:23 +0900 Subject: [PATCH 10/13] Fixed typo Signed-off-by: TaikiYamada4 --- .../docs/how_to_contribute.md | 27 ++++++++++++++++++- .../template/create_new_validator.py | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md b/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md index 8f097c10..a07b28be 100644 --- a/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md +++ b/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md @@ -37,7 +37,32 @@ This section is aimed at contributors who want to add their own validators. If y -Contributors are encouraged to make their validators by following the class structure shown in [`validator_template.cpp`](https://github.com/autowarefoundation/autoware_tools/blob/main/map/autoware_lanelet2_map_validator/src/validators/validator_template.cpp) and [`validator_template.hpp`](https://github.com/autowarefoundation/autoware_tools/blob/main/map/autoware_lanelet2_map_validator/src/validators/validator_template.hpp). Looking at other implementations may also be helpful. +Contributors are encouraged to make their validators by following the class structure shown in [`validator_template.cpp`](https://github.com/autowarefoundation/autoware_tools/blob/main/map/autoware_lanelet2_map_validator/template/validator_template.cpp) and [`validator_template.hpp`](https://github.com/autowarefoundation/autoware_tools/blob/main/map/autoware_lanelet2_map_validator/template/validator_template.hpp). + +#### `create_new_validator.py` may be useful + +You can use the script [`create_new_validator.py`](https://github.com/autowarefoundation/autoware_tools/blob/main/map/autoware_lanelet2_map_validator/template/create_new_validator.py) to generate the required files below. + +- Source codes (cpp and hpp) +- Test code (cpp) +- Document file (md) + +You can use this by the command like this example: + +```shell +python3 create_new_validator.py --base_directory ./ --category_name traffic_light --code_name traffic_light_facing --class_name TrafficLightFacingValidator --validator_name mapping.traffic_light.correct_facing --check_function_name check_traffic_light_facing +``` + +All arguments are required. + +- `--base_directory`: The directory to the `autoware_lanelet2_map_validator` package. +- `--category_name`: The category (like lanelet, traffic_light...) where your validator belongs to. Look [Design Concept](#design-concept) to see the list of categories. +- `--class_name`: The base class name of your validator which will be defined in your new header file. +- `--validator_name`: The name of the validator which will be displayed when `autoware_lanelet2_map_validator` is executed with a `--print` option. The naming rules are explained in [Restrictions for validator class implementation](#restrictions-for-validator-class-implementation). +- `--check_function_name`: The main function name of your validator which will be defined in your header file, and its implementation will be written in the cpp source file. + +It may be quicker to recognize what this script do by trying the command out. +If you feel typing these arguments exhausting, you can overwrite the `default` value in the python script, but do not forget not to commit those changes. #### Restrictions for path structure diff --git a/map/autoware_lanelet2_map_validator/template/create_new_validator.py b/map/autoware_lanelet2_map_validator/template/create_new_validator.py index 90bec7f6..b704843d 100755 --- a/map/autoware_lanelet2_map_validator/template/create_new_validator.py +++ b/map/autoware_lanelet2_map_validator/template/create_new_validator.py @@ -55,7 +55,7 @@ def create_files( "lanelet2_map_validator/validators/" + category_name + "/" + code_name + ".hpp", ) content = content.replace( - "MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATES__VALIDATOR_TEMPLATE_HPP_", + "MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATE__VALIDATOR_TEMPLATE_HPP_", "LANELET2_MAP_VALIDATOR__VALIDATORS__" + category_name.upper() + "__" From 1171aec8413450e18480dde296443748cd2c1e14 Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Thu, 26 Dec 2024 14:42:27 +0900 Subject: [PATCH 11/13] Write explanation of create_new_validator.py Signed-off-by: TaikiYamada4 --- .../template/validator_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/map/autoware_lanelet2_map_validator/template/validator_template.md b/map/autoware_lanelet2_map_validator/template/validator_template.md index 3585f68e..5e5f81ab 100644 --- a/map/autoware_lanelet2_map_validator/template/validator_template.md +++ b/map/autoware_lanelet2_map_validator/template/validator_template.md @@ -6,7 +6,7 @@ mapping.validator.template ## Feature -Feature explaination here. +Feature explanation here. | Issue Code | Message | Severity | Description | Approach | | ---------- | ------- | -------- | ----------- | -------- | From 092b6d07984d6cb13580d1e5925e881b4fe16202 Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Thu, 26 Dec 2024 15:02:53 +0900 Subject: [PATCH 12/13] Added back slashes to example command Signed-off-by: TaikiYamada4 --- .../docs/how_to_contribute.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md b/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md index a07b28be..19ce474d 100644 --- a/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md +++ b/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md @@ -50,7 +50,13 @@ You can use the script [`create_new_validator.py`](https://github.com/autowarefo You can use this by the command like this example: ```shell -python3 create_new_validator.py --base_directory ./ --category_name traffic_light --code_name traffic_light_facing --class_name TrafficLightFacingValidator --validator_name mapping.traffic_light.correct_facing --check_function_name check_traffic_light_facing +python3 create_new_validator.py \ +--base_directory ./ \ +--category_name traffic_light \ +--code_name traffic_light_facing \ +--class_name TrafficLightFacingValidator \ +--validator_name mapping.traffic_light.correct_facing \ +--check_function_name check_traffic_light_facing ``` All arguments are required. From 07684326011e1c24951da8ff0a756375a91f34ad Mon Sep 17 00:00:00 2001 From: TaikiYamada4 Date: Thu, 26 Dec 2024 15:37:34 +0900 Subject: [PATCH 13/13] Enable the generation script to be run by `ros2 run` Signed-off-by: TaikiYamada4 --- .../CMakeLists.txt | 5 +++++ .../docs/how_to_contribute.md | 15 ++++++++++++++- .../template/create_new_validator.py | 18 +++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/map/autoware_lanelet2_map_validator/CMakeLists.txt b/map/autoware_lanelet2_map_validator/CMakeLists.txt index 36776605..3d5e1789 100644 --- a/map/autoware_lanelet2_map_validator/CMakeLists.txt +++ b/map/autoware_lanelet2_map_validator/CMakeLists.txt @@ -31,6 +31,11 @@ target_link_libraries(autoware_lanelet2_map_validator autoware_lanelet2_map_validator_lib ) +install(PROGRAMS + template/create_new_validator.py + DESTINATION lib/${PROJECT_NAME} +) + if(BUILD_TESTING) file(GLOB_RECURSE test_src "test/src/test_*.cpp") ament_auto_add_library(autoware_lanelet2_map_validator_test_lib ${test_src}) diff --git a/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md b/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md index 19ce474d..6689b2ee 100644 --- a/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md +++ b/map/autoware_lanelet2_map_validator/docs/how_to_contribute.md @@ -50,7 +50,19 @@ You can use the script [`create_new_validator.py`](https://github.com/autowarefo You can use this by the command like this example: ```shell -python3 create_new_validator.py \ +create_new_validator.py \ +--base_directory ./ \ +--category_name traffic_light \ +--code_name traffic_light_facing \ +--class_name TrafficLightFacingValidator \ +--validator_name mapping.traffic_light.correct_facing \ +--check_function_name check_traffic_light_facing +``` + +OR + +```shell +ros2 run autoware_lanelet2_map_validator create_new_validator.py \ --base_directory ./ \ --category_name traffic_light \ --code_name traffic_light_facing \ @@ -63,6 +75,7 @@ All arguments are required. - `--base_directory`: The directory to the `autoware_lanelet2_map_validator` package. - `--category_name`: The category (like lanelet, traffic_light...) where your validator belongs to. Look [Design Concept](#design-concept) to see the list of categories. +- `--code_name`: The name for the files. The source code names will be like `.cpp` and `` - `--class_name`: The base class name of your validator which will be defined in your new header file. - `--validator_name`: The name of the validator which will be displayed when `autoware_lanelet2_map_validator` is executed with a `--print` option. The naming rules are explained in [Restrictions for validator class implementation](#restrictions-for-validator-class-implementation). - `--check_function_name`: The main function name of your validator which will be defined in your header file, and its implementation will be written in the cpp source file. diff --git a/map/autoware_lanelet2_map_validator/template/create_new_validator.py b/map/autoware_lanelet2_map_validator/template/create_new_validator.py index b704843d..da64764e 100755 --- a/map/autoware_lanelet2_map_validator/template/create_new_validator.py +++ b/map/autoware_lanelet2_map_validator/template/create_new_validator.py @@ -1,3 +1,19 @@ +#!/usr/bin/env python3 + +# Copyright 2024 TIER IV, Inc. All rights reserved. +# +# 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. + import argparse import os import shutil @@ -13,7 +29,7 @@ def create_files( base_directory, "src/include/lanelet2_map_validator/validators", category_name ) docs_directory = os.path.join(base_directory, "docs", category_name) - test_directory = os.path.join(base_directory, "test/src") + test_directory = os.path.join(base_directory, "test/src", category_name) # Define source and destination file paths cpp_template = os.path.join(template_directory, "validator_template.cpp")