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.dlr.de/
10 // Copyright (C) 2001-2017 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 
60 // ===========================================================================
61 // member method definitions
62 // ===========================================================================
63 
64 GNEStoppingPlace::GNEStoppingPlace(const std::string& id, GNEViewNet* viewNet, SumoXMLTag tag, GUIIcon icon, GNELane* lane, double startPos, double endPos) :
65  GNEAdditional(id, viewNet, Position(), tag, icon),
66  myStartPos(startPos),
67  myEndPos(endPos),
68  mySignColor(RGBColor::YELLOW),
69  mySignColorSelected(RGBColor::BLUE),
70  myTextColor(RGBColor::CYAN),
71  myTextColorSelected(RGBColor::BLUE) {
72  // This additional belongs to a Lane
73  myLane = lane;
74 }
75 
76 
78 }
79 
80 
84 }
85 
86 
87 void
88 GNEStoppingPlace::moveAdditionalGeometry(double offsetx, double offsety) {
89  // Due a stoppingplace is placed over an lane ignore Warning of posy
90  UNUSED_PARAMETER(offsety);
91  // Move to Right if distance is positive, to left if distance is negative
92  if (((offsetx > 0) &&
94  ((offsetx < 0) && ((myLane->getPositionRelativeToParametricLength(myStartPos) + offsetx) > 0))) {
95  // change attribute
96  myStartPos += offsetx;
97  myEndPos += offsetx;
98  // Update geometry
100  }
101 }
102 
103 
104 void
105 GNEStoppingPlace::commmitAdditionalGeometryMoved(double oldPosx, double oldPosy, GNEUndoList* undoList) {
106  undoList->p_begin("position of " + toString(getTag()));
107  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_STARTPOS, toString(getStartPosition()), true, toString(oldPosx)));
108  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_ENDPOS, toString(getEndPosition()), true, toString(oldPosy)));
109  undoList->p_end();
110  // Refresh element
112 }
113 
114 
115 double
117  return myStartPos;
118 }
119 
120 
121 double
123  return myEndPos;
124 }
125 
126 
127 void
129  if (startPos < 0) {
130  throw InvalidArgument(toString(SUMO_ATTR_STARTPOS) + " '" + toString(startPos) + "' not allowed. Must be greater than 0");
131  } else if (startPos >= myEndPos) {
132  throw InvalidArgument(toString(SUMO_ATTR_STARTPOS) + " '" + toString(startPos) + "' not allowed. Must be smaller than endPos '" + toString(myEndPos) + "'");
133  } else if ((myEndPos - startPos) < 1) {
134  throw InvalidArgument(toString(SUMO_ATTR_STARTPOS) + " '" + toString(startPos) + "' not allowed. Length of StoppingPlace must be equal or greater than 1");
135  } else {
136  myStartPos = startPos;
137  }
138 }
139 
140 
141 void
143  if (endPos > myLane->getLaneShapeLength()) {
144  throw InvalidArgument(toString(SUMO_ATTR_ENDPOS) + " '" + toString(endPos) + "' not allowed. Must be smaller than lane length");
145  } else if (myStartPos >= endPos) {
146  throw InvalidArgument(toString(SUMO_ATTR_ENDPOS) + " '" + toString(endPos) + "' not allowed. Must be smaller than endPos '" + toString(myEndPos) + "'");
147  } else if ((endPos - myStartPos) < 1) {
148  throw InvalidArgument(toString(SUMO_ATTR_ENDPOS) + " '" + toString(endPos) + "' not allowed. Length of StoppingPlace must be equal or greater than 1");
149  } else {
150  myEndPos = endPos;
151  }
152 }
153 
154 
155 const std::string&
157  return myLane->getMicrosimID();
158 }
159 
160 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
void setEndPosition(double endPos)
Set a new End position in StoppingPlace.
GNELane * myLane
The lane this additional belongs.
GNEStoppingPlace(const std::string &id, GNEViewNet *viewNet, SumoXMLTag tag, GUIIcon icon, GNELane *lane, double startPos, double endPos)
Constructor.
Position getPositionInView() const
Returns position of StoppingPlace in view.
double getPositionRelativeToParametricLength(double position) const
Definition: GNELane.cpp:727
double x() const
Returns the x-position.
Definition: Position.h:63
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
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:82
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
void setStartPosition(double startPos)
Set a new Start position in StoppingPlace.
double myEndPos
The end position this stopping place is located at.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
double getEndPosition() const
Returns the End position of the stoppingPlace.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:715
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:825
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:89
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
friend class GNEChange_Attribute
declare friend class
const std::string & getParentName() const
Returns the name of the parent object (if any)
void moveAdditionalGeometry(double offsetx, double offsety)
change the position of the StoppingPlace geometry
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
~GNEStoppingPlace()
Destructor.
double getLaneShapeLength() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:721
double getStartPosition() const
Returns the Start position of the stoppingPlace.
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:621
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
virtual void updateGeometry()=0
update pre-computed geometry information
GNENet * getNet() const
get the net object
double myStartPos
The start position this stopping place is located at.
Position myPosition
The position in which this additional element is located.
void commmitAdditionalGeometryMoved(double oldPosx, double oldPosy, GNEUndoList *undoList)
updated geometry changes in the attributes of additional
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
SumoXMLTag getTag() const
get XML Tag assigned to this object