moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
package_settings_config.hpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2021, PickNik Robotics, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of PickNik Robotics nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35#pragma once
36
39
40namespace moveit_setup
41{
42static const std::string SETUP_ASSISTANT_FILE = ".setup_assistant";
43
45{
46public:
53 void loadPrevious(const std::filesystem::path& package_path, const YAML::Node& node) override;
54 YAML::Node saveToYaml() const override;
55
61 void loadExisting(const std::string& package_path_or_name);
62
63 const std::filesystem::path& getPackagePath() const
64 {
65 return config_pkg_path_;
66 }
67
68 const std::string& getPackageName() const
69 {
70 return new_package_name_;
71 }
72
73 void setPackagePath(const std::filesystem::path& package_path);
74
75 void setPackageName(const std::string& package_name);
76
81
82 bool isConfigured() const override
83 {
84 return !config_pkg_path_.empty();
85 }
86
87 bool hasValidName() const;
88
89 bool hasValidEmail() const;
90
92 {
93 public:
94 GeneratedSettings(const std::filesystem::path& package_path, const GeneratedTime& last_gen_time,
96 : YamlGeneratedFile(package_path, last_gen_time), parent_(parent)
97 {
98 }
99
100 std::filesystem::path getRelativePath() const override
101 {
102 return SETUP_ASSISTANT_FILE;
103 }
104
105 std::string getDescription() const override
106 {
107 return "MoveIt Setup Assistant's hidden settings file. You should not need to edit this file.";
108 }
109
110 bool hasChanges() const override
111 {
112 // We write this file on any changes
113 return true;
114 }
115
116 bool writeYaml(YAML::Emitter& emitter) override;
117
118 protected:
120 };
121
123 {
124 public:
125 GeneratedPackageXML(const std::filesystem::path& package_path, const GeneratedTime& last_gen_time,
126 PackageSettingsConfig& parent)
127 : TemplatedGeneratedFile(package_path, last_gen_time), parent_(parent)
128 {
129 }
130
131 bool hasChanges() const override
132 {
134 }
135
136 std::filesystem::path getRelativePath() const override
137 {
138 return "package.xml";
139 }
140
141 std::filesystem::path getTemplatePath() const override
142 {
143 // Note: we call the file package.xml.template so that it isn't automatically indexed by rosprofile
144 return getSharePath("moveit_setup_framework") / "templates" / "package.xml.template";
145 }
146
147 std::string getDescription() const override
148 {
149 return "Defines a ROS package";
150 }
151
152 protected:
154 };
155
157 {
158 public:
159 using TemplatedGeneratedFile::TemplatedGeneratedFile;
160
161 bool hasChanges() const override
162 {
163 return false; // Generally doesn't change
164 }
165
166 std::filesystem::path getRelativePath() const override
167 {
168 return "CMakeLists.txt";
169 }
170
171 std::filesystem::path getTemplatePath() const override
172 {
173 return getSharePath("moveit_setup_framework") / "templates" / "CMakeLists.txt";
174 }
175
176 std::string getDescription() const override
177 {
178 return "CMake build system configuration file";
179 }
180 };
181
182 void collectFiles(const std::filesystem::path& package_path, const GeneratedTime& last_gen_time,
183 std::vector<GeneratedFilePtr>& files) override
184 {
185 files.push_back(std::make_shared<GeneratedSettings>(package_path, last_gen_time, *this));
186 files.push_back(std::make_shared<GeneratedPackageXML>(package_path, last_gen_time, *this));
187 files.push_back(std::make_shared<GeneratedCMake>(package_path, last_gen_time));
188 }
189
190 void collectVariables(std::vector<TemplateVariable>& variables) override;
191
192 void loadDependencies();
193
194 std::string getAuthorName() const
195 {
196 return author_name_;
197 }
198 std::string getAuthorEmail() const
199 {
200 return author_email_;
201 }
202 void setAuthorName(const std::string& name)
203 {
204 author_name_ = name;
205 }
206 void setAuthorEmail(const std::string& email)
207 {
208 author_email_ = email;
209 }
210
211 void setGenerationTime();
212
213protected:
215 std::filesystem::path config_pkg_path_;
216
218 std::string new_package_name_{ "unnamed_moveit_config" };
219
221 std::string author_name_;
222
224 std::string author_email_;
225
226 bool author_info_changed_{ false };
227
230
231 std::set<std::string> package_dependencies_;
232};
233} // namespace moveit_setup
std::string getDescription() const override
Returns an English description of this file's purpose.
std::filesystem::path getTemplatePath() const override
Returns the full path to the template file.
std::filesystem::path getRelativePath() const override
Returns the path relative to the configuration package root.
bool hasChanges() const override
Returns true if this file will have changes when it is written to file.
std::string getDescription() const override
Returns an English description of this file's purpose.
std::filesystem::path getRelativePath() const override
Returns the path relative to the configuration package root.
std::filesystem::path getTemplatePath() const override
Returns the full path to the template file.
bool hasChanges() const override
Returns true if this file will have changes when it is written to file.
GeneratedPackageXML(const std::filesystem::path &package_path, const GeneratedTime &last_gen_time, PackageSettingsConfig &parent)
GeneratedSettings(const std::filesystem::path &package_path, const GeneratedTime &last_gen_time, PackageSettingsConfig &parent)
std::filesystem::path getRelativePath() const override
Returns the path relative to the configuration package root.
std::string getDescription() const override
Returns an English description of this file's purpose.
bool hasChanges() const override
Returns true if this file will have changes when it is written to file.
void setAuthorName(const std::string &name)
bool isConfigured() const override
Return true if this part of the configuration is completely set up.
void collectVariables(std::vector< TemplateVariable > &variables) override
Collect key/value pairs for use in templates.
std::string author_name_
Name of the author of this config.
GeneratedTime config_pkg_generated_timestamp_
Timestamp when configuration package was generated, if it was previously generated.
void setAuthorEmail(const std::string &email)
void setPackagePath(const std::filesystem::path &package_path)
void loadPrevious(const std::filesystem::path &package_path, const YAML::Node &node) override
Overridden method to load THIS config's data variables.
void collectFiles(const std::filesystem::path &package_path, const GeneratedTime &last_gen_time, std::vector< GeneratedFilePtr > &files) override
Collect the files generated by this configuration and add them to the vector.
void setPackageName(const std::string &package_name)
const GeneratedTime & getGenerationTime() const
std::string author_email_
Email of the author of this config.
YAML::Node saveToYaml() const override
Optionally save "meta" information for saving in the .setup_assistant yaml file.
void loadExisting(const std::string &package_path_or_name)
Method for loading the contents of the .setup_assistant file into all the configs.
std::string new_package_name_
Name of the new package that is being (or going) to be generated, based on user specified save path.
std::filesystem::path config_pkg_path_
Loaded configuration package path - if an existing package was loaded, holds that path.
const std::filesystem::path & getPackagePath() const
where all the data for each part of the configuration is stored.
Definition config.hpp:58
Specialization of GeneratedFile for generating a text file from a template.
Definition templates.hpp:60
std::filesystem::path getSharePath(const std::string &package_name)
Return a path for the given package's share folder.
Definition utilities.hpp:51
std::filesystem::file_time_type GeneratedTime