SUMO - Simulation of Urban MObility
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-2015 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 
58 // ===========================================================================
59 // static member definitions
60 // ===========================================================================
61 
62 
63 // ===========================================================================
64 // method definitions
65 // ===========================================================================
66 GNECrossing::GNECrossing(GNEJunction& parentJunction, const std::string& id) :
69  myParentJunction(parentJunction),
70  myCrossing(parentJunction.getNBNode()->getCrossing(id)),
71  myShape(myCrossing.shape) {
72  int segments = (int) myShape.size() - 1;
73  if (segments >= 0) {
74  myShapeRotations.reserve(segments);
75  myShapeLengths.reserve(segments);
76  for (int i = 0; i < segments; ++i) {
77  const Position& f = myShape[i];
78  const Position& s = myShape[i + 1];
79  myShapeLengths.push_back(f.distanceTo2D(s));
80  myShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
81  }
82  }
83 }
84 
85 
87 
88 
89 void
92  return;
93  }
94  glPushMatrix();
95  glPushName(getGlID());
96  glTranslated(0, 0, GLO_JUNCTION + 0.1); // must draw on top of junction
97 
98  if (myCrossing.priority) {
99  glColor3d(0.9, 0.9, 0.9);
100  } else {
101  glColor3d(0.1, 0.1, 0.1);
102  }
103  glTranslated(0, 0, .2);
104  // @todo: duplicate eliminate duplicate code with GNELane::drawCrossties(0.5, 1.0, myCrossing.width * 0.5);
105  {
106  SUMOReal length = 0.5;
107  SUMOReal spacing = 1.0;
108  SUMOReal halfWidth = myCrossing.width * 0.5;
109  glPushMatrix();
110  // draw on top of of the white area between the rails
111  glTranslated(0, 0, 0.1);
112  int e = (int) myShape.size() - 1;
113  for (int i = 0; i < e; ++i) {
114  glPushMatrix();
115  glTranslated(myShape[i].x(), myShape[i].y(), 0.0);
116  glRotated(myShapeRotations[i], 0, 0, 1);
117  for (SUMOReal t = 0; t < myShapeLengths[i]; t += spacing) {
118  glBegin(GL_QUADS);
119  glVertex2d(-halfWidth, -t);
120  glVertex2d(-halfWidth, -t - length);
121  glVertex2d(halfWidth, -t - length);
122  glVertex2d(halfWidth, -t);
123  glEnd();
124  }
125  glPopMatrix();
126  }
127  glPopMatrix();
128  }
129 
130 
131  glTranslated(0, 0, -.2);
132  glPopName();
133  glPopMatrix();
134 }
135 
136 
139  myPopup = new GUIGLObjectPopupMenu(app, parent, *this);
141  return myPopup;
142 }
143 
144 
149  new GUIParameterTableWindow(app, *this, 2);
150  // add items
151  // close building
152  ret->closeBuilding();
153  return ret;
154 }
155 
156 
157 Boundary
160  b.grow(10);
161  return b;
162 }
163 
164 
165 std::string
167  switch (key) {
168  case SUMO_ATTR_ID:
169  return getMicrosimID();
170  break;
171  case SUMO_ATTR_WIDTH:
172  return toString(myCrossing.width);
173  break;
174  case SUMO_ATTR_PRIORITY:
175  return myCrossing.priority ? "true" : "false";
176  break;
177  case SUMO_ATTR_EDGES:
178  return toString(myCrossing.edges);
179  break;
180  default:
181  throw InvalidArgument("junction attribute '" + toString(key) + "' not allowed");
182  }
183 }
184 
185 
186 void
187 GNECrossing::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
188  if (value == getAttribute(key)) {
189  return; //avoid needless changes, later logic relies on the fact that attributes have changed
190  }
191  switch (key) {
192  case SUMO_ATTR_ID:
193  case SUMO_ATTR_EDGES:
194  throw InvalidArgument("modifying crossing attribute '" + toString(key) + "' not allowed");
195  case SUMO_ATTR_WIDTH:
196  case SUMO_ATTR_PRIORITY:
197  undoList->add(new GNEChange_Attribute(this, key, value), true);
198  break;
199  default:
200  throw InvalidArgument("crossing attribute '" + toString(key) + "' not allowed");
201  }
202 }
203 
204 
205 bool
206 GNECrossing::isValid(SumoXMLAttr key, const std::string& value) {
207  switch (key) {
208  case SUMO_ATTR_ID:
209  case SUMO_ATTR_EDGES:
210  return false;
211  case SUMO_ATTR_WIDTH:
212  return isPositive<SUMOReal>(value);
213  case SUMO_ATTR_PRIORITY:
214  return value == "true" || value == "false";
215  default:
216  throw InvalidArgument("crossing attribute '" + toString(key) + "' not allowed");
217  }
218 }
219 
220 // ===========================================================================
221 // private
222 // ===========================================================================
223 
224 void
225 GNECrossing::setAttribute(SumoXMLAttr key, const std::string& value) {
226  switch (key) {
227  case SUMO_ATTR_ID:
228  case SUMO_ATTR_EDGES:
229  throw InvalidArgument("modifying crossing attribute '" + toString(key) + "' not allowed");
230  case SUMO_ATTR_WIDTH:
231  myCrossing.width = parse<SUMOReal>(value);
233  break;
234  case SUMO_ATTR_PRIORITY:
235  myCrossing.priority = value == "true";
237  break;
238  default:
239  throw InvalidArgument("crossing attribute '" + toString(key) + "' not allowed");
240  }
241 }
242 /****************************************************************************/
a tl-logic
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
SUMOReal width
This lane&#39;s width.
Definition: NBNode.h:143
GNECrossing(GNEJunction &parentJunction, const std::string &id)
Constructor.
Definition: GNECrossing.cpp:66
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNECrossing.cpp:90
std::vector< SUMOReal > myShapeLengths
The lengths of the shape parts.
Definition: GNECrossing.h:138
Stores the information about how to visualize structures.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:154
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.
Definition: GUIGlObject.h:123
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
bool priority
whether the pedestrians have priority
Definition: NBNode.h:151
#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
GNEJunction & myParentJunction
the parent junction of this crossing
Definition: GNECrossing.h:124
GUIGLObjectPopupMenu * myPopup
the created popup
Definition: GNECrossing.h:142
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
NBNode::Crossing myCrossing
the data for this crossing
Definition: GNECrossing.h:127
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:201
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:86
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:130
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&#39;s parameter.
std::vector< SUMOReal > myShapeRotations
The rotations of the shape parts.
Definition: GNECrossing.h:135
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
a junction