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 /****************************************************************************/
14 // A network change used to modify sorting of hierarchical element childrens
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
23 #include <netedit/GNEViewNet.h>
24 #include <netedit/GNENet.h>
25 
26 #include "GNEChange_Children.h"
27 
28 // ===========================================================================
29 // FOX-declarations
30 // ===========================================================================
31 FXIMPLEMENT_ABSTRACT(GNEChange_Children, GNEChange, nullptr, 0)
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
37 GNEChange_Children::GNEChange_Children(GNEDemandElement* demandElementParent, GNEDemandElement* demandElementChild, const Operation operation) :
38  GNEChange(demandElementParent->getViewNet()->getNet(), true),
39  myParentDemandElement(demandElementParent),
40  myChildDemandElement(demandElementChild),
41  myOperation(operation),
42  myOriginalChildElements(demandElementParent->getChildDemandElements()),
43  myEditedChildElements(demandElementParent->getChildDemandElements()) {
44  myParentDemandElement->incRef("GNEChange_Children");
45  // obtain iterator to demandElementChild
46  auto it = std::find(myEditedChildElements.begin(), myEditedChildElements.end(), myChildDemandElement);
47  // edit myEditedChildElements vector
48  if (it != myEditedChildElements.end()) {
49  if ((operation == Operation::MOVE_FRONT) && (it != (myEditedChildElements.end() - 1))) {
50  // remove element
51  it = myEditedChildElements.erase(it);
52  // insert again in a different position
53  myEditedChildElements.insert(it + 1, myChildDemandElement);
54  } else if ((operation == Operation::MOVE_BACK) && (it != myEditedChildElements.begin())) {
55  // remove element
56  it = myEditedChildElements.erase(it);
57  // insert again in a different position
58  myEditedChildElements.insert(it - 1, myChildDemandElement);
59  }
60  }
61 }
62 
63 
65  assert(myParentDemandElement);
66  myParentDemandElement->decRef("GNEChange_Children");
67 }
68 
69 
70 void
72  if (myForward) {
73  // continue depending of myOperation
74  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
75  // show extra information for tests
76  WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
77  // restore child demand element original vector in myChildDemandElement
79  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
80  // show extra information for tests
81  WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
82  // restore child demand element original vector in myChildDemandElement
84  }
85  } else {
86  // continue depending of myOperation
87  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
88  // show extra information for tests
89  WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
90  // set child demand element edited vector in myChildDemandElement
92  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
93  // show extra information for tests
94  WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
95  // set child demand element edited vector in myChildDemandElement
97  }
98  }
99  // Requiere always save childrens
101 }
102 
103 
104 void
106  if (myForward) {
107  // continue depending of myOperation
108  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
109  // show extra information for tests
110  WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
111  // set child demand element edited vector in myChildDemandElement
113  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
114  // show extra information for tests
115  WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
116  // set child demand element edited vector in myChildDemandElement
118  }
119  } else {
120  // continue depending of myOperation
121  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
122  // show extra information for tests
123  WRITE_DEBUG("Moving front " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
124  // restore child demand element original vector in myChildDemandElement
126  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
127  // show extra information for tests
128  WRITE_DEBUG("Moving back " + myChildDemandElement->getTagStr() + " within demandElement parent '" + myParentDemandElement->getID() + "' in GNEChange_Children");
129  // restore child demand element original vector in myChildDemandElement
131  }
132  }
133  // Requiere always save childrens
135 }
136 
137 
138 FXString
140  if (myForward) {
141  // check myOperation
142  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
143  return ("Undo moving up " + myChildDemandElement->getTagStr()).c_str();
144  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
145  return ("Undo moving down " + myChildDemandElement->getTagStr()).c_str();
146  } else {
147  return ("Invalid operation");
148  }
149  } else {
150  // check myOperation
151  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
152  return ("Undo moving down " + myChildDemandElement->getTagStr()).c_str();
153  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
154  return ("Undo moving up " + myChildDemandElement->getTagStr()).c_str();
155  } else {
156  return ("Invalid operation");
157  }
158  }
159 }
160 
161 
162 FXString
164  if (myForward) {
165  // check myOperation
166  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
167  return ("Redo moving front " + myParentDemandElement->getTagStr()).c_str();
168  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
169  return ("Redo moving back " + myParentDemandElement->getTagStr()).c_str();
170  } else {
171  return ("Invalid operation");
172  }
173  } else {
174  // check myOperation
175  if (myOperation == GNEChange_Children::Operation::MOVE_FRONT) {
176  return ("Redo moving front " + myParentDemandElement->getTagStr()).c_str();
177  } else if (myOperation == GNEChange_Children::Operation::MOVE_BACK) {
178  return ("Redo moving back " + myParentDemandElement->getTagStr()).c_str();
179  } else {
180  return ("Invalid operation");
181  }
182  }
183 }
GNEDemandElement
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEDemandElement.h:55
GNEChange_Children::myChildDemandElement
GNEDemandElement * myChildDemandElement
demand element which position will be edited edited
Definition: GNEChange_Children.h:81
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:80
GNEChange_Children::myParentDemandElement
GNEDemandElement * myParentDemandElement
full information regarding the parent demand element element that will be modified
Definition: GNEChange_Children.h:78
GNEChange_Children::redo
void redo()
redo action
Definition: GNEChange_Children.cpp:105
GNEChange_Children::myOperation
const Operation myOperation
Definition: GNEChange_Children.h:84
GNEChange_Children
Definition: GNEChange_Children.h:40
GNENet::requireSaveDemandElements
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2392
GNEHierarchicalChildElements::myChildDemandElements
std::vector< GNEDemandElement * > myChildDemandElements
vector with the demand elements children
Definition: GNEHierarchicalChildElements.h:253
GNEDemandElement.h
GNEViewNet.h
GNEChange_Children::Operation
Operation
Definition: GNEChange_Children.h:45
GNEChange::myNet
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:75
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:52
GNEChange_Children::myOriginalChildElements
const std::vector< GNEDemandElement * > myOriginalChildElements
copy of child demand elementss before apply operation
Definition: GNEChange_Children.h:87
GNEChange_Children::myEditedChildElements
std::vector< GNEDemandElement * > myEditedChildElements
element childrens after apply operation
Definition: GNEChange_Children.h:90
config.h
GNEChange_Children::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Children.cpp:139
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEChange_Children::undo
void undo()
undo action
Definition: GNEChange_Children.cpp:71
GNEChange_Children::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Children.cpp:163
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:284
GNENet.h
GNEChange_Children.h
GNEChange_Children::~GNEChange_Children
~GNEChange_Children()
Destructor.
Definition: GNEChange_Children.cpp:64