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