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 
24 #include <netedit/GNENet.h>
25 #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(additional->getTagStr() + " with ID='" + additional->getID() + "' was already inserted in " + getTagStr() + " 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(additional->getTagStr() + " with ID='" + additional->getID() + "' doesn't exist in " + getTagStr() + " 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(additional->getTagStr() + " with ID='" + additional->getID() + "' was already inserted in " + getTagStr() + " 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(additional->getTagStr() + " with ID='" + additional->getID() + "' doesn't exist in " + getTagStr() + " 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
125  // Iterate over attributes
126  for (const auto &i : myTagProperty) {
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 {
146  // add object into list of selected objects
148  if (changeFlag) {
149  mySelected = true;
150 
151  }
152  }
153 }
154 
155 
156 void
158  if (!myNet) {
159  throw ProcessError("Net cannot be nullptr");
160  } else {
162  // remove object of list of selected objects
164  if (changeFlag) {
165  mySelected = false;
166  }
167  }
168 }
169 
170 
171 bool
173  return mySelected;
174 }
175 
176 
177 std::string
181  } else {
182  return getTagStr() + ": " + getID();
183  }
184 }
185 
186 
187 std::string
191  } else if (myTagProperty.getTag() == SUMO_TAG_CONNECTION) {
193  } else if (myTagProperty.getTag() == SUMO_TAG_CROSSING) {
195  } else {
196  return getTagStr();
197  }
198 }
199 
200 /****************************************************************************/
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
const TagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
SumoXMLTag
Numbers representing SUMO-XML - element names.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
void addedLockedObject(const GUIGlObjectType type)
set object selected
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.
GNEViewParent * getViewParent() const
get the net object
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:77
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) ...
LockGLObjectTypes * getLockGLObjectTypes() const
get selected items
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void addAdditionalParent(GNEAdditional *additional)
add additional child to this edge
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void addAdditionalChild(GNEAdditional *additional)
add additional child to this edge
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
int getNumberOfAttributes() const
get number of attributes
void removeLockedObject(const GUIGlObjectType type)
set object unselected
GNESelectorFrame * getSelectorFrame() const
get frame for GNE_MODE_SELECT
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:48
const std::string & getTagStr() const
get tag assigned to this object in string format
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
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
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1730