LCOV - code coverage report
Current view: top level - src/utils/gui/div - GUIDialog_GLChosenEditor.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 0.0 % 88 0
Test Date: 2025-12-06 15:35:27 Functions: 0.0 % 13 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 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    GUIDialog_GLChosenEditor.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Thu, 11.03.2004
      19              : ///
      20              : // Editor for the list of chosen objects
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <vector>
      26              : #include <iostream>
      27              : #include <fstream>
      28              : #include <fxkeys.h>
      29              : #include <utils/common/MsgHandler.h>
      30              : #include <utils/gui/windows/GUIAppEnum.h>
      31              : #include <utils/gui/globjects/GUIGlObject.h>
      32              : #include <utils/foxtools/MFXUtils.h>
      33              : #include "GUIDialog_GLChosenEditor.h"
      34              : #include <utils/gui/div/GUIGlobalSelection.h>
      35              : #include <utils/gui/globjects/GUIGlObjectStorage.h>
      36              : #include <utils/gui/div/GUIIOGlobals.h>
      37              : #include <utils/gui/div/GUIDesigns.h>
      38              : #include <utils/gui/windows/GUIMainWindow.h>
      39              : #include <utils/gui/images/GUIIconSubSys.h>
      40              : 
      41              : 
      42              : // ===========================================================================
      43              : // FOX callback mapping
      44              : // ===========================================================================
      45              : FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[] = {
      46              :     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSEN_LOAD,       GUIDialog_GLChosenEditor::onCmdLoad),
      47              :     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSEN_SAVE,       GUIDialog_GLChosenEditor::onCmdSave),
      48              :     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSEN_DESELECT,   GUIDialog_GLChosenEditor::onCmdDeselect),
      49              :     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSEN_CLEAR,      GUIDialog_GLChosenEditor::onCmdClear),
      50              :     FXMAPFUNC(SEL_COMMAND,  MID_CANCEL,             GUIDialog_GLChosenEditor::onCmdClose),
      51              :     FXMAPFUNC(SEL_KEYPRESS, 0,                      GUIDialog_GLChosenEditor::onKeyPress),
      52              : };
      53              : 
      54            0 : FXIMPLEMENT(GUIDialog_GLChosenEditor, FXMainWindow, GUIDialog_GLChosenEditorMap, ARRAYNUMBER(GUIDialog_GLChosenEditorMap))
      55              : 
      56              : 
      57              : // ===========================================================================
      58              : // method definitions
      59              : // ===========================================================================
      60              : #ifdef _MSC_VER
      61              : #pragma warning(push)
      62              : #pragma warning(disable: 4355) // mask warning about "this" in initializers
      63              : #endif
      64            0 : GUIDialog_GLChosenEditor::GUIDialog_GLChosenEditor(GUIMainWindow* parent, GUISelectedStorage* str) :
      65              :     FXMainWindow(parent->getApp(), "List of Selected Items", GUIIconSubSys::getIcon(GUIIcon::APP_SELECTOR), nullptr, GUIDesignChooserDialog),
      66              :     GUIPersistentWindowPos(this, "DIALOG_EDIT_SELECTED", true, 20, 40, 300, 350),
      67            0 :     myParent(parent), myStorage(str) {
      68            0 :     myStorage->add2Update(this);
      69            0 :     FXHorizontalFrame* hbox = new FXHorizontalFrame(this, GUIDesignAuxiliarFrame);
      70              :     // create layout left
      71            0 :     FXVerticalFrame* layoutLeft = new FXVerticalFrame(hbox, GUIDesignChooserLayoutLeft);
      72              :     // create frame for list
      73            0 :     FXVerticalFrame* layoutList = new FXVerticalFrame(layoutLeft, GUIDesignChooserLayoutList);
      74              :     // build the list and rebuild it
      75            0 :     myList = new FXList(layoutList, this, MID_CHOOSER_LIST, GUIDesignChooserListMultiple);
      76            0 :     rebuildList();
      77              :     // build the layout
      78            0 :     FXVerticalFrame* layout = new FXVerticalFrame(hbox, GUIDesignChooserLayoutRight);
      79              :     // "Load"
      80            0 :     GUIDesigns::buildFXButton(layout, TL("&Load selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::OPEN), this, MID_CHOOSEN_LOAD, GUIDesignChooserButtons);
      81              :     // "Save"
      82            0 :     GUIDesigns::buildFXButton(layout, TL("&Save selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::SAVE), this, MID_CHOOSEN_SAVE, GUIDesignChooserButtons);
      83              :     // extra separator
      84            0 :     new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
      85              :     // "Deselect Chosen"
      86            0 :     GUIDesigns::buildFXButton(layout, TL("&Deselect chosen"), "", "", GUIIconSubSys::getIcon(GUIIcon::FLAG), this, MID_CHOOSEN_DESELECT, GUIDesignChooserButtons);
      87              :     // "Clear List"
      88            0 :     GUIDesigns::buildFXButton(layout, TL("&Clear selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::FLAG), this, MID_CHOOSEN_CLEAR, GUIDesignChooserButtons);
      89              :     // extra separator
      90            0 :     new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
      91              :     // "Close"
      92            0 :     GUIDesigns::buildFXButton(layout, TL("Cl&ose"), "", "", GUIIconSubSys::getIcon(GUIIcon::NO), this, MID_CANCEL, GUIDesignChooserButtons);
      93            0 :     myParent->addChild(this);
      94            0 :     loadWindowPos();
      95            0 : }
      96              : #ifdef _MSC_VER
      97              : #pragma warning(pop)
      98              : #endif
      99              : 
     100              : 
     101            0 : GUIDialog_GLChosenEditor::~GUIDialog_GLChosenEditor() {
     102            0 :     myStorage->remove2Update();
     103            0 :     myParent->removeChild(this);
     104            0 : }
     105              : 
     106              : 
     107              : void
     108            0 : GUIDialog_GLChosenEditor::rebuildList() {
     109            0 :     myList->clearItems();
     110            0 :     const auto& chosen = gSelected.getSelected();
     111            0 :     for (auto i : chosen) {
     112            0 :         GUIGlObject* object = GUIGlObjectStorage::gIDStorage.getObjectBlocking(i);
     113            0 :         if (object != nullptr) {
     114              :             std::string name = object->getFullName();
     115            0 :             FXListItem* item = myList->getItem(myList->appendItem(name.c_str()));
     116              :             item->setData(object);
     117            0 :             GUIGlObjectStorage::gIDStorage.unblockObject(i);
     118              :         }
     119              :     }
     120            0 : }
     121              : 
     122              : 
     123              : void
     124            0 : GUIDialog_GLChosenEditor::selectionUpdated() {
     125            0 :     rebuildList();
     126            0 :     FXMainWindow::update();
     127            0 : }
     128              : 
     129              : 
     130              : long
     131            0 : GUIDialog_GLChosenEditor::onCmdLoad(FXObject*, FXSelector, void*) {
     132              :     // get the new file name
     133            0 :     FXFileDialog opendialog(this, TL("Open List of Selected Items"));
     134            0 :     opendialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::OPEN));
     135            0 :     opendialog.setSelectMode(SELECTFILE_EXISTING);
     136            0 :     opendialog.setPatternList(SUMOXMLDefinitions::TXTFileExtensions.getMultilineString().c_str());
     137            0 :     if (gCurrentFolder.length() != 0) {
     138            0 :         opendialog.setDirectory(gCurrentFolder);
     139              :     }
     140            0 :     if (opendialog.execute()) {
     141            0 :         gCurrentFolder = opendialog.getDirectory();
     142            0 :         std::string file = opendialog.getFilename().text();
     143            0 :         std::string msg = gSelected.load(file);
     144            0 :         if (msg != "") {
     145            0 :             FXMessageBox::error(this, MBOX_OK, TL("Errors while loading Selection"), "%s", msg.c_str());
     146              :         }
     147            0 :         rebuildList();
     148            0 :         myParent->updateChildren();
     149              :     }
     150            0 :     return 1;
     151            0 : }
     152              : 
     153              : 
     154              : long
     155            0 : GUIDialog_GLChosenEditor::onCmdSave(FXObject*, FXSelector, void*) {
     156            0 :     FXString file = MFXUtils::getFilename2Write(this, TL("Save List of selected Items"),
     157            0 :                     SUMOXMLDefinitions::TXTFileExtensions.getMultilineString().c_str(),
     158            0 :                     GUIIconSubSys::getIcon(GUIIcon::SAVE), gCurrentFolder);
     159            0 :     if (file == "") {
     160              :         return 1;
     161              :     }
     162              :     try {
     163            0 :         gSelected.save(file.text());
     164            0 :     } catch (IOError& e) {
     165            0 :         FXMessageBox::error(this, MBOX_OK, TL("Storing failed!"), "%s", e.what());
     166            0 :     }
     167              :     return 1;
     168            0 : }
     169              : 
     170              : 
     171              : long
     172            0 : GUIDialog_GLChosenEditor::onCmdDeselect(FXObject*, FXSelector, void*) {
     173            0 :     FXint no = myList->getNumItems();
     174              :     FXint i;
     175              :     std::vector<GUIGlID> selected;
     176            0 :     for (i = 0; i < no; ++i) {
     177            0 :         if (myList->getItem(i)->isSelected()) {
     178            0 :             selected.push_back(static_cast<GUIGlObject*>(myList->getItem(i)->getData())->getGlID());
     179              :         }
     180              :     }
     181              :     // remove items from list
     182            0 :     for (i = 0; i < (FXint) selected.size(); ++i) {
     183            0 :         gSelected.deselect(selected[i]);
     184              :     }
     185              :     // rebuild list
     186            0 :     rebuildList();
     187            0 :     myParent->updateChildren();
     188            0 :     return 1;
     189            0 : }
     190              : 
     191              : 
     192              : long
     193            0 : GUIDialog_GLChosenEditor::onKeyPress(FXObject* o, FXSelector sel, void* ptr) {
     194              :     const FXEvent* e = (FXEvent*) ptr;
     195            0 :     if(e->code==KEY_Escape){
     196            0 :         onCmdClose(nullptr, 0, nullptr);
     197            0 :         return 1;
     198              :     }
     199            0 :     return FXMainWindow::onKeyPress(o, sel, ptr);
     200              : }
     201              : 
     202              : 
     203              : long
     204            0 : GUIDialog_GLChosenEditor::onCmdClear(FXObject*, FXSelector, void*) {
     205            0 :     myList->clearItems();
     206            0 :     gSelected.clear();
     207            0 :     myParent->updateChildren();
     208            0 :     return 1;
     209              : }
     210              : 
     211              : 
     212              : long
     213            0 : GUIDialog_GLChosenEditor::onCmdClose(FXObject*, FXSelector, void*) {
     214            0 :     close(true);
     215            0 :     return 1;
     216              : }
     217              : 
     218              : 
     219              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1