- Modified colors gree, yellow, blue in simulation widget

- modified test-holt_widget accordling



git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1006 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
paolo 2006-09-04 14:23:42 +00:00
parent 5242b37e13
commit c9d9766092
3 changed files with 125 additions and 34 deletions

View File

@ -36,9 +36,9 @@ using namespace sgpem;
SimulationWidget::SimulationWidget(Simulation& simulation)
: Glib::ObjectBase("sgpem_SimulationWidget"),
CairoWidget(),
SimulationObserver(),
HistoryObserver(),
CairoWidget(),
_simulation(&simulation),
_x_unit(10), _y_unit(10),
_n_proc(0), _n_thr(0)
@ -69,24 +69,31 @@ SimulationWidget::SimulationWidget(Simulation& simulation)
_xu_left_graph_margin = 11.0;
/**
* bar spacing in y units
* process bar spacing in y units
*/
_yu_process_bar_spacing = 1.0;
/**
* process bar height in y units
*/
_yu_process_bar_height = 1.0;
_yu_process_bar_height = 2.0;
/**
* thread bar spacing in y units
*/
_yu_thread_bar_spacing = 0.4;
_yu_thread_bar_spacing = 0.5;
/**
* thread bar height in y units
*/
_yu_thread_bar_height = 0.2;
_yu_thread_bar_height = 1.0;
_ready_process_gradient = 0;
_running_process_gradient = 0;
_blocked_process_gradient = 0;
}
@ -100,7 +107,7 @@ SimulationWidget::~SimulationWidget()
}
void
SimulationWidget::update(const Simulation& changed_simulation)
SimulationWidget::update(const Simulation& /* changed_simulation */ )
{
// Force redraw
//count_elements();
@ -108,7 +115,7 @@ SimulationWidget::update(const Simulation& changed_simulation)
}
void
SimulationWidget::update(const History& changed_history)
SimulationWidget::update(const History& /* changed_history */ )
{
// Force redraw
//count_elements();
@ -176,12 +183,12 @@ SimulationWidget::draw_names(cairo_t* ctx)
const History& hist = _simulation->get_history();
const double top_margin = _yu_top_margin * _y_unit;
const double left_margin = _x_unit;
const double left_graph_margin = _xu_left_graph_margin * _x_unit;
// const double left_graph_margin = _xu_left_graph_margin * _x_unit;
const double process_bar_spacing = _yu_process_bar_spacing * _y_unit;
const double process_bar_height = _yu_process_bar_height * _y_unit;
const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit;
const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit;
const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height;
// const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height;
// set a rectangular clip region to cut long names
// - set the rectangle
@ -193,7 +200,7 @@ SimulationWidget::draw_names(cairo_t* ctx)
cairo_clip(ctx);
*/
// draw schedulables names
double ypos = top_margin + _y_unit; // margin + text height
double ypos = top_margin + _y_unit / 2.0; // margin + half of text height
const Environment::Processes& processes = hist.get_last_environment().get_processes();
Environment::Processes::const_iterator proc_iter = processes.begin();
// - draw processes names
@ -201,10 +208,10 @@ SimulationWidget::draw_names(cairo_t* ctx)
{
Process* p = (*proc_iter);
proc_iter++;
ypos += process_bar_spacing; // white row before text
ypos += process_bar_spacing + process_bar_height/2.0; // white row before text
cairo_move_to(ctx, left_margin, ypos);
cairo_show_text(ctx,p->get_name().c_str());
ypos += process_bar_height; // height of process bar
ypos += process_bar_height/2.0; // height of process bar
if(_show_threads)
{
const std::vector<Thread*>& tvect = p->get_threads();
@ -213,9 +220,10 @@ SimulationWidget::draw_names(cairo_t* ctx)
{
Thread* t = (*thr_iter);
thr_iter++;
ypos += thread_height/2.0;
cairo_move_to(ctx, left_margin+_x_unit, ypos);
cairo_show_text(ctx,t->get_name().c_str());
ypos += thread_height; // height of thread bar
ypos += thread_height/2.0; // height of thread bar
} // ~ while(thr_iter!=tvect.end())
} // ~ if(_show_threads)
ypos += process_bar_spacing; // white row after text
@ -232,10 +240,10 @@ SimulationWidget::draw_grid(cairo_t* ctx)
//const int hist_size = hist.get_size();
const unsigned int hist_front = hist.get_front();
const double top_margin = _yu_top_margin * _y_unit;
const double left_margin = _x_unit;
// const double left_margin = _x_unit;
const double left_graph_margin = _xu_left_graph_margin * _x_unit;
const double process_bar_spacing = _yu_process_bar_spacing * _y_unit;
const double process_bar_height = _yu_process_bar_height * _y_unit;
// const double process_bar_spacing = _yu_process_bar_spacing * _y_unit;
// const double process_bar_height = _yu_process_bar_height * _y_unit;
const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit;
const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit;
const double graph_width = (2.0 + hist_front) * _x_unit;
@ -282,7 +290,7 @@ SimulationWidget::draw_grid(cairo_t* ctx)
top_margin + graph_height + 2.0 * _y_unit);
cairo_show_text(ctx,"T");
for(int t=0; t<=hist_front; t++)
for(unsigned int t=0; t<=hist_front; t++)
{
cairo_move_to(ctx, left_graph_margin + (t+1)*_x_unit,
top_margin + graph_height);
@ -307,7 +315,7 @@ SimulationWidget::draw_bars(cairo_t* ctx)
const History& hist = _simulation->get_history();
const unsigned int hist_front = hist.get_front();
const double top_margin = _yu_top_margin * _y_unit;
const double left_margin = _x_unit;
// const double left_margin = _x_unit;
const double left_graph_margin = _xu_left_graph_margin * _x_unit;
const double process_bar_spacing = _yu_process_bar_spacing * _y_unit;
const double process_bar_height = _yu_process_bar_height * _y_unit;
@ -315,11 +323,13 @@ SimulationWidget::draw_bars(cairo_t* ctx)
const double thread_bar_height = _yu_thread_bar_height * _y_unit;
const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit;
const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit;
const double graph_width = (2.0 + hist_front) * _x_unit;
const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height;
// const double graph_width = (2.0 + hist_front) * _x_unit;
// const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height;
for(int t=1; t<=hist_front; t++)
make_gradients();
for(unsigned int t=1; t<=hist_front; t++)
{
// draw schedulables bars
double xpos = left_graph_margin + t * _x_unit; // left start of first process
@ -358,17 +368,52 @@ void
SimulationWidget::draw_instant_rect(cairo_t* ctx, double x, double y,
double w, double h, Schedulable::state state)
{
// _ready_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// _running_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// _blocked_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
cairo_matrix_t matrix;
switch(state)
{
case Schedulable::state_running:
cairo_set_source_rgb(ctx, 0, 1, 0);
// cairo_set_source_rgb(ctx, 0, 1, 0);
cairo_save(ctx);
cairo_set_source(ctx, _running_process_gradient);
// cairo_matrix_init_scale(&matrix, 1.0, y);
// cairo_matrix_translate(&matrix, 0, -y);
cairo_matrix_init_translate(&matrix, 0, -y);
cairo_pattern_set_matrix (_running_process_gradient, &matrix);
cairo_rectangle(ctx, x, y, w, h);
cairo_fill(ctx);
cairo_restore(ctx);
break;
case Schedulable::state_ready:
cairo_set_source_rgb(ctx, 1, 1, 0);
// cairo_set_source_rgb(ctx, 1, 1, 0);
cairo_save(ctx);
cairo_set_source(ctx, _ready_process_gradient);
cairo_matrix_init_translate(&matrix, 0, -y);
// cairo_matrix_scale(&matrix, 1.0, y);
cairo_pattern_set_matrix (_ready_process_gradient, &matrix);
cairo_rectangle(ctx, x, y, w, h);
cairo_fill(ctx);
cairo_restore(ctx);
break;
case Schedulable::state_blocked:
cairo_set_source_rgb(ctx, 1, 0, 0);
// cairo_set_source_rgb(ctx, 1, 0, 0);
cairo_save(ctx);
cairo_set_source(ctx, _blocked_process_gradient);
cairo_matrix_init_translate(&matrix, 0, -y);
cairo_pattern_set_matrix (_blocked_process_gradient, &matrix);
cairo_rectangle(ctx, x, y, w, h);
cairo_fill(ctx);
cairo_restore(ctx);
break;
case Schedulable::state_future:
return; // don't draw
break;
@ -377,8 +422,6 @@ SimulationWidget::draw_instant_rect(cairo_t* ctx, double x, double y,
// cairo_set_source_rgb(ctx, 0, 0, 0);
break;
} // ~ switch(state)
cairo_rectangle(ctx, x, y, w, h);
cairo_fill(ctx);
}
// OLD - START ***************
@ -585,12 +628,12 @@ SimulationWidget::draw_widget(cairo_t* ctx)
void
SimulationWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
{
std::cout << "Simulation widget BEFORE calc_drawing_size width=" << width << " height=" << height << std::endl;
// std::cout << "Simulation widget BEFORE calc_drawing_size width=" << width << " height=" << height << std::endl;
if(!_simulation)
return;
const History& hist = _simulation->get_history();
const Environment::Processes& processes = hist.get_last_environment().get_processes();
// const Environment::Processes& processes = hist.get_last_environment().get_processes();
int pos = _simulation->get_history().get_front();
cairo_text_extents_t extents;
@ -603,14 +646,18 @@ SimulationWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
_y_unit=extents.height;
// left margin, labels, graph
width = (1.0 + 11.0 + 3.0 + pos) * _x_unit;
height = (1.0 + 3.0 * _n_proc + 3.0) * _y_unit;
width = (size_t)((_xu_left_graph_margin + _xu_left_graph_margin + 3.0 + pos) * _x_unit);
// top margin,
height = (size_t)((_yu_top_margin + (_yu_process_bar_spacing*2.0+_yu_process_bar_height) * _n_proc + 3.0) * _y_unit);
if(_show_threads)
height += _n_thr * _y_unit;
height += (size_t) (_n_thr * (_yu_thread_bar_spacing*2.0+_yu_thread_bar_height) * _y_unit);
std::cout << "Simulation widget AFTER calc_drawing_size width=" << width << " height=" << height << std::endl;
// std::cout << "Simulation widget AFTER calc_drawing_size width=" << width << " height=" << height << std::endl;
}
void
SimulationWidget::count_elements()
{
@ -635,3 +682,24 @@ SimulationWidget::count_elements()
std::cout << " _n_proc=" << _n_proc << " _n_thr=" << _n_thr << std::endl;
// count_elements();
}
void
SimulationWidget::make_gradients()
{
_ready_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// yellow
cairo_pattern_add_color_stop_rgba(_ready_process_gradient, 0.00, 1.0, 1.0, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(_ready_process_gradient, 1.00, 1.0, 1.0, 0.0, 1.0);
_running_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// green
cairo_pattern_add_color_stop_rgba(_running_process_gradient, 0.00, 0.5, 1.0, 0.5, 0.7);
cairo_pattern_add_color_stop_rgba(_running_process_gradient, 1.00, 0.0, 1.0, 0.0, 1.0);
_blocked_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// blue
cairo_pattern_add_color_stop_rgba(_blocked_process_gradient, 0.00, 0.5, 0.5, 1.0, 0.7);
cairo_pattern_add_color_stop_rgba(_blocked_process_gradient, 1.00, 0.0, 0.0, 1.0, 1.0);
}

View File

@ -56,16 +56,34 @@ namespace sgpem
void draw_bars(cairo_t* ctx);
void draw_instant_rect(cairo_t* ctx, double x, double y,
double w, double h, sgpem::Schedulable::state state);
void make_gradients();
private:
int _x_unit;
int _y_unit;
Simulation* _simulation;
bool _show_threads;
/**
drawing x unit
*/
double _x_unit;
/**
drawing y unit
*/
double _y_unit;
/**
actual number of processes
*/
int _n_proc;
/**
actual number of threads
*/
int _n_thr;
/**
* top margin in y units
*/
@ -101,6 +119,9 @@ namespace sgpem
*/
double _yu_thread_bar_height;
cairo_pattern_t* _ready_process_gradient;
cairo_pattern_t* _running_process_gradient;
cairo_pattern_t* _blocked_process_gradient;
};
} //~ namespace sgpem

View File

@ -467,7 +467,9 @@ void MainWindow::on_buttons_radio_clicked()
_holt_widget.set_scaling_mode(CairoWidget::scaling_all);
}
_simulation_widget.resize_redraw();
_simulation_widget.set_size_request (20, 20);
_holt_widget.resize_redraw();
_holt_widget.set_size_request (20, 20);
}