Eclipse SUMO - Simulation of Urban MObility
GNEDemandSelector.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-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Frame for select demand elements
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
27
28#include "GNEDemandSelector.h"
29
30
31// ===========================================================================
32// FOX callback mapping
33// ===========================================================================
34
35FXDEFMAP(DemandElementSelector) DemandElementSelectorMap[] = {
37};
38
39// Object implementation
40FXIMPLEMENT(DemandElementSelector, MFXGroupBoxModule, DemandElementSelectorMap, ARRAYNUMBER(DemandElementSelectorMap))
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46
47DemandElementSelector::DemandElementSelector(GNEFrame* frameParent, SumoXMLTag demandElementTag, GNEDemandElement* defaultElement) :
48 MFXGroupBoxModule(frameParent, ("Parent " + toString(demandElementTag)).c_str()),
49 myFrameParent(frameParent),
50 myCurrentDemandElement(defaultElement),
51 myDemandElementTags({demandElementTag}),
52mySelectingMultipleElements(false) {
53 // Create MFXIconComboBox
54 myDemandElementsMatchBox = new MFXIconComboBox(getCollapsableFrame(), GUIDesignComboBoxNCol, true, this, MID_GNE_SET_TYPE, GUIDesignComboBox);
55 // create info label
56 myInfoLabel = new FXLabel(getCollapsableFrame(), "", nullptr, GUIDesignLabelFrameInformation);
57 // refresh demand element MatchBox
58 refreshDemandElementSelector();
59 // shown after creation
60 show();
61}
62
63
64DemandElementSelector::DemandElementSelector(GNEFrame* frameParent, const std::vector<GNETagProperties::TagType>& tagTypes) :
65 MFXGroupBoxModule(frameParent, TL("Parent element")),
66 myFrameParent(frameParent),
67 myCurrentDemandElement(nullptr),
68 mySelectingMultipleElements(false) {
69 // fill myDemandElementTags
70 for (const auto& tagType : tagTypes) {
71 const auto tagProperties = GNEAttributeCarrier::getTagPropertiesByType(tagType);
72 for (const auto& tagProperty : tagProperties) {
73 myDemandElementTags.push_back(tagProperty.getTag());
74 }
75 }
76 // Create MFXIconComboBox
78 // create info label
80 // refresh demand element MatchBox
82 // shown after creation
83 show();
84}
85
86
88
89
93}
94
95
96const std::vector<SumoXMLTag>&
99}
100
101
102void
105 // Set new current demand element
106 myCurrentDemandElement = demandElement;
107 if (demandElement == nullptr) {
108 myDemandElementsMatchBox->setCustomText("select item...");
109 // set info label
110 myInfoLabel->setText("-Select an item in the list or\n click over an element in view");
111 myInfoLabel->show();
112 } else {
113 // check that demandElement tag correspond to a tag of myDemandElementTags
114 if (std::find(myDemandElementTags.begin(), myDemandElementTags.end(), demandElement->getTagProperty().getTag()) != myDemandElementTags.end()) {
115 // update text of myDemandElementsMatchBox
116 myDemandElementsMatchBox->setItem(demandElement->getID().c_str(), demandElement->getACIcon());
117 }
118 myInfoLabel->hide();
119 }
120 // call demandElementSelected function
122}
123
124
125void
126DemandElementSelector::setDemandElements(const std::vector<GNEDemandElement*>& demandElements) {
128 myCurrentDemandElement = nullptr;
130 for (const auto& demandElement : demandElements) {
131 myDemandElementsMatchBox->appendIconItem(demandElement->getID().c_str(), demandElement->getACIcon());
132 }
133 myDemandElementsMatchBox->setCustomText("select sub-item...");
134 // set info label
135 myInfoLabel->setText("-Clicked over multiple\n elements\n-Select an item in the\n list or click over an\n element in view");
136 myInfoLabel->show();
137}
138
139
140void
142 // first refresh modul
144 // if current selected item isn't valid, set DEFAULT_VTYPE_ID or DEFAULT_PEDTYPE_ID
147 } else if (myDemandElementTags.size() == 1) {
148 if (myDemandElementTags.at(0) == SUMO_TAG_VTYPE) {
150 myDemandElementsMatchBox->setItem(defaultVType->getID().c_str(), defaultVType->getACIcon());
151 }
152 }
153 onCmdSelectDemandElement(nullptr, 0, nullptr);
154 show();
155}
156
157
158void
160 hide();
161}
162
163
164bool
166 return shown();
167}
168
169
170void
172 // get demand elemenst container
173 const auto& demandElements = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements();
174 // clear demand elements comboBox
176 // fill myTypeMatchBox with list of demand elements
177 for (const auto& demandElementTag : myDemandElementTags) {
178 // special case for VTypes
179 if (demandElementTag == SUMO_TAG_VTYPE) {
180 // add default types in the first positions
186 // add rest of vTypes
187 for (const auto& vType : demandElements.at(demandElementTag)) {
188 // avoid insert duplicated default vType
189 if (DEFAULT_VTYPES.count(vType->getID()) == 0) {
190 myDemandElementsMatchBox->appendIconItem(vType->getID().c_str(), vType->getACIcon());
191 }
192 }
193 } else {
194 // insert all Ids
195 for (const auto& demandElement : demandElements.at(demandElementTag)) {
196 myDemandElementsMatchBox->appendIconItem(demandElement->getID().c_str(), demandElement->getACIcon());
197 }
198 }
199 }
200 // Set number of items (maximum 10)
203 } else {
205 }
206 // update myCurrentDemandElement
208 myCurrentDemandElement = nullptr;
209 } else if (myCurrentDemandElement) {
210 for (int i = 0; i < myDemandElementsMatchBox->getNumItems(); i++) {
213 }
214 }
215 } else {
216 // set first element in the list as myCurrentDemandElement (Special case for default person and vehicle type)
219 } else {
220 // disable myCurrentDemandElement
221 myCurrentDemandElement = nullptr;
222 // update myCurrentDemandElement with the first allowed element
223 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
224 if (demandElements.at(*i).size() > 0) {
225 myCurrentDemandElement = *demandElements.at(*i).begin();
226 }
227 }
228 }
229 }
230}
231
232
233GNEEdge*
235 if (myCurrentDemandElement == nullptr) {
236 return nullptr;
237 }
239 return nullptr;
240 }
242 return nullptr;
243 }
244 // get last person plan
245 const GNEDemandElement* lastPersonPlan = myCurrentDemandElement->getChildDemandElements().back();
246 // check tag
247 switch (lastPersonPlan->getTagProperty().getTag()) {
248 // person trips
250 // rides
252 // walks
255 // stops
257 return lastPersonPlan->getParentEdges().back();
258 // person trips
260 // person trips
262 // walks
264 // stops
266 return lastPersonPlan->getParentAdditionals().back()->getParentLanes().front()->getParentEdge();
267 // route walks
269 return lastPersonPlan->getParentDemandElements().back()->getParentEdges().back();
270 default:
271 return nullptr;
272 }
273}
274
275
276GNEEdge*
278 if (myCurrentDemandElement == nullptr) {
279 return nullptr;
280 }
282 return nullptr;
283 }
285 return nullptr;
286 }
287 // get last container plan
288 const GNEDemandElement* lastContainerPlan = myCurrentDemandElement->getChildDemandElements().back();
289 // check tag
290 switch (lastContainerPlan->getTagProperty().getTag()) {
291 // transport
293 // tranship
296 // stop
298 return lastContainerPlan->getParentEdges().back();
299 // transport
301 // tranship
303 // stop
305 return lastContainerPlan->getParentAdditionals().back()->getParentLanes().front()->getParentEdge();
306 default:
307 return nullptr;
308 }
309}
310
311
312long
314 // Check if value of myTypeMatchBox correspond to a demand element
315 for (const auto& demandElementTag : myDemandElementTags) {
316 for (const auto& demandElement : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(demandElementTag)) {
317 if (demandElement->getID() == myDemandElementsMatchBox->getText().text()) {
318 // set color of myTypeMatchBox to black (valid)
319 myDemandElementsMatchBox->setTextColor(FXRGB(0, 0, 0));
320 myDemandElementsMatchBox->killFocus();
321 // Set new current demand element
322 myCurrentDemandElement = demandElement;
323 // call demandElementSelected function
325 // Write Warning in console if we're in testing mode
326 WRITE_DEBUG(("Selected item '" + myDemandElementsMatchBox->getText() + "' in DemandElementSelector").text());
327 myInfoLabel->hide();
328 return 1;
329 }
330 }
331 }
332 // if demand element selected is invalid, set demand element as null
333 myCurrentDemandElement = nullptr;
334 // call demandElementSelected function
336 // change color of myDemandElementsMatchBox to red (invalid)
337 myDemandElementsMatchBox->setTextColor(FXRGB(255, 0, 0));
338 // Write Warning in console if we're in testing mode
339 WRITE_DEBUG("Selected invalid item in DemandElementSelector");
340 return 1;
341}
342
343/****************************************************************************/
FXDEFMAP(DemandElementSelector) DemandElementSelectorMap[]
@ MID_GNE_SET_TYPE
used to select a type of element in a combo box
Definition: GUIAppEnum.h:888
#define GUIDesignComboBox
Definition: GUIDesigns.h:306
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:321
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:271
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:276
#define TL(string)
Definition: MsgHandler.h:282
const std::string DEFAULT_TAXITYPE_ID
const std::string DEFAULT_PEDTYPE_ID
const std::set< std::string > DEFAULT_VTYPES
const std::string DEFAULT_VTYPE_ID
const std::string DEFAULT_CONTAINERTYPE_ID
const std::string DEFAULT_BIKETYPE_ID
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_TRANSPORT_CONTAINERSTOP
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ GNE_TAG_PERSONTRIP_BUSSTOP
@ GNE_TAG_WALK_EDGES
@ GNE_TAG_STOPCONTAINER_EDGE
@ GNE_TAG_STOPPERSON_BUSSTOP
@ GNE_TAG_TRANSHIP_EDGES
@ GNE_TAG_STOPCONTAINER_CONTAINERSTOP
@ GNE_TAG_WALK_BUSSTOP
@ GNE_TAG_RIDE_EDGE
@ GNE_TAG_TRANSHIP_EDGE
@ GNE_TAG_WALK_EDGE
@ GNE_TAG_PERSONTRIP_EDGE
@ GNE_TAG_RIDE_BUSSTOP
@ GNE_TAG_STOPPERSON_EDGE
@ GNE_TAG_WALK_ROUTE
@ GNE_TAG_TRANSHIP_CONTAINERSTOP
@ GNE_TAG_TRANSPORT_EDGE
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
GNEDemandElement * getCurrentDemandElement() const
get current demand element
bool mySelectingMultipleElements
flag for enable/disable multiple element selection
long onCmdSelectDemandElement(FXObject *, FXSelector, void *)
~DemandElementSelector()
destructor
bool isDemandElementSelectorShown() const
check if demand element selector is shown
GNEDemandElement * myCurrentDemandElement
current demand element
void refreshDemandElementSelector()
refresh demand element selector
GNEEdge * getPersonPlanPreviousEdge() const
get previous edge for the current person plan
DemandElementSelector(GNEFrame *frameParent, SumoXMLTag demandElementTag, GNEDemandElement *defaultElement=nullptr)
FOX-declaration.
MFXIconComboBox * myDemandElementsMatchBox
comboBox with the list of elements type
FXLabel * myInfoLabel
info label
const std::vector< SumoXMLTag > & getAllowedTags() const
void setDemandElement(GNEDemandElement *demandElement)
set current demand element
GNEEdge * getContainerPlanPreviousEdge() const
get previous edge for the current container plan
std::vector< SumoXMLTag > myDemandElementTags
demand element tags
void showDemandElementSelector()
show demand element selector
void setDemandElements(const std::vector< GNEDemandElement * > &demandElements)
set multiple demand elements to filter
GNEFrame * myFrameParent
FOX need this.
void hideDemandElementSelector()
hide demand element selector
const std::string getID() const
get ID (all Attribute Carriers have one)
FXIcon * getACIcon() const
get FXIcon associated to this AC
static const std::vector< GNETagProperties > getTagPropertiesByType(const int tagPropertyCategory)
get tagProperties associated to the given GNETagProperties::TagType (NETWORKELEMENT,...
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
An Element which don't belong to GNENet but has influence in the simulation.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:150
virtual void demandElementSelected()
selected demand element in DemandElementSelector
Definition: GNEFrame.cpp:272
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
const std::map< SumoXMLTag, std::set< GNEDemandElement * > > & getDemandElements() const
get demand elements
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
GNEDemandElement * getDefaultType() const
get default type
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
bool isContainer() const
return true if tag correspond to a container element
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool isPerson() const
return true if tag correspond to a person element
GNENet * getNet() const
get the net object
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
ComboBox with icon.
FXString getItem(FXint index) const
Return the item at the given index.
FXString getText() const
Get the text.
void setCurrentItem(FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
void setTextColor(FXColor clr)
Change text color.
void clearItems()
Remove all items from the list.
FXint getNumItems() const
Return the number of items in the list.
void setNumVisible(FXint nvis)
Set the number of visible items in the drop down list.
void setCustomText(const FXString text)
set custom text
bool setItem(const FXString &text, FXIcon *icon)
set Item
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon