Transition.cpp 5.4 KB
Newer Older
1
/**
Weichen's avatar
Weichen committed
2 3
 * \file        Transition.cpp
 * \date        Nov 16, 2010
4
 * \version     v0.6
Weichen's avatar
Weichen committed
5
 * \copyright   <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
6
 *
Weichen's avatar
Weichen committed
7
 * \section License
8 9 10
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
Weichen's avatar
Weichen committed
11
 * it under the terms of the GNU Lesser General Public License as published by
12 13 14 15 16 17 18 19
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * JuPedSim 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.
 *
Weichen's avatar
Weichen committed
20
 * You should have received a copy of the GNU Lesser General Public License
21 22
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
Weichen's avatar
Weichen committed
23
 * \section Description
24 25
 *
 *
Weichen's avatar
Weichen committed
26 27
 **/

Ulrich Kemloh's avatar
Ulrich Kemloh committed
28 29

#include "Transition.h"
30 31
#include "Room.h"
#include "SubRoom.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
32
#include "../IO/OutputHandler.h"
33 34

using namespace std;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
35 36 37 38 39

/************************************************************
 Transition (abgeleitet von Crossing)
 ************************************************************/

40 41 42 43 44 45
Transition::Transition() : Crossing()
{
     _isOpen = true;
     _doorUsage=0;
     _lastPassingTime=0;
     _room2 = NULL;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
46 47
}

48 49
Transition::~Transition()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
50 51 52
}


53 54 55
void Transition::Close()
{
     _isOpen = false;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
56 57
}

58 59 60
void Transition::Open()
{
     _isOpen = true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
61 62
}

63 64 65
void Transition::SetType(string type)
{
     _type=type;
66
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
67

68 69 70
void Transition::SetRoom2(Room* r)
{
     _room2 = r;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
71 72
}

73

Ulrich Kemloh's avatar
Ulrich Kemloh committed
74

75 76 77
bool Transition::IsOpen() const
{
     return _isOpen;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
78 79 80
}


81 82 83
Room* Transition::GetRoom2() const
{
     return _room2;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
84
}
85

86 87 88
string Transition::GetType() const
{
     return _type;
89
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
90 91 92
// Sonstiges

// gibt den ANDEREN room != roomID zurück
93 94 95 96 97 98 99 100 101 102 103 104
Room* Transition::GetOtherRoom(int roomID) const
{
     if (GetRoom1()!=NULL && GetRoom1()->GetID() == roomID) {
          return GetRoom2();
     } else if (GetRoom2()!=NULL && GetRoom2()->GetID() == roomID) {
          return GetRoom1();
     } else {
          char msg[CLENGTH];
          sprintf(msg,"ERROR: \tTransition::GetOtherRoom() wrong roomID [%d]",roomID);
          Log->Write(msg);
          exit(0);
     }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
105 106 107 108 109

}
// virtuelle Funktionen

// prüft ob Ausgang nach draußen
110 111 112 113 114 115
bool Transition::IsExit() const
{
     if(GetRoom1()!=NULL && _room2!=NULL)
          return false;
     else
          return true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
116 117
}
// prüft, ob Transition in Raum mit roomID
118 119 120 121 122 123 124 125 126
bool Transition::IsInRoom(int roomID) const
{
     bool c1 = false;
     bool c2 = false;
     if (GetRoom1() != NULL && GetRoom1()->GetID() == roomID)
          c1 = true;
     if (GetRoom2() != NULL && GetRoom2()->GetID() == roomID)
          c2 = true;
     return c1 || c2;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
127 128
}

129 130 131
bool Transition::IsTransition() const
{
     return true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
132 133
}

134

Ulrich Kemloh's avatar
Ulrich Kemloh committed
135 136 137
/* gibt den ANDEREN Subroom mit GetRoomID() != roomID zurück
 * subroomID wird hier nicht benötigt, aber in Crossings::GetOtherSubRoom()
 * (virtuelle Funktion) */
138 139 140 141 142 143 144 145 146 147 148
SubRoom* Transition::GetOtherSubRoom(int roomID, int subroomID) const
{
     if ((GetRoom1() != NULL) && (GetRoom1()->GetID() == roomID))
          return GetSubRoom2();
     else if ((GetRoom2() != NULL) && (GetRoom2()->GetID() == roomID))
          return GetSubRoom1();
     else {
          Log->Write("ERROR: \tTransition::GetOtherSubRoom No exit found "
                     "on the other side\n ID=%d, roomID=%d, subroomID=%d\n",GetUniqueID(),roomID,subroomID);
          exit(EXIT_FAILURE);
     }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
149 150 151 152
}

// Ein-Ausgbae

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
void Transition::WriteToErrorLog() const
{
     string s;
     char tmp[CLENGTH];
     sprintf(tmp, "\t\tTRANS: %d [%s] (%f, %f) -- (%f, %f)\n", GetID(), GetCaption().c_str(),
             GetPoint1().GetX(), GetPoint1().GetY(), GetPoint2().GetX(), GetPoint2().GetY());
     s.append(tmp);
     // erster Raum
     if (GetRoom1() != NULL) {
          sprintf(tmp, "\t\t\t\tRoom: %d [%s] SubRoom: %d", GetRoom1()->GetID(),
                  GetRoom1()->GetCaption().c_str(), GetSubRoom1()->GetSubRoomID());
     } else {
          sprintf(tmp, "\t\t\t\tAusgang");
     }
     s.append(tmp);
     // zweiter Raum
     if (GetRoom2() != NULL) {
          sprintf(tmp, " <->\tRoom: %d [%s] SubRoom: %d\n", GetRoom2()->GetID(),
                  GetRoom2()->GetCaption().c_str(), GetSubRoom2()->GetSubRoomID());
     } else {
          sprintf(tmp, " <->\tAusgang\n");
     }
     s.append(tmp);
     Log->Write(s);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
177 178 179
}

// TraVisTo Ausgabe
180
string Transition::GetDescription() const
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
{
     string geometry;
     char tmp[CLENGTH] = "";

     sprintf(tmp,"\t\t<door ID=\"%d\" color=\"180\" caption=\"%d_%d_%s\">\n",GetUniqueID(),GetID(),GetUniqueID(),GetCaption().c_str());
     geometry.append(tmp);
     sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\" zPos=\"%.2f\"/>\n",
             (GetPoint1().GetX()) * FAKTOR,
             (GetPoint1().GetY()) * FAKTOR,
             GetSubRoom1()->GetElevation(GetPoint1())*FAKTOR);
     geometry.append(tmp);
     sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\" zPos=\"%.2f\"/>\n",
             (GetPoint2().GetX()) * FAKTOR,
             (GetPoint2().GetY()) * FAKTOR,
             GetSubRoom1()->GetElevation(GetPoint2())*FAKTOR);
     geometry.append(tmp);
     geometry.append("\t\t</door>\n");
     return geometry;
}

void Transition::IncreaseDoorUsage(int number, double time)
{
     _doorUsage+=number;
     _lastPassingTime=time;
}

int Transition::GetDoorUsage() const
{
     return _doorUsage;
}

double Transition::GetLastPassingTime() const
{
     return _lastPassingTime;
215
}