moveit2
The MoveIt Motion Planning Framework for ROS 2.
launch_bundle.hpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2022, Metro Robots
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 Metro Robots 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 /* Author: David V. Lu!! */
36 #pragma once
37 
40 
41 namespace moveit_setup
42 {
43 namespace app
44 {
52 {
53 public:
60  LaunchBundle(const std::string& title, const std::string& description, const std::string& launch_name,
61  const std::set<std::string>& dependencies = {})
62  : title_(title), description_(description), launch_name_(launch_name), dependencies_(dependencies), id_(-1)
63  {
64  }
65 
66  const std::string& getTitle() const
67  {
68  return title_;
69  }
70 
71  const std::string& getDescription() const
72  {
73  return description_;
74  }
75 
79  unsigned int getID() const
80  {
81  return id_;
82  }
83 
84  void setID(unsigned int id)
85  {
86  id_ = id;
87  }
88 
89  void addFile(const std::filesystem::path& relative_path, const std::string& description)
90  {
91  bonus_files_.push_back(BonusFile(relative_path, description));
92  }
93 
94  const std::set<std::string> getDependencies() const
95  {
96  return dependencies_;
97  }
98 
102  bool operator<(const LaunchBundle& other) const
103  {
104  return title_ < other.title_;
105  }
106 
108  {
109  public:
110  GenericLaunchTemplate(const std::filesystem::path& package_path, const GeneratedTime& last_gen_time,
111  const LaunchBundle& parent)
112  : TemplatedGeneratedFile(package_path, last_gen_time), parent_(parent)
113  {
114  function_name_ = "generate_" + parent_.launch_name_ + "_launch";
115  relative_path_ = std::filesystem::path("launch") / (parent_.launch_name_ + ".launch.py");
116  template_path_ = getSharePath("moveit_setup_app_plugins") / "templates/launch/generic.launch.py.template";
117  }
118 
119  std::filesystem::path getRelativePath() const override
120  {
121  return relative_path_;
122  }
123 
124  std::string getDescription() const override
125  {
126  return parent_.description_;
127  }
128 
129  std::filesystem::path getTemplatePath() const override
130  {
131  return template_path_;
132  }
133 
134  bool hasChanges() const override
135  {
136  return false;
137  }
138 
139  bool write() override
140  {
141  // Add function name as a TemplateVariable, then remove it
142  variables.push_back(TemplateVariable("FUNCTION_NAME", function_name_));
143  bool ret = TemplatedGeneratedFile::write();
144  variables.pop_back();
145  return ret;
146  }
147 
148  protected:
150  std::string function_name_;
151  std::filesystem::path relative_path_, template_path_;
152  };
153 
154  struct BonusFile // basically a std::pair<std::filesystem::path, std::string>
155  {
156  BonusFile(const std::filesystem::path& path, const std::string& description) : path(path), description(description)
157  {
158  }
159  std::filesystem::path path;
160  std::string description;
161  };
162 
164  {
165  public:
166  BonusTemplatedFile(const std::filesystem::path& package_path, const GeneratedTime& last_gen_time,
167  const std::filesystem::path& relative_path, const std::string& description)
168  : TemplatedGeneratedFile(package_path, last_gen_time), relative_path_(relative_path), description_(description)
169  {
170  }
171 
172  std::filesystem::path getRelativePath() const override
173  {
174  return relative_path_;
175  }
176 
177  std::string getDescription() const override
178  {
179  return description_;
180  }
181 
182  std::filesystem::path getTemplatePath() const override
183  {
184  return getSharePath("moveit_setup_app_plugins") / "templates" / relative_path_;
185  }
186 
187  bool hasChanges() const override
188  {
189  return false;
190  }
191 
192  protected:
193  std::filesystem::path relative_path_;
194  std::string description_;
195  };
196 
197  void collectFiles(const std::filesystem::path& package_path, const GeneratedTime& last_gen_time,
198  std::vector<GeneratedFilePtr>& files) const
199  {
200  files.push_back(std::make_shared<GenericLaunchTemplate>(package_path, last_gen_time, *this));
201 
202  for (const BonusFile& bonus_file : bonus_files_)
203  {
204  files.push_back(
205  std::make_shared<BonusTemplatedFile>(package_path, last_gen_time, bonus_file.path, bonus_file.description));
206  }
207  }
208 
209 protected:
211  std::set<std::string> dependencies_;
212  unsigned int id_;
213 
214  std::vector<BonusFile> bonus_files_;
215 };
216 } // namespace app
217 } // namespace moveit_setup
Specialization of GeneratedFile for generating a text file from a template.
Definition: templates.hpp:60
static std::vector< TemplateVariable > variables
Definition: templates.hpp:72
bool write() override
Writes the file to disk.
Definition: templates.cpp:53
std::filesystem::path getTemplatePath() const override
Returns the full path to the template file.
std::string getDescription() const override
Returns an English description of this file's purpose.
BonusTemplatedFile(const std::filesystem::path &package_path, const GeneratedTime &last_gen_time, const std::filesystem::path &relative_path, const std::string &description)
bool hasChanges() const override
Returns true if this file will have changes when it is written to file.
std::filesystem::path getRelativePath() const override
Returns the path relative to the configuration package root.
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.
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.
GenericLaunchTemplate(const std::filesystem::path &package_path, const GeneratedTime &last_gen_time, const LaunchBundle &parent)
bool write() override
Writes the file to disk.
One launch file and any other bonus files that get bundled with it, i.e. the RViz launch file and its...
const std::set< std::string > getDependencies() const
const std::string & getDescription() const
const std::string & getTitle() const
bool operator<(const LaunchBundle &other) const
Defined so that LaunchBundles can be added to sets.
unsigned int getID() const
The ID is an index in a list, used for quick identification and argument passing.
LaunchBundle(const std::string &title, const std::string &description, const std::string &launch_name, const std::set< std::string > &dependencies={})
void setID(unsigned int id)
std::vector< BonusFile > bonus_files_
void collectFiles(const std::filesystem::path &package_path, const GeneratedTime &last_gen_time, std::vector< GeneratedFilePtr > &files) const
void addFile(const std::filesystem::path &relative_path, const std::string &description)
std::set< std::string > dependencies_
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
description
Definition: setup.py:19
Simple Key/value pair for templates.
Definition: templates.hpp:47
BonusFile(const std::filesystem::path &path, const std::string &description)