Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/moving/GNEMoveElementPlanParent.cpp
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 GNEMoveElementPlanParent.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Oct 2025
17
///
18
// Class used for elements that can be moved over a edge with two positions
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <foreign/fontstash/fontstash.h>
23
#include <netedit/changes/GNEChange_Attribute.h>
24
#include <netedit/changes/GNEChange_Connection.h>
25
#include <netedit/elements/demand/GNEDemandElement.h>
26
#include <netedit/elements/GNEAttributeCarrier.h>
27
#include <netedit/elements/moving/GNEMoveElement.h>
28
#include <netedit/elements/network/GNEConnection.h>
29
#include <netedit/frames/common/GNEMoveFrame.h>
30
#include <netedit/GNENet.h>
31
#include <netedit/GNETagProperties.h>
32
#include <netedit/GNEUndoList.h>
33
#include <netedit/GNEViewNet.h>
34
#include <netedit/GNEViewParent.h>
35
#include <utils/gui/div/GLHelper.h>
36
#include <utils/gui/div/GUIGlobalViewObjectsHandler.h>
37
#include <utils/gui/globjects/GLIncludes.h>
38
#include <utils/gui/globjects/GUIGlObject.h>
39
#include <utils/options/OptionsCont.h>
40
#include <utils/xml/NamespaceIDs.h>
41
42
#include "GNEMoveElementPlanParent.h"
43
44
// ===========================================================================
45
// member method definitions
46
// ===========================================================================
47
48
GNEMoveElementPlanParent::GNEMoveElementPlanParent(GNEDemandElement* planParent,
49
double& departPos, DepartPosDefinition& departPosProcedure) :
50
GNEMoveElement(planParent),
51
myPlanParent(planParent),
52
myDepartPos(departPos),
53
myDepartPosProcedure(departPosProcedure) {
54
}
55
56
57
GNEMoveElementPlanParent::~GNEMoveElementPlanParent() {}
58
59
60
GNEMoveOperation*
61
GNEMoveElementPlanParent::getMoveOperation() {
62
const auto firstContainerPlan = myPlanParent->getChildDemandElements().front();
63
// check first person plan
64
if (firstContainerPlan->getTagProperty()->isPlanStopPerson()) {
65
return nullptr;
66
} else if (firstContainerPlan->getParentEdges().size() > 0) {
67
// get lane
68
const GNELane* lane = firstContainerPlan->getParentEdges().front()->getLaneByAllowedVClass(myPlanParent->getVClass());
69
// declare departPos
70
double posOverLane = 0;
71
if (GNEAttributeCarrier::canParse<double>(myPlanParent->getAttribute(SUMO_ATTR_DEPARTPOS))) {
72
posOverLane = GNEAttributeCarrier::parse<double>(myPlanParent->getAttribute(SUMO_ATTR_DEPARTPOS));
73
}
74
// return move operation
75
return new GNEMoveOperation(this, lane, posOverLane, false);
76
} else {
77
return nullptr;
78
}
79
}
80
81
82
std::string
83
GNEMoveElementPlanParent::getMovingAttribute(SumoXMLAttr key) const {
84
return myMovedElement->getCommonAttribute(key);
85
}
86
87
88
double
89
GNEMoveElementPlanParent::getMovingAttributeDouble(SumoXMLAttr key) const {
90
return myMovedElement->getCommonAttributeDouble(key);
91
}
92
93
94
Position
95
GNEMoveElementPlanParent::getMovingAttributePosition(SumoXMLAttr key) const {
96
return myMovedElement->getCommonAttributePosition(key);
97
}
98
99
100
PositionVector
101
GNEMoveElementPlanParent::getMovingAttributePositionVector(SumoXMLAttr key) const {
102
return myMovedElement->getCommonAttributePositionVector(key);
103
}
104
105
106
void
107
GNEMoveElementPlanParent::setMovingAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
108
myMovedElement->setCommonAttribute(key, value, undoList);
109
}
110
111
112
bool
113
GNEMoveElementPlanParent::isMovingAttributeValid(SumoXMLAttr key, const std::string& value) const {
114
return myMovedElement->isCommonAttributeValid(key, value);
115
}
116
117
118
void
119
GNEMoveElementPlanParent::setMovingAttribute(SumoXMLAttr key, const std::string& value) {
120
myMovedElement->setCommonAttribute(key, value);
121
}
122
123
124
void
125
GNEMoveElementPlanParent::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
126
// nothing to do here
127
}
128
129
130
void
131
GNEMoveElementPlanParent::setMoveShape(const GNEMoveResult& moveResult) {
132
// change departPos
133
myDepartPosProcedure = DepartPosDefinition::GIVEN;
134
myDepartPos = moveResult.newFirstPos;
135
// update geometry
136
myPlanParent->updateGeometry();
137
}
138
139
140
void
141
GNEMoveElementPlanParent::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
142
undoList->begin(myPlanParent, TLF("departPos of %", myPlanParent->getTagStr()));
143
// now set departPos
144
myPlanParent->setAttribute(SUMO_ATTR_DEPARTPOS, toString(moveResult.newFirstPos), undoList);
145
undoList->end();
146
}
147
148
/****************************************************************************/
149
150