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-2024 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(GNEDemandElementSelector) DemandElementSelectorMap[] = {
37};
38
39// Object implementation
40FXIMPLEMENT(GNEDemandElementSelector, MFXGroupBoxModule, DemandElementSelectorMap, ARRAYNUMBER(DemandElementSelectorMap))
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46
47GNEDemandElementSelector::GNEDemandElementSelector(GNEFrame* frameParent, SumoXMLTag demandElementTag, int tagType) :
48 MFXGroupBoxModule(frameParent, (TL("Parent ") + toString(demandElementTag)).c_str()),
49 myFrameParent(frameParent),
50 myCurrentDemandElement(nullptr),
51 myDemandElementTags({demandElementTag}),
52 myTagType(tagType),
53mySelectingMultipleElements(false) {
54 // Create MFXComboBoxIcon
55 myDemandElementsComboBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, true, GUIDesignComboBoxVisibleItemsMedium,
57 // refresh demand element MatchBox
58 refreshDemandElementSelector();
59 // shown after creation
60 show();
61}
62
63
64GNEDemandElementSelector::GNEDemandElementSelector(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, false);
72 for (const auto& tagProperty : tagProperties) {
73 myDemandElementTags.push_back(tagProperty.getTag());
74 }
75 }
76 // Create MFXComboBoxIcon
79 // refresh demand element MatchBox
81 // shown after creation
82 show();
83}
84
85
87
88
93
94
95const std::vector<SumoXMLTag>&
99
100
101void
104 // Set new current demand element
105 myCurrentDemandElement = demandElement;
106 if (demandElement != nullptr) {
107 // check that demandElement tag correspond to a tag of myDemandElementTags
108 if (std::find(myDemandElementTags.begin(), myDemandElementTags.end(), demandElement->getTagProperty().getTag()) != myDemandElementTags.end()) {
109 // update text of myDemandElementsComboBox
110 myDemandElementsComboBox->setCurrentItem(demandElement->getID().c_str());
111 }
112 }
113 // call demandElementSelected function
115}
116
117
118void
119GNEDemandElementSelector::setDemandElements(const std::vector<GNEDemandElement*>& demandElements) {
121 myCurrentDemandElement = nullptr;
123 for (const auto& demandElement : demandElements) {
124 myDemandElementsComboBox->appendIconItem(demandElement->getID().c_str(), demandElement->getACIcon());
125 }
126}
127
128
129void
131 // first refresh modul
133 // if current selected item isn't valid, set DEFAULT_VTYPE_ID or DEFAULT_PEDTYPE_ID
136 } else if (myDemandElementTags.size() == 1) {
137 if (myDemandElementTags.at(0) == SUMO_TAG_VTYPE) {
139 myDemandElementsComboBox->setCurrentItem(defaultVType->getID().c_str());
140 }
141 }
142 onCmdSelectDemandElement(nullptr, 0, nullptr);
143 show();
144}
145
146
147void
151
152
153bool
157
158
159void
161 // get demand elemenst container
162 const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
163 // clear demand elements comboBox
165 // fill myTypeMatchBox with list of demand elements
166 for (const auto& demandElementTag : myDemandElementTags) {
167 // special case for VTypes
168 if (demandElementTag == SUMO_TAG_VTYPE) {
169 // add default types in the first positions depending of frame parent
171 // first pedestrian
179 // first container
186 } else {
187 // first default vType
194 }
195 // add rest of vTypes
196 for (const auto& vType : ACs->getDemandElements().at(demandElementTag)) {
197 // avoid insert duplicated default vType
198 if (DEFAULT_VTYPES.count(vType.second->getID()) == 0) {
199 myDemandElementsComboBox->appendIconItem(vType.second->getID().c_str(), vType.second->getACIcon());
200 }
201 }
202 } else {
203 // insert all elements sorted by ID
204 std::map<std::string, GNEDemandElement*> sortedElements;
205 for (const auto& demandElement : ACs->getDemandElements().at(demandElementTag)) {
206 sortedElements[demandElement.second->getID()] = demandElement.second;
207 }
208 for (const auto& demandElement : sortedElements) {
209 myDemandElementsComboBox->appendIconItem(demandElement.first.c_str(), demandElement.second->getACIcon(),
210 demandElement.second->getTagProperty().getBackGroundColor());
211 }
212 }
213 }
214 // update myCurrentDemandElement
216 myCurrentDemandElement = nullptr;
217 } else if (myCurrentDemandElement) {
218 for (int i = 0; i < myDemandElementsComboBox->getNumItems(); i++) {
221 }
222 }
223 } else {
224 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
225 myCurrentDemandElement = ACs->retrieveDemandElement(*i, myDemandElementsComboBox->getItemText(0), false);
226 }
227 if (myCurrentDemandElement == nullptr) {
228 // update myCurrentDemandElement with the first allowed element
229 for (auto i = myDemandElementTags.begin(); (i != myDemandElementTags.end()) && (myCurrentDemandElement == nullptr); i++) {
230 if (ACs->getDemandElements().at(*i).size() > 0) {
231 myCurrentDemandElement = ACs->getDemandElements().at(*i).begin()->second;
232 }
233 }
234 }
235 }
236}
237
238
241 if (myCurrentDemandElement == nullptr) {
242 return nullptr;
243 }
246 return nullptr;
247 }
249 return nullptr;
250 }
252}
253
254
255long
257 // Check if value of myTypeMatchBox correspond to a demand element
258 for (const auto& demandElementTag : myDemandElementTags) {
259 for (const auto& demandElement : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(demandElementTag)) {
260 if (demandElement.second->getID() == myDemandElementsComboBox->getText().text()) {
261 // set color of myTypeMatchBox to black (valid)
262 myDemandElementsComboBox->setTextColor(FXRGB(0, 0, 0));
263 myDemandElementsComboBox->killFocus();
264 // Set new current demand element
265 myCurrentDemandElement = demandElement.second;
266 // call demandElementSelected function
268 // Write Warning in console if we're in testing mode
269 WRITE_DEBUG((TL("Selected item '") + myDemandElementsComboBox->getText() + TL("' in DemandElementSelector")).text());
270 return 1;
271 }
272 }
273 }
274 // if demand element selected is invalid, set demand element as null
275 myCurrentDemandElement = nullptr;
276 // call demandElementSelected function
278 // change color of myDemandElementsComboBox to red (invalid)
279 myDemandElementsComboBox->setTextColor(FXRGB(255, 0, 0));
280 // Write Warning in console if we're in testing mode
281 WRITE_DEBUG(TL("Selected invalid item in DemandElementSelector"));
282 return 1;
283}
284
285/****************************************************************************/
FXDEFMAP(GNEDemandElementSelector) DemandElementSelectorMap[]
@ MID_GNE_SET_TYPE
used to select a type of element in a combo box
Definition GUIAppEnum.h:959
#define GUIDesignComboBox
Definition GUIDesigns.h:299
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:317
#define GUIDesignComboBoxVisibleItemsMedium
combo box medium small
Definition GUIDesigns.h:53
@ VTYPE_CONTAINER
@ VTYPE_PEDESTRIAN
@ VTYPE_DEFAULT
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
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)
static const std::vector< GNETagProperties > getTagPropertiesByType(const int tagPropertyCategory, const bool mergeCommonPlans)
get tagProperties associated to the given GNETagProperties::TagType (NETWORKELEMENT,...
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
std::vector< SumoXMLTag > myDemandElementTags
demand element tags
GNEDemandElementSelector(GNEFrame *frameParent, SumoXMLTag demandElementTag, int 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
int myTagType
tag type (person, container or vehicle)
void hideDemandElementSelector()
hide demand element selector
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
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
const std::map< SumoXMLTag, std::map< const GUIGlObject *, GNEDemandElement * > > & getDemandElements() const
get demand elements
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:125
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.
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.
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)