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 double& departPos, GNEEdge* toEdge, double& arrivalPos) :
57 GNEMoveElement(vehicle),
58 myVehicle(vehicle),
59 myDepartPos(departPos),
60 myArrivalPos(arrivalPos) {
61 // set parents
62 vehicle->getHierarchicalElement()->setParents<GNEEdge*>({fromEdge, toEdge});
63}
64
65
67
68
71 // get first and last lanes
72 const GNELane* firstLane = myVehicle->getFirstPathLane();
73 const GNELane* lastLane = myVehicle->getLastPathLane();
74 // check both lanes
75 if (firstLane && lastLane) {
76 // get depart and arrival positions (doubles)
77 const double startPosDouble = myVehicle->getAttributeDouble(SUMO_ATTR_DEPARTPOS);
79 // check if allow change lane
81 // obtain diameter
83 // return move operation depending if we're editing departPos or arrivalPos
85 return new GNEMoveOperation(this, firstLane, startPosDouble, lastLane, INVALID_DOUBLE, true, allowChangeLane);
87 return new GNEMoveOperation(this, firstLane, INVALID_DOUBLE, lastLane, endPosDouble, false, allowChangeLane);
88 }
89 }
90 // nothing to move
91 return nullptr;
92}
93
94
95std::string
99
100
101double
105
106
111
112
117
118
119void
120GNEMoveElementVehicle::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
121 myMovedElement->setCommonAttribute(key, value, undoList);
122}
123
124
125bool
126GNEMoveElementVehicle::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
127 return myMovedElement->isCommonAttributeValid(key, value);
128}
129
130
131void
134}
135
136
137void
138GNEMoveElementVehicle::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
139 // nothing to do here
140}
141
142
143void
145 if (moveResult.newFirstPos != INVALID_DOUBLE) {
146 // change depart
149 myVehicle->departPos = moveResult.newFirstPos;
150 // check if depart lane has to be changed
151 if (moveResult.newFirstLane) {
152 // set new depart lane
153 std::string error = "";
155 // mark parameter as set
157 }
158 } else if (moveResult.newLastPos != INVALID_DOUBLE) {
159 // change arrival
162 myVehicle->arrivalPos = moveResult.newFirstPos;
163 // check if arrival lane has to be changed
164 if (moveResult.newLastLane) {
165 // set new arrival lane
166 std::string error = "";
168 // mark parameter as set
170 }
171 }
172 // set lateral offset
174 // update geometry
176}
177
178
179void
181 // reset lateral offset
183 // check value
184 if (moveResult.newFirstPos != INVALID_DOUBLE) {
185 // begin change attribute
186 undoList->begin(myVehicle, TLF("departPos of %", myVehicle->getTagStr()));
187 // now set departPos
189 // check if depart lane has to be changed
190 if (moveResult.newFirstLane) {
191 // set new depart lane
193 }
194 } else if (moveResult.newLastPos != INVALID_DOUBLE) {
195 // begin change attribute
196 undoList->begin(myVehicle, TLF("arrivalPos of %", myVehicle->getTagStr()));
197 // now set arrivalPos
199 // check if arrival lane has to be changed
200 if (moveResult.newLastLane) {
201 // set new arrival lane
203 }
204 }
205 // end change attribute
206 undoList->end();
207}
208
209/****************************************************************************/
#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
const std::string getID() const
get ID (all Attribute Carriers have one)
double getCommonAttributeDouble(SumoXMLAttr key) const
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
GNEMoveOperation * getMoveOperation()
get edge movable move operation for elements with
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList) override
commit move shape
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
GNEMoveElementVehicle(GNEVehicle *vehicle, GNEEdge *fromEdge, double &departPos, GNEEdge *toEdge, double &arrivalPos)
Constructor.
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
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
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
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.