Simplify pick event system

This commit is contained in:
Gaute Lindkvist
2019-02-11 13:46:48 +01:00
parent fac9870c76
commit d9672ad9a1
28 changed files with 315 additions and 390 deletions

View File

@@ -47,7 +47,6 @@ RicMeasurementPickEventHandler* RicMeasurementPickEventHandler::instance()
///
//--------------------------------------------------------------------------------------------------
RicMeasurementPickEventHandler::RicMeasurementPickEventHandler()
: Ric3dViewPickEventHandler(nullptr)
{}
//--------------------------------------------------------------------------------------------------

View File

@@ -20,13 +20,6 @@
#include <typeinfo>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Ric3dViewPickEventHandler::Ric3dViewPickEventHandler(const caf::PdmObjectHandle* handlingObject)
: caf::PickEventHandler(handlingObject)
{}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -28,8 +28,6 @@
class Ric3dViewPickEventHandler : public caf::PickEventHandler
{
public:
Ric3dViewPickEventHandler(const caf::PdmObjectHandle* handlingObject);
// Override from caf
void registerAsPickEventHandler() override;
void unregisterAsPickEventHandler() override;

View File

@@ -26,10 +26,8 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicVec3dPickEventHandler::RicVec3dPickEventHandler(const caf::PdmObjectHandle* handlingObject,
caf::PdmField<cvf::Vec3d>* vectorField)
: Ric3dViewPickEventHandler(handlingObject)
, m_vectorField(vectorField)
RicVec3dPickEventHandler::RicVec3dPickEventHandler(caf::PdmField<cvf::Vec3d>* vectorField)
: m_vectorField(vectorField)
{
}
@@ -38,19 +36,14 @@ RicVec3dPickEventHandler::RicVec3dPickEventHandler(const caf::PdmObjectHandle* h
//--------------------------------------------------------------------------------------------------
bool RicVec3dPickEventHandler::handle3dPickEvent(const Ric3dPickEvent& eventObject)
{
caf::PdmObjectHandle* selectedObject = caf::SelectionManager::instance()->selectedItemOfType<caf::PdmObjectHandle>();
if (isObjectBeingModified(selectedObject))
{
const Rim3dView* rimView = eventObject.m_view;
const Rim3dView* rimView = eventObject.m_view;
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
cvf::Vec3d pickedPositionInUTM = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint());
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
cvf::Vec3d pickedPositionInUTM = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint());
pickedPositionInUTM.z() *= -1.0;
m_vectorField->setValueWithFieldChanged(pickedPositionInUTM);
return true;
}
return false;
pickedPositionInUTM.z() *= -1.0;
m_vectorField->setValueWithFieldChanged(pickedPositionInUTM);
return true;
}
//--------------------------------------------------------------------------------------------------

View File

@@ -29,7 +29,7 @@ class Rim3dView;
class RicVec3dPickEventHandler : public Ric3dViewPickEventHandler
{
public:
RicVec3dPickEventHandler(const caf::PdmObjectHandle* handlingObject, caf::PdmField<cvf::Vec3d>* vectorField);
RicVec3dPickEventHandler(caf::PdmField<cvf::Vec3d>* vectorField);
bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override;

View File

@@ -23,6 +23,7 @@
#include "RimPolylineTarget.h"
#include "RimUserDefinedPolylinesAnnotation.h"
#include "cafPickEventHandler.h"
CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicPolyline3dEditor);
@@ -43,6 +44,10 @@ RicPolyline3dEditor::~RicPolyline3dEditor()
{
delete targetEditor;
}
if (m_attribute.pickEventHandler != nullptr)
{
m_attribute.pickEventHandler->unregisterAsPickEventHandler();
}
}
//--------------------------------------------------------------------------------------------------
@@ -60,6 +65,18 @@ void RicPolyline3dEditor::configureAndUpdateUi(const QString& uiConfigName)
if (!geomDef) return;
geomDef->objectEditorAttribute("", &m_attribute);
if (m_attribute.pickEventHandler != nullptr)
{
if (m_attribute.enablePicking)
{
m_attribute.pickEventHandler->registerAsPickEventHandler();
}
else
{
m_attribute.pickEventHandler->unregisterAsPickEventHandler();
}
}
std::vector<RimPolylineTarget*> targets = geomDef->activeTargets();

View File

@@ -17,10 +17,39 @@
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmUi3dObjectEditorHandle.h"
#include "cafPdmUiFieldEditorHandle.h"
#include <memory>
namespace caf
{
class PickEventHandler;
};
class RicPolylineTarget3dEditor;
//==================================================================================================
///
//==================================================================================================
class RicPolyline3dEditorAttribute : public caf::PdmUiEditorAttribute
{
public:
RicPolyline3dEditorAttribute()
: enablePicking(false)
{
}
public:
bool enablePicking;
std::shared_ptr<caf::PickEventHandler> pickEventHandler;
};
//==================================================================================================
///
//==================================================================================================
class RicPolyline3dEditor : public caf::PdmUi3dObjectEditorHandle
{
CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT;
@@ -33,8 +62,8 @@ protected:
void configureAndUpdateUi(const QString& uiConfigName) override;
private:
std::vector<RicPolylineTarget3dEditor*> m_targetEditors;
RicPolyline3dEditorAttribute m_attribute;
};

