- 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

@ -18,17 +18,21 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "gettext.h"
#include "jump_to_dialog.hh"
#include <sgpemv2/templates/sequences.tcc>
#include <sgpemv2/history.hh>
#include <sgpemv2/environment.hh>
#include <sgpemv2/simulation.hh>
#include <sgpemv2/resource.hh>
#include <iostream>
#include <sstream>
#include <gtkmm/main.h>
#include "gettext.h"
#ifndef NDEBUG
#include <iostream>
#endif
#include <cassert>
@ -56,6 +60,11 @@ JumpToDialog::JumpToDialog(BaseObjectType* cobject, const RefPtr<Xml>& glade) :
_stop_button->signal_clicked().connect(
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
_stop_button->set_sensitive(false);
}
@ -64,24 +73,47 @@ void
JumpToDialog::_on_jump()
{
_ok_button->set_sensitive(false);
// _stop_button->set_sensitive(true);
_stop_button->set_sensitive(true);
_jump_button->set_sensitive(false);
_progress->set_fraction(0.0);
assert(_instant_spin->get_value_as_int() > 0);
_target_instant = _instant_spin->get_value_as_int();
Simulation::get_instance().attach(*this);
Simulation::get_instance().jump_to(_target_instant);
Simulation::get_instance().detach(*this);
Simulation& sim = Simulation::get_instance();
History& h = sim.get_history();
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);
// _stop_button->set_sensitive(false);
_stop_button->set_sensitive(false);
_jump_button->set_sensitive(true);
}
void
JumpToDialog::_on_stop()
{
Simulation::get_instance().stop();
}
void
@ -92,4 +124,10 @@ JumpToDialog::update(const Simulation& changed_simulation)
double percent = static_cast<double>(front) / _target_instant;
_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();
}