mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4999 Refactoring point target manipulator part manager preparing for fix
This commit is contained in:
parent
3aa4e37383
commit
25b97c9cca
@ -46,7 +46,7 @@
|
||||
RicPointTangentManipulatorPartMgr::RicPointTangentManipulatorPartMgr()
|
||||
: m_tangentOnStartManipulation( cvf::Vec3d::UNDEFINED )
|
||||
, m_originOnStartManipulation( cvf::Vec3d::UNDEFINED )
|
||||
, m_currentHandleIndex( cvf::UNDEFINED_SIZE_T )
|
||||
, m_activeHandle( NONE )
|
||||
, m_handleSize( 1.0 )
|
||||
{
|
||||
}
|
||||
@ -104,7 +104,7 @@ void RicPointTangentManipulatorPartMgr::originAndTangent( cvf::Vec3d* origin, cv
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicPointTangentManipulatorPartMgr::isManipulatorActive() const
|
||||
{
|
||||
return m_currentHandleIndex != cvf::UNDEFINED_SIZE_T;
|
||||
return m_activeHandle != NONE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -112,14 +112,14 @@ bool RicPointTangentManipulatorPartMgr::isManipulatorActive() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicPointTangentManipulatorPartMgr::appendPartsToModel( cvf::ModelBasicList* model )
|
||||
{
|
||||
if ( !m_handleParts.size() )
|
||||
if ( m_handleParts.empty() )
|
||||
{
|
||||
recreateAllGeometryAndParts();
|
||||
}
|
||||
|
||||
for ( size_t i = 0; i < m_handleParts.size(); i++ )
|
||||
for ( auto& idPartIt : m_handleParts )
|
||||
{
|
||||
model->addPart( m_handleParts.at( i ) );
|
||||
model->addPart( idPartIt.second.p() );
|
||||
}
|
||||
|
||||
for ( auto activeModePart : m_activeDragModeParts )
|
||||
@ -142,14 +142,14 @@ void RicPointTangentManipulatorPartMgr::tryToActivateManipulator( const cvf::Hit
|
||||
|
||||
if ( !pickedPart ) return;
|
||||
|
||||
for ( size_t i = 0; i < m_handleParts.size(); i++ )
|
||||
for ( auto& idPartIt : m_handleParts )
|
||||
{
|
||||
if ( pickedPart == m_handleParts.at( i ) )
|
||||
if ( pickedPart == idPartIt.second.p() )
|
||||
{
|
||||
m_initialPickPoint = intersectionPoint;
|
||||
m_tangentOnStartManipulation = m_tangent;
|
||||
m_originOnStartManipulation = m_origin;
|
||||
m_currentHandleIndex = i;
|
||||
m_activeHandle = idPartIt.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,7 +162,7 @@ void RicPointTangentManipulatorPartMgr::updateManipulatorFromRay( const cvf::Ray
|
||||
{
|
||||
if ( !isManipulatorActive() ) return;
|
||||
|
||||
if ( m_handleIds[m_currentHandleIndex] == HORIZONTAL_PLANE )
|
||||
if ( m_activeHandle == HORIZONTAL_PLANE )
|
||||
{
|
||||
cvf::Plane plane;
|
||||
plane.setFromPointAndNormal( m_origin, cvf::Vec3d::Z_AXIS );
|
||||
@ -173,7 +173,7 @@ void RicPointTangentManipulatorPartMgr::updateManipulatorFromRay( const cvf::Ray
|
||||
|
||||
m_origin = newOrigin;
|
||||
}
|
||||
else if ( m_handleIds[m_currentHandleIndex] == VERTICAL_AXIS )
|
||||
else if ( m_activeHandle == VERTICAL_AXIS )
|
||||
{
|
||||
cvf::Plane plane;
|
||||
cvf::Vec3d planeNormal = ( newMouseRay->direction() ^ cvf::Vec3d::Z_AXIS ) ^ cvf::Vec3d::Z_AXIS;
|
||||
@ -201,7 +201,7 @@ void RicPointTangentManipulatorPartMgr::updateManipulatorFromRay( const cvf::Ray
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicPointTangentManipulatorPartMgr::endManipulator()
|
||||
{
|
||||
m_currentHandleIndex = cvf::UNDEFINED_SIZE_T;
|
||||
m_activeHandle = NONE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -209,7 +209,6 @@ void RicPointTangentManipulatorPartMgr::endManipulator()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicPointTangentManipulatorPartMgr::clearAllGeometryAndParts()
|
||||
{
|
||||
m_handleIds.clear();
|
||||
m_handleParts.clear();
|
||||
m_activeDragModeParts.clear();
|
||||
}
|
||||
@ -222,6 +221,25 @@ void RicPointTangentManipulatorPartMgr::recreateAllGeometryAndParts()
|
||||
createAllHandleParts();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicPointTangentManipulatorPartMgr::clearGeometryOnly()
|
||||
{
|
||||
for ( auto& idPartIt : m_handleParts )
|
||||
{
|
||||
idPartIt.second->setDrawable( nullptr );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicPointTangentManipulatorPartMgr::createGeometryOnly()
|
||||
{
|
||||
// m_handleParts[]
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -237,23 +255,8 @@ void RicPointTangentManipulatorPartMgr::createAllHandleParts()
|
||||
void RicPointTangentManipulatorPartMgr::createHorizontalPlaneHandle()
|
||||
{
|
||||
using namespace cvf;
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray( 6 );
|
||||
|
||||
vertexArray->set( 0, {-1, -1, 0} );
|
||||
vertexArray->set( 1, {1, -1, 0} );
|
||||
vertexArray->set( 2, {1, 1, 0} );
|
||||
vertexArray->set( 3, {-1, -1, 0} );
|
||||
vertexArray->set( 4, {1, 1, 0} );
|
||||
vertexArray->set( 5, {-1, 1, 0} );
|
||||
|
||||
Vec3f origin( m_origin );
|
||||
for ( cvf::Vec3f& vx : *vertexArray )
|
||||
{
|
||||
vx *= 0.5 * m_handleSize;
|
||||
vx += origin;
|
||||
}
|
||||
|
||||
ref<DrawableGeo> geo = createTriangelDrawableGeo( vertexArray.p() );
|
||||
ref<cvf::DrawableGeo> geo = createHorizontalPlaneGeo();
|
||||
|
||||
HandleType handleId = HORIZONTAL_PLANE;
|
||||
cvf::Color4f color = cvf::Color4f( 1.0f, 0.0f, 1.0f, 0.5f );
|
||||
@ -262,15 +265,56 @@ void RicPointTangentManipulatorPartMgr::createHorizontalPlaneHandle()
|
||||
addHandlePart( geo.p(), color, handleId, partName );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> RicPointTangentManipulatorPartMgr::createHorizontalPlaneGeo()
|
||||
{
|
||||
using namespace cvf;
|
||||
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray( 6 );
|
||||
|
||||
vertexArray->set( 0, { -1, -1, 0 } );
|
||||
vertexArray->set( 1, { 1, -1, 0 } );
|
||||
vertexArray->set( 2, { 1, 1, 0 } );
|
||||
vertexArray->set( 3, { -1, -1, 0 } );
|
||||
vertexArray->set( 4, { 1, 1, 0 } );
|
||||
vertexArray->set( 5, { -1, 1, 0 } );
|
||||
|
||||
Vec3f origin( m_origin );
|
||||
for ( cvf::Vec3f& vx : *vertexArray )
|
||||
{
|
||||
vx *= 0.5 * m_handleSize;
|
||||
vx += origin;
|
||||
}
|
||||
|
||||
return createTriangelDrawableGeo( vertexArray.p() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicPointTangentManipulatorPartMgr::createVerticalAxisHandle()
|
||||
{
|
||||
using namespace cvf;
|
||||
cvf::ref<cvf::DrawableGeo> geo = createVertexAxisGeo();
|
||||
|
||||
HandleType handleId = VERTICAL_AXIS;
|
||||
cvf::Color4f color = cvf::Color4f( 0.0f, 0.2f, 0.8f, 0.5f );
|
||||
cvf::String partName( "PointTangentManipulator Vertical Axis Handle" );
|
||||
|
||||
addHandlePart( geo.p(), color, handleId, partName );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::ref<cvf::DrawableGeo> RicPointTangentManipulatorPartMgr::createVertexAxisGeo()
|
||||
{
|
||||
using namespace cvf;
|
||||
|
||||
cvf::ref<cvf::GeometryBuilderTriangles> geomBuilder = new cvf::GeometryBuilderTriangles;
|
||||
cvf::GeometryUtils::createBox( {-0.3f, -0.3f, -1.0f}, {0.3f, 0.3f, 1.0f}, geomBuilder.p() );
|
||||
cvf::GeometryUtils::createBox( { -0.3f, -0.3f, -1.0f }, { 0.3f, 0.3f, 1.0f }, geomBuilder.p() );
|
||||
|
||||
cvf::ref<cvf::Vec3fArray> vertexArray = geomBuilder->vertices();
|
||||
cvf::ref<cvf::UIntArray> indexArray = geomBuilder->triangles();
|
||||
@ -282,13 +326,7 @@ void RicPointTangentManipulatorPartMgr::createVerticalAxisHandle()
|
||||
vx += origin;
|
||||
}
|
||||
|
||||
ref<DrawableGeo> geo = createIndexedTriangelDrawableGeo( vertexArray.p(), indexArray.p() );
|
||||
|
||||
HandleType handleId = VERTICAL_AXIS;
|
||||
cvf::Color4f color = cvf::Color4f( 0.0f, 0.2f, 0.8f, 0.5f );
|
||||
cvf::String partName( "PointTangentManipulator Vertical Axis Handle" );
|
||||
|
||||
addHandlePart( geo.p(), color, handleId, partName );
|
||||
return createIndexedTriangelDrawableGeo( vertexArray.p(), indexArray.p() );
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -369,9 +407,7 @@ void RicPointTangentManipulatorPartMgr::addHandlePart( cvf::DrawableGeo* geo,
|
||||
const cvf::String& partName )
|
||||
{
|
||||
cvf::ref<cvf::Part> handlePart = createPart( geo, color, partName );
|
||||
|
||||
m_handleParts.push_back( handlePart.p() );
|
||||
m_handleIds.push_back( handleId );
|
||||
m_handleParts[handleId] = handlePart;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "cvfMatrix4.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class ModelBasicList;
|
||||
@ -49,7 +51,8 @@ public:
|
||||
HORIZONTAL_PLANE,
|
||||
VERTICAL_AXIS,
|
||||
AZIMUTH,
|
||||
INCLINATION
|
||||
INCLINATION,
|
||||
NONE
|
||||
};
|
||||
|
||||
public:
|
||||
@ -69,12 +72,18 @@ public:
|
||||
void appendPartsToModel( cvf::ModelBasicList* model );
|
||||
|
||||
private:
|
||||
void clearGeometryOnly();
|
||||
void createGeometryOnly();
|
||||
|
||||
void createAllHandleParts();
|
||||
void clearAllGeometryAndParts();
|
||||
void recreateAllGeometryAndParts();
|
||||
|
||||
void createHorizontalPlaneHandle();
|
||||
void createVerticalAxisHandle();
|
||||
void createHorizontalPlaneHandle();
|
||||
cvf::ref<cvf::DrawableGeo> createHorizontalPlaneGeo();
|
||||
|
||||
void createVerticalAxisHandle();
|
||||
cvf::ref<cvf::DrawableGeo> createVertexAxisGeo();
|
||||
|
||||
void addHandlePart( cvf::DrawableGeo* geo, const cvf::Color4f& color, HandleType handleId, const cvf::String& partName );
|
||||
|
||||
@ -89,14 +98,13 @@ private:
|
||||
static cvf::ref<cvf::Part> createPart( cvf::DrawableGeo* geo, const cvf::Color4f& color, const cvf::String& partName );
|
||||
|
||||
private:
|
||||
size_t m_currentHandleIndex;
|
||||
std::vector<HandleType> m_handleIds; // These arrays have the same length
|
||||
cvf::Collection<cvf::Part> m_handleParts; // These arrays have the same length
|
||||
cvf::Collection<cvf::Part> m_activeDragModeParts;
|
||||
cvf::Vec3d m_origin;
|
||||
cvf::Vec3d m_tangent;
|
||||
double m_handleSize;
|
||||
cvf::Vec3d m_initialPickPoint;
|
||||
cvf::Vec3d m_tangentOnStartManipulation;
|
||||
cvf::Vec3d m_originOnStartManipulation;
|
||||
HandleType m_activeHandle;
|
||||
std::map<HandleType, cvf::ref<cvf::Part>> m_handleParts; // These arrays have the same length
|
||||
cvf::Collection<cvf::Part> m_activeDragModeParts;
|
||||
cvf::Vec3d m_origin;
|
||||
cvf::Vec3d m_tangent;
|
||||
double m_handleSize;
|
||||
cvf::Vec3d m_initialPickPoint;
|
||||
cvf::Vec3d m_tangentOnStartManipulation;
|
||||
cvf::Vec3d m_originOnStartManipulation;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user