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/attributefill/Plugin.cpp
22 
23  \brief Plugin implementation for the Attribute Fill 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/events/LayerEvents.h"
33 #include "../../af/Utils.h"
34 #include "RasterToVectorAction.h"
35 #include "VectorToRasterAction.h"
36 #include "VectorToVectorAction.h"
37 #include "Plugin.h"
38 
39 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
40 //Log4cxx
41 #include <log4cxx/basicconfigurator.h>
42 #include <log4cxx/consoleappender.h>
43 #include <log4cxx/fileappender.h>
44 #include <log4cxx/helpers/pool.h>
45 #include <log4cxx/helpers/transcoder.h>
46 #include <log4cxx/logger.h>
47 #include <log4cxx/logmanager.h>
48 #include <log4cxx/logstring.h>
49 #include <log4cxx/patternlayout.h>
50 #include <log4cxx/rollingfileappender.h>
51 #include <log4cxx/simplelayout.h>
52 #endif
53 
54 // QT
55 #include <QMenu>
56 #include <QMenuBar>
57 #include <qaction.h>
58 
60  : te::plugin::Plugin(pluginInfo),
61  m_attributefillMenu(0),
62  m_popupAction(0),
63  m_rasterToVector(0),
64  m_vectorToRaster(0),
65  m_vectorToVector(0)
66 {
67 }
68 
70 {
71 }
72 
74 {
75  if(m_initialized)
76  return;
77 
78  TE_LOG_TRACE(TE_TR("TerraLib Qt Attribute Fill Plugin startup!"));
79 
80 // add plugin menu
81  QMenu* pluginMenu = te::qt::af::ApplicationController::getInstance().getMenu("Processing");
82  m_attributefillMenu = new QMenu(pluginMenu);
83  m_attributefillMenu->setIcon(QIcon::fromTheme("attributefill-icon"));
84 
85  // Insert action before plugin manager action
86  QAction* pluginsSeparator = te::qt::af::ApplicationController::getInstance().findAction("ManagePluginsSeparator");
87 
88  pluginMenu->insertMenu(pluginsSeparator, m_attributefillMenu);
89 
90  m_attributefillMenu->setTitle(TE_TR("Attribute Fill"));
91 
92  // register actions
93  registerActions();
94 
95 // add pop up menu
96  m_popupAction = new QAction(m_attributefillMenu);
97  m_popupAction->setText(TE_TR("Attribute Fill"));
98 
99  // attribute fill log startup
100  std::string path = te::qt::af::ApplicationController::getInstance().getUserDataDir().toStdString();
101  path += "/log/terralib_attributefill.log";
102 
103 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
104  std::string layout = "%d{ISO8601} [%t] %-5p %c - %m%n";
105  log4cxx::LogString lString(layout.begin(), layout.end());
106 
107  log4cxx::FileAppender* fileAppender = new log4cxx::RollingFileAppender(log4cxx::LayoutPtr(new log4cxx::PatternLayout(lString)),
108  log4cxx::helpers::Transcoder::decode(path.c_str()), true);
109 
110  log4cxx::helpers::Pool p;
111  fileAppender->activateOptions(p);
112 
113  log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
114  log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
115 
116  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("attributefill");
117  logger->setAdditivity(false);
118  logger->addAppender(fileAppender);
119 #endif
120 
121  te::qt::af::AddActionToCustomToolbars(m_rasterToVector->getAction());
122  te::qt::af::AddActionToCustomToolbars(m_vectorToRaster->getAction());
123  te::qt::af::AddActionToCustomToolbars(m_vectorToVector->getAction());
124 
125  m_initialized = true;
126 }
127 
129 {
130  if(!m_initialized)
131  return;
132 
133 // remove menu
134  delete m_attributefillMenu;
135 
136  // unregister actions
137  unRegisterActions();
138 
139 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
140  log4cxx::LogManager::shutdown();
141 #endif
142 
143  TE_LOG_TRACE(TE_TR("TerraLib Qt Attribute Fill Plugin shutdown!"));
144 
145  m_initialized = false;
146 }
147 
149 {
150  m_rasterToVector = new te::qt::plugins::attributefill::RasterToVectorAction(m_attributefillMenu);
151  m_vectorToRaster = new te::qt::plugins::attributefill::VectorToRasterAction(m_attributefillMenu);
152  m_vectorToVector = new te::qt::plugins::attributefill::VectorToVectorAction(m_attributefillMenu);
153 }
154 
156 {
157  delete m_rasterToVector;
158  delete m_vectorToRaster;
159 }
160 
#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 Attribute Fill Plugin.
This file defines the RasterToVector class.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:346
void registerActions()
Function used to register all attributefill actions.
Definition: Plugin.cpp:148
#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()
Virtual destructor.
Definition: Plugin.cpp:69
This file defines the VectorToRaster class.
TEQTAFEXPORT void AddActionToCustomToolbars(QAction *act)
Check QSettings for existance of act and adds it if necessary.
Definition: Utils.cpp:767
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
Plugin(const te::plugin::PluginInfo &pluginInfo)
Definition: Plugin.cpp:59
URI C++ Library.
void unRegisterActions()
Function used to unregister all attributefill actions.
Definition: Plugin.cpp:155
This class register the contrast action into Attribute Fill Plugin.
void shutdown()
Do nothing! Just set plugin as stopped.
Definition: Plugin.cpp:128
This class register the contrast action into Attribute Fill Plugin.
bool decode(std::string &s)
Decode the pct-encoded (hex) sequences, if any, return success.
Definition: urisyn.cpp:171
Plugin implementation for the SA Qt Plugin widget.
This file defines the RasterToVector class.
The basic information about a plugin.
Definition: PluginInfo.h:61
void startup()
Do nothing! Just set plugin as started.
Definition: Plugin.cpp:73