All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HorizontalRulerModel.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 HorizontalRulerModel.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "HorizontalRulerModel.h"
30 #include "ContextItem.h"
31 #include "ItemModelObservable.h"
32 #include "Context.h"
33 #include "EnumMode.h"
34 #include "Utils.h"
35 #include "../../../maptools/Canvas.h"
36 #include "../../../geometry/Envelope.h"
37 #include "../../../geometry/Point.h"
38 #include "../../../color/RGBAColor.h"
39 
40 // STL
41 #include <sstream>
42 #include <string>
43 
45 {
46 
47 }
48 
50 {
51 
52 }
53 
55 {
56  te::color::RGBAColor** pixmap = 0;
57 
59  Utils* utils = Context::getInstance()->getUtils();
60 
61  if(context.isResizeCanvas())
62  utils->configCanvas(m_box);
63 
64  drawRuler(canvas, utils);
65 
66  if(context.isResizeCanvas())
67  pixmap = utils->getImageW(m_box);
68 
69  ContextItem contextNotify;
70  contextNotify.setPixmap(pixmap);
71  notifyAll(contextNotify);
72 }
73 
75 {
76  if(!m_visible)
77  {
78  return;
79  }
80 
81  te::gm::Envelope envPaper;
82  te::gm::Envelope envMargin;
83 
84  te::color::RGBAColor colorp4(180,180,180, TE_OPAQUE);
85  drawRectW(m_box, colorp4, canvas, utils);
86 
87  te::color::RGBAColor colorp85(145,145,145, TE_OPAQUE);
88  drawRectW(m_backEndBox, colorp85, canvas, utils);
89 
90  envPaper = te::gm::Envelope(m_paperBox.getLowerLeftX(), m_backEndBox.getLowerLeftY(),
91  m_paperBox.getUpperRightX(), m_backEndBox.getUpperRightY());
92 
93  te::color::RGBAColor colorp5(255,255,255, TE_OPAQUE);
94  drawRectW(envPaper, colorp5, canvas, utils);
95 
96  te::color::RGBAColor colorp6(0,0,0, TE_OPAQUE);
97  canvas->setLineColor(colorp6);
98 
99  drawHorizontalRuler(canvas, utils);
100 
101  envMargin = te::gm::Envelope(m_backEndBox.getLowerLeftX(), m_backEndBox.getUpperRightY() - m_lineMargin,
102  m_backEndBox.getWidth(), m_backEndBox.getUpperRightY() - m_lineMargin);
103 
104  drawLineW(envMargin, utils);
105 }
106 
108 {
109  if(!m_box.isValid())
110  return;
111 
112  double llx = m_backEndBox.getLowerLeftX();
113  double urx = m_backEndBox.getUpperRightX();
114 
115  te::gm::Envelope box;
116 
117  for(int i = (int)llx ; i < (int) urx ; ++i)
118  {
119  if((i % (int)m_blockSize) == 0)
120  {
121  box = te::gm::Envelope(i, m_backEndBox.getUpperRightY(), i, m_backEndBox.getUpperRightY() - m_longLine);
122  drawLineW(box, utils);
123 
124  std::stringstream ss;//create a stringstream
125  ss << i;//add number to the stream
126 
127  canvas->drawText((double)i, m_backEndBox.getUpperRightY() - (m_longLine + 1.), ss.str(), 0);
128  }
129  else if((i % (int)m_middleBlockSize) == 0)
130  {
131  box = te::gm::Envelope(i, m_backEndBox.getUpperRightY(), i, m_backEndBox.getUpperRightY() - m_mediumLine);
132  drawLineW(box, utils);
133  }
134  else if((i % (int)m_smallBlockSize) == 0)
135  {
136  box = te::gm::Envelope(i, m_backEndBox.getUpperRightY(), i, m_backEndBox.getUpperRightY() - m_smallLine);
137  drawLineW(box, utils);
138  }
139  }
140 }
141 
143 {
144  if(box.getWidth() < 15. || box.getHeight() < 3.)
145  return;
146 
147  m_box = box;
148  m_backEndBox = te::gm::Envelope(m_box.getLowerLeftX() + m_backEndSpacing, m_box.getLowerLeftY() + m_backEndMargin,
149  m_box.getUpperRightX(), m_box.getUpperRightY() - m_backEndMargin);
150 }
void setPixmap(te::color::RGBAColor **pixmap)
Definition: ContextItem.cpp:77
virtual void drawText(int x, int y, const std::string &txt, float angle=0.0, te::at::HorizontalAlignment hAlign=te::at::Start, te::at::VerticalAlignment vAlign=te::at::Baseline)=0
It draws a text.
virtual void configCanvas(te::gm::Envelope box, bool resize=true)
Definition: Utils.cpp:124
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
virtual void drawHorizontalRuler(te::map::Canvas *canvas, Utils *utils)
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
Definition: Config.h:39
virtual void drawRuler(te::map::Canvas *canvas, Utils *utils)
Utils * getUtils()
Definition: Context.cpp:126
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
virtual void setBox(te::gm::Envelope box)
virtual te::color::RGBAColor ** getImageW(te::gm::Envelope boxmm)
Definition: Utils.cpp:97
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
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
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
te::map::Canvas * getCanvas()
Definition: Context.cpp:116
virtual void draw(ContextItem context)