Path: blob/main/src/netedit/frames/GNEOverlappedInspection.cpp
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNEOverlappedInspection.cpp14/// @author Pablo Alvarez Lopez15/// @date Mar 202216///17// Frame for overlapped elements18/****************************************************************************/1920#include <netedit/GNEViewNet.h>21#include <netedit/GNEViewParent.h>22#include <netedit/GNEApplicationWindow.h>23#include <netedit/GNETagProperties.h>24#include <netedit/dialogs/basic/GNEHelpBasicDialog.h>25#include <netedit/elements/network/GNELane.h>26#include <netedit/frames/common/GNEInspectorFrame.h>27#include <utils/gui/div/GUIDesigns.h>28#include <utils/gui/windows/GUIAppEnum.h>2930#include "GNEOverlappedInspection.h"3132// ===========================================================================33// FOX callback mapping34// ===========================================================================3536FXDEFMAP(GNEOverlappedInspection) OverlappedInspectionMap[] = {37FXMAPFUNC(SEL_COMMAND, MID_GNE_OVERLAPPED_NEXT, GNEOverlappedInspection::onCmdInspectNextElement),38FXMAPFUNC(SEL_COMMAND, MID_GNE_OVERLAPPED_PREVIOUS, GNEOverlappedInspection::onCmdInspectPreviousElement),39FXMAPFUNC(SEL_COMMAND, MID_GNE_OVERLAPPED_SHOWLIST, GNEOverlappedInspection::onCmdShowList),40FXMAPFUNC(SEL_COMMAND, MID_GNE_OVERLAPPED_ITEMSELECTED, GNEOverlappedInspection::onCmdListItemSelected),41FXMAPFUNC(SEL_COMMAND, MID_HELP, GNEOverlappedInspection::onCmdOverlappingHelp)42};4344// Object implementation45FXIMPLEMENT(GNEOverlappedInspection, MFXGroupBoxModule, OverlappedInspectionMap, ARRAYNUMBER(OverlappedInspectionMap))4647// ===========================================================================48// method definitions49// ===========================================================================5051GNEOverlappedInspection::GNEOverlappedInspection(GNEFrame* frameParent, const bool onlyJunctions) :52MFXGroupBoxModule(frameParent, onlyJunctions ? TL("Overlapped junctions") : TL("Overlapped elements")),53myFrameParent(frameParent),54myOnlyJunctions(onlyJunctions) {55FXHorizontalFrame* frameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);56// Create previous Item Button57myPreviousElement = GUIDesigns::buildFXButton(frameButtons, "", "", "", GUIIconSubSys::getIcon(GUIIcon::BIGARROWLEFT), this, MID_GNE_OVERLAPPED_PREVIOUS, GUIDesignButtonRectangular);58// create current index button59myCurrentIndexButton = GUIDesigns::buildFXButton(frameButtons, "", "", "", nullptr, this, MID_GNE_OVERLAPPED_SHOWLIST, GUIDesignButton);60// Create next Item Button61myNextElement = GUIDesigns::buildFXButton(frameButtons, "", "", "", GUIIconSubSys::getIcon(GUIIcon::BIGARROWRIGHT), this, MID_GNE_OVERLAPPED_NEXT, GUIDesignButtonRectangular);62// Create list of overlapped elements (by default hidden)63myOverlappedElementList = new FXList(getCollapsableFrame(), this, MID_GNE_OVERLAPPED_ITEMSELECTED, GUIDesignListFixedHeight);64// by default list of overlapped elements is hidden)65myOverlappedElementList->hide();66// Create help button67myHelpButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Help"), "", "", nullptr, this, MID_HELP, GUIDesignButtonRectangular);68// by default hidden69hide();70}717273GNEOverlappedInspection::~GNEOverlappedInspection() {}747576void77GNEOverlappedInspection::showOverlappedInspection(GNEViewNetHelper::ViewObjectsSelector& viewObjects, const Position& clickedPosition, const bool shiftKeyPressed) {78// check if filter all except junctions79if (myOnlyJunctions) {80viewObjects.filterAllExcept(GLO_JUNCTION);81} else {82// filter by supermode83viewObjects.filterBySuperMode();84// filtger edges if we clicked over a lane85if (viewObjects.getAttributeCarrierFront() && viewObjects.getAttributeCarrierFront() == viewObjects.getLaneFront()) {86viewObjects.filterEdges();87}88}89// check if previously we clicked an edge and now we want to inspect their lane90bool toogleInspectEdgeLane = false;91if (!myOnlyJunctions && (myOverlappedACs.size() > 0) && (myOverlappedACs.front()->getTagProperty()->getTag() == SUMO_TAG_EDGE) && shiftKeyPressed) {92toogleInspectEdgeLane = true;93}94// in this point, check if we want to iterate over existent overlapped inspection, or we want to inspet a new set of elements95if (!toogleInspectEdgeLane && (myOverlappedACs.size() > 0) && (myClickedPosition != Position::INVALID) && (myClickedPosition.distanceSquaredTo(clickedPosition) < 0.05) && (myShiftKeyPressed == shiftKeyPressed)) {96onCmdInspectNextElement(nullptr, 0, nullptr);97} else {98myOverlappedACs = viewObjects.getAttributeCarriers();99myItemIndex = 0;100myOverlappedElementList->hide();101}102// update clicked position and refresh overlapped inspection103myClickedPosition = clickedPosition;104myShiftKeyPressed = shiftKeyPressed;105refreshOverlappedInspection();106}107108109void110GNEOverlappedInspection::clearOverlappedInspection() {111myOverlappedACs.clear();112myItemIndex = 0;113myOverlappedElementList->hide();114refreshOverlappedInspection();115}116117118void119GNEOverlappedInspection::hiderOverlappedInspection() {120hide();121}122123void124GNEOverlappedInspection::refreshOverlappedInspection() {125// show modul depending of number of overlapped elements126if (myOverlappedACs.size() > 1) {127// update text of current index button128myCurrentIndexButton->setText((toString(myItemIndex + 1) + " / " + toString(myOverlappedACs.size())).c_str());129// clear and fill list again130myOverlappedElementList->clearItems();131for (int i = 0; i < (int)myOverlappedACs.size(); i++) {132myOverlappedElementList->insertItem(i, myOverlappedACs.at(i)->getID().c_str(), myOverlappedACs.at(i)->getACIcon());133}134// select current item135myOverlappedElementList->getItem(myItemIndex)->setSelected(TRUE);136// show modul137show();138// call selectedOverlappedElement139myFrameParent->selectedOverlappedElement(myOverlappedACs.at(myItemIndex));140} else {141if (myOverlappedACs.size() > 0) {142myFrameParent->selectedOverlappedElement(myOverlappedACs.front());143} else {144myFrameParent->selectedOverlappedElement(nullptr);145}146hide();147}148}149150151bool152GNEOverlappedInspection::overlappedInspectionShown() const {153// show GNEOverlappedInspection modul154return shown();155}156157158int159GNEOverlappedInspection::getNumberOfOverlappedACs() const {160return (int)myOverlappedACs.size();161}162163164GNEAttributeCarrier*165GNEOverlappedInspection::getCurrentAC() const {166if (myOverlappedACs.size() > 0) {167return myOverlappedACs.at(myItemIndex);168} else {169return nullptr;170}171}172173long174GNEOverlappedInspection::onCmdInspectPreviousElement(FXObject*, FXSelector, void*) {175// check if there is items176if (myOverlappedElementList->getNumItems() > 0) {177// set index (it works as a ring)178if (myItemIndex > 0) {179myItemIndex--;180} else {181myItemIndex = ((int)myOverlappedACs.size() - 1);182}183refreshOverlappedInspection();184}185return 1;186}187188189long190GNEOverlappedInspection::onCmdInspectNextElement(FXObject*, FXSelector, void*) {191// check if there is items192if (myOverlappedElementList->getNumItems() > 0) {193// set index (it works as a ring)194myItemIndex = (myItemIndex + 1) % myOverlappedACs.size();195refreshOverlappedInspection();196}197return 1;198}199200201long202GNEOverlappedInspection::onCmdShowList(FXObject*, FXSelector, void*) {203// show or hide element list204if (myOverlappedElementList->shown()) {205myOverlappedElementList->hide();206} else {207myOverlappedElementList->show();208}209if (myOverlappedElementList->getNumItems() <= 10) {210myOverlappedElementList->setHeight(23 * myOverlappedElementList->getNumItems());211} else {212myOverlappedElementList->setHeight(230);213}214myOverlappedElementList->recalc();215// recalc and update frame216recalc();217return 1;218}219220long221GNEOverlappedInspection::onCmdListItemSelected(FXObject*, FXSelector, void*) {222for (int i = 0; i < myOverlappedElementList->getNumItems(); i++) {223if (myOverlappedElementList->getItem(i)->isSelected()) {224myItemIndex = i;225refreshOverlappedInspection();226return 1;227}228}229return 0;230}231232233long234GNEOverlappedInspection::onCmdOverlappingHelp(FXObject*, FXSelector, void*) {235// create text for help dialog236std::ostringstream help;237help238<< TL(" - Click in the same position") << "\n"239<< TL(" to inspect next element") << "\n"240<< TL(" - Shift + Click in the same") << "\n"241<< TL(" position to inspect") << "\n"242<< TL(" previous element");243// create help dialog244GNEHelpBasicDialog(myFrameParent->getViewNet()->getViewParent()->getGNEAppWindows(),245TL("GEO attributes Help"), help);246return 1;247}248249250GNEOverlappedInspection::GNEOverlappedInspection() {}251252/****************************************************************************/253254255