src/mobility/grid-topology.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 15 Jan 2008 12:43:07 +0100
changeset 2251 04963d8cca51
parent 2250 18f432098389
child 2257 71a58e70c671
permissions -rw-r--r--
iid (void) -> GetTypeId (void)

/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2007 INRIA
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
 */
#include "grid-topology.h"
#include "static-mobility-model.h"

namespace ns3 {

GridTopology::GridTopology (double xMin, double yMin, uint32_t n, double deltaX, double deltaY)
  : m_xMin (xMin),
    m_yMin (yMin),
    m_n (n),
    m_deltaX (deltaX),
    m_deltaY (deltaY),
    m_positionTypeId (StaticMobilityModel::GetTypeId ())
{}

void 
GridTopology::SetMobilityModel (TypeId interfaceId)
{
  m_positionTypeId = interfaceId;
}

void 
GridTopology::LayoutOneRowFirst (Ptr<Object> object, uint32_t i)
{
  double x, y;
  x = m_xMin + m_deltaX * (i % m_n);
  y = m_yMin + m_deltaY * (i / m_n);
  Ptr<MobilityModel> mobility = m_positionTypeId.CreateObject ()->QueryInterface<MobilityModel> ();
  object->AddInterface (mobility);
  mobility->SetPosition (Vector (x, y, 0.0));
}

void 
GridTopology::LayoutOneColumnFirst (Ptr<Object> object, uint32_t i)
{
  double x, y;
  x = m_xMin + m_deltaX * (i / m_n);
  y = m_yMin + m_deltaY * (i % m_n);
  Ptr<MobilityModel> mobility = m_positionTypeId.CreateObject ()->QueryInterface<MobilityModel> ();
  object->AddInterface (mobility);
  mobility->SetPosition (Vector (x, y, 0.0));
}


} // namespace ns3