40#ifndef GEOGRAM_GFX_GUI_COMMAND
41#define GEOGRAM_GFX_GUI_COMMAND
145 template<
class FPTR>
static void set_current(
146 const std::string& prototype, FPTR tfun
199 template<
class T,
class TFPTR>
static void set_current(
200 const std::string& prototype, T* target, TFPTR tfun
229 const std::string&
name()
const {
243 if(auto_create_args_) {
245 auto_create_args_ =
false;
325 command->visible_ =
true;
338 const Arg& arg = find_arg_by_index(i);
340 return arg.val.bool_val;
377 const Arg& arg = find_arg_by_index(i);
379 return arg.val.float_val;
393 return double(float_arg_by_index(i));
406 const Arg& arg = find_arg_by_index(i);
408 return std::string(arg.val.string_val);
424 Logger::err(
"Cmd") <<
"Attempted to read argument #"
426 <<
" to variable of unknown type"
443 T* target,
void (T::*fptr)(void)
445 this->assert_nb_args_matches(0);
446 if(target !=
nullptr && fptr !=
nullptr) {
466 void (T::*fptr)(ARG0)
468 this->assert_nb_args_matches(1);
470 this->get_arg_by_index(0,a0);
471 if(target !=
nullptr && fptr !=
nullptr) {
488 class ARG0,
class ARG1
491 void (T::*fptr)(ARG0,ARG1)
493 this->assert_nb_args_matches(2);
495 this->get_arg_by_index(0,a0);
497 this->get_arg_by_index(1,a1);
498 if(target !=
nullptr && fptr !=
nullptr) {
499 (*target.*fptr)(a0,a1);
516 class ARG0,
class ARG1,
class ARG2
519 void (T::*fptr)(ARG0,ARG1,ARG2)
521 this->assert_nb_args_matches(3);
523 this->get_arg_by_index(0,a0);
525 this->get_arg_by_index(1,a1);
527 this->get_arg_by_index(2,a2);
528 if(target !=
nullptr && fptr !=
nullptr) {
529 (*target.*fptr)(a0,a1,a2);
546 class ARG0,
class ARG1,
class ARG2,
class ARG3
549 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3)
551 this->assert_nb_args_matches(4);
553 this->get_arg_by_index(0,a0);
555 this->get_arg_by_index(1,a1);
557 this->get_arg_by_index(2,a2);
559 this->get_arg_by_index(3,a3);
560 if(target !=
nullptr && fptr !=
nullptr) {
561 (*target.*fptr)(a0,a1,a2,a3);
578 class ARG0,
class ARG1,
class ARG2,
class ARG3,
582 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4)
584 this->assert_nb_args_matches(5);
586 this->get_arg_by_index(0,a0);
588 this->get_arg_by_index(1,a1);
590 this->get_arg_by_index(2,a2);
592 this->get_arg_by_index(3,a3);
594 this->get_arg_by_index(4,a4);
595 if(target !=
nullptr && fptr !=
nullptr) {
596 (*target.*fptr)(a0,a1,a2,a3,a4);
613 class ARG0,
class ARG1,
class ARG2,
class ARG3,
614 class ARG4,
class ARG5
617 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5)
619 this->assert_nb_args_matches(6);
621 this->get_arg_by_index(0,a0);
623 this->get_arg_by_index(1,a1);
625 this->get_arg_by_index(2,a2);
627 this->get_arg_by_index(3,a3);
629 this->get_arg_by_index(4,a4);
631 this->get_arg_by_index(5,a5);
632 if(target !=
nullptr && fptr !=
nullptr) {
633 (*target.*fptr)(a0,a1,a2,a3,a4,a5);
650 class ARG0,
class ARG1,
class ARG2,
class ARG3,
651 class ARG4,
class ARG5,
class ARG6
654 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)
656 this->assert_nb_args_matches(7);
658 this->get_arg_by_index(0,a0);
660 this->get_arg_by_index(1,a1);
662 this->get_arg_by_index(2,a2);
664 this->get_arg_by_index(3,a3);
666 this->get_arg_by_index(4,a4);
668 this->get_arg_by_index(5,a5);
670 this->get_arg_by_index(6,a6);
671 if(target !=
nullptr && fptr !=
nullptr) {
672 (*target.*fptr)(a0,a1,a2,a3,a4,a5,a6);
689 class ARG0,
class ARG1,
class ARG2,
class ARG3,
690 class ARG4,
class ARG5,
class ARG6,
class ARG7
693 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)
695 this->assert_nb_args_matches(8);
697 this->get_arg_by_index(0,a0);
699 this->get_arg_by_index(1,a1);
701 this->get_arg_by_index(2,a2);
703 this->get_arg_by_index(3,a3);
705 this->get_arg_by_index(4,a4);
707 this->get_arg_by_index(5,a5);
709 this->get_arg_by_index(6,a6);
711 this->get_arg_by_index(7,a7);
712 if(target !=
nullptr && fptr !=
nullptr) {
713 (*target.*fptr)(a0,a1,a2,a3,a4,a5,a6,a7);
730 this->assert_nb_args_matches(0);
731 if(fptr !=
nullptr) {
750 this->assert_nb_args_matches(1);
752 this->get_arg_by_index(0,a0);
753 if(fptr !=
nullptr) {
768 class ARG0,
class ARG1
770 void (*fptr)(ARG0,ARG1)
772 this->assert_nb_args_matches(2);
774 this->get_arg_by_index(0,a0);
776 this->get_arg_by_index(1,a1);
777 if(fptr !=
nullptr) {
792 class ARG0,
class ARG1,
class ARG2
794 void (*fptr)(ARG0,ARG1,ARG2)
796 this->assert_nb_args_matches(3);
798 this->get_arg_by_index(0,a0);
800 this->get_arg_by_index(1,a1);
802 this->get_arg_by_index(2,a2);
803 if(fptr !=
nullptr) {
818 class ARG0,
class ARG1,
class ARG2,
class ARG3
820 void (*fptr)(ARG0,ARG1,ARG2,ARG3)
822 this->assert_nb_args_matches(4);
824 this->get_arg_by_index(0,a0);
826 this->get_arg_by_index(1,a1);
828 this->get_arg_by_index(2,a2);
830 this->get_arg_by_index(3,a3);
831 if(fptr !=
nullptr) {
832 (*fptr)(a0,a1,a2,a3);
846 class ARG0,
class ARG1,
class ARG2,
class ARG3,
849 void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4)
851 this->assert_nb_args_matches(5);
853 this->get_arg_by_index(0,a0);
855 this->get_arg_by_index(1,a1);
857 this->get_arg_by_index(2,a2);
859 this->get_arg_by_index(3,a3);
861 this->get_arg_by_index(4,a4);
862 if(fptr !=
nullptr) {
863 (*fptr)(a0,a1,a2,a3,a4);
877 class ARG0,
class ARG1,
class ARG2,
class ARG3,
878 class ARG4,
class ARG5
880 void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5)
882 this->assert_nb_args_matches(6);
884 this->get_arg_by_index(0,a0);
886 this->get_arg_by_index(1,a1);
888 this->get_arg_by_index(2,a2);
890 this->get_arg_by_index(3,a3);
892 this->get_arg_by_index(4,a4);
894 this->get_arg_by_index(5,a5);
895 if(fptr !=
nullptr) {
896 (*fptr)(a0,a1,a2,a3,a4,a5);
910 class ARG0,
class ARG1,
class ARG2,
class ARG3,
911 class ARG4,
class ARG5,
class ARG6
913 void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)
915 this->assert_nb_args_matches(7);
917 this->get_arg_by_index(0,a0);
919 this->get_arg_by_index(1,a1);
921 this->get_arg_by_index(2,a2);
923 this->get_arg_by_index(3,a3);
925 this->get_arg_by_index(4,a4);
927 this->get_arg_by_index(5,a5);
929 this->get_arg_by_index(6,a6);
930 if(fptr !=
nullptr) {
931 (*fptr)(a0,a1,a2,a3,a4,a5,a6);
945 class ARG0,
class ARG1,
class ARG2,
class ARG3,
946 class ARG4,
class ARG5,
class ARG6,
class ARG7
948 void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)
950 this->assert_nb_args_matches(8);
952 this->get_arg_by_index(0,a0);
954 this->get_arg_by_index(1,a1);
956 this->get_arg_by_index(2,a2);
958 this->get_arg_by_index(3,a3);
960 this->get_arg_by_index(4,a4);
962 this->get_arg_by_index(5,a5);
964 this->get_arg_by_index(6,a6);
966 this->get_arg_by_index(7,a7);
967 if(fptr !=
nullptr) {
968 (*fptr)(a0,a1,a2,a3,a4,a5,a6,a7);
987 (auto_create_args_ && args_.size() == 0) ||
1003 const std::string& name,
const T& default_val,
1004 const std::string& help =
""
1006 args_.push_back(Arg(name, default_val, help));
1018 index_t i,
const T& default_val
1020 if(i >= args_.size()) {
1023 args_[i] = Arg(
"arg " + String::to_string(i), default_val);
1026 static void set_queued(
Command* command) {
1054 ArgVal(
const ArgVal& rhs);
1062 ArgVal& operator=(
const ArgVal& rhs);
1067 char string_val[64];
1090 const std::string& name_in,
bool x,
1091 const std::string& help_in=
""
1102 const std::string& name_in,
int x,
1103 const std::string& help_in=
""
1115 const std::string& name_in,
unsigned int x,
1116 const std::string& help_in=
""
1127 const std::string& name_in,
float x,
1128 const std::string& help_in=
""
1140 const std::string& name_in,
double x,
1141 const std::string& help_in=
""
1153 const std::string& name_in,
const std::string& x,
1154 const std::string& help_in=
""
1176 const Arg& find_arg(
const std::string& name)
const {
1177 for(index_t i=0; i<args_.size(); ++i) {
1178 if(args_[i].name == name) {
1190 const Arg& find_arg_by_index(index_t i)
const {
1205 bool auto_create_args_;
1206 static SmartPointer<Command> current_;
1207 static SmartPointer<Command> queued_;
1218 if(auto_create_args_) {
1232 if(auto_create_args_) {
1246 if(auto_create_args_) {
1260 if(auto_create_args_) {
1274 if(auto_create_args_) {
1288 if(auto_create_args_) {
1303 template <
class FPTR>
1331 command_->
invoke(FPTR(
nullptr));
1348 template <
class T,
class TFPTR>
1366 target_fun_(target_fun) {
1374 command_->
invoke(target_, target_fun_);
1382 command_->
invoke((T*)(
nullptr), (TFPTR)(
nullptr));
1395 const std::string& prototype,
1407 const std::string& prototype,
#define geo_assert_not_reached
Sets a non reachable point in the program.
#define geo_assert(x)
Verifies that a condition is met.
Abstract class for calling functions or calling member functions.
CommandInvoker()
CommandInvoker constructor.
virtual void auto_create_args()=0
Creates the arguments in the target command.
~CommandInvoker() override
CommandInvoker destructor.
virtual void invoke()=0
Invokes the target function.
Manages the GUI of a command with ImGUI.
static void flush_queue()
Flushes the potentially queued command invokation.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2))
Invokes a member function with the stored arguments.
~Command() override
Command destructor.
void get_arg_by_index(index_t i, T &val)
Gets the value of an argument by index.
bool is_visible() const
Tests whether this Command is visible.
int int_arg_by_index(index_t i) const
Gets the value of an integer argument by index.
void assert_nb_args_matches(index_t nb)
Tests whether the number of declared arguments matches a specified number.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1))
Invokes a member function with the stored arguments.
virtual void reset_factory_settings()
Restores default parameter values for all parameters.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4))
Invokes a member function with the stored arguments.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4))
Invokes a function with the stored arguments.
const std::string & name() const
Gets the name of this command.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5))
Invokes a member function with the stored arguments.
virtual void draw()
Displays and manages the GUI of this Command.
void invoke(void(*fptr)(void))
Invokes a function with the stored arguments.
float float_arg_by_index(index_t i) const
Gets the value of a floating-point argument by index.
void invoke(void(*fptr)(ARG0))
Invokes a function with the stored arguments.
static void set_current(Command *command)
Sets the current command.
void set_invoker(CommandInvoker *invoker)
Sets the invoker.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6))
Invokes a function with the stored arguments.
void invoke(T *target, void(T::*fptr)(ARG0))
Invokes a member function with the stored arguments.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7))
Invokes a function with the stored arguments.
virtual void apply()
Gets the value of the parameters and does the task.
void add_arg(const std::string &name, const T &default_val, const std::string &help="")
Adds a parameter to this command.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5))
Invokes a function with the stored arguments.
void invoke(T *target, void(T::*fptr)(void))
Invokes a member function with the stored arguments.
bool bool_arg_by_index(index_t i) const
Gets the value of a boolean argument by index.
static void reset_current()
Resets the current command.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7))
Invokes a member function with the stored arguments.
std::string string_arg_by_index(index_t i) const
Gets the value of a string argument by index.
void invoke(void(*fptr)(ARG0, ARG1))
Invokes a function with the stored arguments.
void create_arg(index_t i, const T &default_val)
Creates an argument at a given index.
bool * is_visible_ptr()
Gets a pointer to the visibility flag of this command.
Command(const std::string &prototype)
Command constructor.
static void set_current(const std::string &prototype, FPTR tfun)
Binds the current command to a function.
void invoke(void(*fptr)(ARG0, ARG1, ARG2))
Invokes a function with the stored arguments.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6))
Invokes a member function with the stored arguments.
static Command * current()
Gets the current command.
double double_arg_by_index(index_t i) const
Gets the value of a floating-point argument by index and converts it to a double.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3))
Invokes a function with the stored arguments.
unsigned int uint_arg_by_index(index_t i) const
Gets the value of an unsigned integer argument by index.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3))
Invokes a member function with the stored arguments.
Base class for reference-counted objects.
An implementation of CommandInvoker that calls a function.
FunctionCommandInvoker(Command *command, FPTR fun)
FunctionCommandInvoker constructor.
void invoke() override
Invokes the target function.
void auto_create_args() override
Creates the arguments in the target command.
An implementation of CommandInvoker that calls a member function of an object.
void auto_create_args() override
Creates the arguments in the target command.
MemberFunctionCommandInvoker(Command *command, T *target, TFPTR target_fun)
MemberFunctionCommandInvoker constructor.
void invoke() override
Invokes the target function.
A smart pointer with reference-counted copy semantics.
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Common include file, providing basic definitions. Should be included before anything else by all head...
Generic logging mechanism.
Global Vorpaline namespace.
SmartPointer< CommandInvoker > CommandInvoker_var
Automatic reference-counted pointer to a CommandInvoker.
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
geo_index_t index_t
The type for storing and manipulating indices.
Functions for string manipulation.