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