- First implementation of a SimulationController in the GUI

that uses a callback to run the simulation in continuous mode.
It isn't finished yet.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@948 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-28 20:15:05 +00:00
parent 1cdd2a6a9e
commit 3689424217
5 changed files with 213 additions and 59 deletions

View file

@ -37,11 +37,9 @@ using namespace sgpem;
using namespace memory;
ConcreteSimulation::ConcreteSimulation() :
_state(state_stopped), _mode(mode_continuous), _policy(NULL)
{
_notify = false;
_front = 0;
}
Simulation(), _state(state_stopped),
_mode(mode_continuous), _policy(NULL)
{}
void
ConcreteSimulation::set_mode(const mode new_mode)
@ -61,16 +59,20 @@ ConcreteSimulation::jump_to(History::position p)
switch (_state)
{
case state_running:
pause();
break;
// pauses the simulation (see below)
break;
case state_stopped:
_history.reset(true);
_front = 0;
break;
default:
;
break;
}
// Disable momentarily updates for registered observers on
// sgpem::Simulation too.
// See History for an example of how to implement this.
set_notify_enabled(false);
pause();
// Disable updates to registered observers
@ -87,6 +89,10 @@ ConcreteSimulation::jump_to(History::position p)
// Reenables updates to registered observers.
// Calls _history.notify_change() on reactivation.
_history.set_notify_enabled(true);
// Do the same for notifications on the state
// of Simulation
set_notify_enabled(true);
}
@ -94,16 +100,20 @@ void
ConcreteSimulation::pause()
{
if(_state != state_paused)
notify_change();
_state = state_paused;
{
_state = state_paused;
notify_change();
}
}
void
ConcreteSimulation::stop()
{
if(_state != state_stopped)
notify_change();
_state = state_stopped;
{
_state = state_stopped;
notify_change();
}
}
void
@ -111,14 +121,12 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
{
switch (_state)
{
case state_running:
return;
case state_stopped:
_history.reset(true);
_front = 0;
break;
default:
;
break;
}
_state = state_running;
@ -126,8 +134,20 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
//step forward
bool yet_to_finish = step();
if (yet_to_finish)
pause();
{
if(_mode == mode_step_by_step)
pause();
else
// We remain in running state, and we notify everybody!
// This is non-trivial, and we must do so since we
// put the state to running inconditionally. Don't
// touch this if you don't provide another way to tell
// a SimulationObserver that the simulation advanced
// and *yet* it is in running state!
notify_change();
}
else
// Simulation ended
stop();
}

View file

@ -35,6 +35,11 @@ using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
template class SG_DLLEXPORT Singleton<ConcreteSimulation>;
Simulation::Simulation()
: _notify(true), _front(0)
{
}
Simulation::~Simulation()
{}
@ -68,7 +73,7 @@ unsigned int Simulation::get_front() const
void
Simulation::notify_change()
{
//if (!_notify) return; // what's the purpose of this?
if (!_notify) return;
for (RegisteredObservers::iterator it = _observers.begin();
it != _observers.end(); it++)

View file

@ -67,9 +67,9 @@ namespace sgpem
public:
enum state
{
state_running,
state_paused,
state_stopped
state_running = 0xdeafd0d0,
state_paused = 0xbaddcafe,
state_stopped = 0xdeadbeef
};
enum mode
@ -78,7 +78,7 @@ namespace sgpem
mode_continuous = 1
};
virtual ~Simulation();
virtual ~Simulation() = 0;
/**
\brief Runs the simulation.
@ -176,13 +176,14 @@ namespace sgpem
RegisteredObservers _observers;
// since no constructor is available, these fields must be defined in concrete subclasses.
bool _notify;
History::position _front;
Simulation(); // Constructor
virtual void notify_change();
private:
bool _notify;
};
}