--- a/src/netanim/examples/dumbbell-animation.cc Wed Oct 19 07:00:15 2011 -0400
+++ b/src/netanim/examples/dumbbell-animation.cc Wed Oct 19 14:25:39 2011 -0400
@@ -36,7 +36,7 @@
uint32_t nLeftLeaf = 5;
uint32_t nRightLeaf = 5;
uint32_t nLeaf = 0; // If non-zero, number of both left and right
- std::string animFile; // Name of file for animation output
+ std::string animFile = "dumbbell-animation.xml" ; // Name of file for animation output
CommandLine cmd;
cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf);
@@ -95,15 +95,8 @@
d.BoundingBox (1, 1, 100, 100);
// Create the animation object and configure for specified output
- AnimationInterface anim;
- if (!animFile.empty ())
- {
- anim.SetOutputFile (animFile);
- }
-
- anim.SetXMLOutput ();
- anim.StartAnimation ();
-
+ AnimationInterface anim (animFile);
+
// Set up the acutal simulation
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
--- a/src/netanim/examples/grid-animation.cc Wed Oct 19 07:00:15 2011 -0400
+++ b/src/netanim/examples/grid-animation.cc Wed Oct 19 14:25:39 2011 -0400
@@ -35,7 +35,7 @@
uint32_t xSize = 5;
uint32_t ySize = 5;
- std::string animFile;
+ std::string animFile = "grid-animation.xml";
CommandLine cmd;
cmd.AddValue ("xSize", "Number of rows of nodes", xSize);
@@ -83,13 +83,7 @@
grid.BoundingBox (1, 1, 100, 100);
// Create the animation object and configure for specified output
- AnimationInterface anim;
- if (!animFile.empty ())
- {
- anim.SetOutputFile (animFile);
- }
- anim.SetXMLOutput ();
- anim.StartAnimation ();
+ AnimationInterface anim (animFile);
// Set up the actual simulation
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
--- a/src/netanim/examples/star-animation.cc Wed Oct 19 07:00:15 2011 -0400
+++ b/src/netanim/examples/star-animation.cc Wed Oct 19 14:25:39 2011 -0400
@@ -55,7 +55,7 @@
// Default number of nodes in the star. Overridable by command line argument.
//
uint32_t nSpokes = 8;
- std::string animFile;
+ std::string animFile = "star-animation.xml";
CommandLine cmd;
cmd.AddValue ("nSpokes", "Number of spoke nodes to place in the star", nSpokes);
@@ -115,13 +115,7 @@
star.BoundingBox (1, 1, 100, 100);
// Create the animation object and configure for specified output
- AnimationInterface anim;
- if (!animFile.empty ())
- {
- anim.SetOutputFile (animFile);
- }
- anim.SetXMLOutput ();
- anim.StartAnimation ();
+ AnimationInterface anim (animFile);
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
--- a/src/netanim/model/animation-interface.cc Wed Oct 19 07:00:15 2011 -0400
+++ b/src/netanim/model/animation-interface.cc Wed Oct 19 14:25:39 2011 -0400
@@ -32,6 +32,7 @@
#include "ns3/animation-interface-helper.h"
#include "ns3/wifi-mac-header.h"
#include "ns3/wimax-mac-header.h"
+#include "ns3/constant-position-mobility-model.h"
#include <stdio.h>
#include <sstream>
@@ -58,6 +59,7 @@
OutputFileSet (false), ServerPortSet (false), gAnimUid (0),randomPosition (true),
m_writeCallback (0)
{
+ StartAnimation ();
}
AnimationInterface::AnimationInterface (const std::string fn, bool usingXML)
@@ -66,6 +68,7 @@
OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true),
m_writeCallback (0)
{
+ StartAnimation ();
}
AnimationInterface::AnimationInterface (const uint16_t port, bool usingXML)
@@ -74,6 +77,7 @@
OutputFileSet (false), ServerPortSet (false), gAnimUid (0), randomPosition (true),
m_writeCallback (0)
{
+ StartAnimation ();
}
AnimationInterface::~AnimationInterface ()
@@ -931,6 +935,21 @@
WriteN (m_fHandle, oss.str ());
}
+void AnimationInterface::SetConstantPosition (Ptr <Node> n, double x, double y, double z)
+{
+ NS_ASSERT (n);
+ Ptr<ConstantPositionMobilityModel> hubLoc = n->GetObject<ConstantPositionMobilityModel> ();
+ if (hubLoc == 0)
+ {
+ hubLoc = CreateObject<ConstantPositionMobilityModel> ();
+ n->AggregateObject (hubLoc);
+ }
+ Vector hubVec (x, y, z);
+ hubLoc->SetPosition (hubVec);
+ NS_LOG_INFO ("Node:" << n->GetId () << " Position set to:(" << x << "," << y << "," << z << ")");
+
+}
+
// XML Private Helpers
--- a/src/netanim/model/animation-interface.h Wed Oct 19 07:00:15 2011 -0400
+++ b/src/netanim/model/animation-interface.h Wed Oct 19 14:25:39 2011 -0400
@@ -193,6 +193,16 @@
*/
void ResetAnimWriteCallback ();
+ /**
+ * \brief Helper function to set Constant Position for a given node
+ * \param n Ptr to the node
+ * \param x X co-ordinate of the node
+ * \param y Y co-ordinate of the node
+ * \param z Z co-ordinate of the node
+ *
+ */
+ void SetConstantPosition (Ptr <Node> n, double x, double y, double z=0);
+
private:
#ifndef WIN32
int m_fHandle; // File handle for output (-1 if none)