312 lines
9.9 KiB
C++
Executable File
312 lines
9.9 KiB
C++
Executable File
|
|
/**
|
|
**
|
|
** @RDE_HEADER@
|
|
** Implementationof rubberband class to define point feature geoemtry
|
|
** $Id$
|
|
** $HeadURL$
|
|
** $Author$
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Hardware-Environment: Intel-PC
|
|
** Software-Environment: Windows 7, Qt 5.4. ArcGIS 10.2.5
|
|
**
|
|
** Language ........: C++ 11
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Author ...........: Jörg Turla, SPD G, Tel. 3132
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
**
|
|
** Notes .........:
|
|
**
|
|
** 27.03.2015, JT : First edition for use with Qt5
|
|
**
|
|
** -----------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "rubberband_point_feature.h"
|
|
#include "rubberband_point_handle.h"
|
|
#include "rubberband_drawable.h"
|
|
|
|
#include "rubberband_internal.h"
|
|
#include "rubberband_base_internal.h"
|
|
|
|
#include <arcgis/Map.h>
|
|
#include <arcgis/MapGraphicsView.h>
|
|
|
|
|
|
namespace SituationMap { namespace RB
|
|
{
|
|
|
|
RubberbandPointFeature::RubberbandPointFeature( SituationMap::Map * map, QObject * parent, bool isActive )
|
|
: Rubberband(map,parent,isActive), _maximalPointCount(1)
|
|
{
|
|
} /* RubberbandPointFeature::RubberbandPointFeature */
|
|
|
|
|
|
RubberbandPointFeature::~RubberbandPointFeature()
|
|
{
|
|
} /* RubberbandPointFeature::~RubberbandPointFeature */
|
|
|
|
|
|
QVector<QPointF> RubberbandPointFeature::coordinateVector( CoordinateSystem cs ) const
|
|
{
|
|
QVector<QPointF> coordinateVector;
|
|
coordinateVector.reserve(_internal->_handleList.size());
|
|
|
|
for (auto handle : qAsConst(_internal->_handleList))
|
|
{
|
|
RubberbandPointHandle * handlePointPtr = dynamic_cast<RubberbandPointHandle*>(handle.get());
|
|
|
|
coordinateVector.push_back(projectCoordinateFromMap( cs, handlePointPtr->getCoordinate()._mapCoordinate ));
|
|
}
|
|
return coordinateVector;
|
|
} /* RubberbandPointFeature::coordinateVector */
|
|
|
|
QVector<QPointF> RubberbandPointFeature::coordinateVectorPixel() const
|
|
{
|
|
QVector<QPointF> coordinateVector;
|
|
coordinateVector.reserve(_internal->_handleList.size());
|
|
|
|
for (auto handle : qAsConst(_internal->_handleList))
|
|
{
|
|
RubberbandPointHandle *handlePointPtr = dynamic_cast<RubberbandPointHandle*>(handle.get());
|
|
coordinateVector.push_back(handlePointPtr->getPixelCoordinate());
|
|
}
|
|
return coordinateVector;
|
|
}
|
|
|
|
|
|
QPointF RubberbandPointFeature::singleCoordinate(unsigned int idx, CoordinateSystem cs ) const
|
|
{
|
|
if (idx < (unsigned int) _internal->_handleList.size())
|
|
{
|
|
const RubberbandPointHandle * handle = dynamic_cast<const RubberbandPointHandle*>(_internal->_handleList[idx].get());
|
|
|
|
return projectCoordinateFromMap( cs, handle->getCoordinate()._mapCoordinate );
|
|
}
|
|
return QPointF();
|
|
} /* RubberbandPointFeature::singleCoordinate */
|
|
|
|
|
|
void RubberbandPointFeature::setCoordinateVector(const QVector<QPointF> & coordinateVector, CoordinateSystem cs )
|
|
{
|
|
_internal->_handleList.clear();
|
|
|
|
for (auto p : coordinateVector)
|
|
{
|
|
const QPointF &mapPos = projectCoordinateToMap( cs, p );
|
|
|
|
RubberbandPointHandle * handlePointPtr = new RubberbandPointHandle( _internal->_mapView
|
|
, _internal->_mapScene
|
|
, Esri::ArcGISRuntime::Point(mapPos.x(),mapPos.y(),Rubberband::_internal->_mapView->map()->spatialReference()) );
|
|
_internal->_handleList.append( SituationMap::RefPointer<RubberbandHandle>(handlePointPtr) );
|
|
}
|
|
update();
|
|
} /* RubberbandPointFeature::setCoordinateVector */
|
|
|
|
|
|
bool RubberbandPointFeature::selectAction( AbstractEventDispatcher * , int x, int y )
|
|
{
|
|
if (rubberbandIsAlive())
|
|
{
|
|
bool eventHandled = false;
|
|
QPointF scenePos(pixel2ScenePosition(x,y));
|
|
|
|
if (_baseInternal->buttonProxyActive(scenePos)) return false;
|
|
|
|
_baseInternal->_lastClickPosition = scenePos;
|
|
|
|
RubberbandHandle * handlePtr = pickHandle(x,y);
|
|
if (handlePtr)
|
|
{
|
|
handlePtr->setSelection();
|
|
enableSelectedState();
|
|
eventHandled = true;
|
|
}
|
|
|
|
if (!isEnabledSelectedState())
|
|
{
|
|
if (isEnabledConstructionState())
|
|
{
|
|
if (!buttonProxyActive(scenePos))
|
|
{
|
|
RubberbandPointHandle * handlePtr = new RubberbandPointHandle( _internal->_mapView, _internal->_mapScene, scenePos );
|
|
|
|
_internal->_handleList.append( SituationMap::RefPointer<RubberbandHandle>(handlePtr) );
|
|
handlePtr->setSelection();
|
|
enableSelectedState();
|
|
eventHandled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (eventHandled)
|
|
{
|
|
update();
|
|
deactivateButtons();
|
|
}
|
|
|
|
|
|
return eventHandled;
|
|
}
|
|
return false;
|
|
} /* RubberbandPointFeature::selectAction */
|
|
|
|
|
|
|
|
bool RubberbandPointFeature::setCoordinateAction( AbstractEventDispatcher * causer, int x, int y )
|
|
{
|
|
if ((rubberbandIsAlive()) && (_internal->_mapView) && (_internal->_mapScene))
|
|
{
|
|
bool eventHandled = false;
|
|
QPointF scenePos(pixel2ScenePosition(x,y));
|
|
|
|
Rubberband::_internal->_lastClickPosition = scenePos;
|
|
|
|
if (isEnabledSelectedState())
|
|
{
|
|
if (_baseInternal->buttonProxyActive(scenePos)) return false;
|
|
for (auto handle : qAsConst(_internal->_handleList))
|
|
{
|
|
RubberbandPointHandle * handlePointPtr = dynamic_cast<RubberbandPointHandle*>(handle.get());
|
|
if ((handlePointPtr) && (handlePointPtr->isSelected()))
|
|
{
|
|
handlePointPtr->setSelection(false);
|
|
handlePointPtr->moveCoordinate( scenePos - _baseInternal->_lastClickPosition );
|
|
eventHandled = true;
|
|
}
|
|
}
|
|
disenableSelectedState();
|
|
disenableMultiSelectedState();
|
|
}
|
|
else if (_baseInternal->buttonProxyActive(scenePos)) return false;
|
|
|
|
if (eventHandled) update();
|
|
|
|
if ((isEnabledConstructionState()) && (_internal->_handleList.size() >= static_cast<int>(_maximalPointCount)))
|
|
{
|
|
completeStateAction( causer, x, y );
|
|
eventHandled = true;
|
|
}
|
|
return eventHandled;
|
|
}
|
|
return false;
|
|
} /* RubberbandPointFeature::setCoordinateAction */
|
|
|
|
|
|
bool RubberbandPointFeature::moveAction( AbstractEventDispatcher*, int x, int y )
|
|
{
|
|
adjustConnectedPreviewPixmap(x,y);
|
|
|
|
if (rubberbandIsAlive())
|
|
{
|
|
if (!isEnabledMultiSelectedState()) deSelectHandles();
|
|
|
|
RubberbandHandle * handlePtr = pickHandle(x,y);
|
|
if (handlePtr)
|
|
{
|
|
handlePtr->setSelection();
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
} /* RubberbandPointFeature::moveAction */
|
|
|
|
|
|
bool RubberbandPointFeature::movePickedAction( AbstractEventDispatcher*, int x, int y )
|
|
{
|
|
adjustConnectedPreviewPixmap(x,y);
|
|
|
|
if ((rubberbandIsAlive()) && (_internal->_mapView) && (_internal->_mapScene))
|
|
{
|
|
if (isEnabledSelectedState())
|
|
{
|
|
QPointF scenePos(pixel2ScenePosition(x,y));
|
|
QPointF deltaMove(scenePos-_baseInternal->_lastClickPosition);
|
|
|
|
_baseInternal->_lastClickPosition = scenePos;
|
|
|
|
bool eventHandled = false;
|
|
|
|
for (auto handle : qAsConst(_internal->_handleList))
|
|
{
|
|
RubberbandPointHandle * handlePointPtr = dynamic_cast<RubberbandPointHandle*>(handle.get());
|
|
if ((handlePointPtr) && (handlePointPtr->isSelected()))
|
|
{
|
|
handlePointPtr->moveCoordinate( deltaMove );
|
|
eventHandled = true;
|
|
}
|
|
}
|
|
if (eventHandled) update();
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
} /* RubberbandPointFeature::movePickedAction */
|
|
|
|
|
|
bool RubberbandPointFeature::contextMenuAction( AbstractEventDispatcher*, int , int )
|
|
{
|
|
return rubberbandIsAlive();
|
|
} /* RubberbandPointFeature::contextMenuAction */
|
|
|
|
|
|
bool RubberbandPointFeature::completeStateAction( AbstractEventDispatcher * causer, int x, int y )
|
|
{
|
|
if (!_internal->_handleList.empty())
|
|
{
|
|
return applyAndEndAction(causer,x,y);
|
|
}
|
|
return false;
|
|
} /* RubberbandPointFeature::completeStateAction */
|
|
|
|
|
|
bool RubberbandPointFeature::undoAction( AbstractEventDispatcher*, int , int )
|
|
{
|
|
if (rubberbandIsAlive())
|
|
{
|
|
if (!_internal->_handleList.empty())
|
|
{
|
|
_internal->_handleList.pop_back();
|
|
update();
|
|
activateButtons();
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
} /* RubberbandPointFeature::undoAction */
|
|
|
|
|
|
bool RubberbandPointFeature::deleteAction(AbstractEventDispatcher*, int x, int y)
|
|
{
|
|
if ((rubberbandIsAlive()) && (_internal->_mapView) && (_internal->_mapScene))
|
|
{
|
|
if ((_internal->_handleList.size() > 1) && (isEnabledSelectedState()))
|
|
{
|
|
QPointF scenePosition = pixel2ScenePosition(x,y);
|
|
QList<SituationMap::RefPointer<RubberbandHandle>>::iterator handleIter = _internal->_handleList.begin();
|
|
|
|
while (handleIter != _internal->_handleList.end())
|
|
{
|
|
if (handleIter->get()->isPositionInside(scenePosition))
|
|
{
|
|
handleIter = _internal->_handleList.erase(handleIter);
|
|
continue;
|
|
}
|
|
++handleIter;
|
|
}
|
|
update();
|
|
activateButtons();
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
} /* RubberbandPointFeature::deleteAction */
|
|
|
|
|
|
} } /* namespace SituationMap::RB */
|