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 /****************************************************************************/
9 // APIs for getting/setting junction values via TraCI
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #ifndef NO_TRACI
34 
35 #include "TraCIConstants.h"
36 #include <microsim/MSNet.h>
37 #include <microsim/MSJunction.h>
39 #include <microsim/MSNet.h>
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // used namespaces
49 // ===========================================================================
50 using namespace traci;
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 bool
58  tcpip::Storage& outputStorage) {
59  // variable
60  int variable = inputStorage.readUnsignedByte();
61  std::string id = inputStorage.readString();
62  // check variable
63  if (variable != ID_LIST && variable != VAR_POSITION && variable != ID_COUNT) {
64  server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Get Junction Variable: unsupported variable specified", outputStorage);
65  return false;
66  }
67  // begin response building
68  tcpip::Storage tempMsg;
69  // response-code, variableID, objectID
71  tempMsg.writeUnsignedByte(variable);
72  tempMsg.writeString(id);
73  if (variable == ID_LIST) {
74  std::vector<std::string> ids;
77  tempMsg.writeStringList(ids);
78  } else if (variable == ID_COUNT) {
79  std::vector<std::string> ids;
82  tempMsg.writeInt((int) ids.size());
83  } else {
85  if (j == 0) {
86  server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_ERR, "Junction '" + id + "' is not known", outputStorage);
87  return false;
88  }
89  switch (variable) {
90  case ID_LIST:
91  break;
92  case VAR_POSITION:
94  tempMsg.writeDouble(j->getPosition().x());
95  tempMsg.writeDouble(j->getPosition().y());
96  break;
97  default:
98  break;
99  }
100  }
101  server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_OK, "", outputStorage);
102  server.writeResponseWithLength(outputStorage, tempMsg);
103  return true;
104 }
105 
106 
107 bool
108 TraCIServerAPI_Junction::getPosition(const std::string& id, Position& p) {
110  if (j == 0) {
111  return false;
112  }
113  p = j->getPosition();
114  return true;
115 }
116 
117 
118 TraCIRTree*
120  TraCIRTree* t = new TraCIRTree();
121  const std::map<std::string, MSJunction*>& junctions = MSNet::getInstance()->getJunctionControl().getMyMap();
122  for (std::map<std::string, MSJunction*>::const_iterator i = junctions.begin(); i != junctions.end(); ++i) {
123  Boundary b = (*i).second->getShape().getBoxBoundary();
124  t->addObject((*i).second, b);
125  }
126  return t;
127 }
128 
129 #endif
130 
131 
132 /****************************************************************************/
133