All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "terralib_config.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), m_vpMenu(0)
68 {
69 }
70 
72 {
73 }
74 
76 {
77  if(m_initialized)
78  return;
79 
80 // it initializes the Translator support for the TerraLib VP Qt Plugin
81  //TE_ADD_TEXT_DOMAIN(TE_QT_PLUGIN_VP_TEXT_DOMAIN, TE_QT_PLUGIN_VP_TEXT_DOMAIN_DIR, "UTF-8");
82 
83  TE_LOG_TRACE(TE_TR("TerraLib Qt VP Plugin startup!"));
84 
85 // add plugin menu
86  QMenu* pluginMenu = te::qt::af::ApplicationController::getInstance().getMenu("Processing");
87  m_vpMenu = new QMenu(pluginMenu);
88  m_vpMenu->setIcon(QIcon::fromTheme("vp-vectorprocessing-icon"));
89 
90  // Insert action before plugin manager action
91  QAction* pluginsSeparator = te::qt::af::ApplicationController::getInstance().findAction("ManagePluginsSeparator");
92 
93  pluginMenu->insertMenu(pluginsSeparator, m_vpMenu);
94 
95  m_vpMenu->setTitle(TE_TR("Vector Processing"));
96 
97 // register actions
98  registerActions();
99 
100 // vp log startup
101  std::string path = te::qt::af::ApplicationController::getInstance().getUserDataDir().toStdString();
102  path += "/log/terralib_vp.log";
103 
104 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
105  std::string layout = "%d{ISO8601} [%t] %-5p %c - %m%n";
106  log4cxx::LogString lString(layout.begin(), layout.end());
107 
108  log4cxx::FileAppender* fileAppender = new log4cxx::RollingFileAppender(log4cxx::LayoutPtr(new log4cxx::PatternLayout(lString)),
109  log4cxx::helpers::Transcoder::decode(path.c_str()), true);
110 
111  log4cxx::helpers::Pool p;
112  fileAppender->activateOptions(p);
113 
114  log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
115  log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
116 
117  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("vp");
118  logger->setAdditivity(false);
119  logger->addAppender(fileAppender);
120 
121 #endif
122  m_initialized = true;
123 }
124 
126 {
127  if(!m_initialized)
128  return;
129 
130 // remove menu
131  delete m_vpMenu;
132 
133 // unregister actions
134  unRegisterActions();
135 
136 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
137  log4cxx::LogManager::shutdown();
138 #endif
139 
140  TE_LOG_TRACE(TE_TR("TerraLib Qt VP Plugin shutdown!"));
141 
142  m_initialized = false;
143 }
144 
146 {
147  m_aggregation = new te::qt::plugins::vp::AggregationAction(m_vpMenu);
148  m_buffer = new te::qt::plugins::vp::BufferAction(m_vpMenu);
149  m_geometricOp = new te::qt::plugins::vp::GeometricOpAction(m_vpMenu);
150  m_intersection = new te::qt::plugins::vp::IntersectionAction(m_vpMenu);
151  m_multipart2singlepart = new te::qt::plugins::vp::MultipartToSinglepartAction(m_vpMenu);
152  m_lineToPolygon = new te::qt::plugins::vp::LineToPolygonAction(m_vpMenu);
153  m_polygonToLine = new te::qt::plugins::vp::PolygonToLineAction(m_vpMenu);
154  //m_summarization = new te::qt::plugins::vp::SummarizationAction(m_vpMenu);
155  //m_transformation = new te::qt::plugins::vp::TransformationAction(m_vpMenu);
156 
157  te::qt::af::AddActionToCustomToolbars(m_aggregation->getAction());
158  te::qt::af::AddActionToCustomToolbars(m_buffer->getAction());
159  te::qt::af::AddActionToCustomToolbars(m_geometricOp->getAction());
160  te::qt::af::AddActionToCustomToolbars(m_intersection->getAction());
161  te::qt::af::AddActionToCustomToolbars(m_multipart2singlepart->getAction());
162  te::qt::af::AddActionToCustomToolbars(m_lineToPolygon->getAction());
163  te::qt::af::AddActionToCustomToolbars(m_polygonToLine->getAction());
164 }
165 
167 {
168  delete m_aggregation;
169  delete m_buffer;
170  delete m_geometricOp;
171  delete m_intersection;
172  delete m_multipart2singlepart;
173  delete m_lineToPolygon;
174  delete m_polygonToLine;
175  //delete m_summarization;
176  //delete m_transformation;
177 }
178 
180 
#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:347
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:57
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:763
void shutdown()
Do nothing! Just set plugin as stopped.
Definition: Plugin.cpp:125
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.
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:145
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:71
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:166
void startup()
Do nothing! Just set plugin as started.
Definition: Plugin.cpp:75