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);
75 const double endPosDouble = (myVehicle->getAttributeDouble(SUMO_ATTR_ARRIVALPOS) < 0) ? lastLane->getLaneShape().length2D() : myVehicle->getAttributeDouble(SUMO_ATTR_ARRIVALPOS);
76 // check if allow change lane
77 const bool allowChangeLane = myVehicle->getNet()->getViewNet()->getViewParent()->getMoveFrame()->getCommonMoveOptions()->getAllowChangeLane();
78 // obtain diameter
79 const double diameter = myVehicle->getAttributeDouble(SUMO_ATTR_WIDTH) > myVehicle->getAttributeDouble(SUMO_ATTR_LENGTH) ? myVehicle->getAttributeDouble(SUMO_ATTR_WIDTH) : myVehicle->getAttributeDouble(SUMO_ATTR_LENGTH);
80 // return move operation depending if we're editing departPos or arrivalPos
81 if (myVehicle->getNet()->getViewNet()->getPositionInformation().distanceSquaredTo2D(myVehicle->getAttributePosition(GNE_ATTR_PLAN_GEOMETRY_STARTPOS)) < (diameter * diameter)) {
82 return new GNEMoveOperation(this, firstLane, startPosDouble, lastLane, INVALID_DOUBLE, true, allowChangeLane);
83 } else if (myVehicle->getNet()->getViewNet()->getPositionInformation().distanceSquaredTo2D(myVehicle->getAttributePosition(GNE_ATTR_PLAN_GEOMETRY_ENDPOS)) < (arrivalPositionDiameter * arrivalPositionDiameter)) {
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
94 return myMovedElement->getCommonAttribute(key);
95}
96
97
98double
100 return myMovedElement->getCommonAttributeDouble(key);
101}
102
103
106 return myMovedElement->getCommonAttributePosition(key);
107}
108
109
112 return myMovedElement->getCommonAttributePositionVector(key);
113}
114
115
116void
118 myMovedElement->setCommonAttribute(key, value, undoList);
119}
120
121
122bool
124 return myMovedElement->isCommonAttributeValid(key, value);
125}
126
127
128void
130 myMovedElement->setCommonAttribute(key, value);
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
144 myVehicle->departPosProcedure = DepartPosDefinition::GIVEN;
145 myVehicle->parametersSet |= VEHPARS_DEPARTPOS_SET;
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 = "";
151 myVehicle->parseDepartLane(moveResult.newFirstLane->getID(), myVehicle->getTagStr(), myVehicle->getID(), myVehicle->departLane, myVehicle->departLaneProcedure, error);
152 // mark parameter as set
153 myVehicle->parametersSet |= VEHPARS_DEPARTLANE_SET;
154 }
155 } else if (moveResult.newLastPos != INVALID_DOUBLE) {
156 // change arrival
157 myVehicle->arrivalPosProcedure = ArrivalPosDefinition::GIVEN;
158 myVehicle->parametersSet |= VEHPARS_ARRIVALPOS_SET;
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 = "";
164 myVehicle->parseArrivalLane(moveResult.newLastLane->getID(), myVehicle->getTagStr(), myVehicle->getID(), myVehicle->departLane, myVehicle->arrivalLaneProcedure, error);
165 // mark parameter as set
166 myVehicle->parametersSet |= VEHPARS_ARRIVALLANE_SET;
167 }
168 }
169 // set lateral offset
171 // update geometry
172 myVehicle->updateGeometry();
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
185 myVehicle->setAttribute(SUMO_ATTR_DEPARTPOS, toString(moveResult.newFirstPos), undoList);
186 // check if depart lane has to be changed
187 if (moveResult.newFirstLane) {
188 // set new depart lane
189 myVehicle->setAttribute(SUMO_ATTR_DEPARTLANE, toString(moveResult.newFirstLane->getIndex()), undoList);
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
195 myVehicle->setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newLastPos), undoList);
196 // check if arrival lane has to be changed
197 if (moveResult.newLastLane) {
198 // set new arrival lane
199 myVehicle->setAttribute(SUMO_ATTR_ARRIVALLANE, toString(moveResult.newLastLane->getIndex()), undoList);
200 }
201 }
202 // end change attribute
203 undoList->end();
204}
205
206/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
const std::string invalid_return< std::string >::value
@ 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
const std::string getID() const override
get ID (all Attribute Carriers have one)
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this GNEDemandElement
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
GNEMoveElement(GNEAttributeCarrier *movedElement)
constructor
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
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
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...
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
double length2D() const
Returns the length.