Files
ResInsight/ApplicationLibCode/Commands/3dView/RicStoreUserDefinedCameraFeature.cpp
T
Magne Sjaastad e8223485b1 Fix ADL lookup for cvf pdmToVariant/pdmFromVariant overloads
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.
2026-04-08 23:12:49 +02:00

123 lines
4.3 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 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 "RicStoreUserDefinedCameraFeature.h"
#include "RiaApplication.h"
#include "RimGridView.h"
#include "RiuMainWindow.h"
#include "RiuViewer.h"
#include "cvfCamera.h"
#include <QAction>
#include <QSettings>
CAF_CMD_SOURCE_INIT( RicStoreUserDefinedCameraFeature, "RicStoreUserDefinedCameraFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicStoreUserDefinedCameraFeature::groupName()
{
return "UserDefinedCamera";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicStoreUserDefinedCameraFeature::eyeName()
{
return "Eye";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicStoreUserDefinedCameraFeature::viewReferencePointName()
{
return "ViewReferencePoint";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicStoreUserDefinedCameraFeature::upName()
{
return "Up";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Camera* RicStoreUserDefinedCameraFeature::activeCamera()
{
if ( auto activeView = RiaApplication::instance()->activeReservoirView() )
{
if ( activeView->viewer() && activeView->viewer()->mainCamera() )
{
return activeView->viewer()->mainCamera();
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicStoreUserDefinedCameraFeature::isCommandEnabled() const
{
return activeCamera() != nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicStoreUserDefinedCameraFeature::onActionTriggered( bool isChecked )
{
if ( auto camera = activeCamera() )
{
QSettings settings;
settings.beginGroup( RicStoreUserDefinedCameraFeature::groupName() );
cvf::Vec3d eye;
cvf::Vec3d vrp;
cvf::Vec3d up;
camera->toLookAt( &eye, &vrp, &up );
settings.setValue( RicStoreUserDefinedCameraFeature::eyeName(), caf::toVariant( eye ) );
settings.setValue( RicStoreUserDefinedCameraFeature::viewReferencePointName(), caf::toVariant( vrp ) );
settings.setValue( RicStoreUserDefinedCameraFeature::upName(), caf::toVariant( up ) );
RiuMainWindow::instance()->refreshViewActions();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicStoreUserDefinedCameraFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Store User Defined View" );
actionToSetup->setIcon( QIcon( ":/user-defined-view.svg" ) );
}