Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Viewer/SituationMap/GraphicalObjects/graphical_object_range.cpp
T

171 lines
4.9 KiB
C++
Executable File

/**
* @RDE_HEADER@
* GraphicalObjectRange
* $Id$
* $HeadURL$
* $Author$
*/
// Own
#include "graphical_object_range.h"
#include <Map/situation_map_utils.h> // operator<<
// ESRI
#include <GraphicsOverlay.h>
#include <PolygonBuilder.h>
#include <MultipartBuilder.h>
#include <ImmutablePartCollection.h>
#include <Polygon.h>
#include <Part.h>
#include <PartCollection.h>
#include <ImmutablePart.h>
#include <Point.h>
#include <Graphic.h>
#include <SpatialReference.h>
// Qt
namespace SituationMap
{
GraphicalObjectRange::GraphicalObjectRange(const Esri::ArcGISRuntime::GeoView *geoView
, Esri::ArcGISRuntime::GraphicsOverlay *graphicsLayer
, const QString &debugInfo
, const UniqueMapId &uniqueMapId)
: BaseClass(geoView, graphicsLayer, debugInfo, uniqueMapId)
, m_logger(getLogger("GraphicalObjectRange"))
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START, debugInfo='" << m_debugInfo << "'";
TRACE_LOG(m_logger) << LOGFUNCTION << " END, debugInfo='" << m_debugInfo << "'";
}
GraphicalObjectRange::~GraphicalObjectRange()
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START, debugInfo='" << m_debugInfo << "'";
TRACE_LOG(m_logger) << LOGFUNCTION << " END, debugInfo='" << m_debugInfo << "'";
}
int GraphicalObjectRange::range() const
{
return m_range.value();
}
float GraphicalObjectRange::angle() const
{
return m_angleDegree.value();
}
void GraphicalObjectRange::setRange(int range, float angleDegree)
{
m_angleDegree = angleDegree;
m_range = range;
}
bool GraphicalObjectRange::updateViewImpl()
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START, debugInfo='" << m_debugInfo << "'";
EllipseParameters ellipsePara;
ellipsePara.setLengthX(m_range.value());
ellipsePara.setLengthY(m_range.value());
ellipsePara.setDirectionDegree(m_angleDegree.value()) ;
ellipsePara.setDirectionDegree((m_angleDegree.value() * -1) + 90);
ellipsePara.setMaxSegmentLength(10);
ellipsePara.setMaxPointCount(30); // limit to 30 to reduce the number of vertices. If to high, keep performance impact to 3D in mind!!!
this->setEllipseParameters(ellipsePara);
bool success = BaseClass::updateViewImpl();
TRACE_LOG(m_logger) << LOGFUNCTION << " END, debugInfo='" << m_debugInfo << "'"
<< " drawOrder = " << m_graphic->zIndex()
<< " success = " << success;
return success;
}
bool GraphicalObjectRange::createEllipse(Esri::ArcGISRuntime::Polygon &ellipse)
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START, debugInfo='" << m_debugInfo << "'"
<< " range=" << m_range
<< " angle=" << m_angleDegree;
bool success = BaseClass::createEllipse(ellipse);
if (success &&
!ellipse.isEmpty() &&
!ellipse.parts().isEmpty() &&
!ellipse.parts().part(0).isEmpty())
{
const Point3D &center = this->origin();
// 'modify' ellipe (by copying, adding and re-assigning):
// part 0 - ellipse
// we have to copy the point since the ellipse does not contain the z value anymore :-(
Esri::ArcGISRuntime::Part partCircle(ellipse.spatialReference());
const Esri::ArcGISRuntime::ImmutablePart &im = ellipse.parts().part(0);
for (int i = 0; i < im.pointCount(); ++i)
{
const Esri::ArcGISRuntime::Point &p = im.point(i);
partCircle.addPoint(Esri::ArcGISRuntime::Point(p.x(),
p.y(),
center.z() // p.z()
));
}
// part 1 - line to center
Esri::ArcGISRuntime::Part partLine(ellipse.spatialReference());
partLine.addPoint(im.startPoint().x(),
im.startPoint().y(),
center.z());
partLine.addPoint(center.x(),
center.y(),
center.z());
// a polyGON requiree to have at least 3 points:
partLine.addPoint(center.x(),
center.y(),
center.z()+0.01);
// combine them to a PartCollection:
Esri::ArcGISRuntime::PartCollection pc(ellipse.spatialReference());
pc.addPart(&partCircle);
pc.addPart(&partLine);
Esri::ArcGISRuntime::PolygonBuilder builder(ellipse.spatialReference());
builder.setParts(&pc);
ellipse = builder.toPolygon();
success = true;
}
else
ERROR_LOG(m_logger) << LOGFUNCTION << " debugInfo='" << m_debugInfo << "'";
return success;
}
//-----------------------------------------------------------------------------
// output operator:
//-----------------------------------------------------------------------------
std::ostream &operator<<(std::ostream &stream,
const GraphicalObjectRange &value)
{
stream << value.toString();
return stream;
}
} // namespace SituationMap