2018-08-16 08:38:34 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2013- Statoil ASA
|
|
|
|
// Copyright (C) 2013- Ceetron Solutions AS
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicPointTangentManipulator.h"
|
|
|
|
|
2018-11-27 04:25:25 -06:00
|
|
|
#include "RicPointTangentManipulatorPartMgr.h"
|
|
|
|
#include "RivPartPriority.h"
|
|
|
|
|
2018-08-16 08:38:34 -05:00
|
|
|
#include "cafViewer.h"
|
2018-11-27 04:25:25 -06:00
|
|
|
#include "cafPdmUiCommandSystemProxy.h"
|
2018-08-16 08:38:34 -05:00
|
|
|
|
|
|
|
#include "cvfCamera.h"
|
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfHitItemCollection.h"
|
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
#include "cvfPart.h"
|
|
|
|
#include "cvfRay.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicPointTangentManipulator::RicPointTangentManipulator(caf::Viewer* viewer)
|
|
|
|
: m_viewer(viewer)
|
|
|
|
{
|
|
|
|
m_partManager = new RicPointTangentManipulatorPartMgr;
|
|
|
|
|
|
|
|
m_viewer->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicPointTangentManipulator::~RicPointTangentManipulator()
|
|
|
|
{
|
|
|
|
if (m_viewer) m_viewer->removeEventFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicPointTangentManipulator::setOrigin(const cvf::Vec3d& origin)
|
|
|
|
{
|
|
|
|
m_partManager->setOrigin(origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicPointTangentManipulator::setTangent(const cvf::Vec3d& tangent)
|
|
|
|
{
|
|
|
|
m_partManager->setTangent(tangent);
|
|
|
|
}
|
|
|
|
|
2018-08-17 03:35:42 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicPointTangentManipulator::setHandleSize(double handleSize)
|
|
|
|
{
|
|
|
|
m_partManager->setHandleSize(handleSize);
|
|
|
|
}
|
|
|
|
|
2018-08-16 08:38:34 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicPointTangentManipulator::appendPartsToModel(cvf::ModelBasicList* model)
|
|
|
|
{
|
|
|
|
m_partManager->appendPartsToModel(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicPointTangentManipulator::eventFilter(QObject *obj, QEvent* inputEvent)
|
|
|
|
{
|
|
|
|
if (inputEvent->type() == QEvent::MouseButtonPress)
|
|
|
|
{
|
|
|
|
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(inputEvent);
|
|
|
|
|
|
|
|
if (mouseEvent->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
cvf::HitItemCollection hitItems;
|
|
|
|
if (m_viewer->rayPick(mouseEvent->x(), mouseEvent->y(), &hitItems))
|
|
|
|
{
|
|
|
|
m_partManager->tryToActivateManipulator(hitItems.firstItem());
|
|
|
|
|
|
|
|
if(m_partManager->isManipulatorActive())
|
|
|
|
{
|
2018-08-31 08:13:58 -05:00
|
|
|
emit notifySelected();
|
2018-08-16 08:38:34 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (inputEvent->type() == QEvent::MouseMove)
|
|
|
|
{
|
|
|
|
if (m_partManager->isManipulatorActive())
|
|
|
|
{
|
|
|
|
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(inputEvent);
|
|
|
|
|
|
|
|
//qDebug() << "Inside mouse move";
|
|
|
|
//qDebug() << mouseEvent->pos();
|
|
|
|
|
|
|
|
int translatedMousePosX = mouseEvent->pos().x();
|
|
|
|
int translatedMousePosY = m_viewer->height() - mouseEvent->pos().y();
|
|
|
|
|
|
|
|
cvf::ref<cvf::Ray> ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
2018-10-02 08:48:28 -05:00
|
|
|
if (!ray.isNull())
|
2018-08-16 08:38:34 -05:00
|
|
|
{
|
|
|
|
m_partManager->updateManipulatorFromRay(ray.p());
|
|
|
|
|
|
|
|
cvf::Vec3d origin;
|
|
|
|
cvf::Vec3d tangent;
|
|
|
|
m_partManager->originAndTangent(&origin, &tangent);
|
|
|
|
|
|
|
|
emit notifyUpdate(origin, tangent);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (inputEvent->type() == QEvent::MouseButtonRelease)
|
|
|
|
{
|
|
|
|
if (m_partManager->isManipulatorActive())
|
|
|
|
{
|
|
|
|
m_partManager->endManipulator();
|
|
|
|
|
|
|
|
cvf::Vec3d origin;
|
|
|
|
cvf::Vec3d tangent;
|
|
|
|
m_partManager->originAndTangent(&origin, &tangent);
|
|
|
|
|
|
|
|
emit notifyUpdate(origin, tangent);
|
2018-09-12 06:18:48 -05:00
|
|
|
emit notifyDragFinished();
|
2018-08-16 08:38:34 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|