- Added visualization of resources queue to resourceswidget. Task #28

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@978 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-09-01 00:23:39 +00:00
parent eb9546a63c
commit 58cf50b500
5 changed files with 138 additions and 54 deletions

View File

@ -110,6 +110,46 @@ GlobalPreferences::set_speed(int new_speed)
return old_speed; return old_speed;
} }
Glib::ustring
GlobalPreferences::get_schedulable_color(Schedulable::state st) const
{
switch(st)
{
case Schedulable::state_running:
return "green";
case Schedulable::state_ready:
return "yellow";
case Schedulable::state_blocked:
return "red";
case Schedulable::state_terminated:
return "DimGray";
case Schedulable::state_future:
return "LightGrey";
default:
return "black";
}
}
Glib::ustring
GlobalPreferences::get_request_color(Request::state st) const
{
switch(st)
{
case Request::state_allocated:
return "green";
case Request::state_allocable:
return "yellow";
case Request::state_unallocable:
return "red";
case Request::state_exhausted:
return "DimGray";
case Request::state_future:
return "LightGrey";
default:
return "black";
}
}
void void
GlobalPreferences::write_configrc() GlobalPreferences::write_configrc()
{ {

View File

@ -29,6 +29,8 @@
// Do not include complete template definition here: // Do not include complete template definition here:
#include "singleton.hh" #include "singleton.hh"
#include "schedulable.hh"
#include "request.hh"
namespace sgpem namespace sgpem
{ {
@ -101,6 +103,18 @@ namespace sgpem
*/ */
int set_speed(int new_speed); int set_speed(int new_speed);
/**
\return A HTML color name or hexadecimal code
*/
Glib::ustring get_schedulable_color(Schedulable::state st) const;
/**
\brief Also works with SubRequest::state
\return A HTML color name or hexadecimal code
*/
Glib::ustring get_request_color(Request::state st) const;
/** /**
\brief Writes preferences to disk \brief Writes preferences to disk

View File

@ -26,6 +26,7 @@
#include "backend/process.hh" #include "backend/process.hh"
#include "backend/thread.hh" #include "backend/thread.hh"
#include "backend/request.hh" #include "backend/request.hh"
#include "backend/global_preferences.hh"
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -43,6 +44,12 @@ using namespace Gtk;
using namespace Glib; using namespace Glib;
using Gnome::Glade::Xml; using Gnome::Glade::Xml;
PropertyProxy_Base
ResourcesWidget::CellRendererTextMarkup::_property_renderable()
{
return Glib::PropertyProxy_Base(this, "markup");
}
ResourcesWidget::ResourcesWidget(BaseObjectType* cobject, const RefPtr<Xml>& glade) : ResourcesWidget::ResourcesWidget(BaseObjectType* cobject, const RefPtr<Xml>& glade) :
TreeView(cobject), TreeView(cobject),
_add_resource_dialog_glade(Xml::create(GLADEDIR "/add-resource-dialog.glade")) _add_resource_dialog_glade(Xml::create(GLADEDIR "/add-resource-dialog.glade"))
@ -54,10 +61,9 @@ ResourcesWidget::ResourcesWidget(BaseObjectType* cobject, const RefPtr<Xml>& gla
set_model(_model); set_model(_model);
append_column(_("key"), _key_column); int idx = append_column(_("resources"), _cell_renderer) - 1;
append_column(_("resources"), _main_column); Gtk::TreeViewColumn* tvc = get_column(idx);
//invisible tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &ResourcesWidget::_on_cell_name_data));
// append_column("handles", _handles_column);
/** DIALOGS **/ /** DIALOGS **/
_add_resource_dialog_glade->get_widget("AddResourceDialog", _add_resource_dialog); _add_resource_dialog_glade->get_widget("AddResourceDialog", _add_resource_dialog);
@ -86,6 +92,20 @@ ResourcesWidget::get_selected_key(unsigned int& selection)
return false; return false;
} }
Resource*
ResourcesWidget::get_selected_resource()
{
unsigned int key;
if(get_selected_key(key))
{
Simulation& sim = Simulation::get_instance();
const Environment& env = sim.get_history().get_environment_at(sim.get_front());
return env.get_resources().find(key)->second;
}
else
return NULL;
}
bool bool
ResourcesWidget::on_button_press_event(GdkEventButton* event) ResourcesWidget::on_button_press_event(GdkEventButton* event)
{ {
@ -184,10 +204,7 @@ ResourcesWidget::add_edit_resource(bool adding)
} }
else else
{ {
const Environment& env = Simulation::get_instance().get_history().get_last_environment(); resource = get_selected_resource();
unsigned int key;
get_selected_key(key);
resource = env.get_resources().find(key)->second;
name_entry->set_text(resource->get_name()); name_entry->set_text(resource->get_name());
places_spin->set_value(static_cast<double>(resource->get_places())); places_spin->set_value(static_cast<double>(resource->get_places()));
@ -253,3 +270,39 @@ ResourcesWidget::_on_remove_resource()
to_delete.pop(); to_delete.pop();
} }
} }
void
ResourcesWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
const Gtk::TreeModel::iterator& it)
{
CellRendererTextMarkup& crtm = static_cast<CellRendererTextMarkup&>(*cr);
unsigned int key = (*it)[_key_column];
Simulation& sim = Simulation::get_instance();
const Environment& env = sim.get_history().get_environment_at(sim.get_front());
Resource& resource = *(env.get_resources().find(key)->second);
std::ostringstream oss;
oss << "<small><b>" << resource.get_name() << "</b>\n";
const Environment::SubRequestQueue& queue = env.get_request_queue(key);
for(Iseq<Environment::SubRequestQueue::const_iterator> it = const_iseq(queue); it; ++it)
{
SubRequest& sr = *(*it);
oss << "<span foreground=\""
<< GlobalPreferences::get_instance().get_request_color(sr.get_state())
<< "\"> " << sr.get_request().get_thread().get_name()
<< "</span>" << " ("
<< (sr.get_length() - sr.get_remaining_time())
<< "/" << sr.get_length() << ")";
++index;
}
oss << "</small>";
crtm.property_markup() = oss.str();
}

