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),
51 myCurrentDemandElement(nullptr),
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),
69 myCurrentDemandElement(nullptr),
70 myTagType(GNETagProperties::Type::OTHER),
71 mySelectingMultipleElements(false) {
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
120}
121
122
123void
124GNEDemandElementSelector::setDemandElements(const std::vector<GNEDemandElement*>& demandElements) {
126 myCurrentDemandElement = nullptr;
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
141 } else if (myDemandElementTags.size() == 1) {
142 if (myDemandElementTags.at(0) == SUMO_TAG_VTYPE) {
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
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
184 // first container
191 } else {
192 // first default vType
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
221 myCurrentDemandElement = nullptr;
222 } else if (myCurrentDemandElement) {
223 for (int i = 0; i < myDemandElementsComboBox->getNumItems(); i++) {
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 }
251 return nullptr;
252 }
254 return nullptr;
255 }
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
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
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
@ VTYPE_PEDESTRIAN
@ VTYPE_DEFAULT
#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
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:152
virtual void demandElementSelected()
selected demand element in DemandElementSelector
Definition GNEFrame.cpp:214
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::unordered_map< SumoXMLTag, std::unordered_map< const GUIGlObject *, GNEDemandElement * >, std::hash< int > > & getDemandElements() const
get demand elements
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
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,...
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
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
long setCurrentItem(const 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.
virtual void clearItems()
Remove all items from the list.
std::string getItemText(FXint index) const
Get text for specified item.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon item in the last position
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)