Eclipse 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-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 /****************************************************************************/
15 // Dialog for edit rerouters
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
27 #include <netedit/GNEViewNet.h>
28 
30 
31 
32 
33 // ===========================================================================
34 // FOX callback mapping
35 // ===========================================================================
36 
37 FXDEFMAP(GNEDialog_AllowDisallow) GNEDialog_AllowDisallowMap[] = {
45 };
46 
47 // Object implementation
48 FXIMPLEMENT(GNEDialog_AllowDisallow, FXDialogBox, GNEDialog_AllowDisallowMap, ARRAYNUMBER(GNEDialog_AllowDisallowMap))
49 
50 // ===========================================================================
51 // member method definitions
52 // ===========================================================================
53 
55  FXDialogBox(viewNet->getApp(), ("Edit " + toString(SUMO_ATTR_ALLOW) + " " + toString(SUMO_ATTR_VCLASS) + "es").c_str(), GUIDesignDialogBox),
56  myViewNet(viewNet),
57  myAC(AC) {
58  assert(AC->getTagProperty().hasAttribute(SUMO_ATTR_ALLOW));
59  // set vehicle icon for this dialog
61  // create main frame
62  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
63  // create groupbox for options
64  FXGroupBox* myGroupBoxOptions = new FXGroupBox(mainFrame, "Selection options", GUIDesignGroupBoxFrame);
65  FXHorizontalFrame* myOptionsFrame = new FXHorizontalFrame(myGroupBoxOptions, GUIDesignAuxiliarHorizontalFrame);
66  mySelectAllVClassButton = new FXButton(myOptionsFrame, "", GUIIconSubSys::getIcon(ICON_OK), this, MID_GNE_ALLOWDISALLOW_SELECTALL, GUIDesignButtonIcon);
67  new FXLabel(myOptionsFrame, "Allow all vehicles", nullptr, GUIDesignLabelLeftThick);
68  mySelectOnlyRoadVClassButton = new FXButton(myOptionsFrame, "", GUIIconSubSys::getIcon(ICON_OK), this, MID_GNE_ALLOWDISALLOW_SELECTONLYROAD, GUIDesignButtonIcon);
69  new FXLabel(myOptionsFrame, "Allow only road vehicles", nullptr, GUIDesignLabelLeftThick);
70  myUnselectAllVClassButton = new FXButton(myOptionsFrame, "", GUIIconSubSys::getIcon(ICON_CANCEL), this, MID_GNE_ALLOWDISALLOW_UNSELECTALL, GUIDesignButtonIcon);
71  new FXLabel(myOptionsFrame, "Disallow all vehicles", nullptr, GUIDesignLabelLeftThick);
72  // create groupbox for vehicles
73  FXGroupBox* myGroupBoxVehiclesFrame = new FXGroupBox(mainFrame, ("Select " + toString(SUMO_ATTR_VCLASS) + "es").c_str(), GUIDesignGroupBoxFrame);
74  // Create frame for vehicles's columns
75  FXHorizontalFrame* myVehiclesFrame = new FXHorizontalFrame(myGroupBoxVehiclesFrame, GUIDesignContentsFrame);
76  // create left frame and fill it
77  FXVerticalFrame* myContentLeftFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
78  buildVClass(myContentLeftFrame, SVC_PASSENGER, ICON_VCLASS_PASSENGER, "Default vehicle class");
79  buildVClass(myContentLeftFrame, SVC_PRIVATE, ICON_VCLASS_PRIVATE, "A passenger car assigned for private use");
80  buildVClass(myContentLeftFrame, SVC_TAXI, ICON_VCLASS_TAXI, "Vehicle for hire with a driver");
81  buildVClass(myContentLeftFrame, SVC_BUS, ICON_VCLASS_BUS, "Urban line traffic");
82  buildVClass(myContentLeftFrame, SVC_COACH, ICON_VCLASS_COACH, "Overland transport");
83  buildVClass(myContentLeftFrame, SVC_DELIVERY, ICON_VCLASS_DELIVERY, "Vehicles specialized to deliver goods");
84  buildVClass(myContentLeftFrame, SVC_TRUCK, ICON_VCLASS_TRUCK, "Vehicle designed to transport cargo");
85  buildVClass(myContentLeftFrame, SVC_TRAILER, ICON_VCLASS_TRAILER, "Truck with trailer");
86  buildVClass(myContentLeftFrame, SVC_EMERGENCY, ICON_VCLASS_EMERGENCY, "Vehicle designated to respond to an emergency");
87  // create center frame and fill it
88  FXVerticalFrame* myContentCenterFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
89  buildVClass(myContentCenterFrame, SVC_MOTORCYCLE, ICON_VCLASS_MOTORCYCLE, "Two- or three-wheeled motor vehicle");
90  buildVClass(myContentCenterFrame, SVC_MOPED, ICON_VCLASS_MOPED, "Motorcycle not allowed in motorways");
91  buildVClass(myContentCenterFrame, SVC_BICYCLE, ICON_VCLASS_BICYCLE, "Human-powered, pedal-driven vehicle");
92  buildVClass(myContentCenterFrame, SVC_PEDESTRIAN, ICON_VCLASS_PEDESTRIAN, "Person traveling on foot");
93  buildVClass(myContentCenterFrame, SVC_TRAM, ICON_VCLASS_TRAM, "Rail vehicle which runs on tracks");
94  buildVClass(myContentCenterFrame, SVC_RAIL_ELECTRIC, ICON_VCLASS_RAIL_ELECTRIC, "Rail electric vehicle");
95  buildVClass(myContentCenterFrame, SVC_RAIL_FAST, ICON_VCLASS_RAIL_ELECTRIC, "High-speed rail vehicle");
96  buildVClass(myContentCenterFrame, SVC_RAIL_URBAN, ICON_VCLASS_RAIL_URBAN, "Heavier than tram");
97  buildVClass(myContentCenterFrame, SVC_RAIL, ICON_VCLASS_RAIL, "Heavy rail vehicle");
98  // create right frame and fill it (8 vehicles)
99  FXVerticalFrame* myContentRightFrame = new FXVerticalFrame(myVehiclesFrame, GUIDesignAuxiliarFrame);
100  buildVClass(myContentRightFrame, SVC_E_VEHICLE, ICON_VCLASS_EVEHICLE, "Future electric mobility vehicles");
101  buildVClass(myContentRightFrame, SVC_ARMY, ICON_VCLASS_ARMY, "Vehicle designed for military forces");
102  buildVClass(myContentRightFrame, SVC_SHIP, ICON_VCLASS_SHIP, "Basic class for navigating waterway");
103  buildVClass(myContentRightFrame, SVC_AUTHORITY, ICON_VCLASS_AUTHORITY, "Vehicle of a governmental security agency");
104  buildVClass(myContentRightFrame, SVC_VIP, ICON_VCLASS_VIP, "A civilian security armored car used by VIPs");
105  buildVClass(myContentRightFrame, SVC_HOV, ICON_VCLASS_HOV, "High-Occupancy Vehicle (two or more passengers)");
106  buildVClass(myContentRightFrame, SVC_CUSTOM1, ICON_VCLASS_CUSTOM1, "Reserved for user-defined semantics");
107  buildVClass(myContentRightFrame, SVC_CUSTOM2, ICON_VCLASS_CUSTOM2, "Reserved for user-defined semantics");
108  // create dialog buttons bot centered
109  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
110  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
111  myAcceptButton = new FXButton(buttonsFrame, "accept\t\tclose", GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_GNE_ADDITIONALDIALOG_BUTTONACCEPT, GUIDesignButtonAccept);
112  myCancelButton = new FXButton(buttonsFrame, "cancel\t\tclose", GUIIconSubSys::getIcon(ICON_CANCEL), this, MID_GNE_ADDITIONALDIALOG_BUTTONCANCEL, GUIDesignButtonCancel);
113  myResetButton = new FXButton(buttonsFrame, "reset\t\tclose", GUIIconSubSys::getIcon(ICON_RESET), this, MID_GNE_ADDITIONALDIALOG_BUTTONRESET, GUIDesignButtonReset);
114  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
115  // reset dialog
116  onCmdReset(nullptr, 0, nullptr);
117 }
118 
119 
121 }
122 
123 
124 long
125 GNEDialog_AllowDisallow::onCmdValueChanged(FXObject* obj, FXSelector, void*) {
126  FXButton* buttonPressed = dynamic_cast<FXButton*>(obj);
127  // change icon of button
128  for (auto i = myVClassMap.begin(); i != myVClassMap.end(); i++) {
129  if (i->second.first == buttonPressed) {
130  if (buttonPressed->getIcon() == GUIIconSubSys::getIcon(ICON_ACCEPT)) {
131  buttonPressed->setIcon(GUIIconSubSys::getIcon(ICON_CANCEL));
132  } else {
133  buttonPressed->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
134  }
135  return 1;
136  }
137  }
138  return 1;
139 }
140 
141 
142 long
143 GNEDialog_AllowDisallow::onCmdSelectAll(FXObject*, FXSelector, void*) {
144  // change all icons to accept
145  for (auto i : myVClassMap) {
146  i.second.first->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
147  }
148  return 1;
149 }
150 
151 
152 long
153 GNEDialog_AllowDisallow::onCmdUnselectAll(FXObject*, FXSelector, void*) {
154  // change all icons to cancel
155  for (auto i : myVClassMap) {
156  i.second.first->setIcon(GUIIconSubSys::getIcon(ICON_CANCEL));
157  }
158  return 1;
159 }
160 
161 
162 long
163 GNEDialog_AllowDisallow::onCmdSelectOnlyRoad(FXObject*, FXSelector, void*) {
164  // change all non-road icons to disallow, and allow for the rest
165  for (auto i : myVClassMap) {
166  if ((i.first & (SVC_PEDESTRIAN | SVC_NON_ROAD)) == 0) {
167  i.second.first->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
168  } else {
169  i.second.first->setIcon(GUIIconSubSys::getIcon(ICON_CANCEL));
170  }
171  }
172  return 1;
173 }
174 
175 
176 long
177 GNEDialog_AllowDisallow::onCmdAccept(FXObject*, FXSelector, void*) {
178  // clear allow and disallow VClasses
179  std::vector<std::string> allowedVehicles;
180  for (auto i : myVClassMap) {
181  // check if vehicle is alloweddepending of the Icon
182  if (i.second.first->getIcon() == GUIIconSubSys::getIcon(ICON_ACCEPT)) {
183  allowedVehicles.push_back(getVehicleClassNames(i.first));
184  }
185  }
186  // chek if all vehicles are enabled and set new allowed vehicles
187  myAC->setAttribute(SUMO_ATTR_ALLOW, joinToString(allowedVehicles, " "), myViewNet->getUndoList());
188  // Stop Modal
189  getApp()->stopModal(this, TRUE);
190  return 1;
191 }
192 
193 
194 long
195 GNEDialog_AllowDisallow::onCmdCancel(FXObject*, FXSelector, void*) {
196  // Stop Modal
197  getApp()->stopModal(this, FALSE);
198  return 1;
199 }
200 
201 
202 long
203 GNEDialog_AllowDisallow::onCmdReset(FXObject*, FXSelector, void*) {
204  if (myAC->getAttribute(SUMO_ATTR_ALLOW) == "all") {
205  // iterate over myVClassMap and set all icons as true
206  for (auto i : myVClassMap) {
207  i.second.first->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
208  }
209  } else {
210  // declare string vector for saving all vclasses
211  const std::vector<std::string>& allowStringVector = StringTokenizer(myAC->getAttribute(SUMO_ATTR_ALLOW)).getVector();
212  const std::set<std::string> allowSet(allowStringVector.begin(), allowStringVector.end());
213  // iterate over myVClassMap and set icons
214  for (auto i : myVClassMap) {
215  if (allowSet.count(getVehicleClassNames(i.first)) > 0) {
216  i.second.first->setIcon(GUIIconSubSys::getIcon(ICON_ACCEPT));
217  } else {
218  i.second.first->setIcon(GUIIconSubSys::getIcon(ICON_CANCEL));
219  }
220  }
221  }
222  return 1;
223 }
224 
225 
226 void
227 GNEDialog_AllowDisallow::buildVClass(FXVerticalFrame* contentsFrame, SUMOVehicleClass vclass, GUIIcon vclassIcon, const std::string& description) {
228  // add frame for vehicle icons
229  FXHorizontalFrame* vehicleFrame = new FXHorizontalFrame(contentsFrame, GUIDesignAuxiliarHorizontalFrame);
230  FXLabel* labelVehicleIcon = new FXLabel(vehicleFrame, "", GUIIconSubSys::getIcon(vclassIcon), GUIDesignLabelIcon64x32Thicked);
231  labelVehicleIcon->setBackColor(FXRGBA(255, 255, 255, 255));
232  // create frame for information and button
233  FXVerticalFrame* buttonAndInformationFrame = new FXVerticalFrame(vehicleFrame, GUIDesignAuxiliarHorizontalFrame);
234  FXHorizontalFrame* buttonAndStatusFrame = new FXHorizontalFrame(buttonAndInformationFrame, GUIDesignAuxiliarHorizontalFrame);
235  // create status and text button
236  myVClassMap[vclass].first = new FXButton(buttonAndStatusFrame, "", GUIIconSubSys::getIcon(ICON_EMPTY), this, MID_GNE_ALLOWDISALLOW_CHANGE, GUIDesignButtonIcon);
237  myVClassMap[vclass].second = new FXLabel(buttonAndStatusFrame, toString(vclass).c_str(), nullptr, GUIDesignLabelLeftThick);
238  // create label for description of vehicle
239  new FXLabel(buttonAndInformationFrame, description.c_str(), nullptr, GUIDesignLabelLeftThick);
240 }
241 
242 /****************************************************************************/
vehicle is a motorcycle
vehicle is a coach
GNEViewNet * myViewNet
to viewNet
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:240
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:36
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:1025
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:298
classes which (normally) do not drive on normal roads
vehicle is a light rail
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:120
long onCmdSelectAll(FXObject *, FXSelector, void *)
event when user press select all VClasses button
vehicle is a HOV
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
select only non road vehicles
Definition: GUIAppEnum.h:1027
long onCmdSelectOnlyRoad(FXObject *, FXSelector, void *)
event when user press select only road button
rail vehicle that requires electrified tracks
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
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:286
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
select all vehicles
Definition: GUIAppEnum.h:1023
#define GUIDesignLabelIcon64x32Thicked
label ticked filled used for VClasses. It uses icons of 64x32 pixels
Definition: GUIDesigns.h:201
army vehicles
private vehicles
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:289
#define GUIDesignButtonReset
Reset Button.
Definition: GUIDesigns.h:123
select/unselect single vehicle
Definition: GUIAppEnum.h:1021
long onCmdUnselectAll(FXObject *, FXSelector, void *)
event when user press unselect all VClasses button
GNEAttributeCarrier * myAC
edited AC
Dialog for edit rerouters.
vehicle is a passenger car (a "normal" car)
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:117
#define GUIDesignButtonIcon
button only with icon (23x23)
Definition: GUIDesigns.h:75
is an arbitrary ship
vehicle is a moped
vehicle is a taxi
vehicle is a bus
#define GUIDesignDialogBox
Definition: GUIDesigns.h:449
const std::string & getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a &#39; &#39;.
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:255
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
vehicle that is allowed to drive on high-speed rail tracks
#define GUIDesignLabelLeftThick
label extended over frame with thick and with text justify to left and height of 23 ...
Definition: GUIDesigns.h:177
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:247
long onCmdValueChanged(FXObject *, FXSelector, void *)
is a user-defined type
is an electric vehicle