- 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:
parent
eb9546a63c
commit
58cf50b500
|
@ -110,6 +110,46 @@ GlobalPreferences::set_speed(int new_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
|
||||
GlobalPreferences::write_configrc()
|
||||
{
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
// Do not include complete template definition here:
|
||||
#include "singleton.hh"
|
||||
#include "schedulable.hh"
|
||||
#include "request.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
@ -101,6 +103,18 @@ namespace sgpem
|
|||
*/
|
||||
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
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "backend/process.hh"
|
||||
#include "backend/thread.hh"
|
||||
#include "backend/request.hh"
|
||||
#include "backend/global_preferences.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
@ -43,6 +44,12 @@ using namespace Gtk;
|
|||
using namespace Glib;
|
||||
using Gnome::Glade::Xml;
|
||||
|
||||
PropertyProxy_Base
|
||||
ResourcesWidget::CellRendererTextMarkup::_property_renderable()
|
||||
{
|
||||
return Glib::PropertyProxy_Base(this, "markup");
|
||||
}
|
||||
|
||||
ResourcesWidget::ResourcesWidget(BaseObjectType* cobject, const RefPtr<Xml>& glade) :
|
||||
TreeView(cobject),
|
||||
_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);
|
||||
|
||||
append_column(_("key"), _key_column);
|
||||
append_column(_("resources"), _main_column);
|
||||
//invisible
|
||||
// append_column("handles", _handles_column);
|
||||
int idx = append_column(_("resources"), _cell_renderer) - 1;
|
||||
Gtk::TreeViewColumn* tvc = get_column(idx);
|
||||
tvc->set_cell_data_func(_cell_renderer, sigc::mem_fun(*this, &ResourcesWidget::_on_cell_name_data));
|
||||
|
||||
/** DIALOGS **/
|
||||
_add_resource_dialog_glade->get_widget("AddResourceDialog", _add_resource_dialog);
|
||||
|
@ -86,6 +92,20 @@ ResourcesWidget::get_selected_key(unsigned int& selection)
|
|||
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
|
||||
ResourcesWidget::on_button_press_event(GdkEventButton* event)
|
||||
{
|
||||
|
@ -184,10 +204,7 @@ ResourcesWidget::add_edit_resource(bool adding)
|
|||
}
|
||||
else
|
||||
{
|
||||
const Environment& env = Simulation::get_instance().get_history().get_last_environment();
|
||||
unsigned int key;
|
||||
get_selected_key(key);
|
||||
resource = env.get_resources().find(key)->second;
|
||||
resource = get_selected_resource();
|
||||
|
||||
name_entry->set_text(resource->get_name());
|
||||
places_spin->set_value(static_cast<double>(resource->get_places()));
|
||||
|
@ -253,3 +270,39 @@ ResourcesWidget::_on_remove_resource()
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,15 @@ namespace sgpem
|
|||
bool on_button_press_event(GdkEventButton* event);
|
||||
|
||||
private:
|
||||
class CellRendererTextMarkup : public Gtk::CellRendererText
|
||||
{
|
||||
public:
|
||||
Glib::PropertyProxy_Base _property_renderable();
|
||||
};
|
||||
|
||||
bool get_selected_key(unsigned int& selection);
|
||||
|
||||
Resource* get_selected_resource();
|
||||
|
||||
void _on_add_resource();
|
||||
void _on_edit_resource();
|
||||
|
@ -59,6 +67,9 @@ namespace sgpem
|
|||
|
||||
void _on_remove_resource();
|
||||
|
||||
void _on_cell_name_data(Gtk::CellRenderer* cr,
|
||||
const Gtk::TreeModel::iterator& it);
|
||||
|
||||
Glib::RefPtr<Gtk::ListStore> _model;
|
||||
Gtk::TreeModelColumnRecord _columns;
|
||||
Gtk::TreeModelColumn<unsigned int> _key_column;
|
||||
|
@ -68,6 +79,8 @@ namespace sgpem
|
|||
Glib::RefPtr<Gtk::UIManager> _UIManager;
|
||||
Glib::RefPtr<Gnome::Glade::Xml> _add_resource_dialog_glade;
|
||||
Gtk::Dialog* _add_resource_dialog;
|
||||
|
||||
CellRendererTextMarkup _cell_renderer;
|
||||
};
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "backend/process.hh"
|
||||
#include "backend/thread.hh"
|
||||
#include "backend/resource.hh"
|
||||
#include "backend/global_preferences.hh"
|
||||
#include "add_request_dialog.hh"
|
||||
|
||||
#include "sequences.tcc"
|
||||
|
@ -598,46 +599,6 @@ SchedulablesTreeWidget::_on_cell_name_data(Gtk::CellRenderer* cr,
|
|||
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
|
||||
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
|
||||
// See the gettext manual.
|
||||
oss << "<small><span foreground=\"" << schedulable_map_color(s.get_state()) << "\"><b>"
|
||||
<< Markup::escape_text(s.get_name()) << "</b></span>"
|
||||
oss << "<small><span foreground=\""
|
||||
<< GlobalPreferences::get_instance().get_schedulable_color(s.get_state())
|
||||
<< "\"><b>" << Markup::escape_text(s.get_name()) << "</b></span>"
|
||||
<< _(", arrived at: ") << s.get_arrival_time()
|
||||
<< _(", base priority: ") << s.get_base_priority()
|
||||
<< _(", elapsed time: ") << s.get_elapsed_time()
|
||||
|
@ -667,8 +629,9 @@ SchedulablesTreeWidget::markup_request(Request& r)
|
|||
|
||||
ostringstream oss;
|
||||
|
||||
oss << "<small><span foreground=\"" << request_map_color(r.get_state()) << "\"><b>"
|
||||
<< _("at ") << r.get_instant() << ":</b></span>";
|
||||
oss << "<small><span foreground=\""
|
||||
<< 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::Resources& resources = env.get_resources();
|
||||
|
@ -679,8 +642,9 @@ SchedulablesTreeWidget::markup_request(Request& r)
|
|||
SubRequest& sr = *(*it);
|
||||
Resource& res = *(resources.find(sr.get_resource_key())->second);
|
||||
|
||||
oss << "<span foreground=\"" << request_map_color(sr.get_state()) << "\">"
|
||||
<< " -> </span>" << res.get_name() << " ("
|
||||
oss << "<span foreground=\""
|
||||
<< GlobalPreferences::get_instance().get_request_color(sr.get_state())
|
||||
<< "\"> -> </span>" << res.get_name() << " ("
|
||||
<< (sr.get_length() - sr.get_remaining_time())
|
||||
<< "/" << sr.get_length() << ")";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue