1#include <cgv/gui/provider.h>
2#include <cgv/gui/gui_driver.h>
3#include <cgv/gui/trigger.h>
4#include <cgv/base/base_generator.h>
21view_ptr provider::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)
25 return parent_group->add_view_void(label,value_ptr,value_type,gui_type,options,
align);
32 return parent_group->add_control_void(label,value_ptr,acp,value_type,gui_type,options,
align,user_data);
43std::string
provider::concat_enum_def(
const std::vector<std::string>& names,
const std::string& additional_first_name,
const std::string& additional_last_name)
45 std::string result =
"enums='";
46 if (!additional_first_name.empty())
47 result += additional_first_name +
"=-1,";
48 for (
unsigned i = 0; i < names.size(); ++i) {
53 if (!additional_last_name.empty()) {
55 result += additional_last_name;
74 update_views(member_ptr);
104 for (
unsigned i=0; i<gp->get_nr_children(); ++i) {
111 update_group_members(cgp);
121gui_group_ptr provider::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)
143 p->parent_provider =
this;
154 p->parent_provider =
this;
188 if (a.size() != 1 || a[0] !=
'\n') {
191 int size = 24-4*level;
194 connect_copy(ggp->add_control(std::string(toggle?
"-":
"+"), toggle,
"toggle", std::string(
"w=")+
cgv::utils::to_string(size),
" ")->value_change,
200std::map<std::pair<const void*,int>,
bool>& get_tree_node_toggle_map()
202 static std::map<std::pair<const void*,int>,
bool> tree_node_toggle_map;
203 return tree_node_toggle_map;
218 int off = size+relative_offset;
220 if (!button_opt.empty())
221 button_opt = std::string(
";")+button_opt;
224 std::map<std::pair<const void*,int>,
bool>::iterator it = get_tree_node_toggle_map().find(std::pair<const void*,int>(value_ptr,index));
225 if (it == get_tree_node_toggle_map().end())
226 get_tree_node_toggle_map()[std::pair<const void*,int>(value_ptr,index)] = initial_visibility;
228 bool& toggle = get_tree_node_toggle_map()[std::pair<const void*,int>(value_ptr,index)];
233 control_ptr = ggp->add_control(std::string(toggle ?
"@-6thinminus" :
"@-6thinplus"), toggle,
"toggle", button_opt,
" ");
235 if (!child_opt.empty())
236 child_opt = std::string(
";")+child_opt;
238 ggp->add_decorator(label,
"heading", child_opt,
align);
241 control_ptr = ggp->add_control(std::string(toggle ?
"@-6thinminus" :
"@-6thinplus"), toggle,
"toggle", button_opt,
align);
257bool& provider::ref_tree_node_visible_flag_void(
const void* value_ptr,
int index)
259 auto& map = get_tree_node_toggle_map();
260 std::pair<const void*, int> key(value_ptr, index);
261 auto iter = map.find(key);
262 if (iter == map.end())
263 return map[key] =
false;
269void provider::end_tree_node_void(
const void* value_ptr,
int)
274bool provider::is_tree_node_visible_void(
const void* value_ptr,
int index)
const
276 return get_tree_node_toggle_map()[std::pair<const void*,int>(value_ptr,index)];
280void provider::set_tree_node_visibility_void(
const void* value_ptr,
int index,
bool is_visible)
282 bool& toggle = get_tree_node_toggle_map()[std::pair<const void*,int>(value_ptr,index)];
283 if (toggle != is_visible) {
319 return parent_group->find_control_void(value_ptr,idx_ptr);
392 size_t pos = mp.find_last_of(
'/');
393 if (pos == std::string::npos || pos == mp.size()-1)
395 return mp.substr(pos+1);
404 return "align_group";
415 tab_group->select_child(c,
true);
451std::set<provider*>& ref_providers()
453 static std::set<provider*> providers;
465void trigger_callback(
double,
double)
470 std::set<provider*>& ps = ref_providers();
471 while (ps.size() > 0) {
472 provider* p = *ps.begin();
481trigger& ref_one_shot_trigger()
484 static bool initialized =
false;
487 connect(t.shoot, &trigger_callback);
495 std::set<provider*>& ps = ref_providers();
501 if (ps.find(
this) != ps.end())
516 std::set<provider*>& ps = ref_providers();
517 if (ps.find(
this) == ps.end()) {
518 bool dont_insert =
false;
520 if (!ref_one_shot_trigger().schedule_one_shot(0))
base class for all classes that can be registered with support for dynamic properties (see also secti...
virtual void update()
this virtual update allows for example to ask a view to update the viewed value. The default implemen...
virtual data::ref_ptr< named, true > get_named()
perform downcast to named
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...
virtual std::string get_type_name() const
overload to return the type name of this object. By default the type interface is queried over get_ty...
The group class is a node with children.
reference counted pointer, which can work together with types that are derived from ref_counted,...
bool empty() const
check if pointer is not yet set
type independent &base class of all views
gui independent group class which is a container for gui elements
derive from this class to provide a gui to the current viewer
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...
void remove_all_elements()
this method removes all elements from the gui and can be used in a method that rebuilds the complete ...
cgv::base::base_ptr add_decorator(const std::string &label, const std::string &decorator_type, const std::string &options="", const std::string &align="\n")
add a newly created decorator to the group
virtual void create_gui()=0
you must overload this for gui creation
virtual std::string get_menu_path() const
return a path in the main menu to select the gui
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())
void version of the templated functions
void align(const std::string &_align)
send pure alignment information
view_ptr find_view_void(void *value_ptr, int *idx_ptr)
access to view of untyped member pointer
virtual void update_all_members()
call this to update all views and controls of all member
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
void remove_element(cgv::base::base_ptr)
remove a single element from the gui
provider()
default construction
virtual bool ensure_selected_in_tab_group_parent()
ensure that my UI is selected in the parent group in case this is a tab group, otherwise return false
void inline_object_gui(cgv::base::base_ptr object)
integrate (if not explicitly done before) and inline the gui of another object that must be derived f...
bool add_tree_node(const std::string &label, bool &toggle, int level, const std::string &a="\n", gui_group_ptr ggp=gui_group_ptr())
add a collapsable node to the gui (deprecated)
gui_group_ptr add_group(const std::string &label, const std::string &group_type, const std::string &options="", const std::string &align="\n")
add a newly created subgroup to the group
~provider()
ensure to remove posted recreation callbacks
virtual void update_member(void *member_ptr)
call this to update all views and controls of a member
void update_parent()
update the parent group
std::string concat_enum_def(const std::vector< std::string > &names, const std::string &additional_first_name="", const std::string &additional_last_name="")
add a new group to the given parent group, not supported yet
virtual std::string get_parent_type() const
Returns the group type that should be used by the class embedding the gui of the provider.
void set_parent(gui_group_ptr)
the gui window sets the parent group through this method
virtual void post_recreate_gui()
delayed recreation of gui
cgv::base::base_ptr find_element(const std::string &name)
find a gui element by name in the current group, return empty pointer if not found
virtual void recreate_gui()
Recreate the gui of this instance right now.
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 std::string get_gui_name() const
Derive a name for this instance that can be used in the gui as heading.
virtual void on_select()
called by selection_change_cb whenever the gui of this provider is selected
virtual void on_deselect()
called by selection_change_cb whenever the gui of this provider is deselected
void integrate_object_gui(cgv::base::base_ptr object)
call this in create_gui() function to integrate gui of another provider object by setting the parent ...
virtual shortcut get_shortcut() const
return a shortcut to activate the gui without menu navigation
button_ptr add_button(const std::string &label, const std::string &options="", const std::string &align="\n")
use the current gui driver to append a new button with the given label
virtual void selection_change_cb(cgv::base::base_ptr new_child, bool selected)
this is called by the gui group when the selection changes
control_ptr find_control_void(void *value_ptr, int *idx_ptr)
access to control of untyped member pointer
gui_group_ptr parent_group
driver specific handle for the group gui element managing the gui built in the provider
the shortcut class encapsulates a key with modifiers
data::ref_ptr< base, true > base_ptr
ref counted pointer to base
bool has_property(const std::string &options, const std::string &property, T &value, bool report_error=true)
simple parsing support to access values of properties in a string of property assignment
data::ref_ptr< gui_group, true > gui_group_ptr
ref counted pointer to a gui group
trigger_server_ptr get_trigger_server()
returns the currently registered trigger server
data::ref_ptr< button > button_ptr
ref counted pointer to button
data::ref_ptr< abst_view > view_ptr
ref counted pointer to abst view
data::ref_ptr< abst_control > control_ptr
ref counted pointer to abst control
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
type independent base class of control provider interface