LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXUtils.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 6 43 14.0 %
Date: 2024-04-27 15:34:54 Functions: 2 8 25.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2006-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    MFXUtils.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @date    2006-01-09
      17             : ///
      18             : // Some helper functions for FOX
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : #include <utils/common/RGBColor.h>
      23             : #include "MFXUtils.h"
      24             : 
      25             : 
      26             : // ===========================================================================
      27             : // method definitions
      28             : // ===========================================================================
      29             : void
      30           0 : MFXUtils::deleteChildren(FXWindow* w) {
      31           0 :     while (w->numChildren() != 0) {
      32           0 :         FXWindow* child = w->childAtIndex(0);
      33           0 :         delete child;
      34             :     }
      35           0 : }
      36             : 
      37             : 
      38             : FXbool
      39           0 : MFXUtils::userPermitsOverwritingWhenFileExists(FXWindow* const parent,
      40             :         const FXString& file) {
      41           0 :     if (!FXStat::exists(file)) {
      42             :         return TRUE;
      43             :     }
      44             :     int answer =
      45           0 :         FXMessageBox::question(parent, MBOX_YES_NO, "File Exists", "Overwrite '%s'?", file.text());
      46           0 :     if (answer == MBOX_CLICKED_NO) {
      47           0 :         return FALSE;
      48             :     }
      49             :     return TRUE;
      50             : }
      51             : 
      52             : 
      53             : FXString
      54        6823 : MFXUtils::getDocumentName(const FXString& filename) {
      55        6823 :     return FXPath::name(filename);
      56             : }
      57             : 
      58             : 
      59             : FXString
      60       35346 : MFXUtils::getTitleText(const FXString& appname, FXString filename) {
      61       35346 :     if (filename.length() == 0) {
      62       28523 :         return appname;
      63             :     }
      64        6823 :     return getDocumentName(filename) + " - " + appname;
      65             : }
      66             : 
      67             : 
      68             : FXString
      69           0 : MFXUtils::assureExtension(const FXString& filename, const FXString& defaultExtension) {
      70           0 :     FXString ext = FXPath::extension(filename);
      71           0 :     if (ext == "") {
      72           0 :         if (filename.rfind('.') == filename.length() - 1) {
      73           0 :             return filename + defaultExtension;
      74             :         }
      75           0 :         return filename + "." + defaultExtension;
      76             :     }
      77           0 :     return filename;
      78           0 : }
      79             : 
      80             : 
      81             : FXString
      82           0 : MFXUtils::getFilename2Write(FXWindow* parent,
      83             :                             const FXString& header, const FXString& extension,
      84             :                             FXIcon* icon, FXString& currentFolder) {
      85             :     // get the new file name
      86           0 :     FXFileDialog opendialog(parent, header);
      87           0 :     opendialog.setIcon(icon);
      88           0 :     opendialog.setSelectMode(SELECTFILE_ANY);
      89           0 :     opendialog.setPatternList("*" + extension);
      90           0 :     if (currentFolder.length() != 0) {
      91           0 :         opendialog.setDirectory(currentFolder);
      92             :     }
      93           0 :     if (!opendialog.execute()) {
      94           0 :         return "";
      95             :     }
      96           0 :     FXString file = assureExtension(opendialog.getFilename(), extension.after('.')).text();
      97           0 :     if (!userPermitsOverwritingWhenFileExists(parent, file)) {
      98           0 :         return "";
      99             :     }
     100           0 :     currentFolder = opendialog.getDirectory();
     101           0 :     return file;
     102           0 : }
     103             : 
     104             : 
     105             : RGBColor
     106           0 : MFXUtils::getRGBColor(FXColor col) {
     107           0 :     return RGBColor(FXREDVAL(col), FXGREENVAL(col), FXBLUEVAL(col), FXALPHAVAL(col));
     108             : }
     109             : 
     110             : 
     111             : FXColor
     112           0 : MFXUtils::getFXColor(const RGBColor& col) {
     113           0 :     return FXRGBA(col.red(), col.green(), col.blue(), col.alpha());
     114             : }
     115             : 
     116             : 
     117             : /****************************************************************************/

Generated by: LCOV version 1.14