All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MapGridModel.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2014 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 MapGridModel.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "MapGridModel.h"
30 #include "ContextItem.h"
31 #include "Context.h"
32 #include "../../../maptools/Canvas.h"
33 #include "Property.h"
34 #include "Properties.h"
35 #include "AbstractType.h"
36 #include "GridPlanarModel.h"
37 #include "GridGeodesicModel.h"
38 
39 // STL
40 #include <vector>
41 #include <string>
44 
46  MapModel(),
47  m_gridPlanar(0),
48  m_gridGeodesic(0),
49  m_planarGridProperties(0),
50  m_geodesicGridProperties(0)
51 {
54 
57 
59 }
60 
62 {
63  if(m_gridPlanar)
64  {
65  delete m_gridPlanar;
66  m_gridPlanar = 0;
67  }
68 
69  if(m_gridGeodesic)
70  {
71  delete m_gridGeodesic;
72  m_gridGeodesic = 0;
73  }
74 
75  if(m_planarGridProperties)
76  {
77  delete m_planarGridProperties;
78  m_planarGridProperties = 0;
79  }
80 
81  if(m_geodesicGridProperties)
82  {
83  delete m_geodesicGridProperties;
84  m_geodesicGridProperties = 0;
85  }
86 }
87 
89 {
90  te::color::RGBAColor** pixmap = 0;
91 
93  Utils* utils = Context::getInstance()->getUtils();
94 
95  utils->configCanvas(m_box);
96 
97  drawGrid(canvas, utils);
98 
99  utils->configCanvas(m_box, false);
100 
101  te::color::RGBAColor colorp6(0,0,0, TE_OPAQUE);
102  canvas->setLineColor(colorp6);
103 
104  canvas->setPolygonContourColor(m_borderColor);
105  canvas->setPolygonFillColor(m_backgroundColor);
106 
107  if(m_border)
108  utils->drawRectW(m_box);
109 
110  if(context.isResizeCanvas())
111  pixmap = utils->getImageW(m_box);
112 
113  ContextItem contextNotify;
114  contextNotify.setPixmap(pixmap);
115  notifyAll(contextNotify);
116 }
117 
119 {
120  if(!m_layer)
121  return;
122 
123  int srid = m_layer->getSRID();
124  double scale = getScale();
125 
126  // Planar Grid
127  te::gm::Envelope planarBox = getWorldInMeters();
128  utils->configGeoCanvas(planarBox, m_box, false);
129 
130  m_gridPlanar->setMapScale(scale);
131  m_gridPlanar->draw(canvas, planarBox, srid);
132 
133  // Geodesic Grid
134  te::gm::Envelope geoBox = getWorldInDegrees();
135  utils->configGeoCanvas(geoBox, m_box, false);
136 
137  m_gridGeodesic->setMapScale(scale);
138  m_gridGeodesic->draw(canvas, geoBox, srid);
139 }
140 
142 {
144 
145  Property pro_grid;
146  pro_grid.setName("grid");
147  pro_grid.setId("unknown");
148  std::string sValuePlanar = "Settings";
149  pro_grid.setValue(sValuePlanar, DataTypeGridSettings);
150 
151  if(m_gridPlanar)
152  {
153  Property propPlanar = m_gridPlanar->getProperty();
154  pro_grid.addSubProperty(propPlanar);
155  }
156 
157  if(m_gridGeodesic)
158  {
159  Property propGeodesic = m_gridGeodesic->getProperty();
160  pro_grid.addSubProperty(propGeodesic);
161  }
162 
163  m_properties->addProperty(pro_grid);
164 
165  return m_properties;
166 }
167 
169 {
170  MapModel::updateProperties(properties);
171 
172  Properties* vectorProps = const_cast<Properties*>(properties);
173 
174  Property pro_grid = vectorProps->contains("grid");
175 
176  Property pro_grid_planar = pro_grid.containsSubProperty(m_planarGridProperties->getName());
177 
178  if(!pro_grid_planar.isNull())
179  {
180  m_gridPlanar->updateProperty(pro_grid_planar);
181  }
182 
183  Property pro_grid_geodesic = pro_grid.containsSubProperty(m_geodesicGridProperties->getName());
184 
185  if(!pro_grid_geodesic.isNull())
186  {
187  m_gridGeodesic->updateProperty(pro_grid_geodesic);
188  }
189 }
void setPixmap(te::color::RGBAColor **pixmap)
Definition: ContextItem.cpp:77
void addSubProperty(Property property)
Definition: Property.cpp:126
virtual void setPolygonFillColor(const te::color::RGBAColor &color)=0
It sets the color used to fill the draw of polygon geometries.
virtual void drawRectW(te::gm::Envelope box)
Definition: Utils.cpp:49
virtual void configCanvas(te::gm::Envelope box, bool resize=true)
Definition: Utils.cpp:124
GridPlanarModel * m_gridPlanar
Definition: MapGridModel.h:60
void setValue(typename ValueType value, LayoutPropertyDataType type)
Definition: Property.h:106
virtual void draw(ContextItem context)
virtual void updateProperties(te::layout::Properties *properties)
Definition: MapModel.cpp:61
virtual void updateProperties(te::layout::Properties *properties)
PlanarGridSettingsConfigProperties * m_planarGridProperties
Definition: MapGridModel.h:63
virtual void drawGrid(te::map::Canvas *canvas, Utils *utils)
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual void setHasGridWindows(bool windows)
Definition: Properties.h:176
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
Definition: Config.h:39
Utils * getUtils()
Definition: Context.cpp:126
virtual te::layout::Properties * getProperties() const
virtual bool containsSubProperty(Property subProperty)
Definition: Property.cpp:167
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
virtual Properties * getProperties() const
virtual te::color::RGBAColor ** getImageW(te::gm::Envelope boxmm)
Definition: Utils.cpp:97
virtual void setPolygonContourColor(const te::color::RGBAColor &color)=0
It sets the pen color used to draw the boundary of polygon geometries.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void setName(std::string name)
Definition: Property.cpp:54
virtual void setLineColor(const te::color::RGBAColor &color)=0
It sets the pen color used to draw line geometries.
static Context * getInstance()
This function is called to create an instance of the class.
Definition: Context.cpp:46
void setId(std::string id)
Definition: Property.cpp:69
virtual bool contains(Property property)
Definition: Properties.h:147
GridGeodesicModel * m_gridGeodesic
Definition: MapGridModel.h:61
te::map::Canvas * getCanvas()
Definition: Context.cpp:116
virtual void configGeoCanvas(te::gm::Envelope boxgeo, te::gm::Envelope boxmm, bool resize=true)
Definition: Utils.cpp:130
GeodesicGridSettingsConfigProperties * m_geodesicGridProperties
Definition: MapGridModel.h:62