SUMO - Simulation of Urban MObility
GNECalibratorRoute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <string>
30 #include <iostream>
31 #include <utility>
35 #include <utils/common/ToString.h>
36 #include <utils/geom/GeomHelper.h>
42 #include <utils/gui/div/GLHelper.h>
46 
47 #include "GNECalibratorRoute.h"
48 #include "GNECalibrator.h"
49 #include "GNECalibratorDialog.h"
50 #include "GNEEdge.h"
51 #include "GNELane.h"
52 #include "GNEViewNet.h"
53 #include "GNENet.h"
54 #include "GNEJunction.h"
55 #include "GNEChange_Attribute.h"
56 #include "GNEUndoList.h"
57 
58 
59 
60 // ===========================================================================
61 // member method definitions
62 // ===========================================================================
63 
66  myCalibratorParent(calibratorDialog->getEditedCalibrator()),
67  myRouteID(calibratorDialog->getEditedCalibrator()->getViewNet()->getNet()->generateCalibratorRouteID()),
68  myColor(RGBColor::BLACK) {
69  // add the Edge in which Calibrator is placed as default Edge
72  } else {
75  }
76 }
77 
78 
79 GNECalibratorRoute::GNECalibratorRoute(GNECalibrator* calibratorParent, const std::string& routeID, const std::vector<GNEEdge*>& edges, const RGBColor& color) :
81  myCalibratorParent(calibratorParent),
82  myRouteID(routeID),
83  myEdges(edges),
84  myColor(color) {
85 }
86 
87 
89 
90 
91 void
93  // Open route tag
94  device.openTag(getTag());
95  // Write route ID
97  // Write edge IDs
99  // Write Color
101  // Close flow tag
102  device.closeTag();
103 }
104 
105 
108  return myCalibratorParent;
109 }
110 
111 
112 const std::vector<GNEEdge*>&
114  return myEdges;
115 }
116 
117 
118 std::string
120  switch (key) {
121  case SUMO_ATTR_ID:
122  return myRouteID;
123  case SUMO_ATTR_EDGES:
124  return parseGNEEdges(myEdges);
125  case SUMO_ATTR_COLOR:
126  return toString(myColor);
127  default:
128  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
129  }
130 }
131 
132 
133 void
134 GNECalibratorRoute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
135  if (value == getAttribute(key)) {
136  return; //avoid needless changes, later logic relies on the fact that attributes have changed
137  }
138  switch (key) {
139  case SUMO_ATTR_ID:
140  case SUMO_ATTR_EDGES:
141  case SUMO_ATTR_COLOR:
142  undoList->p_add(new GNEChange_Attribute(this, key, value));
143  break;
144  default:
145  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
146  }
147 }
148 
149 
150 bool
151 GNECalibratorRoute::isValid(SumoXMLAttr key, const std::string& value) {
152  switch (key) {
153  case SUMO_ATTR_ID:
154  return isValidID(value) && (myCalibratorParent->getViewNet()->getNet()->retrieveCalibratorRoute(value, false) == NULL);
155  case SUMO_ATTR_EDGES:
156  if (checkGNEEdgesValid(myCalibratorParent->getViewNet()->getNet(), value, false)) {
157  // all edges exist, then check if compounds a valid route
159  } else {
160  return false;
161  }
162  case SUMO_ATTR_COLOR:
163  return canParse<RGBColor>(value);
164  default:
165  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
166  }
167 }
168 
169 // ===========================================================================
170 // private
171 // ===========================================================================
172 
173 void
174 GNECalibratorRoute::setAttribute(SumoXMLAttr key, const std::string& value) {
175  switch (key) {
176  case SUMO_ATTR_ID: {
177  std::string oldID = myRouteID;
178  myRouteID = value;
180  break;
181  }
182  case SUMO_ATTR_EDGES:
184  break;
185  case SUMO_ATTR_COLOR:
186  myColor = parse<RGBColor>(value);
187  break;
188  default:
189  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
190  }
191 }
192 
193 
194 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:902
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
weights: time range begin
const std::vector< GNEEdge * > & getGNEEdges() const
get GNEEdges of Calibrator ROute
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:53
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNECalibratorRoute(GNECalibratorDialog *calibratorDialog)
default constructor (used only in GNECalibratorDialog)
std::vector< GNEEdge * > myEdges
edges of route
static std::vector< GNEEdge * > parseGNEEdges(GNENet *net, const std::string &value)
parse string into vector of GNEEdges
std::string myRouteID
route in which this flow is used
begin/end of the description of a route
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
GNECalibrator * myCalibratorParent
pointer to calibrator parent
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
static bool hasAttribute(SumoXMLTag tag, SumoXMLAttr attr)
check if an element with certain tag has a certain attribute
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1121
void writeRoute(OutputDevice &device)
write Route values into a XML
friend class GNEChange_Attribute
declare friend class
void changeCalibratorRouteID(GNECalibratorRoute *route, const std::string &oldID)
change Calibrator Route ID
Definition: GNENet.cpp:1878
RGBColor myColor
color of ROute
~GNECalibratorRoute()
destructor
const std::string getID() const
function to support debugging
GNECalibratorRoute * retrieveCalibratorRoute(const std::string &id, bool hardFail=true) const
Returns the named calibrator route.
Definition: GNENet.cpp:1800
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Dialog for edit calibrators.
bool isValid(SumoXMLAttr key, const std::string &value)
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
GNENet * getNet() const
get the net object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
static bool isRouteValid(const std::vector< GNEEdge *> &edges, bool report)
check if a route is valid
static bool checkGNEEdgesValid(GNENet *net, const std::string &value, bool report)
check if a list of edge IDs is valid
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1000
A color information.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SumoXMLTag getTag() const
get XML Tag assigned to this object
GNECalibrator * getCalibratorParent() const
get pointer to calibrator parent