Eclipse 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-2019 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/GNEViewNet.h>
26 #include <netedit/GNEViewParent.h>
30 #include <utils/geom/GeomHelper.h>
31 
32 #include "GNENetElement.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 
39 // ---------------------------------------------------------------------------
40 // GNENetElement::NetElementGeometry - methods
41 // ---------------------------------------------------------------------------
42 
44 
45 
46 void
48  shape.clear();
49  shapeRotations.clear();
50  shapeLengths.clear();
51 }
52 
53 
54 void
56  // Get number of parts of the shape
57  int numberOfSegments = (int)shape.size() - 1;
58  // If number of segments is more than 0
59  if (numberOfSegments >= 0) {
60  // Reserve memory (To improve efficiency)
61  shapeRotations.reserve(numberOfSegments);
62  shapeLengths.reserve(numberOfSegments);
63  // For every part of the shape
64  for (int i = 0; i < numberOfSegments; ++i) {
65  // Obtain first position
66  const Position& f = shape[i];
67  // Obtain next position
68  const Position& s = shape[i + 1];
69  // Save distance between position into myShapeLengths
70  shapeLengths.push_back(f.distanceTo(s));
71  // Save rotation (angle) of the vector constructed by points f and s
72  shapeRotations.push_back((double)atan2((s.x() - f.x()), (f.y() - s.y())) * (double) 180.0 / (double)M_PI);
73  }
74  }
75 }
76 
77 // ---------------------------------------------------------------------------
78 // GNENetElement - methods
79 // ---------------------------------------------------------------------------
80 
81 GNENetElement::GNENetElement(GNENet* net, const std::string& id, GUIGlObjectType type, SumoXMLTag tag) :
82  GUIGlObject(type, id),
84  GNEHierarchicalElementParents(this, {}, {}, {}, {}, {}),
85  GNEHierarchicalElementChildren(this, {}, {}, {}, {}, {}),
86  myNet(net),
88 }
89 
90 
92 
93 
96  return myGeometry;
97 }
98 
99 
100 std::string
102  return "";
103 }
104 
105 
106 GNENet*
108  return myNet;
109 }
110 
111 
114  // Create table
116  // Iterate over attributes
117  for (const auto& i : myTagProperty) {
118  // Add attribute and set it dynamic if aren't unique
119  if (i.isUnique()) {
120  ret->mkItem(i.getAttrStr().c_str(), false, getAttribute(i.getAttr()));
121  } else {
122  ret->mkItem(i.getAttrStr().c_str(), true, getAttribute(i.getAttr()));
123  }
124  }
125  // close building
126  ret->closeBuilding();
127  return ret;
128 }
129 
130 
131 void
133  if (!myNet) {
134  throw ProcessError("Net cannot be nullptr");
135  } else {
137  // add object into list of selected objects
139  if (changeFlag) {
140  mySelected = true;
141 
142  }
143  }
144 }
145 
146 
147 void
149  if (!myNet) {
150  throw ProcessError("Net cannot be nullptr");
151  } else {
153  // remove object of list of selected objects
155  if (changeFlag) {
156  mySelected = false;
157  }
158  }
159 }
160 
161 
162 bool
164  return mySelected;
165 }
166 
167 
168 bool
171  return true;
172  } else {
173  return false;
174  }
175 }
176 
177 
178 void
180  //
181 }
182 
183 
184 bool
186  return true;
187 }
188 
189 
190 std::string
194  } else {
195  return getTagStr() + ": " + getID();
196  }
197 }
198 
199 
200 std::string
204  } else if (myTagProperty.getTag() == SUMO_TAG_CONNECTION) {
207  return getPopUpID();
208  } else {
209  return getTagStr();
210  }
211 }
212 
213 
214 void
215 GNENetElement::setEnabledAttribute(const int /*enabledAttributes*/) {
216  //
217 }
218 
219 /****************************************************************************/
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
PositionVector shape
The shape of the netElement element.
Definition: GNENetElement.h:57
GNENet * myNet
the net to inform about updates
struct for pack all variables related with geometry of elemement
Definition: GNENetElement.h:46
GUIGlObjectType
begin/end of the description of a single lane
GNENet * getNet() const
get Net in which this element is placed
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
virtual std::string generateChildID(SumoXMLTag childTag)=0
gererate a new ID for an element child
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
Definition: GNEViewNet.cpp:921
double y() const
Returns the y-position.
Definition: Position.h:62
void setEnabledAttribute(const int enabledAttributes)
method for enabling the attribute and nothing else (used in GNEChange_EnableAttribute) ...
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
double x() const
Returns the x-position.
Definition: Position.h:57
NetElementGeometry myGeometry
netElement geometry
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:78
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Boundary myMovingGeometryBoundary
boundary used during moving of elements
~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.
An special type of Attribute carrier that owns hierarchical elements.
std::vector< double > shapeRotations
The rotations of the single shape parts.
Definition: GNENetElement.h:60
LockGLObjectTypes * getLockGLObjectTypes() const
get selected items Modul
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
int getNumberOfAttributes() const
get number of attributes
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Supermode currentSupermode
the current supermode
void removeLockedObject(const GUIGlObjectType type)
set object unselected
bool isAttributeEnabled(SumoXMLAttr key) const
GNESelectorFrame * getSelectorFrame() const
get frame for GNE_NMODE_SELECT
const std::string getID() const
function to support debugging
const NetElementGeometry & getGeometry() const
void selectAttributeCarrier(bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
std::vector< double > shapeLengths
The lengths of the single shape parts.
Definition: GNENetElement.h:63
begin/end of the description of an edge
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
void deselect(GUIGlID id)
Deselects the object with the given id.
#define M_PI
Definition: odrSpiral.cpp:40
const std::string & getTagStr() const
get tag assigned to this object in string format
GNEHierarchicalElementChildren(GNEAttributeCarrier *AC, const std::vector< GNEEdge *> &edgeChildren, const std::vector< GNELane *> &laneChildren, const std::vector< GNEShape *> &shapeChildren, const std::vector< GNEAdditional *> &additionalChildren, const std::vector< GNEDemandElement *> &demandElementChildren)
Parameter Constructor.
crossing between edges for pedestrians
virtual std::string getAttribute(SumoXMLAttr key) const =0
GUIGlID getGlID() const
Returns the numerical id of the object.
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:234
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:399
Network mode (Edges, junctions, etc..)
GUISelectedStorage gSelected
A global holder of selected objects.
void clearGeometry()
reset geometry
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:2067