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/service_chooser_dialog.h> 36 #include <gui_utils/interface_dispatcher.h> 37 #include <gui_utils/plugin_tree_view.h> 47 #define ACTIVE_SKILL "Active Skill" 48 #define SKILL_DOT "Skills dot graph" 49 #define SKILL_SEP_LINE "----------------" 63 const Glib::RefPtr<Gtk::Builder> &builder)
64 : Gtk::Window(cobject)
73 __gconf = Gnome::Conf::Client::get_default_client();
74 __gconf->add_dir(GCONF_PREFIX);
75 }
catch (Gnome::Conf::Error &e) {
76 std::cerr << e.what() << std::endl;
81 builder->get_widget_derived(
"trv_log", __logview);
82 builder->get_widget(
"tb_connection", tb_connection);
83 builder->get_widget(
"but_clearlog", but_clearlog);
84 builder->get_widget(
"tb_exit", tb_exit);
85 builder->get_widget(
"cbe_skillstring", cbe_skillstring);
86 builder->get_widget(
"but_exec", but_exec);
87 builder->get_widget(
"but_stop", but_stop);
88 builder->get_widget(
"lab_status", lab_status);
89 builder->get_widget(
"lab_alive", lab_alive);
90 builder->get_widget(
"lab_skillstring", lab_skillstring);
91 builder->get_widget(
"lab_error", lab_error);
92 builder->get_widget(
"scw_graph", scw_graph);
94 builder->get_widget(
"ntb_tabs", ntb_tabs);
95 builder->get_widget(
"tb_skiller", tb_skiller);
96 builder->get_widget(
"tb_agent", tb_agent);
97 builder->get_widget(
"tb_graphlist", tb_graphlist);
98 builder->get_widget(
"tb_controller", tb_controller);
99 builder->get_widget(
"tb_graphsave", tb_graphsave);
100 builder->get_widget(
"tb_graphopen", tb_graphopen);
101 builder->get_widget(
"tb_graphupd", tb_graphupd);
102 builder->get_widget(
"tb_graphrecord", tb_graphrecord);
103 builder->get_widget(
"tb_zoomin", tb_zoomin);
104 builder->get_widget(
"tb_zoomout", tb_zoomout);
105 builder->get_widget(
"tb_zoomfit", tb_zoomfit);
106 builder->get_widget(
"tb_zoomreset", tb_zoomreset);
107 builder->get_widget(
"tb_graphdir", tb_graphdir);
108 builder->get_widget(
"tb_graphcolored", tb_graphcolored);
110 #if GTKMM_VERSION_GE(2,20) 111 builder->get_widget(
"tb_spinner", tb_spinner);
113 builder->get_widget_derived(
"trv_plugins", __trv_plugins);
115 Gtk::SeparatorToolItem *spacesep;
116 builder->get_widget(
"tb_spacesep", spacesep);
117 spacesep->set_expand();
120 tb_graphsave->set_homogeneous(
false);
121 tb_graphopen->set_homogeneous(
false);
122 tb_graphupd->set_homogeneous(
false);
123 tb_graphrecord->set_homogeneous(
false);
124 tb_zoomin->set_homogeneous(
false);
125 tb_zoomout->set_homogeneous(
false);
126 tb_zoomfit->set_homogeneous(
false);
127 tb_zoomreset->set_homogeneous(
false);
128 tb_graphdir->set_homogeneous(
false);
129 tb_graphcolored->set_homogeneous(
false);
131 #if GTK_VERSION_GE(3,0) 132 if (! cbe_skillstring->get_has_entry()) {
133 throw Exception(
"Skill string combo box has no entry, invalid UI file?");
136 __sks_list = Gtk::ListStore::create(__sks_record);
137 cbe_skillstring->set_model(__sks_list);
138 #if GTK_VERSION_GE(3,0) 139 cbe_skillstring->set_entry_text_column(__sks_record.skillstring);
141 cbe_skillstring->set_text_column(__sks_record.skillstring);
144 cbe_skillstring->get_entry()->set_activates_default(
true);
153 scw_graph->add(*pvp_graph);
157 scw_graph->add(*gda);
161 cb_graphlist = Gtk::manage(
new Gtk::ComboBoxText());
162 #if GTK_VERSION_GE(3,0) 163 cb_graphlist->append(ACTIVE_SKILL);
165 cb_graphlist->append_text(ACTIVE_SKILL);
167 cb_graphlist->set_active_text(ACTIVE_SKILL);
168 tb_graphlist->add(*cb_graphlist);
169 cb_graphlist->show();
173 connection_dispatcher.
signal_connected().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_connect));
174 connection_dispatcher.
signal_disconnected().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_disconnect));
176 tb_connection->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_connection_clicked));
177 but_exec->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_exec_clicked));
178 tb_controller->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_controller_clicked));
179 tb_exit->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_exit_clicked));
180 but_stop->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_stop_clicked));
181 but_clearlog->signal_clicked().connect(sigc::mem_fun(*__logview, &LogView::clear));
182 tb_skiller->signal_toggled().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skdbg_data_changed));
183 tb_skiller->signal_toggled().connect(sigc::bind(sigc::mem_fun(*cb_graphlist, &Gtk::ComboBoxText::set_sensitive),
true));
184 tb_agent->signal_toggled().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_agdbg_data_changed));
185 tb_agent->signal_toggled().connect(sigc::bind(sigc::mem_fun(*cb_graphlist, &Gtk::ComboBoxText::set_sensitive),
false));
186 cb_graphlist->signal_changed().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skill_changed));
187 tb_graphupd->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphupd_clicked));
188 tb_graphdir->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphdir_clicked));
189 tb_graphcolored->signal_toggled().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphcolor_toggled));
203 tb_graphrecord->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_recording_toggled));
208 __gconf->signal_value_changed().connect(sigc::hide(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_config_changed))));
218 __gconf->remove_dir(GCONF_PREFIX);
226 SkillGuiGtkWindow::on_config_changed()
229 Gnome::Conf::SListHandle_ValueString l(__gconf->get_string_list(GCONF_PREFIX
"/command_history"));
232 for (Gnome::Conf::SListHandle_ValueString::const_iterator i = l.begin(); i != l.end(); ++i) {
233 Gtk::TreeModel::Row row = *__sks_list->append();
234 row[__sks_record.skillstring] = *i;
237 bool colored = __gconf->get_bool(GCONF_PREFIX
"/graph_colored");
238 tb_graphcolored->set_active(colored);
244 SkillGuiGtkWindow::on_skill_changed()
246 Glib::ustring skill = cb_graphlist->get_active_text();
247 if ( skill == ACTIVE_SKILL || skill == SKILL_SEP_LINE ) {
249 }
else if( skill == SKILL_DOT ) {
258 SkillGuiGtkWindow::on_connection_clicked()
270 SkillGuiGtkWindow::on_exit_clicked()
277 SkillGuiGtkWindow::on_controller_clicked()
290 Gtk::MessageDialog md(*
this,
291 "Another component already acquired the exclusive " 292 "control for the Skiller; not acquiring exclusive control.",
294 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
296 md.set_title(
"Control Acquisition Failed");
302 SkillGuiGtkWindow::on_stop_clicked()
311 SkillGuiGtkWindow::close_bb()
317 delete __skiller_ifd;
325 bb->
close(__skiller_if);
326 bb->
close(__skdbg_if);
327 bb->
close(__agdbg_if);
338 SkillGuiGtkWindow::on_connect()
346 on_skiller_data_changed();
347 on_skdbg_data_changed();
348 on_agdbg_data_changed();
356 __skiller_ifd->
signal_data_changed().connect(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skiller_data_changed)));
357 __skdbg_ifd->
signal_data_changed().connect(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skdbg_data_changed)));
358 __agdbg_ifd->
signal_data_changed().connect(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_agdbg_data_changed)));
362 __skiller_if->read();
363 if (__skiller_if->has_writer() && __skiller_if->exclusive_controller() == 0) {
365 __skiller_if->msgq_enqueue(aqm);
372 tb_connection->set_stock_id(Gtk::Stock::DISCONNECT);
375 tb_controller->set_sensitive(
true);
376 cbe_skillstring->set_sensitive(
true);
380 Glib::ustring message = *(e.
begin());
381 Gtk::MessageDialog md(*
this, message,
false,
382 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
384 md.set_title(
"BlackBoard connection failed");
394 SkillGuiGtkWindow::on_disconnect()
396 tb_controller->set_sensitive(
false);
397 cbe_skillstring->set_sensitive(
false);
398 but_exec->set_sensitive(
false);
399 but_stop->set_sensitive(
false);
403 tb_connection->set_stock_id(Gtk::Stock::CONNECT);
405 pvp_graph->queue_draw();
409 this->set_title(
"Skill GUI");
414 SkillGuiGtkWindow::on_exec_clicked()
416 Glib::ustring sks =
"";
417 if ( cbe_skillstring->get_active_row_number() == -1 ) {
418 Gtk::Entry *entry = cbe_skillstring->get_entry();
419 sks = entry->get_text();
421 Gtk::TreeModel::Row row = *cbe_skillstring->get_active();
422 #if GTK_VERSION_GE(3,0) 423 row.get_value(cbe_skillstring->get_entry_text_column(), sks);
425 row.get_value(cbe_skillstring->get_text_column(), sks);
430 #if GTKMM_VERSION_GE(2,20) 440 Gtk::TreeModel::Children children = __sks_list->children();
442 if ( ! children.empty() ) {
444 Gtk::TreeIter i = children.begin();
445 while (ok && (i != children.end())) {
447 i = __sks_list->erase(i);
449 Gtk::TreeModel::Row row = *i;
450 ok = (row[__sks_record.skillstring] != sks);
457 Gtk::TreeModel::Row row = *__sks_list->prepend();
458 row[__sks_record.skillstring] = sks;
460 std::list<Glib::ustring> l;
461 for (Gtk::TreeIter i = children.begin(); i != children.end(); ++i) {
462 Gtk::TreeModel::Row row = *i;
463 l.push_back(row[__sks_record.skillstring]);
467 __gconf->set_string_list(GCONF_PREFIX
"/command_history", l);
471 Gtk::MessageDialog md(*
this,
"The exclusive control over the skiller has " 472 "not been acquired yet and skills cannot be executed",
474 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
476 md.set_title(
"Skill Execution Failure");
484 SkillGuiGtkWindow::on_skiller_data_changed()
487 __skiller_if->
read();
489 switch (__skiller_if->
status()) {
490 case SkillerInterface::S_INACTIVE:
491 #if GTKMM_VERSION_GE(2,20) 494 lab_status->set_text(
"S_INACTIVE");
496 case SkillerInterface::S_FINAL:
497 #if GTKMM_VERSION_GE(2,20) 501 lab_status->set_text(
"S_FINAL");
503 case SkillerInterface::S_RUNNING:
504 #if GTKMM_VERSION_GE(2,20) 507 lab_status->set_text(
"S_RUNNING");
509 case SkillerInterface::S_FAILED:
510 #if GTKMM_VERSION_GE(2,20) 514 lab_status->set_text(
"S_FAILED");
518 lab_skillstring->set_text(__skiller_if->
skill_string());
519 lab_error->set_text(__skiller_if->
error());
520 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12 ) 521 lab_skillstring->set_tooltip_text(__skiller_if->
skill_string());
522 lab_error->set_tooltip_text(__skiller_if->
error());
524 lab_alive->set_text(__skiller_if->
has_writer() ?
"Yes" :
"No");
527 if ( tb_controller->get_stock_id() == Gtk::Stock::NO.id ) {
528 tb_controller->set_stock_id(Gtk::Stock::YES);
529 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12 ) 530 tb_controller->set_tooltip_text(
"Release exclusive control");
533 but_exec->set_sensitive(
true);
534 but_stop->set_sensitive(
true);
536 if ( tb_controller->get_stock_id() == Gtk::Stock::YES.id ) {
537 tb_controller->set_stock_id(Gtk::Stock::NO);
538 #if GTKMM_MAJOR_VERSION > 2 || ( GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12 ) 539 tb_controller->set_tooltip_text(
"Gain exclusive control");
542 but_exec->set_sensitive(
false);
543 but_stop->set_sensitive(
false);
548 #if GTKMM_VERSION_GE(2,20) 556 SkillGuiGtkWindow::on_skdbg_data_changed()
558 if (tb_skiller->get_active() && __skdbg_if) {
562 if (strcmp(__skdbg_if->
graph_fsm(),
"LIST") == 0) {
563 Glib::ustring list = __skdbg_if->
graph();
564 #if GTK_VERSION_GE(3,0) 565 cb_graphlist->remove_all();
566 cb_graphlist->append(ACTIVE_SKILL);
567 cb_graphlist->append(SKILL_DOT);
568 cb_graphlist->append(SKILL_SEP_LINE);
570 cb_graphlist->clear_items();
571 cb_graphlist->append_text(ACTIVE_SKILL);
572 cb_graphlist->append_text(SKILL_DOT);
573 cb_graphlist->append_text(SKILL_SEP_LINE);
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;
624 SkillGuiGtkWindow::on_agdbg_data_changed()
626 if (tb_agent->get_active() && __agdbg_if) {
630 pvp_graph->set_graph_fsm(__agdbg_if->
graph_fsm());
631 pvp_graph->set_graph(__agdbg_if->
graph());
639 case SkillerDebugInterface::GD_TOP_BOTTOM:
640 tb_graphdir->set_stock_id(Gtk::Stock::GO_DOWN);
break;
641 case SkillerDebugInterface::GD_BOTTOM_TOP:
642 tb_graphdir->set_stock_id(Gtk::Stock::GO_UP);
break;
643 case SkillerDebugInterface::GD_LEFT_RIGHT:
644 tb_graphdir->set_stock_id(Gtk::Stock::GO_FORWARD);
break;
645 case SkillerDebugInterface::GD_RIGHT_LEFT:
646 tb_graphdir->set_stock_id(Gtk::Stock::GO_BACK);
break;
656 SkillGuiGtkWindow::on_graphupd_clicked()
659 if ( pvp_graph->get_update_graph() ) {
660 pvp_graph->set_update_graph(
false);
661 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
663 pvp_graph->set_update_graph(
true);
664 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_PLAY);
670 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
673 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_PLAY);
680 SkillGuiGtkWindow::on_graphdir_clicked()
683 if (tb_agent->get_active()) {
687 Glib::ustring stockid = tb_graphdir->get_stock_id();
688 if (stockid == Gtk::Stock::GO_DOWN.
id) {
689 send_graphdir_message(iface, SkillerDebugInterface::GD_BOTTOM_TOP);
690 }
else if (stockid == Gtk::Stock::GO_UP.
id) {
691 send_graphdir_message(iface, SkillerDebugInterface::GD_LEFT_RIGHT);
692 }
else if (stockid == Gtk::Stock::GO_FORWARD.
id) {
693 send_graphdir_message(iface, SkillerDebugInterface::GD_RIGHT_LEFT);
694 }
else if (stockid == Gtk::Stock::GO_BACK.
id) {
695 send_graphdir_message(iface, SkillerDebugInterface::GD_TOP_BOTTOM);
709 throw Exception(
"Not connected to Fawkes.");
712 Gtk::MessageDialog md(*
this,
713 Glib::ustring(
"Setting graph direction failed: ") + e.
what(),
715 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK,
717 md.set_title(
"Communication Failure");
725 if (tb_agent->get_active()) {
726 send_graphdir_message(__agdbg_if, gd);
728 send_graphdir_message(__skdbg_if, gd);
734 SkillGuiGtkWindow::on_graphcolor_toggled()
737 __gconf->set(GCONF_PREFIX
"/graph_colored", tb_graphcolored->get_active());
741 if (tb_agent->get_active()) {
751 throw Exception(
"Not connected to Fawkes.");
768 SkillGuiGtkWindow::SkillStringRecord::SkillStringRecord()
775 SkillGuiGtkWindow::on_update_disabled()
779 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
785 SkillGuiGtkWindow::on_recording_toggled()
789 bool active = tb_graphrecord->get_active();
791 tb_graphrecord->set_active(!active);
char * skill_string() const
Get skill_string value.
SkillerDebugInterface Fawkes BlackBoard Interface.
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
sigc::signal< void > signal_connected()
Get "connected" signal.
void set_graph(std::string graph)
Set graph.
Fawkes library namespace.
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.
char * error() const
Get error value.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
virtual const char * what() const
Get primary string.
uint32_t exclusive_controller() const
Get exclusive_controller value.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
SetGraphMessage Fawkes BlackBoard Interface Message.
~SkillGuiGtkWindow()
Destructor.
bool get_update_graph()
Check if graph is being updated.
bool is_valid() const
Check validity of interface.
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.
GraphDirectionEnum graph_dir() const
Get graph_dir value.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
void zoom_fit()
Zoom to fit.
void zoom_reset()
Zoom reset.
Base class for exceptions in Fawkes.
unsigned short serial() const
Get instance serial of interface.
void read()
Read from BlackBoard into local copy.
GraphDirectionEnum
Primary direction of the graph.
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.
bool has_writer() const
Check if there is a writer for the interface.
iterator begin()
Get iterator for messages.
SkillStatusEnum status() const
Get status value.
ExecSkillMessage Fawkes BlackBoard Interface Message.
SetGraphColoredMessage Fawkes BlackBoard Interface Message.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
void set_network_client(fawkes::FawkesNetworkClient *client)
Set the network client.
const char * get_hostname() const
Get the client's hostname.
SkillerInterface Fawkes BlackBoard Interface.
bool is_graph_colored() const
Get graph_colored value.
char * graph() const
Get graph value.
void open()
Open a dot graph and display it.
bool connected() const
Check if connection is alive.
void zoom_fit()
Zoom to fit.
char * graph_fsm() const
Get graph_fsm value.
void set_client(FawkesNetworkClient *client)
Set FawkesNetworkClient instance.
FawkesNetworkClient * get_client()
Get client.
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.