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-2026 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, GNEGroupBoxModule, DemandElementSelectorMap, ARRAYNUMBER(DemandElementSelectorMap))
42
43
44// ===========================================================================
45// method definitions
46// ===========================================================================
47
48GNEDemandElementSelector::GNEDemandElementSelector(GNEFrame* frameParent, SumoXMLTag demandElementTag, const GNETagProperties::Type tagType) :
49 GNEDemandElementSelector(frameParent, std::vector<SumoXMLTag>({demandElementTag}), tagType) {
50}
51
52
53GNEDemandElementSelector::GNEDemandElementSelector(GNEFrame* frameParent, const std::vector<SumoXMLTag> demandElementTags, const GNETagProperties::Type tagType) :
54 GNEGroupBoxModule(frameParent, TLF("Parent %", toString(demandElementTags.front())).c_str()),
55 myFrameParent(frameParent),
56 myCurrentDemandElement(nullptr),
57 myDemandElementTags(demandElementTags),
58 myTagType(tagType),
59 mySelectingMultipleElements(false) {
60 // Create MFXComboBoxIcon
63 // refresh demand element MatchBox
65 // shown after creation
66 show();
67}
68
69
70
71GNEDemandElementSelector::GNEDemandElementSelector(GNEFrame* frameParent, const std::vector<GNETagProperties::Type> tagTypes,
72 const std::vector<SumoXMLTag> exceptions) :
73 GNEGroupBoxModule(frameParent, TL("Parent element")),
74 myFrameParent(frameParent),
75 myCurrentDemandElement(nullptr),
76 myTagType(GNETagProperties::Type::OTHER),
77 mySelectingMultipleElements(false) {
78 // fill myDemandElementTags
79 for (const auto& tagType : tagTypes) {
80 const auto tagPropertiesByType = frameParent->getViewNet()->getNet()->getTagPropertiesDatabase()->getTagPropertiesByType(tagType);
81 for (const auto tagProperty : tagPropertiesByType) {
82 if (std::find(exceptions.begin(), exceptions.end(), tagProperty->getTag()) == exceptions.end()) {
83 myDemandElementTags.push_back(tagProperty->getTag());
84 }
85 }
86 }
87 // Create MFXComboBoxIcon
90 // refresh demand element MatchBox
92 // shown after creation
93 show();
94}
95
96
98
99
104
105
106const std::vector<SumoXMLTag>&
110
111
112void
115 // Set new current demand element
116 myCurrentDemandElement = demandElement;
117 if (demandElement != nullptr) {
118 // check that demandElement tag correspond to a tag of myDemandElementTags
119 if (std::find(myDemandElementTags.begin(), myDemandElementTags.end(), demandElement->getTagProperty()->getTag()) != myDemandElementTags.end()) {
120 // update text of myDemandElementsComboBox
121 myDemandElementsComboBox->setCurrentItem(demandElement->getID().c_str());
122 }
123 }
124 // call demandElementSelected function
126}
127
128
129void
130GNEDemandElementSelector::setDemandElements(const std::vector<GNEDemandElement*>& demandElements) {
132 myCurrentDemandElement = nullptr;
134 for (const auto& demandElement : demandElements) {
135 myDemandElementsComboBox->appendIconItem(demandElement->getID().c_str(), demandElement->getACIcon());
136 }
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 myDemandElementsComboBox->setCurrentItem(defaultVType->getID().c_str());
151 }
152 }
153 onCmdSelectDemandElement(nullptr, 0, nullptr);
154 show();
155}
156
157
158void
162
163
164bool
168
169
170void
172 // get demand elemenst container
173 const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
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 depending of frame parent
182 // first pedestrian
190 // first container
197 } else {
198 // first default vType
205 }
206 // add rest of vTypes
207 for (const auto& vType : ACs->getDemandElements().at(demandElementTag)) {
208 // avoid insert duplicated default vType
209 if (DEFAULT_VTYPES.count(vType.second->getID()) == 0) {
210 myDemandElementsComboBox->appendIconItem(vType.second->getID().c_str(), vType.second->getACIcon());
211 }
212 }
213 } else {
214 // insert all elements sorted by ID
215 std::map<std::string, GNEDemandElement*> sortedElements;
216 for (const auto& demandElement : ACs->getDemandElements().at(demandElementTag)) {
217 sortedElements[demandElement.second->getID()] = demandElement.second;
218 }
219 for (const auto& demandElement : sortedElements) {
220 myDemandElementsComboBox->appendIconItem(demandElement.first.c_str(), demandElement.second->getACIcon(),
221 demandElement.second->getTagProperty()->getBackGroundColor());
222 }
223 }
224 }
225 // update myCurrentDemandElement
227 myCurrentDemandElement = nullptr;
228 } else if (myCurrentDemandElement) {
229 for (int i = 0; i < myDemandElementsComboBox->getNumItems(); i++) {
232 }
233 }
234 } else {
235 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
236 myCurrentDemandElement = ACs->retrieveDemandElement(*i, myDemandElementsComboBox->getItemText(0), false);
237 }
238 if (myCurrentDemandElement == nullptr) {
239 // update myCurrentDemandElement with the first allowed element
240 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
241 if (ACs->getDemandElements().at(*i).size() > 0) {
242 myCurrentDemandElement = ACs->getDemandElements().at(*i).begin()->second;
243 }
244 }
245 }
246 }
247}
248
249
252 if (myCurrentDemandElement == nullptr) {
253 return nullptr;
254 }
257 return nullptr;
258 }
260 return nullptr;
261 }
263}
264
265
266long
268 // Check if value of myTypeMatchBox correspond to a demand element
269 for (const auto& demandElementTag : myDemandElementTags) {
270 for (const auto& demandElement : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(demandElementTag)) {
271 if (demandElement.second->getID() == myDemandElementsComboBox->getText().text()) {
272 // set color of myTypeMatchBox to black (valid)
274 myDemandElementsComboBox->killFocus();
275 // Set new current demand element
276 myCurrentDemandElement = demandElement.second;
277 // call demandElementSelected function
279 return 1;
280 }
281 }
282 }
283 // if demand element selected is invalid, set demand element as null
284 myCurrentDemandElement = nullptr;
285 // call demandElementSelected function
287 // change color of myDemandElementsComboBox to red (invalid)
289 return 1;
290}
291
292/****************************************************************************/
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:49
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
virtual void demandElementSelected()
selected demand element in DemandElementSelector
Definition GNEFrame.cpp:208
GNEGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
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:174
const GNETagPropertiesDatabase * getTagPropertiesDatabase() const
get tag properties database (used for simplify code)
Definition GNENet.cpp:162
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
Definition json.hpp:4471