Eclipse SUMO - Simulation of Urban MObility
GNETAZRelData.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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // class for TAZ relation data
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEUndoList.h>
29 #include <netedit/GNEViewNet.h>
30 #include <netedit/GNEViewParent.h>
33 
34 #include "GNETAZRelData.h"
35 #include "GNEDataInterval.h"
36 
37 
38 // ===========================================================================
39 // member method definitions
40 // ===========================================================================
41 
42 // ---------------------------------------------------------------------------
43 // GNETAZRelData - methods
44 // ---------------------------------------------------------------------------
45 
47  const std::map<std::string, std::string>& parameters) :
48  GNEGenericData(SUMO_TAG_TAZREL, GLO_TAZRELDATA, dataIntervalParent, parameters,
49 {}, {}, {}, {}, {}, {fromTAZ, toTAZ}, {}, {}) {
50 }
51 
52 
54 
55 
56 const RGBColor&
58  return RGBColor::ORANGE;
59 }
60 
61 
62 bool
64  // first check if we're in supermode data
66  return false;
67  }
68  // obtain pointer to TAZ data frame (only for code legibly)
69  const GNETAZRelDataFrame* TAZRelDataFrame = myNet->getViewNet()->getViewParent()->getTAZRelDataFrame();
70  // get current data edit mode
72  // check if we have to filter generic data
73  if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
75  } else if (TAZRelDataFrame->shown()) {
76  // check interval
77  if ((TAZRelDataFrame->getIntervalSelector()->getDataInterval() != nullptr) &&
78  (TAZRelDataFrame->getIntervalSelector()->getDataInterval() != myDataIntervalParent)) {
79  return false;
80  }
81  // check attribute
82  if ((TAZRelDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
83  (getParametersMap().count(TAZRelDataFrame->getAttributeSelector()->getFilteredAttribute()) == 0)) {
84  return false;
85  }
86  // all checks ok, then return true
87  return true;
88  } else {
89  // GNETAZRelDataFrame hidden, then return false
90  return false;
91  }
92 }
93 
94 
95 void
97  // nothing to update
98 }
99 
100 
101 Position
103  return getParentTAZElements().front()->getPositionInView();
104 }
105 
106 
107 void
109  // open device
110  device.openTag(SUMO_TAG_TAZREL);
111  // write from
112  device.writeAttr(SUMO_ATTR_FROM, getParentTAZElements().front()->getID());
113  // write to
114  device.writeAttr(SUMO_ATTR_TO, getParentTAZElements().back()->getID());
115  // iterate over attributes
116  for (const auto& attribute : getParametersMap()) {
117  // write attribute (don't use writeParams)
118  device.writeAttr(attribute.first, attribute.second);
119  }
120  // close device
121  device.closeTag();
122 }
123 
124 
125 bool
127  return true;
128 }
129 
130 
131 std::string
133  return "";
134 }
135 
136 
137 void
139  throw InvalidArgument(getTagStr() + " cannot fix any problem");
140 }
141 
142 
143 void
145  // Nothing to draw
146 }
147 
148 
149 void
150 GNETAZRelData::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const double /*offsetFront*/) const {
151  //
152 }
153 
154 
155 void
156 GNETAZRelData::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const double /*offsetFront*/) const {
157  //
158 }
159 
160 
161 Boundary
163  return getParentTAZElements().front()->getCenteringBoundary();
164 }
165 
166 
167 std::string
169  switch (key) {
170  case SUMO_ATTR_ID:
171  return getParentTAZElements().front()->getID();
172  case SUMO_ATTR_FROM:
173  return getParentTAZElements().front()->getID();
174  case SUMO_ATTR_TO:
175  return getParentTAZElements().back()->getID();
176  case GNE_ATTR_DATASET:
178  case GNE_ATTR_SELECTED:
180  case GNE_ATTR_PARAMETERS:
181  return getParametersStr();
182  default:
183  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
184  }
185 }
186 
187 
188 double
190  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
191 }
192 
193 
194 void
195 GNETAZRelData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
196  if (value == getAttribute(key)) {
197  return; //avoid needless changes, later logic relies on the fact that attributes have changed
198  }
199  switch (key) {
200  case SUMO_ATTR_FROM:
201  case SUMO_ATTR_TO:
202  case GNE_ATTR_SELECTED:
203  case GNE_ATTR_PARAMETERS:
204  undoList->p_add(new GNEChange_Attribute(this, key, value));
205  break;
206  default:
207  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
208  }
209 }
210 
211 
212 bool
213 GNETAZRelData::isValid(SumoXMLAttr key, const std::string& value) {
214  switch (key) {
215  case SUMO_ATTR_FROM:
216  case SUMO_ATTR_TO:
217  return SUMOXMLDefinitions::isValidNetID(value) && (myNet->retrieveTAZElement(SUMO_TAG_TAZ, value, false) != nullptr);
218  case GNE_ATTR_SELECTED:
219  return canParse<bool>(value);
220  case GNE_ATTR_PARAMETERS:
221  return Parameterised::areParametersValid(value);
222  default:
223  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
224  }
225 }
226 
227 
228 void
230  // Nothing to enable
231 }
232 
233 
234 void
236  // Nothing to disable enable
237 }
238 
239 
241  switch (key) {
242  case SUMO_ATTR_ID:
243  return false;
244  default:
245  return true;
246  }
247 }
248 
249 
250 std::string
252  return getTagStr();
253 }
254 
255 
256 std::string
258  return getTagStr() + ": " + getParentTAZElements().front()->getID() + "->" + getParentTAZElements().back()->getID();
259 }
260 
261 
262 void
263 GNETAZRelData::setAttribute(SumoXMLAttr key, const std::string& value) {
264  switch (key) {
265  case SUMO_ATTR_FROM: {
266  // change first TAZ
268  break;
269  }
270  case SUMO_ATTR_TO: {
271  // change last TAZ
273  break;
274  }
275  case GNE_ATTR_SELECTED:
276  if (parse<bool>(value)) {
278  } else {
280  }
281  break;
282  case GNE_ATTR_PARAMETERS:
283  setParametersStr(value);
284  // update attribute colors
286  break;
287  default:
288  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
289  }
290 }
291 
292 
293 void
294 GNETAZRelData::setEnabledAttribute(const int /*enabledAttributes*/) {
295  throw InvalidArgument("Nothing to enable");
296 }
297 
298 /****************************************************************************/
DataEditMode
@brie enum for data edit modes
@ DATA_SELECT
mode for selecting data elements
@ DATA_INSPECT
mode for inspecting data elements
@ DATA_DELETE
mode for deleting data elements
@ GLO_TAZRELDATA
TAZ relation data.
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_TAZREL
a relation between two TAZs
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ GNE_ATTR_DATASET
data set of a generic data
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
An Element which don't belongs to GNENet but has influency in the simulation.
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
const std::string & getID() const
get ID
Definition: GNEDataSet.cpp:119
void updateAttributeColors()
update attribute colors deprecated
Definition: GNEDataSet.cpp:142
std::string getFilteredAttribute() const
get filtered attribute
GNEDataInterval * getDataInterval() const
get current select data set ID
const AttributeSelector * getAttributeSelector() const
getattribute selector modul
const IntervalSelector * getIntervalSelector() const
get interval selector modul
An Element which don't belongs to GNENet but has influency in the simulation.
void replaceFirstParentTAZElement(SumoXMLTag tag, const std::string &value)
replace the first parent TAZElement
GNEDataInterval * myDataIntervalParent
dataInterval Parent
void replaceLastParentTAZElement(SumoXMLTag tag, const std::string &value)
replace the last parent TAZElement
bool isVisibleInspectDeleteSelect() const
check if attribute is visible in inspect, delete or select mode
const std::string & getID() const
get ID
const std::vector< GNETAZElement * > & getParentTAZElements() const
get parent TAZElements
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
GNETAZElement * retrieveTAZElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named TAZElement.
Definition: GNENet.cpp:3001
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNETAZElement.h:45
bool isGenericDataValid() const
check if current data set is valid to be writed into XML (by default true, can be reimplemented in ch...
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const double offsetFront) const
Draws partial object (lane)
GNETAZRelData(GNEDataInterval *dataIntervalParent, GNETAZElement *fromTAZ, GNETAZElement *toTAZ, const std::map< std::string, std::string > &parameters)
Constructor.
void writeGenericData(OutputDevice &device) const
writte data set element into a xml file
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void setEnabledAttribute(const int enabledAttributes)
method for enabling the attribute and nothing else (used in GNEChange_EnableAttribute)
Boundary getCenteringBoundary() const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform data set changes
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool isGenericDataVisible() const
check if current TAZ rel data is visible
std::string getGenericDataProblem() const
return a string with the current data set problem (by default empty, can be reimplemented in children...
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
const RGBColor & getColor() const
get TAZ rel data color
std::string getAttribute(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
Position getPositionInView() const
Returns element position in view.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void fixGenericDataProblem()
fix data set problem (by default throw an exception, has to be reimplemented in children)
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
bool isAttributeEnabled(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
double getAttributeDouble(SumoXMLAttr key) const
~GNETAZRelData()
Destructor.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:467
GNEViewParent * getViewParent() const
get the net object
GNETAZRelDataFrame * getTAZRelDataFrame() const
get frame for DATA_TAZRELDATA
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:239
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
static const RGBColor ORANGE
Definition: RGBColor.h:186
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
DataEditMode dataEditMode
the current Data edit mode
bool isCurrentSupermodeData() const
@check if current supermode is Data