cgv
Loading...
Searching...
No Matches
provider.h
1#pragma once
2
3#include <cgv/base/base.h>
4#include <cgv/type/info/type_name.h>
5#include <cgv/signal/rebind.h>
6#include <cgv/utils/convert.h>
7#include "gui_group.h"
8#include "shortcut.h"
9#include "gui_creator.h"
10
11#include "lib_begin.h"
12
13namespace cgv {
14 namespace gui {
15
16
18template <typename T>
20{
21 const T& value;
22 int index;
23 with_index_struct(const T& _value, int _index) : value(_value), index(_index) {}
24};
25
27template <typename T>
28with_index_struct<T> with_index(const T& _value, int _index)
29{
30 return with_index_struct<T>(_value, _index);
31}
32
33
34template <typename T>
36{
37 typedef const T* pointer_type;
38 static pointer_type get_value_ptr(const T& value) { return &value; }
39 static int get_index(const T& value) { return -1; }
40};
41
42template <typename T>
44{
45 typedef const T* pointer_type;
46 static pointer_type get_value_ptr(const with_index_struct<T>& value) { return &value.value; }
47 static int get_index(const with_index_struct<T>& value) { return value.index; }
48};
49
50template <typename T>
51typename with_index_traits<T>::pointer_type wi_get_value_ptr(const T& value)
52{
54}
55
56template <typename T>
57int wi_get_index(const T& value)
58{
59 return with_index_traits<T>::get_index(value);
60}
61
63class CGV_API provider : virtual public cgv::signal::tacker
64{
65protected:
71 provider* parent_provider;
73 void set_parent(gui_group_ptr);
75 void update_parent();
77 friend class gui_group;
79public:
81 gui_group_ptr get_parent_group() const { return parent_group; }
83 view_ptr add_view_void(const std::string& label, const void* value_ptr, const std::string& value_type, const std::string& gui_type, const std::string& options, const std::string& align);
85 control_ptr add_control_void(const std::string& label, void* value_ptr, abst_control_provider* acp, const std::string& value_type, const std::string& gui_type, const std::string& options, const std::string& align, void* user_data);
89 void align(const std::string& _align);
91 // gui_group_ptr add_group(const std::string& label, const std::string& group_type, const std::string& options, const std::string& align);
93
97 std::string concat_enum_def(const std::vector<std::string>& names, const std::string& additional_first_name = "", const std::string& additional_last_name = "");
98
99 gui_group_ptr add_object_gui(cgv::base::base_ptr object, const std::string& label, const std::string& group_type, const std::string& options, const std::string& align);
101 void integrate_object_gui(cgv::base::base_ptr object);
103 void inline_object_gui(cgv::base::base_ptr object);
105 gui_group_ptr add_group(const std::string& label, const std::string& group_type, const std::string& options = "", const std::string& align = "\n");
107 cgv::base::base_ptr add_decorator(const std::string& label, const std::string& decorator_type, const std::string& options = "", const std::string& align = "\n");
109 button_ptr add_button(const std::string& label, const std::string& options = "", const std::string& align = "\n");
111 template <typename T>
112 data::ref_ptr<view<T> > add_view(const std::string& label, const T& value, const std::string& gui_type = "", const std::string& options = "", const std::string& align = "\n") {
113 if (parent_group.empty())
114 return data::ref_ptr<view<T> >();
115 return parent_group->add_view(label, value, gui_type, options, align);
116 }
118 template <typename T>
119 data::ref_ptr<control<T> > add_control(const std::string& label, T& value, const std::string& gui_type = "", const std::string& options = "", const std::string& align = "\n") {
120 if (parent_group.empty())
121 return data::ref_ptr<control<T> >();
122 return parent_group->add_control(label, value, gui_type, options,align);
123 }
125 template <typename T>
126 data::ref_ptr<control<T> > add_control(const std::string& label,
127 control_provider<T>* provider, const std::string& gui_type = "",
128 const std::string& options = "", const std::string& align = "\n", void* user_data = 0) {
129 if (parent_group.empty())
130 return data::ref_ptr<control<T> >();
131 return parent_group->add_control(label, provider, gui_type, options,align,user_data);
132 }
134
136 template <typename T>
137 data::ref_ptr<control<T> > add_member_control(cgv::base::base* base_ptr, const std::string& label, T& value, const std::string& gui_type = "", const std::string& options = "", const std::string& align = "\n") {
138 data::ref_ptr<control<T> > cp = add_control(label, value, gui_type, options, align);
139 if (cp)
140 connect_copy(cp->value_change,
141 cgv::signal::rebind(base_ptr, &cgv::base::base::on_set, &value));
142 return cp;
143 }
145
165 bool add_tree_node(const std::string& label, bool& toggle, int level, const std::string& a= "\n", gui_group_ptr ggp = gui_group_ptr());
167
211 template <typename T>
212 bool begin_tree_node(const std::string& label, const T& value, bool initial_visibility = false, const std::string& options = "", gui_group_ptr ggp = gui_group_ptr()) { return begin_tree_node_void(label, wi_get_value_ptr(value), wi_get_index(value), initial_visibility, options, ggp); }
214
216 template <typename T>
217 static bool& ref_tree_node_visible_flag(const T& value) { return ref_tree_node_visible_flag_void(wi_get_value_ptr(value), wi_get_index(value)); }
220
221 template <typename T>
222 void end_tree_node(const T& value) { end_tree_node_void(wi_get_value_ptr(value), wi_get_index(value)); }
224 template <typename T>
225 bool is_tree_node_visible(const T& value) const { return is_tree_node_visible_void(wi_get_value_ptr(value), wi_get_index(value)); }
227 template <typename T>
228 void set_tree_node_visibility(const T& value, bool is_visible) { set_tree_node_visibility_void(wi_get_value_ptr(value), wi_get_index(value), is_visible); }
230 bool begin_tree_node_void(const std::string& label, const void* value_ptr, int index = -1, bool initial_visibility = false, const std::string& options = "", gui_group_ptr ggp = gui_group_ptr());
232 static bool& ref_tree_node_visible_flag_void(const void* value_ptr, int index = -1);
234 void end_tree_node_void(const void* value_ptr, int index = -1);
236 bool is_tree_node_visible_void(const void* value_ptr, int index) const;
238 void set_tree_node_visibility_void(const void* value_ptr, int index, bool is_visible);
239
241
246 template <typename T>
247 bool add_gui(const std::string& label, T& value, const std::string& gui_type = "", const std::string& options = "")
248 {
249 return cgv::gui::create_gui(this, label, &value, cgv::type::info::type_name<T>::get_name(), gui_type, options, 0);
250 }
252protected:
256 virtual void on_select();
258 virtual void on_deselect();
260 virtual void selection_change_cb(cgv::base::base_ptr new_child, bool selected);
262public:
264 provider();
266 ~provider();
268
277 virtual std::string get_gui_name() const;
279
281 virtual std::string get_parent_type() const;
283 virtual bool ensure_selected_in_tab_group_parent();
285 virtual void update_member(void* member_ptr);
287 virtual void update_all_members();
289 virtual std::string get_menu_path() const;
291 virtual shortcut get_shortcut() const;
293 virtual void create_gui() = 0;
295
301 virtual void recreate_gui();
303
305 virtual void post_recreate_gui();
306
310 void remove_element(cgv::base::base_ptr);
312 void remove_all_elements();
314 cgv::base::base_ptr find_element(const std::string& name);
316
319 template <typename T>
320 data::ref_ptr<view<T> > find_view(const T& value, int* idx_ptr=0) {
321 if (parent_group.empty())
322 return data::ref_ptr<view<T> >();
323 return parent_group->find_view(value,idx_ptr);
324 }
326
329 template <typename T>
330 data::ref_ptr<control<T> > find_control(T& value, int* idx_ptr=0) {
331 if (parent_group.empty())
332 return data::ref_ptr<control<T> >();
333 return parent_group->find_control(value,idx_ptr);
334 }
336 control_ptr find_control_void(void* value_ptr, int* idx_ptr);
338 view_ptr find_view_void(void* value_ptr, int* idx_ptr);
340
342 template <typename T>
343 void set_control_property(T& value, const std::string& property_name, const std::string& property_value) {
344 int idx = 0;
345 data::ref_ptr<control<T> > control_ptr = find_control(value, &idx);
346 while(control_ptr) {
347 ++idx;
348 control_ptr->set(property_name, property_value);
349 control_ptr = find_control(value, &idx);
350 }
351 }
353};
354
355
356
357 }
358}
359
360#include <cgv/config/lib_end.h>
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
virtual void on_set(void *member_ptr)
this callback is called when the set_void method has changed a member and can be overloaded in derive...
Definition base.cxx:210
bool empty() const
check if pointer is not yet set
Definition ref_ptr.h:230
gui independent group class which is a container for gui elements
Definition gui_group.h:38
derive from this class to provide a gui to the current viewer
Definition provider.h:64
bool add_gui(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="")
Add a composed gui of the given gui_type for the given value.
Definition provider.h:247
gui_group_ptr get_parent_group() const
use the parent group to append to be managed elements that should be destroyed in a post_recreate_gui...
Definition provider.h:81
virtual void create_gui()=0
you must overload this for gui creation
void set_tree_node_visibility(const T &value, bool is_visible)
set the visibility status of sub tree attached to a value. This calls the post_recreate method if nee...
Definition provider.h:228
data::ref_ptr< view< T > > find_view(const T &value, int *idx_ptr=0)
find a view of a given class member
Definition provider.h:320
bool begin_tree_node(const std::string &label, const T &value, bool initial_visibility=false, const std::string &options="", gui_group_ptr ggp=gui_group_ptr())
Begin a sub tree of a tree structured gui.
Definition provider.h:212
data::ref_ptr< control< T > > add_member_control(cgv::base::base *base_ptr, const std::string &label, T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
add control with callback to cgv::base::on_set method on cgv::gui::control::value_change
Definition provider.h:137
void end_tree_node(const T &value)
template specialization that allows to specify value reference plus node_instance by using the result...
Definition provider.h:222
void set_control_property(T &value, const std::string &property_name, const std::string &property_value)
Set the property value of all controls of a given class member.
Definition provider.h:343
data::ref_ptr< control< T > > add_control(const std::string &label, control_provider< T > *provider, const std::string &gui_type="", const std::string &options="", const std::string &align="\n", void *user_data=0)
use this to add a new control to the gui, where the control is implemented with a control provider cl...
Definition provider.h:126
bool is_tree_node_visible(const T &value) const
return whether the sub tree attached to a value is visible
Definition provider.h:225
data::ref_ptr< view< T > > add_view(const std::string &label, const T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
use this to add a new view to the gui with a given value type, gui type and init options
Definition provider.h:112
data::ref_ptr< control< T > > add_control(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
use this to add a new control to the gui with a given value type, gui type and init options
Definition provider.h:119
static bool & ref_tree_node_visible_flag(const T &value)
return a reference to the boolean flag, that tells whether the tree node for the passed value is visi...
Definition provider.h:217
data::ref_ptr< control< T > > find_control(T &value, int *idx_ptr=0)
find a control of a given class member
Definition provider.h:330
gui_group_ptr parent_group
driver specific handle for the group gui element managing the gui built in the provider
Definition provider.h:69
the shortcut class encapsulates a key with modifiers
Definition shortcut.h:84
with_index_struct< T > with_index(const T &_value, int _index)
helper function to support value references as well as value references with index for the tree_node ...
Definition provider.h:28
bool create_gui(provider *p, const std::string &label, void *value_ptr, const std::string &value_type, const std::string &gui_type, const std::string &options, bool *toggles)
create the gui for a composed structure
the cgv namespace
Definition print.h:11
type independent base class of control provider interface
Definition control.h:37
helper struct to support value references as well as value references with index
Definition provider.h:20
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54