Eclipse SUMO - Simulation of Urban MObility
GNETranship.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // A class for visualizing tranships in Netedit
19 /****************************************************************************/
20 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
27 
28 #include "GNETranship.h"
29 #include "GNERoute.h"
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 
36 GNETranship::buildTranship(GNENet* net, GNEDemandElement* containerParent, GNEEdge* fromEdge,
37  GNEAdditional* fromContainerStop, GNEEdge* toEdge, GNEAdditional* toContainerStop,
38  std::vector<GNEEdge*> edgeList, const double departPosition, const double arrivalPosition, const double speed) {
39  // declare icon an tag
40  const auto iconTag = getTranshipTagIcon(edgeList, fromEdge, toEdge, fromContainerStop, toContainerStop);
41  // declare containers
42  std::vector<GNEEdge*> edges;
43  std::vector<GNEAdditional*> additionals;
44  // continue depending of input parameters
45  if (edgeList.size() > 0) {
46  edges = edgeList;
47  } else {
48  if (fromEdge) {
49  edges.push_back(fromEdge);
50  } else if (fromContainerStop) {
51  additionals.push_back(fromContainerStop);
52  }
53  if (toEdge) {
54  edges.push_back(toEdge);
55  } else if (toContainerStop) {
56  additionals.push_back(toContainerStop);
57  }
58  }
59  return new GNETranship(net, iconTag.first, iconTag.second, containerParent, edges, additionals, departPosition, arrivalPosition, speed);
60 }
61 
62 
65  GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
66  GNEDemandElementPlan(this, -1, -1),
67 mySpeed(0) {
68  // reset default values
69  resetDefaultValues();
70 }
71 
72 
74 
75 
78  return getPlanMoveOperation();
79 }
80 
81 
84  return getPlanPopUpMenu(app, parent);
85 }
86 
87 
88 void
90  writeOriginStop(device);
91  device.openTag(SUMO_TAG_TRANSHIP);
93  device.closeTag();
94 }
95 
96 
99  return isPlanPersonValid();
100 }
101 
102 
103 std::string
105  return getPersonPlanProblem();
106 }
107 
108 
109 void
111  // currently the only solution is removing Tranship
112 }
113 
114 
117  return SVC_IGNORING;
118 }
119 
120 
121 const RGBColor&
124 }
125 
126 
127 void
130 }
131 
132 
133 Position
135  return getPlanPositionInView();
136 }
137 
138 
139 std::string
141  return getParentDemandElements().front()->getID();
142 }
143 
144 
145 Boundary
147  return getPlanCenteringBoundary();
148 }
149 
150 
151 void
152 GNETranship::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
153  // only split geometry of TranshipEdges
155  // obtain new list of tranship edges
156  std::string newTranshipEdges = getNewListOfParents(originalElement, newElement);
157  // update tranship edges
158  if (newTranshipEdges.size() > 0) {
159  setAttribute(SUMO_ATTR_EDGES, newTranshipEdges, undoList);
160  }
161  }
162 }
163 
164 
165 void
168 }
169 
170 
171 void
174 }
175 
176 
177 void
178 GNETranship::drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
180 }
181 
182 
183 void
184 GNETranship::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
186 }
187 
188 
189 GNELane*
191  return getFirstPlanPathLane();
192 }
193 
194 
195 GNELane*
197  return getLastPlanPathLane();
198 }
199 
200 
201 std::string
203  switch (key) {
204  // Common attributes
205  case SUMO_ATTR_SPEED:
206  return toString(mySpeed);
207  default:
208  return getPlanAttribute(key);
209  }
210 }
211 
212 
213 double
215  return getPlanAttributeDouble(key);
216 }
217 
218 
219 Position
221  return getPlanAttributePosition(key);
222 }
223 
224 
225 void
226 GNETranship::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
227  switch (key) {
228  // Common attributes
229  case SUMO_ATTR_SPEED:
230  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
231  break;
232  default:
233  setPlanAttribute(key, value, undoList);
234  break;
235  }
236 }
237 
238 
239 bool
240 GNETranship::isValid(SumoXMLAttr key, const std::string& value) {
241  return isPlanValid(key, value);
242 }
243 
244 
245 bool
247  return isPlanAttributeEnabled(key);
248 }
249 
250 
251 std::string
253  return getTagStr();
254 }
255 
256 
257 std::string
259  return getPlanHierarchyName();
260 }
261 
262 
263 const Parameterised::Map&
265  return getParametersMap();
266 }
267 
268 // ===========================================================================
269 // private
270 // ===========================================================================
271 
272 void
273 GNETranship::setAttribute(SumoXMLAttr key, const std::string& value) {
274  switch (key) {
275  // Common attributes
276  case SUMO_ATTR_SPEED:
277  break;
278  default:
279  setPlanAttribute(key, value);
280  break;
281  }
282 }
283 
284 
285 void
287  // change both position
288  myArrivalPosition = moveResult.newFirstPos;
289  // update geometry
290  updateGeometry();
291 }
292 
293 
294 void
296  undoList->begin(this, "arrivalPos of " + getTagStr());
297  // now adjust start position
298  setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newFirstPos), undoList);
299  undoList->end();
300 }
301 
302 
304  const std::vector<GNEEdge*>& edges, const std::vector<GNEAdditional*>& additionals,
305  const double departPosition, const double arrivalPosition, const double speed) :
306  GNEDemandElement(containerParent, net, GLO_TRANSHIP, tag, GUIIconSubSys::getIcon(icon),
307  GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, edges, {}, additionals, {containerParent}, {}),
308 GNEDemandElementPlan(this, departPosition, arrivalPosition),
309 mySpeed(speed) {
310 }
311 
312 /****************************************************************************/
@ GLO_TRANSHIP
a container tranship
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ TRANSHIP_EDGE
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TRANSHIP
@ GNE_TAG_TRANSHIP_EDGES
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_EDGES
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
Problem
enum class for demandElement problems
bool isPlanValid(SumoXMLAttr key, const std::string &value)
check if plan attribute is valid
Boundary getPlanCenteringBoundary() const
get centering boundaryt
Position getPlanPositionInView() const
Returns position of additional in view.
std::string getPersonPlanProblem() const
get plan problem
void computePlanPathElement()
compute plan pathElement
Position getPlanAttributePosition(SumoXMLAttr key) const
get plan attribute position
GNEDemandElement::Problem isPlanPersonValid() const
check if plan is valid
void drawPlanLanePartial(const bool drawPlan, const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront, const double planWidth, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan partial lane
GUIGLObjectPopupMenu * getPlanPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void drawPlanJunctionPartial(const bool drawPlan, const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront, const double planWidth, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan partial junction
std::string getPlanHierarchyName() const
get plan Hierarchy Name (Used in AC Hierarchy)
void writeLocationAttributes(OutputDevice &device) const
write plan element common attributes
bool checkDrawPersonPlan() const
check if person plan can be drawn
GNEMoveOperation * getPlanMoveOperation()
get move operation
double getPlanAttributeDouble(SumoXMLAttr key) const
get plan attribute double
void setPlanAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
set plan attribute
double myArrivalPosition
arrival position (used in all plans over edges)
std::string getPlanAttribute(SumoXMLAttr key) const
get plan attribute string
bool isPlanAttributeEnabled(SumoXMLAttr key) const
check if plan attribute is enabled
bool checkDrawContainerPlan() const
check if container plan can be drawn
GNELane * getLastPlanPathLane() const
get last plan path lane
void drawPlanGL(const bool drawPlan, const GUIVisualizationSettings &s, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan
void updatePlanGeometry()
update pre-computed geometry information
GNELane * getFirstPlanPathLane() const
get first plan path lane
static std::pair< SumoXMLTag, GUIIcon > getTranshipTagIcon(const std::vector< GNEEdge * > &consecutiveEdges, const GNEEdge *fromEdge, const GNEEdge *toEdge, const GNEAdditional *fromContainerStop, const GNEAdditional *toContainerStop)
get the tranship tag and icon for the combination
void writeOriginStop(OutputDevice &device) const
write initial stop stage if plan starts at a stopping place
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
move operation
move result
double newFirstPos
new first position
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNETranship()
destructor
Definition: GNETranship.cpp:73
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
double mySpeed
speed
Definition: GNETranship.h:215
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
GNELane * getFirstPathLane() const
get first path lane
GNETranship(SumoXMLTag tag, GNENet *net)
default constructor
Definition: GNETranship.cpp:63
bool isAttributeEnabled(SumoXMLAttr key) const
static GNETranship * buildTranship(GNENet *net, GNEDemandElement *containerParent, GNEEdge *fromEdge, GNEAdditional *fromContainerStop, GNEEdge *toEdge, GNEAdditional *toContainerStop, std::vector< GNEEdge * > edgeList, const double departPosition, const double arrivalPosition, const double speed)
general constructor for tranships
Definition: GNETranship.cpp:36
void updateGeometry()
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Position getAttributePosition(SumoXMLAttr key) const
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNETranship.cpp:77
Position getPositionInView() const
Returns position of additional in view.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNETranship.cpp:83
double getAttributeDouble(SumoXMLAttr key) const
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void computePathElement()
compute pathElement
const Parameterised::Map & getACParametersMap() const
get parameters map
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Definition: GNETranship.cpp:98
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
Definition: GNETranship.cpp:89
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
std::string getParentName() const
Returns the name of the parent object.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
GNELane * getLastPathLane() const
get last path lane
const RGBColor & getColor() const
get color
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
The popup menu of a globject.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
Stores the information about how to visualize structures.
GUIVisualizationWidthSettings widthSettings
width settings
GUIVisualizationColorSettings colorSettings
color settings
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
RGBColor selectedPersonPlanColor
person plan selection color (Rides, Walks, stopPersons...)
RGBColor transhipColor
color for tranships
RGBColor selectedContainerPlanColor
container plan selection color (Rides, Walks, containerStops...)