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