2006-09-07 04:08:00 +02:00
|
|
|
// src/jump_to_dialog.cc - Copyright 2005, 2006, University
|
|
|
|
// of Padova, dept. of Pure and Applied
|
|
|
|
// Mathematics
|
|
|
|
//
|
|
|
|
// This file is part of SGPEMv2.
|
|
|
|
//
|
|
|
|
// This is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// SGPEMv2 is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with SGPEMv2; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-09-07 11:32:24 +02:00
|
|
|
#include "gettext.h"
|
|
|
|
|
2006-09-07 04:08:00 +02:00
|
|
|
#include "jump_to_dialog.hh"
|
2006-09-07 11:32:24 +02:00
|
|
|
|
2006-09-07 04:08:00 +02:00
|
|
|
#include <sgpemv2/templates/sequences.tcc>
|
|
|
|
#include <sgpemv2/history.hh>
|
|
|
|
#include <sgpemv2/environment.hh>
|
|
|
|
#include <sgpemv2/simulation.hh>
|
|
|
|
#include <sgpemv2/resource.hh>
|
|
|
|
|
2006-09-07 11:32:24 +02:00
|
|
|
#include <gtkmm/main.h>
|
2006-09-07 04:08:00 +02:00
|
|
|
|
2006-09-07 11:32:24 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#include <iostream>
|
|
|
|
#endif
|
2006-09-07 04:08:00 +02:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
using namespace sgpem;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
|
|
|
using Gnome::Glade::Xml;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
JumpToDialog::JumpToDialog(BaseObjectType* cobject, const RefPtr<Xml>& glade) :
|
|
|
|
Dialog(cobject), _glade(glade), _target_instant(0)
|
|
|
|
{
|
|
|
|
_glade->get_widget("OK.Button", _ok_button);
|
|
|
|
_glade->get_widget("Jump.Button", _jump_button);
|
|
|
|
_glade->get_widget("Stop.Button", _stop_button);
|
|
|
|
_glade->get_widget("Instant.Spin", _instant_spin);
|
|
|
|
_glade->get_widget("ProgressBar", _progress);
|
|
|
|
|
|
|
|
|
|
|
|
/** ATTACH SIGNAL HANDLERS FOR BUTTONS **/
|
|
|
|
|
|
|
|
_jump_button->signal_clicked().connect(
|
|
|
|
sigc::mem_fun(*this, &JumpToDialog::_on_jump));
|
|
|
|
|
|
|
|
_stop_button->signal_clicked().connect(
|
|
|
|
sigc::mem_fun(*this, &JumpToDialog::_on_stop));
|
|
|
|
|
2006-09-07 11:32:24 +02:00
|
|
|
_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));
|
|
|
|
|
2006-09-07 04:08:00 +02:00
|
|
|
// FIXME: not implemented
|
|
|
|
_stop_button->set_sensitive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JumpToDialog::_on_jump()
|
|
|
|
{
|
|
|
|
_ok_button->set_sensitive(false);
|
2006-09-07 11:32:24 +02:00
|
|
|
_stop_button->set_sensitive(true);
|
2006-09-07 04:08:00 +02:00
|
|
|
_jump_button->set_sensitive(false);
|
|
|
|
_progress->set_fraction(0.0);
|
|
|
|
|
2006-09-07 11:32:24 +02:00
|
|
|
assert(_instant_spin->get_value_as_int() > 0);
|
2006-09-07 04:08:00 +02:00
|
|
|
_target_instant = _instant_spin->get_value_as_int();
|
|
|
|
|
2006-09-07 11:32:24 +02:00
|
|
|
Simulation& sim = Simulation::get_instance();
|
|
|
|
History& h = sim.get_history();
|
|
|
|
|
|
|
|
sim.attach(*this);
|
2006-09-07 11:56:56 +02:00
|
|
|
bool reenable = h.is_notify_enabled();
|
2006-09-07 11:32:24 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if(_target_instant < h.get_size() - 1)
|
|
|
|
sim.jump_to(_target_instant);
|
|
|
|
else
|
|
|
|
sim.jump_to(h.get_size() - 1);
|
2006-09-07 11:56:56 +02:00
|
|
|
h.set_notify_enabled(false);
|
2006-09-07 11:32:24 +02:00
|
|
|
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!
|
|
|
|
}
|
2006-09-07 11:56:56 +02:00
|
|
|
h.set_notify_enabled(reenable);
|
2006-09-07 11:32:24 +02:00
|
|
|
sim.detach(*this);
|
2006-09-07 04:08:00 +02:00
|
|
|
|
|
|
|
_ok_button->set_sensitive(true);
|
2006-09-07 11:32:24 +02:00
|
|
|
_stop_button->set_sensitive(false);
|
2006-09-07 04:08:00 +02:00
|
|
|
_jump_button->set_sensitive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JumpToDialog::_on_stop()
|
|
|
|
{
|
2006-09-07 11:32:24 +02:00
|
|
|
Simulation::get_instance().stop();
|
2006-09-07 04:08:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JumpToDialog::update(const Simulation& changed_simulation)
|
|
|
|
{
|
|
|
|
unsigned int front = changed_simulation.get_history().get_front();
|
|
|
|
|
|
|
|
double percent = static_cast<double>(front) / _target_instant;
|
|
|
|
|
|
|
|
_progress->set_fraction(percent);
|
2006-09-07 11:32:24 +02:00
|
|
|
|
|
|
|
// 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();
|
2006-09-07 04:08:00 +02:00
|
|
|
}
|