• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

/builddir/build/BUILD/flowcanvas-0.6.4/flowcanvas/Canvas.hpp

Go to the documentation of this file.
00001 /* This file is part of FlowCanvas.
00002  * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
00003  *
00004  * FlowCanvas is free software; you can redistribute it and/or modify it under the
00005  * terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * FlowCanvas is distributed in the hope that it will be useful, but WITHOUT ANY
00010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
00012  *
00013  * You should have received a copy of the GNU General Public License along
00014  * with this program; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
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 /*CANVASBASE*/Gnome::Canvas::CanvasAA
00057 // (CANVASBASE is a hook for a sed script in configure.ac)
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, bool center=true);
00103 
00104     void move_contents_to(double x, double y);
00105 
00106     double width() const  { return _width; }
00107     double height() const { return _height; }
00108 
00109     void resize(double width, double height);
00110     void resize_all_items();
00111 
00112     void scroll_to_center();
00113 
00114     enum FlowDirection {
00115         HORIZONTAL,
00116         VERTICAL
00117     };
00118 
00119     void set_direction(FlowDirection d) { _direction = d; }
00120     FlowDirection direction() const     { return _direction; }
00121 
00124     ArtVpathDash* select_dash() { return _select_dash; }
00125 
00127     virtual void connect(boost::shared_ptr<Connectable> /*tail*/,
00128                          boost::shared_ptr<Connectable> /*head*/) {}
00129 
00131     virtual void disconnect(boost::shared_ptr<Connectable> /*tail*/,
00132                             boost::shared_ptr<Connectable> /*head*/) {}
00133 
00134     static sigc::signal<void, Gnome::Canvas::Item*> signal_item_entered;
00135     static sigc::signal<void, Gnome::Canvas::Item*> signal_item_left;
00136 
00137 protected:
00138     ItemList                                   _items;  
00139     ConnectionList                             _connections;  
00140     std::list< boost::shared_ptr<Item> >       _selected_items;  
00141     std::list< boost::shared_ptr<Connection> > _selected_connections;  
00142 
00143     virtual bool canvas_event(GdkEvent* event);
00144     virtual bool frame_event(GdkEvent* ev);
00145 
00146 private:
00147 
00148     friend class Module;
00149     bool port_event(GdkEvent* event, boost::weak_ptr<Port> port);
00150 
00151     GVNodes layout_dot(bool use_length_hints, const std::string& filename);
00152 
00153     void remove_connection(boost::shared_ptr<Connection> c);
00154     bool are_connected(boost::shared_ptr<const Connectable> tail,
00155                        boost::shared_ptr<const Connectable> head);
00156 
00157     void select_port(boost::shared_ptr<Port> p, bool unique = false);
00158     void select_port_toggle(boost::shared_ptr<Port> p, int mod_state);
00159     void unselect_port(boost::shared_ptr<Port> p);
00160     void selection_joined_with(boost::shared_ptr<Port> port);
00161     void join_selection();
00162 
00163     boost::shared_ptr<Port> get_port_at(double x, double y);
00164 
00165     bool         scroll_drag_handler(GdkEvent* event);
00166     virtual bool select_drag_handler(GdkEvent* event);
00167     virtual bool connection_drag_handler(GdkEvent* event);
00168 
00169     void ports_joined(boost::shared_ptr<Port> port1, boost::shared_ptr<Port> port2);
00170     bool animate_selected();
00171 
00172     void move_contents_to_internal(double x, double y, double min_x, double min_y);
00173 
00174     void on_parent_changed(Gtk::Widget* old_parent);
00175     sigc::connection _parent_event_connection;
00176 
00177     typedef std::list< boost::shared_ptr<Port> > SelectedPorts;
00178     SelectedPorts _selected_ports; 
00179     boost::shared_ptr<Port> _connect_port;  
00180     boost::shared_ptr<Port> _last_selected_port;
00181 
00182     double _zoom;   
00183     double _width;
00184     double _height;
00185 
00186     enum DragState { NOT_DRAGGING, CONNECTION, SCROLL, SELECT };
00187     DragState      _drag_state;
00188 
00189     bool _remove_objects; // flag to avoid removing objects from destructors when unnecessary
00190     bool _locked;
00191 
00192     FlowDirection _direction;
00193 
00194     Gnome::Canvas::Rect  _base_rect;   
00195     Gnome::Canvas::Rect* _select_rect; 
00196     ArtVpathDash*        _select_dash; 
00197 };
00198 
00199 
00200 } // namespace FlowCanvas
00201 
00202 #endif // FLOWCANVAS_CANVAS_HPP

Generated on Thu Sep 30 2010 for FlowCanvas by  doxygen 1.7.1