Eclipse SUMO - Simulation of Urban MObility
GNEDialogACChooser.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-2020 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 // Class for the window that allows to choose a street, junction or vehicle
19 /****************************************************************************/
20 #include <config.h>
21 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEViewParent.h>
25 
26 #include "GNEDialogACChooser.h"
27 
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
32 
33 GNEDialogACChooser::GNEDialogACChooser(GNEViewParent* viewParent, FXIcon* icon, const std::string& title, const std::vector<GNEAttributeCarrier*>& ACs):
34  GUIDialog_ChooserAbstract(viewParent, icon, title.c_str(), std::vector<GUIGlID>(), GUIGlObjectStorage::gIDStorage),
35  myViewParent(viewParent),
36  myACs(ACs),
37  myFilteredACs(ACs),
38  myLocateTLS(title.find("TLS") != std::string::npos) {
39  // @note refresh must be called here because the base class constructor cannot
40  // call the virtual function getObjectName
41  std::vector<GUIGlID> ids;
42  for (const auto& AC : ACs) {
43  ids.push_back(AC->getGUIGlObject()->getGlID());
44  }
45  refreshList(ids);
46 }
47 
48 
51 }
52 
53 
54 void
56  // always filtered ACs
57  GNEAttributeCarrier* ac = myFilteredACs[listIndex];
58  if (ac->isAttributeCarrierSelected()) {
60  } else {
62  }
63 }
64 
65 
66 void
67 GNEDialogACChooser::filterACs(const std::vector<GUIGlID>& GLIDs) {
68  if (GLIDs.empty()) {
70  } else {
71  // clear myFilteredACs
72  myFilteredACs.clear();
73  // iterate over myACs
74  for (const auto& AC : myACs) {
75  // search in GLIDs
76  if (std::find(GLIDs.begin(), GLIDs.end(), AC->getGUIGlObject()->getGlID()) != GLIDs.end()) {
77  myFilteredACs.push_back(AC);
78  }
79  }
80  }
81 }
82 
83 
84 std::string
86  // check if we're locating a TLS
87  if (myLocateTLS) {
88  // obtain junction
89  GNEJunction* junction = dynamic_cast<GNEJunction*>(o);
90  // check that junction exist
91  if (junction == nullptr) {
92  throw ProcessError("Invalid Junction");
93  }
94  // get definitions
95  const std::set<NBTrafficLightDefinition*>& defs = junction->getNBNode()->getControllingTLS();
96  // check that traffic light exists
97  if (defs.empty()) {
98  throw ProcessError("Invalid number of TLSs");
99  }
100  // get TLDefinition
101  const std::string& tlDefID = (*defs.begin())->getID();
102  if (tlDefID == o->getMicrosimID()) {
103  return o->getMicrosimID();
104  } else {
105  return tlDefID + " (" + o->getMicrosimID() + ")";
106  }
107  } else {
109  }
110 }
111 
112 
113 /****************************************************************************/
unsigned int GUIGlID
Definition: GUIGlObject.h:40
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
std::vector< GNEAttributeCarrier * > myACs
list of displayed ACs
bool myLocateTLS
whether the current locator is for TLS
~GNEDialogACChooser()
Destructor.
void filterACs(const std::vector< GUIGlID > &GLIDs) override
filter ACs
GNEViewParent * myViewParent
pointer to view parent
GNEDialogACChooser(GNEViewParent *viewParent, FXIcon *icon, const std::string &title, const std::vector< GNEAttributeCarrier * > &ACs)
Constructor.
void toggleSelection(int listIndex) override
toogle selection
std::string getObjectName(GUIGlObject *o) const override
@bbrief retrieve name for the given object (special case for TLS)
std::vector< GNEAttributeCarrier * > myFilteredACs
list of filtered ACs
NBNode * getNBNode() const
Return net build node.
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:81
void eraseACChooserDialog(GNEDialogACChooser *chooserDialog)
remove created chooser dialog
void refreshList(const std::vector< GUIGlID > &ids)
update the list with the given ids
virtual std::string getObjectName(GUIGlObject *o) const
@bbrief retrieve name for the given object
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
A storage for of displayed objects via their numerical id.
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node (The set of tls that control this node)
Definition: NBNode.h:322