Eclipse SUMO - Simulation of Urban MObility
GNEVehicleTypeFrame.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 // The Widget for edit Vehicle Type elements
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
31 
32 #include "GNEVehicleTypeFrame.h"
33 
34 
35 // ===========================================================================
36 // FOX callback mapping
37 // ===========================================================================
38 
39 FXDEFMAP(GNEVehicleTypeFrame::VehicleTypeSelector) vehicleTypeSelectorMap[] = {
41 };
42 
43 FXDEFMAP(GNEVehicleTypeFrame::VehicleTypeEditor) vehicleTypeEditorMap[] = {
48 };
49 
50 // Object implementation
51 FXIMPLEMENT(GNEVehicleTypeFrame::VehicleTypeSelector, FXGroupBox, vehicleTypeSelectorMap, ARRAYNUMBER(vehicleTypeSelectorMap))
52 FXIMPLEMENT(GNEVehicleTypeFrame::VehicleTypeEditor, FXGroupBox, vehicleTypeEditorMap, ARRAYNUMBER(vehicleTypeEditorMap))
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 
58 // ---------------------------------------------------------------------------
59 // GNEVehicleTypeFrame::VehicleTypeSelector - methods
60 // ---------------------------------------------------------------------------
61 
63  FXGroupBox(vehicleTypeFrameParent->myContentFrame, "Current Vehicle Type", GUIDesignGroupBoxFrame),
64  myVehicleTypeFrameParent(vehicleTypeFrameParent),
65  myCurrentVehicleType(nullptr) {
66  // Create FXComboBox
67  myTypeMatchBox = new FXComboBox(this, GUIDesignComboBoxNCol, this, MID_GNE_SET_TYPE, GUIDesignComboBox);
68  // add default Vehicle an Bike types in the first and second positions
69  myTypeMatchBox->appendItem(DEFAULT_VTYPE_ID.c_str());
70  myTypeMatchBox->appendItem(DEFAULT_BIKETYPE_ID.c_str());
71  // fill myTypeMatchBox with list of VTypes IDs
72  for (const auto& i : myVehicleTypeFrameParent->getViewNet()->getNet()->getAttributeCarriers().demandElements.at(SUMO_TAG_VTYPE)) {
73  if ((i.first != DEFAULT_VTYPE_ID) && (i.first != DEFAULT_BIKETYPE_ID)) {
74  myTypeMatchBox->appendItem(i.first.c_str());
75  }
76  }
77  // set DEFAULT_VEHTYPE as default VType
78  myCurrentVehicleType = myVehicleTypeFrameParent->getViewNet()->getNet()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID);
79  // Set visible items
80  if (myTypeMatchBox->getNumItems() <= 20) {
81  myTypeMatchBox->setNumVisible((int)myTypeMatchBox->getNumItems());
82  } else {
83  myTypeMatchBox->setNumVisible(20);
84  }
85  // VehicleTypeSelector is always shown
86  show();
87 }
88 
89 
91 
92 
95  return myCurrentVehicleType;
96 }
97 
98 
99 void
101  myCurrentVehicleType = vType;
103 }
104 
105 
106 void
108  bool valid = false;
109  // clear items
110  myTypeMatchBox->clearItems();
111  // add default Vehicle an Bike types in the first and second positions
112  myTypeMatchBox->appendItem(DEFAULT_VTYPE_ID.c_str());
113  myTypeMatchBox->appendItem(DEFAULT_BIKETYPE_ID.c_str());
114  // fill myTypeMatchBox with list of VTypes IDs
116  if ((i.first != DEFAULT_VTYPE_ID) && (i.first != DEFAULT_BIKETYPE_ID)) {
117  myTypeMatchBox->appendItem(i.first.c_str());
118  }
119  }
120  // Set visible items
121  if (myTypeMatchBox->getNumItems() <= 20) {
122  myTypeMatchBox->setNumVisible((int)myTypeMatchBox->getNumItems());
123  } else {
124  myTypeMatchBox->setNumVisible(20);
125  }
126  // make sure that tag is in myTypeMatchBox
127  for (int i = 0; i < (int)myTypeMatchBox->getNumItems(); i++) {
128  if (myTypeMatchBox->getItem(i).text() == myCurrentVehicleType->getID()) {
129  myTypeMatchBox->setCurrentItem(i);
130  valid = true;
131  }
132  }
133  // Check that give vType type is valid
134  if (!valid) {
135  // set DEFAULT_VEHTYPE as default VType
137  // refresh myTypeMatchBox again
138  for (int i = 0; i < (int)myTypeMatchBox->getNumItems(); i++) {
139  if (myTypeMatchBox->getItem(i).text() == myCurrentVehicleType->getID()) {
140  myTypeMatchBox->setCurrentItem(i);
141  }
142  }
143  }
144  // refresh vehicle type editor modul
146  // show Attribute Editor modul if selected item is valid
148 }
149 
150 
151 void
153  if (myCurrentVehicleType) {
154  myTypeMatchBox->setItem(myTypeMatchBox->getCurrentItem(), myCurrentVehicleType->getID().c_str());
155  }
156 }
157 
158 
159 long
161  // Check if value of myTypeMatchBox correspond of an allowed additional tags
163  if (i.first == myTypeMatchBox->getText().text()) {
164  // set pointer
165  myCurrentVehicleType = i.second;
166  // set color of myTypeMatchBox to black (valid)
167  myTypeMatchBox->setTextColor(FXRGB(0, 0, 0));
168  // refresh vehicle type editor modul
170  // show moduls if selected item is valid
172  // Write Warning in console if we're in testing mode
173  WRITE_DEBUG(("Selected item '" + myTypeMatchBox->getText() + "' in VehicleTypeSelector").text());
174  return 1;
175  }
176  }
177  myCurrentVehicleType = nullptr;
178  // refresh vehicle type editor modul
180  // hide all moduls if selected item isn't valid
182  // set color of myTypeMatchBox to red (invalid)
183  myTypeMatchBox->setTextColor(FXRGB(255, 0, 0));
184  // Write Warning in console if we're in testing mode
185  WRITE_DEBUG("Selected invalid item in VehicleTypeSelector");
186  return 1;
187 }
188 
189 // ---------------------------------------------------------------------------
190 // GNEVehicleTypeFrame::VehicleTypeEditor - methods
191 // ---------------------------------------------------------------------------
192 
194  FXGroupBox(vehicleTypeFrameParent->myContentFrame, "Vehicle Type Editor", GUIDesignGroupBoxFrame),
195  myVehicleTypeFrameParent(vehicleTypeFrameParent) {
196  // Create new vehicle type
197  myCreateVehicleTypeButton = new FXButton(this, "Create Vehicle Type", nullptr, this, MID_GNE_CREATE, GUIDesignButton);
198  // Create delete vehicle type
199  myDeleteVehicleTypeButton = new FXButton(this, "Delete Vehicle Type", nullptr, this, MID_GNE_DELETE, GUIDesignButton);
200  // Create reset vehicle type
201  myResetDefaultVehicleTypeButton = new FXButton(this, "Reset default Vehicle Type", nullptr, this, MID_GNE_RESET, GUIDesignButton);
202  // Create copy vehicle type
203  myCopyVehicleTypeButton = new FXButton(this, "Copy Vehicle Type", nullptr, this, MID_GNE_COPY, GUIDesignButton);
204 }
205 
206 
208 
209 
210 void
213  show();
214 }
215 
216 
217 void
219  hide();
220 }
221 
222 
223 void
225  // first check if selected VType is valid
227  // disable all buttons except create button
228  myDeleteVehicleTypeButton->disable();
230  myCopyVehicleTypeButton->disable();
232  // enable copy button
233  myCopyVehicleTypeButton->enable();
234  // hide delete vehicle type buttond and show reset default vehicle type button
237  // check if reset default vehicle type button has to be enabled or disabled
240  } else {
242  }
243  } else {
244  // enable copy button
245  myCopyVehicleTypeButton->enable();
246  // show delete vehicle type button and hide reset default vehicle type button
248  myDeleteVehicleTypeButton->enable();
250  }
251  // update modul
252  recalc();
253 }
254 
255 
256 long
258  // obtain a new valid Vehicle Type ID
260  // create new vehicle type
262  // add it using undoList (to allow undo-redo)
263  myVehicleTypeFrameParent->myViewNet->getUndoList()->p_begin("create vehicle type");
264  myVehicleTypeFrameParent->myViewNet->getUndoList()->add(new GNEChange_DemandElement(vehicleType, true), true);
266  // set created vehicle type in selector
268  // refresh VehicleType Editor Modul
270  return 1;
271 }
272 
273 
274 long
276  // show question dialog if vtype has already assigned vehicles
278  std::string plural = myVehicleTypeFrameParent->myVehicleTypeSelector->getCurrentVehicleType()->getDemandElementChildren().size() == 1 ? ("") : ("s");
279  // show warning in gui testing debug mode
280  WRITE_DEBUG("Opening FXMessageBox 'remove vType'");
281  // Ask confirmation to user
282  FXuint answer = FXMessageBox::question(getApp(), MBOX_YES_NO,
283  ("Remove " + toString(SUMO_TAG_VTYPE) + "s").c_str(), "%s",
286  " vehicle" + plural + ". Continue?").c_str());
287  if (answer != 1) { // 1:yes, 2:no, 4:esc
288  // write warning if netedit is running in testing mode
289  if (answer == 2) {
290  WRITE_DEBUG("Closed FXMessageBox 'remove vType' with 'No'");
291  } else if (answer == 4) {
292  WRITE_DEBUG("Closed FXMessageBox 'remove vType' with 'ESC'");
293  }
294  } else {
295  // begin undo list operation
296  myVehicleTypeFrameParent->myViewNet->getUndoList()->p_begin("delete vehicle type");
297  // remove vehicle type (and all of their children)
300  // end undo list operation
302  }
303  } else {
304  // begin undo list operation
305  myVehicleTypeFrameParent->myViewNet->getUndoList()->p_begin("delete vehicle type");
306  // remove vehicle type (and all of their children)
309  // end undo list operation
311  }
312  return 1;
313 }
314 
315 
316 long
318  // begin reset default vehicle type values
319  myVehicleTypeFrameParent->getViewNet()->getUndoList()->p_begin("reset default vehicle type values");
320  // reset all values of default vehicle type
322  // change all attributes with "" to reset it (except ID and vClass)
323  if ((i.getAttr() != SUMO_ATTR_ID) && (i.getAttr() != SUMO_ATTR_VCLASS)) {
325  }
326  }
327  // change manually VClass (because it depends of Default VType)
332  }
333  // change special attribute GNE_ATTR_DEFAULT_VTYPE_MODIFIED
335  // finish reset default vehicle type values
337  // refresh VehicleTypeSelector
339  return 1;
340 }
341 
342 
343 long
345  // obtain a new valid Vehicle Type ID
347  // obtain vehicle type in which new Vehicle Type will be based
349  // check that vType exist
350  if (vType) {
351  // create a new Vehicle Type based on the current selected vehicle type
352  GNEDemandElement* vehicleTypeCopy = new GNEVehicleType(myVehicleTypeFrameParent->myViewNet, vehicleTypeID, vType);
353  // begin undo list operation
354  myVehicleTypeFrameParent->myViewNet->getUndoList()->p_begin("copy vehicle type");
355  // add it using undoList (to allow undo-redo)
356  myVehicleTypeFrameParent->myViewNet->getUndoList()->add(new GNEChange_DemandElement(vehicleTypeCopy, true), true);
357  // end undo list operation
359  // refresh Vehicle Type Selector (to show the new VType)
361  // set created vehicle type in selector
363  // refresh VehicleType Editor Modul
365  }
366  return 1;
367 }
368 
369 // ---------------------------------------------------------------------------
370 // GNEVehicleTypeFrame - methods
371 // ---------------------------------------------------------------------------
372 
373 GNEVehicleTypeFrame::GNEVehicleTypeFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
374  GNEFrame(horizontalFrameParent, viewNet, "Vehicle Types") {
375 
376  // create modul for edit vehicle types (Create, copy, etc.)
378 
379  // create vehicle type selector
381 
382  // Create vehicle type attributes editor
384 
385  // create modul for open extended attributes dialog
387 
388  // set "VTYPE_DEFAULT" as default vehicle Type
390 }
391 
392 
394 
395 
396 void
398  // refresh vehicle type and Attribute Editor
400  // show vehicle type attributes editor (except extended attributes)
402  // show frame
403  GNEFrame::show();
404 }
405 
406 
409  return myVehicleTypeSelector;
410 }
411 
412 
413 void
415  // after changing an attribute myVehicleTypeSelector, we need to update the list of vehicleTypeSelector, because ID could be changed
417 }
418 
419 
420 void
422  // open vehicle type dialog
425  // call "showAttributeEditorModul" to refresh attribute list
427  }
428 }
429 
430 /****************************************************************************/
const AttributeCarriers & getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:1014
static const TagProperties & getTagProperties(SumoXMLTag tag)
get Tag Properties
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:233
void setCurrentVehicleType(GNEDemandElement *vType)
set current Vehicle Type
description of a vehicle type
Dialog for edit rerouter intervals.
delete element
Definition: GUIAppEnum.h:623
void deleteDemandElement(GNEDemandElement *demandElement, GNEUndoList *undoList)
remove demand element
Definition: GNENet.cpp:638
GNEVehicleTypeFrame * myVehicleTypeFrameParent
pointer to vehicle type Frame Parent
vehicle is a bicycle
void attributesEditorExtendedDialogOpened()
open AttributesCreator extended dialog (used for editing advance attributes of Vehicle Types) ...
GNEDemandElement * myCurrentVehicleType
pointer to current vehicle type
long onCmdSelectItem(FXObject *, FXSelector, void *)
GNEFrameAttributesModuls::AttributesEditorExtended * myAttributesEditorExtended
modul for open extended attributes dialog
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:73
const std::string DEFAULT_BIKETYPE_ID
VehicleTypeSelector * getVehicleTypeSelector() const
get vehicle type selector
FXButton * myResetDefaultVehicleTypeButton
"delete default vehicle type" button
const std::string DEFAULT_VTYPE_ID
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:133
FXDEFMAP(GNEVehicleTypeFrame::VehicleTypeSelector) vehicleTypeSelectorMap[]
const std::vector< GNEDemandElement * > & getDemandElementChildren() const
return vector of demand elements that have as Parent this edge (For example, Calibrators) ...
#define GUIDesignComboBox
Definition: GUIDesigns.h:221
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:120
FXButton * myDeleteVehicleTypeButton
"delete vehicle type" button
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
FXComboBox * myTypeMatchBox
comboBox with the list of elements type
void hideVehicleTypeEditorModul()
hide VehicleTypeEditor box
void refreshVehicleTypeSelector()
refresh vehicle type selector
GNEFrameAttributesModuls::AttributesEditor * myVehicleTypeAttributesEditor
editorinternal vehicle type attributes
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:123
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
Definition: GNENet.cpp:2266
reset element
Definition: GUIAppEnum.h:627
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:80
GNEVehicleTypeFrame * myVehicleTypeFrameParent
pointer to Frame Parent
std::map< SumoXMLTag, std::map< std::string, GNEDemandElement * > > demandElements
map with the name and pointer to demand elements of net
Definition: GNENet.h:105
void showAttributeEditorModul(const std::vector< GNEAttributeCarrier *> &ACs, bool includeExtended)
show attributes of multiple ACs
const std::string getID() const
function to support debugging
VehicleTypeSelector * myVehicleTypeSelector
vehicle type selector
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
std::string generateDemandElementID(const std::string &prefix, SumoXMLTag type) const
generate demand element id
Definition: GNENet.cpp:2411
vehicle is a passenger car (a "normal" car)
long onCmdCopyVehicleType(FXObject *, FXSelector, void *)
Called when "Copy Vehicle Type" button is clicked.
copy element
Definition: GUIAppEnum.h:631
long onCmdResetVehicleType(FXObject *, FXSelector, void *)
Called when "Delete Vehicle Type" button is clicked.
void showVehicleTypeEditorModul()
show VehicleTypeEditor modul
~GNEVehicleTypeFrame()
Destructor.
void refreshVehicleTypeSelectorIDs()
refresh vehicle type selector (only IDs, without refreshing attributes)
#define GUIDesignButton
Definition: GUIDesigns.h:66
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
Flag to check if VType is a default VType.
GNEVehicleTypeFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:255
long onCmdCreateVehicleType(FXObject *, FXSelector, void *)
GNEDemandElement * getCurrentVehicleType() const
get current Vehicle Type
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform demand element changes ...
void attributeUpdated()
function called after set a valid attribute in AttributeCreator/AttributeEditor/GenericParametersEdit...
FXButton * myCopyVehicleTypeButton
"copy vehicle type"
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
VehicleTypeEditor * myVehicleTypeEditor
Vehicle Type editor (Create, copy, etc.)
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
used to select a type of element in a combo box
Definition: GUIAppEnum.h:635
create element
Definition: GUIAppEnum.h:621
Flag to check if a default VType was modified.
void refreshVehicleTypeEditorModul()
update VehicleTypeEditor modul
long onCmdDeleteVehicleType(FXObject *, FXSelector, void *)
Called when "Delete Vehicle Type" button is clicked.
virtual std::string getAttribute(SumoXMLAttr key) const =0
C++ TraCI client API implementation.
Definition: Vehicle.h:40
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
FXButton * myCreateVehicleTypeButton
"create vehicle type" button