RasterSlicingAction.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/rp/RasterSlicingAction.cpp
22 
23  \brief This file defines the RasterSlicing class
24 */
25 
26 // Terralib
27 #include "../../../qt/widgets/rp/RasterSlicingWizard.h"
28 #include "../../../raster/Raster.h"
29 #include "../../af/ApplicationController.h"
30 #include "../../af/BaseApplication.h"
31 #include "../../af/events/LayerEvents.h"
32 #include "../../widgets/canvas/MapDisplay.h"
33 #include "RasterSlicingAction.h"
34 
35 // Qt
36 #include <QObject>
37 #include <QMessageBox>
38 
39 // STL
40 #include <memory>
41 
42 te::qt::plugins::rp::RasterSlicingAction::RasterSlicingAction(QMenu* menu, QMenu* popupMenu):te::qt::plugins::rp::AbstractAction(menu, popupMenu)
43 {
44  createAction(tr("Raster Slicing...").toUtf8().data(), "rasterslicing");
45  m_action->setObjectName("Processing.Raster Processing.RasterSlicing");
46 }
47 
49 
51  bool /*checked*/)
52 {
54 
56 
57  //get display extent
59 
60  /*
61  The extent and srid information is optional
62  If this is not available, the user won't be able to trim the raster
63  However, the user can stil proceed with the slicing function normally
64  */
65 
66  if(ba)
67  {
68  const te::gm::Envelope extent = ba->getMapDisplay()->getExtent();
69  int srid = ba->getMapDisplay()->getSRID();
70 
71  m_rasterSlicingWizard->setExtent(extent);
72  m_rasterSlicingWizard->setSRID(srid);
73  }
74 
75  m_rasterSlicingWizard->setMapDisplay(ba->getMapDisplay());
76 
77  connect(m_rasterSlicingWizard.get(), SIGNAL(addLayer(te::map::AbstractLayerPtr)), this, SLOT(addLayerSlot(te::map::AbstractLayerPtr)));
78  connect(m_rasterSlicingWizard.get(), SIGNAL(finished(int)), SLOT(onRasterSlicingFinished()));
79 
80  QActionGroup* mapEditionTools = te::qt::af::AppCtrlSingleton::getInstance().findActionGroup("Map.ToolsGroup");
81  assert(mapEditionTools);
82 
83  m_rasterSlicingWizard->setActionGroup(mapEditionTools);
84 
85  std::list<te::map::AbstractLayerPtr> layersList = getLayers();
86 
87  m_rasterSlicingWizard->setAttribute(Qt::WA_DeleteOnClose);
88 
89  m_rasterSlicingWizard->setList(layersList);
90 
91  m_rasterSlicingWizard->setModal(false);
92 
93  m_rasterSlicingWizard->show();
94 }
95 
97  bool /*checked*/)
98 {
100 
101  if(layer.get())
102  {
104 
105  if(dlg.exec() == QDialog::Accepted)
106  {
107  //add new layer
109  }
110  }
111  else
112  {
113  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(), tr("Warning"), tr("The layer selected is invalid or does not have an raster representation."));
114  }
115 }
116 
118 {
119  te::qt::af::AppCtrlSingleton::getInstance().removeListener(this);
120 
121  m_rasterSlicingWizard.release();
122 }
123 
125 {
126  addNewLayer(layer);
127 }
128 
130 {
131  switch(e->m_id)
132  {
134  {
135  m_rasterSlicingWizard->onMapDisplayExtentChanged();
136  }
137  break;
138 
139  default:
140  break;
141  }
142 }
This is an abstract class used to register actions into rp pluging.
virtual void onPopUpActionActivated(bool checked)
A base class for application events.
te::map::AbstractLayerPtr getOutputLayer()
This function returns the layer that has been created by the wizard with the sliced raster...
std::unique_ptr< te::qt::widgets::RasterSlicingWizard > m_rasterSlicingWizard
void addLayerSlot(te::map::AbstractLayerPtr layer)
RasterSlicingAction(QMenu *menu, QMenu *popupMenu)
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
void createAction(std::string name, std::string pixmap="")
Create and set the actions parameters.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
te::map::AbstractLayerPtr getCurrentLayer()
Get the selected layer from layer explorer in app.
URI C++ Library.
Definition: Attributes.h:37
QAction * m_action
Action used to call the process.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
te::qt::widgets::MapDisplay * getMapDisplay()
void onApplicationTriggered(te::qt::af::evt::Event *e)
void addNewLayer(te::map::AbstractLayerPtr layer)
Add a new layer into layer explorer widget.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::list< te::map::AbstractLayerPtr > getLayers()
Get the list of layers from app.
This file defines the RasterSlicing class.