mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#884 Improved interface to BoxManipulatorPartManager
This commit is contained in:
parent
caf6a5dcf2
commit
58acd22afa
@ -19,8 +19,7 @@
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicBoxManipulatorEventHandler::RicBoxManipulatorEventHandler(caf::Viewer* viewer)
|
||||
: m_viewer(viewer),
|
||||
m_currentPartIndex(cvf::UNDEFINED_SIZE_T)
|
||||
: m_viewer(viewer)
|
||||
{
|
||||
m_partManager = new caf::BoxManipulatorPartManager;
|
||||
m_model = new cvf::ModelBasicList;
|
||||
@ -85,9 +84,9 @@ bool RicBoxManipulatorEventHandler::eventFilter(QObject *obj, QEvent* inputEvent
|
||||
{
|
||||
if (hitItems.firstItem() && hitItems.firstItem()->part())
|
||||
{
|
||||
m_currentPartIndex = m_partManager->partIndexFromSourceInfo(hitItems.firstItem()->part(), hitItems.firstItem()->intersectionPoint());
|
||||
m_partManager->activateManipulator(hitItems.firstItem()->part(), hitItems.firstItem()->intersectionPoint());
|
||||
|
||||
if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T)
|
||||
if (m_partManager->isManipulatorActive())
|
||||
{
|
||||
updateParts();
|
||||
emit notifyRedraw();
|
||||
@ -100,7 +99,7 @@ bool RicBoxManipulatorEventHandler::eventFilter(QObject *obj, QEvent* inputEvent
|
||||
}
|
||||
else if (inputEvent->type() == QEvent::MouseMove)
|
||||
{
|
||||
if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T)
|
||||
if (m_partManager->isManipulatorActive())
|
||||
{
|
||||
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(inputEvent);
|
||||
|
||||
@ -112,7 +111,7 @@ bool RicBoxManipulatorEventHandler::eventFilter(QObject *obj, QEvent* inputEvent
|
||||
|
||||
cvf::ref<cvf::Ray> ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
||||
{
|
||||
m_partManager->updateFromPartIndexAndRay(m_currentPartIndex, ray.p());
|
||||
m_partManager->updateManipulatorFromRay(ray.p());
|
||||
|
||||
updateParts();
|
||||
|
||||
@ -130,9 +129,9 @@ bool RicBoxManipulatorEventHandler::eventFilter(QObject *obj, QEvent* inputEvent
|
||||
}
|
||||
else if (inputEvent->type() == QEvent::MouseButtonRelease)
|
||||
{
|
||||
if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T)
|
||||
if (m_partManager->isManipulatorActive())
|
||||
{
|
||||
m_currentPartIndex = cvf::UNDEFINED_SIZE_T;
|
||||
m_partManager->endManipulator();
|
||||
|
||||
cvf::Vec3d origin;
|
||||
cvf::Vec3d size;
|
||||
|
@ -55,8 +55,6 @@ private:
|
||||
cvf::ref<cvf::ModelBasicList> m_model;
|
||||
QPointer<caf::Viewer> m_viewer;
|
||||
|
||||
size_t m_currentPartIndex;
|
||||
|
||||
cvf::ref<caf::BoxManipulatorPartManager> m_partManager;
|
||||
};
|
||||
|
||||
|
@ -23,7 +23,9 @@ namespace caf {
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
BoxManipulatorPartManager::BoxManipulatorPartManager() : m_sizeOnStartManipulation(cvf::Vec3d::UNDEFINED)
|
||||
BoxManipulatorPartManager::BoxManipulatorPartManager()
|
||||
: m_sizeOnStartManipulation(cvf::Vec3d::UNDEFINED),
|
||||
m_currentHandleIndex(cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
}
|
||||
|
||||
@ -56,6 +58,14 @@ void BoxManipulatorPartManager::originAndSize(cvf::Vec3d* origin, cvf::Vec3d* si
|
||||
*size = m_size;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool BoxManipulatorPartManager::isManipulatorActive() const
|
||||
{
|
||||
return m_currentHandleIndex != cvf::UNDEFINED_SIZE_T;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -78,15 +88,17 @@ void BoxManipulatorPartManager::appendPartsToModel(cvf::ModelBasicList* model)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t BoxManipulatorPartManager::partIndexFromSourceInfo(const cvf::Part* candidatePart, const cvf::Vec3d& intersectionPoint)
|
||||
void BoxManipulatorPartManager::activateManipulator(const cvf::Part* candidatePart, const cvf::Vec3d& intersectionPoint)
|
||||
{
|
||||
if (!candidatePart) return cvf::UNDEFINED_SIZE_T;
|
||||
endManipulator();
|
||||
|
||||
if (!candidatePart) return;
|
||||
|
||||
const cvf::Object* siConstObj = candidatePart->sourceInfo();
|
||||
cvf::Object* siObj = const_cast<cvf::Object*>(siConstObj);
|
||||
|
||||
BoxManipulatorSourceInfo* candidateSourceInfo = dynamic_cast<BoxManipulatorSourceInfo*>(siObj);
|
||||
if (!candidateSourceInfo) return cvf::UNDEFINED_SIZE_T;
|
||||
if (!candidateSourceInfo) return;
|
||||
|
||||
for (size_t i = 0; i < m_handleParts.size(); i++)
|
||||
{
|
||||
@ -98,21 +110,20 @@ size_t BoxManipulatorPartManager::partIndexFromSourceInfo(const cvf::Part* candi
|
||||
{
|
||||
m_initialPickPoint = intersectionPoint;
|
||||
m_sizeOnStartManipulation = m_size;
|
||||
|
||||
return i;
|
||||
m_currentHandleIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return cvf::UNDEFINED_SIZE_T;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::updateFromPartIndexAndRay(size_t partIndex, const cvf::Ray* ray)
|
||||
void BoxManipulatorPartManager::updateManipulatorFromRay(const cvf::Ray* ray)
|
||||
{
|
||||
BoxFace face = m_handleIds[partIndex].first;
|
||||
if (!isManipulatorActive()) return;
|
||||
|
||||
BoxFace face = m_handleIds[m_currentHandleIndex].first;
|
||||
cvf::Vec3d faceDir = normalFromFace(face);
|
||||
|
||||
cvf::Vec3d closestPoint1;
|
||||
@ -177,6 +188,14 @@ void BoxManipulatorPartManager::updateFromPartIndexAndRay(size_t partIndex, cons
|
||||
setSize(newSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::endManipulator()
|
||||
{
|
||||
m_currentHandleIndex = cvf::UNDEFINED_SIZE_T;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -233,7 +252,7 @@ void BoxManipulatorPartManager::createAllHandleParts()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void BoxManipulatorPartManager::createCubeFaceHandlePart(BoxFace face, cvf::Vec3f p1, cvf::Vec3f p2, cvf::Vec3f p3, cvf::Vec3f p4)
|
||||
{
|
||||
float handleSize = m_sizeOnStartManipulation.length() * 0.04;
|
||||
float handleSize = static_cast<float>(m_sizeOnStartManipulation.length() * 0.04);
|
||||
|
||||
Vec3f center = (p1 + p2 + p3 + p4) / 4.0f;
|
||||
|
||||
@ -245,12 +264,12 @@ void BoxManipulatorPartManager::createCubeFaceHandlePart(BoxFace face, cvf::Vec3
|
||||
Vec3f v = nv * handleSize;
|
||||
Vec3f w = nw * handleSize;
|
||||
|
||||
Vec3f pi1 = center - u / 2.0 - v / 2.0 + w*0.1;
|
||||
Vec3f pi1 = center - u / 2.0f - v / 2.0f + w*0.1f;
|
||||
|
||||
Vec3f pi2 = pi1 + u;
|
||||
Vec3f pi3 = pi2 + v;
|
||||
Vec3f pi4 = pi1 + v;
|
||||
Vec3f pi5 = center + w * 0.3;
|
||||
Vec3f pi5 = center + w * 0.3f;
|
||||
|
||||
ref<DrawableGeo> geo = createHandleGeo(pi1, pi2, pi3, pi4, pi5);
|
||||
|
||||
|
@ -53,8 +53,10 @@ public:
|
||||
void setSize(const cvf::Vec3d& size);
|
||||
void originAndSize(cvf::Vec3d* origin, cvf::Vec3d* size);
|
||||
|
||||
size_t partIndexFromSourceInfo(const cvf::Part* part, const cvf::Vec3d& intersectionPoint);
|
||||
void updateFromPartIndexAndRay(size_t partIndex, const cvf::Ray* ray);
|
||||
bool isManipulatorActive() const;
|
||||
void activateManipulator(const cvf::Part* part, const cvf::Vec3d& intersectionPoint);
|
||||
void updateManipulatorFromRay(const cvf::Ray* ray);
|
||||
void endManipulator();
|
||||
|
||||
void appendPartsToModel(cvf::ModelBasicList* model);
|
||||
|
||||
@ -80,17 +82,18 @@ private:
|
||||
cvf::Vec3d* closestPoint1, cvf::Vec3d* closestPoint2);
|
||||
|
||||
private:
|
||||
//cvf::Collection<cvf::DrawableGeo> m_handleGeos; // These arrays have the same length
|
||||
std::vector< std::pair<BoxFace, HandleType> > m_handleIds; // These arrays have the same length
|
||||
cvf::Collection<cvf::Part> m_handleParts; // These arrays have the same length
|
||||
std::vector< std::pair<BoxFace, HandleType> > m_handleIds; // These arrays have the same length
|
||||
cvf::Collection<cvf::Part> m_handleParts; // These arrays have the same length
|
||||
|
||||
cvf::ref<cvf::Part> m_boundingBoxPart;
|
||||
cvf::ref<cvf::Part> m_boundingBoxPart;
|
||||
|
||||
cvf::Vec3d m_origin;
|
||||
cvf::Vec3d m_size;
|
||||
|
||||
cvf::Vec3d m_initialPickPoint;
|
||||
cvf::Vec3d m_sizeOnStartManipulation;
|
||||
|
||||
size_t m_currentHandleIndex;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user