View File

@@ -24,6 +24,7 @@
#include "RimWellPathTarget.h"
#include "RimWellPathGeometryDef.h"
#include "cafPickEventHandler.h"
CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicWellPathGeometry3dEditor);
@@ -44,6 +45,10 @@ RicWellPathGeometry3dEditor::~RicWellPathGeometry3dEditor()
{
delete targetEditor;
}
if (m_attribute.pickEventHandler)
{
m_attribute.pickEventHandler->unregisterAsPickEventHandler();
}
}
//--------------------------------------------------------------------------------------------------
@@ -61,6 +66,7 @@ void RicWellPathGeometry3dEditor::configureAndUpdateUi(const QString& uiConfigNa
if (!geomDef) return;
geomDef->objectEditorAttribute("", &m_attribute);
std::vector<RimWellPathTarget*> targets = geomDef->activeWellTargets();
@@ -72,6 +78,18 @@ void RicWellPathGeometry3dEditor::configureAndUpdateUi(const QString& uiConfigNa
m_targetEditors.push_back(targetEditor);
targetEditor->updateUi();
}
if (m_attribute.pickEventHandler)
{
if (m_attribute.enablePicking)
{
m_attribute.pickEventHandler->registerAsPickEventHandler();
}
else
{
m_attribute.pickEventHandler->unregisterAsPickEventHandler();
}
}
}

View File

@@ -18,9 +18,25 @@
#pragma once
#include "cafPdmUi3dObjectEditorHandle.h"
#include "cafPdmUiFieldEditorHandle.h"
#include <memory>
namespace caf
{
class PickEventHandler;
}
class RicWellTarget3dEditor;
class RicWellPathGeometry3dEditorAttribute : public caf::PdmUiEditorAttribute
{
public:
RicWellPathGeometry3dEditorAttribute() : enablePicking(false) {}
bool enablePicking;
std::shared_ptr<caf::PickEventHandler> pickEventHandler;
};
class RicWellPathGeometry3dEditor : public caf::PdmUi3dObjectEditorHandle
{
CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT;
@@ -33,8 +49,8 @@ protected:
void configureAndUpdateUi(const QString& uiConfigName) override;
private:
std::vector<RicWellTarget3dEditor*> m_targetEditors;
std::vector<RicWellTarget3dEditor*> m_targetEditors;
RicWellPathGeometry3dEditorAttribute m_attribute;
};

View File

