SUMO - Simulation of Urban MObility
MFXUtils.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Some helper functions for FOX
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This file is part of SUMO.
00014 //   SUMO is free software: you can redistribute it and/or modify
00015 //   it under the terms of the GNU General Public License as published by
00016 //   the Free Software Foundation, either version 3 of the License, or
00017 //   (at your option) any later version.
00018 //
00019 /****************************************************************************/
00020 
00021 
00022 // ===========================================================================
00023 // included modules
00024 // ===========================================================================
00025 #ifdef _MSC_VER
00026 #include <windows_config.h>
00027 #else
00028 #include <config.h>
00029 #endif
00030 
00031 #include <utils/common/RGBColor.h>
00032 #include "MFXUtils.h"
00033 
00034 #ifdef CHECK_MEMORY_LEAKS
00035 #include <foreign/nvwa/debug_new.h>
00036 #endif // CHECK_MEMORY_LEAKS
00037 
00038 
00039 // ===========================================================================
00040 // method definitions
00041 // ===========================================================================
00042 void
00043 MFXUtils::deleteChildren(FXWindow* w) {
00044     while (w->numChildren() != 0) {
00045         FXWindow* child = w->childAtIndex(0);
00046         delete child;
00047     }
00048 }
00049 
00050 
00051 FXbool
00052 MFXUtils::userPermitsOverwritingWhenFileExists(FXWindow* const parent,
00053         const FXString& file) {
00054     if (!FXStat::exists(file)) {
00055         return TRUE;
00056     }
00057     int answer =
00058         FXMessageBox::question(parent, MBOX_YES_NO, "File Exists", "Overwrite '%s'?", file.text());
00059     if (answer == MBOX_CLICKED_NO) {
00060         return FALSE;
00061     }
00062     return TRUE;
00063 }
00064 
00065 
00066 FXString
00067 MFXUtils::getDocumentName(const FXString& filename) {
00068     return FXPath::name(filename);
00069 }
00070 
00071 
00072 FXString
00073 MFXUtils::getTitleText(const FXString& appname, FXString filename) {
00074     if (filename.length() == 0) {
00075         return appname;
00076     }
00077     return getDocumentName(filename) + " - " + appname;
00078 }
00079 
00080 
00081 FXString
00082 MFXUtils::assureExtension(const FXString& filename, const FXString& defaultExtension) {
00083     FXString ext = FXPath::extension(filename);
00084     if (ext == "") {
00085         if (filename.rfind('.') == filename.length() - 1) {
00086             return filename + defaultExtension;
00087         }
00088         return filename + "." + defaultExtension;
00089     }
00090     return filename;
00091 }
00092 
00093 
00094 FXString
00095 MFXUtils::getFilename2Write(FXWindow* parent,
00096                             const FXString& header, const FXString& extension,
00097                             FXIcon* icon, FXString& currentFolder) {
00098     // get the new file name
00099     FXFileDialog opendialog(parent, header);
00100     opendialog.setIcon(icon);
00101     opendialog.setSelectMode(SELECTFILE_ANY);
00102     opendialog.setPatternList("*" + extension);
00103     if (currentFolder.length() != 0) {
00104         opendialog.setDirectory(currentFolder);
00105     }
00106     if (!opendialog.execute()) {
00107         return "";
00108     }
00109     FXString file = assureExtension(opendialog.getFilename(), extension.after('.')).text();
00110     if (!userPermitsOverwritingWhenFileExists(parent, file)) {
00111         return "";
00112     }
00113     currentFolder = opendialog.getDirectory();
00114     return file;
00115 }
00116 
00117 
00118 RGBColor
00119 MFXUtils::getRGBColor(FXColor col) {
00120     return RGBColor(FXREDVAL(col) / 255.0, FXGREENVAL(col) / 255.0, FXBLUEVAL(col) / 255.0);
00121 }
00122 
00123 
00124 FXColor
00125 MFXUtils::getFXColor(const RGBColor& col) {
00126     return FXRGB(col.red() * 255, col.green() * 255, col.blue() * 255);
00127 }
00128 
00129 
00130 /****************************************************************************/
00131 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines