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