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-2025 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
23#include <netedit/GNENet.h>
25#include <netedit/GNEViewNet.h>
29
30#include "GNEDemandSelector.h"
31
32// ===========================================================================
33// FOX callback mapping
34// ===========================================================================
35
36FXDEFMAP(GNEDemandElementSelector) DemandElementSelectorMap[] = {
38};
39
40// Object implementation
41FXIMPLEMENT(GNEDemandElementSelector, MFXGroupBoxModule, DemandElementSelectorMap, ARRAYNUMBER(DemandElementSelectorMap))
42
43
44// ===========================================================================
45// method definitions
46// ===========================================================================
47
48GNEDemandElementSelector::GNEDemandElementSelector(GNEFrame* frameParent, SumoXMLTag demandElementTag, const GNETagProperties::Type tagType) :
49 MFXGroupBoxModule(frameParent, TLF("Parent %", toString(demandElementTag)).c_str()),
50 myFrameParent(frameParent),
52 myDemandElementTags({demandElementTag}),
53 myTagType(tagType),
54mySelectingMultipleElements(false) {
55 // Create MFXComboBoxIcon
56 myDemandElementsComboBox = new MFXComboBoxIcon(getCollapsableFrame(), frameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
58 // refresh demand element MatchBox
59 refreshDemandElementSelector();
60 // shown after creation
61 show();
62}
63
64
65GNEDemandElementSelector::GNEDemandElementSelector(GNEFrame* frameParent, const std::vector<GNETagProperties::Type> tagTypes,
66 const std::vector<SumoXMLTag> exceptions) :
67 MFXGroupBoxModule(frameParent, TL("Parent element")),
68 myFrameParent(frameParent),
70 myTagType(GNETagProperties::Type::OTHER),
72 // fill myDemandElementTags
73 for (const auto& tagType : tagTypes) {
74 const auto tagPropertiesByType = frameParent->getViewNet()->getNet()->getTagPropertiesDatabase()->getTagPropertiesByType(tagType);
75 for (const auto tagProperty : tagPropertiesByType) {
76 if (std::find(exceptions.begin(), exceptions.end(), tagProperty->getTag()) == exceptions.end()) {
77 myDemandElementTags.push_back(tagProperty->getTag());
78 }
79 }
80 }
81 // Create MFXComboBoxIcon
84 // refresh demand element MatchBox
86 // shown after creation
87 show();
88}
89
90
92
93
98
99
100const std::vector<SumoXMLTag>&
104
105
106void
109 // Set new current demand element
110 myCurrentDemandElement = demandElement;
111 if (demandElement != nullptr) {
112 // check that demandElement tag correspond to a tag of myDemandElementTags
113 if (std::find(myDemandElementTags.begin(), myDemandElementTags.end(), demandElement->getTagProperty()->getTag()) != myDemandElementTags.end()) {
114 // update text of myDemandElementsComboBox
115 myDemandElementsComboBox->setCurrentItem(demandElement->getID().c_str());
116 }
117 }
118 // call demandElementSelected function
119 myFrameParent->demandElementSelected();
120}
121
122
123void
124GNEDemandElementSelector::setDemandElements(const std::vector<GNEDemandElement*>& demandElements) {
126 myCurrentDemandElement = nullptr;
127 myDemandElementsComboBox->clearItems();
128 for (const auto& demandElement : demandElements) {
129 myDemandElementsComboBox->appendIconItem(demandElement->getID().c_str(), demandElement->getACIcon());
130 }
131}
132
133
134void
136 // first refresh modul
138 // if current selected item isn't valid, set DEFAULT_VTYPE_ID or DEFAULT_PEDTYPE_ID
140 myDemandElementsComboBox->setCurrentItem(myCurrentDemandElement->getID().c_str());
141 } else if (myDemandElementTags.size() == 1) {
142 if (myDemandElementTags.at(0) == SUMO_TAG_VTYPE) {
143 const auto defaultVType = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID);
144 myDemandElementsComboBox->setCurrentItem(defaultVType->getID().c_str());
145 }
146 }
147 onCmdSelectDemandElement(nullptr, 0, nullptr);
148 show();
149}
150
151
152void
156
157
158bool
162
163
164void
166 // get demand elemenst container
167 const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
168 // clear demand elements comboBox
169 myDemandElementsComboBox->clearItems();
170 // fill myTypeMatchBox with list of demand elements
171 for (const auto& demandElementTag : myDemandElementTags) {
172 // special case for VTypes
173 if (demandElementTag == SUMO_TAG_VTYPE) {
174 // add default types in the first positions depending of frame parent
176 // first pedestrian
177 myDemandElementsComboBox->appendIconItem(DEFAULT_PEDTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_PEDESTRIAN), FXRGBA(253, 255, 206, 255));
178 myDemandElementsComboBox->appendIconItem(DEFAULT_VTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_DEFAULT), FXRGBA(253, 255, 206, 255));
179 myDemandElementsComboBox->appendIconItem(DEFAULT_BIKETYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_BIKE), FXRGBA(253, 255, 206, 255));
180 myDemandElementsComboBox->appendIconItem(DEFAULT_TAXITYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_TAXI), FXRGBA(253, 255, 206, 255));
181 myDemandElementsComboBox->appendIconItem(DEFAULT_RAILTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_RAIL), FXRGBA(253, 255, 206, 255));
182 myDemandElementsComboBox->appendIconItem(DEFAULT_CONTAINERTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_CONTAINER), FXRGBA(253, 255, 206, 255));
184 // first container
185 myDemandElementsComboBox->appendIconItem(DEFAULT_CONTAINERTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_CONTAINER), FXRGBA(253, 255, 206, 255));
186 myDemandElementsComboBox->appendIconItem(DEFAULT_VTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_DEFAULT), FXRGBA(253, 255, 206, 255));
187 myDemandElementsComboBox->appendIconItem(DEFAULT_BIKETYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_BIKE), FXRGBA(253, 255, 206, 255));
188 myDemandElementsComboBox->appendIconItem(DEFAULT_TAXITYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_RAIL), FXRGBA(253, 255, 206, 255));
189 myDemandElementsComboBox->appendIconItem(DEFAULT_RAILTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_RAIL), FXRGBA(253, 255, 206, 255));
190 myDemandElementsComboBox->appendIconItem(DEFAULT_PEDTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_PEDESTRIAN), FXRGBA(253, 255, 206, 255));
191 } else {
192 // first default vType
193 myDemandElementsComboBox->appendIconItem(DEFAULT_VTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_DEFAULT), FXRGBA(253, 255, 206, 255));
194 myDemandElementsComboBox->appendIconItem(DEFAULT_BIKETYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_BIKE), FXRGBA(253, 255, 206, 255));
195 myDemandElementsComboBox->appendIconItem(DEFAULT_TAXITYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_TAXI), FXRGBA(253, 255, 206, 255));
196 myDemandElementsComboBox->appendIconItem(DEFAULT_RAILTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_RAIL), FXRGBA(253, 255, 206, 255));
197 myDemandElementsComboBox->appendIconItem(DEFAULT_PEDTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_PEDESTRIAN), FXRGBA(253, 255, 206, 255));
198 myDemandElementsComboBox->appendIconItem(DEFAULT_CONTAINERTYPE_ID.c_str(), GUIIconSubSys::getIcon(GUIIcon::VTYPE_CONTAINER), FXRGBA(253, 255, 206, 255));
199 }
200 // add rest of vTypes
201 for (const auto& vType : ACs->getDemandElements().at(demandElementTag)) {
202 // avoid insert duplicated default vType
203 if (DEFAULT_VTYPES.count(vType.second->getID()) == 0) {
204 myDemandElementsComboBox->appendIconItem(vType.second->getID().c_str(), vType.second->getACIcon());
205 }
206 }
207 } else {
208 // insert all elements sorted by ID
209 std::map<std::string, GNEDemandElement*> sortedElements;
210 for (const auto& demandElement : ACs->getDemandElements().at(demandElementTag)) {
211 sortedElements[demandElement.second->getID()] = demandElement.second;
212 }
213 for (const auto& demandElement : sortedElements) {
214 myDemandElementsComboBox->appendIconItem(demandElement.first.c_str(), demandElement.second->getACIcon(),
215 demandElement.second->getTagProperty()->getBackGroundColor());
216 }
217 }
218 }
219 // update myCurrentDemandElement
220 if (myDemandElementsComboBox->getNumItems() == 0) {
221 myCurrentDemandElement = nullptr;
222 } else if (myCurrentDemandElement) {
223 for (int i = 0; i < myDemandElementsComboBox->getNumItems(); i++) {
224 if (myDemandElementsComboBox->getItemText(i) == myCurrentDemandElement->getID()) {
225 myDemandElementsComboBox->setCurrentItem(i, FALSE);
226 }
227 }
228 } else {
229 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
230 myCurrentDemandElement = ACs->retrieveDemandElement(*i, myDemandElementsComboBox->getItemText(0), false);
231 }
232 if (myCurrentDemandElement == nullptr) {
233 // update myCurrentDemandElement with the first allowed element
234 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
235 if (ACs->getDemandElements().at(*i).size() > 0) {
236 myCurrentDemandElement = ACs->getDemandElements().at(*i).begin()->second;
237 }
238 }
239 }
240 }
241}
242
243
246 if (myCurrentDemandElement == nullptr) {
247 return nullptr;
248 }
249 if (!myCurrentDemandElement->getTagProperty()->isPerson() &&
250 !myCurrentDemandElement->getTagProperty()->isContainer()) {
251 return nullptr;
252 }
253 if (myCurrentDemandElement->getChildDemandElements().empty()) {
254 return nullptr;
255 }
256 return myCurrentDemandElement->getChildDemandElements().back();
257}
258
259
260long
262 // Check if value of myTypeMatchBox correspond to a demand element
263 for (const auto& demandElementTag : myDemandElementTags) {
264 for (const auto& demandElement : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(demandElementTag)) {
265 if (demandElement.second->getID() == myDemandElementsComboBox->getText().text()) {
266 // set color of myTypeMatchBox to black (valid)
268 myDemandElementsComboBox->killFocus();
269 // Set new current demand element
270 myCurrentDemandElement = demandElement.second;
271 // call demandElementSelected function
272 myFrameParent->demandElementSelected();
273 return 1;
274 }
275 }
276 }
277 // if demand element selected is invalid, set demand element as null
278 myCurrentDemandElement = nullptr;
279 // call demandElementSelected function
280 myFrameParent->demandElementSelected();
281 // change color of myDemandElementsComboBox to red (invalid)
283 return 1;
284}
285
286/****************************************************************************/
FXDEFMAP(GNEDemandElementSelector) DemandElementSelectorMap[]
@ MID_GNE_SET_TYPE
used to select a type of element in a combo box
#define GUIDesignTextColorRed
red color (for invalid text)
Definition GUIDesigns.h:44
#define GUIDesignComboBox
Definition GUIDesigns.h:295
#define GUIDesignComboBoxVisibleItems
Definition GUIDesigns.h:64
#define GUIDesignTextColorBlack
black color (for correct text)
Definition GUIDesigns.h:38
@ VTYPE_CONTAINER
Definition GUIIcons.h:502
@ VTYPE_RAIL
Definition GUIIcons.h:500
@ VTYPE_BIKE
Definition GUIIcons.h:498
@ VTYPE_TAXI
Definition GUIIcons.h:499
@ VTYPE_PEDESTRIAN
Definition GUIIcons.h:501
@ VTYPE_DEFAULT
Definition GUIIcons.h:497
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
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.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string getID() const override
get ID (all Attribute Carriers have one)
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
std::vector< SumoXMLTag > myDemandElementTags
demand element tags
GNEDemandElementSelector(GNEFrame *frameParent, SumoXMLTag demandElementTag, const GNETagProperties::Type tagType)
FOX-declaration.
void setDemandElements(const std::vector< GNEDemandElement * > &demandElements)
set multiple demand elements to filter
GNEDemandElement * getPreviousPlanElement() const
get previous plan element
GNEFrame * myFrameParent
FOX need this.
bool isDemandElementSelectorShown() const
check if demand element selector is shown
void showDemandElementSelector()
show demand element selector
void setDemandElement(GNEDemandElement *demandElement)
set current demand element
long onCmdSelectDemandElement(FXObject *, FXSelector, void *)
void refreshDemandElementSelector()
refresh demand element selector
GNEDemandElement * myCurrentDemandElement
current demand element
GNEDemandElement * getCurrentDemandElement() const
get current demand element
bool mySelectingMultipleElements
flag for enable/disable multiple element selection
const std::vector< SumoXMLTag > & getAllowedTags() const
MFXComboBoxIcon * myDemandElementsComboBox
comboBox with the list of elements type
void hideDemandElementSelector()
hide demand element selector
GNETagProperties::Type myTagType
tag type (person, container or vehicle)
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:145
const GNETagPropertiesDatabase * getTagPropertiesDatabase() const
get tag properties database
Definition GNENet.cpp:138
const std::vector< const GNETagProperties * > getTagPropertiesByType(const GNETagProperties::Type type) const
get tagProperties associated to the given GNETagProperties::Type (NETWORKELEMENT, ADDITIONALELEMENT,...
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
GNENet * getNet() const
get the net object
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXStaticToolTip * getStaticTooltipMenu() const
get static toolTip for menus
MFXGroupBoxModule (based on FXGroupBox).
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
MFXGroupBoxModule(GNEFrame *frame, const std::string &text, const int options=Options::COLLAPSIBLE)
constructor for frames