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  myStartPos(startPos),
71  myEndPos(endPos),
72  mySignColor(RGBColor::YELLOW),
73  mySignColorSelected(RGBColor::BLUE),
74  myTextColor(RGBColor::CYAN),
75  myTextColorSelected(RGBColor::BLUE) {
76  // This additional belongs to a Lane
77  myLane = lane;
78 }
79 
80 
82 }
83 
84 
88 }
89 
90 
91 void
93  // Due a stoppingplace is placed over an lane ignore Warning of posy
94  UNUSED_PARAMETER(offsety);
95  // Move to Right if distance is positive, to left if distance is negative
96  if (((offsetx > 0) &&
98  ((offsetx < 0) && ((myLane->getPositionRelativeToParametricLenght(myStartPos) + offsetx) > 0))) {
99  // change attribute
100  myStartPos += offsetx;
101  myEndPos += offsetx;
102  // Update geometry
103  updateGeometry();
104  }
105 }
106 
107 
108 void
110  undoList->p_begin("position of " + toString(getTag()));
111  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_STARTPOS, toString(getStartPosition()), true, toString(oldPosx)));
112  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_ENDPOS, toString(getEndPosition()), true, toString(oldPosy)));
113  undoList->p_end();
114  // Refresh element
116 }
117 
118 
119 SUMOReal
121  return myStartPos;
122 }
123 
124 
125 SUMOReal
127  return myEndPos;
128 }
129 
130 
131 void
133  if (startPos < 0) {
134  throw InvalidArgument("Start position '" + toString(startPos) + "' not allowed. Must be greather than 0");
135  } else if (startPos >= myEndPos) {
136  throw InvalidArgument("Start position '" + toString(startPos) + "' not allowed. Must be smaller than endPos '" + toString(myEndPos) + "'");
137  } else if ((myEndPos - startPos) < 1) {
138  throw InvalidArgument("Start position '" + toString(startPos) + "' not allowed. Lenght of StoppingPlace must be equal or greather than 1");
139  } else {
140  myStartPos = startPos;
141  }
142 }
143 
144 
145 void
147  if (endPos > myLane->getLaneShapeLenght()) {
148  throw InvalidArgument("End position '" + toString(endPos) + "' not allowed. Must be smaller than lane length");
149  } else if (myStartPos >= endPos) {
150  throw InvalidArgument("End position '" + toString(endPos) + "' not allowed. Must be smaller than endPos '" + toString(myEndPos) + "'");
151  } else if ((endPos - myStartPos) < 1) {
152  throw InvalidArgument("End position '" + toString(endPos) + "' not allowed. Lenght of StoppingPlace must be equal or greather than 1");
153  } else {
154  myEndPos = endPos;
155  }
156 }
157 
158 
159 const std::string&
161  return myLane->getMicrosimID();
162 }
163 
164 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
void commmitAdditionalGeometryMoved(SUMOReal oldPosx, SUMOReal oldPosy, GNEUndoList *undoList)
updated geometry changes in the attributes of additional
void setStartPosition(SUMOReal startPos)
Set a new Start position in StoppingPlace.
GNELane * myLane
The lane this additional belongs NULL if additional doesnt&#39; belongs to a lane.
Position getPositionInView() const
Returns position of StoppingPlace in view.
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:55
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:86
SUMOReal myEndPos
The end position this stopping place is located at.
SUMOReal getStartPosition() const
Returns the Start position of the stoppingPlace.
SUMOReal getLaneParametricLenght() const
returns the parameteric length of the lane
Definition: GNELane.cpp:681
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
SUMOReal getLaneShapeLenght() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:687
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:784
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:93
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOReal getEndPosition() const
Returns the End position of the stoppingPlace.
friend class GNEChange_Attribute
declare friend class
const std::string & getParentName() const
Returns the name of the parent object (if any)
SUMOReal myStartPos
The start position this stopping place is located at.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
~GNEStoppingPlace()
Destructor.
void moveAdditionalGeometry(SUMOReal offsetx, SUMOReal offsety)
change the position of the StoppingPlace geometry
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:583
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
SUMOReal getPositionRelativeToParametricLenght(SUMOReal position) const
Definition: GNELane.cpp:693
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:912
Position myPosition
The position in which this additional element is located.
#define SUMOReal
Definition: config.h:213
SumoXMLTag getTag() const
get Tag assigned to this object