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.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 // Class for the window that allows to choose a street, junction or vehicle
19 /****************************************************************************/
20 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEViewParent.h>
24 
25 #include "GNEDialogACChooser.h"
26 
27 
28 // ===========================================================================
29 // method definitions
30 // ===========================================================================
31 
32 GNEDialogACChooser::GNEDialogACChooser(GNEViewParent* viewParent, int messageId, FXIcon* icon, const std::string& title, const std::vector<GNEAttributeCarrier*>& ACs):
33  GUIDialog_ChooserAbstract(viewParent, messageId, icon, title.c_str(), std::vector<GUIGlID>(), GUIGlObjectStorage::gIDStorage),
34  myViewParent(viewParent),
35  myACs(ACs),
36  myFilteredACs(ACs),
37  myLocateTLS(title.find("TLS") != std::string::npos) {
38  // @note refresh must be called here because the base class constructor cannot
39  // call the virtual function getObjectName
40  std::vector<GUIGlID> ids;
41  for (const auto& AC : ACs) {
42  ids.push_back(AC->getGUIGlObject()->getGlID());
43  }
44  refreshList(ids);
45 }
46 
47 
50 }
51 
52 
53 void
55  // always filtered ACs
56  GNEAttributeCarrier* ac = myFilteredACs[listIndex];
57  if (ac->isAttributeCarrierSelected()) {
59  } else {
61  }
62 }
63 
64 
65 void
67  // always filtered ACs
68  GNEAttributeCarrier* ac = myFilteredACs[listIndex];
69  if (!ac->isAttributeCarrierSelected()) {
71  }
72 }
73 
74 
75 void
77  // always filtered ACs
78  GNEAttributeCarrier* ac = myFilteredACs[listIndex];
79  if (ac->isAttributeCarrierSelected()) {
81  }
82 }
83 
84 
85 void
86 GNEDialogACChooser::filterACs(const std::vector<GUIGlID>& GLIDs) {
87  if (GLIDs.empty()) {
89  } else {
90  // clear myFilteredACs
91  myFilteredACs.clear();
92  // iterate over myACs
93  for (const auto& AC : myACs) {
94  // search in GLIDs
95  if (std::find(GLIDs.begin(), GLIDs.end(), AC->getGUIGlObject()->getGlID()) != GLIDs.end()) {
96  myFilteredACs.push_back(AC);
97  }
98  }
99  }
100 }
101 
102 
103 std::string
105  // check if we're locating a TLS
106  if (myLocateTLS) {
107  // obtain junction
108  GNEJunction* junction = dynamic_cast<GNEJunction*>(o);
109  // check that junction exist
110  if (junction == nullptr) {
111  throw ProcessError(TL("Invalid Junction"));
112  }
113  // get definitions
114  const std::set<NBTrafficLightDefinition*>& defs = junction->getNBNode()->getControllingTLS();
115  // check that traffic light exists
116  if (defs.empty()) {
117  throw ProcessError(TL("Invalid number of TLSs"));
118  }
119  // get TLDefinition
120  const std::string& tlDefID = (*defs.begin())->getID();
121  if (tlDefID == o->getMicrosimID()) {
122  return o->getMicrosimID();
123  } else {
124  return tlDefID + " (" + o->getMicrosimID() + ")";
125  }
126  } else {
128  }
129 }
130 
131 
132 /****************************************************************************/
unsigned int GUIGlID
Definition: GUIGlObject.h:43
#define TL(string)
Definition: MsgHandler.h:315
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
GNEDialogACChooser(GNEViewParent *viewParent, int messageId, FXIcon *icon, const std::string &title, const std::vector< GNEAttributeCarrier * > &ACs)
Constructor.
std::vector< GNEAttributeCarrier * > myACs
list of displayed ACs
void select(int listIndex) override
set selection (handled differently in netedit)
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
void toggleSelection(int listIndex) override
toggle selection
std::string getObjectName(GUIGlObject *o) const override
retrieve name for the given object (special case for TLS)
std::vector< GNEAttributeCarrier * > myFilteredACs
list of filtered ACs
void deselect(int listIndex) override
unset selection (handled differently in netedit)
NBNode * getNBNode() const
Return net build node.
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:88
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
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
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:336
Definition: json.hpp:4471