Eclipse SUMO - Simulation of Urban MObility
GNEChange_LaneType.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 in which a single laneType is created or deleted
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
25 
26 #include "GNEChange_LaneType.h"
27 
28 // ===========================================================================
29 // FOX-declarations
30 // ===========================================================================
31 FXIMPLEMENT_ABSTRACT(GNEChange_LaneType, GNEChange, nullptr, 0)
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
37 
38 GNEChange_LaneType::GNEChange_LaneType(GNELaneType* laneType, const int position, bool forward):
40  GNEChange(laneType, forward, laneType->isAttributeCarrierSelected()),
41  myLaneType(laneType),
42  myPosition(position) {
43  laneType->incRef("GNEChange_LaneType");
44 }
45 
46 
48  myLaneType->decRef("GNEChange_LaneType");
49  if (myLaneType->unreferenced()) {
50  // get lane types
51  const auto &laneTypes = myLaneType->getEdgeTypeParent()->getLaneTypes();
52  // remove it from edgeType
53  if (std::find(laneTypes.begin(), laneTypes.end(), myLaneType) != laneTypes.end()) {
55  }
56  // show extra information for tests
57  WRITE_DEBUG("Deleting unreferenced " + myLaneType->getTagStr() + " '" + myLaneType->getID() + "' GNEChange_LaneType");
58  // delete laneType
59  delete myLaneType;
60  }
61 }
62 
63 
64 void
66  if (myForward) {
67  // show extra information for tests
68  WRITE_DEBUG("Removing " + myLaneType->getTagStr() + " from " + toString(SUMO_TAG_NET));
69  // delete laneType from edgeType parent
71  } else {
72  // show extra information for tests
73  WRITE_DEBUG("Adding " + myLaneType->getTagStr() + " into " + toString(SUMO_TAG_NET));
74  // insert laneType into edgeType parent
76  }
77  // enable save networkElements
79 }
80 
81 
82 void
84  if (myForward) {
85  // show extra information for tests
86  WRITE_DEBUG("Adding " + myLaneType->getTagStr() + " into " + toString(SUMO_TAG_NET));
87  // insert laneType into edgeType parent
89  } else {
90  // show extra information for tests
91  WRITE_DEBUG("Removing " + myLaneType->getTagStr() + " from " + toString(SUMO_TAG_NET));
92  // delete laneType from edgeType parent
94  }
95  // enable save networkElements
97 }
98 
99 
100 FXString
102  if (myForward) {
103  return "Undo create laneType";
104  } else {
105  return "Undo delete laneType";
106  }
107 }
108 
109 
110 FXString
112  if (myForward) {
113  return "Redo create laneType";
114  } else {
115  return "Redo delete laneType";
116  }
117 }
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:286
@ SUMO_TAG_NET
root element of a network file
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * getNet() const
get pointer to net
void redo()
redo action
const int myPosition
position in edgeType Parent
void undo()
undo action
~GNEChange_LaneType()
Destructor.
GNELaneType * myLaneType
full information regarding the laneType that is to be created/deleted
FXString redoName() const
get Redo name
FXString undoName() const
return undoName
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
const std::vector< GNELaneType * > & getLaneTypes() const
get laneTypes
Definition: GNEEdgeType.cpp:87
void removeLaneType(GNELaneType *laneType)
remove laneType
void addLaneType(GNELaneType *laneType, const int position)
add laneType
GNEEdgeType * getEdgeTypeParent() const
get edge type parent
Definition: GNELaneType.cpp:57
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:1047
const std::string & getID() const
get ID
void decRef(const std::string &debugMsg="")
Decrease reference.
bool unreferenced()
check if object ins't referenced