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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A network change used to modify sorting of hierarchical element childrens
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
24 #include <netedit/GNEViewNet.h>
25 #include <netedit/GNENet.h>
26 
27 #include "GNEChange_Children.h"
28 
29 // ===========================================================================
30 // FOX-declarations
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(demandElementParent->getViewNet()->getNet(), true),
40  myDemandElementParent(demandElementParent),
41  myDemandElementChild(demandElementChild),
42  myOperation(operation),
43  myOriginalElementChildren(demandElementParent->getDemandElementChildren()),
44  myEditedElementChildren(demandElementParent->getDemandElementChildren()) {
45  myDemandElementParent->incRef("GNEChange_Children");
46  // obtain iterator to demandElementChild
47  auto it = std::find(myEditedElementChildren.begin(), myEditedElementChildren.end(), myDemandElementChild);
48  // edit myEditedElementChildren vector
49  if (it != myEditedElementChildren.end()) {
50  if ((operation == Operation::MOVE_FRONT) && (it != (myEditedElementChildren.end() - 1))) {
51  // remove element
52  it = myEditedElementChildren.erase(it);
53  // insert again in a different position
54  myEditedElementChildren.insert(it + 1, myDemandElementChild);
55  } else if ((operation == Operation::MOVE_BACK) && (it != myEditedElementChildren.begin())) {
56  // remove element
57  it = myEditedElementChildren.erase(it);
58  // insert again in a different position
59  myEditedElementChildren.insert(it - 1, myDemandElementChild);
60  }
61  }
62 }
63 
64 
66  assert(myDemandElementParent);
67  myDemandElementParent->decRef("GNEChange_Children");
68 }
69 
70 
71 void
73  if (myForward) {
74  // continue depending of myOperation
75  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
76  // show extra information for tests
77  WRITE_DEBUG("Moving front " + myDemandElementChild->getTagStr() + " within demandElement parent '" + myDemandElementParent->getID() + "' in GNEChange_Children");
78  // restore demand element child original vector in myDemandElementChild
79  myDemandElementParent->myDemandElementChildren = myOriginalElementChildren;
80  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
81  // show extra information for tests
82  WRITE_DEBUG("Moving back " + myDemandElementChild->getTagStr() + " within demandElement parent '" + myDemandElementParent->getID() + "' in GNEChange_Children");
83  // restore demand element child original vector in myDemandElementChild
84  myDemandElementParent->myDemandElementChildren = myOriginalElementChildren;
85  }
86  } else {
87  // continue depending of myOperation
88  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
89  // show extra information for tests
90  WRITE_DEBUG("Moving front " + myDemandElementChild->getTagStr() + " within demandElement parent '" + myDemandElementParent->getID() + "' in GNEChange_Children");
91  // set demand element child edited vector in myDemandElementChild
92  myDemandElementParent->myDemandElementChildren = myEditedElementChildren;
93  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
94  // show extra information for tests
95  WRITE_DEBUG("Moving back " + myDemandElementChild->getTagStr() + " within demandElement parent '" + myDemandElementParent->getID() + "' in GNEChange_Children");
96  // set demand element child edited vector in myDemandElementChild
97  myDemandElementParent->myDemandElementChildren = myEditedElementChildren;
98  }
99  }
100  // Requiere always save childrens
102 }
103 
104 
105 void
107  if (myForward) {
108  // continue depending of myOperation
109  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
110  // show extra information for tests
111  WRITE_DEBUG("Moving front " + myDemandElementChild->getTagStr() + " within demandElement parent '" + myDemandElementParent->getID() + "' in GNEChange_Children");
112  // set demand element child edited vector in myDemandElementChild
113  myDemandElementParent->myDemandElementChildren = myEditedElementChildren;
114  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
115  // show extra information for tests
116  WRITE_DEBUG("Moving back " + myDemandElementChild->getTagStr() + " within demandElement parent '" + myDemandElementParent->getID() + "' in GNEChange_Children");
117  // set demand element child edited vector in myDemandElementChild
118  myDemandElementParent->myDemandElementChildren = myEditedElementChildren;
119  }
120  } else {
121  // continue depending of myOperation
122  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
123  // show extra information for tests
124  WRITE_DEBUG("Moving front " + myDemandElementChild->getTagStr() + " within demandElement parent '" + myDemandElementParent->getID() + "' in GNEChange_Children");
125  // restore demand element child original vector in myDemandElementChild
126  myDemandElementParent->myDemandElementChildren = myOriginalElementChildren;
127  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
128  // show extra information for tests
129  WRITE_DEBUG("Moving back " + myDemandElementChild->getTagStr() + " within demandElement parent '" + myDemandElementParent->getID() + "' in GNEChange_Children");
130  // restore demand element child original vector in myDemandElementChild
131  myDemandElementParent->myDemandElementChildren = myOriginalElementChildren;
132  }
133  }
134  // Requiere always save childrens
136 }
137 
138 
139 FXString
141  if (myForward) {
142  // check myOperation
143  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
144  return ("Undo moving up " + myDemandElementChild->getTagStr()).c_str();
145  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
146  return ("Undo moving down " + myDemandElementChild->getTagStr()).c_str();
147  } else {
148  return ("Invalid operation");
149  }
150  } else {
151  // check myOperation
152  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
153  return ("Undo moving down " + myDemandElementChild->getTagStr()).c_str();
154  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
155  return ("Undo moving up " + myDemandElementChild->getTagStr()).c_str();
156  } else {
157  return ("Invalid operation");
158  }
159  }
160 }
161 
162 
163 FXString
165  if (myForward) {
166  // check myOperation
167  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
168  return ("Redo moving front " + myDemandElementParent->getTagStr()).c_str();
169  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
170  return ("Redo moving back " + myDemandElementParent->getTagStr()).c_str();
171  } else {
172  return ("Invalid operation");
173  }
174  } else {
175  // check myOperation
176  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
177  return ("Redo moving front " + myDemandElementParent->getTagStr()).c_str();
178  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
179  return ("Redo moving back " + myDemandElementParent->getTagStr()).c_str();
180  } else {
181  return ("Invalid operation");
182  }
183  }
184 }
void redo()
redo action
FXString undoName() const
return undoName
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
GNEDemandElement * myDemandElementParent
full information regarding the demand element parent element that will be modified ...
~GNEChange_Children()
Destructor.
const std::vector< GNEDemandElement * > myOriginalElementChildren
copy of demand element childrens before apply operation
const Operation myOperation
void requiereSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2342
const std::string getID() const
function to support debugging
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
void decRef(const std::string &debugMsg="")
Decrease reference.
GNEDemandElement * myDemandElementChild
demand element which position will be edited edited
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:76
FXString redoName() const
get Redo name
void undo()
undo action
const std::string & getTagStr() const
get tag assigned to this object in string format
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:81
std::vector< GNEDemandElement * > myEditedElementChildren
element childrens after apply operation
An Element which don&#39;t belongs to GNENet but has influency in the simulation.