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