- Now it is possible to edit resources
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@940 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
14f3fd5cbc
commit
57059b647b
|
@ -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;
|
||||
|
|
|
@ -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)
|
|||
" <popup name='PopupMenu'>"
|
||||
" <menuitem action='AddResource'/>";
|
||||
if(get_selected_key(selection))
|
||||
ui_info +=
|
||||
ui_info +=
|
||||
" <separator/>"
|
||||
" <menuitem action='EditResource'/>"
|
||||
" <separator/>"
|
||||
" <menuitem action='RemoveResource'/>";
|
||||
|
||||
|
@ -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<double>(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();
|
||||
|
|
|
@ -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<Gtk::ListStore> _model;
|
||||
|
|
Loading…
Reference in New Issue