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/attributefill/Plugin.cpp
22 
23  \brief Plugin implementation for the Attribute Fill 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/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), m_attributefillMenu(0)
61 {
62 }
63 
65 {
66 }
67 
69 {
70  if(m_initialized)
71  return;
72 
73  TE_LOG_TRACE(TE_TR("TerraLib Qt Attribute Fill Plugin startup!"));
74 
75 // add plugin menu
76  QMenu* pluginMenu = te::qt::af::ApplicationController::getInstance().getMenu("Processing");
77  m_attributefillMenu = new QMenu(pluginMenu);
78  m_attributefillMenu->setIcon(QIcon::fromTheme("attributefill-icon"));
79 
80  // Insert action before plugin manager action
81  QAction* pluginsSeparator = te::qt::af::ApplicationController::getInstance().findAction("ManagePluginsSeparator");
82 
83  pluginMenu->insertMenu(pluginsSeparator, m_attributefillMenu);
84 
85  m_attributefillMenu->setTitle(TE_TR("Attribute Fill"));
86 
87  // register actions
88  registerActions();
89 
90 // add pop up menu
91  m_popupAction = new QAction(m_attributefillMenu);
92  m_popupAction->setText(TE_TR("Attribute Fill"));
93 
94  // attribute fill log startup
95  std::string path = te::qt::af::ApplicationController::getInstance().getUserDataDir().toStdString();
96  path += "/log/terralib_attributefill.log";
97 
98 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
99  std::string layout = "%d{ISO8601} [%t] %-5p %c - %m%n";
100  log4cxx::LogString lString(layout.begin(), layout.end());
101 
102  log4cxx::FileAppender* fileAppender = new log4cxx::RollingFileAppender(log4cxx::LayoutPtr(new log4cxx::PatternLayout(lString)),
103  log4cxx::helpers::Transcoder::decode(path.c_str()), true);
104 
105  log4cxx::helpers::Pool p;
106  fileAppender->activateOptions(p);
107 
108  log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(fileAppender));
109  log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
110 
111  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("attributefill");
112  logger->setAdditivity(false);
113  logger->addAppender(fileAppender);
114 #endif
115 
116  te::qt::af::AddActionToCustomToolbars(m_rasterToVector->getAction());
117  te::qt::af::AddActionToCustomToolbars(m_vectorToRaster->getAction());
118  te::qt::af::AddActionToCustomToolbars(m_vectorToVector->getAction());
119 
120  m_initialized = true;
121 }
122 
124 {
125  if(!m_initialized)
126  return;
127 
128 // remove menu
129  delete m_attributefillMenu;
130 
131  // unregister actions
132  unRegisterActions();
133 
134 #if defined(TERRALIB_APACHE_LOG4CXX_ENABLED) && defined(TERRALIB_LOGGER_ENABLED)
135  log4cxx::LogManager::shutdown();
136 #endif
137 
138  TE_LOG_TRACE(TE_TR("TerraLib Qt Attribute Fill Plugin shutdown!"));
139 
140  m_initialized = false;
141 }
142 
144 {
145  m_rasterToVector = new te::qt::plugins::attributefill::RasterToVectorAction(m_attributefillMenu);
146  m_vectorToRaster = new te::qt::plugins::attributefill::VectorToRasterAction(m_attributefillMenu);
147  m_vectorToVector = new te::qt::plugins::attributefill::VectorToVectorAction(m_attributefillMenu);
148 }
149 
151 {
152  delete m_rasterToVector;
153  delete m_vectorToRaster;
154 }
155 
#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:347
void registerActions()
Function used to register all attributefill actions.
Definition: Plugin.cpp:143
#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()
Virtual destructor.
Definition: Plugin.cpp:64
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:763
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
Plugin(const te::plugin::PluginInfo &pluginInfo)
Definition: Plugin.cpp:59
void unRegisterActions()
Function used to unregister all attributefill actions.
Definition: Plugin.cpp:150
This class register the contrast action into Attribute Fill Plugin.
void shutdown()
Do nothing! Just set plugin as stopped.
Definition: Plugin.cpp:123
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:68