2018-11-23 06:33:59 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2018-11-27 07:43:25 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-11-23 06:33:59 -06: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.
|
|
|
|
//
|
|
|
|
// 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 "RimTextAnnotation.h"
|
|
|
|
|
|
|
|
#include "RimAnnotationInViewCollection.h"
|
|
|
|
#include "RimGridView.h"
|
|
|
|
#include "RimProject.h"
|
2018-11-28 07:18:10 -06:00
|
|
|
#include "RimAnnotationCollection.h"
|
2018-12-03 06:14:04 -06:00
|
|
|
#include "RimAnnotationGroupCollection.h"
|
2018-12-05 07:38:58 -06:00
|
|
|
#include "RimAnnotationTextAppearance.h"
|
|
|
|
|
2019-02-05 09:03:39 -06:00
|
|
|
#include "RicVec3dPickEventHandler.h"
|
2018-11-29 08:51:32 -06:00
|
|
|
#include "AnnotationCommands/RicTextAnnotation3dEditor.h"
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2019-02-05 09:03:39 -06:00
|
|
|
#include "cafCmdFeatureManager.h"
|
2019-02-11 06:46:48 -06:00
|
|
|
#include "cafPdmUiPushButtonEditor.h"
|
2018-12-05 08:27:07 -06:00
|
|
|
#include "cafPdmUiTextEditor.h"
|
2018-12-13 08:13:51 -06:00
|
|
|
#include "cafPdmUiTreeOrdering.h"
|
2019-02-11 06:46:48 -06:00
|
|
|
#include "cafPdmUiPickableLineEditor.h"
|
2019-02-05 09:03:39 -06:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QPointer>
|
2018-11-23 06:33:59 -06:00
|
|
|
|
|
|
|
CAF_PDM_SOURCE_INIT(RimTextAnnotation, "RimTextAnnotation");
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimTextAnnotation::RimTextAnnotation()
|
|
|
|
{
|
2018-11-28 08:40:20 -06:00
|
|
|
CAF_PDM_InitObject("TextAnnotation", ":/TextAnnotation16x16.png", "", "");
|
2018-11-29 08:51:32 -06:00
|
|
|
this->setUi3dEditorTypeName(RicTextAnnotation3dEditor::uiEditorTypeName());
|
|
|
|
|
2018-11-28 06:07:21 -06:00
|
|
|
CAF_PDM_InitField(&m_anchorPointXyd, "AnchorPointXyd", Vec3d::ZERO, "Anchor Point", "", "", "");
|
2019-02-11 06:46:48 -06:00
|
|
|
m_anchorPointXyd.uiCapability()->setUiEditorTypeName(caf::PdmUiPickableLineEditor::uiEditorTypeName());
|
2019-04-12 06:58:54 -05:00
|
|
|
CAF_PDM_InitField(&m_anchorPointPickEnabledButtonField, "AnchorPointPick", false, "", "", "", "");
|
2019-02-11 06:46:48 -06:00
|
|
|
caf::PdmUiPushButtonEditor::configureEditorForField(&m_anchorPointPickEnabledButtonField);
|
|
|
|
m_anchorPointPickEnabledButtonField.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::LabelPosType::HIDDEN);
|
|
|
|
|
2018-11-28 06:07:21 -06:00
|
|
|
CAF_PDM_InitField(&m_labelPointXyd, "LabelPointXyd", Vec3d::ZERO, "Label Point", "", "", "");
|
2019-02-11 06:46:48 -06:00
|
|
|
m_labelPointXyd.uiCapability()->setUiEditorTypeName(caf::PdmUiPickableLineEditor::uiEditorTypeName());
|
|
|
|
CAF_PDM_InitField(&m_labelPointPickEnabledButtonField, "LabelPointPick", false, "", "", "", "");
|
|
|
|
caf::PdmUiPushButtonEditor::configureEditorForField(&m_labelPointPickEnabledButtonField);
|
|
|
|
m_labelPointPickEnabledButtonField.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::LabelPosType::HIDDEN);
|
|
|
|
|
2018-11-26 07:48:06 -06:00
|
|
|
CAF_PDM_InitField(&m_text, "Text", QString("(New text)"), "Text", "", "", "");
|
2018-12-05 08:27:07 -06:00
|
|
|
m_text.uiCapability()->setUiEditorTypeName(caf::PdmUiTextEditor::uiEditorTypeName());
|
2018-11-28 07:18:10 -06:00
|
|
|
|
|
|
|
CAF_PDM_InitField(&m_isActive, "IsActive", true, "Is Active", "", "", "");
|
|
|
|
m_isActive.uiCapability()->setUiHidden(true);
|
|
|
|
|
2018-12-05 07:38:58 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault(&m_textAppearance, "TextAppearance", "Text Appearance", "", "", "");
|
|
|
|
m_textAppearance = new RimAnnotationTextAppearance();
|
2018-12-13 08:13:51 -06:00
|
|
|
m_textAppearance.uiCapability()->setUiTreeHidden(true);
|
|
|
|
m_textAppearance.uiCapability()->setUiTreeChildrenHidden(true);
|
2018-12-05 08:27:07 -06:00
|
|
|
|
|
|
|
CAF_PDM_InitFieldNoDefault(&m_nameProxy, "NameProxy", "Name Proxy", "", "", "");
|
|
|
|
m_nameProxy.registerGetMethod(this, &RimTextAnnotation::extractNameFromText);
|
|
|
|
m_nameProxy.uiCapability()->setUiReadOnly(true);
|
|
|
|
m_nameProxy.xmlCapability()->disableIO();
|
|
|
|
|
2019-02-11 06:46:48 -06:00
|
|
|
m_anchorPointPickEventHandler.reset(new RicVec3dPickEventHandler(&m_anchorPointXyd));
|
|
|
|
m_labelPointPickEventHandler.reset(new RicVec3dPickEventHandler(&m_labelPointXyd));
|
2019-02-05 09:03:39 -06:00
|
|
|
|
2018-11-28 07:18:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimTextAnnotation::~RimTextAnnotation()
|
|
|
|
{
|
|
|
|
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Vec3d RimTextAnnotation::anchorPoint() const
|
|
|
|
{
|
2018-11-28 06:07:21 -06:00
|
|
|
auto pos = m_anchorPointXyd();
|
|
|
|
pos.z() = -pos.z();
|
|
|
|
return pos;
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 07:29:46 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimTextAnnotation::setAnchorPoint(const Vec3d & pointXyz)
|
|
|
|
{
|
|
|
|
m_anchorPointXyd = pointXyz;
|
|
|
|
m_anchorPointXyd.v().z() *= -1;
|
|
|
|
}
|
|
|
|
|
2018-11-23 06:33:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
cvf::Vec3d RimTextAnnotation::labelPoint() const
|
|
|
|
{
|
2018-11-28 06:07:21 -06:00
|
|
|
auto pos = m_labelPointXyd();
|
|
|
|
pos.z() = -pos.z();
|
|
|
|
return pos;
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
2018-11-30 07:29:46 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimTextAnnotation::setLabelPoint(const Vec3d & pointXyz)
|
|
|
|
{
|
|
|
|
m_labelPointXyd = pointXyz;
|
|
|
|
m_labelPointXyd.v().z() *= -1;
|
|
|
|
}
|
|
|
|
|
2018-11-23 06:33:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimTextAnnotation::setText(const QString& text)
|
|
|
|
{
|
|
|
|
m_text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
const QString& RimTextAnnotation::text() const
|
|
|
|
{
|
|
|
|
return m_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimTextAnnotation::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
|
|
|
{
|
2018-11-28 06:07:21 -06:00
|
|
|
uiOrdering.add(&m_anchorPointXyd);
|
2019-02-11 06:46:48 -06:00
|
|
|
uiOrdering.add(&m_anchorPointPickEnabledButtonField, false);
|
2018-11-28 06:07:21 -06:00
|
|
|
uiOrdering.add(&m_labelPointXyd);
|
2019-02-11 06:46:48 -06:00
|
|
|
uiOrdering.add(&m_labelPointPickEnabledButtonField, false);
|
|
|
|
|
2018-11-23 06:33:59 -06:00
|
|
|
uiOrdering.add(&m_text);
|
|
|
|
|
2018-12-05 07:38:58 -06:00
|
|
|
auto appearanceGroup = uiOrdering.addNewGroup("Text Appearance");
|
|
|
|
m_textAppearance->uiOrdering(uiConfigName, *appearanceGroup);
|
|
|
|
|
2018-11-23 06:33:59 -06:00
|
|
|
uiOrdering.skipRemainingFields(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimTextAnnotation::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
|
|
|
|
const QVariant& oldValue,
|
|
|
|
const QVariant& newValue)
|
|
|
|
{
|
2019-02-11 06:46:48 -06:00
|
|
|
if (changedField == &m_anchorPointXyd)
|
|
|
|
{
|
|
|
|
m_anchorPointPickEnabledButtonField = false;
|
|
|
|
if (m_labelPointXyd().isZero())
|
|
|
|
{
|
|
|
|
m_labelPointXyd = m_anchorPointXyd;
|
|
|
|
}
|
|
|
|
this->updateConnectedEditors();
|
|
|
|
}
|
|
|
|
if (changedField == &m_labelPointXyd)
|
2019-02-05 09:03:39 -06:00
|
|
|
{
|
2019-02-11 06:46:48 -06:00
|
|
|
m_labelPointPickEnabledButtonField = false;
|
|
|
|
this->updateConnectedEditors();
|
2019-02-05 09:03:39 -06:00
|
|
|
}
|
2019-02-11 06:46:48 -06:00
|
|
|
if (changedField == &m_anchorPointPickEnabledButtonField || changedField == &m_labelPointPickEnabledButtonField)
|
2019-02-05 09:03:39 -06:00
|
|
|
{
|
2019-02-11 06:46:48 -06:00
|
|
|
this->updateConnectedEditors();
|
2019-02-05 09:03:39 -06:00
|
|
|
}
|
|
|
|
|
2018-11-28 08:27:32 -06:00
|
|
|
RimAnnotationCollectionBase* annColl = nullptr;
|
2018-11-28 07:18:10 -06:00
|
|
|
this->firstAncestorOrThisOfTypeAsserted(annColl);
|
|
|
|
|
2018-11-28 08:27:32 -06:00
|
|
|
if(annColl) annColl->scheduleRedrawOfRelevantViews();
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
caf::PdmFieldHandle* RimTextAnnotation::userDescriptionField()
|
|
|
|
{
|
2018-12-05 08:27:07 -06:00
|
|
|
return &m_nameProxy;
|
2018-11-26 02:27:18 -06:00
|
|
|
}
|
|
|
|
|
2018-11-23 06:33:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-28 07:18:10 -06:00
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimTextAnnotation::isActive()
|
|
|
|
{
|
|
|
|
return m_isActive();
|
|
|
|
}
|
|
|
|
|
2018-12-03 06:14:04 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Returns true if annotation can be displayed due to all toggles that affect this annotation
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RimTextAnnotation::isVisible() const
|
|
|
|
{
|
|
|
|
RimAnnotationGroupCollection* coll;
|
|
|
|
firstAncestorOrThisOfType(coll);
|
|
|
|
|
|
|
|
bool visible = true;
|
|
|
|
if (coll) visible = coll->isVisible();
|
|
|
|
if(visible) visible = m_isActive;
|
2019-02-05 09:03:39 -06:00
|
|
|
|
2018-12-03 06:14:04 -06:00
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
2019-04-12 06:58:54 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimTextAnnotation::enablePicking(bool enable)
|
|
|
|
{
|
|
|
|
m_anchorPointPickEnabledButtonField = enable;
|
|
|
|
}
|
|
|
|
|
2018-12-05 07:38:58 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimAnnotationTextAppearance* RimTextAnnotation::appearance() const
|
|
|
|
{
|
|
|
|
return m_textAppearance();
|
|
|
|
}
|
|
|
|
|
2018-11-28 07:18:10 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
2018-11-23 06:33:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-28 07:18:10 -06:00
|
|
|
caf::PdmFieldHandle* RimTextAnnotation::objectToggleField()
|
2018-11-23 06:33:59 -06:00
|
|
|
{
|
2018-11-28 07:18:10 -06:00
|
|
|
return &m_isActive;
|
|
|
|
}
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2019-02-05 09:03:39 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimTextAnnotation::defineEditorAttribute(const caf::PdmFieldHandle* field,
|
|
|
|
QString uiConfigName,
|
|
|
|
caf::PdmUiEditorAttribute* attribute)
|
|
|
|
{
|
2019-02-11 06:46:48 -06:00
|
|
|
caf::PdmUiPickableLineEditorAttribute* attr = dynamic_cast<caf::PdmUiPickableLineEditorAttribute*>(attribute);
|
2019-02-05 09:03:39 -06:00
|
|
|
|
|
|
|
if (attr && field == &m_anchorPointXyd)
|
|
|
|
{
|
|
|
|
attr->pickEventHandler = m_anchorPointPickEventHandler;
|
2019-02-11 06:46:48 -06:00
|
|
|
attr->enablePicking = m_anchorPointPickEnabledButtonField;
|
2019-02-05 09:03:39 -06:00
|
|
|
}
|
|
|
|
else if (attr && field == &m_labelPointXyd)
|
|
|
|
{
|
|
|
|
attr->pickEventHandler = m_labelPointPickEventHandler;
|
2019-02-11 06:46:48 -06:00
|
|
|
attr->enablePicking = m_labelPointPickEnabledButtonField;
|
2019-02-05 09:03:39 -06:00
|
|
|
}
|
2019-02-11 06:46:48 -06:00
|
|
|
|
|
|
|
if (field == &m_anchorPointPickEnabledButtonField || field == &m_labelPointPickEnabledButtonField)
|
|
|
|
{
|
|
|
|
auto* pbAttribute = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>(attribute);
|
|
|
|
if (pbAttribute)
|
|
|
|
{
|
|
|
|
auto boolField = static_cast<const caf::PdmField<bool>*>(field);
|
|
|
|
if (boolField->v())
|
|
|
|
{
|
|
|
|
pbAttribute->m_buttonText = "Stop";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pbAttribute->m_buttonText = "Pick";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 09:03:39 -06:00
|
|
|
}
|
|
|
|
|
2018-12-05 08:27:07 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimTextAnnotation::extractNameFromText() const
|
|
|
|
{
|
|
|
|
return m_text().split("\n").front();
|
|
|
|
}
|
2018-11-23 06:33:59 -06:00
|
|
|
|
|
|
|
|