From 9d657891ea68ab979bb8c1877bfea656db0bdb1e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 25 Feb 2007 04:11:07 +0000 Subject: More serialization work (loading, saving works from GUI). git-svn-id: http://svn.drobilla.net/lad/machina@338 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/MachinaCanvas.cpp | 63 +++++++++++++++++++++++++++++++++++++++++------ src/gui/MachinaCanvas.hpp | 4 ++- src/gui/MachinaGUI.cpp | 19 +++++++++++--- 3 files changed, 75 insertions(+), 11 deletions(-) (limited to 'src/gui') diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 03a05bc..878e790 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -46,11 +46,9 @@ MachinaCanvas::status_message(const string& msg) void -MachinaCanvas::node_clicked(SharedPtr item, GdkEventButton* event) +MachinaCanvas::node_clicked(WeakPtr item, GdkEventButton* event) { - cerr << "CLICKED: " << item->name() << endl; - - SharedPtr node = PtrCast(item); + SharedPtr node = PtrCast(item.lock()); if (!node) return; @@ -101,10 +99,8 @@ MachinaCanvas::canvas_event(GdkEvent* event) SharedPtr view(new NodeView(node, shared_from_this(), name, x, y)); - //view->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, - // &MachinaCanvas::node_clicked), view)); view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, - &MachinaCanvas::node_clicked), view)); + &MachinaCanvas::node_clicked), WeakPtr(view))); add_item(view); view->resize(); view->raise_to_top(); @@ -173,3 +169,56 @@ MachinaCanvas::disconnect_node(boost::shared_ptr src, } +void +MachinaCanvas::build(SharedPtr machine) +{ + destroy(); + + for (Machina::Machine::Nodes::const_iterator i = machine->nodes().begin(); + i != machine->nodes().end(); ++i) { + + const double x = 1600 + rand() % 300; + const double y = 1200 + rand() % 300; + + SharedPtr view(new NodeView((*i), shared_from_this(), + "", x, y)); + + view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, + &MachinaCanvas::node_clicked), WeakPtr(view))); + + add_item(view); + view->resize(); + } + + for (ItemMap::iterator n = _items.begin(); n != _items.end(); ++n) { + + SharedPtr src = PtrCast(n->second); + if (!src) + continue; + + for (Machina::Node::Edges::const_iterator e = src->node()->outgoing_edges().begin(); + e != src->node()->outgoing_edges().end(); ++e) { + + SharedPtr dst; + for (ItemMap::iterator m = _items.begin(); m != _items.end(); ++m) { + SharedPtr nv = PtrCast((*m).second); + if (nv && nv->node() == (*e)->dst()) { + dst = nv; + break; + } + } + + if (dst) { + boost::shared_ptr c(new EdgeView(shared_from_this(), + src, dst, (*e))); + src->add_connection(c); + dst->add_connection(c); + add_connection(c); + } + + } + } + +} + + diff --git a/src/gui/MachinaCanvas.hpp b/src/gui/MachinaCanvas.hpp index 361e154..feead3e 100644 --- a/src/gui/MachinaCanvas.hpp +++ b/src/gui/MachinaCanvas.hpp @@ -42,10 +42,12 @@ public: void status_message(const string& msg); + void build(SharedPtr machine); + protected: bool canvas_event(GdkEvent* event); - void node_clicked(SharedPtr item, GdkEventButton* ev); + void node_clicked(WeakPtr item, GdkEventButton* ev); private: MachinaGUI* _app; diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index 77dcbc5..3dd0c96 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -351,8 +351,21 @@ MachinaGUI::menu_file_quit() void MachinaGUI::menu_file_open() { - cerr << "open\n"; + Gtk::FileChooserDialog dialog(*_main_window, "Open Machine", Gtk::FILE_CHOOSER_ACTION_OPEN); + + dialog.set_local_only(false); + + dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + const int result = dialog.run(); + + if (result == Gtk::RESPONSE_OK) { + SharedPtr new_machine = _engine->load_machine(dialog.get_uri()); + _canvas->destroy(); + _canvas->build(new_machine); + _save_filename = dialog.get_filename(); + } } @@ -387,8 +400,8 @@ MachinaGUI::menu_file_save_as() if (result == Gtk::RESPONSE_OK) { string filename = dialog.get_filename(); - if (filename.length() < 12 || filename.substr(filename.length()-12) != ".machina.ttl") - filename += ".machina.ttl"; + if (filename.length() < 8 || filename.substr(filename.length()-8) != ".machina") + filename += ".machina"; bool confirm = false; std::fstream fin; -- cgit v1.2.1