Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNETagSelector.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 tags
19/****************************************************************************/
20
23#include <netedit/GNENet.h>
25#include <netedit/GNEViewNet.h>
29
30#include "GNETagSelector.h"
31
32// ===========================================================================
33// FOX callback mapping
34// ===========================================================================
35
36FXDEFMAP(GNETagSelector) TagSelectorMap[] = {
38};
39
40// Object implementation
41FXIMPLEMENT(GNETagSelector, MFXGroupBoxModule, TagSelectorMap, ARRAYNUMBER(TagSelectorMap))
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46
47GNETagSelector::GNETagSelector(GNEFrame* frameParent, const GNETagProperties::Type type, const SumoXMLTag tag) :
48 MFXGroupBoxModule(frameParent, TL("Element")),
49 myFrameParent(frameParent),
50 myCurrentTemplateAC(nullptr) {
51 // Create MFXComboBoxIcon
52 myTagsMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), frameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
54 // update tag types without informing parent (because we're in the creator
55 updateTagTypes(type, tag, false);
56 // GNETagSelector is always shown
57 show();
58}
59
60
62
63
64void
68
69
70void
74
75
80
81
82void
83GNETagSelector::updateTagTypes(const GNETagProperties::Type type, const SumoXMLTag newTag, const bool informParent) {
84 // check if net has proj
85 const bool proj = (GeoConvHelper::getFinal().getProjString() != "!");
86 // change GNETagSelector text
87 switch (type) {
89 setText(TL("network elements"));
90 break;
92 setText(TL("Additional elements"));
93 break;
95 setText(TL("Shape elements"));
96 break;
98 setText(TL("TAZ elements"));
99 break;
101 setText(TL("Wire elements"));
102 break;
104 setText(TL("Vehicles"));
105 break;
107 setText(TL("Stops"));
108 break;
110 setText(TL("Persons"));
111 break;
113 setText(TL("Person plans"));
114 break;
116 setText(TL("Container"));
117 break;
119 setText(TL("Container plans"));
120 break;
122 setText(TL("Person trips"));
123 break;
125 setText(TL("Walks"));
126 break;
128 setText(TL("Rides"));
129 break;
131 setText(TL("Person stops"));
132 break;
133 default:
134 throw ProcessError("invalid tag property");
135 }
136 myTagsMatchBox->clearItems();
137 // get tag properties
138 const auto tagPropertiesByType = myFrameParent->getViewNet()->getNet()->getTagPropertiesDatabase()->getTagPropertiesByType(type);
139 // fill myACTemplates and myTagsMatchBox
140 for (const auto tagProperty : tagPropertiesByType) {
141 if ((!tagProperty->requireProj() || proj) && !tagProperty->isListedElement() && !tagProperty->isSymbol()) {
142 myTagsMatchBox->appendIconItem(tagProperty->getSelectorText().c_str(), GUIIconSubSys::getIcon(tagProperty->getGUIIcon()), tagProperty->getBackGroundColor());
143 }
144 }
145 if (myTagsMatchBox->getNumItems() > 0) {
146 myTagsMatchBox->enable();
147 setCurrentTag(newTag, informParent);
148 } else {
149 myTagsMatchBox->disable();
150 }
151}
152
153
154void
155GNETagSelector::setCurrentTag(SumoXMLTag newTag, const bool informParent) {
156 // first reset myCurrentTemplateAC
157 myCurrentTemplateAC = myFrameParent->getViewNet()->getNet()->getACTemplates()->getTemplateAC(newTag);
158 // iterate over all myTagsMatchBox
159 for (int i = 0; i < myTagsMatchBox->getNumItems(); i++) {
160 if (myTagsMatchBox->getItemText(i) == myCurrentTemplateAC->getTagProperty()->getTagStr()) {
161 myTagsMatchBox->setCurrentItem(i);
162 // set color of myTypeMatchBox to black (valid)
164 myTagsMatchBox->killFocus();
165 }
166 }
167 // inform to frame parent that a tag was selected
168 if (informParent) {
169 myFrameParent->tagSelected();
170 }
171}
172
173
174void
176 // call tag selected function
177 myFrameParent->tagSelected();
178}
179
180
181long
182GNETagSelector::onCmdSelectTag(FXObject*, FXSelector, void*) {
183 myCurrentTemplateAC = myFrameParent->getViewNet()->getNet()->getACTemplates()->getTemplateAC(myTagsMatchBox->getText().text());
185 // set color of myTypeMatchBox to black (valid)
187 myTagsMatchBox->killFocus();
188 } else {
189 // set color of myTypeMatchBox to red (invalid)
191 }
192 // inform to frame parent that a tag was selected
193 myFrameParent->tagSelected();
194 return 1;
195}
196
197/****************************************************************************/
FXDEFMAP(GNETagSelector) TagSelectorMap[]
@ MID_GNE_TAG_SELECTED
tag selected in ComboBox
#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
#define TL(string)
Definition MsgHandler.h:304
SumoXMLTag
Numbers representing SUMO-XML - element names.
MFXComboBoxIcon * myTagsMatchBox
comboBox with the tags
GNEAttributeCarrier * myCurrentTemplateAC
current templateAC;
void updateTagTypes(const GNETagProperties::Type type, const SumoXMLTag tag, const bool informParent)
update tag types to select
void refreshTagSelector()
refresh tagSelector (used when frameParent is show)
void showTagSelector()
show item selector
void setCurrentTag(SumoXMLTag newTag, const bool informParent=true)
set current type manually
long onCmdSelectTag(FXObject *, FXSelector, void *ptr)
GNEFrame * myFrameParent
FOX need this.
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
void hideTagSelector()
hide item selector
~GNETagSelector()
destructor
GNETagSelector(GNEFrame *frameParent, const GNETagProperties::Type type, const SumoXMLTag tag)
FOX-declaration.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
const std::string & getProjString() const
Returns the original projection definition.
MFXGroupBoxModule (based on FXGroupBox).
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
void setText(const std::string &text)
set text
MFXGroupBoxModule(GNEFrame *frame, const std::string &text, const int options=Options::COLLAPSIBLE)
constructor for frames