SUMO - Simulation of Urban MObility
GNEStoppingPlace.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 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 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <iostream>
32 #include <utility>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
45 #include <utils/gui/div/GLHelper.h>
49 
50 #include "GNEStoppingPlace.h"
51 #include "GNELane.h"
52 #include "GNEEdge.h"
53 #include "GNEJunction.h"
54 #include "GNEUndoList.h"
55 #include "GNENet.h"
56 #include "GNEChange_Attribute.h"
57 #include "GNEViewNet.h"
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif
62 
63 
64 // ===========================================================================
65 // member method definitions
66 // ===========================================================================
67 
68 GNEStoppingPlace::GNEStoppingPlace(const std::string& id, GNEViewNet* viewNet, SumoXMLTag tag, GNELane* lane, SUMOReal startPos, SUMOReal endPos, bool blocked) :
69  GNEAdditional(id, viewNet, Position(), tag, NULL, blocked),
70  myLane(lane),
71  myStartPos(startPos),
72  myEndPos(endPos),
73  mySignColor(RGBColor::YELLOW),
74  mySignColorSelected(RGBColor::BLUE),
75  myTextColor(RGBColor::CYAN),
76  myTextColorSelected(RGBColor::BLUE) {
77  myLane->addAdditional(this);
78 }
79 
80 
82  if (myLane) {
83  myLane->removeAdditional(this);
84  }
85 }
86 
87 
91 }
92 
93 
94 void
96  // Due a stoppingplace is placed over an lane ignore Warning of posy
97  UNUSED_PARAMETER(posy);
98  // if item isn't blocked
99  if (myBlocked == false) {
100  // Move to Right if distance is positive, to left if distance is negative
101  if (((posx > 0) && ((myEndPos + posx) < myLane->getLaneShapeLenght())) || ((posx < 0) && ((myStartPos + posx) > 0))) {
102  // change attribute
103  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_STARTPOS, toString(myStartPos + posx)));
104  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_ENDPOS, toString(myEndPos + posx)));
105  }
106  }
107 }
108 
109 
110 GNELane*
112  return myLane;
113 }
114 
115 
116 void
118  myLane = NULL;
119 }
120 
121 void
123  myLane->removeAdditional(this);
124  myLane = newLane;
125  myLane->addAdditional(this);
126  updateGeometry();
127  getViewNet()->update();
128 }
129 
130 
131 SUMOReal
133  return myStartPos;
134 }
135 
136 
137 SUMOReal
139  return myEndPos;
140 }
141 
142 
143 void
145  if (startPos < 0) {
146  throw InvalidArgument("Start position '" + toString(startPos) + "' not allowed. Must be greather than 0");
147  } else if (startPos >= myEndPos) {
148  throw InvalidArgument("Start position '" + toString(startPos) + "' not allowed. Must be smaller than endPos '" + toString(myEndPos) + "'");
149  } else if ((myEndPos - startPos) < 1) {
150  throw InvalidArgument("Start position '" + toString(startPos) + "' not allowed. Lenght of StoppingPlace must be equal or greather than 1");
151  } else {
152  myStartPos = startPos;
153  }
154 }
155 
156 
157 void
159  if (endPos > myLane->getLaneShapeLenght()) {
160  throw InvalidArgument("End position '" + toString(endPos) + "' not allowed. Must be smaller than lane length");
161  } else if (myStartPos >= endPos) {
162  throw InvalidArgument("End position '" + toString(endPos) + "' not allowed. Must be smaller than endPos '" + toString(myEndPos) + "'");
163  } else if ((endPos - myStartPos) < 1) {
164  throw InvalidArgument("End position '" + toString(endPos) + "' not allowed. Lenght of StoppingPlace must be equal or greather than 1");
165  } else {
166  myEndPos = endPos;
167  }
168 }
169 
170 
171 const std::string&
173  return myLane->getMicrosimID();
174 }
175 
176 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
SUMOReal getStartPosition() const
Returns the Start position of the stoppingPlace.
void setStartPosition(SUMOReal startPos)
Set a new Start position in StoppingPlace.
void moveAdditional(SUMOReal posx, SUMOReal posy, GNEUndoList *undoList)
change the position of the StoppingPlace geometry
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
SUMOReal myEndPos
The end position this stopping place is located at.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:530
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GNELane * myLane
The lane this stopping place belongs.
friend class GNEChange_Attribute
declare friend class
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
SUMOReal myStartPos
The start position this stopping place is located at.
~GNEStoppingPlace()
Destructor.
GNELane * getLane() const
Returns pointer to Lane of stopping place.
bool removeAdditional(GNEAdditional *additional)
Definition: GNELane.cpp:548
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void setEndPosition(SUMOReal endPos)
Set a new End position in StoppingPlace.
GNEStoppingPlace(const std::string &id, GNEViewNet *viewNet, SumoXMLTag tag, GNELane *lane, SUMOReal startPos, SUMOReal endPos, bool blocked=false)
Constructor.
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:456
SUMOReal getLaneShapeLenght() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:524
void changeLane(GNELane *newLane)
change lane of stopping place
bool myBlocked
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:63
virtual void updateGeometry()=0
update pre-computed geometry information
void removeLaneReference()
Remove reference to Lane of stopping place.
Position myPosition
The position in which this additional element is located.
#define SUMOReal
Definition: config.h:213
const std::string & getParentName() const
Returns the name of the parent object (if any)
void addAdditional(GNEAdditional *additional)
Definition: GNELane.cpp:542
Position getPositionInView() const
Returns position of StoppingPlace in view.
SUMOReal getEndPosition() const
Returns the End position of the stoppingPlace.