Fix grid lines draft default tip
authorJohn Abraham <john.abraham.in@gmail.com>
Sun, 12 Jan 2014 17:59:47 -0800
changeset 198 a22e3de633ef
parent 197 2377eee84cf8
Fix grid lines
animatormode.cpp
animatormode.h
animatorscene.cpp
animevent.h
animpropertybrowser.h
animxmlparser.h
common.h
log.cpp
packetsmode.cpp
packetsmode.h
packetsscene.cpp
packetsscene.h
qrc_qtpropertybrowser.cpp
qrc_resources.cpp
table.cpp
table.h
--- a/animatormode.cpp	Sun Jan 12 16:14:23 2014 -0800
+++ b/animatormode.cpp	Sun Jan 12 17:59:47 2014 -0800
@@ -47,13 +47,13 @@
   m_simulationCompleted (false),
   m_showPacketMetaInfo (true),
   m_showPackets (true),
+  m_packetAnimationGroup (0),
   m_fastForwarding (false),
-  m_parsingXMLDialog (0),
-  m_packetAnimationGroup (0),
   m_lastPacketEventTime (-1),
   m_pauseAtTime (65535),
   m_pauseAtTimeTriggered (false),
-  m_backgroundExists (false)
+  m_backgroundExists (false),
+  m_parsingXMLDialog (0)
 
 {
   init ();
--- a/animatormode.h	Sun Jan 12 16:14:23 2014 -0800
+++ b/animatormode.h	Sun Jan 12 17:59:47 2014 -0800
@@ -114,6 +114,7 @@
   bool m_showPacketMetaInfo;
   QString m_traceFileName;
   bool m_showPackets;
+  QParallelAnimationGroup * m_packetAnimationGroup;
   bool m_fastForwarding;
   qreal m_lastPacketEventTime;
   qreal m_firstPacketEventTime;
@@ -128,6 +129,7 @@
 
 
 
+
   //controls
   QVBoxLayout * m_vLayout;
   QLabel * m_gridLinesLabel;
@@ -171,7 +173,6 @@
   QSlider * m_simulationTimeSlider;
   QToolButton * m_showRoutePathButton;
   QToolButton * m_showPropertiesButton;
-  QParallelAnimationGroup * m_packetAnimationGroup;
   QParallelAnimationGroup * m_buttonAnimationGroup;
   QLabel * m_pauseAtLabel;
   QLineEdit * m_pauseAtEdit;
--- a/animatorscene.cpp	Sun Jan 12 16:14:23 2014 -0800
+++ b/animatorscene.cpp	Sun Jan 12 17:59:47 2014 -0800
@@ -463,9 +463,12 @@
 void
 AnimatorScene::markGridCoordinates ()
 {
+  QRectF simulationRect (m_minPoint, m_maxPoint);
+  if (!(simulationRect.width ()) || !(simulationRect.height ()))
+    return;
   int i = 0;
-  for (qreal x = 0; x <= sceneRect ().width () ; x = x + (sceneRect ().width ()/2))
-    for (qreal y = 0; y <= sceneRect ().height () ; y = y + (sceneRect ().height ()/2))
+  for (qreal x = 0; x <= simulationRect.right () ; x = x + (simulationRect.right ()/2))
+    for (qreal y = 0; y <= simulationRect.bottom () ; y = y + (simulationRect.bottom ()/2))
       {
         QString text = QString::number (qRound (x))
                        + ","
@@ -483,10 +486,10 @@
 {
   m_showGrid = true;
   QRectF simulationRect (m_minPoint, m_maxPoint);
-  qreal xStep =  simulationRect.width ()/ (m_nGridLines-1);
-  qreal yStep = simulationRect.height ()/ (m_nGridLines-1);
-  xStep = ceil (xStep);
-  yStep = ceil (yStep);
+  qreal xStep = (simulationRect.right ())/ (m_nGridLines-1);
+  qreal yStep = (simulationRect.bottom ())/ (m_nGridLines-1);
+  //xStep = ceil (xStep);
+  //yStep = ceil (yStep);
   QPen pen (QColor (100, 100, 155, 125));
 
   // draw horizontal grid
@@ -494,12 +497,12 @@
   qreal x;
   for (int c = 0; c < m_nGridLines; ++c, y += yStep)
     {
-      m_gridLines.push_back (addLine (0, y, simulationRect.right () + xStep, y, pen));
+      m_gridLines.push_back (addLine (0, y, simulationRect.right (), y, pen));
     }
   // now draw vertical grid
   for (int c = 0; c < m_nGridLines; ++c, x += xStep)
     {
-      m_gridLines.push_back (addLine (x, 0, x,  simulationRect.bottom () + yStep, pen));
+      m_gridLines.push_back (addLine (x, 0, x,  simulationRect.bottom (), pen));
     }
   initGridCoordinates ();
   markGridCoordinates ();
--- a/animevent.h	Sun Jan 12 16:14:23 2014 -0800
+++ b/animevent.h	Sun Jan 12 17:59:47 2014 -0800
@@ -30,8 +30,6 @@
   typedef enum
   {
     PACKET_FBTX_EVENT,
-    PACKET_FBRX_EVENT,
-    PACKET_LBTX_EVENT,
     PACKET_LBRX_EVENT,
     ADD_NODE_EVENT,
     UPDATE_NODE_POS_EVENT,
@@ -208,20 +206,6 @@
 
 };
 
-
-class AnimPacketLbTxEvent: public AnimEvent
-{
-public:
-  AnimPacketLbTxEvent (void * p):
-    AnimEvent (PACKET_LBTX_EVENT),
-    m_pkt (p)
-  {
-  }
-  void * m_pkt;
-
-};
-
-
 class AnimPacketLbRxEvent: public AnimEvent
 {
 public:
--- a/animpropertybrowser.h	Sun Jan 12 16:14:23 2014 -0800
+++ b/animpropertybrowser.h	Sun Jan 12 17:59:47 2014 -0800
@@ -78,6 +78,8 @@
   QtProperty * m_backgroundScaleY;
   QtProperty * m_backgroundOpacity;
 
+  uint32_t m_currentNodeId;
+
   QtIntPropertyManager * m_intManager;
   QtStringPropertyManager * m_stringManager;
   QtDoublePropertyManager * m_doubleManager;
@@ -85,9 +87,9 @@
 
   QtColorPropertyManager * m_colorManager;
   FilePathManager * m_filePathManager;
+  QtGroupPropertyManager * m_nodePositionManager;
   QtGroupPropertyManager * m_ipv4AddressManager;
   QtGroupPropertyManager * m_macAddressManager;
-  QtGroupPropertyManager * m_nodePositionManager;
   QtStringPropertyManager * m_staticStringManager;
   QtBoolPropertyManager * m_boolManager;
 
@@ -99,7 +101,6 @@
 
 
 
-  uint32_t m_currentNodeId;
   typedef std::map <QtProperty *, QString> PropertyIdMap_t;
   PropertyIdMap_t m_propertyId;
 private slots:
--- a/animxmlparser.h	Sun Jan 12 16:14:23 2014 -0800
+++ b/animxmlparser.h	Sun Jan 12 17:59:47 2014 -0800
@@ -151,8 +151,8 @@
   QXmlStreamReader * m_reader;
   QFile * m_traceFile;
   double m_maxSimulationTime;
+  bool m_fileIsValid;
   qreal m_lastPacketEventTime;
-  bool m_fileIsValid;
   double m_version;
   qreal m_thousandThPacketTime;
   qreal m_firstPacketTime;
--- a/common.h	Sun Jan 12 16:14:23 2014 -0800
+++ b/common.h	Sun Jan 12 17:59:47 2014 -0800
@@ -39,6 +39,7 @@
 #include <QScrollBar>
 #include <QTableWidget>
 #include <QCheckBox>
+#include <QRegExp>
 
 
 #include "log.h"
--- a/log.cpp	Sun Jan 12 16:14:23 2014 -0800
+++ b/log.cpp	Sun Jan 12 17:59:47 2014 -0800
@@ -238,6 +238,7 @@
       cur = next + 1;
     }
 #endif
+  (void)name;
 }
 
 
@@ -443,6 +444,7 @@
     }
 }
 
+#if NETANIM
 static bool ComponentExists(std::string componentName)
 {
   char const*name=componentName.c_str();
@@ -461,6 +463,7 @@
   // nothing matched
   return false;
 }
+#endif
 
 static void CheckEnvironmentVariables (void)
 {
--- a/packetsmode.cpp	Sun Jan 12 16:14:23 2014 -0800
+++ b/packetsmode.cpp	Sun Jan 12 17:59:47 2014 -0800
@@ -25,6 +25,7 @@
 #define TIME_EDIT_MASK "dddd.ddddddddd"
 #define ALLOWED_NODES_WITH 300
 #define ALLOWED_NODES "0:1:2:3:4:5:6:7:8:9"
+#define REGEX_EDIT_WIDTH 300
 
 namespace netanim {
 PacketsMode * pPacketsMode = 0;
@@ -113,6 +114,9 @@
   m_olsrFilterCb = new QCheckBox ("Olsr");
 
 
+  m_regexFilterLabel = new QLabel ("Regex on meta data");
+  m_regexFilterEdit = new QLineEdit (".*");
+  m_regexFilterEdit->setMaximumWidth (REGEX_EDIT_WIDTH);
 
   m_packetsTable = new Table;
   QStringList packetTableHeaders;
@@ -130,6 +134,11 @@
   m_filterToolBar->addWidget (m_ethernetFilterCb);
   m_filterToolBar->addWidget (m_pppFilterCb);
   m_filterToolBar->addWidget (m_aodvFilterCb);
+  m_filterToolBar->addWidget (m_olsrFilterCb);
+  m_filterToolBar->addWidget (m_arpFilterCb);
+  m_filterToolBar->addSeparator ();
+  m_filterToolBar->addWidget (m_regexFilterLabel);
+  m_filterToolBar->addWidget (m_regexFilterEdit);
 
   m_mainSplitter = new QSplitter;
   m_vLayout = new QVBoxLayout;
@@ -161,6 +170,9 @@
   connect (m_ethernetFilterCb, SIGNAL(clicked()), this, SLOT(filterClickedSlot()));
   connect (m_pppFilterCb, SIGNAL(clicked()), this, SLOT(filterClickedSlot()));
   connect (m_aodvFilterCb, SIGNAL(clicked()), this, SLOT(filterClickedSlot()));
+  connect (m_olsrFilterCb, SIGNAL(clicked()), this, SLOT(filterClickedSlot()));
+  connect (m_arpFilterCb, SIGNAL(clicked()), this, SLOT(filterClickedSlot()));
+  connect (m_regexFilterEdit, SIGNAL(textEdited(QString)), this, SLOT(regexFilterSlot(QString)));
 
 }
 
@@ -211,15 +223,15 @@
       m_allowedNodes.clear ();
       for (uint32_t i = 0; i < nodeCount; ++i)
         {
-          if (i>10)
-            break;
+          //if (i>10)
+          //  break;
           m_allowedNodes.push_back (i);
         }
       setAllowedNodes (nodeVectorToString (m_allowedNodes));
       //m_allowedNodes.clear ();
       qreal thousandthPacketTime = AnimatorMode::getInstance ()->getThousandthPacketTime ();
       if (thousandthPacketTime < 0)
-        return;
+        m_toTime = lastPacketTime;
       m_fromTime = AnimatorMode::getInstance ()->getFirstPacketTime ();
       m_toTime = thousandthPacketTime;
       m_toTimeEdit->setText (QString::number (m_toTime, 'g', 6));
@@ -286,7 +298,7 @@
 PacketsMode::nodeVectorToString (QVector<uint32_t> nodeVector)
 {
   QString s;
-  for (uint32_t i = 0; i < nodeVector.size (); ++i)
+  for (int i = 0; i < nodeVector.size (); ++i)
     {
       s += QString::number (nodeVector[i]) + ":";
     }
@@ -357,6 +369,12 @@
 
 }
 
+void
+PacketsMode::regexFilterSlot (QString reg)
+{
+  PacketsScene::getInstance ()->setRegexFilter (reg);
+  PacketsScene::getInstance ()->redraw(m_fromTime, m_toTime, m_allowedNodes, m_showGrid);
+}
 
 void
 PacketsMode::allowedNodesChangedSlot (QString allowedNodes)
--- a/packetsmode.h	Sun Jan 12 16:14:23 2014 -0800
+++ b/packetsmode.h	Sun Jan 12 17:59:47 2014 -0800
@@ -70,6 +70,8 @@
   QCheckBox * m_olsrFilterCb;
   QCheckBox * m_ipv4FilterCb;
   QCheckBox * m_icmpFilterCb;
+  QLineEdit * m_regexFilterEdit;
+  QLabel * m_regexFilterLabel;
 
 
   Table * m_packetsTable;
@@ -91,6 +93,7 @@
   void fromTimeChangedSlot (QString fromTimeText);
   void toTimeChangedSlot (QString toTimeText);
   void allowedNodesChangedSlot (QString allowedNodes);
+  void regexFilterSlot (QString reg);
   void showGridLinesSlot ();
   void showPacketTableSlot ();
   void filterClickedSlot ();
--- a/packetsscene.cpp	Sun Jan 12 16:14:23 2014 -0800
+++ b/packetsscene.cpp	Sun Jan 12 17:59:47 2014 -0800
@@ -15,6 +15,7 @@
  *
  * Author: John Abraham <john.abraham.in@gmail.com>
  */
+#include <QRegExp>
 #include "packetsscene.h"
 #include "logqt.h"
 #include "animpacket.h"
@@ -38,7 +39,8 @@
   m_textBubble (0),
   m_showGrid (true),
   m_showTable (true),
-  m_filter (AnimPacket::ALL)
+  m_filter (AnimPacket::ALL),
+  m_filterRegex (".*")
 {
   m_textBubble = new TextBubble ("Info:", "No data available\nDid you load the XML file?");
   m_infoWidget = addWidget (m_textBubble);
@@ -139,7 +141,7 @@
   if (!nodeCount)
     return foundNodes;
 
-  for (uint32_t lineIndex = 0; lineIndex < m_allowedNodes.count () ; ++lineIndex)
+  for (int lineIndex = 0; lineIndex < m_allowedNodes.count () ; ++lineIndex)
     {
       foundNodes = true;
       QGraphicsLineItem * lineItem = addLine (m_interNodeSpacing * lineIndex, m_borderHeight, m_interNodeSpacing * lineIndex, m_lineLength);
@@ -182,6 +184,12 @@
       shortMeta = AnimPacket::getShortMeta (metaInfo);
     }
 
+  QRegExp rex (m_filterRegex);
+  if (rex.indexIn (metaInfo) == -1)
+  {
+    return;
+  }
+
   qreal fromNodeX = m_interNodeSpacing * m_lineIndex[fromNodeId];
   qreal toNodeX = m_interNodeSpacing * m_lineIndex[toNodeId];
   qreal txY = timeToY (tx);
@@ -248,6 +256,12 @@
 }
 
 void
+PacketsScene::setRegexFilter (QString reg)
+{
+  m_filterRegex = reg;
+}
+
+void
 PacketsScene::setFilter (int ft)
 {
   m_filter = ft;
@@ -274,7 +288,7 @@
 bool
 PacketsScene::isAllowedNode (uint32_t nodeId)
 {
-  for (uint32_t i = 0; i < m_allowedNodes.count (); ++i)
+  for (int i = 0; i < m_allowedNodes.count (); ++i)
     {
       if (m_allowedNodes[i] == nodeId)
         return true;
@@ -310,8 +324,10 @@
 
 
           addPacket (packetEvent->m_fbTx, packetEvent->m_fbRx, packetEvent->m_fromId, packetEvent->m_toId, packetEvent->m_metaInfo);
+          AnimatorMode::getInstance ()->keepAppResponsive ();
         }
     }
+  table->adjust ();
   m_infoWidget->setVisible (false);
 
 }
--- a/packetsscene.h	Sun Jan 12 16:14:23 2014 -0800
+++ b/packetsscene.h	Sun Jan 12 17:59:47 2014 -0800
@@ -33,6 +33,8 @@
   void addPackets ();
   void redraw (qreal fromTime, qreal toTime , QVector <uint32_t> allowedNodes, bool showGrid);
   void setFilter (int ft);
+  void setRegexFilter (QString reg);
+
 private:
   PacketsScene ();
   bool setUpNodeLines ();
@@ -58,12 +60,13 @@
   QGraphicsProxyWidget * m_infoWidget;
   qreal m_borderHeight;
   qreal m_lineLength;
+  TextBubble * m_textBubble;
   bool m_showGrid;
   bool m_showTable;
   int m_filter;
 
   QGraphicsLineItem * m_rulerLine;
-  TextBubble * m_textBubble;
+  QString m_filterRegex;
 
 };
 }
