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