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 * Makhtar Diouf <makhtar.diouf@gmail.com> 20 */ 21 22 #ifndef AnimatorPlugin_H 23 #define AnimatorPlugin_H 24 25 #include "common.h" 26 #include "animatorconstants.h" 27 #include "animatorscene.h" 28 #include "animatorview.h" 29 #include "mode.h" 30 #include "timevalue.h" 31 #include "animevent.h" 32 #include "QtTreePropertyBrowser" 33 34 namespace netanim 35 { 36 37 38 typedef struct { 39 QString fileName; 40 qreal x; 41 qreal y; 42 qreal scaleX; 43 qreal scaleY; 44 qreal opacity; 45 46 } BackgroudImageProperties_t; 47 48 class AnimatorMode: public Mode 49 { 50 Q_OBJECT 51 52 public: 53 // Getters 54 55 static AnimatorMode * getInstance (); 56 QWidget * getCentralWidget (); 57 QString getTabName (); 58 qreal getCurrentNodeSize (); 59 QGraphicsPixmapItem * getBackground (); 60 TimeValue<AnimEvent *>* getEvents (); 61 qreal getLastPacketEventTime (); 62 qreal getThousandthPacketTime (); 63 qreal getFirstPacketTime (); 64 65 // Setters 66 67 void setParsingCount (uint64_t parsingCount); 68 void setVersion (double version); 69 void setWPacketDetected (); 70 void setFocus (bool focus); 71 void setCurrentTime (qreal currentTime); 72 void addAnimEvent (qreal t, AnimEvent *); 73 void setNodeSize (AnimNode * animNode, qreal size); 74 void setNodePos (AnimNode * animNode, qreal x, qreal y); 75 void setNodeResource (AnimNode * animNode, uint32_t resourceId); 76 void setNodeSysId (AnimNode * animNode, uint32_t sysId); 77 void setShowNodeTrajectory (AnimNode * animNode); 78 void setBackgroundImageProperties (BackgroudImageProperties_t prop); 79 BackgroudImageProperties_t getBackgroundProperties (); 80 81 // Actions 82 83 bool keepAppResponsive (); 84 void showPopup (QString msg); 85 void externalPauseEvent (); 86 void start (); 87 void openPropertyBroswer (); 88 89 private: 90 91 // state 92 typedef enum 93 { 94 APP_INIT, 95 APP_START, 96 SYSTEM_RESET_IN_PROGRESS, 97 SYSTEM_RESET_COMPLETE, 98 PLAYING, 99 PAUSING, 100 SIMULATION_COMPLETE 101 } AnimatorModeState_t; 102 double m_version; 103 bool m_playing; 104 AnimatorModeState_t m_state; 105 QTimer * m_updateRateTimer; 106 double m_currentTime; 107 qreal m_currentZoomFactor; 108 bool m_showWiressCircles; 109 double m_updateRates[UPDATE_RATE_SLIDER_MAX]; 110 double m_currentUpdateRate; 111 double m_parsedMaxSimulationTime; 112 int m_oldTimelineValue; 113 QVector <QWidget *> m_toolButtonVector; 114 QTime m_appResponsiveTimer; 115 bool m_simulationCompleted; 116 uint64_t m_rxCount; 117 TimeValue<AnimEvent *> m_events; 118 bool m_showPacketMetaInfo; 119 QString m_traceFileName; 120 bool m_showPackets; 121 bool m_fastForwarding; 122 qreal m_lastPacketEventTime; 123 qreal m_firstPacketEventTime; 124 std::map <AnimPacket *, AnimPacket *> m_wiredPacketsToAnimate; 125 std::map <AnimPacket *, AnimPacket *> m_wirelessPacketsToAnimate; 126 qreal m_thousandthPacketTime; 127 qreal m_pauseAtTime; 128 bool m_pauseAtTimeTriggered; 129 BackgroudImageProperties_t m_backgroundImageProperties; 130 QPointF m_minPoint; 131 QPointF m_maxPoint; 132 bool m_backgroundExists; 133 134 135 136 137 //controls 138 QVBoxLayout * m_vLayout; 139 QLabel * m_gridLinesLabel; 140 QLabel * m_nodeSizeLabel; 141 QToolButton * m_gridButton; 142 QToolButton * m_batteryCapacityButton; 143 QSpinBox * m_gridLinesSpinBox; 144 QComboBox * m_nodeSizeComboBox; 145 QToolButton * m_testButton; 146 QToolButton * m_showIpButton; 147 QToolButton * m_showMacButton; 148 QToolButton * m_showNodeIdButton; 149 QToolButton * m_showNodeSysIdButton; 150 QToolButton * m_playButton; 151 QToolButton * m_fileOpenButton; 152 QToolButton * m_reloadFileButton; 153 QToolButton * m_zoomInButton; 154 QToolButton * m_zoomOutButton; 155 QToolButton * m_showWirelessCirclesButton; 156 QSlider * m_updateRateSlider; 157 QLabel * m_fastRateLabel; 158 QLabel * m_slowRateLabel; 159 QLCDNumber * m_qLcdNumber; 160 QWidget * m_centralWidget; 161 QDialog * m_parsingXMLDialog; 162 QDialog * m_transientDialog; 163 QToolBar * m_topToolBar; 164 QToolButton * m_packetStatsButton; 165 QSplitter * m_mainSplitter; 166 QToolButton * m_nodeTrajectoryButton; 167 QLabel * m_timelineSliderLabel; 168 QToolBar * m_verticalToolbar; 169 QLabel * m_pktFilterFromLabel; 170 QComboBox * m_pktFilterFromComboBox; 171 QLabel * m_pktFilterToLabel; 172 QComboBox * m_pktFilterToComboBox; 173 QToolButton * m_blockPacketsButton; 174 QToolBar * m_bottomToolbar; 175 QLabel * m_bottomStatusLabel; 176 QToolButton * m_resetButton; 177 QToolButton * m_showMetaButton; 178 QProgressBar * m_parseProgressBar; 179 QSlider * m_simulationTimeSlider; 180 QToolButton * m_showRoutePathButton; 181 QToolButton * m_showPropertiesButton; 182 QParallelAnimationGroup * m_buttonAnimationGroup; 183 QLabel * m_pauseAtLabel; 184 QLineEdit * m_pauseAtEdit; 185 QToolButton * m_stepButton; 186 QToolButton * m_mousePositionButton; 187 188 189 190 //functions 191 AnimatorMode (); 192 bool parseXMLTraceFile (QString traceFileName); 193 void setLabelStyleSheet (); 194 void initUpdateRate (); 195 void enableAllToolButtons (bool show); 196 qreal nodeSizeStringToValue (QString nodeSize); 197 void systemReset (); 198 void preParse (); 199 void postParse (); 200 void initToolbars (); 201 void initLabels (); 202 void initControls (); 203 void setTopToolbarWidgets (); 204 void setVerticalToolbarWidgets (); 205 void setBottomToolbarWidgets (); 206 void setToolButtonVector (); 207 void setControlDefaults (); 208 bool checkSimulationCompleted (); 209 void doSimulationCompleted (); 210 void timerCleanup (); 211 void showParsingXmlDialog (bool show); 212 void showTransientDialog (bool show, QString msg = ""); 213 void setProgressBarRange (uint64_t rxCount); 214 void init (); 215 void showAnimatorView (bool show); 216 void showPackets (bool show); 217 void setMaxSimulationTime (double maxTime); 218 void resetBackground (); 219 void displayPacket (qreal t); 220 void dispatchEvents (); 221 void setSimulationCompleted (); 222 void purgeWiredPackets (bool sysReset = false); 223 void purgeWirelessPackets (); 224 void purgeAnimatedNodes (); 225 void fastForward (qreal t); 226 void reset (); 227 QPropertyAnimation * getButtonAnimation (QToolButton * toolButton); 228 void initPropertyBrowser (); 229 void removeWiredPacket (AnimPacket * animPacket); 230 231 232 private slots: 233 void testSlot (); 234 void clickTraceFileOpenSlot (); 235 void reloadFileSlot (); 236 void clickZoomInSlot (); 237 void clickZoomOutSlot (); 238 void clickResetSlot (); 239 void clickPlaySlot (); 240 void simulationSliderPressedSlot (); 241 void updateTimelineSlot (int value); 242 void updateTimelineSlot (); 243 void updateRateTimeoutSlot (); 244 void updateGridLinesSlot (int value); 245 void updateNodeSizeSlot (QString value); 246 void updateUpdateRateSlot (int); 247 void showGridLinesSlot (); 248 void showNodeIdSlot (); 249 void showNodeSysIdSlot (); 250 void showMetaSlot (); 251 void showPacketSlot (); 252 void showWirelessCirclesSlot (); 253 void showPacketStatsSlot (); 254 void showNodePositionStatsSlot (); 255 void showIpSlot (); 256 void showMacSlot (); 257 void showRoutePathSlot (); 258 void showBatteryCapacitySlot (); 259 void buttonAnimationGroupFinishedSlot (); 260 void showPropertiesSlot (); 261 void pauseAtTimeSlot (); 262 void stepSlot (); 263 void enableMousePositionSlot (); 264 }; 265 266 267 } // namespace netanim 268 269 #endif // AnimatorPlugin_H 270