1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License version 2 as 5 * published by the Free Software Foundation; 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 * 16 * Author: John Abraham <john.abraham.in@gmail.com> 17 * Contributions: Eugene Kalishenko <ydginster@gmail.com> (Open Source and Linux Laboratory http://dev.osll.ru/) 18 * Dmitrii Shakshin <d.shakshin@gmail.com> (Open Source and Linux Laboratory http://dev.osll.ru/) 19 */ 20 #ifndef ANIMNODE_H 21 #define ANIMNODE_H 22 23 #include "common.h" 24 #include "resizeableitem.h" 25 26 namespace netanim 27 { 28 29 typedef 30 struct { 31 qreal t; 32 QPointF p; 33 } TimePosition_t; 34 35 class AnimNode: public ResizeableItem 36 { 37 public: 38 typedef QSet <QString> Ipv4Set_t; 39 typedef QSet <QString> Ipv6Set_t; 40 41 typedef QVector <QString> MacVector_t; 42 typedef std::map <uint32_t, uint32_t> CounterIdValueUint32_t; 43 typedef std::map <uint32_t, double> CounterIdValueDouble_t; 44 45 typedef enum { 46 UINT32_COUNTER, 47 DOUBLE_COUNTER 48 } CounterType_t; 49 50 AnimNode (uint32_t nodeId, uint32_t nodeSysId, qreal x, qreal y, QString nodeDescription); 51 ~AnimNode (); 52 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 53 void mouseMoveEvent (QGraphicsSceneMouseEvent *event); 54 void setNodeDescription (QString description); 55 QPointF getCenter (); 56 QGraphicsTextItem * getDescription (); 57 qreal getX (); 58 qreal getY (); 59 void setX (qreal x); 60 void setY (qreal y); 61 bool getShowNodeTrajectory (); 62 QColor getColor (); 63 uint32_t getNodeId (); 64 uint32_t getNodeSysId (); 65 qreal getWidth (); 66 int getResourceId (); 67 Ipv4Set_t getIpv4Addresses (); 68 Ipv6Set_t getIpv6Addresses (); 69 MacVector_t getMacAddresses (); 70 void setWidth (qreal width); 71 void setHeight (qreal height); 72 void setColor (uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255); 73 void setResource (int resourceId); 74 void setPos (qreal x, qreal y); 75 void setShowNodeTrajectory (bool showNodeTrajectory); 76 void addIpv4Address (QString ip); 77 void addIpv6Address (QString ip); 78 void addMacAddress (QString mac); 79 bool hasIpv4 (QString ip); 80 bool hasMac (QString mac); 81 void showNodeId (bool show); 82 void showNodeSysId (bool show); 83 bool isVisibleNodeSysId () const; 84 void updateCounter (uint32_t counterId, qreal counterValue, CounterType_t counterType); 85 86 qreal getDoubleCounterValue (uint32_t counterId, bool & result); 87 uint32_t getUint32CounterValue (uint32_t counterId, bool & result); 88 void updateBatteryCapacityImage (bool show); 89 void updateNodeSysId (uint32_t nodeSysId, bool show); 90 91 private: 92 QGraphicsTextItem * m_nodeDescription; 93 uint32_t m_nodeId; 94 uint32_t m_nodeSysId; 95 qreal m_x; 96 qreal m_y; 97 bool m_showNodeId; 98 bool m_showNodeSysId; 99 Ipv4Set_t m_ipv4Set; 100 Ipv6Set_t m_ipv6Set; 101 MacVector_t m_macVector; 102 int m_resourceId; 103 bool m_showNodeTrajectory; 104 QPixmap m_batteryPixmap; //!< Battery image 105 bool m_showBatteryCapcity; 106 107 QColor m_lastColor; 108 109 CounterIdValueUint32_t m_counterIdToValuesUint32; 110 CounterIdValueDouble_t m_counterIdToValuesDouble; 111 112 }; 113 114 115 class AnimNodeMgr 116 { 117 public: 118 typedef std::map <uint32_t, AnimNode *> NodeIdAnimNodeMap_t; 119 typedef QVector <TimePosition_t> TimePosVector_t; 120 typedef std::map <uint32_t, TimePosVector_t> NodeIdPositionMap_t; 121 typedef std::map <uint32_t, QString> CounterIdName_t; 122 123 static AnimNodeMgr * getInstance (); 124 AnimNode * getNode (uint32_t nodeId); 125 AnimNode * add (uint32_t nodeId, uint32_t nodeSysId, qreal x, qreal y, QString nodeDescription); 126 uint32_t getCount (); 127 QPointF getMinPoint (); 128 QPointF getMaxPoint (); 129 void systemReset (); 130 void addIpv4Address (uint32_t nodeId, QString ip); 131 void addIpv6Address (uint32_t nodeId, QString ip); 132 void addMacAddress (uint32_t nodeId, QString mac); 133 void setSize (qreal width, qreal height); 134 void showNodeId (bool show); 135 void showNodeSysId (bool show); 136 TimePosVector_t getPositions (uint32_t nodeId); 137 void addAPosition (uint32_t nodeId, qreal t, QPointF pos); 138 void showRemainingBatteryCapacity (bool show); 139 140 void addNodeCounterUint32 (uint32_t counterId, QString counterName); 141 void addNodeCounterDouble (uint32_t counterId, QString counterName); 142 void updateNodeCounter (uint32_t nodeId, uint32_t counterId, qreal counterValue); 143 144 CounterIdName_t getUint32CounterNames (); 145 CounterIdName_t getDoubleCounterNames (); 146 uint32_t getCounterIdForName (QString counterName, bool & result, AnimNode::CounterType_t & counterType); 147 148 private: 149 AnimNodeMgr (); 150 NodeIdAnimNodeMap_t m_nodes; 151 qreal m_minX; 152 qreal m_minY; 153 qreal m_maxX; 154 qreal m_maxY; 155 NodeIdPositionMap_t m_nodePositions; 156 CounterIdName_t m_counterIdToNamesUint32; 157 CounterIdName_t m_counterIdToNamesDouble; 158 159 }; 160 161 162 } 163 #endif // ANIMNODE_H 164