27 #include "../../../common/STLUtils.h"
28 #include "../../../common/UnitOfMeasure.h"
29 #include "../../../common/UnitsOfMeasureManager.h"
30 #include "../../../geometry/Envelope.h"
31 #include "../../../geometry/Geometry.h"
32 #include "../../../geometry/LinearRing.h"
33 #include "../../../geometry/LineString.h"
34 #include "../../../geometry/Point.h"
35 #include "../../../geometry/Polygon.h"
36 #include "../canvas/Canvas.h"
37 #include "../canvas/MapDisplay.h"
41 #include <QtGui/QMouseEvent>
42 #include <QtGui/QPainter>
43 #include <QtGui/QPixmap>
50 m_measureType(measureType),
55 m_pen.setColor(QColor(100, 177, 216));
57 m_brush = QColor(100, 177, 216, 80);
63 m_unit = unit->getSymbol();
71 QPixmap* draft = m_display->getDraftPixmap();
72 draft->fill(Qt::transparent);
77 if(e->button() != Qt::LeftButton)
87 if(m_coords.size() == 2 && m_measureType ==
Angle)
90 QPointF pw = m_display->transform(e->pos());
98 if(m_coords.size() < 1 || m_isFinished)
101 QPointF pw = m_display->transform(e->posF());
104 QPointF pos = e->posF() + QPointF(0.0001, 0.0001);
105 pw = m_display->transform(pos);
120 if(e->button() != Qt::LeftButton)
123 if(m_measureType ==
Area && m_coords.size() < 3)
138 QPixmap* draft = m_display->getDraftPixmap();
139 draft->fill(Qt::transparent);
142 Canvas canvas(m_display->width(), m_display->height());
145 canvas.setRenderHint(QPainter::Antialiasing,
true);
148 switch(m_measureType)
162 m_display->repaint();
169 for(std::size_t i = 0; i < m_coords.size(); ++i)
170 line->
setPoint(i, m_coords[i].x, m_coords[i].y);
180 if(m_measureType == Distance)
182 drawText(canvas, (tr(
"Distance: ") + QString::number(calculateLength(line)) +
" " + m_unit.c_str()).toStdString(), line->
getEndPoint());
184 else if(m_measureType ==
Angle)
187 drawText(canvas, (tr(
"Angle: ") + QString::number(calculateAngle(line)) +
" deg").toStdString(), line->
getPointN(1));
195 if(m_coords.size() < 3)
196 return drawLine(canvas);
200 for(std::size_t i = 0; i < m_coords.size(); ++i)
201 ring->
setPoint(i, m_coords[i].x, m_coords[i].y);
202 ring->
setPoint(m_coords.size(), m_coords[0].x, m_coords[0].y);
213 canvas.
draw(polygon);
218 drawText(canvas, (tr(
"Area: ") + QString::number(polygon->
getArea()) + (m_unit.empty() ?
"" : (
" " + m_unit +
"^2").c_str())).toStdString(), &p);
240 QPixmap* draft = m_display->getDraftPixmap();
241 draft->fill(Qt::transparent);
243 m_display->repaint();
250 for(std::size_t i = 0; i < n - 1; ++i)
268 return line1.angle(line2);
277 m_unit = unit->getSymbol();
287 m_coords.push_back(m_lastPos);
void setPolygonContourColor(const te::color::RGBAColor &color)
It sets the pen color used to draw the boundary of polygon geometries.
bool mouseReleaseEvent(QMouseEvent *e)
bool isValid() const
It tells if the rectangle is valid or not.
bool mouseMoveEvent(QMouseEvent *e)
void setTextContourWidth(int width)
It sets the text contour width.
void setLineColor(const te::color::RGBAColor &color)
It sets the pen color used to draw line geometries.
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
MeasureType
Defines the measure type measured by this tool.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
double getArea() const
It returns the area of this surface, as measured in the spatial reference system of this surface...
A LinearRing is a LineString that is both closed and simple.
This class implements a concrete tool to measure operation (distance, area, and angle).
bool mouseDoubleClickEvent(QMouseEvent *e)
void setLineWidth(int w)
It sets the line width.
virtual double distance(const Geometry *const rhs) const
It returns the shortest distance between any two points in the two geometry objects.
This class defines an interface for objects that can receive application events and respond to them...
void drawText(Canvas &canvas, const std::string &text, te::gm::Point *p)
std::string m_unit
The unit symbol for the measure.
Measure(MapDisplay *display, const MeasureType &measureType, QObject *parent=0)
It constructs a measure tool associated with the given map display.
void drawLine(Canvas &canvas)
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
double calculateLength(te::gm::LineString *line) const
void setDevice(QPaintDevice *device, bool takeOwnerShip)
It sets new device as QPrinter.
void setPolygonFillColor(const te::color::RGBAColor &color)
It sets the color used to fill the draw of polygon geometries.
An utility struct for representing 2D coordinates.
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
LineString is a curve with linear interpolation between points.
bool mousePressEvent(QMouseEvent *e)
const double & getX() const
It returns the Point x-coordinate value.
void draw(const te::gm::Geometry *geom)
It draws the geometry on canvas.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
void setTextPointSize(double psize)
It sets the text point Size.
double m_lly
Lower left corner y-coordinate.
void setTextContourColor(const te::color::RGBAColor &color)
It sets the text contour (outline) drawing color.
double m_ury
Upper right corner y-coordinate.
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)
It draws a text.
MapDisplay * m_display
The map display associated with the tool.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
A canvas built on top of Qt.
A point with x and y coordinate values.
void setTextWeight(te::at::FontWeight weight)
It sets the text weight.
void setTextColor(const te::color::RGBAColor &color)
It sets the text drawing color.
double m_urx
Upper right corner x-coordinate.
A widget to control the display of a set of layers.
void setFontFamily(const std::string &family)
It sets the text font family.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
Point * getPointN(std::size_t i) const
It returns the specified point in this LineString.
Point * getEndPoint() const
It returns the curve end point.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
void setPolygonContourWidth(int w)
It sets the polygon contour width.
double calculateAngle(te::gm::LineString *line) const
double m_llx
Lower left corner x-coordinate.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
QBrush m_brush
The brush used to draw the path.
const double & getY() const
It returns the Point y-coordinate value.
QPen m_pen
The pen used to draw the path.
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
void setTextContourEnabled(bool b)
It controls the display of the text outline.
An Envelope defines a 2D rectangular region.
void drawPolygon(Canvas &canvas)