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
00039
00053 class Canvas : boost::noncopyable
00054 , public boost::enable_shared_from_this<Canvas>
00055 , public Gnome::Canvas::CanvasAA
00056
00057 {
00058 public:
00059 Canvas(double width, double height);
00060 virtual ~Canvas();
00061
00062 void destroy();
00063
00064 void add_item(boost::shared_ptr<Item> i);
00065 bool remove_item(boost::shared_ptr<Item> i);
00066
00067 boost::shared_ptr<Connection>
00068 get_connection(boost::shared_ptr<Connectable> tail,
00069 boost::shared_ptr<Connectable> head) const;
00070
00071 bool add_connection(boost::shared_ptr<Connectable> tail,
00072 boost::shared_ptr<Connectable> head,
00073 uint32_t color);
00074
00075 bool add_connection(boost::shared_ptr<Connection> connection);
00076
00077 boost::shared_ptr<Connection> remove_connection(boost::shared_ptr<Connectable> tail,
00078 boost::shared_ptr<Connectable> head);
00079
00080 void set_default_placement(boost::shared_ptr<Module> m);
00081
00082 void clear_selection();
00083 void select_item(boost::shared_ptr<Item> item);
00084 void unselect_ports();
00085 void unselect_item(boost::shared_ptr<Item> item);
00086 void unselect_connection(Connection* c);
00087
00088 ItemList& items() { return _items; }
00089 ItemList& selected_items() { return _selected_items; }
00090 ConnectionList& connections() { return _connections; }
00091 ConnectionList& selected_connections() { return _selected_connections; }
00092
00093 void lock(bool l);
00094 bool locked() const { return _locked; }
00095
00096 double get_zoom() { return _zoom; }
00097 void set_zoom(double pix_per_unit);
00098 void zoom_full();
00099
00100 void render_to_dot(const std::string& filename);
00101 virtual void arrange(bool use_length_hints=false);
00102
00103 double width() const { return _width; }
00104 double height() const { return _height; }
00105
00106 void resize(double width, double height);
00107 void resize_all_items();
00108
00111 ArtVpathDash* select_dash() { return _select_dash; }
00112
00114 virtual void connect(boost::shared_ptr<Connectable> ,
00115 boost::shared_ptr<Connectable> ) {}
00116
00118 virtual void disconnect(boost::shared_ptr<Connectable> ,
00119 boost::shared_ptr<Connectable> ) {}
00120
00121 protected:
00122 ItemList _items;
00123 ConnectionList _connections;
00124 std::list< boost::shared_ptr<Item> > _selected_items;
00125 std::list< boost::shared_ptr<Connection> > _selected_connections;
00126
00127 virtual bool canvas_event(GdkEvent* event);
00128 virtual bool frame_event(GdkEvent* ev);
00129
00130 private:
00131
00132 friend class Module;
00133 bool port_event(GdkEvent* event, boost::weak_ptr<Port> port);
00134
00135 void remove_connection(boost::shared_ptr<Connection> c);
00136 bool are_connected(boost::shared_ptr<const Connectable> tail,
00137 boost::shared_ptr<const Connectable> head);
00138
00139 void select_port(boost::shared_ptr<Port> p, bool unique = false);
00140 void select_port_toggle(boost::shared_ptr<Port> p, int mod_state);
00141 void unselect_port(boost::shared_ptr<Port> p);
00142 void selection_joined_with(boost::shared_ptr<Port> port);
00143 void join_selection();
00144
00145 boost::shared_ptr<Port> get_port_at(double x, double y);
00146
00147 bool scroll_drag_handler(GdkEvent* event);
00148 virtual bool select_drag_handler(GdkEvent* event);
00149 virtual bool connection_drag_handler(GdkEvent* event);
00150
00151 void ports_joined(boost::shared_ptr<Port> port1, boost::shared_ptr<Port> port2);
00152 bool animate_selected();
00153
00154 void scroll_to_center();
00155 void on_parent_changed(Gtk::Widget* old_parent);
00156 sigc::connection _parent_event_connection;
00157
00158 typedef std::list< boost::shared_ptr<Port> > SelectedPorts;
00159 SelectedPorts _selected_ports;
00160 boost::shared_ptr<Port> _connect_port;
00161 boost::shared_ptr<Port> _last_selected_port;
00162
00163 double _zoom;
00164 double _width;
00165 double _height;
00166
00167 enum DragState { NOT_DRAGGING, CONNECTION, SCROLL, SELECT };
00168 DragState _drag_state;
00169
00170 bool _remove_objects;
00171 bool _locked;
00172
00173 Gnome::Canvas::Rect _base_rect;
00174 Gnome::Canvas::Rect* _select_rect;
00175 ArtVpathDash* _select_dash;
00176 };
00177
00178
00179 }
00180
00181 #endif // FLOWCANVAS_CANVAS_HPP