- 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();
}