Eclipse SUMO - Simulation of Urban MObility
GNEPersonTypeFrame.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 person type (pTypes with vclass='pedestrian) elements
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNEUndoList.h>
30 
31 #include "GNEPersonTypeFrame.h"
32 
33 
34 // ===========================================================================
35 // FOX callback mapping
36 // ===========================================================================
37 
38 FXDEFMAP(GNEPersonTypeFrame::PersonTypeSelector) personTypeSelectorMap[] = {
40 };
41 
42 FXDEFMAP(GNEPersonTypeFrame::PersonTypeEditor) personTypeEditorMap[] = {
47 };
48 
49 // Object implementation
50 FXIMPLEMENT(GNEPersonTypeFrame::PersonTypeSelector, FXGroupBox, personTypeSelectorMap, ARRAYNUMBER(personTypeSelectorMap))
51 FXIMPLEMENT(GNEPersonTypeFrame::PersonTypeEditor, FXGroupBox, personTypeEditorMap, ARRAYNUMBER(personTypeEditorMap))
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 
57 // ---------------------------------------------------------------------------
58 // GNEPersonTypeFrame::PersonTypeSelector - methods
59 // ---------------------------------------------------------------------------
60 
62  FXGroupBox(personTypeFrameParent->myContentFrame, "Current Person Type", GUIDesignGroupBoxFrame),
63  myPersonTypeFrameParent(personTypeFrameParent),
64  myCurrentPersonType(nullptr) {
65  // Create FXComboBox
66  myTypeMatchBox = new FXComboBox(this, GUIDesignComboBoxNCol, this, MID_GNE_SET_TYPE, GUIDesignComboBox);
67  // fill myTypeMatchBox with list of pTypes IDs
68  for (const auto& i : myPersonTypeFrameParent->getViewNet()->getNet()->getAttributeCarriers().demandElements.at(SUMO_TAG_PTYPE)) {
69  myTypeMatchBox->appendItem(i.first.c_str());
70  }
71  // set DEFAULT_PEDTYPE_ID as default pType
72  myCurrentPersonType = myPersonTypeFrameParent->getViewNet()->getNet()->retrieveDemandElement(SUMO_TAG_PTYPE, DEFAULT_PEDTYPE_ID);
73  // Set visible items
74  if (myTypeMatchBox->getNumItems() <= 20) {
75  myTypeMatchBox->setNumVisible((int)myTypeMatchBox->getNumItems());
76  } else {
77  myTypeMatchBox->setNumVisible(20);
78  }
79  // PersonTypeSelector is always shown
80  show();
81 }
82 
83 
85 
86 
89  return myCurrentPersonType;
90 }
91 
92 
93 void
95  myCurrentPersonType = vType;
97 }
98 
99 
100 void
102  bool valid = false;
103  myTypeMatchBox->clearItems();
104  // fill myTypeMatchBox with list of pTypes IDs
106  myTypeMatchBox->appendItem(i.first.c_str());
107  }
108  // Set visible items
109  if (myTypeMatchBox->getNumItems() <= 20) {
110  myTypeMatchBox->setNumVisible((int)myTypeMatchBox->getNumItems());
111  } else {
112  myTypeMatchBox->setNumVisible(20);
113  }
114  // make sure that tag is in myTypeMatchBox
115  for (int i = 0; i < (int)myTypeMatchBox->getNumItems(); i++) {
116  if (myTypeMatchBox->getItem(i).text() == myCurrentPersonType->getID()) {
117  myTypeMatchBox->setCurrentItem(i);
118  valid = true;
119  }
120  }
121  // Check that give vType type is valid
122  if (!valid) {
123  // set DEFAULT_VEHTYPE as default pType
125  // refresh myTypeMatchBox again
126  for (int i = 0; i < (int)myTypeMatchBox->getNumItems(); i++) {
127  if (myTypeMatchBox->getItem(i).text() == myCurrentPersonType->getID()) {
128  myTypeMatchBox->setCurrentItem(i);
129  }
130  }
131  }
132  // refresh person type editor modul
134  // show Attribute Editor modul if selected item is valid
136 }
137 
138 
139 long
141  // Check if value of myTypeMatchBox correspond of an allowed additional tags
143  if (i.first == myTypeMatchBox->getText().text()) {
144  // set pointer
145  myCurrentPersonType = i.second;
146  // set color of myTypeMatchBox to black (valid)
147  myTypeMatchBox->setTextColor(FXRGB(0, 0, 0));
148  // refresh person type editor modul
150  // show moduls if selected item is valid
152  // Write Warning in console if we're in testing mode
153  WRITE_DEBUG(("Selected item '" + myTypeMatchBox->getText() + "' in PersonTypeSelector").text());
154  return 1;
155  }
156  }
157  myCurrentPersonType = nullptr;
158  // refresh person type editor modul
160  // hide all moduls if selected item isn't valid
162  // set color of myTypeMatchBox to red (invalid)
163  myTypeMatchBox->setTextColor(FXRGB(255, 0, 0));
164  // Write Warning in console if we're in testing mode
165  WRITE_DEBUG("Selected invalid item in PersonTypeSelector");
166  return 1;
167 }
168 
169 // ---------------------------------------------------------------------------
170 // GNEPersonTypeFrame::PersonTypeEditor - methods
171 // ---------------------------------------------------------------------------
172 
174  FXGroupBox(personTypeFrameParent->myContentFrame, "Person Type Editor", GUIDesignGroupBoxFrame),
175  myPersonTypeFrameParent(personTypeFrameParent) {
176  // Create new person type
177  myCreatePersonTypeButton = new FXButton(this, "Create Person Type", nullptr, this, MID_GNE_CREATE, GUIDesignButton);
178  // Create delete person type
179  myDeletePersonTypeButton = new FXButton(this, "Delete Person Type", nullptr, this, MID_GNE_DELETE, GUIDesignButton);
180  // Create reset person type
181  myResetDefaultPersonTypeButton = new FXButton(this, "Reset default Person Type", nullptr, this, MID_GNE_RESET, GUIDesignButton);
182  // Create copy person type
183  myCopyPersonTypeButton = new FXButton(this, "Copy Person Type", nullptr, this, MID_GNE_COPY, GUIDesignButton);
184 }
185 
186 
188 
189 
190 void
193  show();
194 }
195 
196 
197 void
199  hide();
200 }
201 
202 
203 void
205  // first check if selected pType is valid
207  // disable all buttons except create button
208  myDeletePersonTypeButton->disable();
210  myCopyPersonTypeButton->disable();
211  } else if (GNEAttributeCarrier::parse<bool>(myPersonTypeFrameParent->myPersonTypeSelector->getCurrentPersonType()->getAttribute(GNE_ATTR_DEFAULT_VTYPE))) {
212  // enable copy button
213  myCopyPersonTypeButton->enable();
214  // hide delete person type buttond and show reset default person type button
215  myDeletePersonTypeButton->hide();
217  // check if reset default person type button has to be enabled or disabled
220  } else {
222  }
223  } else {
224  // enable copy button
225  myCopyPersonTypeButton->enable();
226  // show delete person type button and hide reset default person type button
227  myDeletePersonTypeButton->show();
228  myDeletePersonTypeButton->enable();
230  }
231  // update modul
232  recalc();
233 }
234 
235 
236 long
238  // obtain a new valid Vehicle Type ID
240  // create new person type
242  // add it using undoList (to allow undo-redo)
243  myPersonTypeFrameParent->myViewNet->getUndoList()->p_begin("create person type");
244  myPersonTypeFrameParent->myViewNet->getUndoList()->add(new GNEChange_DemandElement(personType, true), true);
246  // set created person type in selector
248  // refresh PersonType Editor Modul
250  return 1;
251 }
252 
253 
254 long
256  // show question dialog if vtype has already assigned persons
258  std::string plural = myPersonTypeFrameParent->myPersonTypeSelector->getCurrentPersonType()->getDemandElementChildren().size() == 1 ? ("") : ("s");
259  // show warning in gui testing debug mode
260  WRITE_DEBUG("Opening FXMessageBox 'remove vType'");
261  // Ask confirmation to user
262  FXuint answer = FXMessageBox::question(getApp(), MBOX_YES_NO,
263  ("Remove " + toString(SUMO_TAG_PTYPE) + "s").c_str(), "%s",
266  " person" + plural + ". Continue?").c_str());
267  if (answer != 1) { // 1:yes, 2:no, 4:esc
268  // write warning if netedit is running in testing mode
269  if (answer == 2) {
270  WRITE_DEBUG("Closed FXMessageBox 'remove vType' with 'No'");
271  } else if (answer == 4) {
272  WRITE_DEBUG("Closed FXMessageBox 'remove vType' with 'ESC'");
273  }
274  } else {
275  // begin undo list operation
276  myPersonTypeFrameParent->myViewNet->getUndoList()->p_begin("delete person type");
277  // remove person type (and all of their children)
280  // end undo list operation
282  }
283  } else {
284  // begin undo list operation
285  myPersonTypeFrameParent->myViewNet->getUndoList()->p_begin("delete person type");
286  // remove person type (and all of their children)
289  // end undo list operation
291  }
292  return 1;
293 }
294 
295 
296 long
298  // begin reset default person type values
299  myPersonTypeFrameParent->getViewNet()->getUndoList()->p_begin("reset default person type values");
300  // reset all values of default person type
302  // change all attributes with "" to reset it (except ID and vClass)
303  if ((i.getAttr() != SUMO_ATTR_ID) && (i.getAttr() != SUMO_ATTR_VCLASS)) {
305  }
306  }
307  // change manually VClass (because it depends of Default pType)
310  }
311  // change special attribute GNE_ATTR_DEFAULT_VTYPE_MODIFIED
313  // finish reset default person type values
315  // refresh PersonTypeSelector
317  return 1;
318 }
319 
320 
321 long
323  // obtain a new valid person Type ID
325  // obtain person type in which new person Type will be based
327  // check that vType exist
328  if (vType) {
329  // create a new person Type based on the current selected person type
330  GNEDemandElement* personTypeCopy = new GNEVehicleType(myPersonTypeFrameParent->myViewNet, personTypeID, vType);
331  // begin undo list operation
332  myPersonTypeFrameParent->myViewNet->getUndoList()->p_begin("copy person type");
333  // add it using undoList (to allow undo-redo)
334  myPersonTypeFrameParent->myViewNet->getUndoList()->add(new GNEChange_DemandElement(personTypeCopy, true), true);
335  // end undo list operation
337  // refresh Vehicle Type Selector (to show the new pType)
339  // set created person type in selector
341  // refresh PersonType Editor Modul
343  }
344  return 1;
345 }
346 
347 // ---------------------------------------------------------------------------
348 // GNEPersonTypeFrame - methods
349 // ---------------------------------------------------------------------------
350 
351 GNEPersonTypeFrame::GNEPersonTypeFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
352  GNEFrame(horizontalFrameParent, viewNet, "Person Types") {
353 
354  // create modul for edit person types (Create, copy, etc.)
356 
357  // create person type selector
359 
360  // Create person type attributes editor
362 
363  // set "VTYPE_DEFAULT" as default person Type
365 }
366 
367 
369 
370 
371 void
373  // refresh person type and Attribute Editor
375  // show person type attributes editor (except extended attributes)
377  // show frame
378  GNEFrame::show();
379 }
380 
381 
384  return myPersonTypeSelector;
385 }
386 
387 
388 void
391 }
392 
393 /****************************************************************************/
const AttributeCarriers & getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:1014
static const TagProperties & getTagProperties(SumoXMLTag tag)
get Tag Properties
PersonTypeEditor * myPersonTypeEditor
Vehicle Type editor (Create, copy, etc.)
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:233
void showPersonTypeEditorModul()
show PersonTypeEditor modul
GNEDemandElement * myCurrentPersonType
pointer to current person type
delete element
Definition: GUIAppEnum.h:623
long onCmdCopyPersonType(FXObject *, FXSelector, void *)
Called when "Copy Vehicle Type" button is clicked.
void deleteDemandElement(GNEDemandElement *demandElement, GNEUndoList *undoList)
remove demand element
Definition: GNENet.cpp:638
GNEFrameAttributesModuls::AttributesEditor * myPersonTypeAttributesEditor
editorinternal person type attributes
~GNEPersonTypeFrame()
Destructor.
long onCmdCreatePersonType(FXObject *, FXSelector, void *)
void refreshPersonTypeSelector()
refresh person type
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
GNEPersonTypeFrame * myPersonTypeFrameParent
pointer to person type Frame Parent
void hidePersonTypeEditorModul()
hide PersonTypeEditor box
const std::string DEFAULT_VTYPE_ID
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:133
const std::vector< GNEDemandElement * > & getDemandElementChildren() const
return vector of demand elements that have as Parent this edge (For example, Calibrators) ...
FXButton * myDeletePersonTypeButton
"delete person type" button
#define GUIDesignComboBox
Definition: GUIDesigns.h:221
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:120
void setCurrentPersonType(GNEDemandElement *vType)
set current Vehicle Type
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
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
long onCmdSelectItem(FXObject *, FXSelector, void *)
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
PersonTypeSelector * getPersonTypeSelector() const
get person type selector
void refreshPersonTypeEditorModul()
update PersonTypeEditor modul
long onCmdDeletePersonType(FXObject *, FXSelector, void *)
Called when "Delete Vehicle Type" button is clicked.
FXButton * myResetDefaultPersonTypeButton
"delete default person type" button
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
void show()
show Frame
#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
copy element
Definition: GUIAppEnum.h:631
GNEDemandElement * getCurrentPersonType() const
get current Vehicle Type
#define GUIDesignButton
Definition: GUIDesigns.h:66
FXDEFMAP(GNEPersonTypeFrame::PersonTypeSelector) personTypeSelectorMap[]
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
Flag to check if VType is a default VType.
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:255
const std::string DEFAULT_PEDTYPE_ID
FXButton * myCreatePersonTypeButton
"create person type" button
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 ...
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
FXButton * myCopyPersonTypeButton
"copy person type"
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
FXComboBox * myTypeMatchBox
comboBox with the list of elements type
description of a person type (used in NETEDIT)
long onCmdResetPersonType(FXObject *, FXSelector, void *)
Called when "Delete Vehicle Type" button is clicked.
used to select a type of element in a combo box
Definition: GUIAppEnum.h:635
PersonTypeSelector * myPersonTypeSelector
person type selector
create element
Definition: GUIAppEnum.h:621
GNEPersonTypeFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
Flag to check if a default VType was modified.
C++ TraCI client API implementation.
virtual std::string getAttribute(SumoXMLAttr key) const =0
GNEPersonTypeFrame * myPersonTypeFrameParent
pointer to Frame Parent
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
void attributeUpdated()
function called after set a valid attribute in AttributeCreator/AttributeEditor/GenericParametersEdit...