Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDemandSelector.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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, (TL("Parent ") + toString(demandElementTag)).c_str()),
49 myFrameParent(frameParent),
50 myCurrentDemandElement(defaultElement),
51 myDemandElementTags({demandElementTag}),
52mySelectingMultipleElements(false) {
53 // Create MFXComboBoxIcon
54 myDemandElementsMatchBox = new MFXComboBoxIcon(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 MFXComboBoxIcon
78 // create info label
80 // refresh demand element MatchBox
82 // shown after creation
83 show();
84}
85
86
88
89
94
95
96const std::vector<SumoXMLTag>&
100
101
102void
105 // Set new current demand element
106 myCurrentDemandElement = demandElement;
107 if (demandElement == nullptr) {
108 myDemandElementsMatchBox->setCustomText(TL("select item..."));
109 // set info label
110 myInfoLabel->setText((TL("-Select an item in the list or") + std::string("\n") + TL("click over an element in view")).c_str());
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(TL("select sub-item..."));
134 // set info label
135 const std::string info =
136 TL("-Clicked over multiple") + std::string("\n") +
137 TL("elements") + std::string("\n") +
138 TL(" - Select an item in the") + std::string("\n") +
139 TL(" list or click over an") + std::string("\n") +
140 TL(" element in view");
141 myInfoLabel->setText(info.c_str());
142 myInfoLabel->show();
143}
144
145
146void
148 // first refresh modul
150 // if current selected item isn't valid, set DEFAULT_VTYPE_ID or DEFAULT_PEDTYPE_ID
153 } else if (myDemandElementTags.size() == 1) {
154 if (myDemandElementTags.at(0) == SUMO_TAG_VTYPE) {
156 myDemandElementsMatchBox->setItem(defaultVType->getID().c_str(), defaultVType->getACIcon());
157 }
158 }
159 onCmdSelectDemandElement(nullptr, 0, nullptr);
160 show();
161}
162
163
164void
168
169
170bool
174
175
176void
178 // get demand elemenst container
179 const auto& demandElements = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements();
180 // clear demand elements comboBox
182 // fill myTypeMatchBox with list of demand elements
183 for (const auto& demandElementTag : myDemandElementTags) {
184 // special case for VTypes
185 if (demandElementTag == SUMO_TAG_VTYPE) {
186 // add default types in the first positions
193 // add rest of vTypes
194 for (const auto& vType : demandElements.at(demandElementTag)) {
195 // avoid insert duplicated default vType
196 if (DEFAULT_VTYPES.count(vType->getID()) == 0) {
197 myDemandElementsMatchBox->appendIconItem(vType->getID().c_str(), vType->getACIcon());
198 }
199 }
200 } else {
201 // insert all Ids
202 for (const auto& demandElement : demandElements.at(demandElementTag)) {
203 myDemandElementsMatchBox->appendIconItem(demandElement->getID().c_str(), demandElement->getACIcon());
204 }
205 }
206 }
207 // Set number of items (maximum 10)
210 } else {
212 }
213 // update myCurrentDemandElement
215 myCurrentDemandElement = nullptr;
216 } else if (myCurrentDemandElement) {
217 for (int i = 0; i < myDemandElementsMatchBox->getNumItems(); i++) {
220 }
221 }
222 } else {
223 // set first element in the list as myCurrentDemandElement (Special case for default person and vehicle type)
226 } else {
227 // disable myCurrentDemandElement
228 myCurrentDemandElement = nullptr;
229 // update myCurrentDemandElement with the first allowed element
230 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
231 if (demandElements.at(*i).size() > 0) {
232 myCurrentDemandElement = *demandElements.at(*i).begin();
233 }
234 }
235 }
236 }
237}
238
239
240GNEEdge*
242 if (myCurrentDemandElement == nullptr) {
243 return nullptr;
244 }
246 return nullptr;
247 }
249 return nullptr;
250 }
251 // get last person plan
252 const GNEDemandElement* lastPersonPlan = myCurrentDemandElement->getChildDemandElements().back();
253 // check tag
254 switch (lastPersonPlan->getTagProperty().getTag()) {
255 // person trips
257 // rides
259 // walks
262 // stops
264 return lastPersonPlan->getParentEdges().back();
265 // person trips
268 // person trips
271 // walks
274 // stops
277 return lastPersonPlan->getParentAdditionals().back()->getParentLanes().front()->getParentEdge();
278 // route walks
280 return lastPersonPlan->getParentDemandElements().back()->getParentEdges().back();
281 default:
282 return nullptr;
283 }
284}
285
286
287GNEEdge*
289 if (myCurrentDemandElement == nullptr) {
290 return nullptr;
291 }
293 return nullptr;
294 }
296 return nullptr;
297 }
298 // get last container plan
299 const GNEDemandElement* lastContainerPlan = myCurrentDemandElement->getChildDemandElements().back();
300 // check tag
301 switch (lastContainerPlan->getTagProperty().getTag()) {
302 // transport
304 // tranship
307 // stop
309 return lastContainerPlan->getParentEdges().back();
310 // transport
312 // tranship
314 // stop
316 return lastContainerPlan->getParentAdditionals().back()->getParentLanes().front()->getParentEdge();
317 default:
318 return nullptr;
319 }
320}
321
322
323long
325 // Check if value of myTypeMatchBox correspond to a demand element
326 for (const auto& demandElementTag : myDemandElementTags) {
327 for (const auto& demandElement : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(demandElementTag)) {
328 if (demandElement->getID() == myDemandElementsMatchBox->getText().text()) {
329 // set color of myTypeMatchBox to black (valid)
330 myDemandElementsMatchBox->setTextColor(FXRGB(0, 0, 0));
331 myDemandElementsMatchBox->killFocus();
332 // Set new current demand element
333 myCurrentDemandElement = demandElement;
334 // call demandElementSelected function
336 // Write Warning in console if we're in testing mode
337 WRITE_DEBUG((TL("Selected item '") + myDemandElementsMatchBox->getText() + TL("' in DemandElementSelector")).text());
338 myInfoLabel->hide();
339 return 1;
340 }
341 }
342 }
343 // if demand element selected is invalid, set demand element as null
344 myCurrentDemandElement = nullptr;
345 // call demandElementSelected function
347 // change color of myDemandElementsMatchBox to red (invalid)
348 myDemandElementsMatchBox->setTextColor(FXRGB(255, 0, 0));
349 // Write Warning in console if we're in testing mode
350 WRITE_DEBUG(TL("Selected invalid item in DemandElementSelector"));
351 return 1;
352}
353
354/****************************************************************************/
FXDEFMAP(DemandElementSelector) DemandElementSelectorMap[]
@ MID_GNE_SET_TYPE
used to select a type of element in a combo box
Definition GUIAppEnum.h:927
#define GUIDesignComboBox
Definition GUIDesigns.h:288
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:306
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:274
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:281
#define TL(string)
Definition MsgHandler.h:287
const std::string DEFAULT_TAXITYPE_ID
const std::string DEFAULT_RAILTYPE_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_PERSONTRIP_TRAINSTOP
@ GNE_TAG_WALK_BUSSTOP
@ GNE_TAG_RIDE_EDGE
@ GNE_TAG_TRANSHIP_EDGE
@ GNE_TAG_WALK_TRAINSTOP
@ GNE_TAG_STOPPERSON_TRAINSTOP
@ GNE_TAG_RIDE_TRAINSTOP
@ 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
MFXComboBoxIcon * myDemandElementsMatchBox
comboBox with the list of elements type
bool mySelectingMultipleElements
flag for enable/disable multiple element selection
long onCmdSelectDemandElement(FXObject *, FXSelector, void *)
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.
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:273
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:120
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
ComboBox with icon.
void setCurrentItem(FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
FXint getNumItems() const
Return the number of items in the list.
FXString getText() const
Get the text.
void setTextColor(FXColor clr)
Change text color.
void setNumVisible(FXint nvis)
Set the number of visible items in the drop down list.
void clearItems()
Remove all items from the list.
FXString getItem(FXint index) const
Return the item at the given index.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon
bool setItem(const FXString &text, FXIcon *icon)
set Item
void setCustomText(const FXString text)
set custom text
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)