- Now resources can be removed

- Little patch to ConcreteHistory to make it remove emptied requests after a resource removal. I hope this will not break anything...

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@926 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-21 22:01:31 +00:00
parent ba00eac7f0
commit 82b4105519
5 changed files with 380 additions and 253 deletions

View File

@ -1,218 +1,320 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<!-- Generated with glade3
Version: 3.0.0
Date: Mon Aug 21 14:07:19 2006
User: matteo
Host: tulip
-->
<glade-interface> <glade-interface>
<widget class="GtkDialog" id="AddRequestDialog">
<property name="width_request">300</property> <widget class="GtkDialog" id="AddRequestDialog">
<property name="height_request">240</property> <property name="width_request">300</property>
<property name="title">Add Request</property> <property name="height_request">240</property>
<property name="modal">True</property> <property name="title">Add Request</property>
<property name="window_position">GTK_WIN_POS_MOUSE</property> <property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> <property name="window_position">GTK_WIN_POS_MOUSE</property>
<child internal-child="vbox"> <property name="modal">True</property>
<widget class="GtkVBox" id="MainVBox"> <property name="resizable">True</property>
<property name="visible">True</property> <property name="destroy_with_parent">False</property>
<child> <property name="decorated">True</property>
<widget class="GtkVBox" id="InputArea"> <property name="skip_taskbar_hint">False</property>
<property name="visible">True</property> <property name="skip_pager_hint">False</property>
<property name="border_width">4</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="spacing">6</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<child> <property name="focus_on_map">True</property>
<widget class="GtkHBox" id="Instant.Box"> <property name="urgency_hint">False</property>
<property name="visible">True</property> <property name="has_separator">True</property>
<property name="spacing">6</property>
<child> <child internal-child="vbox">
<widget class="GtkLabel" id="Instant.Label"> <widget class="GtkVBox" id="MainVBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0,000000</property> <property name="homogeneous">False</property>
<property name="yalign">0,000000</property> <property name="spacing">0</property>
<property name="label" translatable="yes">Instant</property>
</widget> <child internal-child="action_area">
<packing> <widget class="GtkHButtonBox" id="MainButtonBox">
<property name="expand">False</property> <property name="visible">True</property>
<property name="fill">False</property> <property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
</packing>
</child> <child>
<child> <widget class="GtkButton" id="Cancel.Button">
<widget class="GtkSpinButton" id="Instant.Spin"> <property name="visible">True</property>
<property name="visible">True</property> <property name="can_default">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="adjustment">0,000000 0,000000 0,000000 1,000000 0,000000 0,000000</property> <property name="label">gtk-cancel</property>
<property name="climb_rate">1</property> <property name="use_stock">True</property>
<property name="numeric">True</property> <property name="relief">GTK_RELIEF_NORMAL</property>
</widget> <property name="focus_on_click">True</property>
<packing> <property name="response_id">-6</property>
<property name="position">1</property> </widget>
</packing> </child>
</child>
</widget> <child>
<packing> <widget class="GtkButton" id="OK.Button">
<property name="expand">False</property> <property name="visible">True</property>
<property name="fill">False</property> <property name="can_default">True</property>
</packing> <property name="has_default">True</property>
</child> <property name="can_focus">True</property>
<child> <property name="label">gtk-ok</property>
<widget class="GtkScrolledWindow" id="SubRequests"> <property name="use_stock">True</property>
<property name="height_request">200</property> <property name="relief">GTK_RELIEF_NORMAL</property>
<property name="visible">True</property> <property name="focus_on_click">True</property>
<property name="can_focus">True</property> <property name="response_id">-5</property>
<property name="hscrollbar_policy">GTK_POLICY_NEVER</property> </widget>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> </child>
<property name="shadow_type">GTK_SHADOW_IN</property> </widget>
<child> <packing>
<widget class="GtkTreeView" id="SubRequests.View"> <property name="padding">0</property>
<property name="height_request">100</property> <property name="expand">False</property>
<property name="visible">True</property> <property name="fill">True</property>
<property name="can_focus">True</property> <property name="pack_type">GTK_PACK_END</property>
<property name="reorderable">True</property> </packing>
</widget> </child>
</child>
</widget> <child>
<packing> <widget class="GtkVBox" id="InputArea">
<property name="position">1</property> <property name="border_width">4</property>
</packing> <property name="visible">True</property>
</child> <property name="homogeneous">False</property>
<child> <property name="spacing">6</property>
<widget class="GtkTable" id="SubRequestInput">
<property name="visible">True</property> <child>
<property name="n_rows">2</property> <widget class="GtkHBox" id="Instant.Box">
<property name="n_columns">2</property> <property name="visible">True</property>
<property name="column_spacing">6</property> <property name="homogeneous">False</property>
<property name="row_spacing">6</property> <property name="spacing">6</property>
<child>
<widget class="GtkLabel" id="Duration.Label"> <child>
<property name="visible">True</property> <widget class="GtkLabel" id="Instant.Label">
<property name="xalign">0,000000</property> <property name="visible">True</property>
<property name="yalign">0,000000</property> <property name="label" translatable="yes">Instant</property>
<property name="label" translatable="yes">Duration</property> <property name="use_underline">False</property>
</widget> <property name="use_markup">False</property>
<packing> <property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="top_attach">1</property> <property name="wrap">False</property>
<property name="bottom_attach">2</property> <property name="selectable">False</property>
<property name="x_options"></property> <property name="xalign">0</property>
<property name="y_options"></property> <property name="yalign">0</property>
</packing> <property name="xpad">0</property>
</child> <property name="ypad">0</property>
<child> <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<widget class="GtkLabel" id="Resource.Label"> <property name="width_chars">-1</property>
<property name="visible">True</property> <property name="single_line_mode">False</property>
<property name="xalign">0,000000</property> <property name="angle">0</property>
<property name="yalign">0,000000</property> </widget>
<property name="label" translatable="yes">Resource</property> <packing>
</widget> <property name="padding">0</property>
<packing> <property name="expand">False</property>
<property name="x_options"></property> <property name="fill">False</property>
<property name="y_options"></property> </packing>
</packing> </child>
</child>
<child> <child>
<widget class="GtkSpinButton" id="Duration.Spin"> <widget class="GtkSpinButton" id="Instant.Spin">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="adjustment">0,000000 1,000000 0,000000 1,000000 0,000000 0,000000</property> <property name="climb_rate">1</property>
<property name="climb_rate">1</property> <property name="digits">0</property>
<property name="numeric">True</property> <property name="numeric">True</property>
</widget> <property name="update_policy">GTK_UPDATE_ALWAYS</property>
<packing> <property name="snap_to_ticks">False</property>
<property name="left_attach">1</property> <property name="wrap">False</property>
<property name="right_attach">2</property> <property name="adjustment">0 0 inf 1 0 0</property>
<property name="top_attach">1</property> </widget>
<property name="bottom_attach">2</property> <packing>
<property name="y_options"></property> <property name="padding">0</property>
</packing> <property name="expand">True</property>
</child> <property name="fill">True</property>
<child> </packing>
<widget class="GtkComboBox" id="Resource.Combo"> </child>
<property name="visible">True</property> </widget>
</widget> <packing>
<packing> <property name="padding">0</property>
<property name="left_attach">1</property> <property name="expand">False</property>
<property name="right_attach">2</property> <property name="fill">False</property>
<property name="x_options"></property> </packing>
<property name="y_options"></property> </child>
</packing>
</child> <child>
</widget> <widget class="GtkScrolledWindow" id="SubRequests">
<packing> <property name="height_request">200</property>
<property name="expand">False</property> <property name="visible">True</property>
<property name="fill">False</property> <property name="can_focus">True</property>
<property name="position">2</property> <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
</packing> <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
</child> <property name="shadow_type">GTK_SHADOW_IN</property>
<child> <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<widget class="GtkHButtonBox" id="AddRemoveButtons">
<property name="visible">True</property> <child>
<property name="border_width">6</property> <widget class="GtkTreeView" id="SubRequests.View">
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property> <property name="height_request">100</property>
<child> <property name="visible">True</property>
<widget class="GtkButton" id="Add"> <property name="can_focus">True</property>
<property name="visible">True</property> <property name="headers_visible">True</property>
<property name="can_default">True</property> <property name="rules_hint">False</property>
<property name="label" translatable="yes">gtk-add</property> <property name="reorderable">True</property>
<property name="use_stock">True</property> <property name="enable_search">True</property>
</widget> <property name="fixed_height_mode">False</property>
</child> <property name="hover_selection">False</property>
<child> <property name="hover_expand">False</property>
<widget class="GtkButton" id="Remove"> </widget>
<property name="visible">True</property> </child>
<property name="label" translatable="yes">gtk-remove</property> </widget>
<property name="use_stock">True</property> <packing>
</widget> <property name="padding">0</property>
<packing> <property name="expand">True</property>
<property name="position">1</property> <property name="fill">True</property>
</packing> </packing>
</child> </child>
</widget>
<packing> <child>
<property name="expand">False</property> <widget class="GtkTable" id="SubRequestInput">
<property name="position">3</property> <property name="visible">True</property>
</packing> <property name="n_rows">2</property>
</child> <property name="n_columns">2</property>
</widget> <property name="homogeneous">False</property>
<packing> <property name="row_spacing">6</property>
<property name="position">2</property> <property name="column_spacing">6</property>
</packing>
</child> <child>
<child internal-child="action_area"> <widget class="GtkLabel" id="Duration.Label">
<widget class="GtkHButtonBox" id="MainButtonBox"> <property name="visible">True</property>
<property name="visible">True</property> <property name="label" translatable="yes">Duration</property>
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property> <property name="use_underline">False</property>
<child> <property name="use_markup">False</property>
<widget class="GtkButton" id="Cancel.Button"> <property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="visible">True</property> <property name="wrap">False</property>
<property name="can_focus">True</property> <property name="selectable">False</property>
<property name="can_default">True</property> <property name="xalign">0</property>
<property name="label">gtk-cancel</property> <property name="yalign">0</property>
<property name="use_stock">True</property> <property name="xpad">0</property>
<property name="response_id">-6</property> <property name="ypad">0</property>
</widget> <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
</child> <property name="width_chars">-1</property>
<child> <property name="single_line_mode">False</property>
<widget class="GtkButton" id="OK.Button"> <property name="angle">0</property>
<property name="visible">True</property> </widget>
<property name="can_focus">True</property> <packing>
<property name="can_default">True</property> <property name="left_attach">0</property>
<property name="has_default">True</property> <property name="right_attach">1</property>
<property name="label">gtk-ok</property> <property name="top_attach">1</property>
<property name="use_stock">True</property> <property name="bottom_attach">2</property>
<property name="response_id">-5</property> <property name="x_options"></property>
</widget> <property name="y_options"></property>
<packing> </packing>
<property name="position">1</property> </child>
</packing>
</child> <child>
</widget> <widget class="GtkLabel" id="Resource.Label">
<packing> <property name="visible">True</property>
<property name="expand">False</property> <property name="label" translatable="yes">Resource</property>
<property name="pack_type">GTK_PACK_END</property> <property name="use_underline">False</property>
</packing> <property name="use_markup">False</property>
</child> <property name="justify">GTK_JUSTIFY_LEFT</property>
</widget> <property name="wrap">False</property>
</child> <property name="selectable">False</property>
</widget> <property name="xalign">0</property>
<property name="yalign">0</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="Duration.Spin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="climb_rate">1</property>
<property name="digits">0</property>
<property name="numeric">True</property>
<property name="update_policy">GTK_UPDATE_ALWAYS</property>
<property name="snap_to_ticks">False</property>
<property name="wrap">False</property>
<property name="adjustment">1 1 inf 1 0 0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="Resource.Combo">
<property name="visible">True</property>
<property name="add_tearoffs">False</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="AddRemoveButtons">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
<property name="spacing">0</property>
<child>
<widget class="GtkButton" id="Add">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="label">gtk-add</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="Remove">
<property name="visible">True</property>
<property name="label">gtk-remove</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface> </glade-interface>

