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