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