- Fixed yellow colours.

- Fixed a bug in scheduler, forgetting to block a thread.
- Added a grid feature to simulation_widget
- Added file->new.



git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1095 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-09-11 21:14:08 +00:00
parent 849a8ff473
commit c4aac86d0a
7 changed files with 80 additions and 20 deletions

View File

@ -42,6 +42,14 @@
<child> <child>
<widget class="GtkMenu" id="MenuItem.File_menu"> <widget class="GtkMenu" id="MenuItem.File_menu">
<child>
<widget class="GtkImageMenuItem" id="MenuItem.File.New">
<property name="visible">True</property>
<property name="label">gtk-new</property>
<property name="use_stock">True</property>
</widget>
</child>
<child> <child>
<widget class="GtkImageMenuItem" id="MenuItem.File.Open"> <widget class="GtkImageMenuItem" id="MenuItem.File.Open">
<property name="visible">True</property> <property name="visible">True</property>

View File

@ -298,6 +298,7 @@ ConcreteHistory::clear()
_snapshots.clear(); _snapshots.clear();
_snapshots.push_back(new ConcreteEnvironment()); _snapshots.push_back(new ConcreteEnvironment());
assert(_snapshots.size() == 1); assert(_snapshots.size() == 1);
notify_change();
} }

View File

@ -344,7 +344,11 @@ determine_subr_allocable_status(const Resource& res, const SubRequestQueue& queu
if (sr.get_state() == Request::state_allocated) if (sr.get_state() == Request::state_allocated)
continue; continue;
if(position_in_queue + 1 > total_places) if(position_in_queue + 1 > total_places)
sr.set_state(Request::state_unallocable); {
sr.set_state(Request::state_unallocable);
// Kludge:
sr.get_request().get_thread().set_state(Schedulable::state_blocked);
}
else else
sr.set_state(Request::state_allocable); sr.set_state(Request::state_allocable);
} //~ for(over subrequest queue) } //~ for(over subrequest queue)

View File

@ -113,6 +113,29 @@ GuiBuilder::on_view_show_holt_graph_activate()
} }
void
GuiBuilder::on_file_new_activate()
{
Simulation& sim = Simulation::get_instance();
History& history = sim.get_history();
const Environment& env = history.get_environment_at(0);
if(!(_filename.empty() && env.get_processes().empty() && env.get_resources().empty()))
{
Gtk::MessageDialog want_to_save(get_initial_window(),
_("<b>Want to save?</b>\nYou'll lose your changes if you don't."),
true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true);
if(want_to_save.run() == Gtk::RESPONSE_YES)
on_file_save_activate();
}
sim.stop();
history.clear();
_filename = "";
}
void void
GuiBuilder::on_file_open_activate() GuiBuilder::on_file_open_activate()
{ {
@ -489,6 +512,15 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
{ {
using namespace Gtk; using namespace Gtk;
// ---------------- Menu items ------------------
// Note: the Play, Pause and Stop menu items are already managed by sgpem::SimulationController.
// file new dialog
MenuItem* file_new = NULL;
_refXml->get_widget("MenuItem.File.New", file_new);
file_new->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_new_activate));
// file open dialog // file open dialog
MenuItem* file_open = NULL; MenuItem* file_open = NULL;
_refXml->get_widget("MenuItem.File.Open", file_open); _refXml->get_widget("MenuItem.File.Open", file_open);
@ -504,11 +536,6 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
_refXml->get_widget("MenuItem.File.SaveAs", file_saveas); _refXml->get_widget("MenuItem.File.SaveAs", file_saveas);
file_saveas->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_saveas_activate)); file_saveas->signal_activate().connect(sigc::mem_fun(*this, &GuiBuilder::on_file_saveas_activate));
// ---------------- Menu items ------------------
// Note: the Play, Pause and Stop menu items are already managed by sgpem::SimulationController.
MenuItem* file_quit = NULL; MenuItem* file_quit = NULL;
_refXml->get_widget("MenuItem.File.Quit", file_quit); _refXml->get_widget("MenuItem.File.Quit", file_quit);
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit)); file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));

View File

@ -51,6 +51,7 @@ namespace sgpem
Gtk::Window& get_initial_window() const; Gtk::Window& get_initial_window() const;
void on_file_new_activate();
void on_file_open_activate(); void on_file_open_activate();
void on_file_save_activate(); void on_file_save_activate();
void on_file_saveas_activate(); void on_file_saveas_activate();

View File

@ -183,7 +183,7 @@ HoltSchedulable::~HoltSchedulable()
void HoltSchedulable::draw(cairo_t *cr) void HoltSchedulable::draw(cairo_t *cr)
{ {
static const Color red(1, 0, 0); static const Color red(1, 0, 0);
static const Color yellow(1, 0.9, 0); static const Color yellow(1, 0.8, 0);
static const Color green(0, 1, 0); static const Color green(0, 1, 0);
@ -284,7 +284,7 @@ void HoltRequest::draw(cairo_t *cr)
break; break;
case Request::state_allocable: case Request::state_allocable:
// yellow // yellow
cairo_set_source_rgb(cr, 1, 1, 0); cairo_set_source_rgb(cr, 1, 0.7, 0);
arrow(cr, schedulable, resource); arrow(cr, schedulable, resource);
break; break;
} }

View File

