27 #include "../../../common/STLUtils.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../dataaccess/dataset/ObjectIdSet.h"
31 #include "../../../dataaccess/utils/Utils.h"
32 #include "../../../geometry/Coord2D.h"
33 #include "../../../geometry/Geometry.h"
34 #include "../../../geometry/GeometryProperty.h"
35 #include "../../../geometry/Point.h"
36 #include "../../../geometry/Utils.h"
37 #include "../../../srs/Config.h"
38 #include "../canvas/MapDisplay.h"
39 #include "../utils/ScopedCursor.h"
43 #include <QtCore/QString>
44 #include <QtGui/QKeyEvent>
45 #include <QtGui/QMessageBox>
46 #include <QtGui/QMouseEvent>
56 m_selectionStarted(false),
57 m_keepPreviousSelection(false),
58 m_selectionByPointing(false)
64 m_pen.setColor(QColor(255, 255, 100));
66 m_brush = QColor(255, 255, 100, 80);
75 if(e->button() != Qt::LeftButton)
78 m_selectionStarted =
true;
86 if(!m_selectionStarted)
96 m_selectionStarted =
false;
98 if(e->button() != Qt::LeftButton)
103 m_keepPreviousSelection =
false;
105 Qt::KeyboardModifiers keys = e->modifiers();
107 if(keys & Qt::ControlModifier || keys & Qt::ShiftModifier)
108 m_keepPreviousSelection =
true;
110 m_selectionByPointing =
false;
114 m_selectionByPointing =
true;
115 QPointF pixelOffset(4.0, 4.0);
116 m_rect = QRectF(e->posF() - pixelOffset, e->posF() + pixelOffset);
120 QPointF ll(m_rect.left(), m_rect.bottom());
121 QPointF ur(m_rect.right(), m_rect.top());
122 ll = m_display->transform(ll);
123 ur = m_display->transform(ur);
128 std::list<te::map::AbstractLayerPtr>::iterator it;
129 for(it = m_layers.begin(); it != m_layers.end(); ++it)
130 executeSelection(*it, envelope);
145 std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
147 if(!dsType->hasGeom())
153 reprojectedEnvelope.
transform(m_display->getSRID(), layer->getSRID());
156 if(!m_keepPreviousSelection)
158 layer->clearSelected();
159 emit layerSelectedObjectsChanged(layer);
162 if(!reprojectedEnvelope.
intersects(layer->getExtent()))
168 std::auto_ptr<const te::map::LayerSchema> schema(layer->getSchema());
169 if(!schema->hasGeom())
176 assert(dataset.get());
183 std::vector<std::string> pnames;
189 if(m_selectionByPointing ==
false)
191 while(dataset->moveNext())
193 std::auto_ptr<te::gm::Geometry> g(dataset->getGeometry(gp->
getName()));
195 if(!g->intersects(geometryFromEnvelope.get()))
208 while(dataset->moveNext())
210 std::auto_ptr<te::gm::Geometry> g(dataset->getGeometry(gp->
getName()));
212 if(g->contains(&point) || g->crosses(geometryFromEnvelope.get()) || geometryFromEnvelope->contains(g.get()))
226 if(currentOids == 0 || !m_keepPreviousSelection)
229 emit layerSelectedObjectsChanged(layer);
238 layer->clearSelected();
240 layer->select(finalSelected);
242 emit layerSelectedObjectsChanged(layer);
244 catch(std::exception& e)
246 QMessageBox::critical(m_display, tr(
"Error"), QString(tr(
"The selection cannot be retrieved from the layer. Details:") +
" %1.").arg(e.what()));
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
virtual bool mouseReleaseEvent(QMouseEvent *e)
This class implements a concrete tool to select layer features using an extent.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Selection(MapDisplay *display, const QCursor &cursor, const std::list< te::map::AbstractLayerPtr > &layers, QObject *parent=0)
It constructs a selection tool associated with the given map display.
bool mouseMoveEvent(QMouseEvent *e)
TEDATAACCESSEXPORT void GetEmptyOIDSet(const DataSetType *type, ObjectIdSet *&set)
Returns an empty ObjectIdSet, with the definitions of fields that compose it.
const std::string & getName() const
It returns the property name.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
An utility struct for representing 2D coordinates.
virtual void setCursor(const QCursor &cursor)
virtual bool mouseMoveEvent(QMouseEvent *e)
virtual bool mousePressEvent(QMouseEvent *e)
TEDATAACCESSEXPORT ObjectId * GenerateOID(DataSet *dataset, const std::vector< std::string > &names)
bool mouseReleaseEvent(QMouseEvent *e)
A point with x and y coordinate values.
void symDifference(const ObjectIdSet *rhs)
It performs the symmetric difference operation between this ObjectIdSet and the given ObjectIdSet...
QPen m_pen
The pen used to draw the rubber band shape.
A widget to control the display of a set of layers.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
This class provides a rectangle that can indicate a boundary.
TEDATAACCESSEXPORT void GetOIDPropertyNames(const DataSetType *type, std::vector< std::string > &pnames)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QBrush m_brush
The brush used to draw the rubber band shape.
An Envelope defines a 2D rectangular region.
void executeSelection(const te::map::AbstractLayerPtr &layer, const te::gm::Envelope &e)
ObjectIdSet * clone() const
void setLayers(const std::list< te::map::AbstractLayerPtr > &layers)
bool mousePressEvent(QMouseEvent *e)
An object that when created shows a cursor during its scope.