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 
161  private:
162 
163  QDir m_SharedTemplatesDir;
164 
165  QDir m_TypedTemplatesDir;
166 
167  QDir m_WareTypeDir;
168 
169  QString m_WareId;
170 
171  bool copyTemplateToNewFile(const QString& TemplatePath, const QString& NewFileName, QString& NewFilePath,
172  QString& ErrMsg);
173 
174  bool replaceInFile(const Replacements& R, const QString& NewFilePath, QString& ErrMsg);
175 
176  public:
177 
179 
180  ~WareSrcFactory();
181 
182  void setWareId(const QString& Id);
183 
184  /**
185  Creates a CMakeLists file in the ware directory, from the CMakeLists file template of the ware type.
186  @param NewFilePath A QString that will be filled with the absolute path of the created file
187  @param ErrMsg A QString that will be filled with error messages if the file creation fails
188  @return bool False if the file creation fails, true otherwise
189  */
190  bool createCMakeListsFile(QString& NewFilePath, QString& ErrMsg);
191 
192  /**
193  Creates a wareshub.json file in the ware directory, from the (shared) Json file template.
194  @param NewFilePath A QString that will be filled with the absolute path of the created file
195  @param ErrMsg A QString that will be filled with error messages if the file creation fails
196  @return bool False if the file creation fails, true otherwise
197  */
198  bool createJsonFile(QString& NewFilePath, QString& ErrMsg);
199 
200  /**
201  Creates a main cpp file in the ware directory, from the source file template of the ware type,
202  depending on the builder extension type (set to TYPE_UNKNOWN means it is not a Builder extension).
203  @param R Replacements struct containing the replacements to perform
204  @param NewFilePath A QString that will be filled with the absolute path of the created file
205  @param ErrMsg A QString that will be filled with error messages if the file creation fails
206  @return bool False if the file creation fails, true otherwise
207  */
208  bool createCppFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
209 
210  /**
211  Creates a main hpp file in the ware directory, from the header file template of the ware type
212  depending on the builder extension type (set to TYPE_UNKNOWN means it is not a Builder extension).
213  @param R Replacements struct containing the replacements to perform
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 createHppFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
219 
220  /**
221  Creates a ui-parameterization cpp file in the ware directory,
222  from the ui-parameterization source file template of the ware type.
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 createParamUiCppFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
229 
230  /**
231  Creates a ui-parameterization hpp file in the ware directory,
232  from the ui-parameterization header file template of the ware type.
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 createParamUiHppFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
239 
240  /**
241  Creates a Cmake.in.config file in the ware directory, from the Cmake.in.config file template of the ware type.
242  @param R Replacements struct containing the replacements to perform
243  @param NewFilePath A QString that will be filled with the absolute path of the created file
244  @param ErrMsg A QString that will be filled with error messages if the file creation fails
245  @return bool False if the file creation fails, true otherwise
246  */
247  bool createCmakeConfigFile(const Replacements& R, QString& NewFilePath, QString& ErrMsg);
248 
249  static QRegExp getCppFilenameRegExp(QString& Tooltip, bool IsHpp = false);
250 
251  static QRegExp getClassnameRegExp(QString& Tooltip);
252 
253  static QRegExp getWareIdRegExp(QString& Tooltip);
254 
255  static QString getHeaderGuard(const QString& HppFilename);
256 
257  static QString getHppFilename(const QString& CppFilename);
258 
259  static QString getSimulatorSignatureInfos(const openfluid::ware::SimulatorSignature& Signature);
260 
261  static QString getSimulatorSignatureData(const openfluid::ware::SimulatorSignature& Signature);
262 
263  static QString getSimulatorInitCode(const openfluid::ware::SimulatorSignature& Signature);
264 
265  static QString getSimulatorRunCode(const openfluid::ware::SimulatorSignature& Signature);
266 
267  static QString getSimulatorSchedulingReturn(const openfluid::ware::SimulatorSignature& Signature);
268 
269 };
270 
271 
272 } } // namespaces
273 
274 
275 #endif /* __OPENFLUID_WARESDEV_WARESRCFACTORY_HPP__ */
QString SignatureInfos
Definition: WareSrcFactory.hpp:83
QString BuilderExtMenuText
Definition: WareSrcFactory.hpp:92
QString getSim2docInstall() const
Definition: WareSrcFactory.hpp:153
QString SimulatorSchedulingReturn
Definition: WareSrcFactory.hpp:89
QString ParamsUiHeaderGuard
Definition: WareSrcFactory.hpp:81
Replacements()
Definition: WareSrcFactory.hpp:95
int Sim2docModeIndex
Definition: WareSrcFactory.hpp:84
ExtensionMode
Definition: BuilderExtensionSignature.hpp:58
QString getSim2docMode() const
Definition: WareSrcFactory.hpp:143
QString ClassName
Definition: WareSrcFactory.hpp:72
QString HppHeaderGuard
Definition: WareSrcFactory.hpp:75
Definition: BuilderExtensionSignature.hpp:58
int BuilderExtCategoryIndex
Definition: WareSrcFactory.hpp:91
QString getBuilderExtCategory() const
Definition: WareSrcFactory.hpp:138
QString LinkUID
Definition: WareSrcFactory.hpp:76
QString ParamsUiClassname
Definition: WareSrcFactory.hpp:78
static QStringList getBuilderExtTypeTexts()
Definition: WareSrcFactory.hpp:109
QString getParamsUiEnabled() const
Definition: WareSrcFactory.hpp:148
Definition: BuilderExtensionSignature.hpp:58
bool Sim2docInstall
Definition: WareSrcFactory.hpp:85
QString SimulatorSignatureData
Definition: WareSrcFactory.hpp:86
Definition: WareSrcFactory.hpp:58
QString RootHppFilename
Definition: WareSrcFactory.hpp:74
QString RootCppFilename
Definition: WareSrcFactory.hpp:73
QString ParamsUiRootHppFilename
Definition: WareSrcFactory.hpp:80
static QStringList getBuilderExtCategoryTexts()
Definition: WareSrcFactory.hpp:116
openfluid::builderext::ExtensionMode getBuilderExtType() const
Definition: WareSrcFactory.hpp:133
int BuilderExtModeIndex
Definition: WareSrcFactory.hpp:90
Definition: ApplicationException.hpp:47
static QStringList getSim2docModeTexts()
Definition: WareSrcFactory.hpp:124
WareType
Definition: TypeDefs.hpp:62
Header of ...
bool ParamsUiEnabled
Definition: WareSrcFactory.hpp:77
Definition: SimulatorSignature.hpp:307
#define OPENFLUID_API
Definition: dllexport.hpp:87
Definition: WareSrcFactory.hpp:62
QString ParamsUiRootCppFilename
Definition: WareSrcFactory.hpp:79
Definition: BuilderExtensionSignature.hpp:58
QString SimulatorInitCode
Definition: WareSrcFactory.hpp:87
Definition: BuilderExtensionSignature.hpp:58
QString SimulatorRunCode
Definition: WareSrcFactory.hpp:88
QString ParamsUiComment
Definition: WareSrcFactory.hpp:82