2016-09-27 04:59:06 -05:00
|
|
|
|
|
|
|
#include "RicBoxManipulatorEventHandler.h"
|
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
#include "cafBoxManipulatorPartManager.h"
|
2016-09-27 04:59:06 -05:00
|
|
|
#include "cafEffectGenerator.h"
|
2016-09-29 04:43:47 -05:00
|
|
|
#include "cafViewer.h"
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
#include "cvfCamera.h"
|
|
|
|
#include "cvfDrawableGeo.h"
|
2016-09-27 04:59:06 -05:00
|
|
|
#include "cvfHitItemCollection.h"
|
2016-09-29 04:43:47 -05:00
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
#include "cvfPart.h"
|
|
|
|
#include "cvfRay.h"
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
#include <QDebug>
|
2016-09-27 04:59:06 -05:00
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicBoxManipulatorEventHandler::RicBoxManipulatorEventHandler(caf::Viewer* viewer)
|
2016-09-30 08:10:39 -05:00
|
|
|
: m_viewer(viewer)
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
|
|
|
m_partManager = new caf::BoxManipulatorPartManager;
|
|
|
|
m_model = new cvf::ModelBasicList;
|
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
m_viewer->installEventFilter(this);
|
2016-09-27 04:59:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2016-09-29 04:43:47 -05:00
|
|
|
RicBoxManipulatorEventHandler::~RicBoxManipulatorEventHandler()
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
2016-09-29 04:43:47 -05:00
|
|
|
m_viewer->removeEventFilter(this);
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
// Make sure the model owned by this manipulator is not used anywhere else
|
|
|
|
CVF_ASSERT(m_model->refCount() == 1);
|
2016-09-27 04:59:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2016-09-29 04:43:47 -05:00
|
|
|
void RicBoxManipulatorEventHandler::setOrigin(const cvf::Vec3d& origin)
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
2016-09-29 04:43:47 -05:00
|
|
|
m_partManager->setOrigin(origin);
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
updateParts();
|
|
|
|
emit notifyRedraw();
|
2016-09-27 04:59:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicBoxManipulatorEventHandler::setSize(const cvf::Vec3d& size)
|
|
|
|
{
|
2016-09-29 04:43:47 -05:00
|
|
|
m_partManager->setSize(size);
|
|
|
|
|
|
|
|
updateParts();
|
|
|
|
emit notifyRedraw();
|
2016-09-27 04:59:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Model* RicBoxManipulatorEventHandler::model()
|
|
|
|
{
|
|
|
|
return m_model.p();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RicBoxManipulatorEventHandler::eventFilter(QObject *obj, QEvent* inputEvent)
|
|
|
|
{
|
|
|
|
if (inputEvent->type() == QEvent::MouseButtonPress)
|
|
|
|
{
|
|
|
|
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(inputEvent);
|
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
if (mouseEvent->button() == Qt::LeftButton)
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
2016-09-29 04:43:47 -05:00
|
|
|
cvf::HitItemCollection hitItems;
|
|
|
|
if (m_viewer->rayPick(mouseEvent->x(), mouseEvent->y(), &hitItems))
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
2016-10-03 02:39:18 -05:00
|
|
|
m_partManager->tryToActivateManipulator(hitItems.firstItem());
|
|
|
|
|
|
|
|
if(m_partManager->isManipulatorActive())
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
2016-10-03 02:39:18 -05:00
|
|
|
updateParts();
|
|
|
|
emit notifyRedraw();
|
|
|
|
|
|
|
|
return true;
|
2016-09-27 04:59:06 -05:00
|
|
|
}
|
|
|
|
}
|
2016-09-29 04:43:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (inputEvent->type() == QEvent::MouseMove)
|
|
|
|
{
|
2016-09-30 08:10:39 -05:00
|
|
|
if (m_partManager->isManipulatorActive())
|
2016-09-29 04:43:47 -05:00
|
|
|
{
|
|
|
|
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();
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
cvf::ref<cvf::Ray> ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
2016-09-27 04:59:06 -05:00
|
|
|
{
|
2016-09-30 08:10:39 -05:00
|
|
|
m_partManager->updateManipulatorFromRay(ray.p());
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
updateParts();
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
cvf::Vec3d origin;
|
|
|
|
cvf::Vec3d size;
|
|
|
|
m_partManager->originAndSize(&origin, &size);
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
emit notifyUpdate(origin, size);
|
|
|
|
|
|
|
|
emit notifyRedraw();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-27 04:59:06 -05:00
|
|
|
}
|
|
|
|
}
|
2016-09-29 04:43:47 -05:00
|
|
|
else if (inputEvent->type() == QEvent::MouseButtonRelease)
|
|
|
|
{
|
2016-09-30 08:10:39 -05:00
|
|
|
if (m_partManager->isManipulatorActive())
|
2016-09-29 04:43:47 -05:00
|
|
|
{
|
2016-09-30 08:10:39 -05:00
|
|
|
m_partManager->endManipulator();
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
cvf::Vec3d origin;
|
|
|
|
cvf::Vec3d size;
|
|
|
|
m_partManager->originAndSize(&origin, &size);
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
emit notifyUpdate(origin, size);
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 04:59:06 -05:00
|
|
|
|
2016-09-29 04:43:47 -05:00
|
|
|
return false;
|
2016-09-27 04:59:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicBoxManipulatorEventHandler::updateParts()
|
|
|
|
{
|
|
|
|
m_model->removeAllParts();
|
|
|
|
|
|
|
|
m_partManager->appendPartsToModel(m_model.p());
|
|
|
|
}
|
|
|
|
|