SUMO - Simulation of Urban MObility
GNEDialog_AllowDisallow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <iostream>
34 #include <utils/common/ToString.h>
37 
38 
39 // ===========================================================================
40 // FOX callback mapping
41 // ===========================================================================
42 
43 FXDEFMAP(GNEDialog_AllowDisallow) GNEDialog_AllowDisallowMap[] = {
51 };
52 
53 // Object implementation
54 FXIMPLEMENT(GNEDialog_AllowDisallow, FXDialogBox, GNEDialog_AllowDisallowMap, ARRAYNUMBER(GNEDialog_AllowDisallowMap))
55 
56 // ===========================================================================
57 // member method definitions
58 // ===========================================================================
59 
60 GNEDialog_AllowDisallow::GNEDialog_AllowDisallow(FXApp* app, std::string* allow) :
61  FXDialogBox(app, ("Edit allowed and disallowed " + toString(SUMO_ATTR_VCLASS) + "es").c_str(), GUIDesignDialogBox),
62  myAllow(allow),
63  myCopyOfAllow(*allow) {
64  // set vehicle icon for this dialog
66  // create main frame
67  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
68  // create groupbox for options
69  FXGroupBox* myGroupBoxOptions = new FXGroupBox(mainFrame, "Selection options", GUIDesignGroupBoxFrame);
70  FXHorizontalFrame* myOptionsFrame = new FXHorizontalFrame(myGroupBoxOptions, GUIDesignAuxiliarHorizontalFrame);
71  mySelectAllVClassButton = new FXButton(myOptionsFrame, "", GUIIconSubSys::getIcon(ICON_OK), this, MID_GNE_ALLOWDISALLOW_SELECTALL, GUIDesignButtonIcon);
72  new FXLabel(myOptionsFrame, "Select all vehicles", NULL, GUIDesignLabelLeftThick);
73  myUnselectAllVClassButton = new FXButton(myOptionsFrame, "", GUIIconSubSys::getIcon(ICON_OK), this, MID_GNE_ALLOWDISALLOW_UNSELECTALL, GUIDesignButtonIcon);
74  new FXLabel(myOptionsFrame, "Unselect all vehicles", NULL, GUIDesignLabelLeftThick);
75  mySelectOnlyNonRoadVClassButton = new FXButton(myOptionsFrame, "", GUIIconSubSys::getIcon(ICON_OK), this, MID_GNE_ALLOWDISALLOW_SELECTONLYNONROAD, GUIDesignButtonIcon);
76  new FXLabel(myOptionsFrame, "Select only non-road vehicles", NULL, GUIDesignLabelLeftThick);
77  // create groupbox for vehicles
78  FXGroupBox* myGroupBoxVehiclesFrame = new FXGroupBox(mainFrame, ("Select " + toString(SUMO_ATTR_VCLASS) + "es").c_str(), GUIDesignGroupBoxFrame);
79  // Create frame for vehicles's columns
80  FXHorizontalFrame* myVehiclesFrame = new FXHorizontalFrame(myGroupBoxVehiclesFrame, GUIDesignContentsFrame);
81  // create left frame and fill it
82  FXVerticalFrame* myContentLeftFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
83  buildVClass(myContentLeftFrame, SVC_PASSENGER, ICON_VCLASS_PASSENGER, "Default vehicle class");
84  buildVClass(myContentLeftFrame, SVC_TAXI, ICON_VCLASS_TAXI, "Vehicle for hire with a driver");
85  buildVClass(myContentLeftFrame, SVC_BUS, ICON_VCLASS_BUS, "Urban line traffic");
86  buildVClass(myContentLeftFrame, SVC_COACH, ICON_VCLASS_COACH, "Overland transport");
87  buildVClass(myContentLeftFrame, SVC_DELIVERY, ICON_VCLASS_DELIVERY, "Vehicles specialized to deliver goods");
88  buildVClass(myContentLeftFrame, SVC_TRUCK, ICON_VCLASS_TRUCK, "Vehicle designed to transport cargo");
89  buildVClass(myContentLeftFrame, SVC_TRAILER, ICON_VCLASS_TRAILER, "Truck with trailer");
90  buildVClass(myContentLeftFrame, SVC_EMERGENCY, ICON_VCLASS_EMERGENCY, "Vehicle designated to respond to an emergency");
91  // create center frame and fill it
92  FXVerticalFrame* myContentCenterFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
93  buildVClass(myContentCenterFrame, SVC_MOTORCYCLE, ICON_VCLASS_MOTORCYCLE, "Two- or three-wheeled motor vehicle");
94  buildVClass(myContentCenterFrame, SVC_MOPED, ICON_VCLASS_MOPED, "Motorcycle not allowed in motorways");
95  buildVClass(myContentCenterFrame, SVC_BICYCLE, ICON_VCLASS_BICYCLE, "Human-powered, pedal-driven vehicle");
96  buildVClass(myContentCenterFrame, SVC_PEDESTRIAN, ICON_VCLASS_PEDESTRIAN, "Person traveling on foot");
97  buildVClass(myContentCenterFrame, SVC_TRAM, ICON_VCLASS_TRAM, "Rail vehicle which runs on tracks");
98  buildVClass(myContentCenterFrame, SVC_RAIL_URBAN, ICON_VCLASS_RAIL_URBAN, "Heavier than tram");
99  buildVClass(myContentCenterFrame, SVC_RAIL, ICON_VCLASS_RAIL, "Heavy rail vehicle (ICE)");
100  buildVClass(myContentCenterFrame, SVC_RAIL_ELECTRIC, ICON_VCLASS_RAIL_ELECTRIC, "Rail electric vehicle (Trolleybus)");
101  buildVClass(myContentCenterFrame, SVC_SHIP, ICON_VCLASS_SHIP, "Basic class for navigating waterway");
102  buildVClass(myContentCenterFrame, SVC_E_VEHICLE, ICON_VCLASS_EVEHICLE, "Future electric mobility vehicles");
103  // create right frame and fill it (8 vehicles)
104  FXVerticalFrame* myContentRightFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
105  buildVClass(myContentRightFrame, SVC_PRIVATE, ICON_VCLASS_PRIVATE, "A passenger car assigned for private use");
106  buildVClass(myContentRightFrame, SVC_ARMY, ICON_VCLASS_ARMY, "Vehicle designed for military forces");
107  buildVClass(myContentRightFrame, SVC_AUTHORITY, ICON_VCLASS_AUTHORITY, "Vehicle of a governmental security agency");
108  buildVClass(myContentRightFrame, SVC_VIP, ICON_VCLASS_VIP, "A civilian security armored car used by VIPs");
109  buildVClass(myContentRightFrame, SVC_HOV, ICON_VCLASS_HOV, "High-Occupancy Vehicle (two or more passengers)");
110  buildVClass(myContentRightFrame, SVC_CUSTOM1, ICON_VCLASS_CUSTOM1, "Reserved for user-defined semantics");
111  buildVClass(myContentRightFrame, SVC_CUSTOM2, ICON_VCLASS_CUSTOM2, "Reserved for user-defined semantics");
112  // create dialog buttons bot centered
113  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
114  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
115  myAcceptButton = new FXButton(buttonsFrame, "accept\t\tclose", GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_GNE_MODE_ADDITIONALDIALOG_ACCEPT, GUIDesignButtonAccept);
116  myCancelButton = new FXButton(buttonsFrame, "cancel\t\tclose", GUIIconSubSys::getIcon(ICON_CANCEL), this, MID_GNE_MODE_ADDITIONALDIALOG_CANCEL, GUIDesignButtonCancel);
117  myResetButton = new FXButton(buttonsFrame, "reset\t\tclose", GUIIconSubSys::getIcon(ICON_RESET), this, MID_GNE_MODE_ADDITIONALDIALOG_RESET, GUIDesignButtonReset);
118  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
119  // reset dialog
120  onCmdReset(0, 0, 0);
121 }
122 
123 
125 }
126 
127 
128 long
129 GNEDialog_AllowDisallow::onCmdValueChanged(FXObject* obj, FXSelector, void*) {
130  FXButton* buttonPressed = dynamic_cast<FXButton*>(obj);
131  // change icon of button
132  for (std::map<SUMOVehicleClass, std::pair<FXButton*, FXLabel*> >::iterator i = myVClassMap.begin(); i != myVClassMap.end(); i++) {
133  if (i->second.first == buttonPressed) {
134  if (buttonPressed->getIcon() == GUIIconSubSys::getIcon(ICON_ACCEPT)) {
135  buttonPressed->setIcon(GUIIconSubSys::getIcon(ICON_CANCEL));
136  } else {
137  buttonPressed->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
138  }
139  return 1;
140  }
141  }
142  return 1;
143 }
144 
145 
146 long
147 GNEDialog_AllowDisallow::onCmdSelectAll(FXObject*, FXSelector, void*) {
148  // change all icons to accept
149  for (std::map<SUMOVehicleClass, std::pair<FXButton*, FXLabel*> >::iterator i = myVClassMap.begin(); i != myVClassMap.end(); i++) {
150  i->second.first->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
151  }
152  return 1;
153 }
154 
155 
156 long
157 GNEDialog_AllowDisallow::onCmdUnselectAll(FXObject*, FXSelector, void*) {
158  // change all icons to cancel
159  for (std::map<SUMOVehicleClass, std::pair<FXButton*, FXLabel*> >::iterator i = myVClassMap.begin(); i != myVClassMap.end(); i++) {
160  i->second.first->setIcon(GUIIconSubSys::getIcon(ICON_CANCEL));
161  }
162  return 1;
163 }
164 
165 
166 long
167 GNEDialog_AllowDisallow::onCmdSelectOnlyNonRoad(FXObject*, FXSelector, void*) {
168  // change all non-road icons to accept, and to cancel for the rest
169  for (std::map<SUMOVehicleClass, std::pair<FXButton*, FXLabel*> >::iterator i = myVClassMap.begin(); i != myVClassMap.end(); i++) {
170  if ((i->first == SVC_TRAM) || (i->first == SVC_RAIL) || (i->first == SVC_RAIL_URBAN) || (i->first == SVC_RAIL_ELECTRIC) || (i->first == SVC_SHIP)) {
171  i->second.first->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
172  } else {
173  i->second.first->setIcon(GUIIconSubSys::getIcon(ICON_CANCEL));
174  }
175  }
176  return 1;
177 }
178 
179 
180 long
181 GNEDialog_AllowDisallow::onCmdAccept(FXObject*, FXSelector, void*) {
182  // clear allow and disallow VClasses
183  std::vector<std::string> allowedVehicles;
184  for (std::map<SUMOVehicleClass, std::pair<FXButton*, FXLabel*> >::iterator i = myVClassMap.begin(); i != myVClassMap.end(); i++) {
185  // check if vehicle is alloweddepending of the Icon
186  if (i->second.first->getIcon() == GUIIconSubSys::getIcon(ICON_ACCEPT)) {
187  allowedVehicles.push_back(getVehicleClassNames(i->first));
188  }
189  }
190  // chek if all vehicles are enabled and set new allowed vehicles
191  if (allowedVehicles.size() == 25) {
192  (*myAllow) = "all";
193  } else {
194  (*myAllow) = joinToString(allowedVehicles, " ");
195  }
196  // Stop Modal
197  getApp()->stopModal(this, TRUE);
198  return 1;
199 }
200 
201 
202 long
203 GNEDialog_AllowDisallow::onCmdCancel(FXObject*, FXSelector, void*) {
204  // Stop Modal
205  getApp()->stopModal(this, FALSE);
206  return 1;
207 }
208 
209 
210 long
211 GNEDialog_AllowDisallow::onCmdReset(FXObject*, FXSelector, void*) {
212  // clear allow and disallow VClasses
213  std::vector<std::string> allowStringVector;
215  // iterate over myVClassMap and set icons
216  for (std::map<SUMOVehicleClass, std::pair<FXButton*, FXLabel*> >::iterator i = myVClassMap.begin(); i != myVClassMap.end(); i++) {
217  if (std::find(allowStringVector.begin(), allowStringVector.end(), getVehicleClassNames(i->first)) != allowStringVector.end()) {
218  i->second.first->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
219  i->second.second->setText((getVehicleClassNames(i->first) + " allowed").c_str());
220  } else {
221  i->second.first->setIcon(GUIIconSubSys::getIcon(ICON_CANCEL));
222  i->second.second->setText((getVehicleClassNames(i->first) + " disallowed").c_str());
223  }
224  }
225  return 1;
226 }
227 
228 
229 void
230 GNEDialog_AllowDisallow::buildVClass(FXVerticalFrame* contentsFrame, SUMOVehicleClass vclass, GUIIcon icon, const std::string& description) {
231  // add frame for vehicle icons
232  FXHorizontalFrame* vehicleFrame = new FXHorizontalFrame(contentsFrame, GUIDesignAuxiliarHorizontalFrame);
233  FXLabel* labelVehicleIcon = new FXLabel(vehicleFrame, "", GUIIconSubSys::getIcon(icon), GUIDesignLabelIcon64x32Thicked);
234  labelVehicleIcon->setBackColor(FXRGBA(255, 255, 255, 255));
235  // create frame for information and button
236  FXVerticalFrame* buttonAndInformationFrame = new FXVerticalFrame(vehicleFrame, GUIDesignAuxiliarHorizontalFrame);
237  FXHorizontalFrame* buttonAndStatusFrame = new FXHorizontalFrame(buttonAndInformationFrame, GUIDesignAuxiliarHorizontalFrame);
238  // create status and text button
239  myVClassMap[vclass].first = new FXButton(buttonAndStatusFrame, "", GUIIconSubSys::getIcon(ICON_EMPTY), this, MID_GNE_ALLOWDISALLOW_CHANGE, GUIDesignButtonIcon);
240  myVClassMap[vclass].second = new FXLabel(buttonAndStatusFrame, "status", NULL, GUIDesignLabelLeftThick);
241  // create label for description of vehicle
242  new FXLabel(buttonAndInformationFrame, description.c_str(), 0, GUIDesignLabelLeftThick);
243 }
244 
245 /****************************************************************************/
long onCmdSelectOnlyNonRoad(FXObject *, FXSelector, void *)
event when user press select only non road button
std::string getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a &#39; &#39;.
vehicle is a motorcycle
vehicle is a coach
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:204
is a pedestrian
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
vehicle is a not electrified rail
vehicle is a bicycle
vehicle is a small delivery vehicle
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:253
vehicle is a light rail
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:104
long onCmdSelectAll(FXObject *, FXSelector, void *)
event when user press select all VClasses button
vehicle is a HOV
vehicle is a (possibly fast moving) electric rail
allowDisallow dialog
Definition: GUIAppEnum.h:508
authorities vehicles
vehicle is a city rail
vehicle is a large transport vehicle
is a user-defined type
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
static void parseStringVector(const std::string &def, std::vector< std::string > &into)
Splits the given string.
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:241
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
#define GUIDesignLabelIcon64x32Thicked
label ticked filled used for VClasses. It uses icons of 64x32 pixels
Definition: GUIDesigns.h:174
army vehicles
private vehicles
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:244
void buildVClass(FXVerticalFrame *contentsFrame, SUMOVehicleClass vclass, GUIIcon icon, const std::string &description)
build VClass
#define GUIDesignButtonReset
Reset Button.
Definition: GUIDesigns.h:107
long onCmdUnselectAll(FXObject *, FXSelector, void *)
event when user press unselect all VClasses button
Dialog for edit rerouters.
vehicle is a passenger car (a "normal" car)
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:101
#define GUIDesignButtonIcon
button only with icon (23x23)
Definition: GUIDesigns.h:66
is an arbitrary ship
std::string myCopyOfAllow
copy of current allowed vehicles
vehicle is a moped
vehicle is a taxi
vehicle is a bus
#define GUIDesignDialogBox
Definition: GUIDesigns.h:393
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:219
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
vip vehicles
vehicle is a large transport vehicle
FXDEFMAP(GNEDialog_AllowDisallow) GNEDialog_AllowDisallowMap[]
public emergency vehicles
std::map< SUMOVehicleClass, std::pair< FXButton *, FXLabel * > > myVClassMap
map with the buttons for every VClass
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
#define GUIDesignLabelLeftThick
label extended over frame with thick and with text justify to left
Definition: GUIDesigns.h:156
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:228
long onCmdValueChanged(FXObject *, FXSelector, void *)
is a user-defined type
is an electric vehicle