src/mobility/hierarchical-mobility-model.cc
author Nicola Baldo <nbaldo@cttc.es>
Tue, 24 Nov 2009 13:59:14 +0100
changeset 5774 0fad665ff307
parent 4356 08cfbddc55f9
permissions -rw-r--r--
fixed bug 668
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "hierarchical-mobility-model.h"
2927
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    21
#include "ns3/pointer.h"
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
namespace ns3 {
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    25
NS_OBJECT_ENSURE_REGISTERED (HierarchicalMobilityModel);
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    26
2250
18f432098389 InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2249
diff changeset
    27
TypeId 
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    28
HierarchicalMobilityModel::GetTypeId (void)
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    29
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2594
diff changeset
    30
  static TypeId tid = TypeId ("ns3::HierarchicalMobilityModel")
2401
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    31
    .SetParent<MobilityModel> ()
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    32
    .AddConstructor<HierarchicalMobilityModel> ()
2543
401bfe8c0176 kill old code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    33
    .AddAttribute ("Child", "The child mobility model.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    34
                   PointerValue (),
3066
f94b285ffd62 add missing getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    35
                   MakePointerAccessor (&HierarchicalMobilityModel::SetChild,
f94b285ffd62 add missing getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    36
                                        &HierarchicalMobilityModel::GetChild),
2927
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    37
                   MakePointerChecker<MobilityModel> ())
2543
401bfe8c0176 kill old code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    38
    .AddAttribute ("Parent", "The parent mobility model.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    39
                   PointerValue (),
3066
f94b285ffd62 add missing getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    40
                   MakePointerAccessor (&HierarchicalMobilityModel::SetParent,
f94b285ffd62 add missing getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    41
                                        &HierarchicalMobilityModel::GetParent),
2927
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    42
                   MakePointerChecker<MobilityModel> ())
2401
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    43
    ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    44
  return tid;
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    45
}
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    46
2401
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    47
HierarchicalMobilityModel::HierarchicalMobilityModel ()
2566
8e3857859ce0 ensure proper initialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2543
diff changeset
    48
  : m_child (0),
8e3857859ce0 ensure proper initialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2543
diff changeset
    49
    m_parent (0)
2401
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    50
{}
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    51
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    52
void 
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    53
HierarchicalMobilityModel::SetChild (Ptr<MobilityModel> model)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
{
4356
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    55
  Ptr<MobilityModel> oldChild = m_child;
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    56
  Vector pos;
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    57
  if (m_child)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    58
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    59
      pos = GetPosition ();
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    60
      m_child->TraceDisconnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    61
    }
2401
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    62
  m_child = model;
3021
5b1479210da3 Removed TraceContext and TraceResolver references, removed MobilityModelNotifier class, and minor changes on samples/main-random-walk.cc.
tjkopena@cs.drexel.edu
parents: 2965
diff changeset
    63
  m_child->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
4356
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    64
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    65
  // if we had a child before, then we had a valid position before;
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    66
  // try to preserve the old absolute position.
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    67
  if (oldChild)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    68
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    69
      SetPosition (pos);
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    70
    }
2401
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    71
}
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    72
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    73
void 
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    74
HierarchicalMobilityModel::SetParent (Ptr<MobilityModel> model)
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    75
{
4356
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    76
  Vector pos;
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    77
  if (m_child)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    78
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    79
      pos = GetPosition ();
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    80
    }
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    81
  if (m_parent)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    82
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    83
      m_parent->TraceDisconnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    84
    }
2401
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    85
  m_parent = model;
4356
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    86
  if (m_parent)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    87
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    88
      m_parent->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    89
    }
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    90
  // try to preserve the old position across parent changes
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    91
  if (m_child)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    92
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    93
      SetPosition (pos);
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
    94
    }
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
2401
281ea8b13525 add hierarchical support to MobilityHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
    97
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
Ptr<MobilityModel> 
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
HierarchicalMobilityModel::GetChild (void) const
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
{
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
  return m_child;
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
Ptr<MobilityModel> 
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
HierarchicalMobilityModel::GetParent (void) const
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
{
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
  return m_parent;
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   110
Vector
1816
d7c9b9da78f4 rename MobilityModel::Get/Set to GetPosition/SetPosition
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1460
diff changeset
   111
HierarchicalMobilityModel::DoGetPosition (void) const
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
{
4356
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   113
  if (!m_parent)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   114
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   115
      return m_child->GetPosition ();
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   116
    }
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   117
  Vector parentPosition = m_parent->GetPosition ();
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   118
  Vector childPosition = m_child->GetPosition ();
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   119
  return Vector (parentPosition.x + childPosition.x,
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
		   parentPosition.y + childPosition.y,
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
		   parentPosition.z + childPosition.z);
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
void 
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   124
HierarchicalMobilityModel::DoSetPosition (const Vector &position)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
{
4356
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   126
  if (m_child == 0)
2566
8e3857859ce0 ensure proper initialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2543
diff changeset
   127
    {
8e3857859ce0 ensure proper initialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2543
diff changeset
   128
      return;
8e3857859ce0 ensure proper initialization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2543
diff changeset
   129
    }
1816
d7c9b9da78f4 rename MobilityModel::Get/Set to GetPosition/SetPosition
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1460
diff changeset
   130
  // This implementation of DoSetPosition is really an arbitraty choice.
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
  // anything else would have been ok.
4356
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   132
  if (m_parent)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   133
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   134
      Vector parentPosition = m_parent->GetPosition ();
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   135
      Vector childPosition (position.x - parentPosition.x,
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   136
                            position.y - parentPosition.y,
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   137
                            position.z - parentPosition.z);
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   138
      m_child->SetPosition (childPosition);
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   139
    }
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   140
  else
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   141
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   142
      m_child->SetPosition (position);
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   143
    }
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
}
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   145
Vector
1818
fbdc8361dc77 GetSpeed -> GetVelocity
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1817
diff changeset
   146
HierarchicalMobilityModel::DoGetVelocity (void) const
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
{
4356
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   148
  if (m_parent)
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   149
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   150
      Vector parentSpeed = m_parent->GetVelocity ();
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   151
      Vector childSpeed = m_child->GetVelocity ();
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   152
      Vector speed (parentSpeed.x + childSpeed.x,
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   153
                    parentSpeed.y + childSpeed.y,
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   154
                    parentSpeed.z + childSpeed.z);
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   155
      return speed;
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   156
    }
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   157
  else
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   158
    {
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   159
      return m_child->GetVelocity ();
08cfbddc55f9 HierarchicalMobilityModel: allow the parent model to be NULL, make the child/parent setters public, and add more detailed documentation; closes bug #511
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3082
diff changeset
   160
    }
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
void 
2542
a9b88fdc09d6 kill TraceResolver et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2458
diff changeset
   164
HierarchicalMobilityModel::ParentChanged (Ptr<const MobilityModel> model)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
{
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
  MobilityModel::NotifyCourseChange ();
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
void 
2542
a9b88fdc09d6 kill TraceResolver et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2458
diff changeset
   170
HierarchicalMobilityModel::ChildChanged (Ptr<const MobilityModel> model)
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
{
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
  MobilityModel::NotifyCourseChange ();
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
}
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
} // namespace ns3