cgv
Loading...
Searching...
No Matches
gui_group.cxx
1#include "gui_group.h"
2#include "gui_driver.h"
3#include "provider.h"
4#include <cgv/base/named.h>
5#include <algorithm>
6
7namespace cgv {
8 namespace gui {
9
10// construct from name
11gui_group::gui_group(const std::string& name) : cgv::base::group(name) {}
12
13// access to protected provider method
18
19void gui_group::register_object(cgv::base::base_ptr object, const std::string& options)
20{
21}
22
23void gui_group::unregister_object(cgv::base::base_ptr object, const std::string& options)
24{
25}
26
27// driver specific handle for the group gui element managing the gui built in the provider
32
34{
35 return false;
36}
37
38void gui_group::select_child(unsigned ci, bool exclusive)
39{
40 select_child(get_child(ci),exclusive);
41}
42
45{
46 if (!is_selected(c)) {
47 if (!multiple_selection())
49 on_selection_change(c, true);
50 }
51}
52
54{
55 return unselect_child(get_child(ci));
56}
57
59{
60 if (is_selected(c)) {
61 on_selection_change(c, false);
62 return false;
63 }
64 return true;
65}
66
68{
69 return -1;
70}
71
73{
74 int ci = get_selected_child_index();
75 if (ci == -1)
76 return cgv::base::base_ptr();
77 return get_child(ci);
78}
79
81{
82 return get_selected_child() == c;
83}
84
85bool gui_group::is_selected(unsigned ci) const
86{
87 return is_selected(get_child(ci));
88}
89
92{
93 return false;
94}
95
98{
99 return true;
100}
101
103bool gui_group::is_open_child_group(unsigned ci) const
104{
105 return get_child(ci)->get_interface<gui_group>() != 0;
106 return true;
107}
108
111{
112 return false;
113}
114
117{
118 return false;
119}
120
121// add a newly created view to the group
122view_ptr gui_group::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)
123{
124 if (get_gui_driver().empty())
125 return view_ptr();
126 return get_gui_driver()->add_view(gui_group_ptr(this),
127 label, value_ptr, value_type, gui_type, options, align);
128}
129// add a newly created control to the group
130control_ptr gui_group::add_control_void(const std::string& label,
131 void* value_ptr, abst_control_provider* acp,
132 const std::string& value_type, const std::string& gui_type,
133 const std::string& options, const std::string& align, void* user_data)
134{
135 if (get_gui_driver().empty())
136 return control_ptr();
137 return get_gui_driver()->add_control(gui_group_ptr(this),
138 label, value_ptr ? value_ptr : user_data, acp, value_type, gui_type, options, align);
139}
142{
143 unsigned n = get_nr_children();
144 for (unsigned i=0; i<n; ++i) {
146 cgv::base::named_ptr np = bp->get_named();
147 if (np) {
148 if (np->get_name() == name)
149 return bp;
150 }
151 }
152 return cgv::base::base_ptr();
153}
154
155// find a view in the group based on a const void pointer
156view_ptr gui_group::find_view_void(const void* value_ptr, int* idx_ptr)
157{
158 if (get_gui_driver().empty())
159 return view_ptr();
160 return get_gui_driver()->find_view(gui_group_ptr(this),
161 value_ptr, idx_ptr);
162}
163// find a control in the group based on a const void pointer
164control_ptr gui_group::find_control_void(void* value_ptr, int* idx_ptr)
165{
166 if (get_gui_driver().empty())
167 return control_ptr();
168 return get_gui_driver()->find_control(gui_group_ptr(this),
169 value_ptr, idx_ptr);
170}
171
172// overload to return the type name of this object
173std::string gui_group::get_type_name() const
174{
175 return "gui_group";
176}
177
179{
180 if (!is_managed_object(object))
181 managed_objects.push_back(object);
182}
183
189
192{
193 std::vector<cgv::base::base_ptr>::iterator iter = std::find(managed_objects.begin(), managed_objects.end(), object);
194 if (iter == managed_objects.end())
195 return;
196 managed_objects.erase(iter);
197}
198
201{
202 std::vector<cgv::base::base_ptr>::iterator iter = std::find(managed_objects.begin(), managed_objects.end(), object);
203 return iter != managed_objects.end();
204}
205
206// send pure alignment information
207void gui_group::align(const std::string& _align)
208{
209}
210
211// add a new group to the given parent group
212gui_group_ptr gui_group::add_group(const std::string& label, const std::string& group_type, const std::string& options, const std::string& align)
213{
214 if (get_gui_driver().empty())
215 return gui_group_ptr();
216 return get_gui_driver()->add_group(gui_group_ptr(this),
217 label, group_type, options, align);
218}
219// add a newly created decorator to the group
220cgv::base::base_ptr gui_group::add_decorator(const std::string& label, const std::string& decorator_type, const std::string& options, const std::string& align)
221{
222 if (get_gui_driver().empty())
223 return cgv::base::base_ptr();
224 return get_gui_driver()->add_decorator(gui_group_ptr(this),
225 label, decorator_type, options, align);
226}
227// add a newly created button to the group
228button_ptr gui_group::add_button(const std::string& label, const std::string& options, const std::string& align)
229{
230 if (get_gui_driver().empty())
231 return button_ptr();
232 return get_gui_driver()->add_button(gui_group_ptr(this),
233 label, options, align);
234}
235
236
237 }
238}
unsigned int get_nr_children() const
return the number of children
Definition group.cxx:29
base_ptr get_child(unsigned int i) const
return the i-th child
Definition group.cxx:33
std::string name
store the name as a string
Definition named.h:25
void clear()
set to null pointer
Definition ref_ptr.h:238
gui independent group class which is a container for gui elements
Definition gui_group.h:38
void add_managed_objects(cgv::base::base_ptr object)
add the passed object as an managed object.
virtual bool can_open_and_close() const
returns whether open and close of sub groups is allowed
Definition gui_group.cxx:91
virtual cgv::base::base_ptr add_decorator(const std::string &label, const std::string &decorator_type, const std::string &options, const std::string &align)
add a newly created decorator to the group
std::string get_type_name() const
overload to return the type name of this object
cgv::signal::signal< cgv::base::base_ptr, bool > on_selection_change
This signal is emitted for every change of the selection of a child.
Definition gui_group.h:108
virtual bool unselect_child(unsigned ci)
unselect the ci-th child.
Definition gui_group.cxx:53
void release_managed_objects(cgv::base::base_ptr object)
release a specific managed object
control_ptr find_control_void(void *value_ptr, int *idx_ptr)
find a control in the group based on a const void pointer
virtual bool is_open_child_group(gui_group_ptr g) const
return whether the given child is open
Definition gui_group.cxx:97
static void set_provider_parent(provider *p, gui_group_ptr g)
access to protected provider method
Definition gui_group.cxx:14
void unregister_object(cgv::base::base_ptr object, const std::string &options)
overload to handle unregistration events
Definition gui_group.cxx:23
virtual bool multiple_selection() const
return whether several children of the group can be selected at the same time
Definition gui_group.cxx:33
virtual gui_group_ptr add_group(const std::string &label, const std::string &group_type, const std::string &options, const std::string &align)
add a new group to the given parent group
virtual bool close_child_group(gui_group_ptr g)
try to close given child group and return whether this was successful
void release_all_managed_objects()
release all managed objects
static gui_group_ptr get_provider_parent(const provider *p)
driver specific handle for the group gui element managing the gui built in the provider
Definition gui_group.cxx:28
std::vector< cgv::base::base_ptr > managed_objects
managed objects can be add to the group such that
Definition gui_group.h:42
virtual 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)
add a newly created control to the group
virtual button_ptr add_button(const std::string &label, const std::string &options, const std::string &align)
add a newly created button to the group
bool is_managed_object(cgv::base::base_ptr object)
check whether an object is managed by this gui group
cgv::base::base_ptr find_element(const std::string &name)
find a gui element by name, return empty pointer if not found
virtual void select_child(unsigned ci, bool exclusive=false)
select the ci-th child of the group.
Definition gui_group.cxx:38
gui_group(const std::string &name="")
construct from name
Definition gui_group.cxx:11
void register_object(cgv::base::base_ptr object, const std::string &options)
interface of adding an object
Definition gui_group.cxx:19
virtual int get_selected_child_index() const
return the index of the currently selected child.
Definition gui_group.cxx:67
view_ptr find_view_void(const void *value_ptr, int *idx_ptr)
find a view in the group based on a const void pointer
virtual cgv::base::base_ptr get_selected_child() const
return the currently selected child.
Definition gui_group.cxx:72
virtual bool open_child_group(gui_group_ptr g)
try to open given child group and return whether this was successful
virtual bool is_selected(cgv::base::base_ptr c) const
return whether the given child is selected
Definition gui_group.cxx:80
virtual void align(const std::string &_align)
send pure alignment information
virtual 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)
add a newly created view to the group
derive from this class to provide a gui to the current viewer
Definition provider.h:64
void set_parent(gui_group_ptr)
the gui window sets the parent group through this method
Definition provider.cxx:360
gui_group_ptr parent_group
driver specific handle for the group gui element managing the gui built in the provider
Definition provider.h:69
data::ref_ptr< base, true > base_ptr
ref counted pointer to base
Definition base.h:37
data::ref_ptr< gui_group, true > gui_group_ptr
ref counted pointer to a gui group
Definition gui_group.h:31
gui_driver_ptr get_gui_driver()
return the currently registered gui driver or an empty pointer if non has been registered
data::ref_ptr< button > button_ptr
ref counted pointer to button
Definition button.h:24
data::ref_ptr< abst_view > view_ptr
ref counted pointer to abst view
Definition view.h:36
data::ref_ptr< abst_control > control_ptr
ref counted pointer to abst control
Definition control.h:29
the cgv namespace
Definition print.h:11
type independent base class of control provider interface
Definition control.h:37