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