View File

@ -103,30 +103,6 @@
</packing> </packing>
</child> </child>
<child>
<widget class="GtkCheckButton" id="Preemptable.Check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child> <child>
<widget class="GtkSpinButton" id="Availability.Spin"> <widget class="GtkSpinButton" id="Availability.Spin">
<property name="visible">True</property> <property name="visible">True</property>
@ -274,6 +250,30 @@
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkCheckButton" id="Preemptable.Check">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>

View File

@ -174,7 +174,7 @@ ConcreteHistory::remove(resource_key_t resource_key)
for (Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++) for (Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
{ {
Requests& reqs = (*it2)->get_dynamic_requests(); Requests& reqs = (*it2)->get_dynamic_requests();
for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++) for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end();)
{ {
SubRequests& subr = (*it3)->get_dynamic_subrequests(); SubRequests& subr = (*it3)->get_dynamic_subrequests();
SubRequests::iterator it4 = subr.begin(); SubRequests::iterator it4 = subr.begin();
@ -186,6 +186,12 @@ ConcreteHistory::remove(resource_key_t resource_key)
} }
else else
it4++; it4++;
// erase empty requests
if(subr.size() == 0)
it3 = reqs.erase(it3);
else
++it3;
} }
} }
} //~ end monstrous construct, "The Thing That Should Not Be" } //~ end monstrous construct, "The Thing That Should Not Be"