@ -262,6 +262,7 @@ SimulationWidget::draw_grid(cairo_t* ctx)
// draw last HOR line // draw last HOR line
cairo_move_to(ctx, left_graph_margin, ypos); cairo_move_to(ctx, left_graph_margin, ypos);
cairo_rel_line_to(ctx, graph_width, 0); cairo_rel_line_to(ctx, graph_width, 0);
// - draw left VER line // - draw left VER line
cairo_move_to(ctx, left_graph_margin, top_margin); cairo_move_to(ctx, left_graph_margin, top_margin);
cairo_rel_line_to(ctx, 0, graph_height); cairo_rel_line_to(ctx, 0, graph_height);
@ -271,9 +272,25 @@ SimulationWidget::draw_grid(cairo_t* ctx)
// - draw right VER line // - draw right VER line
cairo_move_to(ctx, left_graph_margin + graph_width, top_margin); cairo_move_to(ctx, left_graph_margin + graph_width, top_margin);
cairo_rel_line_to(ctx, 0, graph_height); cairo_rel_line_to(ctx, 0, graph_height);
} }
cairo_stroke(ctx); cairo_stroke(ctx);
// Draw a vertical line every fifth step
cairo_save(ctx);
cairo_set_line_width(ctx, 0.125 * cairo_get_line_width(ctx));
cairo_set_source_rgb(ctx, 0.3, 0.3, 0.3);
for(double step = 2.0 + _x_unit; step < graph_width - _x_unit; step += 5 * _x_unit)
{
cairo_new_path(ctx);
cairo_move_to(ctx, left_graph_margin + step, top_margin);
cairo_rel_line_to(ctx, 0, graph_height);
cairo_stroke(ctx);
}
cairo_restore(ctx);
// draw and write time line // draw and write time line
cairo_save(ctx); cairo_save(ctx);
cairo_set_source_rgb(ctx, 0, 0, 0); cairo_set_source_rgb(ctx, 0, 0, 0);
@ -332,19 +349,19 @@ SimulationWidget::draw_bars(cairo_t* ctx)
from_time = 1; from_time = 1;
} }
// We draw the interval [0, front)
// so if front <= 1, we've nothing to draw
if(hist_front <= 1)
return;
else
hist_front--;
#ifndef NDEBUG #ifndef NDEBUG
std::cout << " SimulationWidget::draw_bars from:" << from_time << " to:" << hist_front << std::endl; std::cout << " SimulationWidget::draw_bars from:" << from_time << " to:" << hist_front << std::endl;
#endif #endif
for(unsigned int t=from_time; t<=hist_front; t++) for(unsigned int t=from_time; t<=hist_front; t++)
{ {
// We draw the interval [0, front), entirely, and
// the instant "front" as a briefer `pulse'
float width_percent = 1.0f;
if(t == hist_front)
width_percent = 0.1f;
// draw schedulables bars // draw schedulables bars
double xpos = left_graph_margin + t * _x_unit; // left start of first process double xpos = left_graph_margin + t * _x_unit; // left start of first process
double ypos = top_margin; // vertical start of first process double ypos = top_margin; // vertical start of first process
@ -358,7 +375,8 @@ SimulationWidget::draw_bars(cairo_t* ctx)
ypos += process_bar_spacing; // white row before bar ypos += process_bar_spacing; // white row before bar
draw_instant_rect(ctx, xpos, ypos, draw_instant_rect(ctx, xpos, ypos,
_x_unit, process_bar_height, p->get_state()); _x_unit * width_percent, process_bar_height,
p->get_state());
ypos += process_bar_height; // height of process bar ypos += process_bar_height; // height of process bar
if(_show_threads) if(_show_threads)
{ {
@ -369,13 +387,14 @@ SimulationWidget::draw_bars(cairo_t* ctx)
Thread* t = (*thr_iter); Thread* t = (*thr_iter);
thr_iter++; thr_iter++;
draw_instant_rect(ctx, xpos, ypos + thread_bar_spacing, draw_instant_rect(ctx, xpos, ypos + thread_bar_spacing,
_x_unit, thread_bar_height, t->get_state()); _x_unit * width_percent, thread_bar_height, t->get_state());
ypos += thread_height; // height of thread bar ypos += thread_height; // height of thread bar
} // ~ while(thr_iter!=tvect.end()) } // ~ while(thr_iter!=tvect.end())
} // ~ if(_show_threads) } // ~ if(_show_threads)
ypos += process_bar_spacing; // white row after bar ypos += process_bar_spacing; // white row after bar
} // ~ while(proc_iter!=processes.end()) } // ~ while(proc_iter!=processes.end())
} // ~ for(int t=0; t<=hist_front; t++) } // ~ for(int t=0; t<=hist_front; t++)
_last_drawn = hist_front; _last_drawn = hist_front;
_partial_redraw = false; _partial_redraw = false;
} }
@ -493,9 +512,9 @@ SimulationWidget::make_gradients()
_ready_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit); _ready_process_gradient = cairo_pattern_create_linear(0, 0, 0, _yu_process_bar_height * _y_unit);
// yellow // yellow
cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 0.0, 1.00, 0.9, 0.0); cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 0.0, 1.00, 0.7, 0.0);
cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 0.3, 1.00, 1.0, 0.9); cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 0.3, 1.00, 0.9, 0.0);
cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 1.0, 1.00, 0.8, 0.0); cairo_pattern_add_color_stop_rgb(_ready_process_gradient, 1.0, 1.00, 0.7, 0.0);
_running_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);
// green // green