FEDEM Solver  R8.0
Source code of the dynamics solver
FFaMsg.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
8 #ifndef FFA_MSG_H
9 #define FFA_MSG_H
10 
11 #include <string>
12 #include <vector>
13 #include <stack>
14 #include <map>
15 
16 // The symbol ERROR might have already been defined if, e.g., windows.h
17 // is included before this header file. To avoid compiler problems due to name
18 // conflict with the FFaDialogType enum value below, it must be undefined here.
19 // TODO: Rename FFaMsg::ERROR to something else?
20 #ifdef ERROR
21 #undef ERROR
22 #endif
23 
28 #define ListUI FFaMsg::getMessager()
29 
30 class FaVec3;
31 
32 
37 class FFaMsg
38 {
39 public:
41  FFaMsg() {}
43  virtual ~FFaMsg() {}
44 
46  static void setMessager(FFaMsg* messager = NULL);
48  static FFaMsg& getMessager();
50  static bool usingDefault() { return ourCurrentMessager == NULL; }
51 
54  {
60  OK,
72  GENERIC
73  };
74 
75  // User feedback methods. These will be routed
76  // to the messager provided, or to the default one.
77 
78  static void resetToAllAnswer(const FFaDialogType type = _ALL_);
79 
80  static int dialog(const std::string& message,
82  const char** genericButtons = (const char**)NULL);
83 
84  static int dialog(const std::string& message,
85  const FFaDialogType type,
86  const std::vector<std::string>& buttonTexts);
87 
88  static int dialog(int& returnedSelectionIdx, const std::string& message,
89  const FFaDialogType type,
90  const std::vector<std::string>& buttonTexts,
91  const std::vector<std::string>& selectionList);
92 
93  static void list(const std::string& str, bool onScreen = false);
94  static void tip (const std::string& str);
95 
96  static void setStatus (const std::string& statusText);
97  static void changeStatus(const std::string& statusText);
98  static void pushStatus (const std::string& statusText);
99  static void popStatus ();
100 
101  static void enableSubSteps (int steps);
102  static void setSubStep (int step);
103  static void disableSubSteps();
104 
105  static void displayTime(int hour, int min, int sec);
106  static void clearTime ();
107 
108  static void setSubTask(const std::string& taskText);
109 
110  static void enableProgress (int nSteps);
111  static void setProgress (int progressStep);
112  static void disableProgress();
113 
114  // Stream-like operators for easy printing of messages to output list
115  friend FFaMsg& operator<< (FFaMsg&, const std::string&);
116  friend FFaMsg& operator<< (FFaMsg&, const char*);
117  friend FFaMsg& operator<< (FFaMsg&, const FaVec3&);
118  friend FFaMsg& operator<< (FFaMsg&, double);
119  friend FFaMsg& operator<< (FFaMsg&, char);
120  friend FFaMsg& operator<< (FFaMsg&, int);
121  friend FFaMsg& operator<< (FFaMsg&, long long int);
122  friend FFaMsg& operator<< (FFaMsg&, size_t);
123 
125  virtual bool openListFile(const char* = NULL, bool = false) { return true; }
127  virtual void closeListFile() {}
128 
129 protected:
130 
131  // Virtual methods reimplemented to make real GUI meaning
132 
133  virtual int dialogVt(const std::string& message,
134  const FFaDialogType type,
135  const char** genericButtons);
136  virtual int dialogVt(const std::string& message,
137  const FFaDialogType type,
138  const std::vector<std::string>& buttonTexts);
139  virtual int dialogVt(int& returnedSelectionIdx,
140  const std::string& message,
141  const FFaDialogType type,
142  const std::vector<std::string>& buttonTexts,
143  const std::vector<std::string>& selectionList);
144 
145  virtual void listVt(const std::string& str, bool onScreen = false);
146  virtual void tipVt (const std::string& str);
147 
148  virtual void setStatusVt (const std::string&) {}
149  virtual void changeStatusVt(const std::string&) {}
150  virtual void pushStatusVt (const std::string&) {}
151  virtual void popStatusVt () {}
152 
153  static void showStatus();
154 
155  virtual void enableSubStepsVt (int) {}
156  virtual void setSubStepVt (int) {}
157  virtual void disableSubStepsVt() {}
158 
159  virtual void displayTimeVt(int, int, int) {}
160  virtual void clearTimeVt () {}
161 
162  virtual void setSubTaskVt(const std::string&) {}
163 
164  virtual void enableProgressVt (int) {}
165  virtual void setProgressVt (int) {}
166  virtual void disableProgressVt() {}
167 
168  static std::stack<std::string> ourStatuses;
169 
170 private:
171  static std::map<FFaDialogType,int> ourToAllAnswer;
172 
174 };
175 
176 #endif
Interface class for various user feedback.
Definition: FFaMsg.H:38
virtual void popStatusVt()
Definition: FFaMsg.H:151
virtual void disableProgressVt()
Definition: FFaMsg.H:166
FFaDialogType
Enums defining various dialog box types.
Definition: FFaMsg.H:54
@ YES_NO_CANCEL
Definition: FFaMsg.H:63
@ _ALL_
Definition: FFaMsg.H:64
@ OK_CANCEL
Definition: FFaMsg.H:61
@ ERROR
Definition: FFaMsg.H:59
@ OK
Definition: FFaMsg.H:60
@ GENERIC
Definition: FFaMsg.H:72
@ DISMISS_ERROR
Definition: FFaMsg.H:56
@ YES_ALL_NO_ALL
Definition: FFaMsg.H:67
@ DISMISS_WARNING
Definition: FFaMsg.H:55
@ YES_NO_ALL_CANCEL
Definition: FFaMsg.H:71
@ YES_NO_ALL
Definition: FFaMsg.H:70
@ YES_ALL_NO_ALL_CANCEL
Definition: FFaMsg.H:69
@ YES_ALL_NO_CANCEL
Definition: FFaMsg.H:68
@ OK_ALL_CANCEL
Definition: FFaMsg.H:65
@ WARNING
Definition: FFaMsg.H:58
@ YES_NO
Definition: FFaMsg.H:62
@ YES_ALL_NO
Definition: FFaMsg.H:66
@ DISMISS_INFO
Definition: FFaMsg.H:57
static int dialog(const std::string &message, const FFaDialogType type=DISMISS_WARNING, const char **genericButtons=(const char **) NULL)
Shows a dialog according to the dialog type.
Definition: FFaMsg.C:44
FFaMsg()
Default constructor.
Definition: FFaMsg.H:41
friend FFaMsg & operator<<(FFaMsg &, const std::string &)
Definition: FFaMsg.C:245
static FFaMsg * ourCurrentMessager
Definition: FFaMsg.H:173
virtual void disableSubStepsVt()
Definition: FFaMsg.H:157
virtual void setProgressVt(int)
Definition: FFaMsg.H:165
static void disableProgress()
Definition: FFaMsg.C:239
virtual void displayTimeVt(int, int, int)
Definition: FFaMsg.H:159
static void clearTime()
Definition: FFaMsg.C:218
virtual void setSubTaskVt(const std::string &)
Definition: FFaMsg.H:162
virtual void setSubStepVt(int)
Definition: FFaMsg.H:156
static void setSubStep(int step)
Definition: FFaMsg.C:202
virtual void enableSubStepsVt(int)
Definition: FFaMsg.H:155
static FFaMsg & getMessager()
Returns the current messager object.
Definition: FFaMsg.C:25
static void setProgress(int progressStep)
Definition: FFaMsg.C:234
static void enableSubSteps(int steps)
Definition: FFaMsg.C:197
virtual ~FFaMsg()
Empty destructor.
Definition: FFaMsg.H:43
static void tip(const std::string &str)
Definition: FFaMsg.C:168
virtual void changeStatusVt(const std::string &)
Definition: FFaMsg.H:149
static void pushStatus(const std::string &statusText)
Definition: FFaMsg.C:186
static std::stack< std::string > ourStatuses
Definition: FFaMsg.H:168
static void resetToAllAnswer(const FFaDialogType type=_ALL_)
Definition: FFaMsg.C:135
virtual void enableProgressVt(int)
Definition: FFaMsg.H:164
static void setMessager(FFaMsg *messager=NULL)
Sets the real messager object to be used.
Definition: FFaMsg.C:18
static std::map< FFaDialogType, int > ourToAllAnswer
Definition: FFaMsg.H:171
virtual void setStatusVt(const std::string &)
Definition: FFaMsg.H:148
static void showStatus()
Definition: FFaMsg.C:357
virtual void clearTimeVt()
Definition: FFaMsg.H:160
virtual void listVt(const std::string &str, bool onScreen=false)
Definition: FFaMsg.C:345
virtual void pushStatusVt(const std::string &)
Definition: FFaMsg.H:150
static void disableSubSteps()
Definition: FFaMsg.C:207
static void setStatus(const std::string &statusText)
Definition: FFaMsg.C:174
static void enableProgress(int nSteps)
Definition: FFaMsg.C:229
static void displayTime(int hour, int min, int sec)
Definition: FFaMsg.C:213
static void popStatus()
Definition: FFaMsg.C:191
virtual void closeListFile()
Closes the list file.
Definition: FFaMsg.H:127
static void changeStatus(const std::string &statusText)
Definition: FFaMsg.C:180
static void list(const std::string &str, bool onScreen=false)
Definition: FFaMsg.C:162
virtual bool openListFile(const char *=NULL, bool=false)
Opens a list file containing a copy of the output list window.
Definition: FFaMsg.H:125
static void setSubTask(const std::string &taskText)
Definition: FFaMsg.C:223
static bool usingDefault()
Returns true if we are using the default messager.
Definition: FFaMsg.H:50
virtual int dialogVt(const std::string &message, const FFaDialogType type, const char **genericButtons)
Definition: FFaMsg.C:302
virtual void tipVt(const std::string &str)
Definition: FFaMsg.C:351
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
character(len=40) type
Function type flag.
Definition: initiateFunctionTypeModule.f90:33