View File

@ -68,17 +68,18 @@ ResourcesWidget::~ResourcesWidget()
Simulation::get_instance().get_history().detach(*this); Simulation::get_instance().get_history().detach(*this);
} }
sgpem::Resource* bool
ResourcesWidget::get_selected_resource() ResourcesWidget::get_selected_key(unsigned int& selection)
{ {
TreeModel::iterator sel = get_selection()->get_selected(); TreeModel::iterator it = get_selection()->get_selected();
if(!sel) if(it)
return NULL; {
selection = (*it)[_key_column];
const void* p_handle = (*sel)[_handles_column]; return true;
}
return reinterpret_cast<Resource*>(const_cast<void*>(p_handle)); else
return false;
} }
bool bool
@ -93,14 +94,24 @@ ResourcesWidget::on_button_press_event(GdkEventButton* event)
action_group->add( Gtk::Action::create("AddResource", "Add Resource"), action_group->add( Gtk::Action::create("AddResource", "Add Resource"),
sigc::mem_fun(*this, &ResourcesWidget::_on_add_resource) ); sigc::mem_fun(*this, &ResourcesWidget::_on_add_resource) );
action_group->add( Gtk::Action::create("RemoveResource", "Remove Resource"),
sigc::mem_fun(*this, &ResourcesWidget::_on_remove_resource) );
RefPtr<UIManager> UIManager = Gtk::UIManager::create(); RefPtr<UIManager> UIManager = Gtk::UIManager::create();
UIManager->insert_action_group(action_group); UIManager->insert_action_group(action_group);
unsigned int selection;
Glib::ustring ui_info = Glib::ustring ui_info =
"<ui>" "<ui>"
" <popup name='PopupMenu'>" " <popup name='PopupMenu'>"
" <menuitem action='AddResource'/>" " <menuitem action='AddResource'/>";
" </popup>" if(get_selected_key(selection))
ui_info +=
" <separator/>"
" <menuitem action='RemoveResource'/>";
ui_info +=
" </popup>"
"</ui>"; "</ui>";
UIManager->add_ui_from_string(ui_info); UIManager->add_ui_from_string(ui_info);
@ -160,3 +171,10 @@ ResourcesWidget::_on_add_resource()
_add_resource_dialog->hide(); _add_resource_dialog->hide();
} }
void
ResourcesWidget::_on_remove_resource()
{
unsigned int selection;
if(get_selected_key(selection))
Simulation::get_instance().get_history().remove(selection);
}

View File

@ -51,9 +51,10 @@ namespace sgpem
bool on_button_press_event(GdkEventButton* event); bool on_button_press_event(GdkEventButton* event);
private: private:
Resource* get_selected_resource(); bool get_selected_key(unsigned int& selection);
void _on_add_resource(); void _on_add_resource();
void _on_remove_resource();
Glib::RefPtr<Gtk::ListStore> _model; Glib::RefPtr<Gtk::ListStore> _model;
Gtk::TreeModelColumnRecord _columns; Gtk::TreeModelColumnRecord _columns;