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-2020 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 // ===========================================================================
29 FXIMPLEMENT_ABSTRACT(GNEChange_Children, GNEChange, nullptr, 0)
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
35 GNEChange_Children::GNEChange_Children(GNEDemandElement* demandElementParent, GNEDemandElement* demandElementChild, const Operation operation) :
36  GNEChange(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
69  delete myParentDemandElement;
70  }
71 }
72 
73 
74 void
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  // Requiere always save children
105 }
106 
107 
108 void
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  // Requiere always save children
139 }
140 
141 
142 FXString
144  if (myForward) {
145  // check myOperation
146  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
147  return ("Undo moving up " + myChildDemandElement->getTagStr()).c_str();
148  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
149  return ("Undo moving down " + myChildDemandElement->getTagStr()).c_str();
150  } else {
151  return ("Invalid operation");
152  }
153  } else {
154  // check myOperation
155  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
156  return ("Undo moving down " + myChildDemandElement->getTagStr()).c_str();
157  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
158  return ("Undo moving up " + myChildDemandElement->getTagStr()).c_str();
159  } else {
160  return ("Invalid operation");
161  }
162  }
163 }
164 
165 
166 FXString
168  if (myForward) {
169  // check myOperation
170  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
171  return ("Redo moving front " + myParentDemandElement->getTagStr()).c_str();
172  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
173  return ("Redo moving back " + myParentDemandElement->getTagStr()).c_str();
174  } else {
175  return ("Invalid operation");
176  }
177  } else {
178  // check myOperation
179  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
180  return ("Redo moving front " + myParentDemandElement->getTagStr()).c_str();
181  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
182  return ("Redo moving back " + myParentDemandElement->getTagStr()).c_str();
183  } else {
184  return ("Invalid operation");
185  }
186  }
187 }
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:286
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * getNet() const
get pointer to net
const Operation myOperation
~GNEChange_Children()
Destructor.
void redo()
redo action
GNEDemandElement * myParentDemandElement
full information regarding the parent demand element element that will be modified
GNEDemandElement * myChildDemandElement
demand element which position will be edited edited
FXString undoName() const
return undoName
FXString redoName() const
get Redo name
void undo()
undo action
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:65
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:215
An Element which don't belongs to GNENet but has influency in the simulation.
const std::string & getID() const
get ID
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2474
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced