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 /****************************************************************************/
10 /// @file GNEChange_Crossing.cpp
11 /// @author Pablo Alvarez Lopez
12 /// @date Oct 2016
13 /// @version $Id$
14 ///
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>
24 #include <netedit/netelements/GNECrossing.h>
25 #include <netedit/netelements/GNEJunction.h>
26 #include <netedit/GNEViewParent.h>
27 #include <netbuild/NBNetBuilder.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/frames/GNEFrame.h>
30
31 #include "GNEChange_Crossing.h"
32
33
34 // ===========================================================================
35 // FOX-declarations
36 // ===========================================================================
37 FXIMPLEMENT_ABSTRACT(GNEChange_Crossing, GNEChange, nullptr, 0)
38
39 // ===========================================================================
40 // member method definitions
41 // ===========================================================================
42
43
GNEChange_Crossing(GNEJunction * junctionParent,const std::vector<NBEdge * > & edges,double width,bool priority,int customTLIndex,int customTLIndex2,const PositionVector & customShape,bool selected,bool forward)44 GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const std::vector<NBEdge*>& edges,
45 double width, bool priority, int customTLIndex, int customTLIndex2, const PositionVector& customShape, bool selected, bool forward):
46 GNEChange(junctionParent->getNet(), forward),
47 myJunctionParent(junctionParent),
48 myEdges(edges),
49 myWidth(width),
50 myPriority(priority),
51 myCustomTLIndex(customTLIndex),
52 myCustomTLIndex2(customTLIndex2),
53 myCustomShape(customShape),
54 mySelected(selected) {
55 assert(myNet);
56 }
57
58
GNEChange_Crossing(GNEJunction * junctionParent,const NBNode::Crossing & crossing,bool forward)59 GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const NBNode::Crossing& crossing, bool forward):
60 GNEChange(junctionParent->getNet(), forward),
61 myJunctionParent(junctionParent),
62 myEdges(crossing.edges),
63 myWidth(crossing.width),
64 myPriority(crossing.priority),
65 myCustomTLIndex(crossing.customTLIndex),
66 myCustomTLIndex2(crossing.customTLIndex2),
67 myCustomShape(crossing.customShape),
68 mySelected(false) {
69 assert(myNet);
70 }
71
72
~GNEChange_Crossing()73 GNEChange_Crossing::~GNEChange_Crossing() {
74 assert(myNet);
75 }
76
77
undo()78 void GNEChange_Crossing::undo() {
79 if (myForward) {
80 // show extra information for tests
81 WRITE_DEBUG("removing " + toString(SUMO_TAG_CROSSING) + " from " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
82 // remove crossing of NBNode
83 myJunctionParent->getNBNode()->removeCrossing(myEdges);
84 // rebuild GNECrossings
85 myJunctionParent->rebuildGNECrossings();
86 // Check if Flag "haveNetworkCrossings" has to be disabled
87 if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
88 // change flag of NetBuilder (For build GNECrossing)
89 myNet->getNetBuilder()->setHaveNetworkCrossings(false);
90 // show extra information for tests
91 WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
92 }
93 // Update view
94 myNet->getViewNet()->update();
95 } else {
96 // show extra information for tests
97 WRITE_DEBUG("Adding " + toString(SUMO_TAG_CROSSING) + " into " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
98 // add crossing of NBNode
99 NBNode::Crossing* c = myJunctionParent->getNBNode()->addCrossing(myEdges, myWidth, myPriority, myCustomTLIndex, myCustomTLIndex2, myCustomShape);
100 // Check if Flag "haveNetworkCrossings" has to be enabled
101 if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
102 myNet->getNetBuilder()->setHaveNetworkCrossings(true);
103 // show extra information for tests
104 WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
105 }
106 // rebuild GNECrossings
107 myJunctionParent->rebuildGNECrossings();
108 // select if mySelected is enabled
109 if (mySelected) {
110 myJunctionParent->retrieveGNECrossing(c, false)->selectAttributeCarrier();
111 }
112 // Update view
113 myNet->getViewNet()->update();
114 }
115 // enable save netElements
116 myNet->requiereSaveNet(true);
117 }
118
119
redo()120 void GNEChange_Crossing::redo() {
121 if (myForward) {
122 // show extra information for tests
123 WRITE_DEBUG("Adding " + toString(SUMO_TAG_CROSSING) + " into " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
124 // add crossing of NBNode and update geometry
125 NBNode::Crossing* c = myJunctionParent->getNBNode()->addCrossing(myEdges, myWidth, myPriority, myCustomTLIndex, myCustomTLIndex2, myCustomShape);
126 // Check if Flag "haveNetworkCrossings" has to be enabled
127 if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
128 myNet->getNetBuilder()->setHaveNetworkCrossings(true);
129 // show extra information for tests
130 WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
131 }
132 // rebuild GNECrossings
133 myJunctionParent->rebuildGNECrossings();
134 // select if mySelected is enabled
135 if (mySelected) {
136 myJunctionParent->retrieveGNECrossing(c, false)->selectAttributeCarrier();
137 }
138 // Update view
139 myNet->getViewNet()->update();
140 } else {
141 // show extra information for tests
142 WRITE_DEBUG("Removing " + toString(SUMO_TAG_CROSSING) + " from " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
143 // remove crossing of NBNode and update geometry
144 myJunctionParent->getNBNode()->removeCrossing(myEdges);
145 // rebuild GNECrossings
146 myJunctionParent->rebuildGNECrossings();
147 // Check if Flag "haveNetworkCrossings" has to be disabled
148 if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
149 // change flag of NetBuilder (For build GNECrossing)
150 myNet->getNetBuilder()->setHaveNetworkCrossings(false);
151 // show extra information for tests
152 WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
153 }
154 // Update view
155 myNet->getViewNet()->update();
156 }
157 // enable save netElements
158 myNet->requiereSaveNet(true);
159 }
160
161
162 FXString
undoName() const163 GNEChange_Crossing::undoName() const {
164 if (myForward) {
165 return ("Undo create " + toString(SUMO_TAG_CROSSING)).c_str();
166 } else {
167 return ("Undo delete " + toString(SUMO_TAG_CROSSING)).c_str();
168 }
169 }
170
171
172 FXString
redoName() const173 GNEChange_Crossing::redoName() const {
174 if (myForward) {
175 return ("Redo create " + toString(SUMO_TAG_CROSSING)).c_str();
176 } else {
177 return ("Redo delete " + toString(SUMO_TAG_CROSSING)).c_str();
178 }
179 }
180