-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lanelet2_map_validator): generation script for new validators (#180
) * temporary commit Signed-off-by: TaikiYamada4 <[email protected]> * Added python script Signed-off-by: TaikiYamada4 <[email protected]> * Finished except docs Signed-off-by: TaikiYamada4 <[email protected]> * Added documents related stuff Signed-off-by: TaikiYamada4 <[email protected]> * Moved stuff to templates Signed-off-by: TaikiYamada4 <[email protected]> * Revised files to suit the current directory Signed-off-by: TaikiYamada4 <[email protected]> * Added arguments Signed-off-by: TaikiYamada4 <[email protected]> * Added prints Signed-off-by: TaikiYamada4 <[email protected]> * added #include <string> to test code Signed-off-by: TaikiYamada4 <[email protected]> * Fixed typo Signed-off-by: TaikiYamada4 <[email protected]> * Write explanation of create_new_validator.py Signed-off-by: TaikiYamada4 <[email protected]> * Added back slashes to example command Signed-off-by: TaikiYamada4 <[email protected]> * Enable the generation script to be run by `ros2 run` Signed-off-by: TaikiYamada4 <[email protected]> --------- Signed-off-by: TaikiYamada4 <[email protected]>
- Loading branch information
1 parent
2b00989
commit 5e7d3cd
Showing
7 changed files
with
257 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
map/autoware_lanelet2_map_validator/template/create_new_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#!/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 | ||
|
||
|
||
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, "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 | ||
) | ||
docs_directory = os.path.join(base_directory, "docs", category_name) | ||
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") | ||
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") | ||
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) | ||
shutil.copy(hpp_template, hpp_new) | ||
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: | ||
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( | ||
"MAP__AUTOWARE_LANELET2_MAP_VALIDATOR__TEMPLATE__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__": | ||
# 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 = 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 | ||
) | ||
print("Process complete.") |
48 changes: 48 additions & 0 deletions
48
map/autoware_lanelet2_map_validator/template/test_validator_template.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 "map_validation_tester.hpp" | ||
#include "validator_template.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
#include <lanelet2_core/LaneletMap.h> | ||
|
||
#include <string> | ||
|
||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
map/autoware_lanelet2_map_validator/template/validator_template.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# validator_template | ||
|
||
## Validator name | ||
|
||
mapping.validator.template | ||
|
||
## Feature | ||
|
||
Feature explanation here. | ||
|
||
| Issue Code | Message | Severity | Description | Approach | | ||
| ---------- | ------- | -------- | ----------- | -------- | | ||
| | | | | | | ||
|
||
## Related source codes | ||
|
||
- validator_template.cpp | ||
- validator_template.hpp |