NetAnim: Allow the user to set the boundary
authorJohn Abraham
Wed, 11 Sep 2013 07:53:45 -0700
changeset 10196 4d23b48380a7
parent 10195 423dfabf60c1
child 10197 0cb30dac6408
NetAnim: Allow the user to set the boundary
src/netanim/examples/wireless-animation.cc
src/netanim/model/animation-interface.cc
src/netanim/model/animation-interface.h
--- a/src/netanim/examples/wireless-animation.cc	Sun Sep 08 09:57:13 2013 -0700
+++ b/src/netanim/examples/wireless-animation.cc	Wed Sep 11 07:53:45 2013 -0700
@@ -157,6 +157,7 @@
   AnimationInterface::SetNodeColor (wifiApNode, 0, 255, 0); // Optional
   AnimationInterface::SetNodeColor (wifiStaNodes, 255, 0, 0); // Optional
   AnimationInterface::SetNodeColor (csmaNodes, 0, 0, 255); // Optional
+  AnimationInterface::SetBoundary (0, 0, 35, 35); // Optional
 
   AnimationInterface anim ("wireless-animation.xml"); // Mandatory
 
--- a/src/netanim/model/animation-interface.cc	Sun Sep 08 09:57:13 2013 -0700
+++ b/src/netanim/model/animation-interface.cc	Wed Sep 11 07:53:45 2013 -0700
@@ -59,6 +59,7 @@
 std::map <uint32_t, std::string> AnimationInterface::nodeDescriptions;
 std::map <uint32_t, Rgb> AnimationInterface::nodeColors;
 std::map <P2pLinkNodeIdPair, LinkProperties, LinkPairCompare> AnimationInterface::linkProperties;
+Rectangle * AnimationInterface::userBoundary = 0;
 
 
 AnimationInterface::AnimationInterface (const std::string fn, uint64_t maxPktsPerFile, bool usingXML)
@@ -78,6 +79,10 @@
 
 AnimationInterface::~AnimationInterface ()
 {
+  if (userBoundary)
+    {
+      delete userBoundary;
+    }
   StopAnimation ();
 }
 
@@ -1701,6 +1706,20 @@
 
 }
 
+void AnimationInterface::SetBoundary (double minX, double minY, double maxX, double maxY)
+{
+  if (initialized)
+    NS_FATAL_ERROR ("SetBoundary must be used prior to creating the AnimationInterface object");
+  if (!userBoundary)
+    {
+      userBoundary = new Rectangle;
+    }
+  userBoundary->xMax = maxX;
+  userBoundary->yMax = maxY;
+  userBoundary->xMin = minX;
+  userBoundary->yMin = minY;
+}
+
 void AnimationInterface::SetNodeColor (Ptr <Node> n, uint8_t r, uint8_t g, uint8_t b)
 {
   if (initialized)
@@ -1855,6 +1874,13 @@
 }
 std::string AnimationInterface::GetXMLOpen_topology (double minX, double minY, double maxX, double maxY)
 {
+  if (userBoundary)
+    {
+      minX = userBoundary->xMin;
+      minY = userBoundary->yMin;
+      maxX = userBoundary->xMax;
+      maxY = userBoundary->yMax;
+    }
   std::ostringstream oss;
   oss << "<topology minX = \"" << minX << "\" minY = \"" << minY
       << "\" maxX = \"" << maxX << "\" maxY = \"" << maxY
--- a/src/netanim/model/animation-interface.h	Sun Sep 08 09:57:13 2013 -0700
+++ b/src/netanim/model/animation-interface.h	Wed Sep 11 07:53:45 2013 -0700
@@ -38,6 +38,7 @@
 #include "ns3/lte-ue-net-device.h"
 #include "ns3/lte-enb-net-device.h"
 #include "ns3/uan-phy-gen.h"
+#include "ns3/rectangle.h"
 
 namespace ns3 {
 
@@ -228,6 +229,16 @@
   static void SetConstantPosition (Ptr <Node> n, double x, double y, double z=0);
 
   /**
+   * \brief Helper function to set the topology boundary rectangle
+   * \param minX X value of the lower left corner
+   * \param minY Y value of the lower left corner
+   * \param maxX X value of the upper right corner
+   * \param maxX Y value of the upper right corner
+   *
+   */
+  static void SetBoundary (double minX, double minY, double maxX, double maxY);
+
+  /**
    * \brief Helper function to set a brief description for a given node
    * \param n Ptr to the node
    * \param descr A string to briefly describe the node
@@ -618,6 +629,7 @@
   double m_topoMinY;
   double m_topoMaxX;
   double m_topoMaxY;
+  static Rectangle * userBoundary;
 
   std::string GetPacketMetadata (Ptr<const Packet> p);