src/buildings/helper/buildings-helper.cc
changeset 8556 f859539f5dd3
child 8557 3b41fe3d7a5a
equal deleted inserted replaced
8555:2d4c2747a344 8556:f859539f5dd3
       
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2010 CTTC
       
     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: Nicola Baldo <nbaldo@cttc.es>
       
    19  */
       
    20 
       
    21 #include "buildings-helper.h"
       
    22 
       
    23 #include <ns3/node-list.h>
       
    24 #include <ns3/building.h>
       
    25 #include <ns3/building-list.h>
       
    26 #include <ns3/mobility-model.h>
       
    27 #include <ns3/buildings-mobility-model.h>
       
    28 #include <ns3/abort.h>
       
    29 #include <ns3/log.h>
       
    30 
       
    31 
       
    32 NS_LOG_COMPONENT_DEFINE ("BuildingsHelper");
       
    33 
       
    34 namespace ns3 {
       
    35 
       
    36 void
       
    37 BuildingsHelper::MakeAllInstancesConsistent ()
       
    38 {
       
    39   NS_LOG_FUNCTION_NOARGS ();
       
    40   for (NodeList::Iterator nit = NodeList::Begin (); nit != NodeList::End (); ++nit)
       
    41     {
       
    42       Ptr<BuildingsMobilityModel> bmm = (*nit)->GetObject<BuildingsMobilityModel> ();
       
    43       NS_ABORT_MSG_UNLESS (0 != bmm, "node " << (*nit)->GetId () << " does not have a BuildingsMobilityModel");
       
    44       bool found = false;
       
    45       for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit)
       
    46 	{
       
    47 	  Vector pos = bmm->GetPosition ();
       
    48 	  if ((*bit)->IsInside (pos))
       
    49 	    {
       
    50 	      NS_LOG_LOGIC ("node " << (*nit)->GetId () << " falls inside building " << (*bit)->GetId ());
       
    51 	      NS_ABORT_MSG_UNLESS (found == false, "node already inside another building!");		
       
    52 	      found = true;
       
    53 	      uint16_t floor = (*bit)->GetFloor (pos);
       
    54 	      uint16_t roomX = (*bit)->GetRoomX (pos);
       
    55 	      uint16_t roomY = (*bit)->GetRoomY (pos);	   
       
    56 	      bmm->SetIndoor (*bit, floor, roomX, roomY);	      
       
    57 	    }		    	  
       
    58 	}
       
    59       if (!found)
       
    60 	{
       
    61 	  NS_LOG_LOGIC ("node " << (*nit)->GetId () << " is outdoor");
       
    62 	  bmm->SetOutdoor ();
       
    63 	}
       
    64     }
       
    65 }
       
    66 
       
    67 } // namespace ns3