mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 06:38:13 -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.
101 lines
4.0 KiB
C++
101 lines
4.0 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 "RicApplyUserDefinedCameraFeature.h"
|
|
#include "RicStoreUserDefinedCameraFeature.h"
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RimGridView.h"
|
|
|
|
#include "RiuViewer.h"
|
|
|
|
#include "cvfCamera.h"
|
|
|
|
#include <QAction>
|
|
#include <QSettings>
|
|
|
|
CAF_CMD_SOURCE_INIT( RicApplyUserDefinedCameraFeature, "RicApplyUserDefinedCameraFeature" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RicApplyUserDefinedCameraFeature::isCommandEnabled() const
|
|
{
|
|
if ( !RicStoreUserDefinedCameraFeature::activeCamera() ) return false;
|
|
|
|
cvf::Vec3d eye = cvf::Vec3d::UNDEFINED;
|
|
cvf::Vec3d vrp = cvf::Vec3d::UNDEFINED;
|
|
cvf::Vec3d up = cvf::Vec3d::UNDEFINED;
|
|
|
|
readCameraFromSettings( eye, vrp, up );
|
|
return !( eye.isUndefined() || vrp.isUndefined() || up.isUndefined() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicApplyUserDefinedCameraFeature::onActionTriggered( bool isChecked )
|
|
{
|
|
if ( RicStoreUserDefinedCameraFeature::activeCamera() )
|
|
{
|
|
cvf::Vec3d eye = cvf::Vec3d::UNDEFINED;
|
|
cvf::Vec3d vrp = cvf::Vec3d::UNDEFINED;
|
|
cvf::Vec3d up = cvf::Vec3d::UNDEFINED;
|
|
|
|
readCameraFromSettings( eye, vrp, up );
|
|
if ( eye.isUndefined() || vrp.isUndefined() || up.isUndefined() ) return;
|
|
|
|
RicStoreUserDefinedCameraFeature::activeCamera()->setFromLookAt( eye, vrp, up );
|
|
RiaApplication::instance()->activeReservoirView()->updateDisplayModelForCurrentTimeStepAndRedraw();
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicApplyUserDefinedCameraFeature::setupActionLook( QAction* actionToSetup )
|
|
{
|
|
actionToSetup->setText( "User Defined View" );
|
|
actionToSetup->setToolTip( "User Defined View (Ctrl+Alt+U)" );
|
|
actionToSetup->setIcon( QIcon( ":/user-defined-view.svg" ) );
|
|
applyShortcutWithHintToAction( actionToSetup, QKeySequence( tr( "Ctrl+Alt+U" ) ) );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RicApplyUserDefinedCameraFeature::readCameraFromSettings( cvf::Vec3d& eye, cvf::Vec3d& vrp, cvf::Vec3d& up )
|
|
{
|
|
eye = cvf::Vec3d::UNDEFINED;
|
|
vrp = cvf::Vec3d::UNDEFINED;
|
|
up = cvf::Vec3d::UNDEFINED;
|
|
|
|
QSettings settings;
|
|
settings.beginGroup( RicStoreUserDefinedCameraFeature::groupName() );
|
|
|
|
QVariant eyeVariant = settings.value( RicStoreUserDefinedCameraFeature::eyeName() );
|
|
QVariant vrpVariant = settings.value( RicStoreUserDefinedCameraFeature::viewReferencePointName() );
|
|
QVariant upVariant = settings.value( RicStoreUserDefinedCameraFeature::upName() );
|
|
if ( eyeVariant.isNull() || vrpVariant.isNull() || upVariant.isNull() ) return;
|
|
|
|
caf::fromVariant( eyeVariant, eye );
|
|
caf::fromVariant( vrpVariant, vrp );
|
|
caf::fromVariant( upVariant, up );
|
|
}
|