Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/changes/GNEChange_Children.cpp
169678 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 GNEChange_Children.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jul 2019
17
///
18
// A network change used to modify sorting of hierarchical element children
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNEViewNet.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/GNEApplicationWindow.h>
25
26
#include "GNEChange_Children.h"
27
28
// ===========================================================================
29
// FOX-declarations
30
// ===========================================================================
31
32
FXIMPLEMENT_ABSTRACT(GNEChange_Children, GNEChange, nullptr, 0)
33
34
// ===========================================================================
35
// member method definitions
36
// ===========================================================================
37
38
GNEChange_Children::GNEChange_Children(GNEDemandElement* demandElementParent, GNEDemandElement* demandElementChild, const Operation operation) :
39
GNEChange(Supermode::DEMAND, true, demandElementChild->isAttributeCarrierSelected()),
40
myParentDemandElement(demandElementParent),
41
myChildDemandElement(demandElementChild),
42
myOperation(operation),
43
myOriginalChildElements(demandElementParent->getChildDemandElements()),
44
myEditedChildElements(demandElementParent->getChildDemandElements()) {
45
myParentDemandElement->incRef("GNEChange_Children");
46
// obtain iterator to demandElementChild
47
auto it = std::find(myEditedChildElements.begin(), myEditedChildElements.end(), myChildDemandElement);
48
// edit myEditedChildElements vector
49
if (it != myEditedChildElements.end()) {
50
if ((operation == Operation::MOVE_FRONT) && (it != (myEditedChildElements.end() - 1))) {
51
// remove element
52
it = myEditedChildElements.erase(it);
53
// insert again in a different position
54
myEditedChildElements.insert(it + 1, myChildDemandElement);
55
} else if ((operation == Operation::MOVE_BACK) && (it != myEditedChildElements.begin())) {
56
// remove element
57
it = myEditedChildElements.erase(it);
58
// insert again in a different position
59
myEditedChildElements.insert(it - 1, myChildDemandElement);
60
}
61
}
62
}
63
64
65
GNEChange_Children::~GNEChange_Children() {
66
// only continue we have undo-redo mode enabled
67
if (myParentDemandElement->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
68
myParentDemandElement->decRef("GNEChange_Children");
69
// remove if is unreferenced
70
if (myParentDemandElement->unreferenced()) {
71
// delete AC
72
delete myParentDemandElement;
73
}
74
}
75
}
76
77
78
void
79
GNEChange_Children::undo() {
80
if (myForward) {
81
// continue depending of myOperation
82
if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
83
// restore child demand element original vector in myChildDemandElement
84
// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
85
} else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
86
// restore child demand element original vector in myChildDemandElement
87
// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
88
}
89
} else {
90
// continue depending of myOperation
91
if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
92
// set child demand element edited vector in myChildDemandElement
93
// myParentDemandElement- myChildDemandElements = myEditedChildElements;
94
} else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
95
// set child demand element edited vector in myChildDemandElement
96
// myParentDemandElement->myChildDemandElements = myEditedChildElements;
97
}
98
}
99
// require always save children
100
myParentDemandElement->getNet()->getSavingStatus()->requireSaveDemandElements();
101
}
102
103
104
void
105
GNEChange_Children::redo() {
106
if (myForward) {
107
// continue depending of myOperation
108
if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
109
// set child demand element edited vector in myChildDemandElement
110
// myParentDemandElement->myChildDemandElements = myEditedChildElements;
111
} else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
112
// set child demand element edited vector in myChildDemandElement
113
// myParentDemandElement->myChildDemandElements = myEditedChildElements;
114
}
115
} else {
116
// continue depending of myOperation
117
if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
118
// restore child demand element original vector in myChildDemandElement
119
// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
120
} else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
121
// restore child demand element original vector in myChildDemandElement
122
// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
123
}
124
}
125
// require always save children
126
myParentDemandElement->getNet()->getSavingStatus()->requireSaveDemandElements();
127
}
128
129
130
std::string
131
GNEChange_Children::undoName() const {
132
if (myForward) {
133
// check myOperation
134
if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
135
return (TL("Undo moving up ") + myChildDemandElement->getTagStr());
136
} else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
137
return (TL("Undo moving down ") + myChildDemandElement->getTagStr());
138
} else {
139
return (TL("Invalid operation"));
140
}
141
} else {
142
// check myOperation
143
if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
144
return (TL("Undo moving down ") + myChildDemandElement->getTagStr());
145
} else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
146
return (TL("Undo moving up ") + myChildDemandElement->getTagStr());
147
} else {
148
return (TL("Invalid operation"));
149
}
150
}
151
}
152
153
154
std::string
155
GNEChange_Children::redoName() const {
156
if (myForward) {
157
// check myOperation
158
if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
159
return (TL("Redo moving front ") + myParentDemandElement->getTagStr());
160
} else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
161
return (TL("Redo moving back ") + myParentDemandElement->getTagStr());
162
} else {
163
return (TL("Invalid operation"));
164
}
165
} else {
166
// check myOperation
167
if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
168
return (TL("Redo moving front ") + myParentDemandElement->getTagStr());
169
} else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
170
return (TL("Redo moving back ") + myParentDemandElement->getTagStr());
171
} else {
172
return (TL("Invalid operation"));
173
}
174
}
175
}
176
177