25# include "graph_viewport.h"
27# include "graph_drawing_area.h"
30#include <blackboard/remote.h>
31#include <gui_utils/interface_dispatcher.h>
32#include <gui_utils/logview.h>
33#include <gui_utils/plugin_tree_view.h>
34#include <gui_utils/service_chooser_dialog.h>
35#include <netcomm/fawkes/client.h>
36#include <utils/system/argparser.h>
45#define ACTIVE_SKILL "Active Skill"
46#define SKILL_DOT "Skills dot graph"
47#define SKILL_SEP_LINE "----------------"
61 const Glib::RefPtr<Gtk::Builder> &builder)
71 gconf_ = Gnome::Conf::Client::get_default_client();
72 gconf_->add_dir(GCONF_PREFIX);
73 }
catch (Gnome::Conf::Error &e) {
74 std::cerr << e.what() << std::endl;
79 builder->get_widget_derived(
"trv_log", logview_);
80 builder->get_widget(
"tb_connection", tb_connection);
81 builder->get_widget(
"but_clearlog", but_clearlog);
82 builder->get_widget(
"tb_exit", tb_exit);
83 builder->get_widget(
"cbe_skillstring", cbe_skillstring);
84 builder->get_widget(
"but_exec", but_exec);
85 builder->get_widget(
"but_stop", but_stop);
86 builder->get_widget(
"lab_status", lab_status);
87 builder->get_widget(
"lab_alive", lab_alive);
88 builder->get_widget(
"lab_skillstring", lab_skillstring);
89 builder->get_widget(
"lab_error", lab_error);
90 builder->get_widget(
"scw_graph", scw_graph);
92 builder->get_widget(
"ntb_tabs", ntb_tabs);
93 builder->get_widget(
"tb_skiller", tb_skiller);
94 builder->get_widget(
"tb_agent", tb_agent);
95 builder->get_widget(
"tb_graphlist", tb_graphlist);
96 builder->get_widget(
"tb_controller", tb_controller);
97 builder->get_widget(
"tb_graphsave", tb_graphsave);
98 builder->get_widget(
"tb_graphopen", tb_graphopen);
99 builder->get_widget(
"tb_graphupd", tb_graphupd);
100 builder->get_widget(
"tb_graphrecord", tb_graphrecord);
101 builder->get_widget(
"tb_zoomin", tb_zoomin);
102 builder->get_widget(
"tb_zoomout", tb_zoomout);
103 builder->get_widget(
"tb_zoomfit", tb_zoomfit);
104 builder->get_widget(
"tb_zoomreset", tb_zoomreset);
105 builder->get_widget(
"tb_graphdir", tb_graphdir);
106 builder->get_widget(
"tb_graphcolored", tb_graphcolored);
108#if GTKMM_VERSION_GE(2, 20)
109 builder->get_widget(
"tb_spinner", tb_spinner);
111 builder->get_widget_derived(
"trv_plugins", trv_plugins_);
113 Gtk::SeparatorToolItem *spacesep;
114 builder->get_widget(
"tb_spacesep", spacesep);
115 spacesep->set_expand();
118 tb_graphsave->set_homogeneous(
false);
119 tb_graphopen->set_homogeneous(
false);
120 tb_graphupd->set_homogeneous(
false);
121 tb_graphrecord->set_homogeneous(
false);
122 tb_zoomin->set_homogeneous(
false);
123 tb_zoomout->set_homogeneous(
false);
124 tb_zoomfit->set_homogeneous(
false);
125 tb_zoomreset->set_homogeneous(
false);
126 tb_graphdir->set_homogeneous(
false);
127 tb_graphcolored->set_homogeneous(
false);
129#if GTK_VERSION_GE(3, 0)
130 if (!cbe_skillstring->get_has_entry()) {
131 throw Exception(
"Skill string combo box has no entry, invalid UI file?");
134 sks_list_ = Gtk::ListStore::create(sks_record_);
135 cbe_skillstring->set_model(sks_list_);
136#if GTK_VERSION_GE(3, 0)
137 cbe_skillstring->set_entry_text_column(sks_record_.skillstring);
139 cbe_skillstring->set_text_column(sks_record_.skillstring);
142 cbe_skillstring->get_entry()->set_activates_default(
true);
151 scw_graph->add(*pvp_graph);
155 scw_graph->add(*gda);
159 cb_graphlist = Gtk::manage(
new Gtk::ComboBoxText());
160#if GTK_VERSION_GE(3, 0)
161 cb_graphlist->append(ACTIVE_SKILL);
163 cb_graphlist->append_text(ACTIVE_SKILL);
165 cb_graphlist->set_active_text(ACTIVE_SKILL);
166 tb_graphlist->add(*cb_graphlist);
167 cb_graphlist->show();
172 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_connect));
174 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_disconnect));
176 tb_connection->signal_clicked().connect(
177 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_connection_clicked));
178 but_exec->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_exec_clicked));
179 tb_controller->signal_clicked().connect(
180 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_controller_clicked));
181 tb_exit->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_exit_clicked));
182 but_stop->signal_clicked().connect(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_stop_clicked));
183 but_clearlog->signal_clicked().connect(sigc::mem_fun(*logview_, &LogView::clear));
184 tb_skiller->signal_toggled().connect(
185 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skdbg_data_changed));
186 tb_skiller->signal_toggled().connect(
187 sigc::bind(sigc::mem_fun(*cb_graphlist, &Gtk::ComboBoxText::set_sensitive),
true));
188 tb_agent->signal_toggled().connect(
189 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_agdbg_data_changed));
190 tb_agent->signal_toggled().connect(
191 sigc::bind(sigc::mem_fun(*cb_graphlist, &Gtk::ComboBoxText::set_sensitive),
false));
192 cb_graphlist->signal_changed().connect(
193 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skill_changed));
194 tb_graphupd->signal_clicked().connect(
195 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphupd_clicked));
196 tb_graphdir->signal_clicked().connect(
197 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphdir_clicked));
198 tb_graphcolored->signal_toggled().connect(
199 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_graphcolor_toggled));
205 tb_zoomreset->signal_clicked().connect(
213 tb_zoomreset->signal_clicked().connect(
215 tb_graphrecord->signal_clicked().connect(
216 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_recording_toggled));
218 sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_update_disabled));
222 gconf_->signal_value_changed().connect(
223 sigc::hide(sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_config_changed))));
232 gconf_->remove_dir(GCONF_PREFIX);
239SkillGuiGtkWindow::on_config_changed()
242 Gnome::Conf::SListHandle_ValueString l(gconf_->get_string_list(GCONF_PREFIX
"/command_history"));
245 for (Gnome::Conf::SListHandle_ValueString::const_iterator i = l.begin(); i != l.end(); ++i) {
246 Gtk::TreeModel::Row row = *sks_list_->append();
247 row[sks_record_.skillstring] = *i;
250 bool colored = gconf_->get_bool(GCONF_PREFIX
"/graph_colored");
251 tb_graphcolored->set_active(colored);
256SkillGuiGtkWindow::on_skill_changed()
258 Glib::ustring skill = cb_graphlist->get_active_text();
259 if (skill == ACTIVE_SKILL || skill == SKILL_SEP_LINE) {
261 }
else if (skill == SKILL_DOT) {
271SkillGuiGtkWindow::on_connection_clicked()
275 ssd.run_and_connect();
282SkillGuiGtkWindow::on_exit_clicked()
288SkillGuiGtkWindow::on_controller_clicked()
301 Gtk::MessageDialog md(*
this,
302 "Another component already acquired the exclusive "
303 "control for the Skiller; not acquiring exclusive control.",
308 md.set_title(
"Control Acquisition Failed");
314SkillGuiGtkWindow::on_stop_clicked()
323SkillGuiGtkWindow::close_bb()
337 bb->
close(skiller_if_);
338 bb->
close(skdbg_if_);
339 bb->
close(agdbg_if_);
350SkillGuiGtkWindow::on_connect()
358 on_skiller_data_changed();
359 on_skdbg_data_changed();
360 on_agdbg_data_changed();
369 sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skiller_data_changed)));
371 sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_skdbg_data_changed)));
373 sigc::hide(sigc::mem_fun(*
this, &SkillGuiGtkWindow::on_agdbg_data_changed)));
389 tb_connection->set_stock_id(Gtk::Stock::DISCONNECT);
392 tb_controller->set_sensitive(
true);
393 cbe_skillstring->set_sensitive(
true);
395 this->set_title(std::string(
"Skill GUI @ ")
398 Glib::ustring message = *(e.
begin());
399 Gtk::MessageDialog md(*
this,
405 md.set_title(
"BlackBoard connection failed");
415SkillGuiGtkWindow::on_disconnect()
417 tb_controller->set_sensitive(
false);
418 cbe_skillstring->set_sensitive(
false);
419 but_exec->set_sensitive(
false);
420 but_stop->set_sensitive(
false);
424 tb_connection->set_stock_id(Gtk::Stock::CONNECT);
426 pvp_graph->queue_draw();
430 this->set_title(
"Skill GUI");
434SkillGuiGtkWindow::on_exec_clicked()
436 Glib::ustring sks =
"";
437 if (cbe_skillstring->get_active_row_number() == -1) {
438 Gtk::Entry *entry = cbe_skillstring->get_entry();
439 sks = entry->get_text();
441 Gtk::TreeModel::Row row = *cbe_skillstring->get_active();
442#if GTK_VERSION_GE(3, 0)
443 row.get_value(cbe_skillstring->get_entry_text_column(), sks);
445 row.get_value(cbe_skillstring->get_text_column(), sks);
450#if GTKMM_VERSION_GE(2, 20)
459 Gtk::TreeModel::Children children = sks_list_->children();
461 if (!children.empty()) {
463 Gtk::TreeIter i = children.begin();
464 while (ok && (i != children.end())) {
466 i = sks_list_->erase(i);
468 Gtk::TreeModel::Row row = *i;
469 ok = (row[sks_record_.skillstring] != sks);
476 Gtk::TreeModel::Row row = *sks_list_->prepend();
477 row[sks_record_.skillstring] = sks;
479 std::list<Glib::ustring> l;
480 for (Gtk::TreeIter i = children.begin(); i != children.end(); ++i) {
481 Gtk::TreeModel::Row row = *i;
482 l.push_back(row[sks_record_.skillstring]);
486 gconf_->set_string_list(GCONF_PREFIX
"/command_history", l);
490 Gtk::MessageDialog md(*
this,
491 "The exclusive control over the skiller has "
492 "not been acquired yet and skills cannot be executed",
497 md.set_title(
"Skill Execution Failure");
504SkillGuiGtkWindow::on_skiller_data_changed()
509 switch (skiller_if_->
status()) {
510 case SkillerInterface::S_INACTIVE:
511#if GTKMM_VERSION_GE(2, 20)
514 lab_status->set_text(
"S_INACTIVE");
516 case SkillerInterface::S_FINAL:
517#if GTKMM_VERSION_GE(2, 20)
521 lab_status->set_text(
"S_FINAL");
523 case SkillerInterface::S_RUNNING:
524#if GTKMM_VERSION_GE(2, 20)
527 lab_status->set_text(
"S_RUNNING");
529 case SkillerInterface::S_FAILED:
530#if GTKMM_VERSION_GE(2, 20)
534 lab_status->set_text(
"S_FAILED");
539 lab_error->set_text(skiller_if_->
error());
540#if GTKMM_MAJOR_VERSION > 2 || (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12)
541 lab_skillstring->set_tooltip_text(skiller_if_->
skill_string());
542 lab_error->set_tooltip_text(skiller_if_->
error());
544 lab_alive->set_text(skiller_if_->
has_writer() ?
"Yes" :
"No");
547 if (tb_controller->get_stock_id() == Gtk::Stock::NO.id) {
548 tb_controller->set_stock_id(Gtk::Stock::YES);
549#if GTKMM_MAJOR_VERSION > 2 || (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12)
550 tb_controller->set_tooltip_text(
"Release exclusive control");
553 but_exec->set_sensitive(
true);
554 but_stop->set_sensitive(
true);
556 if (tb_controller->get_stock_id() == Gtk::Stock::YES.id) {
557 tb_controller->set_stock_id(Gtk::Stock::NO);
558#if GTKMM_MAJOR_VERSION > 2 || (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12)
559 tb_controller->set_tooltip_text(
"Gain exclusive control");
562 but_exec->set_sensitive(
false);
563 but_stop->set_sensitive(
false);
567#if GTKMM_VERSION_GE(2, 20)
574SkillGuiGtkWindow::on_skdbg_data_changed()
576 if (tb_skiller->get_active() && skdbg_if_) {
580 if (strcmp(skdbg_if_->graph_fsm(),
"LIST") == 0) {
581 Glib::ustring list = skdbg_if_->graph();
582#if GTK_VERSION_GE(3, 0)
583 cb_graphlist->remove_all();
584 cb_graphlist->append(ACTIVE_SKILL);
585 cb_graphlist->append(SKILL_DOT);
586 cb_graphlist->append(SKILL_SEP_LINE);
588 cb_graphlist->clear_items();
589 cb_graphlist->append_text(ACTIVE_SKILL);
590 cb_graphlist->append_text(SKILL_DOT);
591 cb_graphlist->append_text(SKILL_SEP_LINE);
593 cb_graphlist->set_active_text(ACTIVE_SKILL);
594#if GTK_VERSION_GE(2, 14)
595 Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create(
"\n");
596 std::list<std::string> skills = regex->split(list);
597 for (std::list<std::string>::iterator i = skills.begin(); i != skills.end(); ++i) {
598# if GTK_VERSION_GE(3, 0)
600 cb_graphlist->append(*i);
603 cb_graphlist->append_text(*i);
614 pvp_graph->set_graph_fsm(skdbg_if_->graph_fsm());
615 pvp_graph->set_graph(skdbg_if_->graph());
623 switch (skdbg_if_->graph_dir()) {
624 case SkillerDebugInterface::GD_TOP_BOTTOM:
625 tb_graphdir->set_stock_id(Gtk::Stock::GO_DOWN);
627 case SkillerDebugInterface::GD_BOTTOM_TOP:
628 tb_graphdir->set_stock_id(Gtk::Stock::GO_UP);
630 case SkillerDebugInterface::GD_LEFT_RIGHT:
631 tb_graphdir->set_stock_id(Gtk::Stock::GO_FORWARD);
633 case SkillerDebugInterface::GD_RIGHT_LEFT:
634 tb_graphdir->set_stock_id(Gtk::Stock::GO_BACK);
638 if (skdbg_if_->is_graph_colored() != tb_graphcolored->get_active()) {
639 tb_graphcolored->set_active(skdbg_if_->is_graph_colored());
648SkillGuiGtkWindow::on_agdbg_data_changed()
650 if (tb_agent->get_active() && agdbg_if_) {
654 pvp_graph->set_graph_fsm(agdbg_if_->
graph_fsm());
655 pvp_graph->set_graph(agdbg_if_->
graph());
663 case SkillerDebugInterface::GD_TOP_BOTTOM:
664 tb_graphdir->set_stock_id(Gtk::Stock::GO_DOWN);
666 case SkillerDebugInterface::GD_BOTTOM_TOP:
667 tb_graphdir->set_stock_id(Gtk::Stock::GO_UP);
669 case SkillerDebugInterface::GD_LEFT_RIGHT:
670 tb_graphdir->set_stock_id(Gtk::Stock::GO_FORWARD);
672 case SkillerDebugInterface::GD_RIGHT_LEFT:
673 tb_graphdir->set_stock_id(Gtk::Stock::GO_BACK);
683SkillGuiGtkWindow::on_graphupd_clicked()
686 if (pvp_graph->get_update_graph()) {
687 pvp_graph->set_update_graph(
false);
688 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
690 pvp_graph->set_update_graph(
true);
691 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_PLAY);
697 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
700 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_PLAY);
706SkillGuiGtkWindow::on_graphdir_clicked()
709 if (tb_agent->get_active()) {
713 Glib::ustring stockid = tb_graphdir->get_stock_id();
714 if (stockid == Gtk::Stock::GO_DOWN.
id) {
715 send_graphdir_message(iface, SkillerDebugInterface::GD_BOTTOM_TOP);
716 }
else if (stockid == Gtk::Stock::GO_UP.
id) {
717 send_graphdir_message(iface, SkillerDebugInterface::GD_LEFT_RIGHT);
718 }
else if (stockid == Gtk::Stock::GO_FORWARD.
id) {
719 send_graphdir_message(iface, SkillerDebugInterface::GD_RIGHT_LEFT);
720 }
else if (stockid == Gtk::Stock::GO_BACK.
id) {
721 send_graphdir_message(iface, SkillerDebugInterface::GD_TOP_BOTTOM);
735 throw Exception(
"Not connected to Fawkes.");
738 Gtk::MessageDialog md(*
this,
739 Glib::ustring(
"Setting graph direction failed: ") + e.
what(),
744 md.set_title(
"Communication Failure");
752 if (tb_agent->get_active()) {
753 send_graphdir_message(agdbg_if_, gd);
755 send_graphdir_message(skdbg_if_, gd);
760SkillGuiGtkWindow::on_graphcolor_toggled()
763 gconf_->set(GCONF_PREFIX
"/graph_colored", tb_graphcolored->get_active());
767 if (tb_agent->get_active()) {
777 throw Exception(
"Not connected to Fawkes.");
793SkillGuiGtkWindow::SkillStringRecord::SkillStringRecord()
799SkillGuiGtkWindow::on_update_disabled()
803 tb_graphupd->set_stock_id(Gtk::Stock::MEDIA_STOP);
808SkillGuiGtkWindow::on_recording_toggled()
812 bool active = tb_graphrecord->get_active();
814 tb_graphrecord->set_active(!active);
sigc::signal< void > signal_update_disabled()
Get "update disabled" signal.
void set_graph(const std::string &graph)
Set graph.
void open()
Open a dot graph and display it.
bool get_update_graph()
Check if graph is being updated.
void zoom_fit()
Zoom to fit.
void save()
save current graph.
void zoom_reset()
Zoom reset.
void set_update_graph(bool update)
Set if the graph should be updated on new data.
void set_graph_fsm(const std::string &fsm_name)
Set graph's FSM name.
bool set_recording(bool recording)
Enable/disable recording.
Skill FSM Graph Viewport.
void zoom_fit()
Zoom to fit.
void save()
Render current graph.
void zoom_reset()
Zoom reset.
SkillGuiGtkWindow(BaseObjectType *cobject, const Glib::RefPtr< Gtk::Builder > &builder)
Constructor.
~SkillGuiGtkWindow()
Destructor.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
virtual void close(Interface *interface)=0
Close interface.
sigc::signal< void > signal_connected()
Get "connected" signal.
FawkesNetworkClient * get_client()
Get client.
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
Base class for exceptions in Fawkes.
virtual const char * what() const noexcept
Get primary string.
iterator begin() noexcept
Get iterator for messages.
const char * get_hostname() const
Get the client's hostname.
void disconnect()
Disconnect socket.
bool connected() const noexcept
Check if connection is alive.
Interface listener with dispatcher.
sigc::signal< void, Interface * > signal_data_changed()
Get "data changed" signal.
unsigned int msgq_enqueue(Message *message, bool proxy=false)
Enqueue message at end of queue.
Uuid serial() const
Get instance serial of interface.
bool is_valid() const
Check validity of interface.
void read()
Read from BlackBoard into local copy.
bool has_writer() const
Check if there is a writer for the interface.
void set_client(FawkesNetworkClient *client)
Set FawkesNetworkClient instance.
void set_network_client(fawkes::FawkesNetworkClient *client)
Set the network client.
void set_gconf_prefix(Glib::ustring gconf_prefix)
Set Gconf prefix.
SetGraphColoredMessage Fawkes BlackBoard Interface Message.
SetGraphDirectionMessage Fawkes BlackBoard Interface Message.
SetGraphMessage Fawkes BlackBoard Interface Message.
SkillerDebugInterface Fawkes BlackBoard Interface.
GraphDirectionEnum
Primary direction of the graph.
char * graph_fsm() const
Get graph_fsm value.
char * graph() const
Get graph value.
GraphDirectionEnum graph_dir() const
Get graph_dir value.
AcquireControlMessage Fawkes BlackBoard Interface Message.
ExecSkillMessage Fawkes BlackBoard Interface Message.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
StopExecMessage Fawkes BlackBoard Interface Message.
SkillerInterface Fawkes BlackBoard Interface.
char * error() const
Get error value.
SkillStatusEnum status() const
Get status value.
char * skill_string() const
Get skill_string value.
char * exclusive_controller() const
Get exclusive_controller value.
std::string get_string() const
Get the string representation of the Uuid.
Fawkes library namespace.