Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEAllowVClassesDialog.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Dialog for edit allow VClass attribute
19/****************************************************************************/
20
21#include <netedit/GNEViewNet.h>
26
28
29
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
45
46// Object implementation
47FXIMPLEMENT(GNEAllowVClassesDialog, FXDialogBox, GNEAllowVClassesDialogMap, ARRAYNUMBER(GNEAllowVClassesDialogMap))
48
49// ===========================================================================
50// member method definitions
51// ===========================================================================
52
53GNEAllowVClassesDialog::GNEAllowVClassesDialog(GNEViewNet* viewNet, SumoXMLAttr attr, std::string* allow, bool* acceptChanges) :
54 FXDialogBox(viewNet->getApp(), TLF("Edit vClasses of attribute '%'", toString(attr)).c_str(), GUIDesignDialogBox),
55 myViewNet(viewNet),
56 myEditedAttr(SUMO_ATTR_ALLOW),
57 myAcceptChanges(acceptChanges),
58 myAllow(allow) {
59 // call constructor
60 constructor();
61}
62
63
66
67
68long
69GNEAllowVClassesDialog::onCmdValueChanged(FXObject* obj, FXSelector, void*) {
70 FXButton* buttonPressed = dynamic_cast<FXButton*>(obj);
71 // change icon of button
72 for (const auto& vClass : myVClassMap) {
73 if (vClass.second.first == buttonPressed) {
74 if (buttonPressed->getIcon() == GUIIconSubSys::getIcon(GUIIcon::ACCEPT)) {
75 buttonPressed->setIcon(GUIIconSubSys::getIcon(GUIIcon::CANCEL));
76 } else {
77 buttonPressed->setIcon(GUIIconSubSys::getIcon(GUIIcon::ACCEPT));
78 }
79 return 1;
80 }
81 }
82 return 1;
83}
84
85
86long
87GNEAllowVClassesDialog::onCmdSelectAll(FXObject*, FXSelector, void*) {
88 // change all icons to accept
89 for (const auto& vClass : myVClassMap) {
90 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::ACCEPT));
91 }
92 return 1;
93}
94
95
96long
97GNEAllowVClassesDialog::onCmdUnselectAll(FXObject*, FXSelector, void*) {
98 // change all icons to cancel
99 for (const auto& vClass : myVClassMap) {
100 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::CANCEL));
101 }
102 return 1;
103}
104
105
106long
107GNEAllowVClassesDialog::onCmdSelectOnlyRoad(FXObject*, FXSelector, void*) {
108 // change all non-road icons to disallow, and allow for the rest
109 for (const auto& vClass : myVClassMap) {
110 if ((vClass.first & (SVC_PEDESTRIAN | SVC_NON_ROAD)) == 0) {
111 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::ACCEPT));
112 } else {
113 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::CANCEL));
114 }
115 }
116 return 1;
117}
118
119
120long
121GNEAllowVClassesDialog::onCmdSelectOnlyRail(FXObject*, FXSelector, void*) {
122 // change all non-road icons to disallow, and allow for the rest
123 for (const auto& vClass : myVClassMap) {
124 if ((vClass.first & SVC_RAIL_CLASSES) != 0) {
125 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::ACCEPT));
126 } else {
127 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::CANCEL));
128 }
129 }
130 return 1;
131}
132
133
134long
135GNEAllowVClassesDialog::onCmdAccept(FXObject*, FXSelector, void*) {
136 // clear allow and disallow VClasses
137 std::vector<std::string> allowedVehicles;
138 for (const auto& vClass : myVClassMap) {
139 // check if vehicle is allowed depending on the Icon
140 if (vClass.second.first->getIcon() == GUIIconSubSys::getIcon(GUIIcon::ACCEPT)) {
141 allowedVehicles.push_back(getVehicleClassNames(vClass.first));
142 }
143 }
144 const auto newAllow = joinToString(allowedVehicles, " ");
145 // only mark as accepted changes if the new vehicles are differents
146 if (newAllow != *myAllow) {
147 // check if all vehicles are enabled and set new allowed vehicles
148 *myAllow = joinToString(allowedVehicles, " ");
149 // enable accept flag
150 *myAcceptChanges = true;
151 }
152 // Stop Modal
153 getApp()->stopModal(this, TRUE);
154 return 1;
155}
156
157
158long
159GNEAllowVClassesDialog::onCmdCancel(FXObject*, FXSelector, void*) {
160 // disable accept flag
161 *myAcceptChanges = false;
162 // Stop Modal
163 getApp()->stopModal(this, FALSE);
164 return 1;
165}
166
167
168long
169GNEAllowVClassesDialog::onCmdReset(FXObject*, FXSelector, void*) {
170 // continue depending of allow
171 if (*myAllow == "all") {
172 // iterate over myVClassMap and set all icons as true
173 for (const auto& vClass : myVClassMap) {
174 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::ACCEPT));
175 }
176 } else {
177 // declare string vector for saving all vclasses
178 const std::vector<std::string>& allowStringVector = StringTokenizer(*myAllow).getVector();
179 const std::set<std::string> allowSet(allowStringVector.begin(), allowStringVector.end());
180 // iterate over myVClassMap and set icons
181 for (const auto& vClass : myVClassMap) {
182 if (allowSet.count(getVehicleClassNames(vClass.first)) > 0) {
183 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::ACCEPT));
184 } else {
185 vClass.second.first->setIcon(GUIIconSubSys::getIcon(GUIIcon::CANCEL));
186 }
187 }
188 }
189 return 1;
190}
191
192
193void
195 // set vehicle icon for this dialog
197 // create main frame
198 FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
199 // create groupbox for options
200 FXGroupBox* myGroupBoxOptions = new FXGroupBox(mainFrame, TL("Selection options"), GUIDesignGroupBoxFrame);
201 FXHorizontalFrame* myOptionsFrame = new FXHorizontalFrame(myGroupBoxOptions, GUIDesignAuxiliarHorizontalFrame);
202 // allow all
204 new FXLabel(myOptionsFrame, TL("Allow all vehicles"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
205 // only road
207 new FXLabel(myOptionsFrame, TL("Allow only road vehicles"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
208 // only rail
210 new FXLabel(myOptionsFrame, TL("Allow only rail vehicles"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
211 // disallow all
213 new FXLabel(myOptionsFrame, TL("Disallow all vehicles"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
214 // create groupbox for vehicles
215 FXGroupBox* myGroupBoxVehiclesFrame = new FXGroupBox(mainFrame, ("Select " + toString(SUMO_ATTR_VCLASS) + "es").c_str(), GUIDesignGroupBoxFrame);
216 // Create frame for vehicles's columns
217 FXHorizontalFrame* myVehiclesFrame = new FXHorizontalFrame(myGroupBoxVehiclesFrame, GUIDesignContentsFrame);
218 // create left frame and fill it
219 FXVerticalFrame* myContentLeftFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
220 buildVClass(myContentLeftFrame, SVC_PASSENGER, GUIIcon::VCLASS_PASSENGER, TL("Default vehicle class"));
221 buildVClass(myContentLeftFrame, SVC_PRIVATE, GUIIcon::VCLASS_PRIVATE, TL("A passenger car assigned for private use"));
222 buildVClass(myContentLeftFrame, SVC_TAXI, GUIIcon::VCLASS_TAXI, TL("Vehicle for hire with a driver"));
223 buildVClass(myContentLeftFrame, SVC_BUS, GUIIcon::VCLASS_BUS, TL("Urban line traffic"));
224 buildVClass(myContentLeftFrame, SVC_COACH, GUIIcon::VCLASS_COACH, TL("Overland transport"));
225 buildVClass(myContentLeftFrame, SVC_DELIVERY, GUIIcon::VCLASS_DELIVERY, TL("Vehicles specialized in delivering goods"));
226 buildVClass(myContentLeftFrame, SVC_TRUCK, GUIIcon::VCLASS_TRUCK, TL("Vehicle designed to transport cargo"));
227 buildVClass(myContentLeftFrame, SVC_TRAILER, GUIIcon::VCLASS_TRAILER, TL("Truck with trailer"));
228 buildVClass(myContentLeftFrame, SVC_EMERGENCY, GUIIcon::VCLASS_EMERGENCY, TL("Vehicle designated to respond to an emergency"));
229 buildVClass(myContentLeftFrame, SVC_MOTORCYCLE, GUIIcon::VCLASS_MOTORCYCLE, TL("Two- or three-wheeled motor vehicle"));
230 buildVClass(myContentLeftFrame, SVC_MOPED, GUIIcon::VCLASS_MOPED, TL("Motorcycle not allowed in motorways"));
231 // create center frame and fill it
232 FXVerticalFrame* myContentCenterFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
233 buildVClass(myContentCenterFrame, SVC_BICYCLE, GUIIcon::VCLASS_BICYCLE, TL("Human-powered, pedal-driven vehicle"));
234 buildVClass(myContentCenterFrame, SVC_SCOOTER, GUIIcon::VCLASS_SCOOTER, TL("An electric scooter or a kick scooter"));
235 buildVClass(myContentCenterFrame, SVC_PEDESTRIAN, GUIIcon::VCLASS_PEDESTRIAN, TL("Person traveling on foot"));
236 buildVClass(myContentCenterFrame, SVC_WHEELCHAIR, GUIIcon::VCLASS_WHEELCHAIR, TL("A mobility impaired person"));
237 buildVClass(myContentCenterFrame, SVC_TRAM, GUIIcon::VCLASS_TRAM, TL("Rail vehicle which runs on tracks"));
238 buildVClass(myContentCenterFrame, SVC_RAIL_ELECTRIC, GUIIcon::VCLASS_RAIL_ELECTRIC, TL("Rail electric vehicle"));
239 buildVClass(myContentCenterFrame, SVC_RAIL_FAST, GUIIcon::VCLASS_RAIL_FAST, TL("High-speed rail vehicle"));
240 buildVClass(myContentCenterFrame, SVC_RAIL_URBAN, GUIIcon::VCLASS_RAIL_URBAN, TL("Heavier than tram"));
241 buildVClass(myContentCenterFrame, SVC_RAIL, GUIIcon::VCLASS_RAIL, TL("Heavy rail vehicle"));
242 buildVClass(myContentCenterFrame, SVC_CABLE_CAR, GUIIcon::VCLASS_CABLE_CAR, TL("A conveyance suspended on a cable"));
243 buildVClass(myContentCenterFrame, SVC_SUBWAY, GUIIcon::VCLASS_SUBWAY, TL("A railway that mostly runs underground"));
244 // create right frame and fill it (8 vehicles)
245 FXVerticalFrame* myContentRightFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
246 buildVClass(myContentRightFrame, SVC_E_VEHICLE, GUIIcon::VCLASS_EVEHICLE, TL("Future electric mobility vehicles"));
247 buildVClass(myContentRightFrame, SVC_ARMY, GUIIcon::VCLASS_ARMY, TL("Vehicle designed for military forces"));
248 buildVClass(myContentRightFrame, SVC_SHIP, GUIIcon::VCLASS_SHIP, TL("Basic class for navigating waterway"));
249 buildVClass(myContentRightFrame, SVC_AUTHORITY, GUIIcon::VCLASS_AUTHORITY, TL("Vehicle of a governmental security agency"));
250 buildVClass(myContentRightFrame, SVC_VIP, GUIIcon::VCLASS_VIP, TL("A civilian security armored car used by VIPs"));
251 buildVClass(myContentRightFrame, SVC_HOV, GUIIcon::VCLASS_HOV, TL("High-Occupancy Vehicle (two or more passengers)"));
252 buildVClass(myContentRightFrame, SVC_CONTAINER, GUIIcon::VCLASS_CONTAINER, TL("A transport container"));
253 buildVClass(myContentRightFrame, SVC_AIRCRAFT, GUIIcon::VCLASS_AIRCRAFT, TL("An airplane"));
254 buildVClass(myContentRightFrame, SVC_DRONE, GUIIcon::VCLASS_DRONE, TL("A small unmanned robot"));
255 buildVClass(myContentRightFrame, SVC_CUSTOM1, GUIIcon::VCLASS_CUSTOM1, TL("Reserved for user-defined semantics"));
256 buildVClass(myContentRightFrame, SVC_CUSTOM2, GUIIcon::VCLASS_CUSTOM2, TL("Reserved for user-defined semantics"));
257 // create dialog buttons bot centered
258 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
259 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
263 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
264 // reset dialog
265 onCmdReset(nullptr, 0, nullptr);
266}
267
268
269void
270GNEAllowVClassesDialog::buildVClass(FXVerticalFrame* contentsFrame, SUMOVehicleClass vclass, GUIIcon vclassIcon, const std::string& description) {
271 // add frame for vehicle icons
272 FXHorizontalFrame* vehicleFrame = new FXHorizontalFrame(contentsFrame, GUIDesignAuxiliarHorizontalFrame);
273 FXLabel* labelVehicleIcon = new FXLabel(vehicleFrame, "", GUIIconSubSys::getIcon(vclassIcon), GUIDesignLabelIcon64x32Thicked);
274 labelVehicleIcon->setBackColor(FXRGBA(255, 255, 255, 255));
275 // create frame for information and button
276 FXVerticalFrame* buttonAndInformationFrame = new FXVerticalFrame(vehicleFrame, GUIDesignAuxiliarHorizontalFrame);
277 FXHorizontalFrame* buttonAndStatusFrame = new FXHorizontalFrame(buttonAndInformationFrame, GUIDesignAuxiliarHorizontalFrame);
278 // create status and text button
280 myVClassMap[vclass].second = new FXLabel(buttonAndStatusFrame, toString(vclass).c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
281 // create label for description of vehicle
282 new FXLabel(buttonAndInformationFrame, description.c_str(), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));
283}
284
285
286/****************************************************************************/
FXDEFMAP(GNEAllowVClassesDialog) GNEAllowVClassesDialogMap[]
@ MID_GNE_ALLOWDISALLOW_CHANGE
select/unselect single vehicle
@ MID_GNE_BUTTON_CANCEL
cancel button
@ MID_GNE_BUTTON_RESET
reset button
@ MID_GNE_ALLOWDISALLOW_ONLY_ROAD
select only non road vehicles
@ MID_GNE_ALLOWDISALLOW_ONLY_RAIL
select only rail vehicles
@ MID_GNE_ALLOWDISALLOW_UNSELECTALL
unselect all vehicles
@ MID_GNE_ALLOWDISALLOW_SELECTALL
select all vehicles
@ MID_GNE_BUTTON_ACCEPT
accept button
#define GUIDesignButtonIcon
button only with icon
Definition GUIDesigns.h:91
#define GUIDesignLabelIcon64x32Thicked
label ticked filled used for VClasses. It uses icons of 64x32 pixels
Definition GUIDesigns.h:270
#define GUIDesignButtonAccept
Accept Button.
Definition GUIDesigns.h:156
#define GUIDesignButtonCancel
Cancel Button.
Definition GUIDesigns.h:162
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog with padding and spacing
Definition GUIDesigns.h:387
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignDialogBox
Definition GUIDesigns.h:599
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition GUIDesigns.h:346
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:249
#define GUIDesignButtonReset
Reset Button.
Definition GUIDesigns.h:165
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:390
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition GUIDesigns.h:328
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ VCLASS_TRAILER
@ VCLASS_PASSENGER
@ VCLASS_BICYCLE
@ VCLASS_RAIL_FAST
@ VCLASS_AIRCRAFT
@ VCLASS_CUSTOM2
@ GREENVEHICLE
@ VCLASS_MOTORCYCLE
@ VCLASS_COACH
@ VCLASS_AUTHORITY
@ VCLASS_SCOOTER
@ VCLASS_TRUCK
@ VCLASS_MOPED
@ VCLASS_PEDESTRIAN
@ VCLASS_PRIVATE
@ VCLASS_CABLE_CAR
@ VCLASS_SUBWAY
@ VCLASS_CONTAINER
@ VCLASS_CUSTOM1
@ VCLASS_DELIVERY
@ VCLASS_DRONE
@ VCLASS_RAIL_ELECTRIC
@ VCLASS_WHEELCHAIR
@ VCLASS_EMERGENCY
@ VCLASS_RAIL_URBAN
@ VCLASS_EVEHICLE
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a ' '.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_SHIP
is an arbitrary ship
@ SVC_PRIVATE
private vehicles
@ SVC_VIP
vip vehicles
@ SVC_HOV
vehicle is a HOV
@ SVC_TRUCK
vehicle is a large transport vehicle
@ SVC_CUSTOM2
is a user-defined type
@ SVC_WHEELCHAIR
@ SVC_RAIL
vehicle is a not electrified rail
@ SVC_RAIL_CLASSES
classes which drive on tracks
@ SVC_COACH
vehicle is a coach
@ SVC_CABLE_CAR
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_CONTAINER
@ SVC_SCOOTER
@ SVC_RAIL_FAST
vehicle that is allowed to drive on high-speed rail tracks
@ SVC_TRAILER
vehicle is a large transport vehicle
@ SVC_CUSTOM1
is a user-defined type
@ SVC_ARMY
army vehicles
@ SVC_DRONE
@ SVC_RAIL_ELECTRIC
rail vehicle that requires electrified tracks
@ SVC_NON_ROAD
classes which (normally) do not drive on normal roads
@ SVC_DELIVERY
vehicle is a small delivery vehicle
@ SVC_RAIL_URBAN
vehicle is a city rail
@ SVC_MOTORCYCLE
vehicle is a motorcycle
@ SVC_EMERGENCY
public emergency vehicles
@ SVC_MOPED
vehicle is a moped
@ SVC_AUTHORITY
authorities vehicles
@ SVC_TRAM
vehicle is a light rail
@ SVC_TAXI
vehicle is a taxi
@ SVC_BUS
vehicle is a bus
@ SVC_E_VEHICLE
is an electric vehicle
@ SVC_AIRCRAFT
@ SVC_SUBWAY
@ SVC_PEDESTRIAN
pedestrian
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_VCLASS
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:283
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
Dialog for edit rerouters.
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
FXButton * myResetButton
cancel button
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
long onCmdSelectOnlyRail(FXObject *, FXSelector, void *)
event when user press select only rail button
void buildVClass(FXVerticalFrame *contentsFrame, SUMOVehicleClass vclass, GUIIcon vclassIcon, const std::string &description)
build VClass
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
FXButton * myKeepOldButton
accept button
FXButton * myCancelButton
cancel button
bool * myAcceptChanges
reference for mark that the new set of VClasses was accepted
std::map< SUMOVehicleClass, std::pair< FXButton *, FXLabel * > > myVClassMap
map with the buttons for every VClass
std::string * myAllow
reference to allow vehicles. Will be modified with the new allowed vehicles
long onCmdUnselectAll(FXObject *, FXSelector, void *)
event when user press unselect all VClasses button
long onCmdSelectOnlyRoad(FXObject *, FXSelector, void *)
event when user press select only road button
long onCmdValueChanged(FXObject *, FXSelector, void *)
long onCmdSelectAll(FXObject *, FXSelector, void *)
event when user press select all VClasses button
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
std::vector< std::string > getVector()
return vector of strings
Definition json.hpp:4471