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 % 81 0
Test Date: 2024-11-20 15:55:46 Functions: 0.0 % 12 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    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 <utils/common/MsgHandler.h>
      29              : #include <utils/gui/windows/GUIAppEnum.h>
      30              : #include <utils/gui/globjects/GUIGlObject.h>
      31              : #include <utils/foxtools/MFXUtils.h>
      32              : #include "GUIDialog_GLChosenEditor.h"
      33              : #include <utils/gui/div/GUIGlobalSelection.h>
      34              : #include <utils/gui/globjects/GUIGlObjectStorage.h>
      35              : #include <utils/gui/div/GUIIOGlobals.h>
      36              : #include <utils/gui/div/GUIDesigns.h>
      37              : #include <utils/gui/windows/GUIMainWindow.h>
      38              : #include <utils/gui/images/GUIIconSubSys.h>
      39              : 
      40              : 
      41              : // ===========================================================================
      42              : // FOX callback mapping
      43              : // ===========================================================================
      44              : FXDEFMAP(GUIDialog_GLChosenEditor) GUIDialog_GLChosenEditorMap[] = {
      45              :     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSEN_LOAD,       GUIDialog_GLChosenEditor::onCmdLoad),
      46              :     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSEN_SAVE,       GUIDialog_GLChosenEditor::onCmdSave),
      47              :     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSEN_DESELECT,   GUIDialog_GLChosenEditor::onCmdDeselect),
      48              :     FXMAPFUNC(SEL_COMMAND,  MID_CHOOSEN_CLEAR,      GUIDialog_GLChosenEditor::onCmdClear),
      49              :     FXMAPFUNC(SEL_COMMAND,  MID_CANCEL,             GUIDialog_GLChosenEditor::onCmdClose),
      50              : };
      51              : 
      52            0 : FXIMPLEMENT(GUIDialog_GLChosenEditor, FXMainWindow, GUIDialog_GLChosenEditorMap, ARRAYNUMBER(GUIDialog_GLChosenEditorMap))
      53              : 
      54              : 
      55              : // ===========================================================================
      56              : // method definitions
      57              : // ===========================================================================
      58              : 
      59            0 : GUIDialog_GLChosenEditor::GUIDialog_GLChosenEditor(GUIMainWindow* parent, GUISelectedStorage* str) :
      60              :     FXMainWindow(parent->getApp(), "List of Selected Items", GUIIconSubSys::getIcon(GUIIcon::APP_SELECTOR), nullptr, GUIDesignChooserDialog),
      61              :     GUIPersistentWindowPos(this, "DIALOG_EDIT_SELECTED", true, 20, 40, 300, 350),
      62            0 :     myParent(parent), myStorage(str) {
      63            0 :     myStorage->add2Update(this);
      64            0 :     FXHorizontalFrame* hbox = new FXHorizontalFrame(this, GUIDesignAuxiliarFrame);
      65              :     // create layout left
      66            0 :     FXVerticalFrame* layoutLeft = new FXVerticalFrame(hbox, GUIDesignChooserLayoutLeft);
      67              :     // create frame for list
      68            0 :     FXVerticalFrame* layoutList = new FXVerticalFrame(layoutLeft, GUIDesignChooserLayoutList);
      69              :     // build the list and rebuild it
      70            0 :     myList = new FXList(layoutList, this, MID_CHOOSER_LIST, GUIDesignChooserListMultiple);
      71            0 :     rebuildList();
      72              :     // build the layout
      73            0 :     FXVerticalFrame* layout = new FXVerticalFrame(hbox, GUIDesignChooserLayoutRight);
      74              :     // "Load"
      75            0 :     GUIDesigns::buildFXButton(layout, TL("&Load selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::OPEN), this, MID_CHOOSEN_LOAD, GUIDesignChooserButtons);
      76              :     // "Save"
      77            0 :     GUIDesigns::buildFXButton(layout, TL("&Save selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::SAVE), this, MID_CHOOSEN_SAVE, GUIDesignChooserButtons);
      78              :     // extra separator
      79            0 :     new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
      80              :     // "Deselect Chosen"
      81            0 :     GUIDesigns::buildFXButton(layout, TL("&Deselect chosen"), "", "", GUIIconSubSys::getIcon(GUIIcon::FLAG), this, MID_CHOOSEN_DESELECT, GUIDesignChooserButtons);
      82              :     // "Clear List"
      83            0 :     GUIDesigns::buildFXButton(layout, TL("&Clear selection"), "", "", GUIIconSubSys::getIcon(GUIIcon::FLAG), this, MID_CHOOSEN_CLEAR, GUIDesignChooserButtons);
      84              :     // extra separator
      85            0 :     new FXHorizontalSeparator(layout, GUIDesignHorizontalSeparator);
      86              :     // "Close"
      87            0 :     GUIDesigns::buildFXButton(layout, TL("Cl&ose"), "", "", GUIIconSubSys::getIcon(GUIIcon::NO), this, MID_CANCEL, GUIDesignChooserButtons);
      88            0 :     myParent->addChild(this);
      89            0 :     loadWindowPos();
      90            0 : }
      91              : 
      92              : 
      93            0 : GUIDialog_GLChosenEditor::~GUIDialog_GLChosenEditor() {
      94            0 :     myStorage->remove2Update();
      95            0 :     myParent->removeChild(this);
      96            0 : }
      97              : 
      98              : 
      99              : void
     100            0 : GUIDialog_GLChosenEditor::rebuildList() {
     101            0 :     myList->clearItems();
     102            0 :     const std::set<GUIGlID>& chosen = gSelected.getSelected();
     103            0 :     for (auto i : chosen) {
     104            0 :         GUIGlObject* object = GUIGlObjectStorage::gIDStorage.getObjectBlocking(i);
     105            0 :         if (object != nullptr) {
     106              :             std::string name = object->getFullName();
     107            0 :             FXListItem* item = myList->getItem(myList->appendItem(name.c_str()));
     108              :             item->setData(object);
     109            0 :             GUIGlObjectStorage::gIDStorage.unblockObject(i);
     110              :         }
     111              :     }
     112            0 : }
     113              : 
     114              : 
     115              : void
     116            0 : GUIDialog_GLChosenEditor::selectionUpdated() {
     117            0 :     rebuildList();
     118            0 :     FXMainWindow::update();
     119            0 : }
     120              : 
     121              : 
     122              : long
     123            0 : GUIDialog_GLChosenEditor::onCmdLoad(FXObject*, FXSelector, void*) {
     124              :     // get the new file name
     125            0 :     FXFileDialog opendialog(this, TL("Open List of Selected Items"));
     126            0 :     opendialog.setIcon(GUIIconSubSys::getIcon(GUIIcon::OPEN));
     127            0 :     opendialog.setSelectMode(SELECTFILE_EXISTING);
     128            0 :     opendialog.setPatternList("*.txt\nAll files (*)");
     129            0 :     if (gCurrentFolder.length() != 0) {
     130            0 :         opendialog.setDirectory(gCurrentFolder);
     131              :     }
     132            0 :     if (opendialog.execute()) {
     133            0 :         gCurrentFolder = opendialog.getDirectory();
     134            0 :         std::string file = opendialog.getFilename().text();
     135            0 :         std::string msg = gSelected.load(file);
     136            0 :         if (msg != "") {
     137            0 :             FXMessageBox::error(this, MBOX_OK, TL("Errors while loading Selection"), "%s", msg.c_str());
     138              :         }
     139            0 :         rebuildList();
     140            0 :         myParent->updateChildren();
     141              :     }
     142            0 :     return 1;
     143            0 : }
     144              : 
     145              : 
     146              : long
     147            0 : GUIDialog_GLChosenEditor::onCmdSave(FXObject*, FXSelector, void*) {
     148            0 :     FXString file = MFXUtils::getFilename2Write(this, TL("Save List of selected Items"), ".txt", GUIIconSubSys::getIcon(GUIIcon::SAVE), gCurrentFolder);
     149            0 :     if (file == "") {
     150              :         return 1;
     151              :     }
     152              :     try {
     153            0 :         gSelected.save(file.text());
     154            0 :     } catch (IOError& e) {
     155            0 :         FXMessageBox::error(this, MBOX_OK, TL("Storing failed!"), "%s", e.what());
     156            0 :     }
     157              :     return 1;
     158            0 : }
     159              : 
     160              : 
     161              : long
     162            0 : GUIDialog_GLChosenEditor::onCmdDeselect(FXObject*, FXSelector, void*) {
     163            0 :     FXint no = myList->getNumItems();
     164              :     FXint i;
     165              :     std::vector<GUIGlID> selected;
     166            0 :     for (i = 0; i < no; ++i) {
     167            0 :         if (myList->getItem(i)->isSelected()) {
     168            0 :             selected.push_back(static_cast<GUIGlObject*>(myList->getItem(i)->getData())->getGlID());
     169              :         }
     170              :     }
     171              :     // remove items from list
     172            0 :     for (i = 0; i < (FXint) selected.size(); ++i) {
     173            0 :         gSelected.deselect(selected[i]);
     174              :     }
     175              :     // rebuild list
     176            0 :     rebuildList();
     177            0 :     myParent->updateChildren();
     178            0 :     return 1;
     179            0 : }
     180              : 
     181              : 
     182              : long
     183            0 : GUIDialog_GLChosenEditor::onCmdClear(FXObject*, FXSelector, void*) {
     184            0 :     myList->clearItems();
     185            0 :     gSelected.clear();
     186            0 :     myParent->updateChildren();
     187            0 :     return 1;
     188              : }
     189              : 
     190              : 
     191              : long
     192            0 : GUIDialog_GLChosenEditor::onCmdClose(FXObject*, FXSelector, void*) {
     193            0 :     close(true);
     194            0 :     return 1;
     195              : }
     196              : 
     197              : 
     198              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1