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 /****************************************************************************/
14 // A network change in which a single junction is created or deleted
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
24 
25 #include "GNEChange_Junction.h"
26 
27 // ===========================================================================
28 // FOX-declarations
29 // ===========================================================================
30 FXIMPLEMENT_ABSTRACT(GNEChange_Junction, GNEChange, nullptr, 0)
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
36 
37 GNEChange_Junction::GNEChange_Junction(GNEJunction* junction, bool forward):
39  GNEChange(junction->getNet(), forward),
40  myJunction(junction) {
41  assert(myNet);
42  junction->incRef("GNEChange_Junction");
43 }
44 
45 
47  assert(myJunction);
48  myJunction->decRef("GNEChange_Junction");
49  if (myJunction->unreferenced()) {
50  // show extra information for tests
51  WRITE_DEBUG("Deleting unreferenced " + myJunction->getTagStr() + " '" + myJunction->getID() + "' in GNEChange_Junction");
52  delete myJunction;
53  }
54 }
55 
56 
57 void
59  if (myForward) {
60  // show extra information for tests
61  WRITE_DEBUG("Removing " + myJunction->getTagStr() + " '" + myJunction->getID() + "' from " + toString(SUMO_TAG_NET));
62  // add junction to net
64  } else {
65  // show extra information for tests
66  WRITE_DEBUG("Adding " + myJunction->getTagStr() + " '" + myJunction->getID() + "' into " + toString(SUMO_TAG_NET));
67  // delete junction from net
69  }
70  // enable save netElements
71  myNet->requireSaveNet(true);
72 }
73 
74 
75 void
77  if (myForward) {
78  // show extra information for tests
79  WRITE_DEBUG("Adding " + myJunction->getTagStr() + " '" + myJunction->getID() + "' into " + toString(SUMO_TAG_NET));
80  // add junction into net
82  } else {
83  // show extra information for tests
84  WRITE_DEBUG("Removing " + myJunction->getTagStr() + " '" + myJunction->getID() + "' from " + toString(SUMO_TAG_NET));
85  // delete junction from net
87  }
88  // enable save netElements
89  myNet->requireSaveNet(true);
90 }
91 
92 
93 FXString
95  if (myForward) {
96  return ("Undo create " + toString(SUMO_TAG_JUNCTION)).c_str();
97  } else {
98  return ("Undo delete " + toString(SUMO_TAG_JUNCTION)).c_str();
99  }
100 }
101 
102 
103 FXString
105  if (myForward) {
106  return ("Redo create " + toString(SUMO_TAG_JUNCTION)).c_str();
107  } else {
108  return ("Redo delete " + toString(SUMO_TAG_JUNCTION)).c_str();
109  }
110 }
GNENet::requireSaveNet
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:982
GNEReferenceCounter::unreferenced
bool unreferenced()
check if object ins't referenced
Definition: GNEReferenceCounter.h:78
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_Junction::~GNEChange_Junction
~GNEChange_Junction()
Destructor.
Definition: GNEChange_Junction.cpp:46
GNENet::insertJunction
void insertJunction(GNEJunction *junction)
inserts a single junction into the net and into the underlying netbuild-container
Definition: GNENet.cpp:2889
GNEChange_Junction::undo
void undo()
undo action
Definition: GNEChange_Junction.cpp:58
GNEJunction.h
GNENet::deleteSingleJunction
void deleteSingleJunction(GNEJunction *junction, bool updateViewAfterDeleting)
deletes a single junction
Definition: GNENet.cpp:2954
GNEChange_Junction
Definition: GNEChange_Junction.h:42
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_Junction::myJunction
GNEJunction * myJunction
full information regarding the junction that is to be created/deleted
Definition: GNEChange_Junction.h:75
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
SUMO_TAG_NET
@ SUMO_TAG_NET
root element of a network file
Definition: SUMOXMLDefinitions.h:45
GNEChange_Junction::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Junction.cpp:104
config.h
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEChange_Junction::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Junction.cpp:94
GNEJunction
Definition: GNEJunction.h:47
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_Junction::redo
void redo()
redo action
Definition: GNEChange_Junction.cpp:76
SUMO_TAG_JUNCTION
@ SUMO_TAG_JUNCTION
begin/end of the description of a junction
Definition: SUMOXMLDefinitions.h:59
GNEChange_Junction.h