SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TraCIServerAPI_Junction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // APIs for getting/setting junction values via TraCI
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
14 // Copyright (C) 2009-2014 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #ifndef NO_TRACI
36 
37 #include "TraCIConstants.h"
38 #include <microsim/MSNet.h>
39 #include <microsim/MSJunction.h>
41 #include <microsim/MSNet.h>
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 bool
54  tcpip::Storage& outputStorage) {
55  // variable
56  int variable = inputStorage.readUnsignedByte();
57  std::string id = inputStorage.readString();
58  // check variable
59  if (variable != ID_LIST && variable != VAR_POSITION && variable != ID_COUNT && variable != VAR_SHAPE) {
60  return server.writeErrorStatusCmd(CMD_GET_JUNCTION_VARIABLE, "Get Junction Variable: unsupported variable specified", outputStorage);
61  }
62  // begin response building
63  tcpip::Storage tempMsg;
64  // response-code, variableID, objectID
66  tempMsg.writeUnsignedByte(variable);
67  tempMsg.writeString(id);
68  if (variable == ID_LIST) {
69  std::vector<std::string> ids;
72  tempMsg.writeStringList(ids);
73  } else if (variable == ID_COUNT) {
74  std::vector<std::string> ids;
77  tempMsg.writeInt((int) ids.size());
78  } else {
80  if (j == 0) {
81  return server.writeErrorStatusCmd(CMD_GET_JUNCTION_VARIABLE, "Junction '" + id + "' is not known", outputStorage);
82  }
83  switch (variable) {
84  case ID_LIST:
85  break;
86  case VAR_POSITION:
88  tempMsg.writeDouble(j->getPosition().x());
89  tempMsg.writeDouble(j->getPosition().y());
90  break;
91  case VAR_SHAPE:
93  tempMsg.writeUnsignedByte((int)MIN2(static_cast<size_t>(255), j->getShape().size()));
94  for (unsigned int iPoint = 0; iPoint < MIN2(static_cast<size_t>(255), j->getShape().size()); ++iPoint) {
95  tempMsg.writeDouble(j->getShape()[iPoint].x());
96  tempMsg.writeDouble(j->getShape()[iPoint].y());
97  }
98  break;
99 
100  default:
101  break;
102  }
103  }
104  server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_OK, "", outputStorage);
105  server.writeResponseWithLength(outputStorage, tempMsg);
106  return true;
107 }
108 
109 bool
110 TraCIServerAPI_Junction::getPosition(const std::string& id, Position& p) {
112  if (j == 0) {
113  return false;
114  }
115  p = j->getPosition();
116  return true;
117 }
118 
119 
120 NamedRTree*
122  NamedRTree* t = new NamedRTree();
123  const std::map<std::string, MSJunction*>& junctions = MSNet::getInstance()->getJunctionControl().getMyMap();
124  for (std::map<std::string, MSJunction*>::const_iterator i = junctions.begin(); i != junctions.end(); ++i) {
125  Boundary b = (*i).second->getShape().getBoxBoundary();
126  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
127  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
128  t->Insert(cmin, cmax, (*i).second);
129  }
130  return t;
131 }
132 
133 #endif
134 
135 
136 /****************************************************************************/
137