SUMO - Simulation of Urban MObility
MFXUtils.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Some helper functions for FOX
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2006-2015 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <utils/common/RGBColor.h>
32 #include "MFXUtils.h"
33 
34 #ifdef CHECK_MEMORY_LEAKS
35 #include <foreign/nvwa/debug_new.h>
36 #endif // CHECK_MEMORY_LEAKS
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 void
44  while (w->numChildren() != 0) {
45  FXWindow* child = w->childAtIndex(0);
46  delete child;
47  }
48 }
49 
50 
51 FXbool
53  const FXString& file) {
54  if (!FXStat::exists(file)) {
55  return TRUE;
56  }
57  int answer =
58  FXMessageBox::question(parent, MBOX_YES_NO, "File Exists", "Overwrite '%s'?", file.text());
59  if (answer == MBOX_CLICKED_NO) {
60  return FALSE;
61  }
62  return TRUE;
63 }
64 
65 
66 FXString
67 MFXUtils::getDocumentName(const FXString& filename) {
68  return FXPath::name(filename);
69 }
70 
71 
72 FXString
73 MFXUtils::getTitleText(const FXString& appname, FXString filename) {
74  if (filename.length() == 0) {
75  return appname;
76  }
77  return getDocumentName(filename) + " - " + appname;
78 }
79 
80 
81 FXString
82 MFXUtils::assureExtension(const FXString& filename, const FXString& defaultExtension) {
83  FXString ext = FXPath::extension(filename);
84  if (ext == "") {
85  if (filename.rfind('.') == filename.length() - 1) {
86  return filename + defaultExtension;
87  }
88  return filename + "." + defaultExtension;
89  }
90  return filename;
91 }
92 
93 
94 FXString
95 MFXUtils::getFilename2Write(FXWindow* parent,
96  const FXString& header, const FXString& extension,
97  FXIcon* icon, FXString& currentFolder) {
98  // get the new file name
99  FXFileDialog opendialog(parent, header);
100  opendialog.setIcon(icon);
101  opendialog.setSelectMode(SELECTFILE_ANY);
102  opendialog.setPatternList("*" + extension);
103  if (currentFolder.length() != 0) {
104  opendialog.setDirectory(currentFolder);
105  }
106  if (!opendialog.execute()) {
107  return "";
108  }
109  FXString file = assureExtension(opendialog.getFilename(), extension.after('.')).text();
110  if (!userPermitsOverwritingWhenFileExists(parent, file)) {
111  return "";
112  }
113  currentFolder = opendialog.getDirectory();
114  return file;
115 }
116 
117 
118 RGBColor
119 MFXUtils::getRGBColor(FXColor col) {
120  return RGBColor(FXREDVAL(col), FXGREENVAL(col), FXBLUEVAL(col), FXALPHAVAL(col));
121 }
122 
123 
124 FXColor
126  return FXRGBA(col.red(), col.green(), col.blue(), col.alpha());
127 }
128 
129 
130 /****************************************************************************/
131 
static RGBColor getRGBColor(FXColor col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:119
static FXbool userPermitsOverwritingWhenFileExists(FXWindow *const parent, const FXString &file)
Returns true if either the file given by its name does not exist or the user allows overwriting it...
Definition: MFXUtils.cpp:52
static void deleteChildren(FXWindow *w)
Deletes all children of the given window.
Definition: MFXUtils.cpp:43
static FXString getFilename2Write(FXWindow *parent, const FXString &header, const FXString &extension, FXIcon *icon, FXString &currentFolder)
Returns the file name to write.
Definition: MFXUtils.cpp:95
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:99
static FXString assureExtension(const FXString &filename, const FXString &defaultExtension)
Corrects missing extension.
Definition: MFXUtils.cpp:82
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:125
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
static FXString getTitleText(const FXString &appname, FXString filename="")
Returns the title text in dependance to an optional file name.
Definition: MFXUtils.cpp:73
static FXString getDocumentName(const FXString &filename)
Returns the document name.
Definition: MFXUtils.cpp:67
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75