- Enjoy the new ResourcesWidget! (to be honest, it`s mainly a cut-n-paste work made from SchedulablesTreeWidget...)
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@921 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
d60a7aa25e
commit
077157739c
|
@ -299,7 +299,8 @@ sgpemv2_SOURCES = \
|
||||||
src/gui_builder.cc \
|
src/gui_builder.cc \
|
||||||
src/main.cc \
|
src/main.cc \
|
||||||
src/parse_opts.cc \
|
src/parse_opts.cc \
|
||||||
src/schedulable_state_widget.cc \
|
src/resources_widget.cc \
|
||||||
|
src/schedulable_state_widget.cc \
|
||||||
src/schedulables_tree_widget.cc \
|
src/schedulables_tree_widget.cc \
|
||||||
src/simulation_widget.cc \
|
src/simulation_widget.cc \
|
||||||
src/text_simulation.cc
|
src/text_simulation.cc
|
||||||
|
@ -312,6 +313,7 @@ noinst_HEADERS += \
|
||||||
src/gui_builder.hh \
|
src/gui_builder.hh \
|
||||||
src/main.hh \
|
src/main.hh \
|
||||||
src/parse_opts.hh \
|
src/parse_opts.hh \
|
||||||
|
src/resources_widget.hh \
|
||||||
src/schedulable_state_widget.hh \
|
src/schedulable_state_widget.hh \
|
||||||
src/schedulables_tree_widget.hh \
|
src/schedulables_tree_widget.hh \
|
||||||
src/simulation_widget.hh \
|
src/simulation_widget.hh \
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -91,9 +91,6 @@ AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Xml>& g
|
||||||
|
|
||||||
_list->get_selection()->signal_changed().connect(
|
_list->get_selection()->signal_changed().connect(
|
||||||
sigc::mem_fun(*this, &AddRequestDialog::_on_list_selection_changed));
|
sigc::mem_fun(*this, &AddRequestDialog::_on_list_selection_changed));
|
||||||
|
|
||||||
Simulation::get_instance().get_history().add_resource("guitar");
|
|
||||||
Simulation::get_instance().get_history().add_resource("drums");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Request&
|
Request&
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "schedulables_tree_widget.hh"
|
#include "schedulables_tree_widget.hh"
|
||||||
#include "simulation_widget.hh"
|
#include "simulation_widget.hh"
|
||||||
|
#include "resources_widget.hh"
|
||||||
|
|
||||||
#include "gui_builder.hh"
|
#include "gui_builder.hh"
|
||||||
#include "graphical_preferences_editor.hh"
|
#include "graphical_preferences_editor.hh"
|
||||||
|
@ -254,7 +255,9 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
// we have to remember to manually show custom added widgets:
|
// we have to remember to manually show custom added widgets:
|
||||||
scheds_tree->show();
|
scheds_tree->show();
|
||||||
|
|
||||||
|
ResourcesWidget* resources_widget = NULL;
|
||||||
|
_refXml->get_widget_derived("Resources.Tree", resources_widget);
|
||||||
|
resources_widget->show();
|
||||||
|
|
||||||
// Main simulation widget
|
// Main simulation widget
|
||||||
ScrolledWindow* simulation_window = NULL;
|
ScrolledWindow* simulation_window = NULL;
|
||||||
|
|
|
@ -0,0 +1,162 @@
|
||||||
|
// src/resources_widget.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
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
|
// (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
|
||||||
|
// along with SGPEMv2; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
#include "resources_widget.hh"
|
||||||
|
#include "templates/sequences.tcc"
|
||||||
|
#include "backend/history.hh"
|
||||||
|
#include "backend/simulation.hh"
|
||||||
|
#include "backend/resource.hh"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <gtkmm/entry.h>
|
||||||
|
#include <gtkmm/spinbutton.h>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
using namespace Gtk;
|
||||||
|
using namespace Glib;
|
||||||
|
using Gnome::Glade::Xml;
|
||||||
|
|
||||||
|
ResourcesWidget::ResourcesWidget(BaseObjectType* cobject, const RefPtr<Xml>& glade) :
|
||||||
|
TreeView(cobject),
|
||||||
|
_add_resource_dialog_glade(Xml::create(GLADEDIR "/add-resource-dialog.glade"))
|
||||||
|
{
|
||||||
|
_columns.add(_key_column);
|
||||||
|
_columns.add(_main_column);
|
||||||
|
_columns.add(_handles_column);
|
||||||
|
_model = ListStore::create(_columns);
|
||||||
|
|
||||||
|
set_model(_model);
|
||||||
|
|
||||||
|
append_column(_("key"), _key_column);
|
||||||
|
append_column(_("resources"), _main_column);
|
||||||
|
//invisible
|
||||||
|
// append_column("handles", _handles_column);
|
||||||
|
|
||||||
|
/** DIALOGS **/
|
||||||
|
_add_resource_dialog_glade->get_widget("AddResourceDialog", _add_resource_dialog);
|
||||||
|
|
||||||
|
set_headers_visible(false);
|
||||||
|
|
||||||
|
Simulation::get_instance().get_history().attach(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourcesWidget::~ResourcesWidget()
|
||||||
|
{
|
||||||
|
Simulation::get_instance().get_history().detach(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
sgpem::Resource*
|
||||||
|
ResourcesWidget::get_selected_resource()
|
||||||
|
{
|
||||||
|
TreeModel::iterator sel = get_selection()->get_selected();
|
||||||
|
|
||||||
|
if(!sel)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
const void* p_handle = (*sel)[_handles_column];
|
||||||
|
|
||||||
|
return reinterpret_cast<Resource*>(const_cast<void*>(p_handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ResourcesWidget::on_button_press_event(GdkEventButton* event)
|
||||||
|
{
|
||||||
|
TreeView::on_button_press_event(event);
|
||||||
|
|
||||||
|
if((event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
|
||||||
|
{
|
||||||
|
RefPtr<ActionGroup> action_group = Gtk::ActionGroup::create();
|
||||||
|
|
||||||
|
action_group->add( Gtk::Action::create("AddResource", "Add Resource"),
|
||||||
|
sigc::mem_fun(*this, &ResourcesWidget::_on_add_resource) );
|
||||||
|
|
||||||
|
RefPtr<UIManager> UIManager = Gtk::UIManager::create();
|
||||||
|
UIManager->insert_action_group(action_group);
|
||||||
|
|
||||||
|
Glib::ustring ui_info =
|
||||||
|
"<ui>"
|
||||||
|
" <popup name='PopupMenu'>"
|
||||||
|
" <menuitem action='AddResource'/>"
|
||||||
|
" </popup>"
|
||||||
|
"</ui>";
|
||||||
|
|
||||||
|
UIManager->add_ui_from_string(ui_info);
|
||||||
|
Gtk::Menu* menu = dynamic_cast<Gtk::Menu*>(UIManager->get_widget("/PopupMenu"));
|
||||||
|
|
||||||
|
menu->popup(event->button, event->time);
|
||||||
|
return true; //It has been handled.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ResourcesWidget::update(const History& history)
|
||||||
|
{
|
||||||
|
typedef Environment::Resources::const_iterator ResourceIt;
|
||||||
|
const Environment::Resources& resources =
|
||||||
|
Simulation::get_instance().get_history().get_last_environment().get_resources();
|
||||||
|
|
||||||
|
_model->clear();
|
||||||
|
|
||||||
|
// TODO use the new sequence iterator, it's been made for
|
||||||
|
// something!!!
|
||||||
|
for(Iseq<ResourceIt> it = const_iseq(resources); it; ++it)
|
||||||
|
{
|
||||||
|
Resource& r = *(it->second);
|
||||||
|
|
||||||
|
TreeModel::Row row = *(_model->append());
|
||||||
|
|
||||||
|
row[_key_column] = it->first;
|
||||||
|
row[_main_column] = r.get_name();
|
||||||
|
row[_handles_column] = &r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ResourcesWidget::_on_add_resource()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
_add_resource_dialog_glade->get_widget("Availability.Spin", availability_spin);
|
||||||
|
_add_resource_dialog_glade->get_widget("Preemptable.Check", preemptable_check);
|
||||||
|
|
||||||
|
Simulation::get_instance().get_history().add_resource(name_entry->get_text(),
|
||||||
|
preemptable_check->get_active(),
|
||||||
|
places_spin->get_value_as_int(),
|
||||||
|
availability_spin->get_value_as_int());
|
||||||
|
}
|
||||||
|
|
||||||
|
_add_resource_dialog->hide();
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
// src/resources_widget.hh - 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
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
|
// (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
|
||||||
|
// along with SGPEMv2; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
#ifndef RESOURCES_WIDGET_HH
|
||||||
|
#define RESOURCES_WIDGET_HH 1
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
class Resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <gtkmm/treeview.h>
|
||||||
|
#include <gtkmm/liststore.h>
|
||||||
|
#include <gtkmm/menu.h>
|
||||||
|
#include <gtkmm/uimanager.h>
|
||||||
|
#include <gtkmm/actiongroup.h>
|
||||||
|
#include <gtkmm/dialog.h>
|
||||||
|
#include <libglademm/xml.h>
|
||||||
|
|
||||||
|
#include "backend/history_observer.hh"
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
class ResourcesWidget : public Gtk::TreeView, public HistoryObserver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ResourcesWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& glade);
|
||||||
|
virtual ~ResourcesWidget();
|
||||||
|
|
||||||
|
virtual void update(const History& history);
|
||||||
|
|
||||||
|
bool on_button_press_event(GdkEventButton* event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Resource* get_selected_resource();
|
||||||
|
|
||||||
|
void _on_add_resource();
|
||||||
|
|
||||||
|
Glib::RefPtr<Gtk::ListStore> _model;
|
||||||
|
Gtk::TreeModelColumnRecord _columns;
|
||||||
|
Gtk::TreeModelColumn<unsigned int> _key_column;
|
||||||
|
Gtk::TreeModelColumn<Glib::ustring> _main_column;
|
||||||
|
Gtk::TreeModelColumn<void*> _handles_column;
|
||||||
|
|
||||||
|
Glib::RefPtr<Gtk::UIManager> _UIManager;
|
||||||
|
Glib::RefPtr<Gnome::Glade::Xml> _add_resource_dialog_glade;
|
||||||
|
Gtk::Dialog* _add_resource_dialog;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //~ namespace sgpem
|
||||||
|
|
||||||
|
|
||||||
|
#endif //~ RESOURCES_WIDGET_HH
|
Loading…
Reference in New Issue