- Fix JumpTo dialog the better I can. Now it should work.

- TODO: manage exceptions both in Simulation::jump_to()
and in JumpToDialog
- TODO: check the semantic of _target_instant, maybe its value
is 1 more than expected?


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1036 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-09-07 09:32:24 +00:00
parent eb0a49eeec
commit 3fe76dad2d
2 changed files with 58 additions and 12 deletions

View File

@ -19,6 +19,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "concrete_simulation.hh" #include "concrete_simulation.hh"
#include <sgpemv2/simulation_observer.hh> #include <sgpemv2/simulation_observer.hh>
#include <sgpemv2/scheduler.hh> #include <sgpemv2/scheduler.hh>
#include <sgpemv2/cpu_policies_gatekeeper.hh> #include <sgpemv2/cpu_policies_gatekeeper.hh>
@ -61,7 +62,7 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
switch (_state) switch (_state)
{ {
case state_running: case state_running:
// pauses the simulation (see below) // pauses the simulation (done below)
break; break;
case state_stopped: case state_stopped:
_history.set_front(0); _history.set_front(0);
@ -72,7 +73,6 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
// Disable momentarily updates for registered observers on // Disable momentarily updates for registered observers on
// sgpem::Simulation too. // sgpem::Simulation too.
// See History for an example of how to implement this.
set_notify_enabled(false); set_notify_enabled(false);
pause(); pause();
@ -82,10 +82,18 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
bool yet_to_finish = true; bool yet_to_finish = true;
History::position increment = 0; History::position increment = 0;
while (yet_to_finish && p > _history.get_front() + increment) while (yet_to_finish && p > _history.get_front() + increment)
{
try
{ {
yet_to_finish = step(); yet_to_finish = step();
increment++; increment++;
} }
catch(...)
{
// FIXME: manage exceptions! Lookout that notifications
// have to be re-enabled.
}
}
get_history().set_front(std::min(p, _history.get_size())); get_history().set_front(std::min(p, _history.get_size()));
if (!yet_to_finish) if (!yet_to_finish)
stop(); stop();

View File

@ -18,17 +18,21 @@
// along with SGPEMv2; if not, write to the Free Software // along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "gettext.h"
#include "jump_to_dialog.hh" #include "jump_to_dialog.hh"
#include <sgpemv2/templates/sequences.tcc> #include <sgpemv2/templates/sequences.tcc>
#include <sgpemv2/history.hh> #include <sgpemv2/history.hh>
#include <sgpemv2/environment.hh> #include <sgpemv2/environment.hh>
#include <sgpemv2/simulation.hh> #include <sgpemv2/simulation.hh>
#include <sgpemv2/resource.hh> #include <sgpemv2/resource.hh>
#include <iostream> #include <gtkmm/main.h>
#include <sstream>
#include "gettext.h" #ifndef NDEBUG
#include <iostream>
#endif
#include <cassert> #include <cassert>
@ -56,6 +60,11 @@ JumpToDialog::JumpToDialog(BaseObjectType* cobject, const RefPtr<Xml>& glade) :
_stop_button->signal_clicked().connect( _stop_button->signal_clicked().connect(
sigc::mem_fun(*this, &JumpToDialog::_on_stop)); sigc::mem_fun(*this, &JumpToDialog::_on_stop));
_ok_button->signal_clicked().connect(sigc::bind(
sigc::mem_fun(*this, &JumpToDialog::response), RESPONSE_OK));
_ok_button->signal_clicked().connect(
sigc::mem_fun(*this, &JumpToDialog::hide));
// FIXME: not implemented // FIXME: not implemented
_stop_button->set_sensitive(false); _stop_button->set_sensitive(false);
} }
@ -64,24 +73,47 @@ void
JumpToDialog::_on_jump() JumpToDialog::_on_jump()
{ {
_ok_button->set_sensitive(false); _ok_button->set_sensitive(false);
// _stop_button->set_sensitive(true); _stop_button->set_sensitive(true);
_jump_button->set_sensitive(false); _jump_button->set_sensitive(false);
_progress->set_fraction(0.0); _progress->set_fraction(0.0);
assert(_instant_spin->get_value_as_int() > 0);
_target_instant = _instant_spin->get_value_as_int(); _target_instant = _instant_spin->get_value_as_int();
Simulation::get_instance().attach(*this); Simulation& sim = Simulation::get_instance();
Simulation::get_instance().jump_to(_target_instant); History& h = sim.get_history();
Simulation::get_instance().detach(*this);
sim.attach(*this);
h.set_notify_enabled(false);
try
{
if(_target_instant < h.get_size() - 1)
sim.jump_to(_target_instant);
else
sim.jump_to(h.get_size() - 1);
while(h.get_front() < _target_instant)
{
sim.run();
if(sim.get_state() == Simulation::state_stopped)
break; // Simulation ended before reaching _target_instant
}
}
catch(...)
{
// FIXME: correctly manage exceptions!
}
h.set_notify_enabled(true);
sim.detach(*this);
_ok_button->set_sensitive(true); _ok_button->set_sensitive(true);
// _stop_button->set_sensitive(false); _stop_button->set_sensitive(false);
_jump_button->set_sensitive(true); _jump_button->set_sensitive(true);
} }
void void
JumpToDialog::_on_stop() JumpToDialog::_on_stop()
{ {
Simulation::get_instance().stop();
} }
void void
@ -92,4 +124,10 @@ JumpToDialog::update(const Simulation& changed_simulation)
double percent = static_cast<double>(front) / _target_instant; double percent = static_cast<double>(front) / _target_instant;
_progress->set_fraction(percent); _progress->set_fraction(percent);
// Needed to force display (else under
// intensive computation it doesn't have
// the time to flush all UI events):
while(Gtk::Main::events_pending())
Gtk::Main::iteration();
} }