RunContextManager.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 
34 /**
35  @file RunContextManager.hpp
36 
37  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__
42 #define __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__
43 
44 
45 #include <string>
46 
47 #include <QString>
48 #include <QVariant>
49 #include <QSettings>
50 
51 #include <openfluid/dllexport.hpp>
54 #include <openfluid/ware/TypeDefs.hpp>
56 
57 
58 namespace openfluid { namespace base {
59 
60 
62 {
63 
65 
66 
67  private:
68 
69  std::string m_OutputDir;
70 
71  std::string m_InputDir;
72 
73  bool m_IsClearOutputDir;
74 
75  bool m_IsProfiling;
76 
77  unsigned int m_ValuesBufferSize;
78 
79  unsigned int m_WaresMaxNumThreads;
80 
81  openfluid::core::MapValue m_WaresSharedEnvironment;
82 
83  openfluid::core::MapValue m_ExtraProperties;
84 
85  QSettings* mp_ProjectFile;
86 
87  std::string m_ProjectPath;
88 
89  std::string m_ProjectName;
90 
91  std::string m_ProjectDescription;
92 
93  std::string m_ProjectAuthors;
94 
95  std::string m_ProjectCreationDate;
96 
97  std::string m_ProjectLastModDate;
98 
99  bool m_ProjectIncOutputDir;
100 
101  bool m_ProjectIsOpen;
102 
103  static QString m_ProjectFileGroupName;
104 
106 
108 
109  static std::string getNow();
110 
111  void updateWaresEnvironment();
112 
113  static std::string getFilePathFromProjectPath(const std::string& ProjectPath);
114 
115  static std::string getInputDirFromProjectPath(const std::string& ProjectPath);
116 
117  static std::string getOuputDirFromProjectPath(const std::string& ProjectPath);
118 
119  static bool checkProject(const std::string& ProjectPath);
120 
121 
122  public:
123 
124  /**
125  Returns the full path of the simulation input directory
126  @return the full path of the directory
127  */
128  std::string getInputDir() const
129  { return m_InputDir; }
130 
131  /**
132  Returns the full path of a file or directory relative to the simulation input directory
133  @param[in] Filename the path relative to the simulation input directory
134  @return the full path to the file or directory
135  */
136  std::string getInputFullPath(const std::string& Filename) const
137  { return m_InputDir + "/" + Filename; }
138 
139  /**
140  Sets the full path of the simulation input directory
141  @return the full path of the directory
142  */
143  void setInputDir(const std::string& InputDir);
144 
145  /**
146  Returns the full path of the simulation output directory
147  @return the full path of the directory
148  */
149  std::string getOutputDir() const
150  { return m_OutputDir; }
151 
152  /**
153  Returns the full path of a file or directory relative to the simulation output directory
154  @param[in] Filename the path relative to the simulation output directory
155  @return the full path to the file or directory
156  */
157  std::string getOutputFullPath(const std::string& Filename) const
158  { return m_OutputDir + "/" + Filename; }
159 
160  /**
161  Sets the full path of the simulation output directory
162  @return the full path of the directory
163  */
164  void setOutputDir(const std::string& OutputDir);
165 
166  void setDateTimeOutputDir();
167 
168  /**
169  Returns the status of automatic cleaning of output directory before simulation run
170  @return true if enabled, false if disabled
171  */
172  bool isClearOutputDir() const
173  { return m_IsClearOutputDir; }
174 
175  /**
176  Sets the status of automatic cleaning of output directory before simulation run
177  @param Enabled set to true to enable
178  */
179  void setClearOutputDir(bool Enabled)
180  { m_IsClearOutputDir = Enabled; }
181 
182  /**
183  Returns the status of simulation profiling
184  @return true if enabled, false if disabled
185  */
186  bool isProfiling() const
187  { return m_IsProfiling; }
188 
189  /**
190  Sets the status of simulation profiling
191  @param Enabled set to true to enable
192  */
193  void setProfiling(bool Enabled)
194  { m_IsProfiling = Enabled; }
195 
196  /**
197  Returns the size of the buffer set by the user for simulation variables values
198  @return the size of the buffer
199  */
200  unsigned int getValuesBufferUserSize() const
201  { return m_ValuesBufferSize; }
202 
203  /**
204  Sets the size of the buffer set by the user for simulation variables values
205  @param[in] Size the size of the buffer
206  */
207  void setValuesBufferUserSize(unsigned int Size)
208  { m_ValuesBufferSize = Size; }
209 
210  /**
211  Unsets the size of the buffer set by the user for simulation variables values
212  @return the size of the buffer
213  */
215  { m_ValuesBufferSize = 0; }
216 
217  /**
218  Returns true if the size of the buffer for simulation variables values has been set by the user
219  @return true if set by user (size > 0), false otherwise
220  */
222  { return (m_ValuesBufferSize > 0); }
223 
224  /**
225  Returns the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...)
226  @return the maximum threads count
227  */
228  unsigned int getWaresMaxNumThreads() const
229  { return m_WaresMaxNumThreads; }
230 
231  /**
232  Sets the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...)
233  @param[in] Num the maximum threads count
234  */
235  void setWaresMaxNumThreads(unsigned int Num)
236  { m_WaresMaxNumThreads = Num; }
237 
238  /**
239  Resets the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...).
240  The value is reset to the ideal thread count given by the OpenFLUID environment
241  */
242  void resetWaresMaxNumThreads();
243 
245  { return m_ExtraProperties; }
246 
248  { return m_WaresSharedEnvironment; }
249 
250  void processWareParams(openfluid::ware::WareParams_t& Params) const;
251 
252  std::string getProjectPath() const
253  { return m_ProjectPath; }
254 
255  std::string getProjectName() const
256  { return m_ProjectName; }
257 
258  void setProjectName(const std::string& Name)
259  { m_ProjectName = Name; }
260 
261  std::string getProjectDescription() const
262  { return m_ProjectDescription; }
263 
264  void setProjectDescription(const std::string& Description)
265  { m_ProjectDescription = Description; }
266 
267  std::string getProjectAuthors() const
268  { return m_ProjectAuthors; }
269 
270  void setProjectAuthors(const std::string& Authors)
271  { m_ProjectAuthors = Authors; }
272 
273  std::string getProjectCreationDate() const
274  { return m_ProjectCreationDate; }
275 
276  void setProjectCreationDate(const std::string& CreationDate)
277  { m_ProjectCreationDate = CreationDate; }
278 
280  { m_ProjectCreationDate = getNow(); }
281 
282  std::string getProjectLastModDate() const
283  { return m_ProjectLastModDate; }
284 
285  void setProjectLastModDate(const std::string& LastModDate)
286  { m_ProjectLastModDate = LastModDate; }
287 
289  { return m_ProjectIncOutputDir; }
290 
291  void setProjectIncrementalOutputDir(const bool Inc)
292  { m_ProjectIncOutputDir = Inc; }
293 
294  bool openProject(const std::string& Path);
295 
296  bool createProject(const std::string& Path, const std::string& Name,
297  const std::string& Description, const std::string& Authors,
298  const bool Inc);
299 
300  bool isProjectOpen() const
301  { return m_ProjectIsOpen; }
302 
303  bool saveProject();
304 
305  void closeProject();
306 
307  static bool isProject(const std::string& Path);
308 
309  static bool getProjectInfos(const std::string& Path,
310  std::string& Name, std::string& Description, std::string& Authors,
311  std::string& CreationDate, std::string& LastModDate);
312 
313  void updateProjectOutputDir();
314 
315  QVariant getProjectConfigValue(const QString& Group, const QString& Key) const;
316 
317  void setProjectConfigValue(const QString& Group, const QString& Key, const QVariant& Value);
318 
319 };
320 
321 
322 } } //namespaces
323 
324 
325 #endif /* __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__ */
const openfluid::core::MapValue & getWaresEnvironment() const
Definition: RunContextManager.hpp:247
void setProjectLastModDate(const std::string &LastModDate)
Definition: RunContextManager.hpp:285
std::string getProjectName() const
Definition: RunContextManager.hpp:255
void setWaresMaxNumThreads(unsigned int Num)
Definition: RunContextManager.hpp:235
std::string getInputDir() const
Definition: RunContextManager.hpp:128
Definition: Environment.hpp:52
unsigned int getValuesBufferUserSize() const
Definition: RunContextManager.hpp:200
void setProjectDescription(const std::string &Description)
Definition: RunContextManager.hpp:264
bool isProfiling() const
Definition: RunContextManager.hpp:186
void setProjectName(const std::string &Name)
Definition: RunContextManager.hpp:258
bool isValuesBufferUserSize() const
Definition: RunContextManager.hpp:221
std::string getProjectCreationDate() const
Definition: RunContextManager.hpp:273
std::string getOutputDir() const
Definition: RunContextManager.hpp:149
Definition: MapValue.hpp:134
void setProjectIncrementalOutputDir(const bool Inc)
Definition: RunContextManager.hpp:291
void setClearOutputDir(bool Enabled)
Definition: RunContextManager.hpp:179
std::string getInputFullPath(const std::string &Filename) const
Definition: RunContextManager.hpp:136
bool isProjectOpen() const
Definition: RunContextManager.hpp:300
std::string getProjectPath() const
Definition: RunContextManager.hpp:252
std::string getProjectAuthors() const
Definition: RunContextManager.hpp:267
void setProfiling(bool Enabled)
Definition: RunContextManager.hpp:193
bool isClearOutputDir() const
Definition: RunContextManager.hpp:172
#define OPENFLUID_SINGLETON_DEFINITION(T)
Definition: SingletonMacros.hpp:78
unsigned int getWaresMaxNumThreads() const
Definition: RunContextManager.hpp:228
Definition: ApplicationException.hpp:47
std::string getProjectDescription() const
Definition: RunContextManager.hpp:261
#define OPENFLUID_API
Definition: dllexport.hpp:87
void setProjectCreationDateAsNow()
Definition: RunContextManager.hpp:279
std::string getOutputFullPath(const std::string &Filename) const
Definition: RunContextManager.hpp:157
std::string getProjectLastModDate() const
Definition: RunContextManager.hpp:282
void setProjectAuthors(const std::string &Authors)
Definition: RunContextManager.hpp:270
void unsetValuesBufferUserSize()
Definition: RunContextManager.hpp:214
Definition: RunContextManager.hpp:61
bool isProjectIncrementalOutputDir() const
Definition: RunContextManager.hpp:288
void setProjectCreationDate(const std::string &CreationDate)
Definition: RunContextManager.hpp:276
void setValuesBufferUserSize(unsigned int Size)
Definition: RunContextManager.hpp:207
openfluid::core::MapValue & extraProperties()
Definition: RunContextManager.hpp:244
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:130