--- a/qrc_qtpropertybrowser.cpp	Sun Jan 12 16:14:23 2014 -0800
+++ b/qrc_qtpropertybrowser.cpp	Sun Jan 12 17:59:47 2014 -0800
@@ -1,7 +1,7 @@
 /****************************************************************************
 ** Resource object code
 **
-** Created: Sun Jan 12 06:20:03 2014
+** Created: Sun Jan 12 17:16:57 2014
 **      by: The Resource Compiler for Qt version 4.8.1
 **
 ** WARNING! All changes made in this file will be lost!
--- a/qrc_resources.cpp	Sun Jan 12 16:14:23 2014 -0800
+++ b/qrc_resources.cpp	Sun Jan 12 17:59:47 2014 -0800
@@ -1,7 +1,7 @@
 /****************************************************************************
 ** Resource object code
 **
-** Created: Sun Jan 12 12:15:38 2014
+** Created: Sun Jan 12 17:16:56 2014
 **      by: The Resource Compiler for Qt version 4.8.1
 **
 ** WARNING! All changes made in this file will be lost!
--- a/table.cpp	Sun Jan 12 16:14:23 2014 -0800
+++ b/table.cpp	Sun Jan 12 17:59:47 2014 -0800
@@ -31,7 +31,7 @@
 }
 
 void
-Table::addRow (QStringList rowContents)
+Table::addRow (QStringList rowContents, bool autoAdjust)
 {
   uint32_t rows = rowCount ();
   setRowCount (rows + 1);
@@ -41,15 +41,18 @@
       QTableWidgetItem * item = new QTableWidgetItem (st);
       setItem (rows, column++, item);
     }
-  resizeRowsToContents();
-  resizeColumnsToContents ();
+  if (autoAdjust)
+    {
+      resizeRowsToContents();
+      resizeColumnsToContents ();
+    }
 }
 
 
 void
 Table::removeAllRows ()
 {
-  for (uint32_t i = 0; i < rowCount (); ++i)
+  for (int i = 0; i < rowCount (); ++i)
     {
       removeRow (i);
     }
@@ -57,4 +60,12 @@
 }
 
 
+void
+Table::adjust ()
+{
+  resizeRowsToContents();
+  resizeColumnsToContents ();
 }
+
+
+}
--- a/table.h	Sun Jan 12 16:14:23 2014 -0800
+++ b/table.h	Sun Jan 12 17:59:47 2014 -0800
@@ -27,8 +27,9 @@
 public:
   Table ();
   void setHeaderList (QStringList headerList);
-  void addRow (QStringList rowContents);
+  void addRow (QStringList rowContents, bool autoAdjust = false);
   void removeAllRows ();
+  void adjust ();
 
 };