2018-12-19 07:41:17 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-09 08:21:38 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2019-01-02 08:04:05 -06:00
|
|
|
//
|
2018-12-19 07:41:17 -06:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2019-01-02 08:04:05 -06:00
|
|
|
//
|
2018-12-19 07:41:17 -06:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2019-01-02 08:04:05 -06:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-12-19 07:41:17 -06:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicMeasurementPickEventHandler.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
2019-03-22 09:55:51 -05:00
|
|
|
#include "RiuViewer.h"
|
2019-04-26 06:42:37 -05:00
|
|
|
#include "RiuViewerCommands.h"
|
2018-12-19 07:41:17 -06:00
|
|
|
|
2019-01-02 08:04:05 -06:00
|
|
|
#include "Rim3dView.h"
|
2019-11-26 04:35:21 -06:00
|
|
|
#include "RimExtrudedCurveIntersection.h"
|
2019-11-26 06:56:02 -06:00
|
|
|
#include "RimGridView.h"
|
2018-12-19 07:41:17 -06:00
|
|
|
#include "RimMeasurement.h"
|
2019-01-02 08:04:05 -06:00
|
|
|
#include "RimProject.h"
|
2018-12-19 07:41:17 -06:00
|
|
|
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
|
|
|
#include "cafSelectionManager.h"
|
|
|
|
|
2019-01-03 04:34:50 -06:00
|
|
|
#include "RivPartPriority.h"
|
|
|
|
|
|
|
|
#include "cvfPart.h"
|
|
|
|
|
2018-12-19 07:41:17 -06:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-02 08:04:05 -06:00
|
|
|
///
|
2018-12-19 07:41:17 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicMeasurementPickEventHandler* RicMeasurementPickEventHandler::instance()
|
|
|
|
{
|
|
|
|
static RicMeasurementPickEventHandler* singleton = new RicMeasurementPickEventHandler;
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
2019-02-06 06:20:33 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-02-12 01:21:01 -06:00
|
|
|
void RicMeasurementPickEventHandler::registerAsPickEventHandler()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RiuViewer::setHoverCursor( Qt::CrossCursor );
|
|
|
|
RiuViewerCommands::setPickEventHandler( RicMeasurementPickEventHandler::instance() );
|
2019-02-12 01:21:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicMeasurementPickEventHandler::unregisterAsPickEventHandler()
|
|
|
|
{
|
2019-03-22 09:55:51 -05:00
|
|
|
RiuViewer::clearHoverCursor();
|
2019-09-06 03:40:57 -05:00
|
|
|
RiuViewerCommands::removePickEventHandlerIfActive( RicMeasurementPickEventHandler::instance() );
|
2019-02-12 01:21:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-02-06 06:20:33 -06:00
|
|
|
RicMeasurementPickEventHandler::RicMeasurementPickEventHandler()
|
2019-09-06 03:40:57 -05:00
|
|
|
: m_polyLineModeEnabled( false )
|
2019-04-26 06:42:37 -05:00
|
|
|
{
|
|
|
|
}
|
2019-03-26 08:05:05 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicMeasurementPickEventHandler::enablePolyLineMode( bool polyLineModeEnabled )
|
2019-03-26 08:05:05 -05:00
|
|
|
{
|
|
|
|
m_polyLineModeEnabled = polyLineModeEnabled;
|
|
|
|
}
|
|
|
|
|
2018-12-19 07:41:17 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-01-02 08:04:05 -06:00
|
|
|
///
|
2018-12-19 07:41:17 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
bool RicMeasurementPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eventObject )
|
2018-12-19 07:41:17 -06:00
|
|
|
{
|
2019-10-28 08:08:15 -05:00
|
|
|
RimMeasurement* measurement = RiaApplication::instance()->project()->measurement();
|
2018-12-19 07:41:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( measurement && measurement->measurementMode() )
|
2018-12-19 07:41:17 -06:00
|
|
|
{
|
2019-01-03 04:34:50 -06:00
|
|
|
const RiuPickItemInfo* firstGeometryPickInfo = nullptr;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const auto& info : eventObject.m_pickItemInfos )
|
2019-01-03 04:34:50 -06:00
|
|
|
{
|
|
|
|
auto partCandidate = info.pickedPart();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !firstGeometryPickInfo && partCandidate->priority() != RivPartPriority::PartType::Text )
|
2019-01-03 04:34:50 -06:00
|
|
|
{
|
|
|
|
firstGeometryPickInfo = &info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-28 08:08:15 -05:00
|
|
|
Rim3dView* rimView = dynamic_cast<Rim3dView*>( RiaApplication::instance()->activeMainOrComparisonGridView() );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( firstGeometryPickInfo && rimView )
|
2019-01-03 04:34:50 -06:00
|
|
|
{
|
|
|
|
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
|
2018-12-19 07:41:17 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Vec3d domainCoord = transForm->transformToDomainCoord( firstGeometryPickInfo->globalPickedPoint() );
|
2019-01-02 08:04:05 -06:00
|
|
|
|
2019-01-03 04:34:50 -06:00
|
|
|
bool isControlButtonDown = QApplication::keyboardModifiers() & Qt::ControlModifier;
|
|
|
|
|
2019-03-26 08:05:05 -05:00
|
|
|
bool isPolyLineMode = m_polyLineModeEnabled != isControlButtonDown;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !isPolyLineMode )
|
2019-01-02 08:04:05 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( measurement->pointsInDomainCoords().size() > 1 )
|
2019-01-03 04:34:50 -06:00
|
|
|
{
|
|
|
|
measurement->removeAllPoints();
|
|
|
|
}
|
2019-01-02 08:04:05 -06:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
measurement->addPointInDomainCoords( domainCoord );
|
2019-01-03 04:34:50 -06:00
|
|
|
}
|
2018-12-19 07:41:17 -06:00
|
|
|
|
2018-12-20 05:34:17 -06:00
|
|
|
// Further Ui processing is stopped when true is returned
|
|
|
|
return true;
|
2018-12-19 07:41:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:13:38 -06:00
|
|
|
void RicMeasurementPickEventHandler::notifyUnregistered()
|
|
|
|
{
|
|
|
|
}
|