25 # include "graph_viewport.h" 27 # include "graph_drawing_area.h" 30 #include <utils/system/argparser.h> 31 #include <blackboard/remote.h> 32 #include <netcomm/fawkes/client.h> 34 #include <gui_utils/logview.h> 35 #include <gui_utils/throbber.h> 36 #include <gui_utils/service_chooser_dialog.h> 37 #include <gui_utils/interface_dispatcher.h> 38 #include <gui_utils/plugin_tree_view.h> 47 #define ACTIVE_SKILL "Active Skill" 61 const Glib::RefPtr<Gtk::Builder> &builder)
62 : Gtk::Window(cobject)
70 __gconf = Gnome::Conf::Client::get_default_client();
71 __gconf->add_dir(GCONF_PREFIX);
74 builder->get_widget_derived(
"trv_log", __logview);
75 builder->get_widget(
"tb_connection", tb_connection);
76 builder->get_widget(
"but_continuous", but_continuous);
77 builder->get_widget(
"but_clearlog", but_clearlog);
78 builder->get_widget(
"tb_exit", tb_exit);
79 builder->get_widget(
"cbe_skillstring", cbe_skillstring);
80 builder->get_widget(
"but_exec", but_exec);
81 builder->get_widget(
"but_stop", but_stop);
82 builder->get_widget(
"lab_status", lab_status);
83 builder->get_widget(
"lab_alive", lab_alive);
84 builder->get_widget(
"lab_continuous", lab_continuous);
85 builder->get_widget(
"lab_skillstring", lab_skillstring);
86 builder->get_widget(
"lab_error", lab_error);
87 builder->get_widget(
"scw_graph", scw_graph);
89 builder->get_widget(
"ntb_tabs", ntb_tabs);
90 builder->get_widget(
"tb_skiller", tb_skiller);
91 builder->get_widget(
"tb_agent", tb_agent);
92 builder->get_widget(
"tb_graphlist", tb_graphlist);
93 builder->get_widget(
"tb_controller", tb_controller);
94 builder->get_widget(
"tb_graphsave", tb_graphsave);
95 builder->get_widget(
"tb_graphopen", tb_graphopen);
96 builder->get_widget(
"tb_graphupd", tb_graphupd);
97 builder->get_widget(
"tb_graphrecord", tb_graphrecord);
98 builder->get_widget(
"tb_zoomin", tb_zoomin);
99 builder->get_widget(
"tb_zoomout", tb_zoomout);
100 builder->get_widget(
"tb_zoomfit", tb_zoomfit);
101 builder->get_widget(
"tb_zoomreset", tb_zoomreset);
102 builder->get_widget(
"tb_graphdir", tb_graphdir);
103 builder->get_widget(
"tb_graphcolored", tb_graphcolored);
105 builder->get_widget_derived(
"img_throbber", __throbber);
106 builder->get_widget_derived(
"trv_plugins", __trv_plugins);
108 Gtk::SeparatorToolItem *spacesep;
109 builder->get_widget(
"tb_spacesep", spacesep);
110 spacesep->set_expand();
113 tb_graphsave->set_homogeneous(
false);
114 tb_graphopen->set_homogeneous(
false);
115 tb_graphupd->set_homogeneous(
false);
116 tb_graphrecord->set_homogeneous(
false);
117 tb_zoomin->set_homogeneous(
false);
118 tb_zoomout->set_homogeneous(
false);
119 tb_zoomfit->set_homogeneous(
false);
120 tb_zoomreset->set_homogeneous(
false);
121 tb_graphdir->set_homogeneous(
false);
122 tb_graphcolored->set_homogeneous(
false);
124 #if GTK_VERSION_GE(3,0) 125 if (! cbe_skillstring->get_has_entry()) {
126 throw Exception(
"Skill string combo box has no entry, invalid UI file?");
129 __sks_list = Gtk::ListStore::create(__sks_record);
130 cbe_skillstring->set_model(__sks_list);
131 #if GTK_VERSION_GE(3,0) 132 cbe_skillstring->set_entry_text_column(__sks_record.skillstring);
134 cbe_skillstring->set_text_column(__sks_record.skillstring);
137 cbe_skillstring->get_entry()->set_activates_default(
true);
146 scw_graph->add(*pvp_graph);
150 scw_graph->add(*gda);
154 cb_graphlist = Gtk::manage(
new Gtk::ComboBoxText());
155 #if GTK_VERSION_GE(3,0) 156 cb_graphlist->append(ACTIVE_SKILL);
158 cb_graphlist->append_text(ACTIVE_SKILL);
160 cb_graphlist->set_active_text(ACTIVE_SKILL);
161 tb_graphlist->add(*cb_graphlist);
162 cb_graphlist->show();
166 connection_dispatcher.
signal_connected().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_connect));
167 connection_dispatcher.
signal_disconnected().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_disconnect));
169 tb_connection->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_connection_clicked));
170 but_exec->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_exec_clicked));
171 tb_controller->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_controller_clicked));
172 tb_exit->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_exit_clicked));
173 but_stop->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_stop_clicked));
174 but_continuous->signal_toggled().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_contexec_toggled));
175 but_clearlog->signal_clicked().connect(sigc::mem_fun(*__logview, &LogView::clear));
176 tb_skiller->signal_toggled().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skdbg_data_changed));
177 tb_skiller->signal_toggled().connect(sigc::bind(sigc::mem_fun(*cb_graphlist, &Gtk::ComboBoxText::set_sensitive),
true));
178 tb_agent->signal_toggled().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_agdbg_data_changed));
179 tb_agent->signal_toggled().connect(sigc::bind(sigc::mem_fun(*cb_graphlist, &Gtk::ComboBoxText::set_sensitive),
false));
180 cb_graphlist->signal_changed().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skill_changed));
181 tb_graphupd->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphupd_clicked));
182 tb_graphdir->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphdir_clicked));
183 tb_graphcolored->signal_toggled().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphcolor_toggled));
197 tb_graphrecord->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_recording_toggled));
202 __gconf->signal_value_changed().connect(sigc::hide(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_config_changed))));
212 __gconf->remove_dir(GCONF_PREFIX);
220 SkillGuiGtkWindow::on_config_changed()
223 Gnome::Conf::SListHandle_ValueString l(__gconf->get_string_list(GCONF_PREFIX
"/command_history"));
226 for (Gnome::Conf::SListHandle_ValueString::const_iterator i = l.begin(); i != l.end(); ++i) {
227 Gtk::TreeModel::Row row = *__sks_list->append();
228 row[__sks_record.skillstring] = *i;
231 #ifdef GLIBMM_EXCEPTIONS_ENABLED 232 bool continuous = __gconf->get_bool(GCONF_PREFIX
"/continuous_exec");
233 bool colored = __gconf->get_bool(GCONF_PREFIX
"/graph_colored");
235 std::auto_ptr<Glib::Error> error;
236 bool continuous = __gconf->get_bool(GCONF_PREFIX
"/continuous_exec", error);
237 bool colored = __gconf->get_bool(GCONF_PREFIX
"/graph_colored", error);
239 but_continuous->set_active(continuous);
240 tb_graphcolored->set_active(colored);
246 SkillGuiGtkWindow::on_skill_changed()
248 Glib::ustring skill = cb_graphlist->get_active_text();
249 if ( skill == ACTIVE_SKILL ) {
257 SkillGuiGtkWindow::on_contexec_toggled()
260 __gconf->set(GCONF_PREFIX
"/continuous_exec", but_continuous->get_active());
266 SkillGuiGtkWindow::on_connection_clicked()
278 SkillGuiGtkWindow::on_exit_clicked()
285 SkillGuiGtkWindow::on_controller_clicked()
298 Gtk::MessageDialog md(*
this,
299 "Another component already acquired the exclusive " 300 "control for the Skiller; not acquiring exclusive control.",
302 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
304 md.set_title(
"Control Acquisition Failed");
310 SkillGuiGtkWindow::on_stop_clicked()
319 SkillGuiGtkWindow::close_bb()
325 delete __skiller_ifd;
333 bb->
close(__skiller_if);
334 bb->
close(__skdbg_if);
335 bb->
close(__agdbg_if);
346 SkillGuiGtkWindow::on_connect()
354 on_skiller_data_changed();
355 on_skdbg_data_changed();
356 on_agdbg_data_changed();
364 __skiller_ifd->
signal_data_changed().connect(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skiller_data_changed)));
365 __skdbg_ifd->
signal_data_changed().connect(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skdbg_data_changed)));
366 __agdbg_ifd->
signal_data_changed().connect(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_agdbg_data_changed)));
370 __skiller_if->read();
371 if (__skiller_if->has_writer() && __skiller_if->exclusive_controller() == 0) {
373 __skiller_if->msgq_enqueue(aqm);
380 tb_connection->set_stock_id(Gtk::Stock::DISCONNECT);
383 but_continuous->set_sensitive(
true);
384 tb_controller->set_sensitive(
true);
385 cbe_skillstring->set_sensitive(
true);
389 Glib::ustring message = *(e.
begin());
390 Gtk::MessageDialog md(*
this, message,
false,
391 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
393 md.set_title(
"BlackBoard connection failed");
403 SkillGuiGtkWindow::on_disconnect()
405 but_continuous->set_sensitive(
false);
406 tb_controller->set_sensitive(
false);
407 cbe_skillstring->set_sensitive(
false);
408 but_exec->set_sensitive(
false);
409 but_stop->set_sensitive(
false);
413 tb_connection->set_stock_id(Gtk::Stock::CONNECT);
415 pvp_graph->queue_draw();
419 this->set_title(
"Skill GUI");
424 SkillGuiGtkWindow::on_exec_clicked()
426 Glib::ustring sks =
"";
427 if ( cbe_skillstring->get_active_row_number() == -1 ) {
428 Gtk::Entry *entry = cbe_skillstring->get_entry();
429 sks = entry->get_text();
431 Gtk::TreeModel::Row row = *cbe_skillstring->get_active();
432 #if GTK_VERSION_GE(3,0) 433 row.get_value(cbe_skillstring->get_entry_text_column(), sks);
435 row.get_value(cbe_skillstring->get_text_column(), sks);
445 if ( but_continuous->get_active() ) {
453 Gtk::TreeModel::Children children = __sks_list->children();
455 if ( ! children.empty() ) {
457 Gtk::TreeIter i = children.begin();
458 while (ok && (i != children.end())) {
460 i = __sks_list->erase(i);
462 Gtk::TreeModel::Row row = *i;
463 ok = (row[__sks_record.skillstring] != sks);
470 Gtk::TreeModel::Row row = *__sks_list->prepend();
471 row[__sks_record.skillstring] = sks;
473 std::list<Glib::ustring> l;
474 for (Gtk::TreeIter i = children.begin(); i != children.end(); ++i) {
475 Gtk::TreeModel::Row row = *i;
476 l.push_back(row[__sks_record.skillstring]);
480 __gconf->set_string_list(GCONF_PREFIX
"/command_history", l);
484 Gtk::MessageDialog md(*
this,
"The exclusive control over the skiller has " 485 "not been acquired yet and skills cannot be executed",
487 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
489 md.set_title(
"Skill Execution Failure");
497 SkillGuiGtkWindow::on_skiller_data_changed()
500 __skiller_if->
read();
502 switch (__skiller_if->
status()) {
503 case SkillerInterface::S_INACTIVE:
505 lab_status->set_text(
"S_INACTIVE");
507 case SkillerInterface::S_FINAL:
509 __throbber->
set_stock(Gtk::Stock::APPLY);
510 lab_status->set_text(
"S_FINAL");
512 case SkillerInterface::S_RUNNING:
514 lab_status->set_text(
"S_RUNNING");
516 case SkillerInterface::S_FAILED:
518 __throbber->
set_stock(Gtk::Stock::DIALOG_WARNING);
519 lab_status->set_text(
"S_FAILED");
523 lab_skillstring->set_text(__skiller_if->
skill_string());
524 lab_error->set_text(__skiller_if->
error());
525 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12 ) 526 lab_skillstring->set_tooltip_text(__skiller_if->
skill_string());
527 lab_error->set_tooltip_text(__skiller_if->
error());
529 lab_continuous->set_text(__skiller_if->
is_continuous() ?
"Yes" :
"No");
530 lab_alive->set_text(__skiller_if->
has_writer() ?
"Yes" :
"No");
533 if ( tb_controller->get_stock_id() == Gtk::Stock::NO.id ) {
534 tb_controller->set_stock_id(Gtk::Stock::YES);
535 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12 ) 536 tb_controller->set_tooltip_text(
"Release exclusive control");
539 but_exec->set_sensitive(
true);
540 but_stop->set_sensitive(
true);
542 if ( tb_controller->get_stock_id() == Gtk::Stock::YES.id ) {
543 tb_controller->set_stock_id(Gtk::Stock::NO);
544 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12 ) 545 tb_controller->set_tooltip_text(
"Gain exclusive control");
548 but_exec->set_sensitive(
false);
549 but_stop->set_sensitive(
false);
560 SkillGuiGtkWindow::on_skdbg_data_changed()
562 if (tb_skiller->get_active() && __skdbg_if) {
566 if (strcmp(__skdbg_if->
graph_fsm(),
"LIST") == 0) {
567 Glib::ustring list = __skdbg_if->
graph();
568 #if GTK_VERSION_GE(3,0) 569 cb_graphlist->remove_all();
570 cb_graphlist->append(ACTIVE_SKILL);
572 cb_graphlist->clear_items();
573 cb_graphlist->append_text(ACTIVE_SKILL);
575 cb_graphlist->set_active_text(ACTIVE_SKILL);
576 #if GTK_VERSION_GE(2,14) 577 Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create(
"\n");
578 std::list<std::string> skills = regex->split(list);
579 for (std::list<std::string>::iterator i = skills.begin(); i != skills.end(); ++i) {
580 #if GTK_VERSION_GE(3,0) 581 if (*i !=
"") cb_graphlist->append(*i);
583 if (*i !=
"") cb_graphlist->append_text(*i);
593 pvp_graph->set_graph_fsm(__skdbg_if->
graph_fsm());
594 pvp_graph->set_graph(__skdbg_if->
graph());
603 case SkillerDebugInterface::GD_TOP_BOTTOM:
604 tb_graphdir->set_stock_id(Gtk::Stock::GO_DOWN);
break;
605 case SkillerDebugInterface::GD_BOTTOM_TOP:
606 tb_graphdir->set_stock_id(Gtk::Stock::GO_UP);
break;
607 case SkillerDebugInterface::GD_LEFT_RIGHT:
608 tb_graphdir->set_stock_id(Gtk::Stock::GO_FORWARD);
break;
609 case SkillerDebugInterface::GD_RIGHT_LEFT:
610 tb_graphdir->set_stock_id(Gtk::Stock::GO_BACK);
break;
620 SkillGuiGtkWindow::on_agdbg_data_changed()
622 if (tb_agent->get_active() && __agdbg_if) {
626 pvp_graph->set_graph_fsm(__agdbg_if->
graph_fsm());
627 pvp_graph->set_graph(__agdbg_if->
graph());
635 case SkillerDebugInterface::GD_TOP_BOTTOM:
636 tb_graphdir->set_stock_id(Gtk::Stock::GO_DOWN);
break;
637 case SkillerDebugInterface::GD_BOTTOM_TOP:
638 tb_graphdir->set_stock_id(Gtk::Stock::GO_UP);
break;
639 case SkillerDebugInterface::GD_LEFT_RIGHT:
640 tb_graphdir->set_stock_id(Gtk::Stock::GO_FORWARD);
break;
641 case SkillerDebugInterface::GD_RIGHT_LEFT:
642 tb_graphdir->set_stock_id(Gtk::Stock::GO_BACK);
break;
652 SkillGuiGtkWindow::on_graphupd_clicked()
655 if ( pvp_graph->get_update_graph() ) {
656 pvp_graph->set_update_graph(
false);
657 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
659 pvp_graph->set_update_graph(
true);
660 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_PLAY);
666 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
669 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_PLAY);
676 SkillGuiGtkWindow::on_graphdir_clicked()
679 if (tb_agent->get_active()) {
683 Glib::ustring stockid = tb_graphdir->get_stock_id();
684 if (stockid == Gtk::Stock::GO_DOWN.
id) {
685 send_graphdir_message(iface, SkillerDebugInterface::GD_BOTTOM_TOP);
686 }
else if (stockid == Gtk::Stock::GO_UP.
id) {
687 send_graphdir_message(iface, SkillerDebugInterface::GD_LEFT_RIGHT);
688 }
else if (stockid == Gtk::Stock::GO_FORWARD.
id) {
689 send_graphdir_message(iface, SkillerDebugInterface::GD_RIGHT_LEFT);
690 }
else if (stockid == Gtk::Stock::GO_BACK.
id) {
691 send_graphdir_message(iface, SkillerDebugInterface::GD_TOP_BOTTOM);
705 throw Exception(
"Not connected to Fawkes.");
708 Gtk::MessageDialog md(*
this,
709 Glib::ustring(
"Setting graph direction failed: ") + e.
what(),
711 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
713 md.set_title(
"Communication Failure");
721 if (tb_agent->get_active()) {
722 send_graphdir_message(__agdbg_if, gd);
724 send_graphdir_message(__skdbg_if, gd);
730 SkillGuiGtkWindow::on_graphcolor_toggled()
733 __gconf->set(GCONF_PREFIX
"/graph_colored", tb_graphcolored->get_active());
737 if (tb_agent->get_active()) {
747 throw Exception(
"Not connected to Fawkes.");
764 SkillGuiGtkWindow::SkillStringRecord::SkillStringRecord()
771 SkillGuiGtkWindow::on_update_disabled()
775 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
781 SkillGuiGtkWindow::on_recording_toggled()
785 bool active = tb_graphrecord->get_active();
787 tb_graphrecord->set_active(!active);
SkillerDebugInterface Fawkes BlackBoard Interface.
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
const char * get_hostname() const
Get the client's hostname.
sigc::signal< void > signal_connected()
Get "connected" signal.
unsigned short serial() const
Get instance serial of interface.
void set_graph(std::string graph)
Set graph.
uint32_t exclusive_controller() const
Get exclusive_controller value.
SkillStatusEnum status() const
Get status value.
Fawkes library namespace.
bool is_valid() const
Check validity of interface.
void disconnect()
Disconnect socket.
bool set_recording(bool recording)
Enable/disable recording.
StopExecMessage Fawkes BlackBoard Interface Message.
sigc::signal< void > signal_update_disabled()
Get "update disabled" signal.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
void start_anim()
Start animation.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
void stop_anim()
Stop animation.
SetGraphMessage Fawkes BlackBoard Interface Message.
~SkillGuiGtkWindow()
Destructor.
bool get_update_graph()
Check if graph is being updated.
AcquireControlMessage Fawkes BlackBoard Interface Message.
void set_graph_fsm(std::string fsm_name)
Set graph's FSM name.
SkillGuiGtkWindow(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
bool has_writer() const
Check if there is a writer for the interface.
bool is_continuous() const
Get continuous value.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
void set_timeout(unsigned int timeout)
Set the animation timeout.
void zoom_fit()
Zoom to fit.
void zoom_reset()
Zoom reset.
virtual const char * what() const
Get primary string.
Base class for exceptions in Fawkes.
void set_stock(const Gtk::StockID &stock_id)
Set image from stock ID.
void read()
Read from BlackBoard into local copy.
GraphDirectionEnum
Primary direction of the graph.
char * graph_fsm() const
Get graph_fsm value.
void run_and_connect()
Run dialog and try to connect.
void save()
save current graph.
void set_update_graph(bool update)
Set if the graph should be updated on new data.
void save()
Render current graph.
void set_gconf_prefix(Glib::ustring gconf_prefix)
Set Gconf prefix.
iterator begin()
Get iterator for messages.
ExecSkillMessage Fawkes BlackBoard Interface Message.
bool connected() const
Check if connection is alive.
SetGraphColoredMessage Fawkes BlackBoard Interface Message.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
char * skill_string() const
Get skill_string value.
char * error() const
Get error value.
GraphDirectionEnum graph_dir() const
Get graph_dir value.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier)=0
Open interface for reading.
void set_network_client(fawkes::FawkesNetworkClient *client)
Set the network client.
SkillerInterface Fawkes BlackBoard Interface.
char * graph() const
Get graph value.
void open()
Open a dot graph and display it.
void zoom_fit()
Zoom to fit.
void set_client(FawkesNetworkClient *client)
Set FawkesNetworkClient instance.
FawkesNetworkClient * get_client()
Get client.
ExecSkillContinuousMessage Fawkes BlackBoard Interface Message.
void zoom_reset()
Zoom reset.
SetGraphDirectionMessage Fawkes BlackBoard Interface Message.
Skill FSM Graph Viewport.
Interface listener with dispatcher.
sigc::signal< void, Interface * > signal_data_changed()
Get "data changed" signal.
virtual void close(Interface *interface)=0
Close interface.