From 27553e15e188f7a43903a0d3eb95389b0efcd1d6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 14 Jan 2013 04:05:44 +0000 Subject: Fix deletion of nodes and edges. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4981 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/Controller.cpp | 2 +- src/gui/MachinaCanvas.cpp | 4 +++- src/gui/MachinaGUI.cpp | 28 ++++++++++++++++++++-------- src/gui/MachinaGUI.hpp | 16 ++++++---------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/engine/Controller.cpp b/src/engine/Controller.cpp index 7d9017e..00ad9f9 100644 --- a/src/engine/Controller.cpp +++ b/src/engine/Controller.cpp @@ -188,7 +188,7 @@ void Controller::erase(uint64_t id) { SPtr key(new StatefulKey(id)); - Objects::iterator i = _objects.find(key); + Objects::iterator i = _objects.find(key); if (i == _objects.end()) { return; } diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 3413a9f..6de0217 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -170,8 +170,10 @@ MachinaCanvas::on_erase_object(SPtr object) { const Raul::Atom& type = object->get(URIs::instance().rdf_type); if (type.get() == URIs::instance().machina_Node) { - // Destruction of the view will remove from the canvas + delete object->view(); + object->set_view(NULL); } else if (type.get() == URIs::instance().machina_Edge) { + remove_edge(dynamic_cast(object->view())); object->set_view(NULL); } else { std::cerr << "Unknown object type" << std::endl; diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index 2147c27..5044dcb 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -241,15 +241,27 @@ MachinaGUI::idle_callback() } static void -erase_node(GanvNode* node, void* data) +destroy_edge(GanvEdge* edge, void* data) { - machina::Controller* controller = (machina::Controller*)data; - NodeView* const view = dynamic_cast( - Glib::wrap(GANV_NODE(node))); + MachinaGUI* gui = (MachinaGUI*)data; + EdgeView* view = dynamic_cast(Glib::wrap(edge)); if (view) { - controller->erase(view->node()->id()); - //_engine->machine()->remove_node(view->node()); - //_canvas->remove_item(view); + NodeView* tail = dynamic_cast(view->get_tail()); + NodeView* head = dynamic_cast(view->get_head()); + gui->controller()->disconnect(tail->node()->id(), head->node()->id()); + } +} + +static void +destroy_node(GanvNode* node, void* data) +{ + MachinaGUI* gui = (MachinaGUI*)data; + NodeView* view = dynamic_cast(Glib::wrap(GANV_NODE(node))); + if (view) { + const SPtr node = view->node(); + gui->canvas()->for_each_edge_on( + GANV_NODE(view->gobj()), destroy_edge, gui); + gui->controller()->erase(node->id()); } } @@ -258,7 +270,7 @@ MachinaGUI::scrolled_window_event(GdkEvent* event) { if (event->type == GDK_KEY_PRESS) { if (event->key.keyval == GDK_Delete) { - _canvas->for_each_selected_node(erase_node, _controller.get()); + _canvas->for_each_selected_node(destroy_node, this); return true; } } diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp index 4bbb238..3c10cda 100644 --- a/src/gui/MachinaGUI.hpp +++ b/src/gui/MachinaGUI.hpp @@ -50,22 +50,18 @@ public: explicit MachinaGUI(SPtr engine); ~MachinaGUI(); - SPtr canvas() { return _canvas; } - SPtr engine() { return _engine; } - - Raul::Forge& forge() { return _forge; } - - SPtr maid() { return _maid; } - - Gtk::Window* window() { return _main_window; } + SPtr canvas() { return _canvas; } + SPtr engine() { return _engine; } + SPtr controller() { return _controller; } + Raul::Forge& forge() { return _forge; } + SPtr maid() { return _maid; } + Gtk::Window* window() { return _main_window; } void attach(); void quit() { _main_window->hide(); } bool chain_mode() const { return _chain_mode; } - SPtr controller() { return _controller; } - double default_length() const { return 1 / (double)_quantize_spinbutton->get_value(); } -- cgit v1.2.1