Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+127
@@ -0,0 +1,127 @@
|
||||
|
||||
/**
|
||||
**
|
||||
** @RDE_HEADER@
|
||||
** Definition of ellipse drawable
|
||||
** $Id$
|
||||
** $HeadURL$
|
||||
** $Author$
|
||||
*/
|
||||
|
||||
#include "drawable_ellipse.h"
|
||||
|
||||
#include <MathUtils/math_const.h>
|
||||
#include <QtWidgets/QGraphicsEllipseItem>
|
||||
|
||||
|
||||
namespace SituationMap { namespace RB
|
||||
{
|
||||
|
||||
DrawableEllipse::DrawableEllipse(Esri::ArcGISRuntime::MapGraphicsView * map) : DrawableEllipse(map,map->scene()) {;}
|
||||
|
||||
|
||||
DrawableEllipse::DrawableEllipse(Esri::ArcGISRuntime::MapGraphicsView * map, QGraphicsScene * scene)
|
||||
: RubberbandDrawable(map, scene)
|
||||
, _elliItem(nullptr)
|
||||
, _center()
|
||||
, _radiusX(0)
|
||||
, _radiusY(0)
|
||||
, _elliStyle()
|
||||
, _sinRect(0)
|
||||
, _cosRect(1)
|
||||
, _sectorStart()
|
||||
, _sectorEnd()
|
||||
{
|
||||
_elliItem = new QGraphicsEllipseItem();
|
||||
_scene -> addItem( _elliItem );
|
||||
makeLineStyle( false, _elliStyle );
|
||||
_elliItem -> setPen( _elliStyle );
|
||||
|
||||
_sectItem = new QGraphicsEllipseItem();
|
||||
_scene -> addItem( _sectItem );
|
||||
makeLineStyle( false, _elliStyle );
|
||||
_sectItem -> setPen( _elliStyle );
|
||||
} /* DrawableLine::DrawableLine */
|
||||
|
||||
|
||||
DrawableEllipse::~DrawableEllipse()
|
||||
{
|
||||
if (_scene)
|
||||
{
|
||||
if (_elliItem) _scene->removeItem(_elliItem);
|
||||
if (_sectItem) _scene->removeItem(_sectItem);
|
||||
delete _elliItem;
|
||||
delete _sectItem;
|
||||
}
|
||||
_elliItem = nullptr;
|
||||
_sectItem = nullptr;
|
||||
} /* DrawableEllipse::~DrawableEllipse */
|
||||
|
||||
|
||||
void DrawableEllipse::updateGraphic()
|
||||
{
|
||||
auto length = []( const QPointF & p ) -> qreal { return sqrt(p.x()*p.x()+p.y()*p.y()); };
|
||||
|
||||
qreal mapRotatePhi = _mapView->mapRotation() * MathConst::pi / 180.0;
|
||||
|
||||
qreal sinMap = sin(mapRotatePhi);
|
||||
qreal cosMap = cos(mapRotatePhi);
|
||||
|
||||
qreal sinPhi = _sinRect * cosMap + _cosRect * sinMap;
|
||||
qreal cosPhi = _cosRect * cosMap - _sinRect * sinMap;
|
||||
|
||||
_center.mapToScene(_mapView);
|
||||
|
||||
QPointF mapCenter( _center._mapCoordinate.x(), _center._mapCoordinate.y() );
|
||||
|
||||
RubberbandCoordinate x0y0(_mapView, convert( mapCenter+QPointF(-_radiusX,-_radiusY), _mapView->map()->spatialReference()) );
|
||||
RubberbandCoordinate x1y0(_mapView, convert( mapCenter+QPointF( _radiusX,-_radiusY), _mapView->map()->spatialReference()) );
|
||||
RubberbandCoordinate x0y1(_mapView, convert( mapCenter+QPointF(-_radiusX, _radiusY), _mapView->map()->spatialReference()) );
|
||||
|
||||
qreal width = length(x1y0._sceneCoordinate-x0y0._sceneCoordinate);
|
||||
qreal height = length(x0y1._sceneCoordinate-x0y0._sceneCoordinate);
|
||||
|
||||
makeLineStyle( false, _elliStyle );
|
||||
|
||||
QColor fillColor = transparentFillColor();
|
||||
//fillColor.setAlpha(0);
|
||||
|
||||
QPen pen(_drawColor);
|
||||
pen.setWidth(_lineWidth);
|
||||
|
||||
if (_sectorStart != _sectorEnd)
|
||||
{
|
||||
auto getAngle = [](qreal sinPhi, qreal cosPhi) -> int
|
||||
{
|
||||
qreal phi = acos( cosPhi );
|
||||
if (sinPhi < 0) phi = MathConst::pi_two - phi;
|
||||
return int( (phi * 180.0 / MathConst::pi) * 16);
|
||||
}; // getAngle
|
||||
|
||||
int startAngle = getAngle(_sectorStart.y(), _sectorStart.x());
|
||||
int endAngle = getAngle( _sectorEnd.y(), _sectorEnd.x());
|
||||
int spanAngle = (endAngle > startAngle) ? endAngle-startAngle : 5760-startAngle+endAngle;
|
||||
|
||||
_sectItem -> setRect( -width*0.5, -height*0.5, width, height );
|
||||
_sectItem -> setPen( pen );
|
||||
_sectItem -> setBrush( (fillColor.alpha() > 0) ? QBrush(fillColor) : QBrush() );
|
||||
_sectItem -> setTransform( QTransform( cosPhi, -sinPhi, sinPhi, cosPhi, _center._sceneCoordinate.x(), _center._sceneCoordinate.y() ));
|
||||
_sectItem -> setStartAngle( startAngle );
|
||||
_sectItem -> setSpanAngle( spanAngle );
|
||||
_sectItem -> setVisible( true );
|
||||
|
||||
fillColor.setAlphaF(fillColor.alphaF() * 0.5 );
|
||||
}
|
||||
else _sectItem -> setVisible( false );
|
||||
|
||||
_elliItem -> setRect( -width*0.5, -height*0.5, width, height );
|
||||
_elliItem -> setPen(pen);
|
||||
_elliItem -> setBrush( (fillColor.alpha() > 0) ? QBrush(fillColor) : QBrush() );
|
||||
_elliItem -> setTransform( QTransform( cosPhi, -sinPhi, sinPhi, cosPhi, _center._sceneCoordinate.x(), _center._sceneCoordinate.y() ));
|
||||
|
||||
} /* DrawableEllipse::updateGraphic */
|
||||
|
||||
void DrawableEllipse::adjustCoordinates() { updateGraphic(); }
|
||||
void DrawableEllipse::adjustWindow( const QRectF& ) { updateGraphic(); }
|
||||
|
||||
} } /* namespace SituationMap::RB */
|
||||
Reference in new issue
Block a user