Eclipse SUMO - Simulation of Urban MObility
GNEChange_Connection.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 connection is created or deleted
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
23 #include <netedit/GNENet.h>
24 
25 #include "GNEChange_Connection.h"
26 
27 // ===========================================================================
28 // FOX-declarations
29 // ===========================================================================
30 FXIMPLEMENT_ABSTRACT(GNEChange_Connection, GNEChange, nullptr, 0)
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
36 
37 GNEChange_Connection::GNEChange_Connection(GNEEdge* edge, NBEdge::Connection nbCon, bool selected, bool forward) :
38  GNEChange(edge->getNet(), forward),
39  myEdge(edge),
40  myNBEdgeConnection(nbCon),
41  mySelected(selected) {
42  assert(myEdge);
43 }
44 
45 
47  assert(myEdge);
48 }
49 
50 
51 void
53  if (myForward) {
54  // show extra information for tests
55  WRITE_DEBUG("Removing " + toString(SUMO_TAG_CONNECTION) + " '" +
57  toString(SUMO_TAG_EDGE) + " '" + myEdge->getID() + "'");
58  // remove connection from edge
60  } else {
61  // show extra information for tests
62  std::string selected = mySelected ? ("a previously selected ") : ("");
63  WRITE_DEBUG("Adding " + selected + toString(SUMO_TAG_CONNECTION) + " '" +
65  toString(SUMO_TAG_EDGE) + " '" + myEdge->getID() + "'");
66  // add connection into edge
68  }
69  // enable save netElements
70  myNet->requireSaveNet(true);
71 }
72 
73 
74 void
76  if (myForward) {
77  // show extra information for tests
78  std::string selected = mySelected ? ("a previously selected ") : ("");
79  WRITE_DEBUG("Adding " + selected + toString(SUMO_TAG_CONNECTION) + " '" +
81  toString(SUMO_TAG_EDGE) + " '" + myEdge->getID() + "'");
82  // add connection into edge
84  } else {
85  // show extra information for tests
86  WRITE_DEBUG("Removing " + toString(SUMO_TAG_CONNECTION) + " '" +
88  toString(SUMO_TAG_EDGE) + " '" + myEdge->getID() + "'");
89  // remove connection from edge
91  }
92  // enable save netElements
93  myNet->requireSaveNet(true);
94 }
95 
96 
97 FXString
99  if (myForward) {
100  return ("Undo create " + toString(SUMO_TAG_CONNECTION)).c_str();
101  } else {
102  return ("Undo delete " + toString(SUMO_TAG_CONNECTION)).c_str();
103  }
104 }
105 
106 
107 FXString
109  if (myForward) {
110  return ("Redo create " + toString(SUMO_TAG_CONNECTION)).c_str();
111  } else {
112  return ("Redo delete " + toString(SUMO_TAG_CONNECTION)).c_str();
113  }
114 }
GNENet::requireSaveNet
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:982
NBEdge::Connection::toEdge
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:212
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNEChange_Connection::myEdge
GNEEdge * myEdge
Definition: GNEChange_Connection.h:78
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:80
GNEChange_Connection::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Connection.cpp:98
NBEdge::Connection::fromLane
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:209
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:51
NBEdge::Connection::toLane
int toLane
The lane the connections yields in.
Definition: NBEdge.h:215
GNEEdge::getNBEdge
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:631
NBEdge::getLaneID
std::string getLaneID(int lane) const
get lane ID
Definition: NBEdge.cpp:3093
SUMO_TAG_EDGE
begin/end of the description of an edge
Definition: SUMOXMLDefinitions.h:47
GNEEdge.h
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
GNEChange_Connection
Definition: GNEChange_Connection.h:44
GNEChange_Connection::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Connection.cpp:108
GNEChange_Connection::mySelected
bool mySelected
flag to indicates if crossing was previously selected
Definition: GNEChange_Connection.h:84
GNEEdge::addConnection
void addConnection(NBEdge::Connection nbCon, bool selectAfterCreation=false)
adds a connection
Definition: GNEEdge.cpp:1777
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GNEChange_Connection::myNBEdgeConnection
NBEdge::Connection myNBEdgeConnection
the data which must be copied because the original reference does not persist
Definition: GNEChange_Connection.h:81
SUMO_TAG_CONNECTION
connectio between two lanes
Definition: SUMOXMLDefinitions.h:202
GNEEdge::removeConnection
void removeConnection(NBEdge::Connection nbCon)
removes a connection
Definition: GNEEdge.cpp:1813
GNEChange_Connection::undo
void undo()
undo action
Definition: GNEChange_Connection.cpp:52
config.h
GNEChange_Connection::~GNEChange_Connection
~GNEChange_Connection()
Destructor.
Definition: GNEChange_Connection.cpp:46
GNEChange_Connection::redo
void redo()
redo action
Definition: GNEChange_Connection.cpp:75
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_Connection.h