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 */ 18 #ifndef ANIMLINK_H 19 #define ANIMLINK_H 20 21 #include "common.h" 22 namespace netanim 23 { 24 25 class AnimLink: public QGraphicsLineItem 26 { 27 public: 28 AnimLink (uint32_t fromId, uint32_t toId, 29 QString pointADescription = "", QString pointBDescription = "", 30 QString linkDescription = "", bool p2p = true); 31 32 ~AnimLink (); 33 uint32_t m_fromId; 34 uint32_t m_toId; 35 QString * m_pointADescription; 36 QString * m_pointBDescription; 37 QString * m_currentLinkDescription; 38 bool m_p2p; 39 40 void updateCurrentLinkDescription (QString linkDescription); 41 void resetCurrentLinkDescription (); 42 QString toString (); 43 QPointF getInterfacePosA (); 44 QPointF getInterfacePosB (); 45 QString getInterfaceADescription (); 46 QString getInterfaceBDescription (); 47 void repairLink (); 48 bool isP2p (); 49 50 protected: 51 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 52 private: 53 54 QString * m_originalLinkDescription; 55 56 QPointF getLinkDescriptionCenter (QPainter *, QPointF *); 57 QPointF m_interfacePosA; 58 QPointF m_interfacePosB; 59 60 }; 61 62 class LinkManager 63 { 64 public: 65 typedef QVector <AnimLink *> AnimLinkVector_t; 66 typedef std::map <uint32_t, AnimLinkVector_t> NodeIdAnimLinkVectorMap_t; 67 static LinkManager * getInstance (); 68 AnimLink * addLink (uint32_t fromId, uint32_t toId, 69 QString pointADescription, 70 QString pointBDescription, QString linkDescription, bool p2p = true); 71 72 73 NodeIdAnimLinkVectorMap_t * getLinks (); 74 AnimLink * getAnimLink (uint32_t fromId, uint32_t toId, bool p2p = true); 75 void updateLink (uint32_t fromId, uint32_t toId, QString linkDescription); 76 void repairLinks (uint32_t nodeId); 77 void systemReset (); 78 79 private: 80 LinkManager (); 81 //AnimLinkVector_t m_pointToPointLinks; 82 NodeIdAnimLinkVectorMap_t m_pointToPointLinks; 83 84 }; 85 86 87 88 } // namespace netanim 89 90 #endif // ANIMLINK_H 91