LCOV - code coverage report
Current view: top level - src/utils/gui/globjects - GUICursorDialog.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 93 0.0 %
Date: 2024-05-06 15:32:35 Functions: 0 15 0.0 %

          Line data    Source code
       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             : /****************************************************************************/
      14             : /// @file    GUICursorDialog.cpp
      15             : /// @author  Pablo Alvarez Lopez
      16             : /// @date    Sep 2022
      17             : ///
      18             : // Dialog for edit element under cursor
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : #include <utils/gui/div/GUIDesigns.h>
      23             : #include <utils/gui/windows/GUIAppEnum.h>
      24             : #include <utils/gui/windows/GUIMainWindow.h>
      25             : #include <utils/gui/windows/GUISUMOAbstractView.h>
      26             : 
      27             : #include <netedit/GNEUndoList.h>
      28             : 
      29             : #include "GUICursorDialog.h"
      30             : 
      31             : 
      32             : #define NUM_VISIBLE_ITEMS 10
      33             : 
      34             : // ===========================================================================
      35             : // FOX callback mapping
      36             : // ===========================================================================
      37             : 
      38             : FXDEFMAP(GUICursorDialog) GUICursorDialogMap[] = {
      39             :     FXMAPFUNC(SEL_COMMAND,  MID_CURSORDIALOG_SETFRONTELEMENT,   GUICursorDialog::onCmdSetFrontElement),
      40             :     FXMAPFUNC(SEL_COMMAND,  MID_CURSORDIALOG_DELETEELEMENT,     GUICursorDialog::onCmdDeleteElement),
      41             :     FXMAPFUNC(SEL_COMMAND,  MID_CURSORDIALOG_SELECTELEMENT,     GUICursorDialog::onCmdSelectElement),
      42             :     FXMAPFUNC(SEL_COMMAND,  MID_CURSORDIALOG_PROPERTIES,        GUICursorDialog::onCmdOpenPropertiesPopUp),
      43             :     FXMAPFUNC(SEL_COMMAND,  MID_CURSORDIALOG_MOVEUP,            GUICursorDialog::onCmdMoveListUp),
      44             :     FXMAPFUNC(SEL_COMMAND,  MID_CURSORDIALOG_MOVEDOWN,          GUICursorDialog::onCmdMoveListDown),
      45             :     FXMAPFUNC(SEL_COMMAND,  MID_CURSORDIALOG_FRONT,             GUICursorDialog::onCmdProcessFront),
      46             :     FXMAPFUNC(SEL_COMMAND,  FXWindow::ID_UNPOST,                GUICursorDialog::onCmdUnpost),
      47             : };
      48             : 
      49             : // Object implementation
      50           0 : FXIMPLEMENT(GUICursorDialog, GUIGLObjectPopupMenu, GUICursorDialogMap, ARRAYNUMBER(GUICursorDialogMap))
      51             : 
      52             : // ===========================================================================
      53             : // member method definitions
      54             : // ===========================================================================
      55             : 
      56           0 : GUICursorDialog::GUICursorDialog(GUIGLObjectPopupMenu::PopupType type, GUISUMOAbstractView* view, const std::vector<GUIGlObject*>& objects) :
      57             :     GUIGLObjectPopupMenu(view->getMainWindow(), view, type),
      58           0 :     myType(type),
      59           0 :     myView(view) {
      60             :     // continue depending of properties
      61           0 :     if (type == GUIGLObjectPopupMenu::PopupType::PROPERTIES) {
      62           0 :         buildDialogElements(view, TL("Overlapped objects"), GUIIcon::MODEINSPECT, MID_CURSORDIALOG_PROPERTIES, objects);
      63           0 :     } else if (type == GUIGLObjectPopupMenu::PopupType::DELETE_ELEMENT) {
      64           0 :         buildDialogElements(view, TL("Delete element"), GUIIcon::MODEDELETE, MID_CURSORDIALOG_DELETEELEMENT, objects);
      65           0 :     } else if (type == GUIGLObjectPopupMenu::PopupType::SELECT_ELEMENT) {
      66           0 :         buildDialogElements(view, TL("Select element"), GUIIcon::MODESELECT, MID_CURSORDIALOG_SELECTELEMENT, objects);
      67           0 :     } else if (type == GUIGLObjectPopupMenu::PopupType::FRONT_ELEMENT) {
      68           0 :         buildDialogElements(view, TL("Mark front element"), GUIIcon::FRONTELEMENT, MID_CURSORDIALOG_SETFRONTELEMENT, objects);
      69             :     }
      70           0 : }
      71             : 
      72             : 
      73           0 : GUICursorDialog::~GUICursorDialog() {
      74             :     // delete all menu commands
      75           0 :     for (const auto& GLObject : myMenuCommandGLObjects) {
      76           0 :         delete GLObject.first;
      77             :     }
      78           0 : }
      79             : 
      80             : 
      81             : long
      82           0 : GUICursorDialog::onCmdSetFrontElement(FXObject* obj, FXSelector, void*) {
      83             :     // search element in myGLObjects
      84           0 :     for (const auto& GLObject : myMenuCommandGLObjects) {
      85           0 :         if (GLObject.first == obj) {
      86           0 :             GLObject.second->markAsFrontElement();
      87             :         }
      88             :     }
      89             :     // destroy popup
      90           0 :     myView->destroyPopup();
      91           0 :     return 1;
      92             : }
      93             : 
      94             : 
      95             : long
      96           0 : GUICursorDialog::onCmdDeleteElement(FXObject* obj, FXSelector, void*) {
      97             :     // search element in myGLObjects
      98           0 :     for (const auto& GLObject : myMenuCommandGLObjects) {
      99           0 :         if (GLObject.first == obj) {
     100           0 :             GLObject.second->deleteGLObject();
     101             :         }
     102             :     }
     103             :     // destroy popup
     104           0 :     myView->destroyPopup();
     105           0 :     return 1;
     106             : }
     107             : 
     108             : 
     109             : long
     110           0 : GUICursorDialog::onCmdSelectElement(FXObject* obj, FXSelector, void*) {
     111             :     // search element in myGLObjects
     112           0 :     for (const auto& GLObject : myMenuCommandGLObjects) {
     113           0 :         if (GLObject.first == obj) {
     114           0 :             GLObject.second->selectGLObject();
     115             :         }
     116             :     }
     117             :     // destroy popup
     118           0 :     myView->destroyPopup();
     119           0 :     return 1;
     120             : }
     121             : 
     122             : 
     123             : long
     124           0 : GUICursorDialog::onCmdOpenPropertiesPopUp(FXObject* obj, FXSelector, void*) {
     125             :     // search element in myGLObjects
     126           0 :     for (const auto& GLObject : myMenuCommandGLObjects) {
     127           0 :         if (GLObject.first == obj) {
     128           0 :             myView->replacePopup(GLObject.second->getPopUpMenu(*myView->getMainWindow(), *myView));
     129             :             return 1;
     130             :         }
     131             :     }
     132             :     return 0;
     133             : }
     134             : 
     135             : 
     136             : long
     137           0 : GUICursorDialog::onCmdMoveListUp(FXObject*, FXSelector, void*) {
     138           0 :     myListIndex -= NUM_VISIBLE_ITEMS;
     139           0 :     updateList();
     140           0 :     show();
     141           0 :     return 0;
     142             : }
     143             : 
     144             : 
     145             : long
     146           0 : GUICursorDialog::onCmdMoveListDown(FXObject*, FXSelector, void*) {
     147           0 :     myListIndex += NUM_VISIBLE_ITEMS;
     148           0 :     updateList();
     149           0 :     show();
     150           0 :     return 0;
     151             : }
     152             : 
     153             : 
     154             : long
     155           0 : GUICursorDialog::onCmdProcessFront(FXObject*, FXSelector, void*) {
     156           0 :     if (myMenuCommandGLObjects.size() > 0) {
     157             :         // continue depending of properties
     158           0 :         if (myType == GUIGLObjectPopupMenu::PopupType::DELETE_ELEMENT) {
     159           0 :             myMenuCommandGLObjects.front().second->deleteGLObject();
     160           0 :         } else if (myType == GUIGLObjectPopupMenu::PopupType::SELECT_ELEMENT) {
     161           0 :             myMenuCommandGLObjects.front().second->selectGLObject();
     162           0 :         } else if (myType == GUIGLObjectPopupMenu::PopupType::FRONT_ELEMENT) {
     163           0 :             myMenuCommandGLObjects.front().second->markAsFrontElement();
     164             :         }
     165             :     }
     166           0 :     return 0;
     167             : }
     168             : 
     169             : 
     170             : long
     171           0 : GUICursorDialog::onCmdUnpost(FXObject* obj, FXSelector, void* ptr) {
     172             :     // ignore move up, down and header
     173           0 :     if ((obj == myMoveUpMenuCommand) || (obj == myMoveDownMenuCommand) || (obj == myMenuHeader)) {
     174             :         return 1;
     175             :     }
     176           0 :     if (grabowner) {
     177           0 :         grabowner->handle(this, FXSEL(SEL_COMMAND, ID_UNPOST), ptr);
     178             :     } else {
     179           0 :         popdown();
     180           0 :         if (grabbed()) {
     181           0 :             ungrab();
     182             :         }
     183             :     }
     184             :     return 1;
     185             : }
     186             : 
     187             : 
     188             : void
     189           0 : GUICursorDialog::updateList() {
     190             :     // first hide all menu commands
     191           0 :     for (const auto& GLObject : myMenuCommandGLObjects) {
     192           0 :         GLObject.first->hide();
     193             :     }
     194             :     // check if disable menu command up
     195           0 :     if (myListIndex == 0) {
     196           0 :         myMoveUpMenuCommand->disable();
     197             :     } else {
     198           0 :         myMoveUpMenuCommand->enable();
     199             :     }
     200             :     // show menu commands depending of myListIndex
     201           0 :     if ((myListIndex + NUM_VISIBLE_ITEMS) > (int)myMenuCommandGLObjects.size()) {
     202           0 :         for (int i = (int)myMenuCommandGLObjects.size() - NUM_VISIBLE_ITEMS; i < (int)myMenuCommandGLObjects.size(); i++) {
     203           0 :             myMenuCommandGLObjects.at(i).first->show();
     204             :         }
     205           0 :         myMoveDownMenuCommand->disable();
     206             :     } else {
     207           0 :         for (int i = myListIndex; i < (myListIndex + NUM_VISIBLE_ITEMS); i++) {
     208           0 :             myMenuCommandGLObjects.at(i).first->show();
     209             :         }
     210           0 :         myMoveDownMenuCommand->enable();
     211             :     }
     212             :     // recalc popup
     213           0 :     recalc();
     214           0 : }
     215             : 
     216             : 
     217             : void
     218           0 : GUICursorDialog::buildDialogElements(GUISUMOAbstractView* view, const FXString text, GUIIcon icon, FXSelector sel, const std::vector<GUIGlObject*>& objects) {
     219             :     // create header
     220           0 :     myMenuHeader = new MFXMenuHeader(this, view->getMainWindow()->getBoldFont(), text, GUIIconSubSys::getIcon(icon), nullptr, 0);
     221           0 :     new FXMenuSeparator(this);
     222             :     // check if create move up menu command
     223           0 :     if (objects.size() > NUM_VISIBLE_ITEMS) {
     224           0 :         myMoveUpMenuCommand = GUIDesigns::buildFXMenuCommand(this, "Previous", GUIIconSubSys::getIcon(GUIIcon::ARROW_UP), this, MID_CURSORDIALOG_MOVEUP);
     225           0 :         new FXMenuSeparator(this);
     226             :     }
     227             :     // create a menu command for every object
     228           0 :     for (const auto& GLObject : objects) {
     229           0 :         myMenuCommandGLObjects.push_back(std::make_pair(GUIDesigns::buildFXMenuCommand(this, GLObject->getMicrosimID(), GLObject->getGLIcon(), this, sel), GLObject));
     230             :     }
     231             :     // check if create move down menu command
     232           0 :     if (objects.size() > NUM_VISIBLE_ITEMS) {
     233           0 :         new FXMenuSeparator(this);
     234           0 :         myMoveDownMenuCommand = GUIDesigns::buildFXMenuCommand(this, "Next", GUIIconSubSys::getIcon(GUIIcon::ARROW_DOWN), this, MID_CURSORDIALOG_MOVEDOWN);
     235           0 :         updateList();
     236             :     }
     237           0 : }
     238             : 
     239             : /****************************************************************************/

Generated by: LCOV version 1.14