Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2024 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#include <netedit/GNEViewNet.h>
26
27#include "GNEChange_Children.h"
28
29// ===========================================================================
30// FOX-declarations
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 // show extra information for tests
72 WRITE_DEBUG("Deleting unreferenced " + myParentDemandElement->getTagStr() + " '" + myParentDemandElement->getID() + "' in GNEChange_Children");
73 // delete AC
75 }
76 }
77}
78
79
80void
82 if (myForward) {
83 // continue depending of myOperation
85 // show extra information for tests
86 WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
87 // restore child demand element original vector in myChildDemandElement
88// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
90 // show extra information for tests
91 WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
92 // restore child demand element original vector in myChildDemandElement
93// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
94 }
95 } else {
96 // continue depending of myOperation
98 // show extra information for tests
99 WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
100 // set child demand element edited vector in myChildDemandElement
101// myParentDemandElement- myChildDemandElements = myEditedChildElements;
103 // show extra information for tests
104 WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
105 // set child demand element edited vector in myChildDemandElement
106// myParentDemandElement->myChildDemandElements = myEditedChildElements;
107 }
108 }
109 // require always save children
111}
112
113
114void
116 if (myForward) {
117 // continue depending of myOperation
119 // show extra information for tests
120 WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
121 // set child demand element edited vector in myChildDemandElement
122// myParentDemandElement->myChildDemandElements = myEditedChildElements;
124 // show extra information for tests
125 WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
126 // set child demand element edited vector in myChildDemandElement
127// myParentDemandElement->myChildDemandElements = myEditedChildElements;
128 }
129 } else {
130 // continue depending of myOperation
132 // show extra information for tests
133 WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
134 // restore child demand element original vector in myChildDemandElement
135// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
137 // show extra information for tests
138 WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
139 // restore child demand element original vector in myChildDemandElement
140// myParentDemandElement->myChildDemandElements = myOriginalChildElements;
141 }
142 }
143 // require always save children
145}
146
147
148std::string
150 if (myForward) {
151 // check myOperation
153 return (TL("Undo moving up ") + myChildDemandElement->getTagStr());
155 return (TL("Undo moving down ") + myChildDemandElement->getTagStr());
156 } else {
157 return (TL("Invalid operation"));
158 }
159 } else {
160 // check myOperation
162 return (TL("Undo moving down ") + myChildDemandElement->getTagStr());
164 return (TL("Undo moving up ") + myChildDemandElement->getTagStr());
165 } else {
166 return (TL("Invalid operation"));
167 }
168 }
169}
170
171
172std::string
174 if (myForward) {
175 // check myOperation
177 return (TL("Redo moving front ") + myParentDemandElement->getTagStr());
179 return (TL("Redo moving back ") + myParentDemandElement->getTagStr());
180 } else {
181 return (TL("Invalid operation"));
182 }
183 } else {
184 // check myOperation
186 return (TL("Redo moving front ") + myParentDemandElement->getTagStr());
188 return (TL("Redo moving back ") + myParentDemandElement->getTagStr());
189 } else {
190 return (TL("Invalid operation"));
191 }
192 }
193}
Supermode
@brie enum for supermodes
@ DEMAND
Demand mode (Routes, Vehicles etc..)
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
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.
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
void requireSaveDemandElements()
inform that demand elements has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:131
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2147
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