Manual for OpenFLUID 2.1.10

WareSrcFactory.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 WareSrcFactory.hpp
35  @brief Header of ...
36 
37  @author Aline LIBRES <aline.libres@gmail.com>
38  */
39 
40 
41 #ifndef __OPENFLUID_WARESDEV_WARESRCFACTORY_HPP__
42 #define __OPENFLUID_WARESDEV_WARESRCFACTORY_HPP__
43 
44 
45 #include <QDir>
46 
47 #include <openfluid/dllexport.hpp>
51 
52 
53 namespace openfluid { namespace waresdev {
54 
55 
57 {
58  public:
59 
60  struct Replacements
61  {
62  private:
63 
64  QList<openfluid::builderext::ExtensionMode> BextMode_Data;
65 
66  QStringList BextCategory_Data;
67 
68  QStringList Sim2docMode_Data;
69 
70  public:
71 
72  QString ClassName;
73 
74  QString RootCppFilename;
75 
76  QString RootHppFilename;
77 
78  QString HppHeaderGuard;
79 
80  QString LinkUID;
81 
83 
85 
87 
89 
91 
92  QString ParamsUiComment;
93 
94  QString SignatureInfos;
95 
97 
99 
101 
103 
105 
107 
109 
111 
113 
114 
116  ParamsUiEnabled(false), ParamsUiClassname("ParamsUiWidget"), ParamsUiRootCppFilename(""),
117  ParamsUiRootHppFilename("ParamsUiWidget.hpp"), ParamsUiComment("//"), Sim2docModeIndex(0),
118  Sim2docInstall(false), BuilderExtModeIndex(-1), BuilderExtCategoryIndex(0)
119  {
122 
123  BextCategory_Data << "openfluid::builderext::CAT_SPATIAL" << "openfluid::builderext::CAT_MODEL"
124  << "openfluid::builderext::CAT_RESULTS" << "openfluid::builderext::CAT_OTHER";
125 
126  Sim2docMode_Data << "ON" << "AUTO" << "OFF";
127  }
128 
129  static QStringList getBuilderExtTypeTexts()
130  {
131  QStringList BextMode_Texts;
132  BextMode_Texts << QObject::tr("Modal") << QObject::tr("Modeless") << QObject::tr("Workspace");
133  return BextMode_Texts;
134  }
135 
136  static QStringList getBuilderExtCategoryTexts()
137  {
138  QStringList BextCategory_Texts;
139  BextCategory_Texts << QObject::tr("Spatial domain") << QObject::tr("Model") << QObject::tr("Results")
140  << QObject::tr("Other");
141  return BextCategory_Texts;
142  }
143 
144  static QStringList getSim2docModeTexts()
145  {
146  QStringList Sim2docMode_Texts;
147  Sim2docMode_Texts << QObject::tr("On - sim2doc must be run manually")
148  << QObject::tr("Auto - sim2doc is automatically run")
149  << QObject::tr("Off - sim2doc is disabled");
150  return Sim2docMode_Texts;
151  }
152 
154  {
155  return BextMode_Data.value(BuilderExtModeIndex, openfluid::builderext::MODE_UNKNOWN);
156  }
157 
158  QString getBuilderExtCategory() const
159  {
160  return BextCategory_Data.value(BuilderExtCategoryIndex, "");
161  }
162 
163  QString getSim2docMode() const
164  {
165  return Sim2docMode_Data.value(Sim2docModeIndex, "");
166  }
167 
168  QString getParamsUiEnabled() const
169  {
170  return ParamsUiEnabled ? "ON" : "OFF";
171  }
172 
173  QString getSim2docInstall() const
174  {
175  return Sim2docInstall ? "OFF" : "ON";
176  }
177 
178  };
179 
180 
181  private:
182 
183  QDir m_SharedTemplatesDir;
184 
185  QDir m_TypedTemplatesDir;
186 
187  QDir m_WareTypeDir;
188 
189  QString m_WareId;
190 
191  bool copyTemplateToNewFile(const QString& TemplatePath, const QString& NewFileName, QString& NewFilePath,
192  QString& ErrMsg);
193 
194  bool replaceInFile(const Replacements& R, const QString& NewFilePath, QString& ErrMsg);
195 
196  public:
197 
199 
200  ~WareSrcFactory();
201 
202  void setWareId(const QString& Id);
203 
204  /**
205  Creates a CMakeLists file in the ware directory, from the CMakeLists file template of the ware type.
206  @param NewFilePath A QString that will be filled with the absolute path of the created file
207  @param ErrMsg A QString that will be filled with error messages if the file creation fails
208  @return bool False if the file creation fails, true otherwise
209  */
210  bool createCMakeListsFile(QString& NewFilePath, QString& ErrMsg);
211 
212  /**
213  Creates a wareshub.json file in the ware directory, from the (shared) Json file template.
214  @param NewFilePath A QString that will be filled with the absolute path of the created file
215  @param ErrMsg A QString that will be filled with error messages if the file creation fails
216  @return bool False if the file creation fails, true otherwise
217  */
218  bool createJsonFile(QString& NewFilePath, QString& ErrMsg);
219 
220  /**
221  Creates a main cpp file in the ware directory, from the source file template of the ware type,
222  depending on the builder extension type (set to TYPE_UNKNOWN means it is not a Builder extension).
223  @param R Replacements struct containing the replacements to perform
224  @param NewFilePath A QString that will be filled with the absolute path of the created file
225  @param ErrMsg A QString that will be filled with error messages if the file creation fails
226  @return bool False if the file creation fails, true otherwise
227  */
228  bool createCppFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
229 
230  /**
231  Creates a main hpp file in the ware directory, from the header file template of the ware type
232  depending on the builder extension type (set to TYPE_UNKNOWN means it is not a Builder extension).
233  @param R Replacements struct containing the replacements to perform
234  @param NewFilePath A QString that will be filled with the absolute path of the created file
235  @param ErrMsg A QString that will be filled with error messages if the file creation fails
236  @return bool False if the file creation fails, true otherwise
237  */
238  bool createHppFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
239 
240  /**
241  Creates a ui-parameterization cpp file in the ware directory,
242  from the ui-parameterization source file template of the ware type.
243  @param R Replacements struct containing the replacements to perform
244  @param NewFilePath A QString that will be filled with the absolute path of the created file
245  @param ErrMsg A QString that will be filled with error messages if the file creation fails
246  @return bool False if the file creation fails, true otherwise
247  */
248  bool createParamUiCppFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
249 
250  /**
251  Creates a ui-parameterization hpp file in the ware directory,
252  from the ui-parameterization header file template of the ware type.
253  @param R Replacements struct containing the replacements to perform
254  @param NewFilePath A QString that will be filled with the absolute path of the created file
255  @param ErrMsg A QString that will be filled with error messages if the file creation fails
256  @return bool False if the file creation fails, true otherwise
257  */
258  bool createParamUiHppFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
259 
260  /**
261  Creates a Cmake.in.config file in the ware directory, from the Cmake.in.config file template of the ware type.
262  @param R Replacements struct containing the replacements to perform
263  @param NewFilePath A QString that will be filled with the absolute path of the created file
264  @param ErrMsg A QString that will be filled with error messages if the file creation fails
265  @return bool False if the file creation fails, true otherwise
266  */
267  bool createCmakeConfigFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
268 
269  static QRegExp getCppFilenameRegExp(QString& Tooltip, bool IsHpp = false);
270 
271  static QRegExp getClassnameRegExp(QString& Tooltip);
272 
273  static QRegExp getWareIdRegExp(QString& Tooltip);
274 
275  static QString getHeaderGuard(const QString& HppFilename);
276 
277  static QString getHppFilename(const QString& CppFilename);
278 
279  static QString getSimulatorSignatureInfos(const openfluid::ware::SimulatorSignature& Signature);
280 
281  static QString getSimulatorSignatureData(const openfluid::ware::SimulatorSignature& Signature);
282 
283  static QString getSimulatorInitCode(const openfluid::ware::SimulatorSignature& Signature);
284 
285  static QString getSimulatorRunCode(const openfluid::ware::SimulatorSignature& Signature);
286 
287  static QString getSimulatorSchedulingReturn(const openfluid::ware::SimulatorSignature& Signature);
288 
289 };
290 
291 
292 } } // namespaces
293 
294 
295 #endif /* __OPENFLUID_WARESDEV_WARESRCFACTORY_HPP__ */
ExtensionMode
Definition: BuilderExtensionSignature.hpp:58
Definition: WareSrcFactory.hpp:60
QString ParamsUiRootCppFilename
Definition: WareSrcFactory.hpp:86
Definition: BuilderExtensionSignature.hpp:58
Definition: ApplicationException.hpp:47
QString SimulatorRunCode
Definition: WareSrcFactory.hpp:104
QString ParamsUiComment
Definition: WareSrcFactory.hpp:92
QString getSim2docMode() const
Definition: WareSrcFactory.hpp:163
Definition: WareSrcFactory.hpp:56
QString getBuilderExtCategory() const
Definition: WareSrcFactory.hpp:158
QString ClassName
Definition: WareSrcFactory.hpp:72
int BuilderExtModeIndex
Definition: WareSrcFactory.hpp:108
QString SimulatorSignatureData
Definition: WareSrcFactory.hpp:100
QString ParamsUiHeaderGuard
Definition: WareSrcFactory.hpp:90
QString ParamsUiClassname
Definition: WareSrcFactory.hpp:84
bool ParamsUiEnabled
Definition: WareSrcFactory.hpp:82
WareType
Definition: TypeDefs.hpp:60
Definition: SimulatorSignature.hpp:308
static QStringList getSim2docModeTexts()
Definition: WareSrcFactory.hpp:144
Definition: BuilderExtensionSignature.hpp:58
Definition: BuilderExtensionSignature.hpp:58
QString RootCppFilename
Definition: WareSrcFactory.hpp:74
QString HppHeaderGuard
Definition: WareSrcFactory.hpp:78
Replacements()
Definition: WareSrcFactory.hpp:115
QString SimulatorInitCode
Definition: WareSrcFactory.hpp:102
bool Sim2docInstall
Definition: WareSrcFactory.hpp:98
Header of ...
QString RootHppFilename
Definition: WareSrcFactory.hpp:76
static QStringList getBuilderExtTypeTexts()
Definition: WareSrcFactory.hpp:129
openfluid::builderext::ExtensionMode getBuilderExtType() const
Definition: WareSrcFactory.hpp:153
Definition: BuilderExtensionSignature.hpp:58
QString getParamsUiEnabled() const
Definition: WareSrcFactory.hpp:168
QString ParamsUiRootHppFilename
Definition: WareSrcFactory.hpp:88
int BuilderExtCategoryIndex
Definition: WareSrcFactory.hpp:110
#define OPENFLUID_API
Definition: dllexport.hpp:86
int Sim2docModeIndex
Definition: WareSrcFactory.hpp:96
QString BuilderExtMenuText
Definition: WareSrcFactory.hpp:112
QString SimulatorSchedulingReturn
Definition: WareSrcFactory.hpp:106
QString SignatureInfos
Definition: WareSrcFactory.hpp:94
QString getSim2docInstall() const
Definition: WareSrcFactory.hpp:173
static QStringList getBuilderExtCategoryTexts()
Definition: WareSrcFactory.hpp:136
QString LinkUID
Definition: WareSrcFactory.hpp:80