All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 #include <QValidator>
47 #include <QRegExpValidator>
48 
49 #include <openfluid/dllexport.hpp>
53 
54 
55 namespace openfluid { namespace waresdev {
56 
57 
59 {
60  public:
61 
62  struct Replacements
63  {
64  private:
65 
66  QList<openfluid::builderext::ExtensionMode> BextMode_Data;
67  QStringList BextCategory_Data;
68  QStringList Sim2docMode_Data;
69 
70  public:
71 
72  QString ClassName;
73  QString RootCppFilename;
74  QString RootHppFilename;
75  QString HppHeaderGuard;
76  QString LinkUID;
82  QString ParamsUiComment;
83  QString SignatureInfos;
93 
94 
96  ParamsUiEnabled(false), ParamsUiClassname("ParamsUiWidget"), ParamsUiRootCppFilename(""),
97  ParamsUiRootHppFilename("ParamsUiWidget.hpp"), ParamsUiComment("//"), Sim2docModeIndex(0),
98  Sim2docInstall(false), BuilderExtModeIndex(-1), BuilderExtCategoryIndex(0)
99  {
102 
103  BextCategory_Data << "openfluid::builderext::CAT_SPATIAL" << "openfluid::builderext::CAT_MODEL"
104  << "openfluid::builderext::CAT_RESULTS" << "openfluid::builderext::CAT_OTHER";
105 
106  Sim2docMode_Data << "ON" << "AUTO" << "OFF";
107  }
108 
109  static QStringList getBuilderExtTypeTexts()
110  {
111  QStringList BextMode_Texts;
112  BextMode_Texts << QObject::tr("Modal") << QObject::tr("Modeless") << QObject::tr("Workspace");
113  return BextMode_Texts;
114  }
115 
116  static QStringList getBuilderExtCategoryTexts()
117  {
118  QStringList BextCategory_Texts;
119  BextCategory_Texts << QObject::tr("Spatial domain") << QObject::tr("Model") << QObject::tr("Results")
120  << QObject::tr("Other");
121  return BextCategory_Texts;
122  }
123 
124  static QStringList getSim2docModeTexts()
125  {
126  QStringList Sim2docMode_Texts;
127  Sim2docMode_Texts << QObject::tr("On - sim2doc must be run manually")
128  << QObject::tr("Auto - sim2doc is automatically run")
129  << QObject::tr("Off - sim2doc is disabled");
130  return Sim2docMode_Texts;
131  }
132 
134  {
135  return BextMode_Data.value(BuilderExtModeIndex, openfluid::builderext::MODE_UNKNOWN);
136  }
137 
138  QString getBuilderExtCategory() const
139  {
140  return BextCategory_Data.value(BuilderExtCategoryIndex, "");
141  }
142 
143  QString getSim2docMode() const
144  {
145  return Sim2docMode_Data.value(Sim2docModeIndex, "");
146  }
147 
148  QString getParamsUiEnabled() const
149  {
150  return ParamsUiEnabled ? "ON" : "OFF";
151  }
152 
153  QString getSim2docInstall() const
154  {
155  return Sim2docInstall ? "OFF" : "ON";
156  }
157 
158  };
159 
160  private:
161 
162  QDir m_SharedTemplatesDir;
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  static QRegExp getClassnameRegExp(QString& Tooltip);
249  static QRegExp getWareIdRegExp(QString& Tooltip);
250 
251  static QString getHeaderGuard(const QString& HppFilename);
252  static QString getHppFilename(const QString& CppFilename);
253 
254  static QString getSimulatorSignatureInfos(const openfluid::ware::SimulatorSignature& Signature);
255  static QString getSimulatorSignatureData(const openfluid::ware::SimulatorSignature& Signature);
256  static QString getSimulatorInitCode(const openfluid::ware::SimulatorSignature& Signature);
257  static QString getSimulatorRunCode(const openfluid::ware::SimulatorSignature& Signature);
258  static QString getSimulatorSchedulingReturn(const openfluid::ware::SimulatorSignature& Signature);
259 
260 };
261 
262 } } // namespaces
263 
264 #endif /* __OPENFLUID_WARESDEV_WARESRCFACTORY_HPP__ */
Replacements()
Definition: WareSrcFactory.hpp:95
int Sim2docModeIndex
Definition: WareSrcFactory.hpp:84
Definition: WareSrcFactory.hpp:58
QString BuilderExtMenuText
Definition: WareSrcFactory.hpp:92
Definition: WareSrcFactory.hpp:62
ExtensionMode
Definition: BuilderExtensionSignature.hpp:58
QString ParamsUiHeaderGuard
Definition: WareSrcFactory.hpp:81
QString SignatureInfos
Definition: WareSrcFactory.hpp:83
Definition: BuilderExtensionSignature.hpp:58
Definition: BuilderExtensionSignature.hpp:58
QString getSim2docInstall() const
Definition: WareSrcFactory.hpp:153
QString getSim2docMode() const
Definition: WareSrcFactory.hpp:143
QString SimulatorSchedulingReturn
Definition: WareSrcFactory.hpp:89
QString LinkUID
Definition: WareSrcFactory.hpp:76
openfluid::builderext::ExtensionMode getBuilderExtType() const
Definition: WareSrcFactory.hpp:133
QString ClassName
Definition: WareSrcFactory.hpp:72
Definition: BuilderExtensionSignature.hpp:58
QString HppHeaderGuard
Definition: WareSrcFactory.hpp:75
bool Sim2docInstall
Definition: WareSrcFactory.hpp:85
WareType
Definition: WareSrcManager.hpp:57
QString getParamsUiEnabled() const
Definition: WareSrcFactory.hpp:148
QString SimulatorSignatureData
Definition: WareSrcFactory.hpp:86
QString RootCppFilename
Definition: WareSrcFactory.hpp:73
static QStringList getBuilderExtCategoryTexts()
Definition: WareSrcFactory.hpp:116
QString SimulatorInitCode
Definition: WareSrcFactory.hpp:87
QString SimulatorRunCode
Definition: WareSrcFactory.hpp:88
int BuilderExtCategoryIndex
Definition: WareSrcFactory.hpp:91
QString getBuilderExtCategory() const
Definition: WareSrcFactory.hpp:138
QString ParamsUiComment
Definition: WareSrcFactory.hpp:82
QString ParamsUiClassname
Definition: WareSrcFactory.hpp:78
static QStringList getBuilderExtTypeTexts()
Definition: WareSrcFactory.hpp:109
int BuilderExtModeIndex
Definition: WareSrcFactory.hpp:90
bool ParamsUiEnabled
Definition: WareSrcFactory.hpp:77
Definition: BuilderExtensionSignature.hpp:58
QString ParamsUiRootCppFilename
Definition: WareSrcFactory.hpp:79
#define OPENFLUID_API
Definition: dllexport.hpp:87
QString RootHppFilename
Definition: WareSrcFactory.hpp:74
QString ParamsUiRootHppFilename
Definition: WareSrcFactory.hpp:80
Definition: SimulatorSignature.hpp:307
static QStringList getSim2docModeTexts()
Definition: WareSrcFactory.hpp:124
Header of ...