UIndicatorContainer.h

00001 #ifndef _UINDICATORCONTAINER_H
00002 #define _UINDICATORCONTAINER_H
00003 // -------------------------------------------------------------------------
00004 #include <gtkmm.h>
00005 #include "UDefaultFunctions.h"
00006 #include "GuiPM.h"
00007 #include "ConfirmSignal.h"
00008 #include "ConfirmController.h"
00009 #include "USignals.h"
00010 #include "plugins.h"
00011 #include "global_macros.h"
00012 // -------------------------------------------------------------------------
00013 struct ChildInfo
00014 {
00015     ChildInfo ():
00016         sensor_id(-1),
00017         node_id(-1),
00018         value(0),
00019         state(false),
00020         wrong(true),
00021         priority(0),
00022         blink_time(DEFAULT_BLINK_TIME),
00023         blink(false),
00024         confirm(false),
00025         confirmed(true)
00026         {}
00027 
00028     UniSetTypes::ObjectId sensor_id;
00029     UniSetTypes::ObjectId node_id;
00030     long value;
00031     bool state;
00032 
00033     bool wrong;
00034 
00035     int priority;
00036 
00037     int blink_time;
00038     bool blink;
00039     bool confirm;
00040     bool confirmed;
00041 
00042     sigc::slot<void, bool> set_state;
00043 
00044     USignals::VConn in_connection;
00045     USignals::VConn out_connection;
00046     USignals::Connection message_connection;
00047     MsgConfirmConnection confirm_connection;
00048 };
00049 // -------------------------------------------------------------------------
00050 struct StateId
00051 {
00052     StateId ():
00053         _id(UniSetTypes::DefaultObjectId),
00054         _node(UniSetTypes::DefaultObjectId),
00055         _value(0),
00056         _msg_type(false)
00057     {}
00058     StateId( UniSetTypes::ObjectId id,
00059         UniSetTypes::ObjectId node,
00060         long value) :
00061         _id(id), _node(node), _value(value), _msg_type(false)
00062     {}
00063 
00064     bool operator< (const StateId& y) const {
00065         if (_id < y._id) return true;
00066         if (_id > y._id) return false;
00067         if (_node < y._node) return true;
00068         if (_node > y._node) return false;
00069         if (_value < y._value) return true;
00070         if (_value > y._value) return false;
00071         if (_msg_type < y._msg_type ) return true;
00072         else return false;
00073     }
00074 
00075     UniSetTypes::ObjectId _id;
00076     UniSetTypes::ObjectId _node;
00077     long _value;
00078     bool _msg_type;
00079 };
00080 // -------------------------------------------------------------------------
00081 typedef std::map<const Gtk::Widget*, ChildInfo*> ChildInfoMap;
00082 // -------------------------------------------------------------------------
00083 class IndConfirmCtl : public ConfirmCtl::ConfirmController<StateId>
00084 {
00085 public:
00086     IndConfirmCtl() {}
00087     virtual ~IndConfirmCtl() {}
00088 protected:
00089     void Error(const char* msg)
00090     { std::cerr << msg << std::endl; }
00091 };
00092 // -------------------------------------------------------------------------
00100 class UIndicatorContainer : public UDefaultFunctions<Gtk::HBox>
00101 {
00102 public:
00103     UIndicatorContainer();
00104     explicit UIndicatorContainer(GtkmmBaseType::BaseObjectType* gobject);
00105     virtual ~UIndicatorContainer();
00106 
00107     virtual void set_child_property_vfunc(GtkWidget* child,
00108             guint property_id,
00109             const GValue* value,
00110             GParamSpec* pspec);
00111     virtual void get_child_property_vfunc(GtkWidget* child,
00112             guint property_id,
00113             GValue* value,
00114             GParamSpec* pspec);
00115 
00116     virtual void sensorInfo(UniSetTypes::SensorMessage *sm) {}
00117     virtual void askSensors(UniversalIO::UIOCommand cmd) {}
00118     void startup_init(void);
00119 
00120     void on_page_changed();
00121     void set_page(int page);
00122 
00123     void set_child_sid(Gtk::Widget* child, UniSetTypes::ObjectId sid);
00124     void set_child_nodeid(Gtk::Widget* child, UniSetTypes::ObjectId nodeid);
00125     void set_child_value(Gtk::Widget* child, long value);
00126 
00127     void set_child_priority(Gtk::Widget* child, int priority);
00128     void set_child_blink_time(Gtk::Widget* child, int blink_time);
00129     void set_child_blink(Gtk::Widget* child, bool blink);
00130     void set_child_confirm(Gtk::Widget* child, bool confirm);
00131 
00132     UniSetTypes::ObjectId get_child_sid(Gtk::Widget* child);
00133     UniSetTypes::ObjectId get_child_nodeid(Gtk::Widget* child);
00134     long get_child_value(Gtk::Widget* child);
00135 
00136     bool get_child_blink(Gtk::Widget* child);
00137     bool get_child_blink_time(Gtk::Widget* child);
00138     bool get_child_confirm(Gtk::Widget* child);
00139 
00140     bool get_child_state(Gtk::Widget* child);
00141     int get_child_position(Gtk::Widget* child);
00142 
00143     void start_blink(int time);
00144     void stop_blink(Gtk::Widget* child = 0);
00145     void connect_confirm(sigc::slot<void>, UMessages::MessageId id);
00146 
00147     Glib::Property<int> property_page_;
00148 
00149 protected:
00150     virtual void on_add(Gtk::Widget* w);
00151     virtual void on_remove(Gtk::Widget* w);
00152     virtual bool on_expose_event(GdkEventExpose*);
00153     virtual void on_size_allocate(Gtk::Allocation& alloc);
00154     virtual void set_connector(const ConnectorRef& connector) throw();
00155 
00156     virtual void on_connect() throw();
00157     virtual void on_disconnect() throw();
00158 
00159     void child_on_connect(Gtk::Widget&);
00160 
00161 private:
00162     void ctor();
00163     Gtk::Widget* current_child_;
00164     IndConfirmCtl confirm_ctl_;
00165 
00166     ChildInfoMap childinfomap_;
00167 
00168     int prev_page_;
00169     bool checked_;
00170 
00171     sigc::connection connection_blink_;
00172 
00173     StateId get_child_state_id( Gtk::Widget* child);
00174     ConfirmCtl::StateInfo create_state_info( Gtk::Widget* child, StateId state_id);
00175     void connect_child(Gtk::Widget* child);
00176     void disconnect_child(Gtk::Widget& child);
00177     void update_msg_on( StateId id, bool* confirmed);
00178     void update_msg_off( StateId id, bool* confirmed);
00179 
00180     void blink(bool state, int time=DEFAULT_BLINK_TIME);
00181     void set_child_connector(Gtk::Widget&, bool empty = false);
00182 
00183     DISALLOW_COPY_AND_ASSIGN(UIndicatorContainer);
00184 };
00185 // -------------------------------------------------------------------------
00186 template<>
00187 inline GType UObj_Get_Type<UIndicatorContainer>()
00188 {
00189 static GType gtype = 0;
00190     if (gtype)
00191         return gtype;
00192 
00193     UIndicatorContainer* dummy = new UIndicatorContainer();
00194     GtkContainerClass* container_klass = GTK_CONTAINER_GET_CLASS( dummy->gobj() );
00195 
00196     GParamSpec* spec;
00197     spec = g_param_spec_long ("ch-sensor-id", "chsid", "Sensor ID", LONG_MIN, LONG_MAX, -1,
00198             GParamFlags(G_PARAM_READABLE|G_PARAM_WRITABLE));
00199     gtk_container_class_install_child_property( container_klass, 5,spec);
00200 
00201     spec = g_param_spec_long ("ch-node-id", "chnodeid", "Node ID", LONG_MIN, LONG_MAX, -1,
00202             GParamFlags(G_PARAM_READABLE|G_PARAM_WRITABLE));
00203     gtk_container_class_install_child_property( container_klass, 6, spec);
00204 
00205     spec = g_param_spec_int ("chblinktime", "chblinktime", "Blink Time", INT_MIN, INT_MAX, DEFAULT_BLINK_TIME,
00206                  GParamFlags(G_PARAM_READABLE|G_PARAM_WRITABLE));
00207     gtk_container_class_install_child_property( container_klass, 7, spec );
00208 
00209     spec =  g_param_spec_boolean ("chblink", "chblink", "Blink Flag", false,
00210         GParamFlags(G_PARAM_READABLE|G_PARAM_WRITABLE));
00211     gtk_container_class_install_child_property( container_klass, 8, spec );
00212 
00213     spec = g_param_spec_boolean ("chconfirm", "chconfirm", "Confirm Flag", false,
00214         GParamFlags(G_PARAM_READABLE|G_PARAM_WRITABLE));
00215     gtk_container_class_install_child_property( container_klass, 9, spec );
00216 
00217     spec = g_param_spec_long("chvalue", "chvalue", "Value", LONG_MIN, LONG_MAX, 0,
00218         GParamFlags(G_PARAM_READABLE|G_PARAM_WRITABLE));
00219     gtk_container_class_install_child_property( container_klass, 10, spec );
00220 
00221     spec = g_param_spec_int ("chpriority", "chpriority", "Priority", INT_MIN, INT_MAX, 0,
00222         GParamFlags(G_PARAM_READABLE|G_PARAM_WRITABLE));
00223     gtk_container_class_install_child_property( container_klass, 11, spec );
00224 
00225     gtype = G_OBJECT_TYPE(dummy->gobj());
00226     delete( dummy );
00227     Glib::wrap_register(gtype, &UObj_Wrap_New<UIndicatorContainer>);
00228 
00229     return gtype;
00230 }
00231 #endif

Документация по UniWidgets. Последние изменения: Fri Oct 10 09:57:50 2014. Создано системой  doxygen 1.5.9