- updated simulation_widget
- now hinerith from SimulationObserver and HistoryObserver - updated gui_builder and test-simulation_widget accordling git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@925 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
2a408b82af
commit
ba00eac7f0
|
@ -262,7 +262,7 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
// Main simulation widget
|
// Main simulation widget
|
||||||
ScrolledWindow* simulation_window = NULL;
|
ScrolledWindow* simulation_window = NULL;
|
||||||
_refXml->get_widget("SimulationScrolledWindow", simulation_window);
|
_refXml->get_widget("SimulationScrolledWindow", simulation_window);
|
||||||
_simulation_widget = new SimulationWidget();
|
_simulation_widget = new SimulationWidget(Simulation::get_instance());
|
||||||
SimulationWidget* simulation_widget = manage(_simulation_widget);
|
SimulationWidget* simulation_widget = manage(_simulation_widget);
|
||||||
simulation_window->add(*simulation_widget);
|
simulation_window->add(*simulation_widget);
|
||||||
simulation_widget->show();
|
simulation_widget->show();
|
||||||
|
|
|
@ -34,33 +34,49 @@
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
SimulationWidget::SimulationWidget()
|
SimulationWidget::SimulationWidget(Simulation& simulation)
|
||||||
: Glib::ObjectBase("sgpem_SimulationWidget"), CairoWidget(),
|
: Glib::ObjectBase("sgpem_SimulationWidget"),
|
||||||
SimulationObserver(), _simulation(0),
|
CairoWidget(),
|
||||||
|
SimulationObserver(),
|
||||||
|
HistoryObserver(),
|
||||||
|
_simulation(&simulation),
|
||||||
_x_unit(10), _y_unit(10)
|
_x_unit(10), _y_unit(10)
|
||||||
|
|
||||||
{
|
{
|
||||||
// Register this observer:
|
// Register this SimulationObserver:
|
||||||
Simulation::get_instance().attach(*this);
|
_simulation->attach(*this);
|
||||||
|
|
||||||
|
// Register this HistoryObserver:
|
||||||
|
_simulation->get_history().attach(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SimulationWidget::~SimulationWidget()
|
SimulationWidget::~SimulationWidget()
|
||||||
{
|
{
|
||||||
Simulation::get_instance().detach(*this);
|
// Unregister this HistoryObserver:
|
||||||
|
_simulation->get_history().detach(*this);
|
||||||
|
|
||||||
|
// Unregister this SimulationObserver:
|
||||||
|
_simulation->detach(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma argsused
|
||||||
void
|
void
|
||||||
SimulationWidget::update(const Simulation& changed_simulation)
|
SimulationWidget::update(const Simulation& changed_simulation)
|
||||||
{
|
{
|
||||||
_simulation = &changed_simulation;
|
|
||||||
|
|
||||||
// Force redraw
|
// Force redraw
|
||||||
//redraw();
|
//redraw();
|
||||||
resize_redraw();
|
resize_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma argsused
|
||||||
|
void
|
||||||
|
SimulationWidget::update(const History& changed_history)
|
||||||
|
{
|
||||||
|
// Force redraw
|
||||||
|
//redraw();
|
||||||
|
resize_redraw();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SimulationWidget::draw_widget(cairo_t* ctx)
|
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 top_margin = _y_unit;
|
||||||
double left_margin = _x_unit;
|
double left_margin = _x_unit;
|
||||||
double top_graph_margin = 1.0 * _y_unit; //3.0 * _y_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_delta = 1.0 * _y_unit;
|
||||||
double process_bar_height = 1.0 * _y_unit;
|
double process_bar_height = 1.0 * _y_unit;
|
||||||
double process_height = process_bar_height + 2*process_bar_delta;
|
double process_height = process_bar_height + 2*process_bar_delta;
|
||||||
Simulation::state sim_state = simu.get_state();
|
Simulation::state sim_state = _simulation->get_state();
|
||||||
const History& hist = simu.get_history();
|
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 nproc = processes.size();
|
int nproc = processes.size();
|
||||||
double text_maxw = 0;
|
double text_maxw = 0;
|
||||||
|
|
|
@ -24,16 +24,18 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "cairo_widget.hh"
|
#include "cairo_widget.hh"
|
||||||
|
#include "backend/history_observer.hh"
|
||||||
#include "backend/simulation_observer.hh"
|
#include "backend/simulation_observer.hh"
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
class SimulationWidget : public SimulationObserver, public CairoWidget
|
class SimulationWidget : public SimulationObserver, public HistoryObserver, public CairoWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SimulationWidget();
|
SimulationWidget(Simulation& simulation);
|
||||||
virtual ~SimulationWidget();
|
virtual ~SimulationWidget();
|
||||||
void update(const Simulation& changed_simulation);
|
void update(const Simulation& changed_simulation);
|
||||||
|
void update(const History& changed_history);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//virtual bool on_button_press_event(GdkEventButton* event);
|
//virtual bool on_button_press_event(GdkEventButton* event);
|
||||||
|
@ -46,7 +48,7 @@ namespace sgpem
|
||||||
private:
|
private:
|
||||||
int _x_unit;
|
int _x_unit;
|
||||||
int _y_unit;
|
int _y_unit;
|
||||||
const Simulation* _simulation;
|
Simulation* _simulation;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //~ namespace sgpem
|
} //~ namespace sgpem
|
||||||
|
|
|
@ -405,7 +405,7 @@ TestWidget::change_scaling_mode()
|
||||||
class MainWindow : public Gtk::Window
|
class MainWindow : public Gtk::Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MainWindow();
|
MainWindow(Simulation& simulation);
|
||||||
virtual ~MainWindow();
|
virtual ~MainWindow();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -428,10 +428,14 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow() : _start_button("Start"), _stop_button("Stop"),
|
MainWindow::MainWindow(Simulation& simulation)
|
||||||
_pause_button("Pause"), _runmode_button("Continue")
|
: _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.
|
// This just sets the title of our new window.
|
||||||
set_title("Simulation Widget Test");
|
set_title("Simulation Widget Test");
|
||||||
add(_main_box);
|
add(_main_box);
|
||||||
|
@ -608,7 +612,7 @@ main(int argc, char** argv)
|
||||||
info << "END environment dump \n";
|
info << "END environment dump \n";
|
||||||
info << "simulation state: " << get_simulation_state_name(simu.get_state()) << endl;
|
info << "simulation state: " << get_simulation_state_name(simu.get_state()) << endl;
|
||||||
|
|
||||||
MainWindow win;
|
MainWindow win(simu);
|
||||||
|
|
||||||
win.set_border_width(10);
|
win.set_border_width(10);
|
||||||
win.resize (400, 200);
|
win.resize (400, 200);
|
||||||
|
@ -671,7 +675,25 @@ void fillHistory(History &hist)
|
||||||
Request& req1 = hist.add_request(p1_t1, 3);
|
Request& req1 = hist.add_request(p1_t1, 3);
|
||||||
|
|
||||||
// add a sub request - Request, resource_key, duration, places
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue