Eclipse SUMO - Simulation of Urban MObility
GNEChange_Children.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2023 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#include <config.h>
21
22#include <netedit/GNENet.h>
23
24#include "GNEChange_Children.h"
25
26// ===========================================================================
27// FOX-declarations
28// ===========================================================================
29FXIMPLEMENT_ABSTRACT(GNEChange_Children, GNEChange, nullptr, 0)
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
35GNEChange_Children::GNEChange_Children(GNEDemandElement* demandElementParent, GNEDemandElement* demandElementChild, const Operation operation) :
36 GNEChange(Supermode::DEMAND, true, demandElementChild->isAttributeCarrierSelected()),
37 myParentDemandElement(demandElementParent),
38 myChildDemandElement(demandElementChild),
39 myOperation(operation),
40 myOriginalChildElements(demandElementParent->getChildDemandElements()),
41 myEditedChildElements(demandElementParent->getChildDemandElements()) {
42 myParentDemandElement->incRef("GNEChange_Children");
43 // obtain iterator to demandElementChild
44 auto it = std::find(myEditedChildElements.begin(), myEditedChildElements.end(), myChildDemandElement);
45 // edit myEditedChildElements vector
46 if (it != myEditedChildElements.end()) {
47 if ((operation == Operation::MOVE_FRONT) && (it != (myEditedChildElements.end() - 1))) {
48 // remove element
49 it = myEditedChildElements.erase(it);
50 // insert again in a different position
51 myEditedChildElements.insert(it + 1, myChildDemandElement);
52 } else if ((operation == Operation::MOVE_BACK) && (it != myEditedChildElements.begin())) {
53 // remove element
54 it = myEditedChildElements.erase(it);
55 // insert again in a different position
56 myEditedChildElements.insert(it - 1, myChildDemandElement);
57 }
58 }
59}
60
61
63 myParentDemandElement->decRef("GNEChange_Children");
64 // remove if is unreferenced
66 // show extra information for tests
67 WRITE_DEBUG("Deleting unreferenced " + myParentDemandElement->getTagStr() + " '" + myParentDemandElement->getID() + "' in GNEChange_Children");
68 // delete AC
70 }
71}
72
73
74void
76 if (myForward) {
77 // continue depending of myOperation
78 if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
79 // show extra information for tests
80 WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
81 // restore child demand element original vector in myChildDemandElement
82// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
83 } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
84 // show extra information for tests
85 WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
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 // show extra information for tests
93 WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
94 // set child demand element edited vector in myChildDemandElement
95// myParentDemandElement- myChildDemandElements = myEditedChildElements;
96 } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
97 // show extra information for tests
98 WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
99 // set child demand element edited vector in myChildDemandElement
100// myParentDemandElement->myChildDemandElements = myEditedChildElements;
101 }
102 }
103 // require always save children
105}
106
107
108void
110 if (myForward) {
111 // continue depending of myOperation
112 if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
113 // show extra information for tests
114 WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
115 // set child demand element edited vector in myChildDemandElement
116// myParentDemandElement->myChildDemandElements = myEditedChildElements;
117 } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
118 // show extra information for tests
119 WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
120 // set child demand element edited vector in myChildDemandElement
121// myParentDemandElement->myChildDemandElements = myEditedChildElements;
122 }
123 } else {
124 // continue depending of myOperation
125 if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
126 // show extra information for tests
127 WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
128 // restore child demand element original vector in myChildDemandElement
129// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
130 } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
131 // show extra information for tests
132 WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
133 // restore child demand element original vector in myChildDemandElement
134// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
135 }
136 }
137 // require always save children
139}
140
141
142std::string
144 if (myForward) {
145 // check myOperation
146 if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
147 return (TL("Undo moving up ") + myChildDemandElement->getTagStr());
148 } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
149 return (TL("Undo moving down ") + myChildDemandElement->getTagStr());
150 } else {
151 return (TL("Invalid operation"));
152 }
153 } else {
154 // check myOperation
155 if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
156 return (TL("Undo moving down ") + myChildDemandElement->getTagStr());
157 } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
158 return (TL("Undo moving up ") + myChildDemandElement->getTagStr());
159 } else {
160 return (TL("Invalid operation"));
161 }
162 }
163}
164
165
166std::string
168 if (myForward) {
169 // check myOperation
170 if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
171 return (TL("Redo moving front ") + myParentDemandElement->getTagStr());
172 } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
173 return (TL("Redo moving back ") + myParentDemandElement->getTagStr());
174 } else {
175 return (TL("Invalid operation"));
176 }
177 } else {
178 // check myOperation
179 if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
180 return (TL("Redo moving front ") + myParentDemandElement->getTagStr());
181 } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
182 return (TL("Redo moving back ") + myParentDemandElement->getTagStr());
183 } else {
184 return (TL("Invalid operation"));
185 }
186 }
187}
Supermode
@brie enum for supermodes
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:278
#define TL(string)
Definition: MsgHandler.h:284
const std::string getID() const
get ID (all Attribute Carriers have one)
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.
void redo()
redo action
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:212
An Element which don't belong to GNENet but has influence in the simulation.
void requireSaveDemandElements()
inform that demand elements has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition: GNENet.cpp:126
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced