diff --git a/src/gui_builder.cc b/src/gui_builder.cc index b583ad0..21e2fe6 100644 --- a/src/gui_builder.cc +++ b/src/gui_builder.cc @@ -262,7 +262,7 @@ GuiBuilder::GuiBuilder(const std::string& gladefile) // Main simulation widget ScrolledWindow* simulation_window = NULL; _refXml->get_widget("SimulationScrolledWindow", simulation_window); - _simulation_widget = new SimulationWidget(); + _simulation_widget = new SimulationWidget(Simulation::get_instance()); SimulationWidget* simulation_widget = manage(_simulation_widget); simulation_window->add(*simulation_widget); simulation_widget->show(); diff --git a/src/simulation_widget.cc b/src/simulation_widget.cc index a5affd9..791b979 100644 --- a/src/simulation_widget.cc +++ b/src/simulation_widget.cc @@ -34,33 +34,49 @@ using namespace sgpem; -SimulationWidget::SimulationWidget() - : Glib::ObjectBase("sgpem_SimulationWidget"), CairoWidget(), - SimulationObserver(), _simulation(0), +SimulationWidget::SimulationWidget(Simulation& simulation) + : Glib::ObjectBase("sgpem_SimulationWidget"), + CairoWidget(), + SimulationObserver(), + HistoryObserver(), + _simulation(&simulation), _x_unit(10), _y_unit(10) { - // Register this observer: - Simulation::get_instance().attach(*this); + // Register this SimulationObserver: + _simulation->attach(*this); + // Register this HistoryObserver: + _simulation->get_history().attach(*this); } SimulationWidget::~SimulationWidget() { - Simulation::get_instance().detach(*this); + // Unregister this HistoryObserver: + _simulation->get_history().detach(*this); + + // Unregister this SimulationObserver: + _simulation->detach(*this); } +#pragma argsused void SimulationWidget::update(const Simulation& changed_simulation) { - _simulation = &changed_simulation; - // Force redraw //redraw(); resize_redraw(); } +#pragma argsused +void +SimulationWidget::update(const History& changed_history) +{ + // Force redraw + //redraw(); + resize_redraw(); +} void SimulationWidget::draw_widget(cairo_t* ctx) @@ -73,7 +89,6 @@ SimulationWidget::draw_widget(cairo_t* ctx) */ - const Simulation& simu = Simulation::get_instance(); double top_margin = _y_unit; double left_margin = _x_unit; double top_graph_margin = 1.0 * _y_unit; //3.0 * _y_unit; @@ -82,8 +97,8 @@ SimulationWidget::draw_widget(cairo_t* ctx) double process_bar_delta = 1.0 * _y_unit; double process_bar_height = 1.0 * _y_unit; double process_height = process_bar_height + 2*process_bar_delta; - Simulation::state sim_state = simu.get_state(); - const History& hist = simu.get_history(); + Simulation::state sim_state = _simulation->get_state(); + const History& hist = _simulation->get_history(); const Environment::Processes& processes = hist.get_last_environment().get_processes(); int nproc = processes.size(); double text_maxw = 0; diff --git a/src/simulation_widget.hh b/src/simulation_widget.hh index 22ab95b..4e26b0c 100644 --- a/src/simulation_widget.hh +++ b/src/simulation_widget.hh @@ -24,16 +24,18 @@ #include "config.h" #include "cairo_widget.hh" +#include "backend/history_observer.hh" #include "backend/simulation_observer.hh" namespace sgpem { - class SimulationWidget : public SimulationObserver, public CairoWidget + class SimulationWidget : public SimulationObserver, public HistoryObserver, public CairoWidget { public: - SimulationWidget(); + SimulationWidget(Simulation& simulation); virtual ~SimulationWidget(); void update(const Simulation& changed_simulation); + void update(const History& changed_history); protected: //virtual bool on_button_press_event(GdkEventButton* event); @@ -46,7 +48,7 @@ namespace sgpem private: int _x_unit; int _y_unit; - const Simulation* _simulation; + Simulation* _simulation; }; } //~ namespace sgpem diff --git a/src/testsuite/test-simulation_widget.cc b/src/testsuite/test-simulation_widget.cc index 6e8f0e6..34be9ac 100644 --- a/src/testsuite/test-simulation_widget.cc +++ b/src/testsuite/test-simulation_widget.cc @@ -405,7 +405,7 @@ TestWidget::change_scaling_mode() class MainWindow : public Gtk::Window { public: - MainWindow(); + MainWindow(Simulation& simulation); virtual ~MainWindow(); protected: @@ -416,7 +416,7 @@ protected: virtual bool on_timer_timeout(); // TestWidget _test_widget; - SimulationWidget _simulation_widget; + SimulationWidget _simulation_widget; Gtk::Button _start_button; Gtk::Button _stop_button; Gtk::Button _pause_button; @@ -428,10 +428,14 @@ protected: }; -MainWindow::MainWindow() : _start_button("Start"), _stop_button("Stop"), - _pause_button("Pause"), _runmode_button("Continue") +MainWindow::MainWindow(Simulation& simulation) +: _start_button("Start"), + _stop_button("Stop"), + _pause_button("Pause"), + _runmode_button("Continue"), + _simulation_widget(simulation), + _sim_state(Simulation::state_stopped) { - _sim_state = Simulation::state_stopped; // This just sets the title of our new window. set_title("Simulation Widget Test"); add(_main_box); @@ -608,7 +612,7 @@ main(int argc, char** argv) info << "END environment dump \n"; info << "simulation state: " << get_simulation_state_name(simu.get_state()) << endl; - MainWindow win; + MainWindow win(simu); win.set_border_width(10); win.resize (400, 200); @@ -671,7 +675,25 @@ void fillHistory(History &hist) Request& req1 = hist.add_request(p1_t1, 3); // add a sub request - Request, resource_key, duration, places - SubRequest& req1_sub1 = hist.add_subrequest(req1, respair.first, 5); + SubRequest& req1_sub1 = hist.add_subrequest(req1, respair.first, 6); + + // add a request - Thread, time + Request& req2 = hist.add_request(p2_t1, 1); + + // add a sub request - Request, resource_key, duration, places + SubRequest& req2_sub1 = hist.add_subrequest(req2, respair.first, 4); + + // add a request - Thread, time + Request& req3 = hist.add_request(p3_t1, 0); + + // add a sub request - Request, resource_key, duration, places + SubRequest& req3_sub1 = hist.add_subrequest(req3, respair.first, 5); + + // add a request - Thread, time + Request& req3bis = hist.add_request(p3_t1, 7); + + // add a sub request - Request, resource_key, duration, places + SubRequest& req3bis_sub1 = hist.add_subrequest(req3bis, respair.first, 5); }