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    GNEClosingReroute.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 "GNEClosingReroute.h"
24 #include <netedit/netelements/GNEEdge.h>
25 #include <netedit/changes/GNEChange_Attribute.h>
26 #include <netedit/dialogs/GNERerouterIntervalDialog.h>
27 
28 #include <netedit/GNEUndoList.h>
29 #include <netedit/GNEViewNet.h>
30 #include <netedit/GNENet.h>
31 
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
GNEClosingReroute(GNERerouterIntervalDialog * rerouterIntervalDialog)37 GNEClosingReroute::GNEClosingReroute(GNERerouterIntervalDialog* rerouterIntervalDialog) :
38     GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_CALIBRATOR, SUMO_TAG_CLOSING_REROUTE, "", false,
39 {}, {}, {}, {rerouterIntervalDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}),
40 myClosedEdge(rerouterIntervalDialog->getEditedAdditional()->getAdditionalParents().at(0)->getEdgeChilds().at(0)) {
41     // fill closing reroute interval with default values
42     setDefaultValues();
43 }
44 
45 
GNEClosingReroute(GNEAdditional * rerouterIntervalParent,GNEEdge * closedEdge,SVCPermissions permissions)46 GNEClosingReroute::GNEClosingReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* closedEdge, SVCPermissions permissions) :
47     GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_CALIBRATOR, SUMO_TAG_CLOSING_REROUTE, "", false,
48 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {}, {}, {}),
49 myClosedEdge(closedEdge),
50 myPermissions(permissions) {
51 }
52 
53 
~GNEClosingReroute()54 GNEClosingReroute::~GNEClosingReroute() {}
55 
56 
57 void
moveGeometry(const Position &)58 GNEClosingReroute::moveGeometry(const Position&) {
59     // This additional cannot be moved
60 }
61 
62 
63 void
commitGeometryMoving(GNEUndoList *)64 GNEClosingReroute::commitGeometryMoving(GNEUndoList*) {
65     // This additional cannot be moved
66 }
67 
68 
69 void
updateGeometry(bool)70 GNEClosingReroute::updateGeometry(bool /*updateGrid*/) {
71     // Currently this additional doesn't own a Geometry
72 }
73 
74 
75 Position
getPositionInView() const76 GNEClosingReroute::getPositionInView() const {
77     return getAdditionalParents().at(0)->getPositionInView();
78 }
79 
80 
81 std::string
getParentName() const82 GNEClosingReroute::getParentName() const {
83     return getAdditionalParents().at(0)->getID();
84 }
85 
86 
87 void
drawGL(const GUIVisualizationSettings &) const88 GNEClosingReroute::drawGL(const GUIVisualizationSettings& /* s */) const {
89     // Currently this additional isn't drawn
90 }
91 
92 
93 std::string
getAttribute(SumoXMLAttr key) const94 GNEClosingReroute::getAttribute(SumoXMLAttr key) const {
95     switch (key) {
96         case SUMO_ATTR_ID:
97             return getAdditionalID();
98         case SUMO_ATTR_EDGE:
99             return myClosedEdge->getID();
100         case SUMO_ATTR_ALLOW:
101             return getVehicleClassNames(myPermissions);
102         case SUMO_ATTR_DISALLOW:
103             return getVehicleClassNames(invertPermissions(myPermissions));
104         case GNE_ATTR_PARENT:
105             return getAdditionalParents().at(0)->getID();
106         case GNE_ATTR_GENERIC:
107             return getGenericParametersStr();
108         default:
109             throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
110     }
111 }
112 
113 
114 void
setAttribute(SumoXMLAttr key,const std::string & value,GNEUndoList * undoList)115 GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
116     if (value == getAttribute(key)) {
117         return; //avoid needless changes, later logic relies on the fact that attributes have changed
118     }
119     switch (key) {
120         case SUMO_ATTR_ID:
121         case SUMO_ATTR_EDGE:
122         case SUMO_ATTR_ALLOW:
123         case SUMO_ATTR_DISALLOW:
124         case GNE_ATTR_GENERIC:
125             undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
126             break;
127         default:
128             throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
129     }
130 }
131 
132 
133 bool
isValid(SumoXMLAttr key,const std::string & value)134 GNEClosingReroute::isValid(SumoXMLAttr key, const std::string& value) {
135     switch (key) {
136         case SUMO_ATTR_ID:
137             return isValidAdditionalID(value);
138         case SUMO_ATTR_EDGE:
139             return (myViewNet->getNet()->retrieveEdge(value, false) != nullptr);
140         case SUMO_ATTR_ALLOW:
141             return canParseVehicleClasses(value);
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 GNEClosingReroute::getPopUpID() const {
154     return getTagStr();
155 }
156 
157 
158 std::string
getHierarchyName() const159 GNEClosingReroute::getHierarchyName() const {
160     return getTagStr() + ": " + myClosedEdge->getID();
161 }
162 
163 // ===========================================================================
164 // private
165 // ===========================================================================
166 
167 void
setAttribute(SumoXMLAttr key,const std::string & value)168 GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
169     switch (key) {
170         case SUMO_ATTR_ID:
171             changeAdditionalID(value);
172             break;
173         case SUMO_ATTR_EDGE:
174             myClosedEdge = myViewNet->getNet()->retrieveEdge(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