From 240eb23e85b8c1b364f691e7027054712e354b67 Mon Sep 17 00:00:00 2001 From: elvez Date: Tue, 12 Sep 2006 23:17:07 +0000 Subject: [PATCH] - Added a "State" column git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1122 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/schedulables_tree_widget.cc | 116 ++++++++++++++++++++++++++------ src/schedulables_tree_widget.hh | 12 +++- 2 files changed, 106 insertions(+), 22 deletions(-) diff --git a/src/schedulables_tree_widget.cc b/src/schedulables_tree_widget.cc index 6bb2954..af6d319 100644 --- a/src/schedulables_tree_widget.cc +++ b/src/schedulables_tree_widget.cc @@ -62,11 +62,15 @@ SchedulablesTreeWidget::SchedulablesTreeWidget() set_model(_model); - int idx = append_column(_("schedulables"), _cell_renderer) - 1; + int idx = append_column(_("Entities"), _cell_renderer) - 1; Gtk::TreeViewColumn* tvc = get_column(idx); - tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_cell_name_data)); + tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_entities_column_data)); - set_headers_visible(false); + idx = append_column(_("State"), _cell_renderer) - 1; + tvc = get_column(idx); + tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &SchedulablesTreeWidget::_on_state_column_data)); + + set_headers_visible(true); Simulation::get_instance().get_history().attach(*this); } @@ -579,24 +583,9 @@ SchedulablesTreeWidget::_on_remove_request() Simulation::get_instance().get_history().remove(*r); } -//void -//SchedulablesTreeWidget::_on_remove_subrequest() -//{ -// SubRequest* sr = get_selected(); -// assert(sr != NULL); -// -// Request& owner = sr->get_request(); -// -// Simulation::get_instance().get_history().remove(*sr); -// -// // empty requests are COMPLETELY useless with the current GUI -// if(owner.get_subrequests().empty()) -// Simulation::get_instance().get_history().remove(owner); -//} - void -SchedulablesTreeWidget::_on_cell_name_data(Gtk::CellRenderer* cr, - const Gtk::TreeModel::iterator& it) +SchedulablesTreeWidget::_on_entities_column_data(Gtk::CellRenderer* cr, + const Gtk::TreeModel::iterator& it) { CellRendererTextMarkup& crtm = static_cast(*cr); @@ -678,3 +667,90 @@ SchedulablesTreeWidget::markup_request(Request& r) return oss.str(); } +void +SchedulablesTreeWidget::_on_state_column_data(Gtk::CellRenderer* cr, + const Gtk::TreeModel::iterator& it) +{ + CellRendererTextMarkup& crtm = static_cast(*cr); + + ustring marked_up; + + switch(get_row_type(it)) + { + case htype_process: + marked_up = markup_state(get_row_handle_as(it)->get_state()); + break; + + case htype_thread: + marked_up = markup_state(get_row_handle_as(it)->get_state()); + break; + + case htype_request: + marked_up = markup_state(get_row_handle_as(it)->get_state()); + break; + default: + marked_up = "NO STATE"; + } + + crtm.property_markup() = marked_up; +} + +ustring +SchedulablesTreeWidget::markup_state(Schedulable::state state) +{ + ustring text; + + switch (state) + { + case Schedulable::state_running: + text = _("RUNNING"); + break; + case Schedulable::state_ready: + text = _("READY"); + break; + case Schedulable::state_blocked: + text = _("BLOCKED"); + break; + case Schedulable::state_future: + text = _("FUTURE"); + break; + case Schedulable::state_terminated: + text = _("TERMINATED"); + break; + default: + text = _("@@@ ERROR @@@"); + } + + return ustring("") + Markup::escape_text(text) + ""; +} + +ustring +SchedulablesTreeWidget::markup_state(Request::state state) +{ + ustring text; + + switch (state) + { + case Request::state_allocated: + text = _("ALLOCATED"); + break; + case Request::state_allocable: + text = _("ALLOCABLE"); + break; + case Request::state_unallocable: + text = _("UNALLOCABLE"); + break; + case Request::state_future: + text = _("FUTURE"); + break; + case Request::state_exhausted: + text = _("EXHAUSTED"); + break; + default: + text = _("@@@ ERROR @@@"); + } + + return ustring("") + Markup::escape_text(text) + ""; +} + + diff --git a/src/schedulables_tree_widget.hh b/src/schedulables_tree_widget.hh index d4c926d..21ac9c3 100644 --- a/src/schedulables_tree_widget.hh +++ b/src/schedulables_tree_widget.hh @@ -41,6 +41,8 @@ namespace sgpem #include #include +#include +#include #include @@ -104,11 +106,17 @@ namespace sgpem void _on_remove_request(); // void _on_remove_subrequest(); - void _on_cell_name_data(Gtk::CellRenderer* cr, - const Gtk::TreeModel::iterator& it); + void _on_entities_column_data(Gtk::CellRenderer* cr, + const Gtk::TreeModel::iterator& it); + + void _on_state_column_data(Gtk::CellRenderer* cr, + const Gtk::TreeModel::iterator& it); Glib::ustring markup_schedulable(const Schedulable& s); Glib::ustring markup_request(Request& s); + + Glib::ustring markup_state(Schedulable::state state); + Glib::ustring markup_state(Request::state state); Glib::RefPtr _model; Gtk::TreeModelColumnRecord _columns;