@@ -18,6 +18,7 @@
#include "RicCreateWellTargetsPickEventHandler.h"
#include "RiaApplication.h"
#include "RiaOffshoreSphericalCoords.h"
#include "RigFemPart.h"
@@ -55,7 +56,7 @@
///
//--------------------------------------------------------------------------------------------------
RicCreateWellTargetsPickEventHandler::RicCreateWellTargetsPickEventHandler(RimWellPathGeometryDef* wellGeometryDef)
: Ric3dViewPickEventHandler(wellGeometryDef), m_geometryToAddTargetsTo(wellGeometryDef)
: m_geometryToAddTargetsTo(wellGeometryDef)
{
}
@@ -64,12 +65,21 @@ RicCreateWellTargetsPickEventHandler::RicCreateWellTargetsPickEventHandler(RimWe
//--------------------------------------------------------------------------------------------------
RicCreateWellTargetsPickEventHandler::~RicCreateWellTargetsPickEventHandler() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateWellTargetsPickEventHandler::registerAsPickEventHandler()
{
RiaApplication::instance()->setOverrideCursor(Qt::CrossCursor);
Ric3dViewPickEventHandler::registerAsPickEventHandler();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateWellTargetsPickEventHandler::notifyUnregistered()
{
m_geometryToAddTargetsTo->enableTargetPointPicking(false);
RiaApplication::instance()->restoreOverrideCursor();
}
//--------------------------------------------------------------------------------------------------
@@ -77,13 +87,6 @@ void RicCreateWellTargetsPickEventHandler::notifyUnregistered()
//--------------------------------------------------------------------------------------------------
bool RicCreateWellTargetsPickEventHandler::handle3dPickEvent(const Ric3dPickEvent& eventObject)
{
if (!isObjectBeingModified(caf::SelectionManager::instance()->selectedItemOfType<caf::PdmObjectHandle>()))
{
m_geometryToAddTargetsTo->enableTargetPointPicking(false);
return false;
}
if (m_geometryToAddTargetsTo)
{
Rim3dView* rimView = eventObject.m_view;

View File

@@ -34,6 +34,8 @@ public:
RicCreateWellTargetsPickEventHandler(RimWellPathGeometryDef* wellGeometryDef);
~RicCreateWellTargetsPickEventHandler();
void registerAsPickEventHandler() override;
protected:
bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override;
void notifyUnregistered() override;

View File

@@ -18,6 +18,7 @@
#include "RicPolylineTargetsPickEventHandler.h"
#include "RiaApplication.h"
#include "RiaOffshoreSphericalCoords.h"
#include "RigWellPath.h"
@@ -40,7 +41,7 @@
///
//--------------------------------------------------------------------------------------------------
RicPolylineTargetsPickEventHandler::RicPolylineTargetsPickEventHandler(RimUserDefinedPolylinesAnnotation* polylineDef)
: Ric3dViewPickEventHandler(polylineDef), m_polylineDef(polylineDef)
: m_polylineDef(polylineDef)
{
}
@@ -49,12 +50,21 @@ RicPolylineTargetsPickEventHandler::RicPolylineTargetsPickEventHandler(RimUserDe
//--------------------------------------------------------------------------------------------------
RicPolylineTargetsPickEventHandler::~RicPolylineTargetsPickEventHandler() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPolylineTargetsPickEventHandler::registerAsPickEventHandler()
{
RiaApplication::instance()->setOverrideCursor(Qt::CrossCursor);
Ric3dViewPickEventHandler::registerAsPickEventHandler();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPolylineTargetsPickEventHandler::notifyUnregistered()
{
//m_polylineDef->enableTargetPointPicking(false);
RiaApplication::instance()->restoreOverrideCursor();
}
//--------------------------------------------------------------------------------------------------
@@ -62,11 +72,6 @@ void RicPolylineTargetsPickEventHandler::notifyUnregistered()
//--------------------------------------------------------------------------------------------------
bool RicPolylineTargetsPickEventHandler::handle3dPickEvent(const Ric3dPickEvent& eventObject)
{
if (!isObjectBeingModified(caf::SelectionManager::instance()->selectedItemOfType<caf::PdmObjectHandle>()))
{
return false;
}
if (m_polylineDef)
{
Rim3dView* rimView = eventObject.m_view;

View File

@@ -33,6 +33,8 @@ public:
RicPolylineTargetsPickEventHandler(RimUserDefinedPolylinesAnnotation* polylineDef);
~RicPolylineTargetsPickEventHandler();
void registerAsPickEventHandler() override;
protected:
bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override;
void notifyUnregistered() override;

View File

@@ -26,7 +26,8 @@
#include "RicVec3dPickEventHandler.h"
#include "cafPdmUiVec3dEditor.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiPickableLineEditor.h"
CAF_PDM_SOURCE_INIT(RimReachCircleAnnotation, "RimReachCircleAnnotation");
@@ -42,7 +43,11 @@ RimReachCircleAnnotation::RimReachCircleAnnotation()
m_isActive.uiCapability()->setUiHidden(true);
CAF_PDM_InitField(&m_centerPointXyd, "CenterPointXyd", Vec3d::ZERO, "Center Point", "", "", "");
m_centerPointXyd.uiCapability()->setUiEditorTypeName(caf::PdmUiVec3dEditor::uiEditorTypeName());
m_centerPointXyd.uiCapability()->setUiEditorTypeName(caf::PdmUiPickableLineEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_centerPointPickEnabled, "AnchorPointPick", true, "", "", "", "");
caf::PdmUiPushButtonEditor::configureEditorForField(&m_centerPointPickEnabled);
m_centerPointPickEnabled.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::LabelPosType::HIDDEN);
CAF_PDM_InitField(&m_radius, "Radius", 100.0, "Radius", "", "", "");
CAF_PDM_InitField(&m_name, "Name", QString("Circle Annotation"), "Name", "", "", "");
@@ -52,7 +57,7 @@ RimReachCircleAnnotation::RimReachCircleAnnotation()
m_appearance.uiCapability()->setUiTreeHidden(true);
m_appearance.uiCapability()->setUiTreeChildrenHidden(true);
m_centerPointEventHandler.reset(new RicVec3dPickEventHandler(this, &m_centerPointXyd));
m_centerPointEventHandler.reset(new RicVec3dPickEventHandler(&m_centerPointXyd));
}
//--------------------------------------------------------------------------------------------------
@@ -115,6 +120,7 @@ void RimReachCircleAnnotation::defineUiOrdering(QString uiConfigName, caf::PdmUi
{
uiOrdering.add(&m_name);
uiOrdering.add(&m_centerPointXyd);
uiOrdering.add(&m_centerPointPickEnabled);
uiOrdering.add(&m_radius);
auto appearanceGroup = uiOrdering.addNewGroup("Appearance");
@@ -130,6 +136,15 @@ void RimReachCircleAnnotation::fieldChangedByUi(const caf::PdmFieldHandle* chang
const QVariant& oldValue,
const QVariant& newValue)
{
if (changedField == &m_centerPointXyd)
{
m_centerPointPickEnabled = false;
this->updateConnectedEditors();
}
if (changedField == &m_centerPointPickEnabled)
{
this->updateConnectedEditors();
}
RimAnnotationCollection* annColl = nullptr;
this->firstAncestorOrThisOfTypeAsserted(annColl);
@@ -161,13 +176,30 @@ void RimReachCircleAnnotation::defineEditorAttribute(const caf::PdmFieldHandle*
{
if (field == &m_centerPointXyd)
{
caf::PdmUiVec3dEditorAttribute* attr = dynamic_cast<caf::PdmUiVec3dEditorAttribute*>(attribute);
auto* attr = dynamic_cast<caf::PdmUiPickableLineEditorAttribute*>(attribute);
if (attr)
{
attr->pickEventHandler = m_centerPointEventHandler;
attr->enablePicking = m_centerPointPickEnabled;
if (m_centerPointXyd().isZero())
{
attr->startInPickingMode = true;
attr->enablePicking = true;
}
}
}
if (field == &m_centerPointPickEnabled)
{
auto* attr = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>(attribute);
if (attr)
{
if (m_centerPointPickEnabled)
{
attr->m_buttonText = "Stop";
}
else
{
attr->m_buttonText = "Pick";
}
}
}

View File

@@ -76,6 +76,7 @@ private:
caf::PdmField<bool> m_isActive;
caf::PdmField<Vec3d> m_centerPointXyd;
caf::PdmField<bool> m_centerPointPickEnabled;
caf::PdmField<double> m_radius;
caf::PdmField<QString> m_name;
caf::PdmChildField<RimReachCircleLineAppearance*> m_appearance;

View File

@@ -29,9 +29,10 @@
#include "AnnotationCommands/RicTextAnnotation3dEditor.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTextEditor.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafPdmUiVec3dEditor.h"
#include "cafPdmUiPickableLineEditor.h"
#include <QAction>
#include <QPointer>
@@ -48,9 +49,17 @@ RimTextAnnotation::RimTextAnnotation()
this->setUi3dEditorTypeName(RicTextAnnotation3dEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_anchorPointXyd, "AnchorPointXyd", Vec3d::ZERO, "Anchor Point", "", "", "");
m_anchorPointXyd.uiCapability()->setUiEditorTypeName(caf::PdmUiVec3dEditor::uiEditorTypeName());
m_anchorPointXyd.uiCapability()->setUiEditorTypeName(caf::PdmUiPickableLineEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_anchorPointPickEnabledButtonField, "AnchorPointPick", true, "", "", "", "");
caf::PdmUiPushButtonEditor::configureEditorForField(&m_anchorPointPickEnabledButtonField);
m_anchorPointPickEnabledButtonField.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::LabelPosType::HIDDEN);
CAF_PDM_InitField(&m_labelPointXyd, "LabelPointXyd", Vec3d::ZERO, "Label Point", "", "", "");
m_labelPointXyd.uiCapability()->setUiEditorTypeName(caf::PdmUiVec3dEditor::uiEditorTypeName());
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);
CAF_PDM_InitField(&m_text, "Text", QString("(New text)"), "Text", "", "", "");
m_text.uiCapability()->setUiEditorTypeName(caf::PdmUiTextEditor::uiEditorTypeName());
@@ -67,8 +76,8 @@ RimTextAnnotation::RimTextAnnotation()
m_nameProxy.uiCapability()->setUiReadOnly(true);
m_nameProxy.xmlCapability()->disableIO();
m_anchorPointPickEventHandler.reset(new RicVec3dPickEventHandler(this, &m_anchorPointXyd));
m_labelPointPickEventHandler.reset(new RicVec3dPickEventHandler(this, &m_labelPointXyd));
m_anchorPointPickEventHandler.reset(new RicVec3dPickEventHandler(&m_anchorPointXyd));
m_labelPointPickEventHandler.reset(new RicVec3dPickEventHandler(&m_labelPointXyd));
}
@@ -140,7 +149,10 @@ const QString& RimTextAnnotation::text() const
void RimTextAnnotation::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
uiOrdering.add(&m_anchorPointXyd);
uiOrdering.add(&m_anchorPointPickEnabledButtonField, false);
uiOrdering.add(&m_labelPointXyd);
uiOrdering.add(&m_labelPointPickEnabledButtonField, false);
uiOrdering.add(&m_text);
auto appearanceGroup = uiOrdering.addNewGroup("Text Appearance");
@@ -156,15 +168,24 @@ void RimTextAnnotation::fieldChangedByUi(const caf::PdmFieldHandle* changedField
const QVariant& oldValue,
const QVariant& newValue)
{
if (changedField == &m_anchorPointXyd && m_labelPointXyd().isZero())
if (changedField == &m_anchorPointXyd)
{
m_labelPointXyd = m_anchorPointXyd();
m_anchorPointPickEnabledButtonField = false;
if (m_labelPointXyd().isZero())
{
m_labelPointXyd = m_anchorPointXyd;
}
this->updateConnectedEditors();
}
if (changedField == &m_labelPointXyd && m_anchorPointXyd().isZero())
if (changedField == &m_labelPointXyd)
{
m_anchorPointXyd = m_labelPointXyd();
m_labelPointPickEnabledButtonField = false;
this->updateConnectedEditors();
}
if (changedField == &m_anchorPointPickEnabledButtonField || changedField == &m_labelPointPickEnabledButtonField)
{
this->updateConnectedEditors();
}
RimAnnotationCollectionBase* annColl = nullptr;
this->firstAncestorOrThisOfTypeAsserted(annColl);
@@ -226,20 +247,36 @@ void RimTextAnnotation::defineEditorAttribute(const caf::PdmFieldHandle* field,
QString uiConfigName,
caf::PdmUiEditorAttribute* attribute)
{
caf::PdmUiVec3dEditorAttribute* attr = dynamic_cast<caf::PdmUiVec3dEditorAttribute*>(attribute);
caf::PdmUiPickableLineEditorAttribute* attr = dynamic_cast<caf::PdmUiPickableLineEditorAttribute*>(attribute);
if (attr && field == &m_anchorPointXyd)
{
attr->pickEventHandler = m_anchorPointPickEventHandler;
if (m_anchorPointXyd().isZero())
{
attr->startInPickingMode = true;
}
attr->enablePicking = m_anchorPointPickEnabledButtonField;
}
else if (attr && field == &m_labelPointXyd)
{
attr->pickEventHandler = m_labelPointPickEventHandler;
attr->enablePicking = m_labelPointPickEnabledButtonField;
}
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";
}
}
}
}
//--------------------------------------------------------------------------------------------------

View File

@@ -84,7 +84,9 @@ private:
QString extractNameFromText() const;
caf::PdmField<Vec3d> m_anchorPointXyd;
caf::PdmField<bool> m_anchorPointPickEnabledButtonField;
caf::PdmField<Vec3d> m_labelPointXyd;
caf::PdmField<bool> m_labelPointPickEnabledButtonField;
caf::PdmField<QString> m_text;
caf::PdmField<bool> m_isActive;

View File

@@ -209,14 +209,6 @@ void RimUserDefinedPolylinesAnnotation::updateVisualization()
void RimUserDefinedPolylinesAnnotation::enablePicking(bool enable)
{
m_enablePicking = enable;
if (enable)
{
RiuViewerCommands::setPickEventHandler(m_pickTargetsEventHandler);
}
else
{
RiuViewerCommands::removePickEventHandlerIfActive(m_pickTargetsEventHandler);
}
updateConnectedEditors();
}
@@ -259,7 +251,7 @@ void RimUserDefinedPolylinesAnnotation::fieldChangedByUi(const caf::PdmFieldHand
{
if (changedField == &m_enablePicking)
{
enablePicking(m_enablePicking);
this->updateConnectedEditors();
}
else if (changedField == &m_showLines)
{
@@ -273,6 +265,19 @@ void RimUserDefinedPolylinesAnnotation::fieldChangedByUi(const caf::PdmFieldHand
updateVisualization();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimUserDefinedPolylinesAnnotation::defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
{
RicPolyline3dEditorAttribute* attrib = dynamic_cast<RicPolyline3dEditorAttribute*>(attribute);
if (attrib)
{
attrib->pickEventHandler = m_pickTargetsEventHandler;
attrib->enablePicking = m_enablePicking;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -22,6 +22,8 @@
#include "cafPdmFieldCvfVec3d.h"
#include "cafPdmChildArrayField.h"
#include <memory>
class RicPolylineTargetsPickEventHandler;
class RimPolylineTarget;
@@ -59,6 +61,7 @@ protected:
void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName) override;
void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
void defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override;
private:
void defineCustomContextMenu(const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget) override;
@@ -71,7 +74,8 @@ private:
caf::PdmField<QString> m_name;
caf::PdmField<bool> m_enablePicking;
caf::PdmChildArrayField<RimPolylineTarget*> m_targets;
RicPolylineTargetsPickEventHandler* m_pickTargetsEventHandler;
std::shared_ptr<RicPolylineTargetsPickEventHandler> m_pickTargetsEventHandler;
};

View File

@@ -100,11 +100,6 @@ RimWellPathGeometryDef::RimWellPathGeometryDef()
//--------------------------------------------------------------------------------------------------
RimWellPathGeometryDef::~RimWellPathGeometryDef()
{
RiuViewerCommands::removePickEventHandlerIfActive(m_pickTargetsEventHandler);
delete m_pickTargetsEventHandler;
m_pickTargetsEventHandler = nullptr;
}
//--------------------------------------------------------------------------------------------------
@@ -290,18 +285,8 @@ const RimWellPathTarget* RimWellPathGeometryDef::lastActiveTarget() const
//--------------------------------------------------------------------------------------------------
void RimWellPathGeometryDef::enableTargetPointPicking(bool isEnabling)
{
if (isEnabling)
{
m_pickPointsEnabled = true;
RiuViewerCommands::setPickEventHandler(m_pickTargetsEventHandler);
updateConnectedEditors();
}
else
{
RiuViewerCommands::removePickEventHandlerIfActive(m_pickTargetsEventHandler);
m_pickPointsEnabled = false;
updateConnectedEditors();
}
m_pickPointsEnabled = isEnabling;
this->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
@@ -333,7 +318,7 @@ void RimWellPathGeometryDef::fieldChangedByUi(const caf::PdmFieldHandle* changed
}
else if (changedField == &m_pickPointsEnabled)
{
enableTargetPointPicking(m_pickPointsEnabled);
this->updateConnectedEditors();
}
updateWellPathVisualization();
@@ -640,6 +625,19 @@ void RimWellPathGeometryDef::defineEditorAttribute(const caf::PdmFieldHandle* fi
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathGeometryDef::defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
{
RicWellPathGeometry3dEditorAttribute* attrib = dynamic_cast<RicWellPathGeometry3dEditorAttribute*>(attribute);
if (attrib)
{
attrib->pickEventHandler = m_pickTargetsEventHandler;
attrib->enablePicking = m_pickPointsEnabled;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -80,6 +80,9 @@ protected:
virtual void defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override;
private:
void fieldChangedByUi(const caf::PdmFieldHandle* changedField,
const QVariant& oldValue,
@@ -101,11 +104,12 @@ private:
caf::PdmChildArrayField<RimWellPathTarget*> m_wellTargets;
caf::PdmField< bool > m_pickPointsEnabled;
RicCreateWellTargetsPickEventHandler* m_pickTargetsEventHandler;
// Unused for now. Remove when dust settles
// TODO: Unused for now. Remove when dust settles
caf::PdmField<caf::AppEnum<WellStartType> > m_wellStartType;
caf::PdmField<double> m_kickoffDepthOrMD;
caf::PdmPtrField<RimWellPath*> m_parentWell;
std::shared_ptr<RicCreateWellTargetsPickEventHandler> m_pickTargetsEventHandler;
};

View File

@@ -10,19 +10,7 @@ else()
include(${QT_USE_FILE})
endif(CAF_USE_QT5)
# These headers need to go through Qt's MOC compiler
set (MOC_HEADER_FILES
cafPdmUiVec3dEditor.h
)
# Run MOC on the headers
add_definitions(-DCVF_USING_CMAKE)
if (CAF_USE_QT5)
qt5_wrap_cpp(MOC_SOURCE_FILES ${MOC_HEADER_FILES} )
else()
qt4_wrap_cpp(MOC_SOURCE_FILES ${MOC_HEADER_FILES} )
endif(CAF_USE_QT5)
add_library( ${PROJECT_NAME}
cafPdmCoreColor3f.h
@@ -45,10 +33,6 @@ add_library( ${PROJECT_NAME}
cafPdmXmlMat4d.cpp
cafPdmXmlMat4d.h
cafPdmFieldCvfMat4d.h
cafPdmUiVec3dEditor.cpp
${MOC_HEADER_FILES}
${MOC_SOURCE_FILES}
)
target_include_directories(${PROJECT_NAME}

View File

@@ -1,239 +0,0 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2019- Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafPdmUiVec3dEditor.h"
#include "cafFactory.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmUiDefaultObjectEditor.h"
#include "cafPdmUiFieldEditorHandle.h"
#include "cafPdmUiOrdering.h"
#include "cafPdmUniqueIdValidator.h"
#include "cafPickEventHandler.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QDoubleValidator>
#include <QHBoxLayout>
#include <QPushButton>
using namespace caf;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWidget* PdmUiVec3dEditor::createEditorWidget(QWidget* parent)
{
QWidget* containerWidget = new QWidget(parent);
QHBoxLayout* layout = new QHBoxLayout();
layout->setMargin(0);
containerWidget->setLayout(layout);
m_lineEdit = new QLineEdit(containerWidget);
connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
m_pickButton = new QPushButton(containerWidget);
m_pickButton->setText("Pick");
m_pickButton->setCheckable(true);
layout->addWidget(m_lineEdit);
layout->addWidget(m_pickButton);
connect(m_pickButton, SIGNAL(toggled(bool)), this, SLOT(pickButtonToggled(bool)));
return containerWidget;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWidget* PdmUiVec3dEditor::createLabelWidget(QWidget* parent)
{
m_label = new QLabel(parent);
return m_label;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmUiVec3dEditor::~PdmUiVec3dEditor()
{
if (pickEventHandler())
{
pickEventHandler()->unregisterAsPickEventHandler();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::PdmUiVec3dEditor::configureAndUpdateUi(const QString& uiConfigName)
{
if (!m_label.isNull())
{
PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
}
PdmUiVec3dEditorAttribute attributes;
caf::PdmUiObjectHandle* uiObject = uiObj(uiField()->fieldHandle()->ownerObject());
if (uiObject)
{
uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &attributes);
}
m_attribute = attributes;
bool isReadOnly = uiField()->isUiReadOnly(uiConfigName);
m_pickButton->setVisible(attributes.pickEventHandler != nullptr);
m_pickButton->setEnabled(!isReadOnly);
m_lineEdit->setText(uiField()->uiValue().toString());
m_lineEdit->setReadOnly(isReadOnly);
if (isReadOnly)
{
m_lineEdit->setStyleSheet("QLineEdit {"
"color: #808080;"
"background-color: #F0F0F0;}");
}
else
{
m_lineEdit->setStyleSheet("");
}
pickButtonToggled(m_attribute.startInPickingMode);
m_lineEdit->setToolTip(uiField()->uiToolTip(uiConfigName));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QMargins caf::PdmUiVec3dEditor::calculateLabelContentMargins() const
{
QSize editorSize = m_lineEdit->sizeHint();
QSize labelSize = m_label->sizeHint();
int heightDiff = editorSize.height() - labelSize.height();
QMargins contentMargins = m_label->contentsMargins();
if (heightDiff > 0)
{
contentMargins.setTop(contentMargins.top() + heightDiff / 2);
contentMargins.setBottom(contentMargins.bottom() + heightDiff / 2);
}
return contentMargins;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::PdmUiVec3dEditor::slotEditingFinished()
{
QString textValue = m_lineEdit->text();
QVariant v = textValue;
this->setValueToField(v);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::PdmUiVec3dEditor::pickButtonToggled(bool checked)
{
if (!pickEventHandler())
{
return;
}
if (checked)
{
m_lineEdit->setStyleSheet("QLineEdit {"
"color: #000000;"
"background-color: #FFDCFF;}");
m_pickButton->setText("Stop Picking");
pickEventHandler()->registerAsPickEventHandler();
m_pickButton->setChecked(true);
}
else
{
m_lineEdit->setStyleSheet("");
m_pickButton->setText("Pick");
pickEventHandler()->unregisterAsPickEventHandler();
m_pickButton->setChecked(false);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool caf::PdmUiVec3dEditor::isMultipleFieldsWithSameKeywordSelected(PdmFieldHandle* editorField) const
{
std::vector<PdmFieldHandle*> fieldsToUpdate;
fieldsToUpdate.push_back(editorField);
// For current selection, find all fields with same keyword
std::vector<PdmUiItem*> items;
SelectionManager::instance()->selectedItems(items, SelectionManager::FIRST_LEVEL);
for (size_t i = 0; i < items.size(); i++)
{
PdmUiFieldHandle* uiField = dynamic_cast<PdmUiFieldHandle*>(items[i]);
if (!uiField) continue;
PdmFieldHandle* field = uiField->fieldHandle();
if (field && field != editorField && field->keyword() == editorField->keyword())
{
fieldsToUpdate.push_back(field);
}
}
if (fieldsToUpdate.size() > 1)
{
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PickEventHandler* caf::PdmUiVec3dEditor::pickEventHandler()
{
return m_attribute.pickEventHandler.get();
}
// Define at this location to avoid duplicate symbol definitions in 'cafPdmUiDefaultObjectEditor.cpp' in a cotire build. The
// variables defined by the macro are prefixed by line numbers causing a crash if the macro is defined at the same line number.
CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiVec3dEditor);

View File

@@ -50,6 +50,7 @@ set (MOC_HEADER_FILES
cafPdmUiDoubleValueEditor.h
cafPdmUniqueIdValidator.h
cafPdmDoubleStringValidator.h
cafPdmUiPickableLineEditor.h
)
if ( NOT CMAKE_AUTOMOC )
@@ -155,7 +156,7 @@ set( PROJECT_FILES
cafPdmUniqueIdValidator.cpp
cafPdmDoubleStringValidator.cpp
cafPickEventHandler.h
cafPickEventHandler.cpp
cafPdmUiPickableLineEditor.cpp
)
add_library( ${PROJECT_NAME}

View File

@@ -116,7 +116,7 @@ protected slots:
private:
bool isMultipleFieldsWithSameKeywordSelected(PdmFieldHandle* editorField) const;
private:
protected:
QPointer<PdmUiLineEdit> m_lineEdit;
QPointer<QLabel> m_label;

View File

@@ -1,7 +1,7 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2019- Ceetron Solution AS
// Copyright (C) 2019- Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
@@ -33,12 +33,59 @@
// for more details.
//
//##################################################################################################
#include "cafPdmUiPickableLineEditor.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmUiDefaultObjectEditor.h"
#include "cafPdmUiFieldEditorHandle.h"
#include "cafPickEventHandler.h"
using namespace caf;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool caf::PickEventHandler::isObjectBeingModified(const PdmObjectHandle* object) const
caf::PdmUiPickableLineEditor::~PdmUiPickableLineEditor()
{
return m_objectBeingModified == object;
if (m_attribute.pickEventHandler)
{
m_attribute.pickEventHandler->unregisterAsPickEventHandler();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::PdmUiPickableLineEditor::configureAndUpdateUi(const QString& uiConfigName)
{
PdmUiLineEditor::configureAndUpdateUi(uiConfigName);
caf::PdmUiObjectHandle* uiObject = uiObj(uiField()->fieldHandle()->ownerObject());
if (uiObject)
{
uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &m_attribute);
}
if (m_attribute.pickEventHandler)
{
if (m_attribute.enablePicking)
{
m_attribute.pickEventHandler->registerAsPickEventHandler();
m_lineEdit->setStyleSheet("QLineEdit {"
"color: #000000;"
"background-color: #FFDCFF;}");
}
else
{
m_attribute.pickEventHandler->unregisterAsPickEventHandler();
m_lineEdit->setStyleSheet("");
}
}
m_lineEdit->setToolTip(uiField()->uiToolTip(uiConfigName));
}
// Define at this location to avoid duplicate symbol definitions in 'cafPdmUiDefaultObjectEditor.cpp' in a cotire build. The
// variables defined by the macro are prefixed by line numbers causing a crash if the macro is defined at the same line number.
CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiPickableLineEditor);

View File

@@ -36,15 +36,8 @@
#pragma once
#include "cafPdmUiLineEditor.h"
#include "cafPdmCoreVec3d.h"
#include "cvfAssert.h"
#include "cvfVector3.h"
#include <memory>
#include <vector>
class QPushButton;
namespace caf
{
@@ -53,46 +46,33 @@ class PickEventHandler;
//==================================================================================================
///
//==================================================================================================
class PdmUiVec3dEditorAttribute : public PdmUiEditorAttribute
class PdmUiPickableLineEditorAttribute : public PdmUiEditorAttribute
{
public:
PdmUiVec3dEditorAttribute() : startInPickingMode(false) {}
PdmUiPickableLineEditorAttribute() : enablePicking(false) {}
public:
bool startInPickingMode;
bool enablePicking;
std::shared_ptr<PickEventHandler> pickEventHandler;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class PdmUiVec3dEditor : public PdmUiFieldEditorHandle
class PdmUiPickableLineEditor : public PdmUiLineEditor
{
Q_OBJECT
CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT;
public:
PdmUiVec3dEditor() {}
~PdmUiVec3dEditor() override;
PdmUiPickableLineEditor() {}
~PdmUiPickableLineEditor() override;
protected:
QWidget* createEditorWidget(QWidget* parent) override;
QWidget* createLabelWidget(QWidget* parent) override;
void configureAndUpdateUi(const QString& uiConfigName) override;
QMargins calculateLabelContentMargins() const override;
void configureAndUpdateUi(const QString& uiConfigName) override;
protected slots:
void slotEditingFinished();
void pickButtonToggled(bool checked);
private:
bool isMultipleFieldsWithSameKeywordSelected(PdmFieldHandle* editorField) const;
PickEventHandler* pickEventHandler();
private:
QPointer<QLineEdit> m_lineEdit;
QPointer<QPushButton> m_pickButton;
QPointer<QLabel> m_label;
PdmUiVec3dEditorAttribute m_attribute;
PdmUiPickableLineEditorAttribute m_attribute;
};
} // end namespace caf

View File

@@ -56,18 +56,12 @@ public:
class PickEventHandler
{
public:
PickEventHandler(const PdmObjectHandle* objectBeingModified) : m_objectBeingModified(objectBeingModified) {}
bool isObjectBeingModified(const PdmObjectHandle* testObject) const;
virtual void registerAsPickEventHandler() = 0;
virtual void unregisterAsPickEventHandler() = 0;
// TODO: Rename to just handlePickEvent when the RicPickEventHandler::handlePickEvent has been renamed
virtual bool handlePickEvent(const PickEvent& eventObject) = 0;
virtual void notifyUnregistered() = 0;
private:
const PdmObjectHandle* m_objectBeingModified;
};
}