Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEChange_Children.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// A network change used to modify sorting of hierarchical element children
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22#include <netedit/GNEViewNet.h>
25
26#include "GNEChange_Children.h"
27
28// ===========================================================================
29// FOX-declarations
30// ===========================================================================
31
32FXIMPLEMENT_ABSTRACT(GNEChange_Children, GNEChange, nullptr, 0)
33
34// ===========================================================================
35// member method definitions
36// ===========================================================================
37
38GNEChange_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
66 // only continue we have undo-redo mode enabled
68 myParentDemandElement->decRef("GNEChange_Children");
69 // remove if is unreferenced
71 // delete AC
73 }
74 }
75}
76
77
78void
80 if (myForward) {
81 // continue depending of myOperation
83 // restore child demand element original vector in myChildDemandElement
84// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
86 // restore child demand element original vector in myChildDemandElement
87// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
88 }
89 } else {
90 // continue depending of myOperation
92 // set child demand element edited vector in myChildDemandElement
93// myParentDemandElement- myChildDemandElements = myEditedChildElements;
95 // set child demand element edited vector in myChildDemandElement
96// myParentDemandElement->myChildDemandElements = myEditedChildElements;
97 }
98 }
99 // require always save children
101}
102
103
104void
106 if (myForward) {
107 // continue depending of myOperation
109 // set child demand element edited vector in myChildDemandElement
110// myParentDemandElement->myChildDemandElements = myEditedChildElements;
112 // set child demand element edited vector in myChildDemandElement
113// myParentDemandElement->myChildDemandElements = myEditedChildElements;
114 }
115 } else {
116 // continue depending of myOperation
118 // restore child demand element original vector in myChildDemandElement
119// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
121 // restore child demand element original vector in myChildDemandElement
122// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
123 }
124 }
125 // require always save children
127}
128
129
130std::string
132 if (myForward) {
133 // check myOperation
135 return (TL("Undo moving up ") + myChildDemandElement->getTagStr());
137 return (TL("Undo moving down ") + myChildDemandElement->getTagStr());
138 } else {
139 return (TL("Invalid operation"));
140 }
141 } else {
142 // check myOperation
144 return (TL("Undo moving down ") + myChildDemandElement->getTagStr());
146 return (TL("Undo moving up ") + myChildDemandElement->getTagStr());
147 } else {
148 return (TL("Invalid operation"));
149 }
150 }
151}
152
153
154std::string
156 if (myForward) {
157 // check myOperation
159 return (TL("Redo moving front ") + myParentDemandElement->getTagStr());
161 return (TL("Redo moving back ") + myParentDemandElement->getTagStr());
162 } else {
163 return (TL("Invalid operation"));
164 }
165 } else {
166 // check myOperation
168 return (TL("Redo moving front ") + myParentDemandElement->getTagStr());
170 return (TL("Redo moving back ") + myParentDemandElement->getTagStr());
171 } else {
172 return (TL("Invalid operation"));
173 }
174 }
175}
Supermode
@brie enum for supermodes
@ DEMAND
Demand mode (Routes, Vehicles etc..)
#define TL(string)
Definition MsgHandler.h:301
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * getNet() const
get pointer to net
std::string undoName() const
return undoName
const Operation myOperation
~GNEChange_Children()
Destructor.
std::string redoName() const
get Redo name
GNEDemandElement * myParentDemandElement
full information regarding the parent demand element element that will be modified
GNEDemandElement * myChildDemandElement
demand element which position will be edited edited
void undo()
undo action
the function-object for an editing operation (abstract base)
Definition GNEChange.h:56
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition GNEChange.h:180
void requireSaveDemandElements()
inform that demand elements has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:164
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows