00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef FLOWCANVAS_CANVAS_HPP
00019 #define FLOWCANVAS_CANVAS_HPP
00020
00021 #include <list>
00022 #include <boost/enable_shared_from_this.hpp>
00023 #include <boost/utility.hpp>
00024 #include <libgnomecanvasmm.h>
00025 #include "flowcanvas/Connection.hpp"
00026 #include "flowcanvas/Module.hpp"
00027 #include "flowcanvas/Item.hpp"
00028
00029
00034 namespace FlowCanvas {
00035
00036 class Port;
00037 class Module;
00038 class GVNodes;
00039
00040
00054 class Canvas : boost::noncopyable
00055 , public boost::enable_shared_from_this<Canvas>
00056 , public Gnome::Canvas::CanvasAA
00057
00058 {
00059 public:
00060 Canvas(double width, double height);
00061 virtual ~Canvas();
00062
00063 void destroy();
00064
00065 void add_item(boost::shared_ptr<Item> i);
00066 bool remove_item(boost::shared_ptr<Item> i);
00067
00068 boost::shared_ptr<Connection>
00069 get_connection(boost::shared_ptr<Connectable> tail,
00070 boost::shared_ptr<Connectable> head) const;
00071
00072 bool add_connection(boost::shared_ptr<Connectable> tail,
00073 boost::shared_ptr<Connectable> head,
00074 uint32_t color);
00075
00076 bool add_connection(boost::shared_ptr<Connection> connection);
00077
00078 boost::shared_ptr<Connection> remove_connection(boost::shared_ptr<Connectable> tail,
00079 boost::shared_ptr<Connectable> head);
00080
00081 void set_default_placement(boost::shared_ptr<Module> m);
00082
00083 void clear_selection();
00084 void select_item(boost::shared_ptr<Item> item);
00085 void unselect_ports();
00086 void unselect_item(boost::shared_ptr<Item> item);
00087 void unselect_connection(Connection* c);
00088
00089 ItemList& items() { return _items; }
00090 ItemList& selected_items() { return _selected_items; }
00091 ConnectionList& connections() { return _connections; }
00092 ConnectionList& selected_connections() { return _selected_connections; }
00093
00094 void lock(bool l);
00095 bool locked() const { return _locked; }
00096
00097 double get_zoom() { return _zoom; }
00098 void set_zoom(double pix_per_unit);
00099 void zoom_full();
00100
00101 void render_to_dot(const std::string& filename);
00102 virtual void arrange(bool use_length_hints=false);
00103
00104 double width() const { return _width; }
00105 double height() const { return _height; }
00106
00107 void resize(double width, double height);
00108 void resize_all_items();
00109
00110 void scroll_to_center();
00111
00112 enum FlowDirection {
00113 HORIZONTAL,
00114 VERTICAL
00115 };
00116
00117 void set_direction(FlowDirection d) { _direction = d; }
00118 FlowDirection direction() const { return _direction; }
00119
00122 ArtVpathDash* select_dash() { return _select_dash; }
00123
00125 virtual void connect(boost::shared_ptr<Connectable> ,
00126 boost::shared_ptr<Connectable> ) {}
00127
00129 virtual void disconnect(boost::shared_ptr<Connectable> ,
00130 boost::shared_ptr<Connectable> ) {}
00131
00132 static sigc::signal<void, Gnome::Canvas::Item*> signal_item_entered;
00133 static sigc::signal<void, Gnome::Canvas::Item*> signal_item_left;
00134
00135 protected:
00136 ItemList _items;
00137 ConnectionList _connections;
00138 std::list< boost::shared_ptr<Item> > _selected_items;
00139 std::list< boost::shared_ptr<Connection> > _selected_connections;
00140
00141 virtual bool canvas_event(GdkEvent* event);
00142 virtual bool frame_event(GdkEvent* ev);
00143
00144 private:
00145
00146 friend class Module;
00147 bool port_event(GdkEvent* event, boost::weak_ptr<Port> port);
00148
00149 GVNodes layout_dot(bool use_length_hints, const std::string& filename);
00150
00151 void remove_connection(boost::shared_ptr<Connection> c);
00152 bool are_connected(boost::shared_ptr<const Connectable> tail,
00153 boost::shared_ptr<const Connectable> head);
00154
00155 void select_port(boost::shared_ptr<Port> p, bool unique = false);
00156 void select_port_toggle(boost::shared_ptr<Port> p, int mod_state);
00157 void unselect_port(boost::shared_ptr<Port> p);
00158 void selection_joined_with(boost::shared_ptr<Port> port);
00159 void join_selection();
00160
00161 boost::shared_ptr<Port> get_port_at(double x, double y);
00162
00163 bool scroll_drag_handler(GdkEvent* event);
00164 virtual bool select_drag_handler(GdkEvent* event);
00165 virtual bool connection_drag_handler(GdkEvent* event);
00166
00167 void ports_joined(boost::shared_ptr<Port> port1, boost::shared_ptr<Port> port2);
00168 bool animate_selected();
00169
00170 void on_parent_changed(Gtk::Widget* old_parent);
00171 sigc::connection _parent_event_connection;
00172
00173 typedef std::list< boost::shared_ptr<Port> > SelectedPorts;
00174 SelectedPorts _selected_ports;
00175 boost::shared_ptr<Port> _connect_port;
00176 boost::shared_ptr<Port> _last_selected_port;
00177
00178 double _zoom;
00179 double _width;
00180 double _height;
00181
00182 enum DragState { NOT_DRAGGING, CONNECTION, SCROLL, SELECT };
00183 DragState _drag_state;
00184
00185 bool _remove_objects;
00186 bool _locked;
00187
00188 FlowDirection _direction;
00189
00190 Gnome::Canvas::Rect _base_rect;
00191 Gnome::Canvas::Rect* _select_rect;
00192 ArtVpathDash* _select_dash;
00193 };
00194
00195
00196 }
00197
00198 #endif // FLOWCANVAS_CANVAS_HPP