From 57059b647bca849fa19e0f149f5b70ecfa1c11fe Mon Sep 17 00:00:00 2001 From: elvez Date: Fri, 25 Aug 2006 21:45:29 +0000 Subject: [PATCH] - Now it is possible to edit resources git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@940 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/history.hh | 6 ++++ src/resources_widget.cc | 66 ++++++++++++++++++++++++++++++++++------- src/resources_widget.hh | 3 ++ 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/backend/history.hh b/src/backend/history.hh index f64f17f..b17d88b 100644 --- a/src/backend/history.hh +++ b/src/backend/history.hh @@ -85,6 +85,12 @@ namespace sgpem size_t places = 1, size_t availability = 0) = 0; + virtual void edit_resource(Resource& resource, + const Glib::ustring& name, + bool preemptable = false, + size_t places = 1, + size_t availability = 0) = 0; + virtual Process& add_process(const Glib::ustring& name, time_t arrival_time, prio_t base_priority = 0) = 0; diff --git a/src/resources_widget.cc b/src/resources_widget.cc index 30037ff..c50974e 100644 --- a/src/resources_widget.cc +++ b/src/resources_widget.cc @@ -98,6 +98,9 @@ ResourcesWidget::on_button_press_event(GdkEventButton* event) action_group->add( Gtk::Action::create("AddResource", "Add Resource"), sigc::mem_fun(*this, &ResourcesWidget::_on_add_resource) ); + action_group->add( Gtk::Action::create("EditResource", "Edit Resource"), + sigc::mem_fun(*this, &ResourcesWidget::_on_edit_resource) ); + action_group->add( Gtk::Action::create("RemoveResource", "Remove Resource"), sigc::mem_fun(*this, &ResourcesWidget::_on_remove_resource) ); @@ -110,7 +113,9 @@ ResourcesWidget::on_button_press_event(GdkEventButton* event) " " " "; if(get_selected_key(selection)) - ui_info += + ui_info += + " " + " " " " " "; @@ -152,19 +157,58 @@ ResourcesWidget::update(const History& history) void ResourcesWidget::_on_add_resource() { + add_edit_resource(true); +} + +void +ResourcesWidget::_on_edit_resource() +{ + add_edit_resource(false); +} + +void +ResourcesWidget::add_edit_resource(bool adding) +{ + Entry* name_entry; + SpinButton* places_spin; + + Resource* resource = NULL; + + _add_resource_dialog_glade->get_widget("Name.Entry", name_entry); + _add_resource_dialog_glade->get_widget("Places.Spin", places_spin); + + if(adding) + { + name_entry->set_text(""); + places_spin->set_value(1.0); + } + else + { + const Environment& env = Simulation::get_instance().get_history().get_last_environment(); + unsigned int key; + get_selected_key(key); + resource = env.get_resources().find(key)->second; + + name_entry->set_text(resource->get_name()); + places_spin->set_value(static_cast(resource->get_places())); + } + if(_add_resource_dialog->run() == RESPONSE_OK) { - Entry* name_entry; - SpinButton* places_spin; - SpinButton* availability_spin; - CheckButton* preemptable_check; - - _add_resource_dialog_glade->get_widget("Name.Entry", name_entry); - _add_resource_dialog_glade->get_widget("Places.Spin", places_spin); - Simulation::get_instance().get_history().add_resource(name_entry->get_text(), - false, - places_spin->get_value_as_int()); + if(adding) + { + Simulation::get_instance().get_history().add_resource(name_entry->get_text(), + false, + places_spin->get_value_as_int()); + } + else + { + Simulation::get_instance().get_history().edit_resource(*resource, + name_entry->get_text(), + false, + places_spin->get_value_as_int()); + } } _add_resource_dialog->hide(); diff --git a/src/resources_widget.hh b/src/resources_widget.hh index 188fcfb..b84ad76 100644 --- a/src/resources_widget.hh +++ b/src/resources_widget.hh @@ -54,6 +54,9 @@ namespace sgpem bool get_selected_key(unsigned int& selection); void _on_add_resource(); + void _on_edit_resource(); + void add_edit_resource(bool adding); + void _on_remove_resource(); Glib::RefPtr _model;