Eclipse SUMO - Simulation of Urban MObility
GNEChange_Junction.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 in which a single junction is created or deleted
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
25 
26 #include "GNEChange_Junction.h"
27 
28 // ===========================================================================
29 // FOX-declarations
30 // ===========================================================================
31 FXIMPLEMENT_ABSTRACT(GNEChange_Junction, GNEChange, nullptr, 0)
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
37 
38 GNEChange_Junction::GNEChange_Junction(GNEJunction* junction, bool forward):
40  GNEChange(junction->getNet(), forward),
41  myJunction(junction) {
42  assert(myNet);
43  junction->incRef("GNEChange_Junction");
44 }
45 
46 
48  assert(myJunction);
49  myJunction->decRef("GNEChange_Junction");
50  if (myJunction->unreferenced()) {
51  // show extra information for tests
52  WRITE_DEBUG("Deleting unreferenced " + myJunction->getTagStr() + " '" + myJunction->getID() + "' in GNEChange_Junction");
53  delete myJunction;
54  }
55 }
56 
57 
58 void
60  if (myForward) {
61  // show extra information for tests
62  WRITE_DEBUG("Removing " + myJunction->getTagStr() + " '" + myJunction->getID() + "' from " + toString(SUMO_TAG_NET));
63  // add junction to net
65  } else {
66  // show extra information for tests
67  WRITE_DEBUG("Adding " + myJunction->getTagStr() + " '" + myJunction->getID() + "' into " + toString(SUMO_TAG_NET));
68  // delete junction from net
70  }
71  // enable save netElements
72  myNet->requiereSaveNet(true);
73 }
74 
75 
76 void
78  if (myForward) {
79  // show extra information for tests
80  WRITE_DEBUG("Adding " + myJunction->getTagStr() + " '" + myJunction->getID() + "' into " + toString(SUMO_TAG_NET));
81  // add junction into net
83  } else {
84  // show extra information for tests
85  WRITE_DEBUG("Removing " + myJunction->getTagStr() + " '" + myJunction->getID() + "' from " + toString(SUMO_TAG_NET));
86  // delete junction from net
88  }
89  // enable save netElements
90  myNet->requiereSaveNet(true);
91 }
92 
93 
94 FXString
96  if (myForward) {
97  return ("Undo create " + toString(SUMO_TAG_JUNCTION)).c_str();
98  } else {
99  return ("Undo delete " + toString(SUMO_TAG_JUNCTION)).c_str();
100  }
101 }
102 
103 
104 FXString
106  if (myForward) {
107  return ("Redo create " + toString(SUMO_TAG_JUNCTION)).c_str();
108  } else {
109  return ("Redo delete " + toString(SUMO_TAG_JUNCTION)).c_str();
110  }
111 }
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:79
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
GNENet::requiereSaveNet
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:933
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:81
GNEChange_Junction::~GNEChange_Junction
~GNEChange_Junction()
Destructor.
Definition: GNEChange_Junction.cpp:47
GNENet::insertJunction
void insertJunction(GNEJunction *junction)
inserts a single junction into the net and into the underlying netbuild-container
Definition: GNENet.cpp:2832
GNEChange_Junction::undo
void undo()
undo action
Definition: GNEChange_Junction.cpp:59
GNEJunction.h
GNENet::deleteSingleJunction
void deleteSingleJunction(GNEJunction *junction, bool updateViewAfterDeleting)
deletes a single junction
Definition: GNENet.cpp:2897
GNEChange_Junction
Definition: GNEChange_Junction.h:43
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:76
GNEReferenceCounter::decRef
void decRef(const std::string &debugMsg="")
Decrease reference.
Definition: GNEReferenceCounter.h:53
GNEChange_Junction::myJunction
GNEJunction * myJunction
full information regarding the junction that is to be created/deleted
Definition: GNEChange_Junction.h:76
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
SUMO_TAG_NET
root element of a network file
Definition: SUMOXMLDefinitions.h:46
GNEChange_Junction::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Junction.cpp:105
config.h
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEChange_Junction::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Junction.cpp:95
GNEJunction
Definition: GNEJunction.h:48
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
GNENet.h
GNEChange_Junction::redo
void redo()
redo action
Definition: GNEChange_Junction.cpp:77
SUMO_TAG_JUNCTION
begin/end of the description of a junction
Definition: SUMOXMLDefinitions.h:60
GNEChange_Junction.h