View File

@ -51,14 +51,25 @@ namespace sgpem
bool on_button_press_event(GdkEventButton* event); bool on_button_press_event(GdkEventButton* event);
private: private:
class CellRendererTextMarkup : public Gtk::CellRendererText
{
public:
Glib::PropertyProxy_Base _property_renderable();
};
bool get_selected_key(unsigned int& selection); bool get_selected_key(unsigned int& selection);
Resource* get_selected_resource();
void _on_add_resource(); void _on_add_resource();
void _on_edit_resource(); void _on_edit_resource();
void add_edit_resource(bool adding); void add_edit_resource(bool adding);
void _on_remove_resource(); void _on_remove_resource();
void _on_cell_name_data(Gtk::CellRenderer* cr,
const Gtk::TreeModel::iterator& it);
Glib::RefPtr<Gtk::ListStore> _model; Glib::RefPtr<Gtk::ListStore> _model;
Gtk::TreeModelColumnRecord _columns; Gtk::TreeModelColumnRecord _columns;
Gtk::TreeModelColumn<unsigned int> _key_column; Gtk::TreeModelColumn<unsigned int> _key_column;
@ -68,6 +79,8 @@ namespace sgpem
Glib::RefPtr<Gtk::UIManager> _UIManager; Glib::RefPtr<Gtk::UIManager> _UIManager;
Glib::RefPtr<Gnome::Glade::Xml> _add_resource_dialog_glade; Glib::RefPtr<Gnome::Glade::Xml> _add_resource_dialog_glade;
Gtk::Dialog* _add_resource_dialog; Gtk::Dialog* _add_resource_dialog;
CellRendererTextMarkup _cell_renderer;
}; };
} //~ namespace sgpem } //~ namespace sgpem

View File

