property_factory.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Bielefeld University
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 Bielefeld University 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: Robert Haschke */
36 
37 #pragma once
38 
39 #include <QObject>
40 #include <QString>
41 #include <map>
42 #include <functional>
43 #include <typeindex>
44 
45 #include <moveit/task_constructor/properties.h>
46 
47 namespace rviz {
48 class Property;
49 class PropertyTreeModel;
50 class DisplayContext;
51 } // namespace rviz
52 namespace planning_scene {
53 class PlanningScene;
54 }
55 namespace moveit {
56 namespace task_constructor {
57 class Stage;
58 }
59 } // namespace moveit
60 
61 namespace moveit_rviz_plugin {
62 
74 {
75 public:
76  static PropertyFactory& instance();
77 
79  std::function<rviz::Property*(const QString&, moveit::task_constructor::Property&,
81  using TreeFactoryFunction = std::function<rviz::PropertyTreeModel*(
83 
85  template <typename T>
86  inline void registerType(const PropertyFactoryFunction& f) {
87  moveit::task_constructor::PropertySerializer<T>(); // register serializer
89  }
90 
92  template <typename T>
93  inline void registerStage(const TreeFactoryFunction& f) {
94  registerStage(typeid(T), f);
95  }
96 
98  rviz::Property* create(const std::string& prop_name, moveit::task_constructor::Property& prop,
99  const planning_scene::PlanningScene* scene, rviz::DisplayContext* display_context) const;
101  static rviz::Property* createDefault(const std::string& name, const std::string& type,
102  const std::string& description, const std::string& value,
103  rviz::Property* old = nullptr);
104 
107  const planning_scene::PlanningScene* scene,
108  rviz::DisplayContext* display_context);
109 
112  const planning_scene::PlanningScene* scene,
113  rviz::DisplayContext* display_context);
114 
117  const planning_scene::PlanningScene* scene, rviz::DisplayContext* display_context);
118 
119 private:
120  std::map<std::string, PropertyFactoryFunction> property_registry_;
121  std::map<std::type_index, TreeFactoryFunction> stage_registry_;
122 
124  PropertyFactory();
125  PropertyFactory(const PropertyFactory&) = delete;
126  void operator=(const PropertyFactory&) = delete;
127 
128  void registerType(const std::string& type_name, const PropertyFactoryFunction& f);
129  void registerStage(const std::type_index& type_index, const TreeFactoryFunction& f);
130 };
131 } // namespace moveit_rviz_plugin
moveit_rviz_plugin::PropertyFactory::create
rviz::Property * create(const std::string &prop_name, moveit::task_constructor::Property &prop, const planning_scene::PlanningScene *scene, rviz::DisplayContext *display_context) const
create rviz::Property for given MTC Property
Definition: property_factory.cpp:129
moveit_rviz_plugin::PropertyFactory::PropertyFactoryFunction
std::function< rviz::Property *(const QString &, moveit::task_constructor::Property &, const planning_scene::PlanningScene *, rviz::DisplayContext *)> PropertyFactoryFunction
Definition: property_factory.h:80
moveit_rviz_plugin::PropertyFactory::stage_registry_
std::map< std::type_index, TreeFactoryFunction > stage_registry_
Definition: property_factory.h:121
moveit_rviz_plugin::PropertyFactory::addRemainingProperties
void addRemainingProperties(rviz::Property *root, moveit::task_constructor::PropertyMap &properties, const planning_scene::PlanningScene *scene, rviz::DisplayContext *display_context)
add all properties from map that are not yet in root
Definition: property_factory.cpp:163
rviz::PropertyTreeModel
moveit_rviz_plugin::PropertyFactory::instance
static PropertyFactory & instance()
Definition: property_factory.cpp:114
planning_scene::PlanningScene
moveit_rviz_plugin::PropertyFactory::operator=
void operator=(const PropertyFactory &)=delete
moveit::task_constructor::Stage
moveit_rviz_plugin::PropertyFactory::PropertyFactory
PropertyFactory()
class is singleton
Definition: property_factory.cpp:107
moveit_rviz_plugin::PropertyFactory::TreeFactoryFunction
std::function< rviz::PropertyTreeModel *(moveit::task_constructor::PropertyMap &, const planning_scene::PlanningScene *, rviz::DisplayContext *)> TreeFactoryFunction
Definition: property_factory.h:82
moveit_rviz_plugin::PropertyFactory::createPropertyTreeModel
rviz::PropertyTreeModel * createPropertyTreeModel(moveit::task_constructor::Stage &stage, const planning_scene::PlanningScene *scene, rviz::DisplayContext *display_context)
create PropertyTreeModel for given Stage
Definition: property_factory.cpp:138
rviz::Property
moveit::task_constructor::PropertyMap
moveit_rviz_plugin::PropertyFactory::defaultPropertyTreeModel
rviz::PropertyTreeModel * defaultPropertyTreeModel(moveit::task_constructor::PropertyMap &properties, const planning_scene::PlanningScene *scene, rviz::DisplayContext *display_context)
turn a PropertyMap into an rviz::PropertyTreeModel
Definition: property_factory.cpp:147
moveit::task_constructor::PropertySerializer
rviz
rviz::DisplayContext
moveit::task_constructor::Property
moveit_rviz_plugin::PropertyFactory
Definition: property_factory.h:73
moveit_rviz_plugin::PropertyFactory::property_registry_
std::map< std::string, PropertyFactoryFunction > property_registry_
Definition: property_factory.h:120
moveit_rviz_plugin
f
f
moveit
moveit_rviz_plugin::PropertyFactory::registerType
void registerType(const PropertyFactoryFunction &f)
register a factory function for type T
Definition: property_factory.h:86
moveit_rviz_plugin::PropertyFactory::registerStage
void registerStage(const TreeFactoryFunction &f)
register a factory function for stage T
Definition: property_factory.h:93
planning_scene
moveit_rviz_plugin::PropertyFactory::createDefault
static rviz::Property * createDefault(const std::string &name, const std::string &type, const std::string &description, const std::string &value, rviz::Property *old=nullptr)
create rviz::Property for property of given name, type, description, and value
Definition: property_factory.cpp:183


visualization
Author(s): Robert Haschke
autogenerated on Thu Feb 27 2025 03:39:51