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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A abstract class for netElements
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNEViewParent.h>
30 
31 #include "GNENetElement.h"
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
37 
38 
39 GNENetElement::GNENetElement(GNENet* net, const std::string& id, GUIGlObjectType type, SumoXMLTag tag) :
40  GUIGlObject(type, id),
42  myNet(net),
43  myMovingGeometryBoundary() {}
44 
45 
47 
48 
49 GNENet*
51  return myNet;
52 }
53 
54 
55 void
57  // First check that additional wasn't already inserted
58  if (std::find(myFirstAdditionalParents.begin(), myFirstAdditionalParents.end(), additional) != myFirstAdditionalParents.end()) {
59  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' was already inserted in " + toString(getTag()) + " with ID='" + getID() + "'");
60  } else {
61  myFirstAdditionalParents.push_back(additional);
62  // update geometry is needed for stacked additionals (routeProbes and Vaporicers)
63  updateGeometry(true);
64  }
65 }
66 
67 
68 void
70  // First check that additional was already inserted
71  auto it = std::find(myFirstAdditionalParents.begin(), myFirstAdditionalParents.end(), additional);
72  if (it == myFirstAdditionalParents.end()) {
73  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' doesn't exist in " + toString(getTag()) + " with ID='" + getID() + "'");
74  } else {
75  myFirstAdditionalParents.erase(it);
76  // update geometry is needed for stacked additionals (routeProbes and Vaporizers)
77  updateGeometry(true);
78  }
79 }
80 
81 
82 void
84  // First check that additional wasn't already inserted
85  if (std::find(myAdditionalChilds.begin(), myAdditionalChilds.end(), additional) != myAdditionalChilds.end()) {
86  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' was already inserted in " + toString(getTag()) + " with ID='" + getID() + "'");
87  } else {
88  myAdditionalChilds.push_back(additional);
89  // update geometry is needed for stacked additionals (routeProbes and Vaporicers)
90  updateGeometry(true);
91  }
92 }
93 
94 
95 void
97  // First check that additional was already inserted
98  auto it = std::find(myAdditionalChilds.begin(), myAdditionalChilds.end(), additional);
99  if (it == myAdditionalChilds.end()) {
100  throw ProcessError(toString(additional->getTag()) + " with ID='" + additional->getID() + "' doesn't exist in " + toString(getTag()) + " with ID='" + getID() + "'");
101  } else {
102  myAdditionalChilds.erase(it);
103  // update geometry is needed for stacked additionals (routeProbes and Vaporizers)
104  updateGeometry(true);
105  }
106 }
107 
108 
109 const std::vector<GNEAdditional*>&
112 }
113 
114 
115 const std::vector<GNEAdditional*>&
117  return myAdditionalChilds;
118 }
119 
120 
123  // Create table
124  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, getTagProperties(getTag()).getNumberOfAttributes());
125  // Iterate over attributes
126  for (auto i : getTagProperties(getTag())) {
127  // Add attribute and set it dynamic if aren't unique
128  if (i.second.isUnique()) {
129  ret->mkItem(toString(i.first).c_str(), false, getAttribute(i.first));
130  } else {
131  ret->mkItem(toString(i.first).c_str(), true, getAttribute(i.first));
132  }
133  }
134  // close building
135  ret->closeBuilding();
136  return ret;
137 }
138 
139 
140 void
142  if (!myNet) {
143  throw ProcessError("Net cannot be nullptr");
144  } else {
145  gSelected.select(dynamic_cast<GUIGlObject*>(this)->getGlID());
146  if (changeFlag) {
147  mySelected = true;
148  }
149  }
150 }
151 
152 
153 void
155  if (!myNet) {
156  throw ProcessError("Net cannot be nullptr");
157  } else {
158  gSelected.deselect(dynamic_cast<GUIGlObject*>(this)->getGlID());
159  if (changeFlag) {
160  mySelected = false;
161  }
162  }
163 }
164 
165 
166 bool
168  return mySelected;
169 }
170 
171 
172 std::string
174  if (getTag() == SUMO_TAG_CONNECTION) {
176  } else {
177  return toString(getTag()) + ": " + getID();
178  }
179 }
180 
181 
182 std::string
184  if (getTag() == SUMO_TAG_LANE) {
186  } else if (getTag() == SUMO_TAG_CONNECTION) {
188  } else if (getTag() == SUMO_TAG_CROSSING) {
190  } else {
191  return toString(getTag());
192  }
193 }
194 
195 /****************************************************************************/
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
SumoXMLTag
Numbers representing SUMO-XML - element names.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
GNENet * myNet
the net to inform about updates
GUIGlObjectType
begin/end of the description of a single lane
GNENet * getNet() const
get Net in which this element is placed
virtual void updateGeometry(bool updateGrid)=0
update pre-computed geometry information
connectio between two lanes
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:80
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
~GNENetElement()
Destructor.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
GNENetElement(GNENet *net, const std::string &id, GUIGlObjectType type, SumoXMLTag tag)
Constructor.
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parameter this edge (For example, Rerouters) ...
void addAdditionalParent(GNEAdditional *additional)
add additional child to this edge
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void addAdditionalChild(GNEAdditional *additional)
add additional child to this edge
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
const std::string getID() const
function to support debugging
void removeAdditionalChild(GNEAdditional *additional)
remove additional child from this edge
void selectAttributeCarrier(bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
void deselect(GUIGlID id)
Deselects the object with the given id.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
crossing between edges for pedestrians
virtual std::string getAttribute(SumoXMLAttr key) const =0
GUIGlID getGlID() const
Returns the numerical id of the object.
std::vector< GNEAdditional * > myAdditionalChilds
list of Additional Childs of this NetElement
void removeAdditionalParent(GNEAdditional *additional)
remove additional child from this edge
const std::vector< GNEAdditional * > & getAdditionalChilds() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
std::vector< GNEAdditional * > myFirstAdditionalParents
list of Additional parents of this NetElement
static const TagValues & getTagProperties(SumoXMLTag tag)
get Tag Properties
GUISelectedStorage gSelected
A global holder of selected objects.
A window containing a gl-object&#39;s parameter.
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
SumoXMLTag getTag() const
get XML Tag assigned to this object