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, const bool checkIcon) :
49 GNEDemandElementSelector(frameParent, std::vector<SumoXMLTag>({demandElementTag}), tagType, checkIcon) {
50}
51
52
53GNEDemandElementSelector::GNEDemandElementSelector(GNEFrame* frameParent, const std::vector<SumoXMLTag> demandElementTags, const GNETagProperties::Type tagType, const bool checkIcon) :
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 myCheckIcon(checkIcon) {
61 // Create MFXComboBoxIcon
64 // refresh demand element MatchBox
66 // shown after creation
67 show();
68}
69
70
71
72GNEDemandElementSelector::GNEDemandElementSelector(GNEFrame* frameParent, const std::vector<GNETagProperties::Type> tagTypes,
73 const std::vector<SumoXMLTag> exceptions, const bool checkIcon) :
74 GNEGroupBoxModule(frameParent, TL("Parent element")),
75 myFrameParent(frameParent),
76 myCurrentDemandElement(nullptr),
77 myTagType(GNETagProperties::Type::OTHER),
78 mySelectingMultipleElements(false),
79 myCheckIcon(checkIcon) {
80 // fill myDemandElementTags
81 for (const auto& tagType : tagTypes) {
82 const auto tagPropertiesByType = frameParent->getViewNet()->getNet()->getTagPropertiesDatabase()->getTagPropertiesByType(tagType);
83 for (const auto tagProperty : tagPropertiesByType) {
84 if (std::find(exceptions.begin(), exceptions.end(), tagProperty->getTag()) == exceptions.end()) {
85 myDemandElementTags.push_back(tagProperty->getTag());
86 }
87 }
88 }
89 // Create MFXComboBoxIcon
92 // refresh demand element MatchBox
94 // shown after creation
95 show();
96}
97
98
100
101
106
107
108const std::vector<SumoXMLTag>&
112
113
114void
117 // Set new current demand element
118 myCurrentDemandElement = demandElement;
119 if (demandElement != nullptr) {
120 // check that demandElement tag correspond to a tag of myDemandElementTags
121 if (std::find(myDemandElementTags.begin(), myDemandElementTags.end(), demandElement->getTagProperty()->getTag()) != myDemandElementTags.end()) {
122 // update text of myDemandElementsComboBox
123 myDemandElementsComboBox->setCurrentItem(demandElement->getID().c_str());
124 }
125 }
126 // call demandElementSelected function
128}
129
130
131void
132GNEDemandElementSelector::setDemandElements(const std::vector<GNEDemandElement*>& demandElements) {
134 myCurrentDemandElement = nullptr;
136 for (const auto& demandElement : demandElements) {
137 myDemandElementsComboBox->appendIconItem(demandElement->getID().c_str(), demandElement->getACIcon());
138 }
139}
140
141
142void
144 // first refresh modul
146 // if current selected item isn't valid, set DEFAULT_VTYPE_ID or DEFAULT_PEDTYPE_ID
149 } else if (myDemandElementTags.size() == 1) {
150 if (myDemandElementTags.at(0) == SUMO_TAG_VTYPE) {
152 myDemandElementsComboBox->setCurrentItem(defaultVType->getID().c_str());
153 }
154 }
155 onCmdSelectDemandElement(nullptr, 0, nullptr);
156 show();
157}
158
159
160void
164
165
166bool
170
171
172void
174 // get demand elemenst container
175 const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
176 // clear demand elements comboBox
178 // fill myTypeMatchBox with list of demand elements
179 for (const auto& demandElementTag : myDemandElementTags) {
180 // special case for VTypes
181 if (demandElementTag == SUMO_TAG_VTYPE) {
182 // add default types in the first positions depending of frame parent
184 // first pedestrian
192 // first container
199 } else {
200 // first default vType
207 }
208 // add rest of vTypes
209 for (const auto& vType : ACs->getDemandElements().at(demandElementTag)) {
210 // avoid insert duplicated default vType
211 if (DEFAULT_VTYPES.count(vType.second->getID()) == 0) {
212 myDemandElementsComboBox->appendIconItem(vType.second->getID().c_str(), vType.second->getACIcon());
213 }
214 }
215 } else {
216 // insert all elements sorted by ID
217 std::map<std::string, GNEDemandElement*> sortedElements;
218 for (const auto& demandElement : ACs->getDemandElements().at(demandElementTag)) {
219 sortedElements[demandElement.second->getID()] = demandElement.second;
220 }
221 for (const auto& demandElement : sortedElements) {
222 myDemandElementsComboBox->appendIconItem(demandElement.first.c_str(), demandElement.second->getACIcon(),
223 demandElement.second->getTagProperty()->getBackGroundColor());
224 }
225 }
226 }
227 // update myCurrentDemandElement
229 myCurrentDemandElement = nullptr;
230 } else if (myCurrentDemandElement) {
231 for (int i = 0; i < myDemandElementsComboBox->getNumItems(); i++) {
234 }
235 }
236 } else {
237 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
238 myCurrentDemandElement = ACs->retrieveDemandElement(*i, myDemandElementsComboBox->getItemText(0), false);
239 }
240 if (myCurrentDemandElement == nullptr) {
241 // update myCurrentDemandElement with the first allowed element
242 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
243 if (ACs->getDemandElements().at(*i).size() > 0) {
244 myCurrentDemandElement = ACs->getDemandElements().at(*i).begin()->second;
245 }
246 }
247 }
248 }
249}
250
251
254 if (myCurrentDemandElement == nullptr) {
255 return nullptr;
256 }
259 return nullptr;
260 }
262 return nullptr;
263 }
265}
266
267
268long
270 // Check if value of myTypeMatchBox correspond to a demand element
271 for (const auto& demandElementTag : myDemandElementTags) {
272 for (const auto& demandElement : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(demandElementTag)) {
273 if (demandElement.second->getID() == myDemandElementsComboBox->getText().text()) {
274 // check if we have to compare the icons
275 if (myCheckIcon && (demandElement.second->getACIcon() != myDemandElementsComboBox->getIcon())) {
276 continue;
277 }
278 // set color of myTypeMatchBox to black (valid)
280 myDemandElementsComboBox->killFocus();
281 // Set new current demand element
282 myCurrentDemandElement = demandElement.second;
283 // call demandElementSelected function
285 return 1;
286 }
287 }
288 }
289 // if demand element selected is invalid, set demand element as null
290 myCurrentDemandElement = nullptr;
291 // call demandElementSelected function
293 // change color of myDemandElementsComboBox to red (invalid)
295 return 1;
296}
297
298/****************************************************************************/
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
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 myCheckIcon
flag to check if we have to compare icons when we choose an element in the comboBox
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 *)
GNEDemandElementSelector(GNEFrame *frameParent, SumoXMLTag demandElementTag, const GNETagProperties::Type tagType, const bool checkIcon)
FOX-declaration.
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.
FXIcon * getIcon() const
Get the icon.
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