2018-11-23 13:33:59 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2018-11-27 14:43:25 +01:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2018-11-23 13:33:59 +01:00
|
|
|
// 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.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2018-11-23 13:33:59 +01:00
|
|
|
// 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.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-11-23 13:33:59 +01:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RimTextAnnotation.h"
|
|
|
|
|
|
2018-11-28 14:18:10 +01:00
|
|
|
#include "RimAnnotationCollection.h"
|
2018-12-03 13:14:04 +01:00
|
|
|
#include "RimAnnotationGroupCollection.h"
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "RimAnnotationInViewCollection.h"
|
2018-12-05 14:38:58 +01:00
|
|
|
#include "RimAnnotationTextAppearance.h"
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "RimGridView.h"
|
|
|
|
|
#include "RimProject.h"
|
2018-12-05 14:38:58 +01:00
|
|
|
|
2018-11-29 15:51:32 +01:00
|
|
|
#include "AnnotationCommands/RicTextAnnotation3dEditor.h"
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "RicVec3dPickEventHandler.h"
|
2018-11-23 13:33:59 +01:00
|
|
|
|
2019-02-05 16:03:39 +01:00
|
|
|
#include "cafCmdFeatureManager.h"
|
2023-07-12 11:42:17 +02:00
|
|
|
#include "cafPdmObjectScriptingCapability.h"
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "cafPdmUiPickableLineEditor.h"
|
2019-02-11 13:46:48 +01:00
|
|
|
#include "cafPdmUiPushButtonEditor.h"
|
2018-12-05 15:27:07 +01:00
|
|
|
#include "cafPdmUiTextEditor.h"
|
2018-12-13 15:13:51 +01:00
|
|
|
#include "cafPdmUiTreeOrdering.h"
|
2019-02-05 16:03:39 +01:00
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QPointer>
|
2025-04-19 03:25:59 +00:00
|
|
|
#include <memory>
|
2018-11-23 13:33:59 +01:00
|
|
|
|
2025-05-16 14:22:08 +02:00
|
|
|
CAF_PDM_SOURCE_INIT( RimTextAnnotation, "TextAnnotation", "RimTextAnnotation" );
|
2018-11-23 13:33:59 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimTextAnnotation::RimTextAnnotation()
|
|
|
|
|
{
|
2023-07-12 11:42:17 +02:00
|
|
|
CAF_PDM_InitScriptableObject( "TextAnnotation", ":/TextAnnotation16x16.png" );
|
2023-08-04 09:04:14 +02:00
|
|
|
setUi3dEditorTypeName( RicTextAnnotation3dEditor::uiEditorTypeName() );
|
2018-11-29 15:51:32 +01:00
|
|
|
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitField( &m_anchorPointXyd, "AnchorPointXyd", Vec3d::ZERO, "Anchor Point" );
|
2019-09-06 10:40:57 +02:00
|
|
|
m_anchorPointXyd.uiCapability()->setUiEditorTypeName( caf::PdmUiPickableLineEditor::uiEditorTypeName() );
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitField( &m_anchorPointPickEnabledButtonField, "AnchorPointPick", false, "" );
|
2026-10-15 08:58:13 +02:00
|
|
|
m_anchorPointPickEnabledButtonField.xmlCapability()->disableIO();
|
|
|
|
|
m_anchorPointPickEnabledButtonField.uiCapability()->setUiHidden( true );
|
2019-02-11 13:46:48 +01:00
|
|
|
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitField( &m_labelPointXyd, "LabelPointXyd", Vec3d::ZERO, "Label Point" );
|
2019-09-06 10:40:57 +02:00
|
|
|
m_labelPointXyd.uiCapability()->setUiEditorTypeName( caf::PdmUiPickableLineEditor::uiEditorTypeName() );
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitField( &m_labelPointPickEnabledButtonField, "LabelPointPick", false, "" );
|
2026-10-15 08:58:13 +02:00
|
|
|
m_labelPointPickEnabledButtonField.xmlCapability()->disableIO();
|
|
|
|
|
m_labelPointPickEnabledButtonField.uiCapability()->setUiHidden( true );
|
2019-02-11 13:46:48 +01:00
|
|
|
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitField( &m_text, "Text", QString( "(New text)" ), "Text" );
|
2019-09-06 10:40:57 +02:00
|
|
|
m_text.uiCapability()->setUiEditorTypeName( caf::PdmUiTextEditor::uiEditorTypeName() );
|
2018-11-28 14:18:10 +01:00
|
|
|
|
2026-03-31 07:19:14 +02:00
|
|
|
m_isChecked.registerKeywordAlias( "IsActive" );
|
|
|
|
|
m_isChecked.uiCapability()->setUiHidden( true );
|
2018-11-28 14:18:10 +01:00
|
|
|
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_textAppearance, "TextAppearance", "Text Appearance" );
|
2018-12-05 14:38:58 +01:00
|
|
|
m_textAppearance = new RimAnnotationTextAppearance();
|
2019-09-06 10:40:57 +02:00
|
|
|
m_textAppearance.uiCapability()->setUiTreeChildrenHidden( true );
|
2018-12-05 15:27:07 +01:00
|
|
|
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_nameProxy, "NameProxy", "Name Proxy" );
|
2019-09-06 10:40:57 +02:00
|
|
|
m_nameProxy.registerGetMethod( this, &RimTextAnnotation::extractNameFromText );
|
|
|
|
|
m_nameProxy.uiCapability()->setUiReadOnly( true );
|
2018-12-05 15:27:07 +01:00
|
|
|
|
2025-04-19 03:25:59 +00:00
|
|
|
m_anchorPointPickEventHandler = std::make_shared<RicVec3dPickEventHandler>( &m_anchorPointXyd );
|
|
|
|
|
m_labelPointPickEventHandler = std::make_shared<RicVec3dPickEventHandler>( &m_labelPointXyd, 0.1 );
|
2020-05-18 16:02:27 +02:00
|
|
|
|
|
|
|
|
setDeletable( true );
|
2018-11-28 14:18:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-28 14:18:10 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 11:13:38 +01:00
|
|
|
RimTextAnnotation::~RimTextAnnotation()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-11-23 13:33:59 +01:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
cvf::Vec3d RimTextAnnotation::anchorPoint() const
|
|
|
|
|
{
|
2018-11-28 13:07:21 +01:00
|
|
|
auto pos = m_anchorPointXyd();
|
2019-09-06 10:40:57 +02:00
|
|
|
pos.z() = -pos.z();
|
2018-11-28 13:07:21 +01:00
|
|
|
return pos;
|
2018-11-23 13:33:59 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-30 14:29:46 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-30 14:29:46 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RimTextAnnotation::setAnchorPoint( const Vec3d& pointXyz )
|
2018-11-30 14:29:46 +01:00
|
|
|
{
|
|
|
|
|
m_anchorPointXyd = pointXyz;
|
|
|
|
|
m_anchorPointXyd.v().z() *= -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 13:33:59 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
cvf::Vec3d RimTextAnnotation::labelPoint() const
|
|
|
|
|
{
|
2018-11-28 13:07:21 +01:00
|
|
|
auto pos = m_labelPointXyd();
|
2019-09-06 10:40:57 +02:00
|
|
|
pos.z() = -pos.z();
|
2018-11-28 13:07:21 +01:00
|
|
|
return pos;
|
2018-11-23 13:33:59 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-30 14:29:46 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-30 14:29:46 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RimTextAnnotation::setLabelPoint( const Vec3d& pointXyz )
|
2018-11-30 14:29:46 +01:00
|
|
|
{
|
|
|
|
|
m_labelPointXyd = pointXyz;
|
|
|
|
|
m_labelPointXyd.v().z() *= -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 13:33:59 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RimTextAnnotation::setText( const QString& text )
|
2018-11-23 13:33:59 +01:00
|
|
|
{
|
|
|
|
|
m_text = text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
const QString& RimTextAnnotation::text() const
|
|
|
|
|
{
|
|
|
|
|
return m_text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RimTextAnnotation::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
2018-11-23 13:33:59 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
uiOrdering.add( &m_anchorPointXyd );
|
2026-10-15 08:58:13 +02:00
|
|
|
m_anchorPointXyd.uiCapability()->setAttribute( caf::PdmUiPickableLineEditor::Keys::PICK_EVENT_HANDLER, m_anchorPointPickEventHandler );
|
|
|
|
|
m_anchorPointXyd.uiCapability()->setAttribute( caf::PdmUiPickableLineEditor::Keys::ENABLE_PICKING,
|
|
|
|
|
(bool)m_anchorPointPickEnabledButtonField );
|
|
|
|
|
uiOrdering.addNewButton( m_anchorPointPickEnabledButtonField ? "Stop" : "Pick",
|
|
|
|
|
[this]()
|
|
|
|
|
{
|
|
|
|
|
m_anchorPointPickEnabledButtonField = !m_anchorPointPickEnabledButtonField;
|
|
|
|
|
updateConnectedEditors();
|
|
|
|
|
},
|
|
|
|
|
{ .newRow = false, .totalColumnSpan = 1 } );
|
2019-09-06 10:40:57 +02:00
|
|
|
uiOrdering.add( &m_labelPointXyd );
|
2026-10-15 08:58:13 +02:00
|
|
|
m_labelPointXyd.uiCapability()->setAttribute( caf::PdmUiPickableLineEditor::Keys::PICK_EVENT_HANDLER, m_labelPointPickEventHandler );
|
|
|
|
|
m_labelPointXyd.uiCapability()->setAttribute( caf::PdmUiPickableLineEditor::Keys::ENABLE_PICKING, (bool)m_labelPointPickEnabledButtonField );
|
|
|
|
|
uiOrdering.addNewButton( m_labelPointPickEnabledButtonField ? "Stop" : "Pick",
|
|
|
|
|
[this]()
|
|
|
|
|
{
|
|
|
|
|
m_labelPointPickEnabledButtonField = !m_labelPointPickEnabledButtonField;
|
|
|
|
|
updateConnectedEditors();
|
|
|
|
|
},
|
|
|
|
|
{ .newRow = false, .totalColumnSpan = 1 } );
|
2018-11-23 13:33:59 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
uiOrdering.add( &m_text );
|
2018-12-05 14:38:58 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
auto appearanceGroup = uiOrdering.addNewGroup( "Text Appearance" );
|
|
|
|
|
m_textAppearance->uiOrdering( uiConfigName, *appearanceGroup );
|
|
|
|
|
|
|
|
|
|
uiOrdering.skipRemainingFields( true );
|
2018-11-23 13:33:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 10:48:40 +01:00
|
|
|
void RimTextAnnotation::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
2018-11-23 13:33:59 +01:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( changedField == &m_anchorPointXyd )
|
2019-02-11 13:46:48 +01:00
|
|
|
{
|
|
|
|
|
m_anchorPointPickEnabledButtonField = false;
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_labelPointXyd().isZero() )
|
2019-02-11 13:46:48 +01:00
|
|
|
{
|
|
|
|
|
m_labelPointXyd = m_anchorPointXyd;
|
|
|
|
|
}
|
2023-08-04 09:04:14 +02:00
|
|
|
updateConnectedEditors();
|
2019-02-11 13:46:48 +01:00
|
|
|
}
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( changedField == &m_labelPointXyd )
|
2019-02-05 16:03:39 +01:00
|
|
|
{
|
2019-02-11 13:46:48 +01:00
|
|
|
m_labelPointPickEnabledButtonField = false;
|
2023-08-04 09:04:14 +02:00
|
|
|
updateConnectedEditors();
|
2019-02-05 16:03:39 +01:00
|
|
|
}
|
|
|
|
|
|
2023-05-12 21:41:34 +02:00
|
|
|
auto annColl = firstAncestorOrThisOfTypeAsserted<RimAnnotationCollectionBase>();
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( annColl ) annColl->scheduleRedrawOfRelevantViews();
|
2018-11-23 13:33:59 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-26 09:27:18 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
caf::PdmFieldHandle* RimTextAnnotation::userDescriptionField()
|
|
|
|
|
{
|
2018-12-05 15:27:07 +01:00
|
|
|
return &m_nameProxy;
|
2018-11-26 09:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-23 13:33:59 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2018-11-28 14:18:10 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimTextAnnotation::isActive()
|
|
|
|
|
{
|
2026-03-31 07:19:14 +02:00
|
|
|
return isChecked();
|
2018-11-28 14:18:10 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-03 13:14:04 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// Returns true if annotation can be displayed due to all toggles that affect this annotation
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool RimTextAnnotation::isVisible() const
|
|
|
|
|
{
|
2023-05-12 21:41:34 +02:00
|
|
|
auto coll = firstAncestorOrThisOfType<RimAnnotationGroupCollection>();
|
2018-12-03 13:14:04 +01:00
|
|
|
|
|
|
|
|
bool visible = true;
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( coll ) visible = coll->isVisible();
|
2026-03-31 07:19:14 +02:00
|
|
|
if ( visible ) visible = isChecked();
|
2019-02-05 16:03:39 +01:00
|
|
|
|
2018-12-03 13:14:04 +01:00
|
|
|
return visible;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-12 13:58:54 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RimTextAnnotation::enablePicking( bool enable )
|
2019-04-12 13:58:54 +02:00
|
|
|
{
|
|
|
|
|
m_anchorPointPickEnabledButtonField = enable;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 14:38:58 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimAnnotationTextAppearance* RimTextAnnotation::appearance() const
|
|
|
|
|
{
|
|
|
|
|
return m_textAppearance();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 15:27:07 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QString RimTextAnnotation::extractNameFromText() const
|
|
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
return m_text().split( "\n" ).front();
|
2018-12-05 15:27:07 +01:00
|
|
|
}
|