- 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,61 +1,136 @@
<?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">
<widget class="GtkDialog" id="AddRequestDialog">
<property name="width_request">300</property> <property name="width_request">300</property>
<property name="height_request">240</property> <property name="height_request">240</property>
<property name="title">Add Request</property> <property name="title">Add Request</property>
<property name="modal">True</property> <property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_MOUSE</property> <property name="window_position">GTK_WIN_POS_MOUSE</property>
<property name="modal">True</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<property name="has_separator">True</property>
<child internal-child="vbox"> <child internal-child="vbox">
<widget class="GtkVBox" id="MainVBox"> <widget class="GtkVBox" id="MainVBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="MainButtonBox">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
<child>
<widget class="GtkButton" id="Cancel.Button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="OK.Button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child> <child>
<widget class="GtkVBox" id="InputArea"> <widget class="GtkVBox" id="InputArea">
<property name="visible">True</property>
<property name="border_width">4</property> <property name="border_width">4</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property> <property name="spacing">6</property>
<child> <child>
<widget class="GtkHBox" id="Instant.Box"> <widget class="GtkHBox" id="Instant.Box">
<property name="visible">True</property> <property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property> <property name="spacing">6</property>
<child> <child>
<widget class="GtkLabel" id="Instant.Label"> <widget class="GtkLabel" id="Instant.Label">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0,000000</property>
<property name="yalign">0,000000</property>
<property name="label" translatable="yes">Instant</property> <property name="label" translatable="yes">Instant</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<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> </widget>
<packing> <packing>
<property name="padding">0</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkSpinButton" id="Instant.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 0,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>
<property name="update_policy">GTK_UPDATE_ALWAYS</property>
<property name="snap_to_ticks">False</property>
<property name="wrap">False</property>
<property name="adjustment">0 0 inf 1 0 0</property>
</widget> </widget>
<packing> <packing>
<property name="position">1</property> <property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing> </packing>
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkScrolledWindow" id="SubRequests"> <widget class="GtkScrolledWindow" id="SubRequests">
<property name="height_request">200</property> <property name="height_request">200</property>
@ -64,59 +139,106 @@
<property name="hscrollbar_policy">GTK_POLICY_NEVER</property> <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property> <property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child> <child>
<widget class="GtkTreeView" id="SubRequests.View"> <widget class="GtkTreeView" id="SubRequests.View">
<property name="height_request">100</property> <property name="height_request">100</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">True</property> <property name="reorderable">True</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
</widget> </widget>
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="position">1</property> <property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkTable" id="SubRequestInput"> <widget class="GtkTable" id="SubRequestInput">
<property name="visible">True</property> <property name="visible">True</property>
<property name="n_rows">2</property> <property name="n_rows">2</property>
<property name="n_columns">2</property> <property name="n_columns">2</property>
<property name="column_spacing">6</property> <property name="homogeneous">False</property>
<property name="row_spacing">6</property> <property name="row_spacing">6</property>
<property name="column_spacing">6</property>
<child> <child>
<widget class="GtkLabel" id="Duration.Label"> <widget class="GtkLabel" id="Duration.Label">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0,000000</property>
<property name="yalign">0,000000</property>
<property name="label" translatable="yes">Duration</property> <property name="label" translatable="yes">Duration</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<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> </widget>
<packing> <packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">1</property> <property name="top_attach">1</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">2</property>
<property name="x_options"></property> <property name="x_options"></property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="Resource.Label"> <widget class="GtkLabel" id="Resource.Label">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0,000000</property>
<property name="yalign">0,000000</property>
<property name="label" translatable="yes">Resource</property> <property name="label" translatable="yes">Resource</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<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> </widget>
<packing> <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="x_options"></property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkSpinButton" id="Duration.Spin"> <widget class="GtkSpinButton" id="Duration.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>
<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> </widget>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
@ -126,93 +248,73 @@
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkComboBox" id="Resource.Combo"> <widget class="GtkComboBox" id="Resource.Combo">
<property name="visible">True</property> <property name="visible">True</property>
<property name="add_tearoffs">False</property>
<property name="focus_on_click">True</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="x_options"></property> <property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">2</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkHButtonBox" id="AddRemoveButtons"> <widget class="GtkHButtonBox" id="AddRemoveButtons">
<property name="visible">True</property>
<property name="border_width">6</property> <property name="border_width">6</property>
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property> <property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
<property name="spacing">0</property>
<child> <child>
<widget class="GtkButton" id="Add"> <widget class="GtkButton" id="Add">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_default">True</property> <property name="can_default">True</property>
<property name="label" translatable="yes">gtk-add</property> <property name="label">gtk-add</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget> </widget>
</child> </child>
<child> <child>
<widget class="GtkButton" id="Remove"> <widget class="GtkButton" id="Remove">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">gtk-remove</property> <property name="label">gtk-remove</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</widget> </widget>
<packing>
<property name="position">1</property>
</packing>
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">3</property> <property name="fill">True</property>
</packing> </packing>
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="position">2</property> <property name="padding">0</property>
</packing> <property name="expand">True</property>
</child> <property name="fill">True</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="MainButtonBox">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
<child>
<widget class="GtkButton" id="Cancel.Button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="OK.Button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="response_id">-5</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing> </packing>
</child> </child>
</widget> </widget>
</child> </child>
</widget> </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,13 +94,23 @@ 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'/>";
if(get_selected_key(selection))
ui_info +=
" <separator/>"
" <menuitem action='RemoveResource'/>";
ui_info +=
" </popup>" " </popup>"
"</ui>"; "</ui>";
@ -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;