FlowCanvas 0.7.1
Canvas.hpp
Go to the documentation of this file.
1/* This file is part of FlowCanvas.
2 * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
3 *
4 * FlowCanvas is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
7 * version.
8 *
9 * FlowCanvas is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18#ifndef FLOWCANVAS_CANVAS_HPP
19#define FLOWCANVAS_CANVAS_HPP
20
21#include <list>
22#include <string>
23
24#include <boost/enable_shared_from_this.hpp>
25#include <boost/utility.hpp>
26
27#include <libgnomecanvasmm.h>
28
30#include "flowcanvas/Item.hpp"
31#include "flowcanvas/Module.hpp"
32
33
38namespace FlowCanvas {
39
40class Port;
41class Module;
42class GVNodes;
43
44
58class Canvas : boost::noncopyable
59 , public boost::enable_shared_from_this<Canvas>
60 , public Gnome::Canvas::CanvasAA
61{
62public:
63 Canvas(double width, double height);
64 virtual ~Canvas();
65
66 void destroy();
67
68 void add_item(boost::shared_ptr<Item> i);
69 bool remove_item(boost::shared_ptr<Item> i);
70
71 boost::shared_ptr<Connection>
72 get_connection(boost::shared_ptr<Connectable> tail,
73 boost::shared_ptr<Connectable> head) const;
74
75 bool add_connection(boost::shared_ptr<Connectable> tail,
76 boost::shared_ptr<Connectable> head,
77 uint32_t color);
78
79 bool add_connection(boost::shared_ptr<Connection> connection);
80
81 boost::shared_ptr<Connection> remove_connection(boost::shared_ptr<Connectable> tail,
82 boost::shared_ptr<Connectable> head);
83
84 void set_default_placement(boost::shared_ptr<Module> m);
85
87 void select_item(boost::shared_ptr<Item> item);
89 void unselect_item(boost::shared_ptr<Item> item);
91
92 ItemList& items() { return _items; }
96
97 void lock(bool l);
98 bool locked() const { return _locked; }
99
100 double get_zoom() { return _zoom; }
101 void set_zoom(double pix_per_unit);
102 void zoom_full();
103
104 void render_to_dot(const std::string& filename);
105 virtual void arrange(bool use_length_hints=false, bool center=true);
106
107 void move_contents_to(double x, double y);
108
109 double width() const { return _width; }
110 double height() const { return _height; }
111
112 void resize(double width, double height);
114
116
120 };
121
122 void set_direction(FlowDirection d) { _direction = d; }
123 FlowDirection direction() const { return _direction; }
124
127 ArtVpathDash* select_dash() { return _select_dash; }
128
130 virtual void connect(boost::shared_ptr<Connectable> /*tail*/,
131 boost::shared_ptr<Connectable> /*head*/) {}
132
134 virtual void disconnect(boost::shared_ptr<Connectable> /*tail*/,
135 boost::shared_ptr<Connectable> /*head*/) {}
136
137 static sigc::signal<void, Gnome::Canvas::Item*> signal_item_entered;
138 static sigc::signal<void, Gnome::Canvas::Item*> signal_item_left;
139
140protected:
143 std::list< boost::shared_ptr<Item> > _selected_items;
144 std::list< boost::shared_ptr<Connection> > _selected_connections;
145
146 virtual bool canvas_event(GdkEvent* event);
147 virtual bool frame_event(GdkEvent* ev);
148
149private:
150 friend class Module;
151 bool port_event(GdkEvent* event, boost::weak_ptr<Port> port);
152
153 GVNodes layout_dot(bool use_length_hints, const std::string& filename);
154
155 void remove_connection(boost::shared_ptr<Connection> c);
156 bool are_connected(boost::shared_ptr<const Connectable> tail,
157 boost::shared_ptr<const Connectable> head);
158
159 void select_port(boost::shared_ptr<Port> p, bool unique = false);
160 void select_port_toggle(boost::shared_ptr<Port> p, int mod_state);
161 void unselect_port(boost::shared_ptr<Port> p);
162 void selection_joined_with(boost::shared_ptr<Port> port);
163 void join_selection();
164
165 boost::shared_ptr<Port> get_port_at(double x, double y);
166
167 bool scroll_drag_handler(GdkEvent* event);
168 bool select_drag_handler(GdkEvent* event);
169 bool connection_drag_handler(GdkEvent* event);
170
171 void ports_joined(boost::shared_ptr<Port> port1, boost::shared_ptr<Port> port2);
172 bool animate_selected();
173
174 void move_contents_to_internal(double x, double y, double min_x, double min_y);
175
176 void on_parent_changed(Gtk::Widget* old_parent);
177 sigc::connection _parent_event_connection;
178
179 typedef std::list< boost::shared_ptr<Port> > SelectedPorts;
180
181 SelectedPorts _selected_ports;
182 boost::shared_ptr<Port> _connect_port;
183 boost::shared_ptr<Port> _last_selected_port;
184
185 Gnome::Canvas::Rect _base_rect;
186 Gnome::Canvas::Rect* _select_rect;
187 ArtVpathDash* _select_dash;
188
189 double _zoom;
190 double _width;
191 double _height;
192
193 enum DragState { NOT_DRAGGING, CONNECTION, SCROLL, SELECT };
194 DragState _drag_state;
195
196 FlowDirection _direction;
197
198 bool _remove_objects :1; // flag to avoid removing objects from destructors when unnecessary
199 bool _locked :1;
200};
201
202
203} // namespace FlowCanvas
204
205#endif // FLOWCANVAS_CANVAS_HPP
The 'master' canvas widget which contains all other objects.
Definition: Canvas.hpp:61
double width() const
Definition: Canvas.hpp:109
static sigc::signal< void, Gnome::Canvas::Item * > signal_item_left
Definition: Canvas.hpp:138
virtual void connect(boost::shared_ptr< Connectable >, boost::shared_ptr< Connectable >)
Make a connection.
Definition: Canvas.hpp:130
void set_direction(FlowDirection d)
Definition: Canvas.hpp:122
bool add_connection(boost::shared_ptr< Connection > connection)
boost::shared_ptr< Connection > remove_connection(boost::shared_ptr< Connectable > tail, boost::shared_ptr< Connectable > head)
void render_to_dot(const std::string &filename)
boost::shared_ptr< Connection > get_connection(boost::shared_ptr< Connectable > tail, boost::shared_ptr< Connectable > head) const
static sigc::signal< void, Gnome::Canvas::Item * > signal_item_entered
Definition: Canvas.hpp:137
bool locked() const
Definition: Canvas.hpp:98
ConnectionList _connections
All connections on this canvas.
Definition: Canvas.hpp:142
virtual void disconnect(boost::shared_ptr< Connectable >, boost::shared_ptr< Connectable >)
Disconnect two ports.
Definition: Canvas.hpp:134
ItemList & items()
Definition: Canvas.hpp:92
void lock(bool l)
void set_zoom(double pix_per_unit)
std::list< boost::shared_ptr< Connection > > _selected_connections
All currently selected connections.
Definition: Canvas.hpp:144
ConnectionList & selected_connections()
Definition: Canvas.hpp:95
void unselect_connection(Connection *c)
bool add_connection(boost::shared_ptr< Connectable > tail, boost::shared_ptr< Connectable > head, uint32_t color)
void add_item(boost::shared_ptr< Item > i)
FlowDirection
Definition: Canvas.hpp:117
@ VERTICAL
Definition: Canvas.hpp:119
@ HORIZONTAL
Definition: Canvas.hpp:118
void select_item(boost::shared_ptr< Item > item)
double height() const
Definition: Canvas.hpp:110
ItemList & selected_items()
Definition: Canvas.hpp:93
void move_contents_to(double x, double y)
ItemList _items
All items on this canvas.
Definition: Canvas.hpp:141
void set_default_placement(boost::shared_ptr< Module > m)
ConnectionList & connections()
Definition: Canvas.hpp:94
virtual bool canvas_event(GdkEvent *event)
std::list< boost::shared_ptr< Item > > _selected_items
All currently selected modules.
Definition: Canvas.hpp:143
double get_zoom()
Definition: Canvas.hpp:100
Canvas(double width, double height)
bool remove_item(boost::shared_ptr< Item > i)
virtual bool frame_event(GdkEvent *ev)
FlowDirection direction() const
Definition: Canvas.hpp:123
virtual void arrange(bool use_length_hints=false, bool center=true)
void unselect_item(boost::shared_ptr< Item > item)
ArtVpathDash * select_dash()
Dash applied to selected items.
Definition: Canvas.hpp:127
void resize(double width, double height)
A connection (line) between two canvas objects.
Definition: Connection.hpp:43
A named block (possibly) containing input and output ports.
Definition: Module.hpp:38
A port on a Module.
Definition: Port.hpp:51
FlowCanvas namespace, everything is defined under this.
Definition: Canvas.hpp:38
std::list< boost::shared_ptr< Connection > > ConnectionList
Definition: Connection.hpp:111
std::list< boost::shared_ptr< Item > > ItemList
Definition: Item.hpp:149