Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Oct 14, 2020
1 parent db3a037 commit ef76fdc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
40 changes: 35 additions & 5 deletions src/netedit/dialogs/GNEDialogACChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
GNEDialogACChooser::GNEDialogACChooser(GNEViewParent* viewParent, FXIcon* icon, const std::string& title, const std::vector<GNEAttributeCarrier*>& ACs):
GUIDialog_GLObjChooser(viewParent, icon, title.c_str(), std::vector<GUIGlID>(), GUIGlObjectStorage::gIDStorage),
myACs(ACs),
myFilteredACs(ACs),
myViewParent(viewParent),
myLocateTLS(title.find("TLS") != std::string::npos) {
// @note refresh must be called here because the base class constructor cannot
// call the virtual function getObjectName
std::vector<GUIGlID> ids;
for (auto ac : ACs) {
ids.push_back(dynamic_cast<GUIGlObject*>(ac)->getGlID());
for (const auto &AC : ACs) {
ids.push_back(AC->getGUIGlObject()->getGlID());
}
refreshList(ids);
}
Expand All @@ -52,7 +53,8 @@ GNEDialogACChooser::~GNEDialogACChooser() {

void
GNEDialogACChooser::toggleSelection(int listIndex) {
GNEAttributeCarrier* ac = myACs[listIndex];
// always filtered ACs
GNEAttributeCarrier* ac = myFilteredACs[listIndex];
if (ac->isAttributeCarrierSelected()) {
ac->unselectAttributeCarrier();
} else {
Expand All @@ -61,13 +63,41 @@ GNEDialogACChooser::toggleSelection(int listIndex) {
}


void
GNEDialogACChooser::filterACs(const std::vector<GUIGlID> &GLIDs) {
if (GLIDs.empty()) {
myFilteredACs = myACs;
} else {
// clear myFilteredACs
myFilteredACs.clear();
// iterate over myACs
for (const auto &AC : myACs) {
// search in GLIDs
if (std::find(GLIDs.begin(), GLIDs.end(), AC->getGUIGlObject()->getGlID()) != GLIDs.end()) {
myFilteredACs.push_back(AC);
}
}
}
}


std::string
GNEDialogACChooser::getObjectName(GUIGlObject* o) const {
// check if we're locating a TLS
if (myLocateTLS) {
// obtain junction
GNEJunction* junction = dynamic_cast<GNEJunction*>(o);
assert(junction != nullptr);
// check that junction exist
if (junction == nullptr) {
throw ProcessError("Invalid Junction");
}
// get definitions
const std::set<NBTrafficLightDefinition*>& defs = junction->getNBNode()->getControllingTLS();
assert(defs.size() > 0);
// check that junction exist
if (defs.size() > 0) {
throw ProcessError("Invalid number of TLSs");
}
// get TLDefinition
NBTrafficLightDefinition* tlDef = *defs.begin();
if (tlDef->getID() == o->getMicrosimID()) {
return o->getMicrosimID();
Expand Down
10 changes: 9 additions & 1 deletion src/netedit/dialogs/GNEDialogACChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,24 @@ class GNEDialogACChooser : public GUIDialog_GLObjChooser {
protected:
FOX_CONSTRUCTOR(GNEDialogACChooser)

/// @brief toogle selection
void toggleSelection(int listIndex) override;

/// @brief filter ACs
void filterACs(const std::vector<GUIGlID> &GLIDs) override;

/// @bbrief retrieve name for the given object (special case for TLS)
std::string getObjectName(GUIGlObject* o) const override;

private:
/// @brief pointer to view parent
GNEViewParent* myViewParent;

/// @brief list of displayed ACs
std::vector<GNEAttributeCarrier*> myACs;
GNEViewParent* myViewParent;

/// @brief list of filtered ACs
std::vector<GNEAttributeCarrier*> myFilteredACs;

/// @brief whether the current locator is for TLS
bool myLocateTLS;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/gui/windows/GUIDialog_GLObjChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ GUIDialog_GLObjChooser::onCmdFilterSubstr(FXObject*, FXSelector, void*) {
}
}
refreshList(selectedGlIDs);
// filter ACs in NETEDIT
filterACs(selectedGlIDs);
myHaveFilteredSubstring = true;
onChgText(nullptr, 0, nullptr);
return 1;
Expand Down Expand Up @@ -311,4 +313,9 @@ GUIDialog_GLObjChooser::toggleSelection(int listIndex) {
}


void
GUIDialog_GLObjChooser::filterACs(const std::vector<GUIGlID> &GLIDs) {
// overrided in GNEDialogACChooser
}

/****************************************************************************/
4 changes: 3 additions & 1 deletion src/utils/gui/windows/GUIDialog_GLObjChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ class GUIDialog_GLObjChooser : public FXMainWindow {
void show();

protected:

/// @brief toggle selection (handled differently in NETEDIT)
virtual void toggleSelection(int listIndex);

/// @brief filter ACs (needed in NETEDIT)
virtual void filterACs(const std::vector<GUIGlID> &GLIDs);

/// update the list with the given ids
void refreshList(const std::vector<GUIGlID>& ids);

Expand Down

0 comments on commit ef76fdc

Please sign in to comment.