All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GridPlanarModel.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 GridPlanarModel.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "GridPlanarModel.h"
30 #include "ContextItem.h"
31 #include "Context.h"
32 #include "../../../../../geometry/Envelope.h"
33 #include "../../../../../geometry/Coord2D.h"
34 #include "Property.h"
35 #include "EnumUtils.h"
37 
39  m_unit(StyleKilometer)
40 {
42 
43  m_name = "GRID_PLANAR_MODEL";
46 }
47 
49 {
50  if(m_settingsConfig)
51  {
52  delete m_settingsConfig;
53  m_settingsConfig = 0;
54  }
55 }
56 
58 {
59  if(!box.isValid())
60  return;
61 
62  calculateGaps(box);
63 
64  if(!m_visible)
65  return;
66 
67  m_srid = srid;
68 
69  Utils* utils = Context::getInstance()->getUtils();
70 
71  te::color::RGBAColor color = te::color::RGBAColor(0, 0, 0, 255);
72  canvas->setLineColor(color);
73 
74  drawVerticalLines(canvas, box);
75  drawHorizontalLines(canvas, box);
76 }
77 
79 {
80  // Draw a horizontal line and the y coordinate change(vertical)
81 
82  Utils* utils = Context::getInstance()->getUtils();
83 
84  double y1;
85  double yInit;
86 
87  yInit = m_initialGridPointY;
88  if(yInit < box.getLowerLeftY())
89  {
90  double dify = box.getLowerLeftY() - yInit;
91  int nParts = (int)(dify/m_lneVrtGap);
92  if(nParts == 0)
93  {
94  yInit = m_initialGridPointY;
95  }
96  else
97  {
98  yInit = yInit + (nParts * m_lneVrtGap);
99  }
100  }
101 
102  y1 = yInit;
103  for( ; y1 < box.getUpperRightY() ; y1 += m_lneVrtGap)
104  {
105  if(y1 < box.getLowerLeftY())
106  continue;
107 
108  te::gm::Envelope newBox(box.getLowerLeftX(), y1,
109  box.getUpperRightX(), y1);
110 
111  te::gm::LinearRing* line = 0;
112  line = utils->createSimpleLine(newBox);
113  utils->drawLineW(line);
114 
115  if(line)
116  {
117  delete line;
118  line = 0;
119  }
120  }
121 }
122 
124 {
125  // Draw a vertical line and the x coordinate change(horizontal)
126 
127  Utils* utils = Context::getInstance()->getUtils();
128 
129  double x1;
130  double xInit;
131 
132  xInit = m_initialGridPointX;
133  if(xInit < box.getLowerLeftX())
134  {
135  double difx = box.getLowerLeftX() - xInit;
136  int nParts = (int)(difx/m_lneHrzGap);
137  if(nParts == 0)
138  {
139  xInit = m_initialGridPointX;
140  }
141  else
142  {
143  xInit = xInit + (nParts * m_lneHrzGap);
144  }
145  }
146 
147  x1 = xInit;
148 
149  for( ; x1 < box.getUpperRightX() ; x1 += m_lneHrzGap)
150  {
151  if(x1 < box.getLowerLeftX())
152  continue;
153 
154  te::gm::Envelope newBox(x1, box.getLowerLeftY(),
155  x1, box.getUpperRightY());
156 
157  te::gm::LinearRing* line = 0;
158  line = utils->createSimpleLine(newBox);
159  utils->drawLineW(line);
160 
161  if(line)
162  {
163  delete line;
164  line = 0;
165  }
166  }
167 }
168 
170 {
171  if(m_lneHrzGap <= 0)
172  {
173  m_lneHrzGap = m_mapScale * 0.05;
174  }
175 
176  if(m_lneVrtGap <= 0)
177  {
178  m_lneVrtGap = m_lneHrzGap;
179  }
180 
181  if(m_initialGridPointX <= 0)
182  {
183  m_initialGridPointX = box.getLowerLeftX();
184  }
185  if(m_initialGridPointY <= 0)
186  {
187  m_initialGridPointY = box.getLowerLeftY();
188  }
189 }
190 
192 {
193  m_property.clear();
194 
195  m_property.setName(m_settingsConfig->getName());
196  m_property.setId("unknown");
197  std::string sValuePlanar = "Settings";
198  m_property.setValue(sValuePlanar, DataTypeGridSettings);
199 
200  Property pro_name;
201  pro_name.setName(m_settingsConfig->getName());
202  pro_name.setValue(m_name, DataTypeString);
203  m_property.addSubProperty(pro_name);
204 
205  /* Grid */
206 
207  Property pro_visible;
208  pro_visible.setName(m_settingsConfig->getVisible());
209  pro_visible.setValue(m_visible, DataTypeBool);
210  m_property.addSubProperty(pro_visible);
211 
212  Property pro_lneHrzGap;
213  pro_lneHrzGap.setName(m_settingsConfig->getLneHrzGap());
214  pro_lneHrzGap.setValue(m_lneHrzGap, DataTypeDouble);
215  m_property.addSubProperty(pro_lneHrzGap);
216 
217  Property pro_lneVrtGap;
218  pro_lneVrtGap.setName(m_settingsConfig->getLneVrtGap());
219  pro_lneVrtGap.setValue(m_lneVrtGap, DataTypeDouble);
220  m_property.addSubProperty(pro_lneVrtGap);
221 
222  Property pro_initialGridPointX;
223  pro_initialGridPointX.setName(m_settingsConfig->getInitialGridPointX());
224  pro_initialGridPointX.setValue(m_initialGridPointX, DataTypeDouble);
225  m_property.addSubProperty(pro_initialGridPointX);
226 
227  Property pro_initialGridPointY;
228  pro_initialGridPointY.setName(m_settingsConfig->getInitialGridPointY());
229  pro_initialGridPointY.setValue(m_initialGridPointY, DataTypeDouble);
230  m_property.addSubProperty(pro_initialGridPointY);
231 
232  /* Just one is visible */
233  Property pro_gridStyle;
234  pro_gridStyle.setName(m_settingsConfig->getStyle());
235  pro_gridStyle.setValue(te::layout::getLayoutGridStyle(m_gridStyle), DataTypeString);
236  m_property.addSubProperty(pro_gridStyle);
237 
238  /* Line */
239  Property pro_lineStyle;
240  pro_lineStyle.setName(m_settingsConfig->getLineStyle());
241  pro_lineStyle.setValue(te::layout::getLayoutDashStyle(m_lineStyle), DataTypeString);
242  m_property.addSubProperty(pro_lineStyle);
243 
244  Property pro_lineColor;
245  pro_lineColor.setName(m_settingsConfig->getLineColor());
246  pro_lineColor.setValue(m_lineColor, DataTypeColor);
247  m_property.addSubProperty(pro_lineColor);
248 
249  Property pro_lineWidth;
250  pro_lineWidth.setName(m_settingsConfig->getLineWidth());
251  pro_lineWidth.setValue(m_lineWidth, DataTypeInt);
252  m_property.addSubProperty(pro_lineWidth);
253 
254  /* Text: Basic Configuration */
255  Property pro_pointTextSize;
256  pro_pointTextSize.setName(m_settingsConfig->getPointTextSize());
257  pro_pointTextSize.setValue(m_pointTextSize, DataTypeInt);
258  m_property.addSubProperty(pro_pointTextSize);
259 
260  Property pro_fontText;
261  pro_fontText.setName(m_settingsConfig->getFontText());
262  pro_fontText.setValue(m_fontText, DataTypeString);
263  m_property.addSubProperty(pro_fontText);
264 
265  Property pro_textColor;
266  pro_textColor.setName(m_settingsConfig->getTextColor());
267  pro_textColor.setValue(m_textColor, DataTypeColor);
268  m_property.addSubProperty(pro_textColor);
269 
270  /* Text: Advanced configuration */
271  Property pro_visibleAllTexts;
272  pro_visibleAllTexts.setName(m_settingsConfig->getVisibleAllTexts());
273  pro_visibleAllTexts.setValue(m_visibleAllTexts, DataTypeBool);
274  m_property.addSubProperty(pro_visibleAllTexts);
275 
276  Property pro_superscriptText;
277  pro_superscriptText.setName(m_settingsConfig->getSuperscriptText());
278  pro_superscriptText.setValue(m_superscriptText, DataTypeBool);
279  m_property.addSubProperty(pro_superscriptText);
280 
281  Property pro_lneVrtDisplacement;
282  pro_lneVrtDisplacement.setName(m_settingsConfig->getLneVrtDisplacement());
283  pro_lneVrtDisplacement.setValue(m_lneVrtDisplacement, DataTypeDouble);
284  m_property.addSubProperty(pro_lneVrtDisplacement);
285 
286  Property pro_lneHrzDisplacement;
287  pro_lneHrzDisplacement.setName(m_settingsConfig->getLneHrzDisplacement());
288  pro_lneHrzDisplacement.setValue(m_lneHrzDisplacement, DataTypeDouble);
289  m_property.addSubProperty(pro_lneHrzDisplacement);
290 
291  Property pro_bottomText;
292  pro_bottomText.setName(m_settingsConfig->getBottomText());
293  pro_bottomText.setValue(m_bottomText, DataTypeBool);
294  m_property.addSubProperty(pro_bottomText);
295 
296  Property pro_leftText;
297  pro_leftText.setName(m_settingsConfig->getLeftText());
298  pro_leftText.setValue(m_leftText, DataTypeBool);
299  m_property.addSubProperty(pro_leftText);
300 
301  Property pro_rightText;
302  pro_rightText.setName(m_settingsConfig->getRightText());
303  pro_rightText.setValue(m_rightText, DataTypeBool);
304  m_property.addSubProperty(pro_rightText);
305 
306  Property pro_topText;
307  pro_topText.setName(m_settingsConfig->getTopText());
308  pro_topText.setValue(m_topText, DataTypeBool);
309  m_property.addSubProperty(pro_topText);
310 
311  Property pro_bottomRotateText;
312  pro_bottomRotateText.setName(m_settingsConfig->getBottomRotateText());
313  pro_bottomRotateText.setValue(m_bottomRotateText, DataTypeBool);
314  m_property.addSubProperty(pro_bottomRotateText);
315 
316  Property pro_leftRotateText;
317  pro_leftRotateText.setName(m_settingsConfig->getLeftRotateText());
318  pro_leftRotateText.setValue(m_leftRotateText, DataTypeBool);
319  m_property.addSubProperty(pro_leftRotateText);
320 
321  Property pro_rightRotateText;
322  pro_rightRotateText.setName(m_settingsConfig->getRightRotateText());
323  pro_rightRotateText.setValue(m_rightRotateText, DataTypeBool);
324  m_property.addSubProperty(pro_rightRotateText);
325 
326  Property pro_topRotateText;
327  pro_topRotateText.setName(m_settingsConfig->getTopRotateText());
328  pro_topRotateText.setValue(m_topRotateText, DataTypeBool);
329  m_property.addSubProperty(pro_topRotateText);
330 
331  //-----------------------------------------------------------
332 
333  return m_property;
334 }
335 
337 {
338  if(property.isNull())
339  {
340  return;
341  }
342 
343  Property pro_visible = property.containsSubProperty(m_settingsConfig->getVisible());
344  if(!pro_visible.isNull())
345  {
346  m_visible = pro_visible.getValue().toBool();
347  }
348 
349  Property pro_lneHrzGap = property.containsSubProperty(m_settingsConfig->getLneHrzGap());
350  if(!pro_lneHrzGap.isNull())
351  {
352  m_lneHrzGap = pro_lneHrzGap.getValue().toDouble();
353  }
354 
355  Property pro_lneVrtGap = property.containsSubProperty(m_settingsConfig->getLneVrtGap());
356  if(!pro_lneVrtGap.isNull())
357  {
358  m_lneVrtGap = pro_lneVrtGap.getValue().toDouble();
359  }
360 
361  Property pro_initialGridPointX = property.containsSubProperty(m_settingsConfig->getInitialGridPointX());
362  if(!pro_initialGridPointX.isNull())
363  {
364  m_initialGridPointX = pro_initialGridPointX.getValue().toDouble();
365  }
366 
367  Property pro_initialGridPointY = property.containsSubProperty(m_settingsConfig->getInitialGridPointY());
368  if(!pro_initialGridPointY.isNull())
369  {
370  m_initialGridPointY = pro_initialGridPointY.getValue().toDouble();
371  }
372 
373  Property pro_gridStyle = property.containsSubProperty(m_settingsConfig->getStyle());
374  if(!pro_gridStyle.isNull())
375  {
376  std::string style = pro_gridStyle.getValue().toString();
377  m_gridStyle = te::layout::getLayoutEnumGridStyle(style);
378  }
379 
380  Property pro_lineStyle = property.containsSubProperty(m_settingsConfig->getLineStyle());
381  if(!pro_lineStyle.isNull())
382  {
383  std::string style = pro_lineStyle.getValue().toString();
384  m_lineStyle = te::layout::getLayoutEnumDashStyle(style);
385  }
386 
387  Property pro_lineColor = property.containsSubProperty(m_settingsConfig->getLineColor());
388  if(!pro_lineColor.isNull())
389  {
390  m_lineColor = pro_lineColor.getValue().toColor();
391  }
392 
393  Property pro_lineWidth = property.containsSubProperty(m_settingsConfig->getLineWidth());
394  if(!pro_lineWidth.isNull())
395  {
396  m_lineWidth = pro_lineWidth.getValue().toInt();
397  }
398 
399  Property pro_pointTextSize = property.containsSubProperty(m_settingsConfig->getPointTextSize());
400  if(!pro_pointTextSize.isNull())
401  {
402  m_pointTextSize = pro_pointTextSize.getValue().toInt();
403  }
404 
405  Property pro_fontText = property.containsSubProperty(m_settingsConfig->getFontText());
406  if(!pro_fontText.isNull())
407  {
408  m_fontText= pro_fontText.getValue().toString();
409  }
410 
411  Property pro_textColor = property.containsSubProperty(m_settingsConfig->getTextColor());
412  if(!pro_textColor.isNull())
413  {
414  m_textColor = pro_textColor.getValue().toColor();
415  }
416 
417  Property pro_visibleAllTexts = property.containsSubProperty(m_settingsConfig->getVisibleAllTexts());
418  if(!pro_visibleAllTexts.isNull())
419  {
420  m_visibleAllTexts = pro_visibleAllTexts.getValue().toBool();
421  }
422 
423  Property pro_superscriptText = property.containsSubProperty(m_settingsConfig->getSuperscriptText());
424  if(!pro_superscriptText.isNull())
425  {
426  m_superscriptText = pro_superscriptText.getValue().toBool();
427  }
428 
429  Property pro_lneVrtDisplacement = property.containsSubProperty(m_settingsConfig->getLneVrtDisplacement());
430  if(!pro_lneVrtDisplacement.isNull())
431  {
432  m_lneVrtDisplacement = pro_lneVrtDisplacement.getValue().toInt();
433  }
434 
435  Property pro_lneHrzDisplacement = property.containsSubProperty(m_settingsConfig->getLneHrzDisplacement());
436  if(!pro_lneHrzDisplacement.isNull())
437  {
438  m_lneHrzDisplacement = pro_lneHrzDisplacement.getValue().toInt();
439  }
440 
441  Property pro_bottomText = property.containsSubProperty(m_settingsConfig->getBottomText());
442  if(!pro_bottomText.isNull())
443  {
444  m_bottomText = pro_bottomText.getValue().toBool();
445  }
446 
447  Property pro_leftText = property.containsSubProperty(m_settingsConfig->getLeftText());
448  if(!pro_leftText.isNull())
449  {
450  m_leftText = pro_leftText.getValue().toBool();
451  }
452 
453  Property pro_rightText = property.containsSubProperty(m_settingsConfig->getRightText());
454  if(!pro_rightText.isNull())
455  {
456  m_rightText = pro_rightText.getValue().toBool();
457  }
458 
459  Property pro_topText = property.containsSubProperty(m_settingsConfig->getTopText());
460  if(!pro_topText.isNull())
461  {
462  m_topText = pro_topText.getValue().toBool();
463  }
464 
465  Property pro_bottomRotateText = property.containsSubProperty(m_settingsConfig->getBottomRotateText());
466  if(!pro_bottomRotateText.isNull())
467  {
468  m_bottomRotateText = pro_bottomRotateText.getValue().toBool();
469  }
470 
471  Property pro_leftRotateText = property.containsSubProperty(m_settingsConfig->getLeftRotateText());
472  if(!pro_leftRotateText.isNull())
473  {
474  m_leftRotateText = pro_leftRotateText.getValue().toBool();
475  }
476 
477  Property pro_rightRotateText = property.containsSubProperty(m_settingsConfig->getRightRotateText());
478  if(!pro_rightRotateText.isNull())
479  {
480  m_rightRotateText = pro_rightRotateText.getValue().toBool();
481  }
482 
483  Property pro_topRotateText = property.containsSubProperty(m_settingsConfig->getTopRotateText());
484  if(!pro_topRotateText.isNull())
485  {
486  m_topRotateText = pro_topRotateText.getValue().toBool();
487  }
488 }
489 
Variant getValue()
Definition: Property.cpp:74
double m_lneHrzDisplacement
Definition: GridModel.h:111
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:410
virtual void drawVerticalLines(te::map::Canvas *canvas, te::gm::Envelope box)
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
Definition: Envelope.h:400
std::string m_name
Definition: GridModel.h:80
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:420
virtual void drawHorizontalLines(te::map::Canvas *canvas, te::gm::Envelope box)
virtual void updateProperty(te::layout::Property property)
virtual te::gm::LinearRing * createSimpleLine(te::gm::Envelope box)
Definition: Utils.cpp:85
void setValue(typename ValueType value, LayoutPropertyDataType type)
Definition: Property.h:106
te::layout::LayoutGridStyle getLayoutEnumGridStyle(std::string val)
Definition: EnumUtils.cpp:56
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
std::string getLayoutGridStyle(int enumVal)
Definition: EnumUtils.cpp:51
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
PlanarGridSettingsConfigProperties * m_settingsConfig
Utils * getUtils()
Definition: Context.cpp:126
virtual te::layout::Property getProperty()
virtual void drawLineW(te::gm::LinearRing *line)
Definition: Utils.cpp:73
virtual void draw(te::map::Canvas *canvas, te::gm::Envelope box, int srid)
virtual bool containsSubProperty(Property subProperty)
Definition: Property.cpp:167
virtual void calculateGaps(te::gm::Envelope box)
double m_lneVrtDisplacement
Definition: GridModel.h:110
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
Definition: Envelope.h:390
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
std::string toString()
Definition: Variant.cpp:237
void setName(std::string name)
Definition: Property.cpp:54
te::map::LineDashStyle getLayoutEnumDashStyle(std::string val)
Definition: EnumUtils.cpp:86
virtual void setLineColor(const te::color::RGBAColor &color)=0
It sets the pen color used to draw line geometries.
te::color::RGBAColor toColor()
Definition: Variant.cpp:267
static Context * getInstance()
This function is called to create an instance of the class.
Definition: Context.cpp:46
std::string getLayoutDashStyle(int enumVal)
Definition: EnumUtils.cpp:81
bool isValid() const
It tells if the rectangle is valid or not.
Definition: Envelope.h:438