A Discrete-Event Network Simulator
API
hierarchical-mobility-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
21 #include "ns3/pointer.h"
22 
23 namespace ns3 {
24 
25 NS_OBJECT_ENSURE_REGISTERED (HierarchicalMobilityModel);
26 
27 TypeId
29 {
30  static TypeId tid = TypeId ("ns3::HierarchicalMobilityModel")
32  .SetGroupName ("Mobility")
33  .AddConstructor<HierarchicalMobilityModel> ()
34  .AddAttribute ("Child", "The child mobility model.",
35  PointerValue (),
38  MakePointerChecker<MobilityModel> ())
39  .AddAttribute ("Parent", "The parent mobility model.",
40  PointerValue (),
43  MakePointerChecker<MobilityModel> ())
44  ;
45  return tid;
46 }
47 
49  : m_child (0),
50  m_parent (0)
51 {
52 }
53 
54 void
56 {
57  Ptr<MobilityModel> oldChild = m_child;
58  Vector pos;
59  if (m_child)
60  {
61  pos = GetPosition ();
63  }
64  m_child = model;
66 
67  // if we had a child before, then we had a valid position before;
68  // try to preserve the old absolute position.
69  if (oldChild)
70  {
71  SetPosition (pos);
72  }
73 }
74 
75 void
77 {
78  Vector pos;
79  if (m_child)
80  {
81  pos = GetPosition ();
82  }
83  if (m_parent)
84  {
86  }
87  m_parent = model;
88  if (m_parent)
89  {
91  }
92  // try to preserve the old position across parent changes
93  if (m_child)
94  {
95  SetPosition (pos);
96  }
97 }
98 
99 
102 {
103  return m_child;
104 }
105 
108 {
109  return m_parent;
110 }
111 
112 Vector
114 {
115  if (!m_parent)
116  {
117  return m_child->GetPosition ();
118  }
119  Vector parentPosition = m_parent->GetPosition ();
120  Vector childPosition = m_child->GetPosition ();
121  return Vector (parentPosition.x + childPosition.x,
122  parentPosition.y + childPosition.y,
123  parentPosition.z + childPosition.z);
124 }
125 void
127 {
128  if (m_child == 0)
129  {
130  return;
131  }
132  // This implementation of DoSetPosition is really an arbitrary choice.
133  // anything else would have been ok.
134  if (m_parent)
135  {
136  Vector parentPosition = m_parent->GetPosition ();
137  Vector childPosition (position.x - parentPosition.x,
138  position.y - parentPosition.y,
139  position.z - parentPosition.z);
140  m_child->SetPosition (childPosition);
141  }
142  else
143  {
144  m_child->SetPosition (position);
145  }
146 }
147 Vector
149 {
150  if (m_parent)
151  {
152  Vector parentSpeed = m_parent->GetVelocity ();
153  Vector childSpeed = m_child->GetVelocity ();
154  Vector speed (parentSpeed.x + childSpeed.x,
155  parentSpeed.y + childSpeed.y,
156  parentSpeed.z + childSpeed.z);
157  return speed;
158  }
159  else
160  {
161  return m_child->GetVelocity ();
162  }
163 }
164 
165 void
167 {
169 }
170 
171 void
173 {
175 }
176 
177 
178 
179 } // namespace ns3
virtual Vector DoGetVelocity(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Vector GetPosition(void) const
Vector GetVelocity(void) const
Keep track of the current position and velocity of an object.
Ptr< MobilityModel > m_child
pointer to child mobility model
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: pointer.h:220
Ptr< MobilityModel > m_parent
pointer to parent mobility model
Ptr< MobilityModel > GetParent(void) const
void NotifyCourseChange(void) const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:319
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void SetChild(Ptr< MobilityModel > model)
Sets the child mobility model to a new one.
Ptr< MobilityModel > GetChild(void) const
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
void SetParent(Ptr< MobilityModel > model)
Sets the parent mobility model to a new one.
virtual Vector DoGetPosition(void) const
virtual void DoSetPosition(const Vector &position)
void SetPosition(const Vector &position)
void ChildChanged(Ptr< const MobilityModel > model)
Callback for when child mobility model course change occurs.
void ParentChanged(Ptr< const MobilityModel > model)
Callback for when parent mobility model course change occurs.
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Register this type with the TypeId system.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915