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  @file RunContextManager.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__
41 #define __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__
42 
43 
44 #include <string>
45 
46 #include <QString>
47 #include <QVariant>
48 #include <QSettings>
49 
50 #include <openfluid/dllexport.hpp>
53 #include <openfluid/ware/TypeDefs.hpp>
55 
56 
57 namespace openfluid { namespace base {
58 
59 
61 {
62 
64 
65 
66  private:
67 
68  std::string m_OutputDir;
69 
70  std::string m_InputDir;
71 
72  bool m_IsClearOutputDir;
73 
74  bool m_IsProfiling;
75 
76  unsigned int m_ValuesBufferSize;
77 
78  unsigned int m_WaresMaxNumThreads;
79 
80  openfluid::core::MapValue m_WaresSharedEnvironment;
81 
82  openfluid::core::MapValue m_ExtraProperties;
83 
84  QSettings* mp_ProjectFile;
85 
86  std::string m_ProjectPath;
87 
88  std::string m_ProjectName;
89 
90  std::string m_ProjectDescription;
91 
92  std::string m_ProjectAuthors;
93 
94  std::string m_ProjectCreationDate;
95 
96  std::string m_ProjectLastModDate;
97 
98  bool m_ProjectIncOutputDir;
99 
100  bool m_ProjectIsOpen;
101 
102  static QString m_ProjectFileGroupName;
103 
105 
107 
108  static std::string getNow();
109 
110  void updateWaresEnvironment();
111 
112  static std::string getFilePathFromProjectPath(const std::string& ProjectPath);
113 
114  static std::string getInputDirFromProjectPath(const std::string& ProjectPath);
115 
116  static std::string getOuputDirFromProjectPath(const std::string& ProjectPath);
117 
118  static bool checkProject(const std::string& ProjectPath);
119 
120 
121  public:
122 
123  /**
124  Returns the full path of the simulation input directory
125  @return the full path of the directory
126  */
127  std::string getInputDir() const
128  {
129  return m_InputDir;
130  }
131 
132  /**
133  Returns the full path of a file or directory relative to the simulation input directory
134  @param[in] Filename the path relative to the simulation input directory
135  @return the full path to the file or directory
136  */
137  std::string getInputFullPath(const std::string& Filename) const
138  {
139  return m_InputDir + "/" + Filename;
140  }
141 
142  /**
143  Sets the full path of the simulation input directory
144  @return the full path of the directory
145  */
146  void setInputDir(const std::string& InputDir);
147 
148  /**
149  Returns the full path of the simulation output directory
150  @return the full path of the directory
151  */
152  std::string getOutputDir() const
153  {
154  return m_OutputDir;
155  }
156 
157  /**
158  Returns the full path of a file or directory relative to the simulation output directory
159  @param[in] Filename the path relative to the simulation output directory
160  @return the full path to the file or directory
161  */
162  std::string getOutputFullPath(const std::string& Filename) const
163  {
164  return m_OutputDir + "/" + Filename;
165  }
166 
167  /**
168  Sets the full path of the simulation output directory
169  @return the full path of the directory
170  */
171  void setOutputDir(const std::string& OutputDir);
172 
173  void setDateTimeOutputDir();
174 
175  /**
176  Returns the status of automatic cleaning of output directory before simulation run
177  @return true if enabled, false if disabled
178  */
179  bool isClearOutputDir() const
180  {
181  return m_IsClearOutputDir;
182  }
183 
184  /**
185  Sets the status of automatic cleaning of output directory before simulation run
186  @param Enabled set to true to enable
187  */
188  void setClearOutputDir(bool Enabled)
189  {
190  m_IsClearOutputDir = Enabled;
191  }
192 
193  /**
194  Returns the status of simulation profiling
195  @return true if enabled, false if disabled
196  */
197  bool isProfiling() const
198  {
199  return m_IsProfiling;
200  }
201 
202  /**
203  Sets the status of simulation profiling
204  @param Enabled set to true to enable
205  */
206  void setProfiling(bool Enabled)
207  {
208  m_IsProfiling = Enabled;
209  }
210 
211  /**
212  Returns the size of the buffer set by the user for simulation variables values
213  @return the size of the buffer
214  */
215  unsigned int getValuesBufferUserSize() const
216  {
217  return m_ValuesBufferSize;
218  }
219 
220  /**
221  Sets the size of the buffer set by the user for simulation variables values
222  @param[in] Size the size of the buffer
223  */
224  void setValuesBufferUserSize(unsigned int Size)
225  {
226  m_ValuesBufferSize = Size;
227  }
228 
229  /**
230  Unsets the size of the buffer set by the user for simulation variables values
231  @return the size of the buffer
232  */
234  { m_ValuesBufferSize = 0; }
235 
236  /**
237  Returns true if the size of the buffer for simulation variables values has been set by the user
238  @return true if set by user (size > 0), false otherwise
239  */
241  {
242  return (m_ValuesBufferSize > 0);
243  }
244 
245  /**
246  Returns the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...)
247  @return the maximum threads count
248  */
249  unsigned int getWaresMaxNumThreads() const
250  {
251  return m_WaresMaxNumThreads;
252  }
253 
254  /**
255  Sets the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...)
256  @param[in] Num the maximum threads count
257  */
258  void setWaresMaxNumThreads(unsigned int Num)
259  {
260  m_WaresMaxNumThreads = Num;
261  }
262 
263  /**
264  Resets the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...).
265  The value is reset to the ideal thread count given by the OpenFLUID environment
266  */
267  void resetWaresMaxNumThreads();
268 
270  {
271  return m_ExtraProperties;
272  }
273 
275  {
276  return m_WaresSharedEnvironment;
277  }
278 
279  void processWareParams(openfluid::ware::WareParams_t& Params) const;
280 
281  std::string getProjectPath() const
282  {
283  return m_ProjectPath;
284  }
285 
286  std::string getProjectName() const
287  {
288  return m_ProjectName;
289  }
290 
291  void setProjectName(const std::string& Name)
292  {
293  m_ProjectName = Name;
294  }
295 
296  std::string getProjectDescription() const
297  {
298  return m_ProjectDescription;
299  }
300 
301  void setProjectDescription(const std::string& Description)
302  {
303  m_ProjectDescription = Description;
304  }
305 
306  std::string getProjectAuthors() const
307  {
308  return m_ProjectAuthors;
309  }
310 
311  void setProjectAuthors(const std::string& Authors)
312  {
313  m_ProjectAuthors = Authors;
314  }
315 
316  std::string getProjectCreationDate() const
317  {
318  return m_ProjectCreationDate;
319  }
320 
321  void setProjectCreationDate(const std::string& CreationDate)
322  {
323  m_ProjectCreationDate = CreationDate;
324  }
325 
327  {
328  m_ProjectCreationDate = getNow();
329  }
330 
331  std::string getProjectLastModDate() const
332  {
333  return m_ProjectLastModDate;
334  }
335 
336  void setProjectLastModDate(const std::string& LastModDate)
337  {
338  m_ProjectLastModDate = LastModDate;
339  }
340 
342  {
343  return m_ProjectIncOutputDir;
344  }
345 
346  void setProjectIncrementalOutputDir(const bool Inc)
347  {
348  m_ProjectIncOutputDir = Inc;
349  }
350 
351  bool openProject(const std::string& Path);
352 
353  bool createProject(const std::string& Path, const std::string& Name,
354  const std::string& Description, const std::string& Authors,
355  const bool Inc);
356 
357  bool isProjectOpen() const
358  {
359  return m_ProjectIsOpen;
360  }
361 
362  bool saveProject();
363 
364  void closeProject();
365 
366  static bool isProject(const std::string& Path);
367 
368  static bool getProjectInfos(const std::string& Path,
369  std::string& Name, std::string& Description, std::string& Authors,
370  std::string& CreationDate, std::string& LastModDate);
371 
372  void updateProjectOutputDir();
373 
374  QVariant getProjectConfigValue(const QString& Group, const QString& Key) const;
375 
376  void setProjectConfigValue(const QString& Group, const QString& Key, const QVariant& Value);
377 
378 };
379 
380 
381 } } //namespaces
382 
383 
384 #endif /* __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__ */
Definition: RunContextManager.hpp:60
unsigned int getValuesBufferUserSize() const
Definition: RunContextManager.hpp:215
void setProjectCreationDateAsNow()
Definition: RunContextManager.hpp:326
std::string getProjectLastModDate() const
Definition: RunContextManager.hpp:331
std::string getProjectPath() const
Definition: RunContextManager.hpp:281
std::string getInputDir() const
Definition: RunContextManager.hpp:127
void setProjectDescription(const std::string &Description)
Definition: RunContextManager.hpp:301
bool isProjectOpen() const
Definition: RunContextManager.hpp:357
bool isClearOutputDir() const
Definition: RunContextManager.hpp:179
std::string getProjectDescription() const
Definition: RunContextManager.hpp:296
void setProjectLastModDate(const std::string &LastModDate)
Definition: RunContextManager.hpp:336
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:128
void setProjectCreationDate(const std::string &CreationDate)
Definition: RunContextManager.hpp:321
void setClearOutputDir(bool Enabled)
Definition: RunContextManager.hpp:188
std::string getOutputFullPath(const std::string &Filename) const
Definition: RunContextManager.hpp:162
std::string getProjectName() const
Definition: RunContextManager.hpp:286
const openfluid::core::MapValue & getWaresEnvironment() const
Definition: RunContextManager.hpp:274
void setProjectAuthors(const std::string &Authors)
Definition: RunContextManager.hpp:311
void setProjectIncrementalOutputDir(const bool Inc)
Definition: RunContextManager.hpp:346
unsigned int getWaresMaxNumThreads() const
Definition: RunContextManager.hpp:249
Definition: MapValue.hpp:92
std::string getOutputDir() const
Definition: RunContextManager.hpp:152
Definition: ApplicationException.hpp:47
#define OPENFLUID_SINGLETON_DEFINITION(T)
Definition: SingletonMacros.hpp:55
void setProfiling(bool Enabled)
Definition: RunContextManager.hpp:206
#define OPENFLUID_API
Definition: dllexport.hpp:86
std::string getProjectCreationDate() const
Definition: RunContextManager.hpp:316
std::string getInputFullPath(const std::string &Filename) const
Definition: RunContextManager.hpp:137
Definition: Environment.hpp:52
bool isProjectIncrementalOutputDir() const
Definition: RunContextManager.hpp:341
void setWaresMaxNumThreads(unsigned int Num)
Definition: RunContextManager.hpp:258
void setProjectName(const std::string &Name)
Definition: RunContextManager.hpp:291
void setValuesBufferUserSize(unsigned int Size)
Definition: RunContextManager.hpp:224
bool isValuesBufferUserSize() const
Definition: RunContextManager.hpp:240
bool isProfiling() const
Definition: RunContextManager.hpp:197
std::string getProjectAuthors() const
Definition: RunContextManager.hpp:306
void unsetValuesBufferUserSize()
Definition: RunContextManager.hpp:233
openfluid::core::MapValue & extraProperties()
Definition: RunContextManager.hpp:269