PluginBuilderWizard.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/plugin/builder/PluginBuilderWizard.cpp
22 
23  \brief A Qt dialog that allows users to create new plugins based on TerraLib framework.
24 */
25 
26 // TerraLib
27 #include "../../../../common/StringUtils.h"
28 #include "../../../../common/Version.h"
29 #include "../../../../core/plugin/PluginManager.h"
30 #include "../../utils/DoubleListWidget.h"
31 #include "../../utils/ParameterTableWidget.h"
32 #include "PluginBuilderWizard.h"
33 #include "PluginCMakeWriter.h"
34 #include "PluginSourceWriter.h"
35 #include "ui_DoubleListWidgetForm.h"
36 #include "ui_ParameterTableWidgetForm.h"
37 #include "ui_PluginBuilderWizardForm.h"
38 
39 // Qt
40 #include <QFileDialog>
41 #include <QMessageBox>
42 #include <QRegExp>
43 #include <QVBoxLayout>
44 
46  : QWizard(parent),
47  m_ui(new Ui::PluginBuilderWizardForm),
48  m_curDir("")
49 {
50  m_ui->setupUi(this);
51 
52  //terralib modules
53  std::vector<std::string> teModulesNeeded;
54  teModulesNeeded.push_back("te.core"); //MANDATORY
55  teModulesNeeded.push_back("te.common"); //MANDATORY
56  teModulesNeeded.push_back("te.plugin"); //MANDATORY
57 
58  std::vector<std::string> teModules;
59  teModules.push_back("te.annotationtext");
60  teModules.push_back("te.color");
61  teModules.push_back("te.dataaccess");
62  teModules.push_back("te.datatype");
63  teModules.push_back("te.filter_encoding");
64  teModules.push_back("te.da.gdal");
65  teModules.push_back("te.geometry");
66  teModules.push_back("te.gml");
67  teModules.push_back("te.maptools");
68  teModules.push_back("te.da.memory");
69  teModules.push_back("te.qt.af");
70  teModules.push_back("te.raster");
71  teModules.push_back("te.rasterprocessing");
72  teModules.push_back("te.srs");
73  teModules.push_back("te.symbology_encoding");
74  teModules.push_back("te.xlinks");
75  teModules.push_back("te.xml");
76 
77  //license types
78  QStringList licenses;
79  licenses.push_back("Berkeley Database License");
80  licenses.push_back("Boost Software License");
81  licenses.push_back("BSD Documentation License");
82  licenses.push_back("Eclipse Distribution License");
83  licenses.push_back("GPL / GNU General Public License");
84  licenses.push_back("Intel Open Source License");
85  licenses.push_back("LGPL / GNU Lesser General Public License");
86  licenses.push_back("License of Python");
87  licenses.push_back("MIT license");
88  licenses.push_back("Public Domain");
89  licenses.push_back("W3C Software Notice and License");
90 
91  //category tpyes
92  QStringList categList;
93  categList.push_back("Cellular Space");
94  categList.push_back("Data Access");
95  categList.push_back("Data Management");
96  categList.push_back("Examples");
97  categList.push_back("Language Bindings");
98  categList.push_back("Location Base Services");
99  categList.push_back("Plugin Managememt");
100  categList.push_back("Spatial Analysis");
101  categList.push_back("Spatial Operations");
102  categList.push_back("Web Services");
103 
104  //fill interface
105  m_ui->m_terralibVersionLineEdit->setText(te::common::Version::asString().c_str());
106  m_ui->m_pluginLicenseComboBox->addItems(licenses);
107 
108  setButtonText(QWizard::CustomButton1, tr("&Settings"));
109 
110  // plugin dependencies
111  m_pluginDependencies.reset(new DoubleListWidget(m_ui->m_pluginDependenciesPage));
112  m_pluginDependencies->getForm()->m_leftItemsLabel->setText(tr("Available Plugins"));
113  m_pluginDependencies->getForm()->m_rightItemsLabel->setText(tr("Required Plugins"));
114  m_ui->m_pluginDependenciesGridLayout->addWidget(m_pluginDependencies.get());
115 
116  std::vector<std::string> plugins = te::core::PluginManager::instance().getPlugins();
117  m_pluginDependencies->setInputValues(plugins);
118 
119 // module dependencies
120  m_moduleDependencies.reset(new DoubleListWidget(m_ui->m_moduleDependenciesPage));
121  m_moduleDependencies->getForm()->m_leftItemsLabel->setText(tr("Available modules"));
122  m_moduleDependencies->getForm()->m_rightItemsLabel->setText(tr("Required modules for your plugin"));
123  m_ui->m_moduleDependenciesGridLayout->addWidget(m_moduleDependencies.get());
124 
125  m_moduleDependencies->setInputValues(teModules);
126  m_moduleDependencies->setOutputValues(teModulesNeeded);
127 
128 // plugin resources
129  m_pluginResources.reset(new ParameterTableWidget(m_ui->m_resourcesPage));
130  m_pluginResources->getForm()->m_parameterTitle->setText(tr("Resources"));
131  m_ui->m_resourcesGridLayout->addWidget(m_pluginResources.get());
132 
133 // plugin parameters
134  m_pluginParameters.reset(new ParameterTableWidget(m_ui->m_parametersPage));
135  m_ui->m_parametersGridLayout->addWidget(m_pluginParameters.get());
136 
137 // connect
138  connect(m_ui->m_terraLibIncludeDirToolButton, SIGNAL(clicked()), this, SLOT(onTeIncludeDirButtonClicked()));
139  connect(m_ui->m_terraLibCmakeDirToolButton, SIGNAL(clicked()), this, SLOT(onTeCmakeDirButtonClicked()));
140  connect(m_ui->m_sourceCodeLocationToolButton, SIGNAL(clicked()), this, SLOT(onPluginSrcDirButtonClicked()));
141  connect(m_ui->m_buildLocationToolButton, SIGNAL(clicked()), this, SLOT(onPluginBuildDirButtonClicked()));
142 }
143 
145 
147 {
148  if(currentPage() == m_ui->m_basicPluginInfoPage)
149  {
150  return pluginInfoPageCheck();
151  }
152  else if(currentPage() == m_ui->m_licenseAndProviderPage)
153  {
154  return providerPageCheck();
155  }
156  else if(currentPage() == m_ui->m_pluginTargetLocationPage)
157  {
158  if(dirPageCheck())
159  {
160  buildPlugin();
161  }
162  else
163  {
164  return false;
165  }
166  }
167 
168  return true;
169 }
170 
172 {
173  m_curDir = QFileDialog::getExistingDirectory(this, tr("Select the Include directory of TerraLib"), m_curDir);
174 
175  if(m_curDir.isEmpty() == false)
176  {
177  m_ui->m_terralibIncludeDirLineEdit->setText(m_curDir);
178  }
179 }
180 
182 {
183  m_curDir = QFileDialog::getExistingDirectory(this, tr("Select the Cmake Configure Files directory of TerraLib"), m_curDir);
184 
185  if(m_curDir.isEmpty() == false)
186  {
187  m_ui->m_terralibCmakeDirLineEdit->setText(m_curDir);
188  }
189 }
190 
192 {
193  m_curDir = QFileDialog::getExistingDirectory(this, tr("Select the location to create the source code files"), m_curDir);
194 
195  if(m_curDir.isEmpty() == false)
196  {
197  m_ui->m_sourceCodeLocationLineEdit->setText(m_curDir);
198  }
199 }
200 
202 {
203  m_curDir = QFileDialog::getExistingDirectory(this, tr("Select the location to create the build files"), m_curDir);
204 
205  if(m_curDir.isEmpty() == false)
206  {
207  m_ui->m_buildLocationLineEdit->setText(m_curDir);
208  }
209 }
210 
212 {
213  if(m_ui->m_pluginNameLineEdit->text().isEmpty())
214  {
215  QMessageBox::warning(this, tr("Plugin Builder"), tr("Plugin Name not defined."));
216  return false;
217  }
218  else
219  {
220  std::string name = m_ui->m_pluginNameLineEdit->text().toUtf8().data();
221  m_pluginResources->add("SharedLibraryName", name);
222 
223  //perhaps this information should be generated elsewhere
224  int pos = static_cast<int>(name.rfind("_"));
225  std::string nameSpace = name.substr(pos + 1, name.size() - 1);
226  std::string macroExport = "TEPLUGIN" + te::common::Convert2UCase(nameSpace) + "DLL";
227 
228  m_ui->m_cPlusPlusNameSpaceLineEdit->setText(nameSpace.c_str());
229  m_ui->m_cPlusPlusMacroExportLineEdit->setText(macroExport.c_str());
230  }
231 
232  if(m_ui->m_pluginVersionLineEdit->text().isEmpty())
233  {
234  QMessageBox::warning(this, tr("Plugin Builder"), tr("Plugin Version not defined."));
235  return false;
236  }
237 
238  if(m_ui->m_pluginDisplayTextLineEdit->text().isEmpty())
239  {
240  QMessageBox::warning(this, tr("Plugin Builder"), tr("Plugin Display Text not defined."));
241  return false;
242  }
243 
244  if(m_ui->m_pluginSiteLineEdit->text().isEmpty())
245  {
246  QMessageBox::warning(this, tr("Plugin Builder"), tr("Plugin Site not defined."));
247  return false;
248  }
249 
250  if(m_ui->m_pluginDescriptionTextEdit->document()->toPlainText().isEmpty())
251  {
252  QMessageBox::warning(this, tr("Plugin Builder"), tr("Plugin Description not defined."));
253  return false;
254  }
255 
256  return true;
257 }
258 
260 {
261  if(m_ui->m_pluginLicenseSiteLineEdit->text().isEmpty())
262  {
263  QMessageBox::warning(this, tr("Plugin Builder"), tr("License Site not defined."));
264  return false;
265  }
266 
267  if(m_ui->m_pluginProviderNameLineEdit->text().isEmpty())
268  {
269  QMessageBox::warning(this, tr("Plugin Builder"), tr("Provider Name not defined."));
270  return false;
271  }
272 
273  if(m_ui->m_pluginProviderSiteLineEdit->text().isEmpty())
274  {
275  QMessageBox::warning(this, tr("Plugin Builder"), tr("Provider Site not defined."));
276  return false;
277  }
278 
279  if(m_ui->m_pluginProviderEmailLineEdit->text().isEmpty())
280  {
281  QMessageBox::warning(this, tr("Plugin Builder"), tr("Provider Email not defined."));
282  return false;
283  }
284 
285  return true;
286 }
287 
289 {
290  if(m_ui->m_terralibIncludeDirLineEdit->text().isEmpty())
291  {
292  QMessageBox::warning(this, tr("Plugin Builder"), tr("TerraLib Include dir not defined."));
293  return false;
294  }
295 
296  if(m_ui->m_terralibCmakeDirLineEdit->text().isEmpty())
297  {
298  QMessageBox::warning(this, tr("Plugin Builder"), tr("TerraLib Cmake dir not defined."));
299  return false;
300  }
301 
302  if(m_ui->m_sourceCodeLocationLineEdit->text().isEmpty())
303  {
304  QMessageBox::warning(this, tr("Plugin Builder"), tr("Plugin Source dir not defined."));
305  return false;
306  }
307 
308  if(m_ui->m_buildLocationLineEdit->text().isEmpty())
309  {
310  QMessageBox::warning(this, tr("Plugin Builder"), tr("Plugin Build dir not defined."));
311  return false;
312  }
313 
314  return true;
315 }
316 
318 {
320  pi.name = m_ui->m_pluginNameLineEdit->text().toUtf8().data();
321  pi.display_name = m_ui->m_pluginDisplayTextLineEdit->text().toUtf8().data();
322  pi.description = m_ui->m_pluginDescriptionTextEdit->document()->toPlainText().toUtf8().data();
323  pi.version = m_ui->m_pluginVersionLineEdit->text().toUtf8().data();
324  pi.release = m_ui->m_pluginReleaseDateTime->text().toUtf8().data();
325  pi.engine = m_ui->m_cPlusPlusLanguageRadioButton->text().toUtf8().data(); // SET TO C++ CHANGE THIS IN THE FUTURE
326  pi.host_application.version = m_ui->m_terralibVersionLineEdit->text().toUtf8().data();
327  pi.license_description = m_ui->m_pluginLicenseComboBox->currentText().toUtf8().data();
328  pi.license_URL= m_ui->m_pluginLicenseSiteLineEdit->text().toUtf8().data();
329  pi.site = m_ui->m_pluginSiteLineEdit->text().toUtf8().data();
330  //pi.m_folder = m_ui->m_buildLocationLineEdit->text().toUtf8().data();
331 
332  pi.dependencies = m_pluginDependencies->getOutputValues();
333  pi.linked_libraries = m_moduleDependencies->getOutputValues();
334 
335  std::map<std::string, std::string> pluginResMap = m_pluginResources->getMap();
336  std::map<std::string, std::string>::iterator it = pluginResMap.begin();
337 
338  while(it != pluginResMap.end())
339  {
340  te::core::Resource r(it->first, it->second);
341  pi.resources.push_back(r);
342  ++it;
343  }
344 
345  std::map<std::string, std::string> pluginParamsMap = m_pluginParameters->getMap();
346  it = pluginParamsMap.begin();
347 
348  while(it != pluginParamsMap.end())
349  {
350  te::core::Parameter p(it->first, it->second);
351  pi.parameters.push_back(p);
352  ++it;
353  }
354 
355  pi.provider.name = m_ui->m_pluginProviderNameLineEdit->text().toUtf8().data();
356  pi.provider.site = m_ui->m_pluginProviderSiteLineEdit->text().toUtf8().data();
357  pi.provider.email = m_ui->m_pluginProviderEmailLineEdit->text().toUtf8().data();
358 
359  //acquire dir informations
360  std::string teIncludeDir = m_ui->m_terralibIncludeDirLineEdit->text().replace(QRegExp("\\\\"), "/").toUtf8().data();
361  std::string teCmakeDir = m_ui->m_terralibCmakeDirLineEdit->text().replace(QRegExp("\\\\"), "/").toUtf8().data();
362  std::string pluginSrcDir = m_ui->m_sourceCodeLocationLineEdit->text().replace(QRegExp("\\\\"), "/").toUtf8().data();
363  std::string pluginBuildDir = m_ui->m_buildLocationLineEdit->text().replace(QRegExp("\\\\"), "/").toUtf8().data();
364  // \\\\ is used to represente a back slash - Believe... QRegExp - Qt Documentation
365 
366  //targuet language information
367  std::string nameSpace;
368  std::string macroExport;
369 
370  if(m_ui->m_cPlusPlusLanguageRadioButton->isChecked())
371  {
372  nameSpace = m_ui->m_cPlusPlusNameSpaceLineEdit->text().toUtf8().data();
373  macroExport = m_ui->m_cPlusPlusMacroExportLineEdit->text().toUtf8().data();
374  }
375 
376  //create cmake files
378  cmakeWriter.createCmakeFile(pluginBuildDir, pluginSrcDir, pi.name, macroExport, teCmakeDir, pi);
379 
380  cmakeWriter.createPluginInfoFile(pluginBuildDir, pi);
381 
382  //create source files
384  sourceWriter.createHeaderFile(pluginSrcDir, nameSpace);
385 
386  sourceWriter.createCppFile(pluginSrcDir, nameSpace, pi.name);
387 
388  sourceWriter.createConfigFile(pluginSrcDir, nameSpace, macroExport, pi.name);
389 
390  QMessageBox::information(this, tr("Plugin Builder"), tr("Plugin built successfully!"));
391 }
392 
QString m_curDir
Attribute used to keep the last dir selected.
std::string license_description
A brief description about the plugin license.
A Qt dialog that allows users to create new plugins based on TerraLib framework.
std::unique_ptr< DoubleListWidget > m_moduleDependencies
std::string email
The provider contact e-mail.
Definition: LibraryInfo.h:50
void createCmakeFile(const std::string &buildPath, const std::string &sourcePath, const std::string &projName, const std::string exportMacro, const std::string &cmakePath, const te::core::PluginInfo &pi)
std::string engine
The type of plugin execution engine: C++, JAVA, LUA or any other supported engine.
std::pair< std::string, std::string > Resource
Definition: LibraryInfo.h:60
static std::string asString()
Definition: Version.cpp:60
HostApplication host_application
Information about the host system. May be used to validate the plugin version.
Basic information about a plugin.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:168
std::unique_ptr< ParameterTableWidget > m_pluginResources
std::vector< Resource > resources
The list of resources used by plugin.
std::string site
The provider home page.
Definition: LibraryInfo.h:49
This class is used to create the cmake file for the new plugin builded.
std::string description
A brief explanation about the plugin.
std::string display_name
The plugin name to be displayed in a graphical interface.
void createCppFile(const std::string &sourcePath, const std::string &nameSpace, const std::string projName)
std::pair< std::string, std::string > Parameter
Definition: LibraryInfo.h:62
std::string name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
std::vector< std::string > getPlugins() const
Return the list of plugins managed by PluginManager.
static PluginManager & instance()
Access the singleton.
std::string name
Provider name: may be a person or a company.
Definition: LibraryInfo.h:48
std::unique_ptr< Ui::PluginBuilderWizardForm > m_ui
std::vector< std::string > dependencies
The list of required plugins in order to launch the plugin.
te::gm::Polygon * p
std::vector< Parameter > parameters
Any configuration parameter that can be informed to plugin (map: parameter-name -> parameter-value)...
std::string license_URL
An URL where someone can find more information on the license.
std::unique_ptr< ParameterTableWidget > m_pluginParameters
std::string release
The release date of the plugin. This may be used to identify new versions of a given plugin...
std::string site
An URL pointing to the plugin site.
std::vector< std::string > linked_libraries
The list of linked libraries.
std::unique_ptr< DoubleListWidget > m_pluginDependencies
std::string version
The plugin version.
This class is used to create the cmake file for the new plugin builded.
void createPluginInfoFile(const std::string &buildPath, const te::core::PluginInfo &pi)
This class is used to create the source files for the new plugin builded.
void createConfigFile(const std::string &sourcePath, const std::string &nameSpace, const std::string exportMacro, const std::string projName)
Provider provider
Information about the plugin provider.
void createHeaderFile(const std::string &sourcePath, const std::string &nameSpace)