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),
87 myMovingGeometryBoundary() {
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 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:181
GNEViewParent::getSelectorFrame
GNESelectorFrame * getSelectorFrame() const
get frame for GNE_NMODE_SELECT
Definition: GNEViewParent.cpp:185
GNENetElement::unselectAttributeCarrier
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Definition: GNENetElement.cpp:148
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:63
GNEAttributeCarrier::mySelected
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
Definition: GNEAttributeCarrier.h:795
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:73
GUIParameterTableWindow.h
GNENet
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:78
SUMO_ATTR_TO_LANE
Definition: SUMOXMLDefinitions.h:717
GUIGlobalSelection.h
SUMO_TAG_LANE
begin/end of the description of a single lane
Definition: SUMOXMLDefinitions.h:50
GNENetElement::~GNENetElement
~GNENetElement()
Destructor.
Definition: GNENetElement.cpp:91
GNENetElement::enableAttribute
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
Definition: GNENetElement.cpp:179
GNEHierarchicalElementParents
An special type of Attribute carrier that owns hierarchical elements.
Definition: GNEHierarchicalElementParents.h:48
GNENetElement::drawUsingSelectColor
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
Definition: GNENetElement.cpp:169
GNENetElement::setEnabledAttribute
void setEnabledAttribute(const int enabledAttributes)
method for enabling the attribute and nothing else (used in GNEChange_EnableAttribute)
Definition: GNENetElement.cpp:215
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:42
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:220
GNEAttributeCarrier::TagProperties::getTag
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
Definition: GNEAttributeCarrier.cpp:521
SUMO_ATTR_TO
Definition: SUMOXMLDefinitions.h:638
GUIGlObjectType
GUIGlObjectType
Definition: GUIGlObjectTypes.h:40
GNENetElement::isAttributeEnabled
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNENetElement.cpp:185
GNENetElement::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNENetElement.cpp:201
GNENetElement::myGeometry
NetElementGeometry myGeometry
netElement geometry
Definition: GNENetElement.h:199
GUISelectedStorage::select
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
Definition: GUISelectedStorage.cpp:114
GNENetElement::NetElementGeometry::calculateShapeRotationsAndLengths
void calculateShapeRotationsAndLengths()
calculate shape rotations and lengths
Definition: GNENetElement.cpp:55
Position::distanceTo
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:234
GUIParameterTableWindow::mkItem
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
Definition: GUIParameterTableWindow.h:109
GNEViewNet.h
GNENetElement.h
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
GNENetElement::getAttribute
virtual std::string getAttribute(SumoXMLAttr key) const =0
SUMO_TAG_EDGE
begin/end of the description of an edge
Definition: SUMOXMLDefinitions.h:48
GNE_SUPERMODE_NETWORK
Network mode (Edges, junctions, etc..)
Definition: GNEViewNetHelper.h:47
ProcessError
Definition: UtilExceptions.h:40
GNEViewNetHelper::EditModes::currentSupermode
Supermode currentSupermode
the current supermode
Definition: GNEViewNetHelper.h:309
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
GNEAttributeCarrier::myTagProperty
const TagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
Definition: GNEAttributeCarrier.h:792
GNENetElement::generateChildID
virtual std::string generateChildID(SumoXMLTag childTag)=0
gererate a new ID for an element child
Definition: GNENetElement.cpp:101
GNENetElement::isAttributeCarrierSelected
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
Definition: GNENetElement.cpp:163
GUIGlObject
Definition: GUIGlObject.h:66
GNENetElement::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNENetElement.cpp:113
GNENetElement::NetElementGeometry::clearGeometry
void clearGeometry()
reset geometry
Definition: GNENetElement.cpp:47
GNENetElement::getGeometry
const NetElementGeometry & getGeometry() const
Definition: GNENetElement.cpp:95
GNENet::getViewNet
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2067
SUMO_ATTR_FROM_LANE
Definition: SUMOXMLDefinitions.h:716
SUMO_ATTR_INDEX
Definition: SUMOXMLDefinitions.h:801
SUMO_ATTR_FROM
Definition: SUMOXMLDefinitions.h:637
GNEViewParent.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNESelectorFrame.h
GUIMainWindow
Definition: GUIMainWindow.h:47
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
SUMO_TAG_CROSSING
crossing between edges for pedestrians
Definition: SUMOXMLDefinitions.h:227
M_PI
#define M_PI
Definition: odrSpiral.cpp:40
GNENetElement::getNet
GNENet * getNet() const
get Net in which this element is placed
Definition: GNENetElement.cpp:107
GNENetElement::GNENetElement
GNENetElement(GNENet *net, const std::string &id, GUIGlObjectType type, SumoXMLTag tag)
Constructor.
Definition: GNENetElement.cpp:81
SUMO_TAG_CONNECTION
connectio between two lanes
Definition: SUMOXMLDefinitions.h:203
gSelected
GUISelectedStorage gSelected
A global holder of selected objects.
Definition: GUIGlobalSelection.cpp:34
GNENetElement::NetElementGeometry::NetElementGeometry
NetElementGeometry()
constructor
Definition: GNENetElement.cpp:43
GNENetElement::myNet
GNENet * myNet
the net to inform about updates
Definition: GNENetElement.h:196
config.h
GeomHelper.h
GNEViewNet::getEditModes
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:399
GNENetElement::NetElementGeometry
struct for pack all variables related with geometry of elemement
Definition: GNENetElement.h:46
GNENetElement::selectAttributeCarrier
void selectAttributeCarrier(bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
Definition: GNENetElement.cpp:132
GNESelectorFrame::LockGLObjectTypes::removeLockedObject
void removeLockedObject(const GUIGlObjectType type)
set object unselected
Definition: GNESelectorFrame.cpp:574
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEUndoList
Definition: GNEUndoList.h:49
GNENetElement::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNENetElement.cpp:191
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNEAttributeCarrier
Definition: GNEAttributeCarrier.h:54
GNEHierarchicalElementChildren
An special type of Attribute carrier that owns hierarchical elements.
Definition: GNEHierarchicalElementChildren.h:46
GNENet.h
GUISelectedStorage::deselect
void deselect(GUIGlID id)
Deselects the object with the given id.
Definition: GUISelectedStorage.cpp:131
GNEViewNet::getViewParent
GNEViewParent * getViewParent() const
get the net object
Definition: GNEViewNet.cpp:921
GNESelectorFrame::getLockGLObjectTypes
LockGLObjectTypes * getLockGLObjectTypes() const
get selected items Modul
Definition: GNESelectorFrame.cpp:460
GNEAttributeCarrier::TagProperties::getNumberOfAttributes
int getNumberOfAttributes() const
get number of attributes
Definition: GNEAttributeCarrier.cpp:646
GNESelectorFrame::LockGLObjectTypes::addedLockedObject
void addedLockedObject(const GUIGlObjectType type)
set object selected
Definition: GNESelectorFrame.cpp:568