Eclipse SUMO - Simulation of Urban MObility
GNETagSelector.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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#include <config.h>
21
22#include <netedit/GNEViewNet.h>
68
69#include "GNETagSelector.h"
70
71
72// ===========================================================================
73// FOX callback mapping
74// ===========================================================================
75
76FXDEFMAP(GNETagSelector) TagSelectorMap[] = {
78};
79
80// Object implementation
81FXIMPLEMENT(GNETagSelector, MFXGroupBoxModule, TagSelectorMap, ARRAYNUMBER(TagSelectorMap))
82
83
84// ===========================================================================
85// method definitions
86// ===========================================================================
87
88GNETagSelector::GNETagSelector(GNEFrame* frameParent, GNETagProperties::TagType type, SumoXMLTag tag, bool onlyDrawables) :
89 MFXGroupBoxModule(frameParent, TL("Element")),
90 myFrameParent(frameParent),
91 myTagType(type),
92 myCurrentTemplateAC(nullptr) {
93 // Create MFXIconComboBox
94 myTagsMatchBox = new MFXIconComboBox(getCollapsableFrame(), GUIDesignComboBoxNCol, true, this, MID_GNE_TAG_SELECTED, GUIDesignComboBox);
95 // set current tag type without notifying
96 setCurrentTagType(myTagType, onlyDrawables, false);
97 // set current tag without notifying
98 setCurrentTag(tag, false);
99 // GNETagSelector is always shown
100 show();
101}
102
103
105 // clear myACTemplates and myTagsMatchBox
106 for (const auto& ACTemplate : myACTemplates) {
107 delete ACTemplate;
108 }
109 myACTemplates.clear();
110}
111
112
113void
115 show();
116}
117
118
119void
121 hide();
122}
123
124
127 // clear myACTemplates and myTagsMatchBox
128 for (const auto& ACTemplate : myACTemplates) {
129 if (ACTemplate->getAC()->getTagProperty().getTag() == ACTag) {
130 return ACTemplate->getAC();
131 }
132 }
133 return nullptr;
134}
135
136
139 return myCurrentTemplateAC;
140}
141
142
143void
144GNETagSelector::setCurrentTagType(GNETagProperties::TagType tagType, const bool onlyDrawables, const bool notifyFrameParent) {
145 // check if net has proj
146 const bool proj = (GeoConvHelper::getFinal().getProjString() != "!");
147 // set new tagType
148 myTagType = tagType;
149 // change GNETagSelector text
150 switch (myTagType) {
151 case GNETagProperties::TagType::NETWORKELEMENT:
152 setText(TL("network elements"));
153 break;
154 case GNETagProperties::TagType::ADDITIONALELEMENT:
155 setText(TL("Additional elements"));
156 break;
157 case GNETagProperties::TagType::SHAPE:
158 setText(TL("Shape elements"));
159 break;
160 case GNETagProperties::TagType::TAZELEMENT:
161 setText(TL("TAZ elements"));
162 break;
163 case GNETagProperties::TagType::WIRE:
164 setText(TL("Wire elements"));
165 break;
166 case GNETagProperties::TagType::VEHICLE:
167 setText(TL("Vehicles"));
168 break;
169 case GNETagProperties::TagType::STOP:
170 setText(TL("Stops"));
171 break;
172 case GNETagProperties::TagType::PERSON:
173 setText(TL("Persons"));
174 break;
175 case GNETagProperties::TagType::PERSONPLAN:
176 setText(TL("Person plans"));
177 break;
178 case GNETagProperties::TagType::CONTAINER:
179 setText(TL("Container"));
180 break;
181 case GNETagProperties::TagType::CONTAINERPLAN:
182 setText(TL("Container plans"));
183 break;
184 case GNETagProperties::TagType::PERSONTRIP:
185 setText(TL("Person trips"));
186 break;
187 case GNETagProperties::TagType::WALK:
188 setText(TL("Walks"));
189 break;
190 case GNETagProperties::TagType::RIDE:
191 setText(TL("Rides"));
192 break;
193 case GNETagProperties::TagType::STOPPERSON:
194 setText(TL("Person stops"));
195 break;
196 default:
197 throw ProcessError("invalid tag property");
198 }
199 // clear myACTemplates and myTagsMatchBox
200 for (const auto& ACTemplate : myACTemplates) {
201 delete ACTemplate;
202 }
203 myACTemplates.clear();
205 // get tag properties
206 const auto tagProperties = GNEAttributeCarrier::getTagPropertiesByType(myTagType);
207 // fill myACTemplates and myTagsMatchBox
208 for (const auto& tagProperty : tagProperties) {
209 if ((!onlyDrawables || tagProperty.isDrawable()) && (!tagProperty.requireProj() || proj)) {
210 myACTemplates.push_back(new ACTemplate(myFrameParent->getViewNet()->getNet(), tagProperty));
211 myTagsMatchBox->appendIconItem(tagProperty.getFieldString().c_str(), GUIIconSubSys::getIcon(tagProperty.getGUIIcon()), tagProperty.getBackGroundColor());
212 }
213 }
214 // set color of myTypeMatchBox to black (valid)
215 myTagsMatchBox->setTextColor(FXRGB(0, 0, 0));
216 myTagsMatchBox->killFocus();
217 // Set visible items
219 // set first myACTemplate as edited AC
220 myCurrentTemplateAC = myACTemplates.front()->getAC();
221 // call tag selected function
222 if (notifyFrameParent) {
224 }
225}
226
227
228void
229GNETagSelector::setCurrentTag(SumoXMLTag newTag, const bool notifyFrameParent) {
230 // first reset myCurrentTemplateAC
231 myCurrentTemplateAC = nullptr;
232 // iterate over all myTagsMatchBox
233 for (int i = 0; i < (int)myACTemplates.size(); i++) {
234 if (myACTemplates.at(i)->getAC() && (myACTemplates.at(i)->getAC()->getTagProperty().getTag() == newTag)) {
235 // set current template and currentItem
236 myCurrentTemplateAC = myACTemplates.at(i)->getAC();
238 // set color of myTypeMatchBox to black (valid)
239 myTagsMatchBox->setTextColor(FXRGB(0, 0, 0));
240 myTagsMatchBox->killFocus();
241 }
242 }
243 // call tag selected function
244 if (notifyFrameParent) {
246 }
247}
248
249
250void
252 // call tag selected function
254}
255
256
257long
258GNETagSelector::onCmdSelectTag(FXObject*, FXSelector, void*) {
259 // iterate over all myTagsMatchBox
260 for (int i = 0; i < (int)myACTemplates.size(); i++) {
261 if (myACTemplates.at(i)->getAC() && myACTemplates.at(i)->getAC()->getTagProperty().getFieldString() == myTagsMatchBox->getText().text()) {
262 // set templateAC and currentItem
263 myCurrentTemplateAC = myACTemplates.at(i)->getAC();
265 // set color of myTypeMatchBox to black (valid)
266 myTagsMatchBox->setTextColor(FXRGB(0, 0, 0));
267 myTagsMatchBox->killFocus();
268 // call tag selected function
270 // Write Warning in console if we're in testing mode
271 WRITE_DEBUG(("Selected item '" + myTagsMatchBox->getText() + "' in GNETagSelector").text());
272 return 1;
273 }
274 }
275 // reset templateAC
276 myCurrentTemplateAC = nullptr;
277 // set color of myTypeMatchBox to red (invalid)
278 myTagsMatchBox->setTextColor(FXRGB(255, 0, 0));
279 // Write Warning in console if we're in testing mode
280 WRITE_DEBUG("Selected invalid item in GNETagSelector");
281 // call tag selected function
283 return 1;
284}
285
286
289 return myAC;
290}
291
292
294 myAC(nullptr) {
295 // create attribute carrier depending of
296 switch (tagProperty.getTag()) {
297 // additional elements
300 myAC = new GNEBusStop(tagProperty.getTag(), net);
301 break;
302 case SUMO_TAG_ACCESS:
303 myAC = new GNEAccess(net);
304 break;
306 myAC = new GNEContainerStop(net);
307 break;
309 myAC = new GNEChargingStation(net);
310 break;
312 myAC = new GNEParkingArea(net);
313 break;
315 myAC = new GNEParkingSpace(net);
316 break;
319 break;
322 myAC = new GNELaneAreaDetector(tagProperty.getTag(), net);
323 break;
326 break;
329 myAC = new GNEEntryExitDetector(tagProperty.getTag(), net);
330 break;
333 break;
334 case SUMO_TAG_VSS:
335 myAC = new GNEVariableSpeedSign(net);
336 break;
337 case SUMO_TAG_STEP:
339 break;
342 myAC = new GNECalibrator(tagProperty.getTag(), net);
343 break;
345 myAC = new GNECalibratorFlow(net);
346 break;
348 myAC = new GNERerouter(net);
349 break;
351 myAC = new GNERerouterInterval(net);
352 break;
354 myAC = new GNEClosingReroute(net);
355 break;
357 myAC = new GNEClosingLaneReroute(net);
358 break;
360 myAC = new GNEDestProbReroute(net);
361 break;
363 myAC = new GNEParkingAreaReroute(net);
364 break;
366 myAC = new GNERouteProbReroute(net);
367 break;
369 myAC = new GNERouteProbe(net);
370 break;
372 myAC = new GNEVaporizer(net);
373 break;
374 // shapes
375 case SUMO_TAG_POLY:
376 myAC = new GNEPoly(net);
377 break;
378 case SUMO_TAG_POI:
379 case GNE_TAG_POILANE:
380 case GNE_TAG_POIGEO:
381 myAC = new GNEPOI(tagProperty.getTag(), net);
382 break;
383 // TAZs
384 case SUMO_TAG_TAZ:
385 myAC = new GNETAZ(net);
386 break;
388 case SUMO_TAG_TAZSINK:
389 myAC = new GNETAZSourceSink(tagProperty.getTag(), net);
390 break;
391 // wires
393 myAC = new GNETractionSubstation(net);
394 break;
396 myAC = new GNEOverheadWire(net);
397 break;
399 myAC = nullptr; // TMP
400 break;
401 // Demand elements
402 case SUMO_TAG_ROUTE:
404 myAC = new GNERoute(tagProperty.getTag(), net);
405 break;
406 case SUMO_TAG_VTYPE:
407 myAC = new GNEVType(net);
408 break;
410 myAC = new GNEVTypeDistribution(net);
411 break;
412 case SUMO_TAG_VEHICLE:
416 case SUMO_TAG_TRIP:
418 case SUMO_TAG_FLOW:
420 myAC = new GNEVehicle(tagProperty.getTag(), net);
421 break;
422 // stops
432 // waypoints
438 myAC = new GNEStop(tagProperty.getTag(), net);
439 break;
440 case SUMO_TAG_PERSON:
442 myAC = new GNEPerson(tagProperty.getTag(), net);
443 break;
446 myAC = new GNEContainer(tagProperty.getTag(), net);
447 break;
450 myAC = new GNETransport(tagProperty.getTag(), net);
451 break;
455 myAC = new GNETranship(tagProperty.getTag(), net);
456 break;
460 myAC = new GNEPersonTrip(tagProperty.getTag(), net);
461 break;
467 myAC = new GNEWalk(tagProperty.getTag(), net);
468 break;
471 myAC = new GNERide(tagProperty.getTag(), net);
472 break;
473 default:
474 throw ProcessError("Non-supported tagProperty in ACTemplate");
475 break;
476 }
477}
478
479
481 delete myAC;
482}
483
484/****************************************************************************/
FXDEFMAP(GNETagSelector) TagSelectorMap[]
@ MID_GNE_TAG_SELECTED
tag selected in ComboBox
Definition: GUIAppEnum.h:892
#define GUIDesignComboBox
Definition: GUIDesigns.h:306
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:321
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:276
#define TL(string)
Definition: MsgHandler.h:282
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_TRIP_JUNCTIONS
a trip between junctions (used in NETEDIT)
@ SUMO_TAG_TRACTION_SUBSTATION
A traction substation.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_CLOSING_REROUTE
reroute of type closing
@ SUMO_TAG_STOP_CONTAINERSTOP
stop placed over a containerStop (used in netedit)
@ GNE_TAG_PERSONTRIP_JUNCTIONS
@ SUMO_TAG_REROUTER
A rerouter.
@ GNE_TAG_WAYPOINT_PARKINGAREA
waypoint placed over a parking area (used in netedit)
@ GNE_TAG_MULTI_LANE_AREA_DETECTOR
an e2 detector over multiple lanes (placed here due create Additional Frame)
@ SUMO_TAG_ROUTEPROBE
a routeprobe detector
@ GNE_TAG_TRANSPORT_CONTAINERSTOP
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_ACCESS
An access point for a train stop.
@ GNE_TAG_PERSONTRIP_BUSSTOP
@ GNE_TAG_WALK_EDGES
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_CONTAINERFLOW
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
@ SUMO_TAG_STOP_CHARGINGSTATION
stop placed over a charging station (used in netedit)
@ SUMO_TAG_TAZSINK
a sink within a district (connection road)
@ SUMO_TAG_STOP_LANE
stop placed over a lane (used in netedit)
@ GNE_TAG_WAYPOINT_CONTAINERSTOP
waypoint placed over a containerStop (used in netedit)
@ GNE_TAG_STOPCONTAINER_EDGE
@ GNE_TAG_WAYPOINT_BUSSTOP
waypoint placed over a busStop (used in netedit)
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_POI
begin/end of the description of a Point of interest
@ GNE_TAG_WAYPOINT_CHARGINGSTATION
waypoint placed over a charging station (used in netedit)
@ GNE_TAG_STOPPERSON_BUSSTOP
@ SUMO_TAG_STEP
trigger: a step description
@ SUMO_TAG_VEHICLE
description of a vehicle
@ GNE_TAG_FLOW_ROUTE
a flow definition using a route instead of a from-to edges route (used in NETEDIT)
@ SUMO_TAG_OVERHEAD_WIRE_CLAMP
An overhead wire clamp (connection of wires in opposite directions)
@ GNE_TAG_FLOW_JUNCTIONS
a flow between junctions (used in NETEDIT)
@ GNE_TAG_POIGEO
Point of interest over view with GEO attributes.
@ GNE_TAG_TRANSHIP_EDGES
@ GNE_TAG_STOPCONTAINER_CONTAINERSTOP
@ GNE_TAG_FLOW_WITHROUTE
description of a vehicle with an embedded route (used in NETEDIT)
@ SUMO_TAG_FLOW
a flow definitio nusing a from-to edges instead of a route (used by router)
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
@ GNE_TAG_CALIBRATOR_LANE
A calibrator placed over lane.
@ SUMO_TAG_DET_ENTRY
an e3 entry point
@ SUMO_TAG_PARKING_SPACE
A parking space for a single vehicle within a parking area.
@ SUMO_TAG_CONTAINER
@ GNE_TAG_WALK_BUSSTOP
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_POLY
begin/end of the description of a polygon
@ SUMO_TAG_OVERHEAD_WIRE_SECTION
An overhead wire section.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ GNE_TAG_RIDE_EDGE
@ SUMO_TAG_STOP_BUSSTOP
stop placed over a busStop (used in netedit)
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
@ GNE_TAG_TRANSHIP_EDGE
@ SUMO_TAG_INSTANT_INDUCTION_LOOP
An instantenous induction loop.
@ GNE_TAG_WALK_JUNCTIONS
@ GNE_TAG_VEHICLE_WITHROUTE
description of a vehicle with an embedded route (used in NETEDIT)
@ GNE_TAG_CALIBRATOR_FLOW
a flow definition within in Calibrator
@ SUMO_TAG_DEST_PROB_REROUTE
probability of destiny of a reroute
@ GNE_TAG_POILANE
Point of interest over Lane.
@ GNE_TAG_WAYPOINT_LANE
waypoint placed over a lane (used in netedit)
@ SUMO_TAG_PERSON
@ SUMO_TAG_DET_EXIT
an e3 exit point
@ SUMO_TAG_VAPORIZER
vaporizer of vehicles
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
@ SUMO_TAG_STOP_PARKINGAREA
stop placed over a parking area (used in netedit)
@ GNE_TAG_WALK_EDGE
@ SUMO_TAG_TAZSOURCE
a source within a district (connection road)
@ SUMO_TAG_CLOSING_LANE_REROUTE
lane of a reroute of type closing
@ GNE_TAG_PERSONTRIP_EDGE
@ GNE_TAG_ROUTE_EMBEDDED
embedded route (used in NETEDIT)
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
@ GNE_TAG_RIDE_BUSSTOP
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
@ SUMO_TAG_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
@ SUMO_TAG_VSS
A variable speed sign.
@ GNE_TAG_STOPPERSON_EDGE
@ GNE_TAG_WALK_ROUTE
@ SUMO_TAG_PERSONFLOW
@ SUMO_TAG_TRIP
a single trip definition (used by router)
@ GNE_TAG_TRANSHIP_CONTAINERSTOP
@ GNE_TAG_TRANSPORT_EDGE
static const std::vector< GNETagProperties > getTagPropertiesByType(const int tagPropertyCategory)
get tagProperties associated to the given GNETagProperties::TagType (NETWORKELEMENT,...
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
A lane area vehicles can halt at (netedit-version)
Definition: GNEBusStop.h:33
A lane area vehicles can halt at (netedit-version)
virtual void tagSelected()
Tag selected in GNETagSelector.
Definition: GNEFrame.cpp:266
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:150
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
Definition: GNEPOI.h:43
A lane area vehicles can park at (netedit-version)
vehicle space used by GNEParkingAreas
Representation of a RouteProbe in netedit.
Definition: GNERouteProbe.h:32
Definition: GNETAZ.h:34
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
ACTemplate(GNENet *net, const GNETagProperties tagProperty)
constructor
GNEAttributeCarrier * myAC
editedAC
GNEAttributeCarrier * getAC() const
get template AC
MFXIconComboBox * myTagsMatchBox
comboBox with the tags
GNETagProperties::TagType myTagType
current tagType
GNEAttributeCarrier * myCurrentTemplateAC
current templateAC;
void refreshTagSelector()
refresh tagSelector (used when frameParent is show)
void showTagSelector()
show item selector
GNEAttributeCarrier * getTemplateAC(SumoXMLTag ACTag) const
get templateAC
long onCmdSelectTag(FXObject *, FXSelector, void *)
GNEFrame * myFrameParent
pointer to Frame Parent
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
void setCurrentTagType(GNETagProperties::TagType tagType, const bool onlyDrawables, const bool notifyFrameParent=true)
set current type manually
void hideTagSelector()
hide item selector
std::vector< ACTemplate * > myACTemplates
list with ACTemplates
~GNETagSelector()
destructor
void setCurrentTag(SumoXMLTag newTag, const bool notifyFrameParent=true)
set current type manually
Representation of a vaporizer in netedit.
Definition: GNEVaporizer.h:33
GNENet * getNet() const
get the net object
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)
void setText(const std::string &text)
set text
ComboBox with icon.
FXString getText() const
Get the text.
void setCurrentItem(FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
void setTextColor(FXColor clr)
Change text color.
void clearItems()
Remove all items from the list.
FXint getNumItems() const
Return the number of items in the list.
void setNumVisible(FXint nvis)
Set the number of visible items in the drop down list.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon