DrawThread.cpp
Go to the documentation of this file.
1 #include "DrawThread.h"
2 
3 // TerraLib
4 #include "../Utils.h"
5 #include "../../../core/logger/Logger.h"
6 #include "../../../core/translator/Translator.h"
7 #include "../../../common/Exception.h"
8 #include "../../../common/StringUtils.h"
9 #include "../../../geometry/Envelope.h"
10 #include "../../../maptools/AbstractLayer.h"
11 #include "../../../srs/Config.h"
12 #include "Canvas.h"
13 
14 // STL
15 #include <ctime>
16 
19  te::gm::Envelope* env,
20  const QColor& bckGround, int srid,
21  double scale, te::map::AlignType hAlign,
22  te::map::AlignType vAlign)
23  :
24 
25  m_device(dev),
26  m_layer(layer),
27  m_envelope(env),
28  m_bckGround(bckGround),
29  m_srid(srid),
30  m_scale(scale),
31  m_hAlign(hAlign),
32  m_vAlign(vAlign),
33  m_cancel(false)
34 {
35  setAutoDelete(false);
36 }
37 
39 
41 {
42  m_finished = false;
43 
44  try
45  {
46  time_t startTime, endTime;
47 
48  time(&startTime);
49 
50  Canvas canvas(m_device);
51  canvas.clear();
52 
53  m_layer->draw(&canvas, *m_envelope, m_srid, m_scale, &m_cancel);
54 
55  time(&endTime);
56 
57  // difference in seconds
58  double diffInSec = difftime(endTime, startTime);
59 
60  std::string strTime = TE_TR("The layer ");
61  strTime += m_layer->getTitle();
62  strTime += TE_TR(" has been drawn in ");
63  strTime += te::common::Convert2String(diffInSec, 2);
64  strTime += TE_TR(" seconds");
65 
66  TE_LOG_INFO(strTime);
67 
68  if(!m_cancel)
69  m_finished = true;
70  }
71  catch(const te::common::Exception& e)
72  {
74  {
75  //try again
76  //msleep(100);
77  }
78  else
79  m_errorMessage = QString(tr("The layer") + " %1 " + tr("could not be drawn! Details:") + " %2").arg(m_layer->getTitle().c_str()).arg(e.what());
80  }
81  catch(const std::exception& e)
82  {
83  m_errorMessage = QString(tr("The layer") + " %1 " + tr("could not be drawn! Details:") + " %2").arg(m_layer->getTitle().c_str()).arg(e.what());
84  }
85  catch(...)
86  {
87  m_errorMessage = QString(tr("The layer") + " %1 " + tr("could not be drawn!")).arg(m_layer->getTitle().c_str());
88  }
89 
90  if (!m_errorMessage.isEmpty())
91  TE_LOG_INFO(m_errorMessage.toUtf8().data());
92 
93  emit finished();
94 }
95 
97 {
98  return m_finished;
99 }
100 
102 {
103  return m_errorMessage;
104 }
105 
107 {
108  return QString::fromUtf8(m_layer->getId().c_str());
109 }
virtual const std::string & getId() const
It returns the layer id.
A canvas built on top of Qt.
void clear()
It clears the canvas content and fills with the background color.
QString layerId() const
Definition: DrawThread.cpp:106
This is the base class for layers.
Definition: AbstractLayer.h:77
virtual const std::string & getTitle() const
It returns the layer title.
Thread to draw a Layer in a PaintDevice.
virtual const char * what() const
It outputs the exception message.
QString errorMessage() const
Definition: DrawThread.cpp:101
te::gm::Envelope * m_envelope
Definition: DrawThread.h:86
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
#define TE_LOG_INFO(message)
Use this tag in order to log a message to the TerraLib default logger with the INFO level...
Definition: Logger.h:315
DrawThread(QPaintDevice *dev, te::map::AbstractLayer *layer, te::gm::Envelope *env, const QColor &bckGround, int srid, double scale, te::map::AlignType hAlign, te::map::AlignType vAlign)
Definition: DrawThread.cpp:17
AlignType
This enum contains values to control the alignment of components (like Canvas and MapDisplay)...
virtual int code() const
It gets the exception code.
An Envelope defines a 2D rectangular region.
te::map::AbstractLayer * m_layer
Definition: DrawThread.h:84
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
QPaintDevice * m_device
Definition: DrawThread.h:82
virtual void draw(Canvas *canvas, const te::gm::Envelope &bbox, int srid, const double &scale, bool *cancel)=0
It draws the layer geographic objects in the given canvas using the informed SRS. ...
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56