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    GNEClosingLaneReroute.cpp
11 /// @author  Pablo Alvarez Lopez
12 /// @date    Jan 2017
13 /// @version $Id$
14 ///
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include "GNEClosingLaneReroute.h"
24 #include <netedit/netelements/GNELane.h>
25 #include <netedit/netelements/GNEEdge.h>
26 #include <netedit/changes/GNEChange_Attribute.h>
27 #include <netedit/dialogs/GNERerouterIntervalDialog.h>
28 
29 #include <netedit/GNEUndoList.h>
30 #include <netedit/GNEViewNet.h>
31 #include <netedit/GNENet.h>
32 
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
37 
GNEClosingLaneReroute(GNERerouterIntervalDialog * rerouterIntervalDialog)38 GNEClosingLaneReroute::GNEClosingLaneReroute(GNERerouterIntervalDialog* rerouterIntervalDialog) :
39     GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_CLOSING_LANE_REROUTE, "", false,
40 {}, {}, {}, {rerouterIntervalDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}),
41 myClosedLane(rerouterIntervalDialog->getEditedAdditional()->getAdditionalParents().at(0)->getEdgeChilds().at(0)->getLanes().at(0)) {
42     // fill closing lane reroute interval with default values
43     setDefaultValues();
44 }
45 
46 
GNEClosingLaneReroute(GNEAdditional * rerouterIntervalParent,GNELane * closedLane,SVCPermissions permissions)47 GNEClosingLaneReroute::GNEClosingLaneReroute(GNEAdditional* rerouterIntervalParent, GNELane* closedLane, SVCPermissions permissions) :
48     GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_CLOSING_LANE_REROUTE, "", false,
49 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {}, {}, {}),
50 myClosedLane(closedLane),
51 myPermissions(permissions) {
52 }
53 
54 
~GNEClosingLaneReroute()55 GNEClosingLaneReroute::~GNEClosingLaneReroute() {}
56 
57 
58 void
moveGeometry(const Position &)59 GNEClosingLaneReroute::moveGeometry(const Position&) {
60     // This additional cannot be moved
61 }
62 
63 
64 void
commitGeometryMoving(GNEUndoList *)65 GNEClosingLaneReroute::commitGeometryMoving(GNEUndoList*) {
66     // This additional cannot be moved
67 }
68 
69 
70 void
updateGeometry(bool)71 GNEClosingLaneReroute::updateGeometry(bool /*updateGrid*/) {
72     // Currently this additional doesn't own a Geometry
73 }
74 
75 
76 Position
getPositionInView() const77 GNEClosingLaneReroute::getPositionInView() const {
78     return getAdditionalParents().at(0)->getPositionInView();
79 }
80 
81 
82 std::string
getParentName() const83 GNEClosingLaneReroute::getParentName() const {
84     return getAdditionalParents().at(0)->getID();
85 }
86 
87 
88 void
drawGL(const GUIVisualizationSettings &) const89 GNEClosingLaneReroute::drawGL(const GUIVisualizationSettings& /* s */) const {
90     // Currently this additional isn't drawn
91 }
92 
93 
94 std::string
getAttribute(SumoXMLAttr key) const95 GNEClosingLaneReroute::getAttribute(SumoXMLAttr key) const {
96     switch (key) {
97         case SUMO_ATTR_ID:
98             return getAdditionalID();
99         case SUMO_ATTR_LANE:
100             return myClosedLane->getID();
101         case SUMO_ATTR_ALLOW:
102             return getVehicleClassNames(myPermissions);
103         case SUMO_ATTR_DISALLOW:
104             return getVehicleClassNames(invertPermissions(myPermissions));
105         case GNE_ATTR_PARENT:
106             return getAdditionalParents().at(0)->getID();
107         case GNE_ATTR_GENERIC:
108             return getGenericParametersStr();
109         default:
110             throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
111     }
112 }
113 
114 
115 void
setAttribute(SumoXMLAttr key,const std::string & value,GNEUndoList * undoList)116 GNEClosingLaneReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
117     if (value == getAttribute(key)) {
118         return; //avoid needless changes, later logic relies on the fact that attributes have changed
119     }
120     switch (key) {
121         case SUMO_ATTR_ID:
122         case SUMO_ATTR_LANE:
123         case SUMO_ATTR_ALLOW:
124         case SUMO_ATTR_DISALLOW:
125         case GNE_ATTR_GENERIC:
126             undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
127             break;
128         default:
129             throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
130     }
131 }
132 
133 
134 bool
isValid(SumoXMLAttr key,const std::string & value)135 GNEClosingLaneReroute::isValid(SumoXMLAttr key, const std::string& value) {
136     switch (key) {
137         case SUMO_ATTR_ID:
138             return isValidAdditionalID(value);
139         case SUMO_ATTR_LANE:
140             return (myViewNet->getNet()->retrieveLane(value, false) != nullptr);
141         case SUMO_ATTR_ALLOW:
142         case SUMO_ATTR_DISALLOW:
143             return canParseVehicleClasses(value);
144         case GNE_ATTR_GENERIC:
145             return isGenericParametersValid(value);
146         default:
147             throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
148     }
149 }
150 
151 
152 std::string
getPopUpID() const153 GNEClosingLaneReroute::getPopUpID() const {
154     return getTagStr();
155 }
156 
157 
158 std::string
getHierarchyName() const159 GNEClosingLaneReroute::getHierarchyName() const {
160     return getTagStr() + ": " + myClosedLane->getID();
161 }
162 
163 // ===========================================================================
164 // private
165 // ===========================================================================
166 
167 void
setAttribute(SumoXMLAttr key,const std::string & value)168 GNEClosingLaneReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
169     switch (key) {
170         case SUMO_ATTR_ID:
171             changeAdditionalID(value);
172             break;
173         case SUMO_ATTR_LANE:
174             myClosedLane = myViewNet->getNet()->retrieveLane(value);
175             break;
176         case SUMO_ATTR_ALLOW:
177             myPermissions = parseVehicleClasses(value);
178             break;
179         case SUMO_ATTR_DISALLOW:
180             myPermissions = invertPermissions(parseVehicleClasses(value));
181             break;
182         case GNE_ATTR_GENERIC:
183             setGenericParametersStr(value);
184             break;
185         default:
186             throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
187     }
188     // check if updated attribute requieres update geometry
189     if (myTagProperty.hasAttribute(key) && myTagProperty.getAttributeProperties(key).requiereUpdateGeometry()) {
190         updateGeometry(true);
191     }
192 }
193 
194 /****************************************************************************/
195