4 #include <KrisLibrary/utils/AnyCollection.h> 5 #include <KrisLibrary/math3d/primitives.h> 13 class GenericBackendBase;
37 virtual bool ProcessMessage(
const AnyCollection& msg);
39 virtual bool SendMessage(
const AnyCollection& msg);
44 void AddRule(
const AnyCollection& inschema,
const AnyCollection& outschema,
bool mapWildcardStrings=
true);
46 void AddCommandRule(
const AnyCollection& inschema,
const string& cmd,
const string& args,
bool mapWildcardStrings=
true);
47 bool LoadRules(
const char* fn);
48 bool LoadRules(istream& in);
50 virtual bool OnQuit() {
return false; }
51 virtual bool OnCommand(
const string& cmd,
const string& args) {
return false; }
52 virtual bool OnNotify(
const string& text,
const string& msglevel) {
return false; }
53 virtual bool OnPauseIdle(
double secs) {
return false; }
54 virtual bool OnRefresh() {
return false; }
55 virtual bool OnResize(
int w,
int h) {
return false; }
56 virtual bool OnDrawText(
double x,
double y,
double z,
const std::string &text,
int height) {
return false; }
57 virtual bool OnDrawText(
int x,
int y,
const std::string &text,
int height) {
return false; }
61 bool SendGLViewport(
int x,
int y,
int w,
int h);
62 bool SendCommand(
const string& cmd,
const string& args);
63 bool SendCommand(
const string& cmd);
65 bool SendCommand(
const string& cmd,
const T& arg1);
66 template <
class T1,
class T2>
67 bool SendCommand(
const string& cmd,
const T1& arg1,
const T2& arg2);
68 template <
class T1,
class T2,
class T3>
69 bool SendCommand(
const string& cmd,
const T1& arg1,
const T2& arg2,
const T3& arg3);
70 bool SendButtonPress(
const string& widget);
71 bool SendButtonToggle(
const string& widget,
int checked);
72 bool SendWidgetValue(
const string& widget,
const string& value);
73 bool SendMouseClick(
int button,
int state,
int mx,
int my);
74 bool SendMouseMove(
int mx,
int my);
75 bool SendMouseWheel(
int dwheel);
76 bool SendScroll(
int dy);
77 bool SendKeyDown(
const string& key);
78 bool SendKeyUp(
const string& key);
79 bool SendSpaceball(
const Math3D::RigidTransform& T);
80 bool SendDevice(
const string& name,
const string& data);
83 vector<pair<AnyCollection,AnyCollection> > rules;
93 virtual void Stop() {}
96 virtual bool ProcessMessage(
const AnyCollection& msg);
98 virtual bool SendMessage(
const AnyCollection& msg) {
return gui->ProcessMessage(msg); }
101 void MapButtonPress(
const string& button,
int* var);
102 void MapButtonToggle(
const string& button,
int* var);
103 void MapWidgetValue(
const string& button,
string* var);
104 void MapKeyToggle(
const string& key,
int* var);
106 virtual bool OnIdle() { SendPauseIdle();
return true; }
107 virtual bool OnGLRender() {
return false; }
108 virtual bool OnGLViewport(
int x,
int y,
int w,
int h) {
return false; }
109 virtual bool OnCommand(
const string& cmd,
const string& args) {
return false; }
110 virtual bool OnButtonPress(
const string& button);
111 virtual bool OnButtonToggle(
const string& button,
int checked);
112 virtual bool OnWidgetValue(
const string& widget,
const string& value);
113 virtual bool OnMouseClick(
int button,
int state,
int mx,
int my) {
return false; }
114 virtual bool OnMouseMove(
int mx,
int my) {
return false; }
115 virtual bool OnMouseWheel(
int dwheel) {
return false; }
116 virtual bool OnScroll(
int dy) {
return false; }
117 virtual bool OnKeyDown(
const string& key);
118 virtual bool OnKeyUp(
const string& key);
119 virtual bool OnSpaceball(
const Math3D::RigidTransform& T) {
return false; }
120 virtual bool OnDevice(
const string& name,
const string& data) {
return false; }
123 bool SendCommand(
const string& cmd,
const string& args);
124 bool SendNotify(
const string& text,
const string& msglevel=
"");
125 bool SendError(
const string& text) {
return SendNotify(text,
"error"); }
126 bool SendWarning(
const string& text) {
return SendNotify(text,
"warning"); }
127 bool SendPauseIdle(
double secs=1e300);
129 bool SendResize(
int w,
int h);
130 bool SendDrawText(
double x,
double y,
double z,
const std::string &text,
int height = 10);
131 bool SendDrawText(
int x,
int y,
const std::string &text,
int height = 10);
134 map<string,int*> liveButtonPresses;
135 map<string,int*> liveButtonToggles;
136 map<string,string*> liveWidgetValues;
137 map<string,int*> liveKeys;
157 void Add(std::shared_ptr<GenericBackendBase>& backend);
158 void SetDefaultBroadcasts();
159 void SetBroadcast(
const string& msgtype) { targets[msgtype]=
"all"; }
160 virtual bool ProcessMessage(
const AnyCollection& msg);
162 vector<std::shared_ptr<GenericBackendBase> > children;
163 map<string,string> targets;
171 #define DISPATCHBEGIN() \ 174 res = msg["type"].as<string>(type); \ 176 cerr<<"Message doesn't contain type"<<endl; \ 180 #define DISPATCHEND() \ 182 cerr<<"Unhandled message type "<<type<<endl; \ 187 #define DISPATCH0(msgtype,func) \ 188 else if(type == msgtype) \ 191 #define DISPATCH1(msgtype,arg1,func) \ 192 else if(type == msgtype) \ 193 return func(msg[#arg1]); 196 #define DISPATCH2(msgtype,arg1,arg2,func) \ 197 else if(type == msgtype) \ 198 return func(msg[#arg1],msg[#arg2]); 200 #define DISPATCH3(msgtype,arg1,arg2,arg3,func) \ 201 else if(type == msgtype) \ 202 return func(msg[#arg1],msg[#arg2],msg[#arg3]); 204 #define DISPATCH4(msgtype,arg1,arg2,arg3,arg4,func) \ 205 else if(type == msgtype) \ 206 return func(msg[#arg1],msg[#arg2],msg[#arg3],msg[#arg4]); 208 #define DISPATCH5(msgtype,arg1,arg2,arg3,arg4,arg5,func) \ 209 else if(type == msgtype) \ 210 return func(msg[#arg1],msg[#arg2],msg[#arg3],msg[#arg4],msg[#arg5]); 217 #define SEND0(msgtype)\ 219 msg["type"] = string(msgtype); \ 220 return SendMessage(msg); 222 #define SEND1(msgtype,arg1) \ 224 msg["type"] = string(msgtype); \ 226 return SendMessage(msg); 228 #define SEND2(msgtype,arg1,arg2) \ 230 msg["type"] = string(msgtype); \ 233 return SendMessage(msg); 235 #define SEND3(msgtype,arg1,arg2,arg3) \ 237 msg["type"] = string(msgtype); \ 241 return SendMessage(msg); 243 #define SEND4(msgtype,arg1,arg2,arg3,arg4) \ 245 msg["type"] = string(msgtype); \ 250 return SendMessage(msg); 252 #define SEND5(msgtype,arg1,arg2,arg3,arg4,arg5) \ 254 msg["type"] = string(msgtype); \ 260 return SendMessage(msg); 264 bool GenericGUIBase::SendCommand(
const string& cmd,
const T& arg1)
268 return this->SendCommand(cmd,ss.str());
271 template <
class T1,
class T2>
272 bool GenericGUIBase::SendCommand(
const string& cmd,
const T1& arg1,
const T2& arg2)
276 return this->SendCommand(cmd,ss.str());
279 template <
class T1,
class T2,
class T3>
280 bool GenericGUIBase::SendCommand(
const string& cmd,
const T1& arg1,
const T2& arg2,
const T3& arg3)
283 ss<<arg1<<
" "<<arg2<<
" "<<arg3<<endl;
284 return this->SendCommand(cmd,ss.str());
virtual void Start()
Default implementation of following do nothing.
Definition: GenericGUI.h:92
virtual bool SendMessage(const AnyCollection &msg)
Send a message to the gui.
Definition: GenericGUI.h:98
Definition: GenericGUI.h:86
A base class for a GUI frontend. Performs message passing to the backend in the easily serializable A...
Definition: GenericGUI.h:27
Definition: GenericGUI.h:154
Definition: ContactDistance.h:6