From 1e01da451b279943ed51999ee06d64aba7c8faa2 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 4 Oct 2006 04:47:30 +0000 Subject: Bug fixes. Added copy to ingen (no cut or paste yet). Serialization work. git-svn-id: http://svn.drobilla.net/lad/ingen@153 a436a847-0d15-0410-975c-d299462d15a1 --- src/progs/ingenuity/Connection.h | 56 +++++++++++++++++++++++++++++++ src/progs/ingenuity/Loader.cpp | 2 +- src/progs/ingenuity/Makefile.am | 1 + src/progs/ingenuity/NodeModule.cpp | 3 -- src/progs/ingenuity/PatchCanvas.cpp | 41 ++++++++++++++++++++--- src/progs/ingenuity/PatchCanvas.h | 3 +- src/progs/ingenuity/PatchWindow.cpp | 24 +++++++++++++ src/progs/ingenuity/PatchWindow.h | 6 ++++ src/progs/ingenuity/ingenuity.glade | 67 ++++++++++++++++++++++++++++++++----- 9 files changed, 186 insertions(+), 17 deletions(-) create mode 100644 src/progs/ingenuity/Connection.h (limited to 'src/progs') diff --git a/src/progs/ingenuity/Connection.h b/src/progs/ingenuity/Connection.h new file mode 100644 index 00000000..08e37e57 --- /dev/null +++ b/src/progs/ingenuity/Connection.h @@ -0,0 +1,56 @@ +/* This file is part of Ingen. Copyright (C) 2006 Dave Robillard. + * + * Ingen 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. + * + * Ingen 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 details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef CONNECTION_H +#define CONNECTION_H + +#include +#include +#include +#include "ConnectionModel.h" +#include "util/CountedPtr.h" +using Ingen::Client::ConnectionModel; + +namespace Ingenuity { + + +/** A Connection on an Module. + * + * \ingroup Ingenuity + */ +class Connection : public LibFlowCanvas::Connection +{ +public: + Connection(boost::shared_ptr canvas, + boost::shared_ptr model, + boost::shared_ptr src, + boost::shared_ptr dst) + : LibFlowCanvas::Connection(canvas, src, dst) + , m_connection_model(model) + {} + + virtual ~Connection() {} + + CountedPtr model() const { return m_connection_model; } + +private: + CountedPtr m_connection_model; +}; + + +} // namespace Ingenuity + +#endif // CONNECTION_H diff --git a/src/progs/ingenuity/Loader.cpp b/src/progs/ingenuity/Loader.cpp index c07d99bf..b22669ec 100644 --- a/src/progs/ingenuity/Loader.cpp +++ b/src/progs/ingenuity/Loader.cpp @@ -97,7 +97,7 @@ Loader::save_patch_event(CountedPtr model, const string& filename, b cerr << "FIXME: Recursive save." << endl; _serializer->start_to_filename(filename); - _serializer->serialize_patch(model); + _serializer->serialize(model); _serializer->finish(); } diff --git a/src/progs/ingenuity/Makefile.am b/src/progs/ingenuity/Makefile.am index 3044a2fc..753980b8 100644 --- a/src/progs/ingenuity/Makefile.am +++ b/src/progs/ingenuity/Makefile.am @@ -70,6 +70,7 @@ ingenuity_SOURCES = \ SubpatchModule.cpp \ Port.h \ Port.cpp \ + Connection.h \ NewSubpatchWindow.h \ NewSubpatchWindow.cpp \ ConfigWindow.h \ diff --git a/src/progs/ingenuity/NodeModule.cpp b/src/progs/ingenuity/NodeModule.cpp index 6d4e54de..d9d91193 100644 --- a/src/progs/ingenuity/NodeModule.cpp +++ b/src/progs/ingenuity/NodeModule.cpp @@ -85,8 +85,6 @@ NodeModule::show_control_window() void NodeModule::store_location() { - cerr << "FIXME: store_location\n"; -#if 0 const float x = static_cast(property_x()); const float y = static_cast(property_y()); @@ -98,7 +96,6 @@ NodeModule::store_location() App::instance().engine()->set_metadata(m_node->path(), "ingenuity:canvas-x", Atom(x)); App::instance().engine()->set_metadata(m_node->path(), "ingenuity:canvas-y", Atom(y)); } -#endif } diff --git a/src/progs/ingenuity/PatchCanvas.cpp b/src/progs/ingenuity/PatchCanvas.cpp index 6d8403eb..3f9c97fa 100644 --- a/src/progs/ingenuity/PatchCanvas.cpp +++ b/src/progs/ingenuity/PatchCanvas.cpp @@ -26,11 +26,14 @@ #include "LoadSubpatchWindow.h" #include "NewSubpatchWindow.h" #include "Port.h" +#include "Connection.h" #include "NodeModel.h" #include "NodeModule.h" #include "SubpatchModule.h" #include "GladeFactory.h" #include "WindowFactory.h" +#include "Serializer.h" +using Ingen::Client::Serializer; namespace Ingenuity { @@ -170,10 +173,14 @@ PatchCanvas::connection(CountedPtr cm) boost::shared_ptr src = get_port(src_parent_name, cm->src_port_path().name()); boost::shared_ptr dst = get_port(dst_parent_name, cm->dst_port_path().name()); - if (src && dst) - add_connection(src, dst); - else + if (src && dst) { + boost::shared_ptr c(new Connection(shared_from_this(), cm, src, dst)); + src->add_connection(c); + dst->add_connection(c); + add_connection(c); + } else { cerr << "[Canvas] ERROR: Unable to find ports to create connection." << endl; + } } @@ -293,7 +300,7 @@ PatchCanvas::canvas_event(GdkEvent* event) void -PatchCanvas::destroy_selected() +PatchCanvas::destroy_selection() { for (list >::iterator m = m_selected_modules.begin(); m != m_selected_modules.end(); ++m) { boost::shared_ptr module = boost::dynamic_pointer_cast(*m); @@ -303,6 +310,32 @@ PatchCanvas::destroy_selected() } +void +PatchCanvas::copy_selection() +{ + Serializer serializer(App::instance().engine()); + serializer.start_to_string(); + + for (list >::iterator m = m_selected_modules.begin(); m != m_selected_modules.end(); ++m) { + boost::shared_ptr module = boost::dynamic_pointer_cast(*m); + if (module) + serializer.serialize(module->node()); + } + + for (list >::iterator c = m_selected_connections.begin(); + c != m_selected_connections.end(); ++c) { + boost::shared_ptr connection = boost::dynamic_pointer_cast(*c); + if (connection) + serializer.serialize_connection(connection->model()); + } + + string result = serializer.finish(); + + Glib::RefPtr clipboard = Gtk::Clipboard::get(); + clipboard->set_text(result); +} + + string PatchCanvas::generate_port_name(const string& base) { string name = base; diff --git a/src/progs/ingenuity/PatchCanvas.h b/src/progs/ingenuity/PatchCanvas.h index 15312367..7074c785 100644 --- a/src/progs/ingenuity/PatchCanvas.h +++ b/src/progs/ingenuity/PatchCanvas.h @@ -69,7 +69,8 @@ public: void get_new_module_location(double& x, double& y); - void destroy_selected(); + void destroy_selection(); + void copy_selection(); void show_menu(GdkEvent* event) { m_menu->popup(event->button.button, event->button.time); } diff --git a/src/progs/ingenuity/PatchWindow.cpp b/src/progs/ingenuity/PatchWindow.cpp index e429d136..2ca3da14 100644 --- a/src/progs/ingenuity/PatchWindow.cpp +++ b/src/progs/ingenuity/PatchWindow.cpp @@ -59,6 +59,10 @@ PatchWindow::PatchWindow(BaseObjectType* cobject, const Glib::RefPtrget_widget("patch_open_into_menuitem", m_menu_open_into); xml->get_widget("patch_save_menuitem", m_menu_save); xml->get_widget("patch_save_as_menuitem", m_menu_save_as); + xml->get_widget("patch_cut_menuitem", m_menu_cut); + xml->get_widget("patch_copy_menuitem", m_menu_copy); + xml->get_widget("patch_paste_menuitem", m_menu_paste); + xml->get_widget("patch_delete_menuitem", m_menu_delete); xml->get_widget("patch_close_menuitem", m_menu_close); xml->get_widget("patch_configuration_menuitem", m_menu_configuration); xml->get_widget("patch_quit_menuitem", m_menu_quit); @@ -84,6 +88,10 @@ PatchWindow::PatchWindow(BaseObjectType* cobject, const Glib::RefPtrsignal_activate().connect( sigc::mem_fun(this, &PatchWindow::event_save_as)); + m_menu_copy->signal_activate().connect( + sigc::mem_fun(this, &PatchWindow::event_copy)); + m_menu_delete->signal_activate().connect( + sigc::mem_fun(this, &PatchWindow::event_delete)); m_menu_quit->signal_activate().connect( sigc::mem_fun(this, &PatchWindow::event_quit)); m_menu_configuration->signal_activate().connect( @@ -306,6 +314,22 @@ PatchWindow::event_save_as() } +void +PatchWindow::event_copy() +{ + if (m_view) + m_view->canvas()->copy_selection(); +} + + +void +PatchWindow::event_delete() +{ + if (m_view) + m_view->canvas()->destroy_selection(); +} + + void PatchWindow::on_show() { diff --git a/src/progs/ingenuity/PatchWindow.h b/src/progs/ingenuity/PatchWindow.h index b957c420..3f9331ec 100644 --- a/src/progs/ingenuity/PatchWindow.h +++ b/src/progs/ingenuity/PatchWindow.h @@ -81,6 +81,8 @@ private: void event_import(); void event_save(); void event_save_as(); + void event_copy(); + void event_delete(); void event_quit(); void event_destroy(); void event_clear(); @@ -100,6 +102,10 @@ private: Gtk::MenuItem* m_menu_import; Gtk::MenuItem* m_menu_save; Gtk::MenuItem* m_menu_save_as; + Gtk::MenuItem* m_menu_cut; + Gtk::MenuItem* m_menu_copy; + Gtk::MenuItem* m_menu_paste; + Gtk::MenuItem* m_menu_delete; Gtk::MenuItem* m_menu_configuration; Gtk::MenuItem* m_menu_close; Gtk::MenuItem* m_menu_quit; diff --git a/src/progs/ingenuity/ingenuity.glade b/src/progs/ingenuity/ingenuity.glade index 7f18f954..7d24d2e8 100644 --- a/src/progs/ingenuity/ingenuity.glade +++ b/src/progs/ingenuity/ingenuity.glade @@ -51,7 +51,7 @@ - + True gtk-open 1 @@ -106,7 +106,7 @@ - + True gtk-preferences 1 @@ -155,6 +155,57 @@ + + + True + _Edit + True + + + + + + + True + False + gtk-cut + True + + + + + + + True + gtk-copy + True + + + + + + + True + False + gtk-paste + True + + + + + + + True + gtk-delete + True + + + + + + + + True @@ -189,7 +240,7 @@ - + True gtk-preferences 1 @@ -231,7 +282,7 @@ - + True gtk-delete 1 @@ -268,7 +319,7 @@ - + True gtk-connect 1 @@ -291,7 +342,7 @@ - + True gtk-index 1 @@ -314,7 +365,7 @@ - + True gtk-dialog-error 1 @@ -349,7 +400,7 @@ - + True gtk-info 1 -- cgit v1.2.1