Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/moving/GNEMoveElement.h
185790 views
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
/****************************************************************************/
14
/// @file GNEMoveElement.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Mar 2020
17
///
18
// Class used for elements that can be moved
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/xml/SUMOXMLDefinitions.h>
24
25
#include "GNEMoveOffset.h"
26
#include "GNEMoveResult.h"
27
28
// ===========================================================================
29
// class declaration
30
// ===========================================================================
31
32
class GNEAttributeCarrier;
33
class GNEUndoList;
34
class GNEViewNet;
35
class GUIGlObject;
36
class Parameterised;
37
38
// ===========================================================================
39
// class definitions
40
// ===========================================================================
41
42
class GNEMoveElement {
43
44
public:
45
/// @brief constructor
46
GNEMoveElement(GNEAttributeCarrier* movedElement);
47
48
//// @brief empty destructor
49
virtual ~GNEMoveElement();
50
51
/**@brief get move operation
52
* @note returned GNEMoveOperation can be nullptr
53
*/
54
virtual GNEMoveOperation* getMoveOperation() = 0;
55
56
/// @name functions related with moving attributes
57
/// @{
58
59
/// @brief get moving attribute
60
virtual std::string getMovingAttribute(SumoXMLAttr key) const = 0;
61
62
/// @brief get moving attribute double
63
virtual double getMovingAttributeDouble(SumoXMLAttr key) const = 0;
64
65
/// @brief get moving attribute position
66
virtual Position getMovingAttributePosition(SumoXMLAttr key) const = 0;
67
68
/// @brief get moving attribute positionVector
69
virtual PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const = 0;
70
71
/// @brief set moving attribute (using undo-list)
72
virtual void setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
73
74
/// @brief check if the given moving attribute is valid
75
virtual bool isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const = 0;
76
77
/// @brief set moving attribute
78
virtual void setMovingAttribute(SumoXMLAttr key, const std::string& value) = 0;
79
80
/// @}
81
82
/// @brief remove geometry point in the clicked position
83
virtual void removeGeometryPoint(const Position clickedPosition, GNEUndoList* undoList) = 0;
84
85
/// @brief move element the for given offset (note: offset can be X-Y-0, 0-0-Z or X-Y-Z)
86
static void moveElement(const GNEViewNet* viewNet, GNEMoveOperation* moveOperation, const GNEMoveOffset& offset);
87
88
/// @brief commit move element for the given offset
89
static void commitMove(const GNEViewNet* viewNet, GNEMoveOperation* moveOperation, const GNEMoveOffset& offset, GNEUndoList* undoList);
90
91
/// @brief move element lateral offset
92
double myMovingLateralOffset = 0;
93
94
protected:
95
/// @brief pointer to element
96
GNEAttributeCarrier* myMovedElement = nullptr;
97
98
/// @brief calculate move shape operation
99
GNEMoveOperation* getEditShapeOperation(const GUIGlObject* obj, const PositionVector originalShape, const bool maintainShapeClosed);
100
101
private:
102
/// @brief set move shape
103
virtual void setMoveShape(const GNEMoveResult& moveResult) = 0;
104
105
/// @brief commit move shape
106
virtual void commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) = 0;
107
108
/// @brief calculate lane offset (used in calculateLanePosition)
109
static double calculateLaneOffset(const GNEViewNet* viewNet, const GNELane* lane, const double firstPosition,
110
const double lastPosition, const GNEMoveOffset& offset);
111
112
/// @brief calculate lane position over one lane with only one position (accesss, E1, star/end positions, etc.)
113
static void calculateLanePosition(double& starPos, const GNEViewNet* viewNet, const GNELane* lane,
114
const double posOverLane, const GNEMoveOffset& offset);
115
116
/// @brief calculate lane position over one lane with two positions (stoppingPlaces, E2 single lanes)
117
static void calculateLanePositions(double& starPos, double& endPos, const GNEViewNet* viewNet, const GNELane* lane,
118
const double firstPosOverLane, const double lastPosOverLane, const GNEMoveOffset& offset);
119
120
/// @brief calculate lane position over two lane with two positions (E2 Multilanes)
121
static void calculateLanePositions(double& starPos, double& endPos, const GNEViewNet* viewNet, const GNELane* firstLane,
122
const double firstPosOverLane, const GNELane* lastLane, const double lastPosOverLane,
123
const bool firstLaneClicked, const GNEMoveOffset& offset);
124
125
/// @brief calculate new lane change
126
static void calculateNewLaneChange(const GNEViewNet* viewNet, const GNELane* originalLane, const GNELane*& newLane, double& laneOffset);
127
128
/// @brief calculate width/height shape
129
static PositionVector calculateExtrapolatedVector(const GNEMoveOperation* moveOperation, const GNEMoveResult& moveResult);
130
131
/// @brief invalidate default constructor
132
GNEMoveElement() = delete;
133
134
/// @brief Invalidated copy constructor.
135
GNEMoveElement(const GNEMoveElement&) = delete;
136
137
/// @brief Invalidated assignment operator.
138
GNEMoveElement& operator=(const GNEMoveElement&) = delete;
139
};
140
141