1 /* This file is part of FlowCanvas. Copyright (C) 2005 Dave Robillard.
3 * FlowCanvas is free software; you can redistribute it and/or modify it under the
4 * terms of the GNU General Public License as published by the Free Software
5 * Foundation; either version 2 of the License, or (at your option) any later
8 * FlowCanvas is distributed in the hope that it will be useful, but WITHOUT ANY
9 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write to the Free Software Foundation, Inc.,
14 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <libgnomecanvasmm.h>
24 #include "Connection.h"
31 /** FlowCanvas namespace, everything is defined under this.
35 namespace LibFlowCanvas {
41 /** \defgroup FlowCanvas Canvas widget for dataflow systems.
43 * A generic dataflow widget using libgnomecanvas. It's used by Om and
44 * Patchage, but could be used by anyone.
48 /** The canvas widget.
50 * Applications must override some virtual methods to make the widget actually
51 * do anything (ie connect).
56 class FlowCanvas : public Gnome::Canvas::CanvasAA
58 class FlowCanvas : public Gnome::Canvas::Canvas
62 FlowCanvas(double width, double height);
63 virtual ~FlowCanvas();
67 void add_module(Module* m);
68 void remove_module(const string& name);
70 void add_connection(const string& mod1_name, const string& port1_name, const string& mod2_name, const string& port2_name);
71 bool remove_connection(const string& mod1_name, const string& port1_name, const string& mod2_name, const string& port2_name);
73 void add_connection(Port* port1, Port* port2);
74 bool remove_connection(Port* port1, Port* port2);
76 Module* find_module(const string& name);
77 Port* find_port(const string& module_name, const string& port_name);
79 void rename_module(const string& old_name, const string& new_name);
81 void set_default_placement(Module* m);
83 float zoom() { return m_zoom; }
84 void zoom(float pix_per_unit);
86 double width() const { return m_width; }
87 double height() const { return m_height; }
89 void clear_selection();
90 void select_module(Module* m);
91 void unselect_module(Module* m);
93 ModuleMap& modules() { return m_modules; }
94 list<Module*>& selected_modules() { return m_selected_modules; }
95 list<Connection*>& selected_connections() { return m_selected_connections; }
97 /** Dash applied to selected items.
98 * Always animating, set a rect's property_dash() to this and it
99 * will automagically do the rubber band thing. */
100 ArtVpathDash* const select_dash() { return m_select_dash; }
102 virtual bool port_event(GdkEvent* event, Port* port);
104 /** Make a connection. Should be overridden by an implementation to do something. */
105 virtual void connect(const Port* const port1, const Port* const port2) = 0;
107 /** Disconnect two ports. Should be overridden by an implementation to do something */
108 virtual void disconnect(const Port* const port1, const Port* const port2) = 0;
111 ModuleMap m_modules; ///< All modules on this canvas
112 ConnectionList m_connections; ///< All connections on this canvas
113 list<Module*> m_selected_modules; ///< All currently selected modules
114 list<Connection*> m_selected_connections; ///< All currently selected connections
116 virtual bool canvas_event(GdkEvent* event) { return false; }
119 Connection* get_connection(const Port* port1, const Port* port2);
120 void remove_connection(Connection* c);
121 void selected_port(Port* p);
122 Port* selected_port() { return m_selected_port; }
123 bool are_connected(const Port* port1, const Port* port2);
124 Port* get_port_at(double x, double y);
126 //bool scroll_drag_handler(GdkEvent* event);
127 virtual bool select_drag_handler(GdkEvent* event);
128 virtual bool connection_drag_handler(GdkEvent* event);
130 void ports_joined(Port* port1, Port* port2);
131 bool animate_selected();
133 Port* m_selected_port; ///< Selected port (hilited red from clicking once)
134 Port* m_connect_port; ///< Port for which a connection is being made (if applicable)
136 float m_zoom; ///< Current zoom level
140 enum DragState { NOT_DRAGGING, CONNECTION, SCROLL, SELECT };
141 DragState m_drag_state;
143 Gnome::Canvas::Rect m_base_rect; ///< Background
145 Gnome::Canvas::Rect* m_select_rect; ///< Rectangle for drag selection
146 ArtVpathDash* m_select_dash; ///< Animated selection dash style
150 } // namespace LibFlowCanvas
152 #endif // FLOWCANVAS_H