@ -26,6 +26,7 @@
#include "backend/process.hh" #include "backend/process.hh"
#include "backend/thread.hh" #include "backend/thread.hh"
#include "backend/resource.hh" #include "backend/resource.hh"
#include "backend/global_preferences.hh"
#include "add_request_dialog.hh" #include "add_request_dialog.hh"
#include "sequences.tcc" #include "sequences.tcc"
@ -598,46 +599,6 @@ SchedulablesTreeWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
crtm.property_markup() = marked_up; crtm.property_markup() = marked_up;
} }
static Glib::ustring
schedulable_map_color(const Schedulable::state st)
{
switch(st)
{
case Process::state_running:
return "green";
case Process::state_ready:
return "yellow";
case Process::state_blocked:
return "Crimson";
case Process::state_terminated:
return "DimGray";
case Process::state_future:
return "LightGrey";
default:
return "black";
}
}
static Glib::ustring
request_map_color(const Request::state st)
{
switch(st)
{
case Request::state_allocated:
return "green";
case Request::state_allocable:
return "yellow";
case Request::state_unallocable:
return "Crimson";
case Request::state_exhausted:
return "DimGray";
case Request::state_future:
return "LightGrey";
default:
return "black";
}
}
ustring ustring
SchedulablesTreeWidget::markup_schedulable(const Schedulable& s) SchedulablesTreeWidget::markup_schedulable(const Schedulable& s)
{ {
@ -648,8 +609,9 @@ SchedulablesTreeWidget::markup_schedulable(const Schedulable& s)
// TODO : add note for the translator to use HTML-escaped text // TODO : add note for the translator to use HTML-escaped text
// See the gettext manual. // See the gettext manual.
oss << "<small><span foreground=\"" << schedulable_map_color(s.get_state()) << "\"><b>" oss << "<small><span foreground=\""
<< Markup::escape_text(s.get_name()) << "</b></span>" << GlobalPreferences::get_instance().get_schedulable_color(s.get_state())
<< "\"><b>" << Markup::escape_text(s.get_name()) << "</b></span>"
<< _(", arrived at: ") << s.get_arrival_time() << _(", arrived at: ") << s.get_arrival_time()
<< _(", base priority: ") << s.get_base_priority() << _(", base priority: ") << s.get_base_priority()
<< _(", elapsed time: ") << s.get_elapsed_time() << _(", elapsed time: ") << s.get_elapsed_time()
@ -667,8 +629,9 @@ SchedulablesTreeWidget::markup_request(Request& r)
ostringstream oss; ostringstream oss;
oss << "<small><span foreground=\"" << request_map_color(r.get_state()) << "\"><b>" oss << "<small><span foreground=\""
<< _("at ") << r.get_instant() << ":</b></span>"; << GlobalPreferences::get_instance().get_request_color(r.get_state())
<< "\"><b>" << _("at ") << r.get_instant() << ":</b></span>";
const Environment& env = Simulation::get_instance().get_history().get_last_environment(); const Environment& env = Simulation::get_instance().get_history().get_last_environment();
const Environment::Resources& resources = env.get_resources(); const Environment::Resources& resources = env.get_resources();
@ -679,8 +642,9 @@ SchedulablesTreeWidget::markup_request(Request& r)
SubRequest& sr = *(*it); SubRequest& sr = *(*it);
Resource& res = *(resources.find(sr.get_resource_key())->second); Resource& res = *(resources.find(sr.get_resource_key())->second);
oss << "<span foreground=\"" << request_map_color(sr.get_state()) << "\">" oss << "<span foreground=\""
<< " -&gt; </span>" << res.get_name() << " (" << GlobalPreferences::get_instance().get_request_color(sr.get_state())
<< "\"> -&gt; </span>" << res.get_name() << " ("
<< (sr.get_length() - sr.get_remaining_time()) << (sr.get_length() - sr.get_remaining_time())
<< "/" << sr.get_length() << ")"; << "/" << sr.get_length() << ")";
} }