Plugin.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/plugins/vp/Plugin.cpp
22 
23  \brief Plugin implementation for the VP Qt Plugin widget.
24 */
25 
26 // TerraLib
27 #include "../../../BuildConfig.h"
28 #include "../../../common/Config.h"
29 #include "../../../common/Translator.h"
30 #include "../../../common/Logger.h"
31 #include "../../af/ApplicationController.h"
32 #include "../../af/Utils.h"
33 #include "AggregationAction.h"
34 #include "GeometricOpAction.h"
35 #include "BufferAction.h"
36 #include "IntersectionAction.h"
37 #include "LineToPolygonAction.h"
39 #include "Plugin.h"
40 #include "PolygonToLineAction.h"
41 //#include "SummarizationAction.h"
42 //#include "TransformationAction.h"
43 
44 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
45 //Log4cxx
46 #include <log4cxx/basicconfigurator.h>
47 #include <log4cxx/consoleappender.h>
48 #include <log4cxx/fileappender.h>
49 #include <log4cxx/helpers/pool.h>
50 #include <log4cxx/helpers/transcoder.h>
51 #include <log4cxx/logger.h>
52 #include <log4cxx/logmanager.h>
53 #include <log4cxx/logstring.h>
54 #include <log4cxx/patternlayout.h>
55 #include <log4cxx/rollingfileappender.h>
56 #endif
57 
58 // QT
59 #include <QMenu>
60 #include <QMenuBar>
61 #include <QString>
62 
63 // STL
64 #include <string>
65 
67  : te::plugin::Plugin(pluginInfo),
68  m_vpMenu(0),
69  m_aggregation(0),
70  m_buffer(0),
71  m_geometricOp(0),
72  m_intersection(0),
73  m_lineToPolygon(0),
74  m_multipart2singlepart(0),
75  m_polygonToLine(0)
76 {
77 }
78 
80 {
81 }
82 
84 {
85  if(m_initialized)
86  return;
87 
88 // it initializes the Translator support for the TerraLib VP Qt Plugin
89  //TE_ADD_TEXT_DOMAIN(TE_QT_PLUGIN_VP_TEXT_DOMAIN, TE_QT_PLUGIN_VP_TEXT_DOMAIN_DIR, "UTF-8");
90 
91  TE_LOG_TRACE(TE_TR("TerraLib Qt VP Plugin startup!"));
92 
93 // add plugin menu
94  QMenu* pluginMenu = te::qt::af::ApplicationController::getInstance().getMenu("Processing");
95  m_vpMenu = new QMenu(pluginMenu);
96  m_vpMenu->setIcon(QIcon::fromTheme("vp-vectorprocessing-icon"));
97 
98  // Insert action before plugin manager action
99  QAction* pluginsSeparator = te::qt::af::ApplicationController::getInstance().findAction("ManagePluginsSeparator");
100 
101  pluginMenu->insertMenu(pluginsSeparator, m_vpMenu);
102 
103  m_vpMenu->setTitle(TE_TR("Vector Processing"));
104 
105 // register actions
106  registerActions();
107 
108 // vp log startup
109  std::string path = te::qt::af::ApplicationController::getInstance().getUserDataDir().toStdString();
110  path += "/log/terralib_vp.log";
111 
112 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
113  std::string layout = "%d{ISO8601} [%t] %-5p %c - %m%n";
114  log4cxx::LogString lString(layout.begin(), layout.end());
115 
116  log4cxx::FileAppender* fileAppender = new log4cxx::RollingFileAppender(log4cxx::LayoutPtr(new log4cxx::PatternLayout(lString)),
117  log4cxx::helpers::Transcoder::decode(path.c_str()), true);
118 
119  log4cxx::helpers::Pool p;
120  fileAppender->activateOptions(p);
121 
122  log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
123  log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
124 
125  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("vp");
126  logger->setAdditivity(false);
127  logger->addAppender(fileAppender);
128 
129 #endif
130  m_initialized = true;
131 }
132 
134 {
135  if(!m_initialized)
136  return;
137 
138 // remove menu
139  delete m_vpMenu;
140 
141 // unregister actions
142  unRegisterActions();
143 
144 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
145  log4cxx::LogManager::shutdown();
146 #endif
147 
148  TE_LOG_TRACE(TE_TR("TerraLib Qt VP Plugin shutdown!"));
149 
150  m_initialized = false;
151 }
152 
154 {
155  m_aggregation = new te::qt::plugins::vp::AggregationAction(m_vpMenu);
156  m_buffer = new te::qt::plugins::vp::BufferAction(m_vpMenu);
157  m_geometricOp = new te::qt::plugins::vp::GeometricOpAction(m_vpMenu);
158  m_intersection = new te::qt::plugins::vp::IntersectionAction(m_vpMenu);
159  m_multipart2singlepart = new te::qt::plugins::vp::MultipartToSinglepartAction(m_vpMenu);
160  m_lineToPolygon = new te::qt::plugins::vp::LineToPolygonAction(m_vpMenu);
161  m_polygonToLine = new te::qt::plugins::vp::PolygonToLineAction(m_vpMenu);
162  //m_summarization = new te::qt::plugins::vp::SummarizationAction(m_vpMenu);
163  //m_transformation = new te::qt::plugins::vp::TransformationAction(m_vpMenu);
164 
165  te::qt::af::AddActionToCustomToolbars(m_aggregation->getAction());
166  te::qt::af::AddActionToCustomToolbars(m_buffer->getAction());
167  te::qt::af::AddActionToCustomToolbars(m_geometricOp->getAction());
168  te::qt::af::AddActionToCustomToolbars(m_intersection->getAction());
169  te::qt::af::AddActionToCustomToolbars(m_multipart2singlepart->getAction());
170  te::qt::af::AddActionToCustomToolbars(m_lineToPolygon->getAction());
171  te::qt::af::AddActionToCustomToolbars(m_polygonToLine->getAction());
172 }
173 
175 {
176  delete m_aggregation;
177  delete m_buffer;
178  delete m_geometricOp;
179  delete m_intersection;
180  delete m_multipart2singlepart;
181  delete m_lineToPolygon;
182  delete m_polygonToLine;
183  //delete m_summarization;
184  //delete m_transformation;
185 }
186 
188 
#define TE_LOG_TRACE(msg)
Use this tag in order to log a message to a specified logger with the TRACE level.
Definition: Logger.h:137
This class register the contrast action into VP Plugin.
This class register the contrast action into VP Plugin.
This file defines the Aggregation class.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:346
This file defines the PolygonToLine class.
This file defines the Aggregation class.
Plugin implementation for the VP Qt Plugin widget.
This file defines the LineToPolygon class.
#define PLUGIN_CALL_BACK_IMPL(PLUGIN_CLASS_NAME)
This macro should be used by C++ plugins in order to declare the exportable/callable DLL function...
Definition: Config.h:54
Plugin(const te::plugin::PluginInfo &pluginInfo)
Definition: Plugin.cpp:66
TEQTAFEXPORT void AddActionToCustomToolbars(QAction *act)
Check QSettings for existance of act and adds it if necessary.
Definition: Utils.cpp:767
void shutdown()
Do nothing! Just set plugin as stopped.
Definition: Plugin.cpp:133
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
This class register the contrast action into VP Plugin.
This file defines the Buffer class.
URI C++ Library.
This class register the contrast action into VP Plugin.
bool decode(std::string &s)
Decode the pct-encoded (hex) sequences, if any, return success.
Definition: urisyn.cpp:171
void registerActions()
Function used to register all raster processing actions.
Definition: Plugin.cpp:153
This class register the contrast action into VP Plugin.
Definition: BufferAction.h:47
This class register the contrast action into VP Plugin.
~Plugin()
Virtual destructor.
Definition: Plugin.cpp:79
This file defines the Intersection class.
The basic information about a plugin.
Definition: PluginInfo.h:61
void unRegisterActions()
Function used to unregister all raster processing actions.
Definition: Plugin.cpp:174
void startup()
Do nothing! Just set plugin as started.
Definition: Plugin.cpp:83