00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef FLOWCANVAS_MODULE_HPP
00019 #define FLOWCANVAS_MODULE_HPP
00020
00021 #include <string>
00022 #include <algorithm>
00023 #include <boost/shared_ptr.hpp>
00024 #include <libgnomecanvasmm.h>
00025 #include "flowcanvas/Port.hpp"
00026 #include "flowcanvas/Item.hpp"
00027
00028 namespace FlowCanvas {
00029
00030 class Canvas;
00031
00032
00037 class Module : public Item
00038 {
00039 public:
00040 Module(boost::shared_ptr<Canvas> canvas,
00041 const std::string& name,
00042 double x = 0,
00043 double y = 0,
00044 bool show_title = true,
00045 bool show_port_labels = true);
00046
00047 virtual ~Module();
00048
00049 const PortVector& ports() const { return _ports; }
00050
00051 inline boost::shared_ptr<Port> get_port(const std::string& name) const;
00052
00053 void add_port(boost::shared_ptr<Port> port);
00054 void remove_port(boost::shared_ptr<Port> port);
00055 boost::shared_ptr<Port> port_at(double x, double y);
00056
00057 void zoom(double z);
00058 void resize();
00059
00060 bool show_port_labels(bool b) { return _show_port_labels; }
00061 void set_show_port_labels(bool b);
00062
00063 virtual void move(double dx, double dy);
00064 virtual void move_to(double x, double y);
00065
00066 virtual void set_name(const std::string& n);
00067
00068 double border_width() const { return _border_width; }
00069 void set_border_width(double w);
00070
00071 void select_tick();
00072 void set_selected(bool b);
00073
00074 void set_highlighted(bool b);
00075 void set_border_color(uint32_t c);
00076 void set_base_color(uint32_t c);
00077 void set_default_base_color();
00078 void set_stacked_border(bool b);
00079 void set_icon(const Glib::RefPtr<Gdk::Pixbuf>& icon);
00080
00081 size_t num_ports() const { return _ports.size(); }
00082
00083 double empty_port_breadth() const;
00084 double empty_port_depth() const;
00085
00086 protected:
00087 virtual bool on_event(GdkEvent* ev);
00088
00089 virtual void set_width(double w);
00090 virtual void set_height(double h);
00091
00092 void fit_canvas();
00093 void measure_ports();
00094 void resize_horiz();
00095 void resize_vert();
00096
00097 void port_renamed() { _port_renamed = true; }
00098
00099 void embed(Gtk::Container* widget);
00100
00101 double _border_width;
00102 bool _title_visible;
00103 double _embed_width;
00104 double _embed_height;
00105 double _icon_size;
00106 bool _port_renamed;
00107 double _widest_input;
00108 double _widest_output;
00109 bool _show_port_labels;
00110 double _title_width;
00111 double _title_height;
00112
00113 PortVector _ports;
00114
00115 Gnome::Canvas::Rect _module_box;
00116 Gnome::Canvas::Text _canvas_title;
00117 Gnome::Canvas::Rect* _stacked_border;
00118 Gnome::Canvas::Pixbuf* _icon_box;
00119 Gtk::Container* _embed_container;
00120 Gnome::Canvas::Widget* _embed_item;
00121
00122 private:
00123 friend class Canvas;
00124
00125 struct PortComparator {
00126 PortComparator(const std::string& name) : _name(name) {}
00127 inline bool operator()(const boost::shared_ptr<Port> port)
00128 { return (port && port->name() == _name); }
00129 const std::string& _name;
00130 };
00131
00132 void embed_size_request(Gtk::Requisition* req, bool force);
00133 };
00134
00135
00136
00137
00138
00139
00141 inline boost::shared_ptr<Port>
00142 Module::get_port(const std::string& port_name) const
00143 {
00144 PortComparator comp(port_name);
00145 PortVector::const_iterator i = std::find_if(_ports.begin(), _ports.end(), comp);
00146 return (i != _ports.end()) ? *i : boost::shared_ptr<Port>();
00147 }
00148
00149
00150 }
00151
00152 #endif // FLOWCANVAS_MODULE_HPP