All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Renderer.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/edit/qt/Renderer.cpp
22 
23  \brief This is a singleton for rendering geometries and features.
24 */
25 
26 // TerraLib
27 #include "../../geometry/Envelope.h"
28 #include "../../geometry/Geometry.h"
29 #include "../../geometry/LineString.h"
30 #include "../../qt/widgets/canvas/Canvas.h"
31 #include "../../qt/widgets/Utils.h"
32 #include "../../srs/Config.h"
33 #include "../Feature.h"
34 #include "../Repository.h"
35 #include "../RepositoryManager.h"
36 #include "../Utils.h"
37 #include "Renderer.h"
38 
39 // STL
40 #include <map>
41 
43  : m_canvas(0),
44  m_srid(TE_UNKNOWN_SRS),
45  m_currentGeomType(te::gm::UnknownGeometryType)
46 {
48 }
49 
51 {
52  delete m_canvas;
53 }
54 
55 void te::edit::Renderer::begin(QPaintDevice* device, const te::gm::Envelope& e, int srid)
56 {
57  delete m_canvas;
58  m_canvas = new te::qt::widgets::Canvas(device->width(), device->height());
59  m_canvas->setDevice(device, false);
60  m_canvas->setWindow(e.m_llx, e.m_lly, e.m_urx, e.m_ury);
61  m_srid = srid;
62 }
63 
65 {
66  const std::map<std::string, Repository*>& repositories = RepositoryManager::getInstance().getRepositories();
67 
68  std::map<std::string, Repository*>::const_iterator it;
69  for(it = repositories.begin(); it != repositories.end(); ++it)
70  drawRepository(it->first, e, srid);
71 }
72 
73 void te::edit::Renderer::drawRepository(const std::string& source, const te::gm::Envelope& e, int srid)
74 {
76 
77  if(repository == 0)
78  return;
79 
80  std::vector<Feature*> features = repository->getFeatures(e, srid);
81 
82  for(std::size_t i = 0; i < features.size(); ++i)
83  draw(features[i]->getGeometry());
84 }
85 
87 {
88  assert(m_canvas);
89 
90  if(m_currentGeomType == type && m_styleChanged == false)
91  return; // No need reconfigure the canvas
92 
93  m_currentGeomType = type;
94 
95  switch(type)
96  {
105  {
106  te::qt::widgets::Config2DrawPolygons(m_canvas, m_polygonFillColor, m_polygonContourColor, m_polygonContourWidth);
107  }
108  break;
109 
118  {
119  te::qt::widgets::Config2DrawLines(m_canvas, m_lineColor, m_lineWidth);
120  }
121  break;
122 
123  case te::gm::PointType:
124  case te::gm::PointZType:
125  case te::gm::PointMType:
126  case te::gm::PointZMType:
131  {
132  te::qt::widgets::Config2DrawPoints(m_canvas, m_pointMark, m_pointSize, m_pointFillColor, m_pointContourColor, m_pointContourWidth);
133  }
134  break;
135 
136  default:
137  return;
138  }
139 }
140 
141 void te::edit::Renderer::draw(te::gm::Geometry* geom, bool showVertexes)
142 {
143  assert(m_canvas);
144  assert(geom);
145 
146  if((geom->getSRID() != TE_UNKNOWN_SRS) && (m_srid != TE_UNKNOWN_SRS) && (geom->getSRID() != m_srid))
147  geom->transform(m_srid);
148 
149  prepare(geom->getGeomTypeId());
150 
151  m_canvas->draw(geom);
152 
153  if(showVertexes)
154  drawVertexes(geom);
155 }
156 
158 {
159  assert(geom);
160 
161  std::vector<te::gm::LineString*> lines;
162  GetLines(geom, lines);
163 
164  prepare(te::gm::PointType);
165 
166  drawVertexes(lines);
167 }
168 
169 void te::edit::Renderer::drawVertexes(const std::vector<te::gm::LineString*>& lines)
170 {
171  for(std::size_t i = 0; i < lines.size(); ++i)
172  drawVertexes(lines[i]);
173 }
174 
176 {
177  assert(m_canvas);
178  assert(line);
179 
180  if((line->getSRID() != TE_UNKNOWN_SRS) && (m_srid != TE_UNKNOWN_SRS) && (line->getSRID() != m_srid))
181  line->transform(m_srid);
182 
183  for(std::size_t j = 0; j < line->getNPoints(); ++j)
184  {
185  std::auto_ptr<te::gm::Point> point(line->getPointN(j));
186  m_canvas->draw(point.get());
187  }
188 }
189 
191 {
192  delete m_canvas;
193  m_canvas = 0;
194 
195  m_srid = TE_UNKNOWN_SRS;
196 
197  m_currentGeomType = te::gm::UnknownGeometryType;
198 
199  setupDefaultStyle();
200 }
201 
202 void te::edit::Renderer::setPolygonStyle(const QColor& fillColor, const QColor& contourColor, const std::size_t& contourWidth)
203 {
204  m_polygonFillColor = fillColor;
205  m_polygonContourColor = contourColor;
206  m_polygonContourWidth = contourWidth;
207 
208  m_styleChanged = true;
209 }
210 
211 void te::edit::Renderer::setPointStyle(const QString& mark, const QColor& fillColor, const QColor& contourColor,
212  const std::size_t& contourWidth, const std::size_t& size)
213 {
214  m_pointMark = mark;
215  m_pointFillColor = fillColor;
216  m_pointContourColor = contourColor;
217  m_pointContourWidth = contourWidth;
218  m_pointSize = size;
219 
220  m_styleChanged = true;
221 }
222 
224 {
225  m_polygonFillColor = QColor(0, 255, 0, 80);
226  m_polygonContourColor = Qt::black;
227  m_polygonContourWidth = 2;
228 
229  m_lineColor = QColor(0, 0, 0, 80);
230  m_lineWidth = 5;
231 
232  m_pointMark = "circle";
233  m_pointFillColor = Qt::red;
234  m_pointContourColor = Qt::black;
235  m_pointContourWidth = 1;
236  m_pointSize = 8;
237 
238  m_styleChanged = false;
239 }
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
Definition: Geometry.h:189
~Renderer()
Singleton destructor.
Definition: Renderer.cpp:50
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
void setDevice(QPaintDevice *device, bool takeOwnerShip)
It sets new device as QPrinter.
Definition: Canvas.cpp:2104
void setPointStyle(const QString &mark, const QColor &fillColor, const QColor &contourColor, const std::size_t &contourWidth, const std::size_t &size)
Definition: Renderer.cpp:211
Point * getPointN(std::size_t i) const
It returns the specified point in this LineString.
Definition: LineString.cpp:323
void setupDefaultStyle()
Definition: Renderer.cpp:223
TEQTWIDGETSEXPORT void Config2DrawLines(te::map::Canvas *canvas, const QColor &color, const std::size_t &width=1)
It configs (i.e. prepares) the given canvas to draw lines.
Definition: Utils.cpp:246
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
void drawRepositories(const te::gm::Envelope &e, int srid)
Definition: Renderer.cpp:64
virtual void transform(int srid)=0
It converts the coordinate values of the geometry to the new spatial reference system.
const std::map< std::string, Repository * > & getRepositories() const
TEQTWIDGETSEXPORT void Config2DrawPolygons(te::map::Canvas *canvas, const QColor &fillColor, const QColor &contourColor, const std::size_t &contourWidth=1)
It configs (i.e. prepares) the given canvas to draw polygons.
Definition: Utils.cpp:239
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
static RepositoryManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:44
void draw(te::gm::Geometry *geom, bool showVertexes=false)
Definition: Renderer.cpp:141
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
Definition: LineString.h:193
TEQTWIDGETSEXPORT void Config2DrawPoints(te::map::Canvas *canvas, const QColor &color, const std::size_t &width=1)
It configs (i.e. prepares) the given canvas to draw points.
Definition: Utils.cpp:252
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:178
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
void prepare(te::gm::GeomType type)
Definition: Renderer.cpp:86
A canvas built on top of Qt.
Definition: Canvas.h:54
Renderer()
It initializes the singleton instance of the renderer.
Definition: Renderer.cpp:42
std::vector< Feature * > getFeatures(const te::gm::Envelope &e, int srid) const
Definition: Repository.cpp:183
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
void drawVertexes(te::gm::Geometry *geom)
Definition: Renderer.cpp:157
void begin(QPaintDevice *device, const te::gm::Envelope &e, int srid)
Definition: Renderer.cpp:55
TEEDITEXPORT void GetLines(te::gm::Geometry *geom, std::vector< te::gm::LineString * > &lines)
Definition: Utils.cpp:109
void drawRepository(const std::string &source, const te::gm::Envelope &e, int srid)
Definition: Renderer.cpp:73
Repository * getRepository(const std::string &source) const
This class represents a repository of geometries and features.
Definition: Repository.h:62
This is a singleton for rendering geometries and features.
void setPolygonStyle(const QColor &fillColor, const QColor &contourColor, const std::size_t &contourWidth)
Definition: Renderer.cpp:202
void transform(int srid)
It converts the coordinate values of the linestring to the new spatial reference system.
Definition: LineString.cpp:181