SUMO - Simulation of Urban MObility
MFXUtils.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2006-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // Some helper functions for FOX
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <utils/common/RGBColor.h>
31 #include "MFXUtils.h"
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
37 void
39  while (w->numChildren() != 0) {
40  FXWindow* child = w->childAtIndex(0);
41  delete child;
42  }
43 }
44 
45 
46 FXbool
48  const FXString& file) {
49  if (!FXStat::exists(file)) {
50  return TRUE;
51  }
52  int answer =
53  FXMessageBox::question(parent, MBOX_YES_NO, "File Exists", "Overwrite '%s'?", file.text());
54  if (answer == MBOX_CLICKED_NO) {
55  return FALSE;
56  }
57  return TRUE;
58 }
59 
60 
61 FXString
62 MFXUtils::getDocumentName(const FXString& filename) {
63  return FXPath::name(filename);
64 }
65 
66 
67 FXString
68 MFXUtils::getTitleText(const FXString& appname, FXString filename) {
69  if (filename.length() == 0) {
70  return appname;
71  }
72  return getDocumentName(filename) + " - " + appname;
73 }
74 
75 
76 FXString
77 MFXUtils::assureExtension(const FXString& filename, const FXString& defaultExtension) {
78  FXString ext = FXPath::extension(filename);
79  if (ext == "") {
80  if (filename.rfind('.') == filename.length() - 1) {
81  return filename + defaultExtension;
82  }
83  return filename + "." + defaultExtension;
84  }
85  return filename;
86 }
87 
88 
89 FXString
90 MFXUtils::getFilename2Write(FXWindow* parent,
91  const FXString& header, const FXString& extension,
92  FXIcon* icon, FXString& currentFolder) {
93  // get the new file name
94  FXFileDialog opendialog(parent, header);
95  opendialog.setIcon(icon);
96  opendialog.setSelectMode(SELECTFILE_ANY);
97  opendialog.setPatternList("*" + extension);
98  if (currentFolder.length() != 0) {
99  opendialog.setDirectory(currentFolder);
100  }
101  if (!opendialog.execute()) {
102  return "";
103  }
104  FXString file = assureExtension(opendialog.getFilename(), extension.after('.')).text();
105  if (!userPermitsOverwritingWhenFileExists(parent, file)) {
106  return "";
107  }
108  currentFolder = opendialog.getDirectory();
109  return file;
110 }
111 
112 
113 RGBColor
114 MFXUtils::getRGBColor(FXColor col) {
115  return RGBColor(FXREDVAL(col), FXGREENVAL(col), FXBLUEVAL(col), FXALPHAVAL(col));
116 }
117 
118 
119 FXColor
121  return FXRGBA(col.red(), col.green(), col.blue(), col.alpha());
122 }
123 
124 
125 /****************************************************************************/
126 
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:89
static RGBColor getRGBColor(FXColor col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:114
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:47
static void deleteChildren(FXWindow *w)
Deletes all children of the given window.
Definition: MFXUtils.cpp:38
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:82
static FXString getFilename2Write(FXWindow *parent, const FXString &header, const FXString &extension, FXIcon *icon, FXString &currentFolder)
Returns the file name to write.
Definition: MFXUtils.cpp:90
static FXString assureExtension(const FXString &filename, const FXString &defaultExtension)
Corrects missing extension.
Definition: MFXUtils.cpp:77
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:75
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:120
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:68
static FXString getTitleText(const FXString &appname, FXString filename="")
Returns the title text in dependance to an optional file name.
Definition: MFXUtils.cpp:68
static FXString getDocumentName(const FXString &filename)
Returns the document name.
Definition: MFXUtils.cpp:62