2006-08-19 02:09:36 +02:00
|
|
|
// src/add_request_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
|
2007-06-30 15:31:19 +02:00
|
|
|
// the Free Software Foundation; either version 3 of the License, or
|
2006-08-19 02:09:36 +02:00
|
|
|
// (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
|
2007-06-30 15:31:19 +02:00
|
|
|
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
2006-08-19 02:09:36 +02:00
|
|
|
|
|
|
|
#include "add_request_dialog.hh"
|
2006-09-07 02:43: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-08-19 02:09:36 +02:00
|
|
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
2006-08-20 19:52:46 +02:00
|
|
|
#include <gtkmm/spinbutton.h>
|
|
|
|
|
2006-09-18 00:26:47 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
2006-08-21 13:58:06 +02:00
|
|
|
#include <cassert>
|
|
|
|
|
2006-08-19 02:09:36 +02:00
|
|
|
using namespace sgpem;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
2006-08-25 02:29:28 +02:00
|
|
|
using std::vector;
|
2006-08-19 02:09:36 +02:00
|
|
|
|
2007-12-05 11:44:09 +01:00
|
|
|
AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Builder>& ui) :
|
|
|
|
Dialog(cobject), _ui(ui)
|
2006-08-19 02:09:36 +02:00
|
|
|
{
|
2007-12-05 11:44:09 +01:00
|
|
|
_ui->get_widget("SubRequests.View", _list);
|
|
|
|
_ui->get_widget("Add", _add_button);
|
|
|
|
_ui->get_widget("Remove", _remove_button);
|
|
|
|
_ui->get_widget("Resource.Combo", _resource_combo);
|
|
|
|
_ui->get_widget("OK.Button", _ok_button);
|
|
|
|
_ui->get_widget("Instant.Spin", _instant_spin);
|
|
|
|
_ui->get_widget("Duration.Spin", _duration_spin);
|
2006-08-25 02:29:28 +02:00
|
|
|
|
2006-08-21 01:17:32 +02:00
|
|
|
|
2006-08-19 02:09:36 +02:00
|
|
|
/** ATTACH SIGNAL HANDLERS FOR BUTTONS **/
|
|
|
|
|
2006-08-21 01:17:32 +02:00
|
|
|
_add_button->signal_clicked().connect(
|
|
|
|
sigc::mem_fun(*this, &AddRequestDialog::_on_add));
|
|
|
|
|
|
|
|
_remove_button->signal_clicked().connect(
|
|
|
|
sigc::mem_fun(*this, &AddRequestDialog::_on_remove));
|
|
|
|
|
|
|
|
_ok_button->set_sensitive(false);
|
|
|
|
_remove_button->set_sensitive(false);
|
|
|
|
_add_button->set_sensitive(false);
|
2006-08-19 02:09:36 +02:00
|
|
|
|
|
|
|
/** INITIALIZE COMBOBOX **/
|
|
|
|
_combo_columns.add(_combo_key_column);
|
|
|
|
_combo_columns.add(_combo_resource_column);
|
|
|
|
|
|
|
|
_combo_model = ListStore::create(_combo_columns);
|
|
|
|
_resource_combo->set_model(_combo_model);
|
2006-08-20 19:52:46 +02:00
|
|
|
_resource_combo->pack_start(_combo_key_column, false);
|
|
|
|
_resource_combo->pack_start(_combo_resource_column, true);
|
2006-08-21 01:17:32 +02:00
|
|
|
|
|
|
|
_resource_combo->signal_changed().connect(
|
|
|
|
sigc::mem_fun(*this, &AddRequestDialog::_on_combo_selection_changed));
|
2006-08-19 02:09:36 +02:00
|
|
|
|
|
|
|
/** INITIALIZE LISTVIEW **/
|
|
|
|
|
2006-08-20 19:52:46 +02:00
|
|
|
_list_columns.add(_list_key_column);
|
2006-08-19 02:09:36 +02:00
|
|
|
_list_columns.add(_list_resource_column);
|
2006-09-13 00:36:25 +02:00
|
|
|
_list_columns.add(_list_duration_column);
|
2006-08-19 02:09:36 +02:00
|
|
|
|
|
|
|
_list_model = ListStore::create(_list_columns);
|
|
|
|
_list->set_model(_list_model);
|
|
|
|
|
2006-08-21 01:17:32 +02:00
|
|
|
_list_model->signal_row_deleted().connect(
|
|
|
|
sigc::mem_fun(*this, &AddRequestDialog::_on_row_removed));
|
|
|
|
|
|
|
|
_list_model->signal_row_inserted().connect(
|
|
|
|
sigc::mem_fun(*this, &AddRequestDialog::_on_row_added));
|
|
|
|
|
2006-08-20 19:52:46 +02:00
|
|
|
_list->append_column(_("key"), _list_key_column);
|
2006-08-19 02:09:36 +02:00
|
|
|
_list->append_column(_("resource"), _list_resource_column);
|
2006-09-13 00:36:25 +02:00
|
|
|
_list->append_column(_("duration"), _list_duration_column);
|
2006-08-20 19:52:46 +02:00
|
|
|
|
|
|
|
_list->get_selection()->signal_changed().connect(
|
2006-08-21 01:17:32 +02:00
|
|
|
sigc::mem_fun(*this, &AddRequestDialog::_on_list_selection_changed));
|
2006-08-19 02:09:36 +02:00
|
|
|
}
|
2006-08-21 01:17:32 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
Request*
|
2006-09-14 22:42:54 +02:00
|
|
|
AddRequestDialog::run_add(sgpem::Thread& owner)
|
2006-08-21 01:17:32 +02:00
|
|
|
{
|
2006-08-25 02:29:28 +02:00
|
|
|
update_combo();
|
2006-08-21 01:17:32 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
Request* r = NULL;
|
2006-08-19 02:09:36 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
// reset the dialog data
|
2006-09-18 00:26:47 +02:00
|
|
|
// _list_model->clear();
|
|
|
|
// _instant_spin->set_value(0.0);
|
|
|
|
// _duration_spin->set_value(0.0);
|
2006-08-21 01:17:32 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
if(run() == RESPONSE_OK)
|
|
|
|
{
|
|
|
|
assert(_list_model->children());
|
|
|
|
|
|
|
|
History& h = Simulation::get_instance().get_history();
|
|
|
|
|
|
|
|
r = &h.add_request(owner, _instant_spin->get_value_as_int());
|
|
|
|
|
|
|
|
TreeNodeChildren sreq_container = _list_model->children();
|
|
|
|
|
|
|
|
for(Iseq<TreeIter> it = iseq(sreq_container); it; ++it)
|
2006-09-13 00:36:25 +02:00
|
|
|
h.add_subrequest(*r, (*it)[_list_key_column], (*it)[_list_duration_column]);
|
2006-08-25 02:29:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hide();
|
2006-08-21 01:17:32 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-08-19 02:09:36 +02:00
|
|
|
void
|
2006-08-25 02:29:28 +02:00
|
|
|
AddRequestDialog::run_edit(Request& request)
|
2006-08-19 02:09:36 +02:00
|
|
|
{
|
2006-08-25 02:29:28 +02:00
|
|
|
update_combo();
|
|
|
|
|
|
|
|
_list_model->clear();
|
|
|
|
|
|
|
|
History& history = Simulation::get_instance().get_history();
|
|
|
|
const Environment::Resources& resources = history.get_last_environment().get_resources();
|
|
|
|
|
|
|
|
_instant_spin->set_value(static_cast<double>(request.get_instant()));
|
2006-08-20 19:52:46 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
// PLEASE KEEP THIS A COPY, WE *NEED* TO COPY IT
|
|
|
|
vector<SubRequest*> subrequests = request.get_subrequests();
|
|
|
|
|
|
|
|
for(Iseq<vector<SubRequest*>::iterator> it = iseq(subrequests); it; ++it)
|
|
|
|
{
|
|
|
|
SubRequest& sr = *(*it);
|
|
|
|
|
|
|
|
TreeModel::Row row = *(_list_model->append());
|
|
|
|
|
|
|
|
unsigned int key = sr.get_resource_key();
|
|
|
|
row[_list_key_column] = key;
|
|
|
|
|
|
|
|
const ustring name = resources.find(key)->second->get_name();
|
|
|
|
row[_list_resource_column] = name;
|
|
|
|
|
2006-09-13 00:36:25 +02:00
|
|
|
row[_list_duration_column] = sr.get_length();
|
2006-08-25 02:29:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(run() == RESPONSE_OK)
|
|
|
|
{
|
|
|
|
assert(_list_model->children());
|
|
|
|
|
2006-09-15 11:34:12 +02:00
|
|
|
History::LockNotify h_lock(history);
|
2006-09-13 21:44:45 +02:00
|
|
|
|
2006-08-25 02:29:28 +02:00
|
|
|
// I know it's a bit hack-ish, but do you know an elegant alternative way?
|
|
|
|
for(Iseq<vector<SubRequest*>::iterator> it = iseq(subrequests); it; ++it)
|
|
|
|
history.remove(*(*it));
|
|
|
|
|
|
|
|
history.edit_request(request, _instant_spin->get_value_as_int());
|
|
|
|
|
|
|
|
TreeNodeChildren sreq_container = _list_model->children();
|
|
|
|
|
|
|
|
for(Iseq<TreeIter> it = iseq(sreq_container); it; ++it)
|
2006-09-13 00:36:25 +02:00
|
|
|
history.add_subrequest(request, (*it)[_list_key_column], (*it)[_list_duration_column]);
|
2006-08-25 02:29:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AddRequestDialog::update_combo()
|
|
|
|
{
|
2006-08-19 02:09:36 +02:00
|
|
|
typedef Environment::Resources::const_iterator ResourceIt;
|
|
|
|
|
|
|
|
const Environment::Resources& resources =
|
|
|
|
Simulation::get_instance().get_history().get_last_environment().get_resources();
|
|
|
|
|
|
|
|
_combo_model->clear();
|
|
|
|
|
2006-09-06 19:39:46 +02:00
|
|
|
for(Iseq<ResourceIt> it = iseq(resources); it; ++it)
|
2006-08-19 02:09:36 +02:00
|
|
|
{
|
|
|
|
TreeModel::Row row = *(_combo_model->append());
|
|
|
|
row[_combo_key_column] = it->first;
|
|
|
|
row[_combo_resource_column] = it->second->get_name();
|
|
|
|
}
|
2006-08-21 01:17:32 +02:00
|
|
|
|
2006-08-20 19:52:46 +02:00
|
|
|
Dialog::on_show();
|
2006-08-19 02:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AddRequestDialog::_on_add()
|
|
|
|
{
|
2006-08-20 19:52:46 +02:00
|
|
|
TreeModel::iterator sel = _resource_combo->get_active();
|
|
|
|
|
2006-08-21 01:17:32 +02:00
|
|
|
TreeModel::Row row = *(_list_model->append());
|
2006-08-20 19:52:46 +02:00
|
|
|
|
2006-08-21 01:17:32 +02:00
|
|
|
const unsigned int key = (*sel)[_combo_key_column];
|
|
|
|
row[_list_key_column] = key;
|
2006-08-20 19:52:46 +02:00
|
|
|
|
2006-08-21 01:17:32 +02:00
|
|
|
const ustring resource = (*sel)[_combo_resource_column];
|
|
|
|
row[_list_resource_column] = resource;
|
|
|
|
|
2006-09-13 00:36:25 +02:00
|
|
|
const unsigned int duration = _duration_spin->get_value_as_int();
|
|
|
|
row[_list_duration_column] = duration;
|
2006-08-19 02:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AddRequestDialog::_on_remove()
|
|
|
|
{
|
2006-08-20 19:52:46 +02:00
|
|
|
TreeModel::iterator it = _list->get_selection()->get_selected();
|
|
|
|
_list_model->erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-08-21 01:17:32 +02:00
|
|
|
AddRequestDialog::_on_list_selection_changed()
|
2006-08-20 19:52:46 +02:00
|
|
|
{
|
|
|
|
_remove_button->set_sensitive(
|
|
|
|
_list->get_selection()->count_selected_rows() > 0);
|
2006-08-19 02:09:36 +02:00
|
|
|
}
|
|
|
|
|
2006-08-21 01:17:32 +02:00
|
|
|
void
|
|
|
|
AddRequestDialog::_on_row_added(const Gtk::TreePath& path, const Gtk::TreeIter& it)
|
|
|
|
{
|
|
|
|
_ok_button->set_sensitive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AddRequestDialog::_on_row_removed(const Gtk::TreePath& path)
|
|
|
|
{
|
|
|
|
_ok_button->set_sensitive(static_cast<bool>(_list_model->children()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AddRequestDialog::_on_combo_selection_changed()
|
|
|
|
{
|
2006-09-18 00:26:47 +02:00
|
|
|
_add_button->set_sensitive(static_cast<bool>(_resource_combo->get_active()));
|
2006-08-21 01:17:32 +02:00
|
|
|
}
|