Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMoveElementVehicle.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-2025 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// Class used for elements that can be moved over a edge with two positions
19/****************************************************************************/
20#include <config.h>
21
30#include <netedit/GNENet.h>
32#include <netedit/GNEUndoList.h>
33#include <netedit/GNEViewNet.h>
42
44
45// ===========================================================================
46// static definitions
47// ===========================================================================
48
50
51// ===========================================================================
52// member method definitions
53// ===========================================================================
54
56 GNEMoveElement(vehicle),
57 myVehicle(vehicle) {
58 // set parents
59 vehicle->getHierarchicalElement()->setParents<GNEEdge*>({fromEdge, toEdge});
60}
61
62
64
65
68 // get first and last lanes
69 const GNELane* firstLane = myVehicle->getFirstPathLane();
70 const GNELane* lastLane = myVehicle->getLastPathLane();
71 // check both lanes
72 if (firstLane && lastLane) {
73 // get depart and arrival positions (doubles)
74 const double startPosDouble = myVehicle->getAttributeDouble(SUMO_ATTR_DEPARTPOS);
76 // check if allow change lane
78 // obtain diameter
80 // return move operation depending if we're editing departPos or arrivalPos
82 return new GNEMoveOperation(this, firstLane, startPosDouble, lastLane, INVALID_DOUBLE, true, allowChangeLane);
84 return new GNEMoveOperation(this, firstLane, INVALID_DOUBLE, lastLane, endPosDouble, false, allowChangeLane);
85 }
86 }
87 // nothing to move
88 return nullptr;
89}
90
91
92std::string
96
97
98double
102
103
108
109
114
115
116void
117GNEMoveElementVehicle::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
118 myMovedElement->setCommonAttribute(key, value, undoList);
119}
120
121
122bool
123GNEMoveElementVehicle::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
124 return myMovedElement->isCommonAttributeValid(key, value);
125}
126
127
128void
131}
132
133
134void
135GNEMoveElementVehicle::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
136 // nothing to do here
137}
138
139
140void
142 if (moveResult.newFirstPos != INVALID_DOUBLE) {
143 // change depart
146 myVehicle->departPos = moveResult.newFirstPos;
147 // check if depart lane has to be changed
148 if (moveResult.newFirstLane) {
149 // set new depart lane
150 std::string error = "";
152 // mark parameter as set
154 }
155 } else if (moveResult.newLastPos != INVALID_DOUBLE) {
156 // change arrival
159 myVehicle->arrivalPos = moveResult.newFirstPos;
160 // check if arrival lane has to be changed
161 if (moveResult.newLastLane) {
162 // set new arrival lane
163 std::string error = "";
165 // mark parameter as set
167 }
168 }
169 // set lateral offset
171 // update geometry
173}
174
175
176void
178 // reset lateral offset
180 // check value
181 if (moveResult.newFirstPos != INVALID_DOUBLE) {
182 // begin change attribute
183 undoList->begin(myVehicle, TLF("departPos of %", myVehicle->getTagStr()));
184 // now set departPos
186 // check if depart lane has to be changed
187 if (moveResult.newFirstLane) {
188 // set new depart lane
190 }
191 } else if (moveResult.newLastPos != INVALID_DOUBLE) {
192 // begin change attribute
193 undoList->begin(myVehicle, TLF("arrivalPos of %", myVehicle->getTagStr()));
194 // now set arrivalPos
196 // check if arrival lane has to be changed
197 if (moveResult.newLastLane) {
198 // set new arrival lane
200 }
201 }
202 // end change attribute
203 undoList->end();
204}
205
206/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
@ GIVEN
The position is given.
const long long int VEHPARS_ARRIVALLANE_SET
const long long int VEHPARS_DEPARTLANE_SET
const long long int VEHPARS_DEPARTPOS_SET
const long long int VEHPARS_ARRIVALPOS_SET
@ GIVEN
The arrival position is given.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ARRIVALLANE
@ GNE_ATTR_PLAN_GEOMETRY_STARTPOS
person/container geometry start position
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_DEPARTLANE
@ GNE_ATTR_PLAN_GEOMETRY_ENDPOS
person/container geometry end position
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_WIDTH
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
const double SUMO_const_halfLaneWidth
Definition StdDefs.h:53
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
double getCommonAttributeDouble(SumoXMLAttr key) const
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * getNet() const
get pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this GNEDemandElement
void setParents(const GNEHierarchicalContainerParents< ParentType > &parents)
set multiple parent element (ONLY use in constructors)
const PositionVector & getLaneShape() const
get elements shape
Definition GNELane.cpp:232
int getIndex() const
returns the index of the lane
Definition GNELane.cpp:624
double myMovingLateralOffset
move element lateral offset
GNEAttributeCarrier * myMovedElement
pointer to element
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
GNEMoveOperation * getMoveOperation() override
get edge movable move operation for elements with
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const override
get moving attribute positionVector
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
GNEMoveElementVehicle(GNEVehicle *vehicle, GNEEdge *fromEdge, GNEEdge *toEdge)
Constructor.
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList) override
remove geometry point in the clicked position
GNEVehicle * myVehicle
vehicle
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
void setMoveShape(const GNEMoveResult &moveResult) override
set move shape
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
static const double arrivalPositionDiameter
vehicle arrival position radius
bool getAllowChangeLane() const
allow change lane
CommonMoveOptions * getCommonMoveOptions() const
get common mode options
const GNELane * newFirstLane
new first Lane
double newFirstPos
new first position
const GNELane * newLastLane
new last Lane
double firstLaneOffset
lane offset
double newLastPos
new last position
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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...
GNELane * getLastPathLane() const override
get last path lane
Position getAttributePosition(SumoXMLAttr key) const override
void updateGeometry() override
update pre-computed geometry information
double getAttributeDouble(SumoXMLAttr key) const override
GNELane * getFirstPathLane() const override
get first path lane
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
GNEViewParent * getViewParent() const
get the net object
GNEMoveFrame * getMoveFrame() const
get frame for move elements
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
Definition Position.h:278
A list of positions.
double length2D() const
Returns the length.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
double departPos
(optional) The position the vehicle shall depart from
double arrivalPos
(optional) The position the vehicle shall arrive on
static bool parseDepartLane(const std::string &val, const std::string &element, const std::string &id, int &lane, DepartLaneDefinition &dld, std::string &error)
Validates a given departLane value.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.