mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-27 07:30:20 -05:00
Move pdmToVariant/pdmFromVariant overloads for cvf::Color3f, Vec3d, Mat4d, and Mat3d from namespace caf to namespace cvf. Templates in cafInternalPdmFieldTypeSpecializations.h use "using caf::pdmToVariant" followed by an unqualified call, so ADL searches the argument's namespace (cvf). With the overloads only in caf, the default template was selected, causing cvf::Color3f to be stored raw in a QVariant instead of as QColor — breaking color field editing and producing QVariant::save warnings. All call sites now use the unqualified "using caf::pdmXxx; pdmXxx(value)" pattern so ADL finds the correct overload without depending on cvf:: as a visible prefix. Add AdlVariantTest to cafPdmCoreColor3fTest.cpp that exercises this exact pattern. Adds caf::toVariant<T> and caf::fromVariant<T> to cafPdmFieldTraits.h as thin wrappers that encapsulate the ADL two-step internally. Client code can now call caf::toVariant(x) directly instead of requiring a using-declaration at every call site.
184 lines
7.0 KiB
C++
184 lines
7.0 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2018- Equinor ASA
|
|
//
|
|
// 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 "RicTextAnnotation3dEditor.h"
|
|
|
|
#include "WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h"
|
|
|
|
#include "Rim3dView.h"
|
|
#include "RimCase.h"
|
|
#include "RimTextAnnotation.h"
|
|
|
|
#include "RiuViewer.h"
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
|
#include "cafPdmUiCommandSystemProxy.h"
|
|
#include "cafSelectionManager.h"
|
|
|
|
#include "cvfModelBasicList.h"
|
|
#include "cvfPart.h"
|
|
|
|
CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT( RicTextAnnotation3dEditor );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RicTextAnnotation3dEditor::RicTextAnnotation3dEditor()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RicTextAnnotation3dEditor::~RicTextAnnotation3dEditor()
|
|
{
|
|
RiuViewer* ownerRiuViewer = dynamic_cast<RiuViewer*>( ownerViewer() );
|
|
|
|
if ( m_cvfModel.notNull() && ownerRiuViewer )
|
|
{
|
|
// Could result in some circularities ....
|
|
ownerRiuViewer->removeStaticModel( m_cvfModel.p() );
|
|
}
|
|
|
|
auto textAnnot = dynamic_cast<RimTextAnnotation*>( pdmObject() );
|
|
if ( textAnnot )
|
|
{
|
|
textAnnot->m_anchorPointXyd.uiCapability()->removeFieldEditor( this );
|
|
textAnnot->m_labelPointXyd.uiCapability()->removeFieldEditor( this );
|
|
}
|
|
|
|
delete m_labelManipulator;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicTextAnnotation3dEditor::configureAndUpdateUi( const QString& uiConfigName )
|
|
{
|
|
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>( pdmObject() );
|
|
RiuViewer* ownerRiuViewer = dynamic_cast<RiuViewer*>( ownerViewer() );
|
|
Rim3dView* view = mainOrComparisonView();
|
|
|
|
if ( !textAnnot || !textAnnot->isActive() || !view )
|
|
{
|
|
if ( m_cvfModel.notNull() ) m_cvfModel->removeAllParts();
|
|
|
|
return;
|
|
}
|
|
|
|
textAnnot->m_anchorPointXyd.uiCapability()->addFieldEditor( this );
|
|
textAnnot->m_labelPointXyd.uiCapability()->addFieldEditor( this );
|
|
|
|
if ( m_labelManipulator.isNull() )
|
|
{
|
|
m_labelManipulator = new RicPointTangentManipulator( ownerRiuViewer );
|
|
m_anchorManipulator = new RicPointTangentManipulator( ownerRiuViewer );
|
|
QObject::connect( m_labelManipulator,
|
|
SIGNAL( notifyUpdate( const cvf::Vec3d&, const cvf::Vec3d& ) ),
|
|
this,
|
|
SLOT( slotLabelUpdated( const cvf::Vec3d&, const cvf::Vec3d& ) ) );
|
|
QObject::connect( m_anchorManipulator,
|
|
SIGNAL( notifyUpdate( const cvf::Vec3d&, const cvf::Vec3d& ) ),
|
|
this,
|
|
SLOT( slotAnchorUpdated( const cvf::Vec3d&, const cvf::Vec3d& ) ) );
|
|
|
|
m_cvfModel = new cvf::ModelBasicList;
|
|
ownerRiuViewer->addStaticModelOnce( m_cvfModel.p(), isInComparisonView() );
|
|
}
|
|
|
|
cvf::ref<caf::DisplayCoordTransform> dispXf = view->displayCoordTransform();
|
|
double handleSize = 0.7 * view->characteristicCellSize();
|
|
|
|
cvf::Vec3d labelPos( textAnnot->m_labelPointXyd() );
|
|
labelPos.z() *= -1.0;
|
|
m_labelManipulator->setOrigin( dispXf->transformToDisplayCoord( labelPos ) );
|
|
m_labelManipulator->setHandleSize( handleSize );
|
|
|
|
cvf::Vec3d anchorPos( textAnnot->m_anchorPointXyd() );
|
|
anchorPos.z() *= -1.0;
|
|
m_anchorManipulator->setOrigin( dispXf->transformToDisplayCoord( anchorPos ) );
|
|
m_anchorManipulator->setHandleSize( handleSize );
|
|
|
|
m_cvfModel->removeAllParts();
|
|
m_labelManipulator->appendPartsToModel( m_cvfModel.p() );
|
|
m_anchorManipulator->appendPartsToModel( m_cvfModel.p() );
|
|
|
|
m_cvfModel->updateBoundingBoxesRecursive();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicTextAnnotation3dEditor::cleanupBeforeSettingPdmObject()
|
|
{
|
|
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>( pdmObject() );
|
|
if ( textAnnot )
|
|
{
|
|
textAnnot->m_anchorPointXyd.uiCapability()->removeFieldEditor( this );
|
|
textAnnot->m_labelPointXyd.uiCapability()->removeFieldEditor( this );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicTextAnnotation3dEditor::slotLabelUpdated( const cvf::Vec3d& origin, const cvf::Vec3d& tangent )
|
|
{
|
|
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>( pdmObject() );
|
|
|
|
if ( !textAnnot )
|
|
{
|
|
return;
|
|
}
|
|
|
|
updatePoint( textAnnot->m_labelPointXyd.uiCapability(), origin );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicTextAnnotation3dEditor::slotAnchorUpdated( const cvf::Vec3d& origin, const cvf::Vec3d& dummy )
|
|
{
|
|
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>( pdmObject() );
|
|
|
|
if ( !textAnnot )
|
|
{
|
|
return;
|
|
}
|
|
|
|
updatePoint( textAnnot->m_anchorPointXyd.uiCapability(), origin );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicTextAnnotation3dEditor::updatePoint( caf::PdmUiFieldHandle* uiField, const cvf::Vec3d& newPos )
|
|
{
|
|
Rim3dView* view = mainOrComparisonView();
|
|
|
|
if ( !view ) return;
|
|
|
|
cvf::ref<caf::DisplayCoordTransform> dispXf = view->displayCoordTransform();
|
|
|
|
cvf::Vec3d domainPos = dispXf->transformToDomainCoord( newPos );
|
|
domainPos.z() = -domainPos.z();
|
|
QVariant originVariant = caf::toVariant( domainPos );
|
|
|
|
caf::PdmUiCommandSystemProxy::instance()->setUiValueToField( uiField, originVariant );
|
|
}
|