Manual for OpenFLUID 2.1.11

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  /**
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  {
151  return m_OutputDir;
152  }
153 
154  /**
155  Returns the full path of a file or directory relative to the simulation output directory
156  @param[in] Filename the path relative to the simulation output directory
157  @return the full path to the file or directory
158  */
159  std::string getOutputFullPath(const std::string& Filename) const;
160 
161  /**
162  Sets the full path of the simulation output directory
163  @return the full path of the directory
164  */
165  void setOutputDir(const std::string& OutputDir);
166 
167  void setDateTimeOutputDir();
168 
169  /**
170  Returns the status of automatic cleaning of output directory before simulation run
171  @return true if enabled, false if disabled
172  */
173  bool isClearOutputDir() const
174  {
175  return m_IsClearOutputDir;
176  }
177 
178  /**
179  Sets the status of automatic cleaning of output directory before simulation run
180  @param Enabled set to true to enable
181  */
182  void setClearOutputDir(bool Enabled)
183  {
184  m_IsClearOutputDir = Enabled;
185  }
186 
187  /**
188  Returns the status of simulation profiling
189  @return true if enabled, false if disabled
190  */
191  bool isProfiling() const
192  {
193  return m_IsProfiling;
194  }
195 
196  /**
197  Sets the status of simulation profiling
198  @param Enabled set to true to enable
199  */
200  void setProfiling(bool Enabled)
201  {
202  m_IsProfiling = Enabled;
203  }
204 
205  /**
206  Returns the size of the buffer set by the user for simulation variables values
207  @return the size of the buffer
208  */
209  unsigned int getValuesBufferUserSize() const
210  {
211  return m_ValuesBufferSize;
212  }
213 
214  /**
215  Sets the size of the buffer set by the user for simulation variables values
216  @param[in] Size the size of the buffer
217  */
218  void setValuesBufferUserSize(unsigned int Size)
219  {
220  m_ValuesBufferSize = Size;
221  }
222 
223  /**
224  Unsets the size of the buffer set by the user for simulation variables values
225  @return the size of the buffer
226  */
228  { m_ValuesBufferSize = 0; }
229 
230  /**
231  Returns true if the size of the buffer for simulation variables values has been set by the user
232  @return true if set by user (size > 0), false otherwise
233  */
235  {
236  return (m_ValuesBufferSize > 0);
237  }
238 
239  /**
240  Returns the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...)
241  @return the maximum threads count
242  */
243  unsigned int getWaresMaxNumThreads() const
244  {
245  return m_WaresMaxNumThreads;
246  }
247 
248  /**
249  Sets the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...)
250  @param[in] Num the maximum threads count
251  */
252  void setWaresMaxNumThreads(unsigned int Num)
253  {
254  m_WaresMaxNumThreads = Num;
255  }
256 
257  /**
258  Resets the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...).
259  The value is reset to the ideal thread count given by the OpenFLUID environment
260  */
261  void resetWaresMaxNumThreads();
262 
264  {
265  return m_ExtraProperties;
266  }
267 
269  {
270  return m_WaresSharedEnvironment;
271  }
272 
273  void processWareParams(openfluid::ware::WareParams_t& Params) const;
274 
275  std::string getProjectPath() const
276  {
277  return m_ProjectPath;
278  }
279 
280  std::string getProjectName() const
281  {
282  return m_ProjectName;
283  }
284 
285  void setProjectName(const std::string& Name)
286  {
287  m_ProjectName = Name;
288  }
289 
290  std::string getProjectDescription() const
291  {
292  return m_ProjectDescription;
293  }
294 
295  void setProjectDescription(const std::string& Description)
296  {
297  m_ProjectDescription = Description;
298  }
299 
300  std::string getProjectAuthors() const
301  {
302  return m_ProjectAuthors;
303  }
304 
305  void setProjectAuthors(const std::string& Authors)
306  {
307  m_ProjectAuthors = Authors;
308  }
309 
310  std::string getProjectCreationDate() const
311  {
312  return m_ProjectCreationDate;
313  }
314 
315  void setProjectCreationDate(const std::string& CreationDate)
316  {
317  m_ProjectCreationDate = CreationDate;
318  }
319 
321  {
322  m_ProjectCreationDate = getNow();
323  }
324 
325  std::string getProjectLastModDate() const
326  {
327  return m_ProjectLastModDate;
328  }
329 
330  void setProjectLastModDate(const std::string& LastModDate)
331  {
332  m_ProjectLastModDate = LastModDate;
333  }
334 
336  {
337  return m_ProjectIncOutputDir;
338  }
339 
340  void setProjectIncrementalOutputDir(const bool Inc)
341  {
342  m_ProjectIncOutputDir = Inc;
343  }
344 
345  bool openProject(const std::string& Path);
346 
347  bool createProject(const std::string& Path, const std::string& Name,
348  const std::string& Description, const std::string& Authors,
349  const bool Inc);
350 
351  bool isProjectOpen() const
352  {
353  return m_ProjectIsOpen;
354  }
355 
356  bool saveProject();
357 
358  void closeProject();
359 
360  static bool isProject(const std::string& Path);
361 
362  static bool getProjectInfos(const std::string& Path,
363  std::string& Name, std::string& Description, std::string& Authors,
364  std::string& CreationDate, std::string& LastModDate);
365 
366  void updateProjectOutputDir();
367 
368  QVariant getProjectConfigValue(const QString& Group, const QString& Key) const;
369 
370  void removeProjectConfigValue(const QString& Group, const QString& Key);
371 
372  void setProjectConfigValue(const QString& Group, const QString& Key, const QVariant& Value);
373 
374 };
375 
376 
377 } } //namespaces
378 
379 
380 #endif /* __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__ */
openfluid::base::RunContextManager::getOutputDir
std::string getOutputDir() const
Definition: RunContextManager.hpp:149
openfluid::base::RunContextManager::isProfiling
bool isProfiling() const
Definition: RunContextManager.hpp:191
openfluid::base::RunContextManager::extraProperties
openfluid::core::MapValue & extraProperties()
Definition: RunContextManager.hpp:263
OPENFLUID_API
#define OPENFLUID_API
Definition: dllexport.hpp:86
openfluid::core::MapValue
Definition: MapValue.hpp:92
openfluid::base::RunContextManager::getProjectLastModDate
std::string getProjectLastModDate() const
Definition: RunContextManager.hpp:325
openfluid::base::RunContextManager::setWaresMaxNumThreads
void setWaresMaxNumThreads(unsigned int Num)
Definition: RunContextManager.hpp:252
OPENFLUID_SINGLETON_DEFINITION
#define OPENFLUID_SINGLETON_DEFINITION(T)
Definition: SingletonMacros.hpp:55
openfluid::base::RunContextManager::setProfiling
void setProfiling(bool Enabled)
Definition: RunContextManager.hpp:200
openfluid::base::RunContextManager
Definition: RunContextManager.hpp:60
openfluid::base::RunContextManager::setProjectAuthors
void setProjectAuthors(const std::string &Authors)
Definition: RunContextManager.hpp:305
openfluid::base::RunContextManager::setProjectCreationDate
void setProjectCreationDate(const std::string &CreationDate)
Definition: RunContextManager.hpp:315
openfluid::base::RunContextManager::setProjectDescription
void setProjectDescription(const std::string &Description)
Definition: RunContextManager.hpp:295
openfluid
Definition: ApplicationException.hpp:47
SingletonMacros.hpp
openfluid::base::RunContextManager::setProjectLastModDate
void setProjectLastModDate(const std::string &LastModDate)
Definition: RunContextManager.hpp:330
openfluid::base::RunContextManager::setProjectIncrementalOutputDir
void setProjectIncrementalOutputDir(const bool Inc)
Definition: RunContextManager.hpp:340
openfluid::base::RunContextManager::setValuesBufferUserSize
void setValuesBufferUserSize(unsigned int Size)
Definition: RunContextManager.hpp:218
openfluid::base::RunContextManager::getWaresEnvironment
const openfluid::core::MapValue & getWaresEnvironment() const
Definition: RunContextManager.hpp:268
openfluid::base::RunContextManager::isValuesBufferUserSize
bool isValuesBufferUserSize() const
Definition: RunContextManager.hpp:234
MapValue.hpp
openfluid::base::RunContextManager::getInputDir
std::string getInputDir() const
Definition: RunContextManager.hpp:127
openfluid::base::RunContextManager::getValuesBufferUserSize
unsigned int getValuesBufferUserSize() const
Definition: RunContextManager.hpp:209
openfluid::base::RunContextManager::setProjectName
void setProjectName(const std::string &Name)
Definition: RunContextManager.hpp:285
openfluid::base::RunContextManager::unsetValuesBufferUserSize
void unsetValuesBufferUserSize()
Definition: RunContextManager.hpp:227
openfluid::base::RunContextManager::isClearOutputDir
bool isClearOutputDir() const
Definition: RunContextManager.hpp:173
openfluid::base::RunContextManager::getProjectDescription
std::string getProjectDescription() const
Definition: RunContextManager.hpp:290
openfluid::base::Environment
Definition: Environment.hpp:52
openfluid::base::RunContextManager::setProjectCreationDateAsNow
void setProjectCreationDateAsNow()
Definition: RunContextManager.hpp:320
openfluid::base::RunContextManager::getProjectPath
std::string getProjectPath() const
Definition: RunContextManager.hpp:275
openfluid::ware::WareParams_t
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:146
openfluid::base::RunContextManager::getProjectCreationDate
std::string getProjectCreationDate() const
Definition: RunContextManager.hpp:310
dllexport.hpp
openfluid::base::RunContextManager::getWaresMaxNumThreads
unsigned int getWaresMaxNumThreads() const
Definition: RunContextManager.hpp:243
openfluid::base::RunContextManager::isProjectIncrementalOutputDir
bool isProjectIncrementalOutputDir() const
Definition: RunContextManager.hpp:335
openfluid::base::RunContextManager::getProjectName
std::string getProjectName() const
Definition: RunContextManager.hpp:280
openfluid::base::RunContextManager::isProjectOpen
bool isProjectOpen() const
Definition: RunContextManager.hpp:351
openfluid::base::RunContextManager::setClearOutputDir
void setClearOutputDir(bool Enabled)
Definition: RunContextManager.hpp:182
openfluid::base::RunContextManager::getProjectAuthors
std::string getProjectAuthors() const
Definition: RunContextManager.hpp:300
Environment.hpp