SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GNECrossing.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A class for visualizing Inner Lanes (used when editing traffic lights)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include <iostream>
33 #include <utility>
34 #include <time.h>
39 #include <utils/common/ToString.h>
44 #include <utils/gui/div/GLHelper.h>
46 
47 #include "GNECrossing.h"
48 #include "GNEJunction.h"
49 #include "GNEUndoList.h"
50 #include "GNEChange_Attribute.h"
51 
52 #ifdef CHECK_MEMORY_LEAKS
53 #include <foreign/nvwa/debug_new.h>
54 #endif // CHECK_MEMORY_LEAKS
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 GNECrossing::GNECrossing(GNEJunction& parentJunction, const std::string& id) :
60  GNENetElement(parentJunction.getNet(), id, GLO_CROSSING, SUMO_TAG_CROSSING),
61  myParentJunction(parentJunction),
62  myCrossing(parentJunction.getNBNode()->getCrossing(id)),
63  myShape(myCrossing.shape) {
64  // Update geometry
66 }
67 
68 
70 
71 
72 void
74  int segments = (int) myShape.size() - 1;
75  if (segments >= 0) {
76  myShapeRotations.reserve(segments);
77  myShapeLengths.reserve(segments);
78  for (int i = 0; i < segments; ++i) {
79  const Position& f = myShape[i];
80  const Position& s = myShape[i + 1];
81  myShapeLengths.push_back(f.distanceTo2D(s));
82  myShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
83  }
84  }
85 }
86 
87 
88 void
91  return;
92  }
93  glPushMatrix();
94  glPushName(getGlID());
95  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
96 
97  if (myCrossing.priority) {
98  glColor3d(0.9, 0.9, 0.9);
99  } else {
100  glColor3d(0.1, 0.1, 0.1);
101  }
102  glTranslated(0, 0, .2);
103  // @todo: duplicate eliminate duplicate code with GNELane::drawCrossties(0.5, 1.0, myCrossing.width * 0.5);
104  {
105  SUMOReal length = 0.5;
106  SUMOReal spacing = 1.0;
107  SUMOReal halfWidth = myCrossing.width * 0.5;
108  glPushMatrix();
109  // draw on top of of the white area between the rails
110  glTranslated(0, 0, 0.1);
111  int e = (int) myShape.size() - 1;
112  for (int i = 0; i < e; ++i) {
113  glPushMatrix();
114  glTranslated(myShape[i].x(), myShape[i].y(), 0.0);
115  glRotated(myShapeRotations[i], 0, 0, 1);
116  for (SUMOReal t = 0; t < myShapeLengths[i]; t += spacing) {
117  glBegin(GL_QUADS);
118  glVertex2d(-halfWidth, -t);
119  glVertex2d(-halfWidth, -t - length);
120  glVertex2d(halfWidth, -t - length);
121  glVertex2d(halfWidth, -t);
122  glEnd();
123  }
124  glPopMatrix();
125  }
126  glPopMatrix();
127  }
128 
129  glTranslated(0, 0, -.2);
130  glPopName();
131  glPopMatrix();
132 }
133 
134 
137  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
139  return myPopup;
140 }
141 
142 
147  new GUIParameterTableWindow(app, *this, 2);
148  // add items
149  // close building
150  ret->closeBuilding();
151  return ret;
152 }
153 
154 
155 Boundary
158  b.grow(10);
159  return b;
160 }
161 
162 
163 std::string
165  switch (key) {
166  case SUMO_ATTR_ID:
167  return getMicrosimID();
168  break;
169  case SUMO_ATTR_WIDTH:
170  return toString(myCrossing.width);
171  break;
172  case SUMO_ATTR_PRIORITY:
173  return myCrossing.priority ? "true" : "false";
174  break;
175  case SUMO_ATTR_EDGES:
176  return toString(myCrossing.edges);
177  break;
178  default:
179  throw InvalidArgument("junction attribute '" + toString(key) + "' not allowed");
180  }
181 }
182 
183 
184 void
185 GNECrossing::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
186  if (value == getAttribute(key)) {
187  return; //avoid needless changes, later logic relies on the fact that attributes have changed
188  }
189  switch (key) {
190  case SUMO_ATTR_ID:
191  case SUMO_ATTR_EDGES:
192  throw InvalidArgument("modifying crossing attribute '" + toString(key) + "' not allowed");
193  case SUMO_ATTR_WIDTH:
194  case SUMO_ATTR_PRIORITY:
195  undoList->add(new GNEChange_Attribute(this, key, value), true);
196  break;
197  default:
198  throw InvalidArgument("crossing attribute '" + toString(key) + "' not allowed");
199  }
200 }
201 
202 
203 bool
204 GNECrossing::isValid(SumoXMLAttr key, const std::string& value) {
205  switch (key) {
206  case SUMO_ATTR_ID:
207  case SUMO_ATTR_EDGES:
208  return false;
209  case SUMO_ATTR_WIDTH:
210  return isPositive<SUMOReal>(value);
211  case SUMO_ATTR_PRIORITY:
212  return value == "true" || value == "false";
213  default:
214  throw InvalidArgument("crossing attribute '" + toString(key) + "' not allowed");
215  }
216 }
217 
218 // ===========================================================================
219 // private
220 // ===========================================================================
221 
222 void
223 GNECrossing::setAttribute(SumoXMLAttr key, const std::string& value) {
224  switch (key) {
225  case SUMO_ATTR_ID:
226  case SUMO_ATTR_EDGES:
227  throw InvalidArgument("modifying crossing attribute '" + toString(key) + "' not allowed");
228  case SUMO_ATTR_WIDTH:
229  myCrossing.width = parse<SUMOReal>(value);
231  break;
232  case SUMO_ATTR_PRIORITY:
233  myCrossing.priority = value == "true";
235  break;
236  default:
237  throw InvalidArgument("crossing attribute '" + toString(key) + "' not allowed");
238  }
239 }
240 /****************************************************************************/
a tl-logic
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
SUMOReal width
This lane's width.
Definition: NBNode.h:143
GNECrossing(GNEJunction &parentJunction, const std::string &id)
Constructor.
Definition: GNECrossing.cpp:59
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNECrossing.cpp:89
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
Definition: GNECrossing.h:142
Stores the information about how to visualize structures.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string getAttribute(SumoXMLAttr key) const
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
bool priority
whether the pedestrians have priority
Definition: NBNode.h:151
void updateGeometry()
update pre-computed geometry information
Definition: GNECrossing.cpp:73
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
#define PI
Definition: polyfonts.c:61
the edges of a route
void updateCrossingAttributes(NBNode::Crossing crossing)
modify the specified crossing (using friend privileges)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
friend class GNEChange_Attribute
declare friend class
GNEJunction & myParentJunction
the parent junction of this crossing
Definition: GNECrossing.h:128
GUIGLObjectPopupMenu * myPopup
the created popup
Definition: GNECrossing.h:146
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
NBNode::Crossing myCrossing
the data for this crossing
Definition: GNECrossing.h:131
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:232
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
The popup menu of a globject.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
virtual ~GNECrossing()
Destructor.
Definition: GNECrossing.cpp:69
bool drawCrossingsAndWalkingareas
whether crosings and walkingareas shall be drawn
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:139
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:232
#define SUMOReal
Definition: config.h:214
bool isValid(SumoXMLAttr key, const std::string &value)
const PositionVector myShape
the shape of the edge
Definition: GNECrossing.h:134
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void closeBuilding()
Closes the building of the table.
A window containing a gl-object's parameter.
std::vector< SUMOReal > myShapeRotations
Definition: GNECrossing.h:139
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
a junction