All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VerticalRulerModel.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 VerticalRulerModel.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "VerticalRulerModel.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 
39 // STL
40 #include <sstream>
41 #include <string> // std::string, std::to_string
42 
44 {
45 
46 }
47 
49 {
50 
51 }
52 
54 {
55  te::color::RGBAColor** pixmap = 0;
56 
58  Utils* utils = Context::getInstance()->getUtils();
59 
60  if(context.isResizeCanvas())
61  utils->configCanvas(m_box);
62 
63  drawRuler(canvas, utils);
64 
65  if(context.isResizeCanvas())
66  pixmap = utils->getImageW(m_box);
67 
68  ContextItem contextNotify;
69  contextNotify.setPixmap(pixmap);
70  notifyAll(contextNotify);
71 }
72 
74 {
75  if(!m_visible)
76  {
77  return;
78  }
79 
80  te::gm::Envelope envPaper;
81  te::gm::Envelope envMargin;
82 
83  te::color::RGBAColor colorp4(180,180,180, TE_OPAQUE);
84  drawRectW(m_box, colorp4, canvas, utils);
85 
86  te::color::RGBAColor colorp85(145,145,145, TE_OPAQUE);
87  drawRectW(m_backEndBox, colorp85, canvas, utils);
88 
89  envPaper = te::gm::Envelope(m_backEndBox.getLowerLeftX(), m_paperBox.getLowerLeftY(),
90  m_backEndBox.getUpperRightX(), m_backEndBox.getUpperRightY());
91 
92  te::color::RGBAColor colorp2(255,255,255, TE_OPAQUE);
93  drawRectW(envPaper, colorp2, canvas, utils);
94 
95  te::color::RGBAColor colorp3(0,0,0, TE_OPAQUE);
96  canvas->setLineColor(colorp3);
97 
98  drawVerticalRuler(canvas, utils);
99 
100  envMargin = te::gm::Envelope(m_backEndBox.getLowerLeftX() + m_lineMargin, m_backEndBox.getLowerLeftY(),
101  m_backEndBox.getLowerLeftX() + m_lineMargin, m_backEndBox.getUpperRightY());
102 
103  drawLineW(envMargin, utils);
104 }
105 
107 {
108  if(!m_box.isValid())
109  return;
110 
111  double lly = m_backEndBox.getLowerLeftY();
112  double ury = m_backEndBox.getUpperRightY();
113 
114  te::gm::Envelope box;
115 
116  for(int i = (int)lly ; i < (int) ury ; ++i)
117  {
118  if((i % (int)m_blockSize) == 0)
119  {
120  box = te::gm::Envelope(m_backEndBox.getLowerLeftX(), i, m_backEndBox.getLowerLeftX() + m_longLine, i);
121  drawLineW(box, utils);
122 
123  std::stringstream ss;//create a stringstream
124  ss << i;//add number to the stream
125 
126  canvas->drawText(m_backEndBox.getLowerLeftX() + (m_longLine + 1.), (double)i, ss.str(), -90);
127  }
128  else if((i % (int)m_middleBlockSize) == 0)
129  {
130  box = te::gm::Envelope(m_backEndBox.getLowerLeftX(), i, m_backEndBox.getLowerLeftX() + m_mediumLine, i);
131  drawLineW(box, utils);
132  }
133  else if((i % (int)m_smallBlockSize) == 0)
134  {
135  box = te::gm::Envelope(m_backEndBox.getLowerLeftX(), i, m_backEndBox.getLowerLeftX() + m_smallLine, i);
136  drawLineW(box, utils);
137  }
138  }
139 }
140 
142 {
143  if(box.getWidth() < 3. || box.getHeight() < 10.)
144  return;
145 
146  m_box = box;
147  m_backEndBox = te::gm::Envelope(m_box.getLowerLeftX() + m_backEndMargin, m_box.getLowerLeftY(),
148  m_box.getUpperRightX() - m_backEndMargin , m_box.getUpperRightY() - m_backEndSpacing);
149 }
virtual void draw(ContextItem context)
void setPixmap(te::color::RGBAColor **pixmap)
Definition: ContextItem.cpp:77
virtual void setBox(te::gm::Envelope box)
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 drawRuler(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
Utils * getUtils()
Definition: Context.cpp:126
virtual void drawVerticalRuler(te::map::Canvas *canvas, Utils *utils)
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
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