SUMO - Simulation of Urban MObility
GNENetElement.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 // A abstract class for netElements
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 
31 
32 #include "GNENetElement.h"
33 #include "GNEAdditional.h"
34 #include "GNENet.h"
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 
40 
41 GNENetElement::GNENetElement(GNENet* net, const std::string& id, GUIGlObjectType type, SumoXMLTag tag, GUIIcon icon) :
42  GUIGlObject(type, id),
43  GNEAttributeCarrier(tag, icon),
44  myNet(net) {
45 }
46 
47 
49 
50 
51 GNENet*
53  return myNet;
54 }
55 
56 
57 void
59  // First check that additional wasn't already inserted
60  if (std::find(myAdditionalParents.begin(), myAdditionalParents.end(), additional) != myAdditionalParents.end()) {
61  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' was already inserted in " + toString(getTag()) + " with ID='" + getID() + "'");
62  } else {
63  myAdditionalParents.push_back(additional);
64  // update geometry is needed for stacked additionals (routeProbes and Vaporicers)
66  }
67 }
68 
69 
70 void
72  // First check that additional was already inserted
73  auto it = std::find(myAdditionalParents.begin(), myAdditionalParents.end(), additional);
74  if (it == myAdditionalParents.end()) {
75  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' doesn't exist in " + toString(getTag()) + " with ID='" + getID() + "'");
76  } else {
77  myAdditionalParents.erase(it);
78  // update geometry is needed for stacked additionals (routeProbes and Vaporicers)
80  }
81 }
82 
83 
84 void
86  // First check that additional wasn't already inserted
87  if (std::find(myAdditionalChilds.begin(), myAdditionalChilds.end(), additional) != myAdditionalChilds.end()) {
88  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' was already inserted in " + toString(getTag()) + " with ID='" + getID() + "'");
89  } else {
90  myAdditionalChilds.push_back(additional);
91  // update geometry is needed for stacked additionals (routeProbes and Vaporicers)
93  }
94 }
95 
96 
97 void
99  // First check that additional was already inserted
100  auto it = std::find(myAdditionalChilds.begin(), myAdditionalChilds.end(), additional);
101  if (it == myAdditionalChilds.end()) {
102  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' doesn't exist in " + toString(getTag()) + " with ID='" + getID() + "'");
103  } else {
104  myAdditionalChilds.erase(it);
105  // update geometry is needed for stacked additionals (routeProbes and Vaporicers)
106  updateGeometry();
107  }
108 }
109 
110 
111 const std::vector<GNEAdditional*>&
113  return myAdditionalParents;
114 }
115 
116 
117 const std::vector<GNEAdditional*>&
119  return myAdditionalChilds;
120 }
121 
122 
123 const std::string&
125  return myNet->getMicrosimID();
126 }
127 
128 
131  // get attributes
132  std::vector<SumoXMLAttr> attributes = getAttrs();
133  // Create table
134  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, (int)attributes.size());
135  // Iterate over attributes
136  for (auto i : attributes) {
137  // Add attribute and set it dynamic if aren't unique
139  ret->mkItem(toString(i).c_str(), false, getAttribute(i));
140  } else {
141  ret->mkItem(toString(i).c_str(), true, getAttribute(i));
142  }
143  }
144  // close building
145  ret->closeBuilding();
146  return ret;
147 }
148 
149 
150 /****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::vector< GNEAdditional * > myAdditionalParents
list of Additional parents of this NetElement
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
GNENet * myNet
the net to inform about updates
GUIGlObjectType
std::vector< SumoXMLAttr > getAttrs() const
get vector of attributes
virtual const std::string & getParentName() const
Returns the name of the parent object.
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:42
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:91
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
~GNENetElement()
Destructor.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GNENet * getNet() const
get Net in which this element is placed
void addAdditionalParent(GNEAdditional *additional)
add additional child to this edge
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
void addAdditionalChild(GNEAdditional *additional)
add additional child to this edge
const std::vector< GNEAdditional * > & getAdditionalChilds() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
const std::string getID() const
function to support debugging
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parameter this edge (For example, Rerouters) ...
static bool isUnique(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is unique (may not be edited for a multi-selection and don&#39;t have a default valu...
virtual void updateGeometry()=0
update pre-computed geometry information
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:59
virtual std::string getAttribute(SumoXMLAttr key) const =0
This functions has to be implemented in all GNEAttributeCarriers.
std::vector< GNEAdditional * > myAdditionalChilds
list of Additional Childs of this NetElement
void removeAdditionalParent(GNEAdditional *additional)
remove additional child from this edge
SumoXMLTag getTag() const
get XML Tag assigned to this object
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
GNENetElement(GNENet *net, const std::string &id, GUIGlObjectType type, SumoXMLTag tag, GUIIcon icon)
Constructor.
A window containing a gl-object&#39;s parameter.