diff --git a/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.cpp b/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.cpp index 3dc23bd0c7..1ef2c2fa00 100644 --- a/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.cpp +++ b/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.cpp @@ -47,7 +47,6 @@ RicMeasurementPickEventHandler* RicMeasurementPickEventHandler::instance() /// //-------------------------------------------------------------------------------------------------- RicMeasurementPickEventHandler::RicMeasurementPickEventHandler() - : Ric3dViewPickEventHandler(nullptr) {} //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/Ric3dViewPickEventHandler.cpp b/ApplicationCode/Commands/Ric3dViewPickEventHandler.cpp index f94d682cb8..1185847025 100644 --- a/ApplicationCode/Commands/Ric3dViewPickEventHandler.cpp +++ b/ApplicationCode/Commands/Ric3dViewPickEventHandler.cpp @@ -20,13 +20,6 @@ #include -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -Ric3dViewPickEventHandler::Ric3dViewPickEventHandler(const caf::PdmObjectHandle* handlingObject) - : caf::PickEventHandler(handlingObject) -{} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/Ric3dViewPickEventHandler.h b/ApplicationCode/Commands/Ric3dViewPickEventHandler.h index aeb7347c44..2e2ce8da46 100644 --- a/ApplicationCode/Commands/Ric3dViewPickEventHandler.h +++ b/ApplicationCode/Commands/Ric3dViewPickEventHandler.h @@ -28,8 +28,6 @@ class Ric3dViewPickEventHandler : public caf::PickEventHandler { public: - Ric3dViewPickEventHandler(const caf::PdmObjectHandle* handlingObject); - // Override from caf void registerAsPickEventHandler() override; void unregisterAsPickEventHandler() override; diff --git a/ApplicationCode/Commands/RicVec3dPickEventHandler.cpp b/ApplicationCode/Commands/RicVec3dPickEventHandler.cpp index 5b397e02dc..1ddc5b835d 100644 --- a/ApplicationCode/Commands/RicVec3dPickEventHandler.cpp +++ b/ApplicationCode/Commands/RicVec3dPickEventHandler.cpp @@ -26,10 +26,8 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RicVec3dPickEventHandler::RicVec3dPickEventHandler(const caf::PdmObjectHandle* handlingObject, - caf::PdmField* vectorField) - : Ric3dViewPickEventHandler(handlingObject) - , m_vectorField(vectorField) +RicVec3dPickEventHandler::RicVec3dPickEventHandler(caf::PdmField* 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(); - if (isObjectBeingModified(selectedObject)) - { - const Rim3dView* rimView = eventObject.m_view; + const Rim3dView* rimView = eventObject.m_view; - cvf::ref transForm = rimView->displayCoordTransform(); - cvf::Vec3d pickedPositionInUTM = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint()); + cvf::ref 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; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/RicVec3dPickEventHandler.h b/ApplicationCode/Commands/RicVec3dPickEventHandler.h index 9b9108bcdf..a345f234ed 100644 --- a/ApplicationCode/Commands/RicVec3dPickEventHandler.h +++ b/ApplicationCode/Commands/RicVec3dPickEventHandler.h @@ -29,7 +29,7 @@ class Rim3dView; class RicVec3dPickEventHandler : public Ric3dViewPickEventHandler { public: - RicVec3dPickEventHandler(const caf::PdmObjectHandle* handlingObject, caf::PdmField* vectorField); + RicVec3dPickEventHandler(caf::PdmField* vectorField); bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override; diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.cpp b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.cpp index 93d0b5786b..7e1e955d09 100644 --- a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.cpp +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.cpp @@ -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 targets = geomDef->activeTargets(); diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.h b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.h index 201796364f..a0df3c30cf 100644 --- a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.h +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.h @@ -17,10 +17,39 @@ ///////////////////////////////////////////////////////////////////////////////// #pragma once + #include "cafPdmUi3dObjectEditorHandle.h" +#include "cafPdmUiFieldEditorHandle.h" + +#include + +namespace caf +{ + class PickEventHandler; +}; class RicPolylineTarget3dEditor; + +//================================================================================================== +/// +//================================================================================================== +class RicPolyline3dEditorAttribute : public caf::PdmUiEditorAttribute +{ +public: + RicPolyline3dEditorAttribute() + : enablePicking(false) + { + } + +public: + bool enablePicking; + std::shared_ptr pickEventHandler; +}; + +//================================================================================================== +/// +//================================================================================================== class RicPolyline3dEditor : public caf::PdmUi3dObjectEditorHandle { CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT; @@ -32,9 +61,9 @@ public: protected: void configureAndUpdateUi(const QString& uiConfigName) override; -private: - +private: std::vector m_targetEditors; + RicPolyline3dEditorAttribute m_attribute; }; diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp index 129d88445b..df09721c38 100644 --- a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.cpp @@ -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 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(); + } + } } diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h index 2482586881..a29bd8808e 100644 --- a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicWellPathGeometry3dEditor.h @@ -18,9 +18,25 @@ #pragma once #include "cafPdmUi3dObjectEditorHandle.h" +#include "cafPdmUiFieldEditorHandle.h" +#include + +namespace caf +{ +class PickEventHandler; +} class RicWellTarget3dEditor; + +class RicWellPathGeometry3dEditorAttribute : public caf::PdmUiEditorAttribute +{ +public: + RicWellPathGeometry3dEditorAttribute() : enablePicking(false) {} + bool enablePicking; + std::shared_ptr 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 m_targetEditors; + std::vector m_targetEditors; + RicWellPathGeometry3dEditorAttribute m_attribute; }; diff --git a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp index 26ab9d912e..587a8bad02 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp @@ -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())) - { - m_geometryToAddTargetsTo->enableTargetPointPicking(false); - - return false; - } - if (m_geometryToAddTargetsTo) { Rim3dView* rimView = eventObject.m_view; diff --git a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.h b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.h index e6e389bdbe..ff098da52b 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.h +++ b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.h @@ -34,6 +34,8 @@ public: RicCreateWellTargetsPickEventHandler(RimWellPathGeometryDef* wellGeometryDef); ~RicCreateWellTargetsPickEventHandler(); + void registerAsPickEventHandler() override; + protected: bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override; void notifyUnregistered() override; diff --git a/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.cpp b/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.cpp index df97f852ad..72cc9849e7 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.cpp @@ -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())) - { - return false; - } - if (m_polylineDef) { Rim3dView* rimView = eventObject.m_view; diff --git a/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.h b/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.h index f0df96e239..0579c027ff 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.h +++ b/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.h @@ -33,6 +33,8 @@ public: RicPolylineTargetsPickEventHandler(RimUserDefinedPolylinesAnnotation* polylineDef); ~RicPolylineTargetsPickEventHandler(); + void registerAsPickEventHandler() override; + protected: bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override; void notifyUnregistered() override; diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.cpp b/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.cpp index 69302e06b9..f8a8e3ad17 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.cpp +++ b/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.cpp @@ -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(attribute); + auto* attr = dynamic_cast(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(attribute); + if (attr) + { + if (m_centerPointPickEnabled) + { + attr->m_buttonText = "Stop"; + } + else + { + attr->m_buttonText = "Pick"; } } } diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.h b/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.h index 289bb76640..3dd1cdd54f 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.h +++ b/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.h @@ -76,6 +76,7 @@ private: caf::PdmField m_isActive; caf::PdmField m_centerPointXyd; + caf::PdmField m_centerPointPickEnabled; caf::PdmField m_radius; caf::PdmField m_name; caf::PdmChildField m_appearance; diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.cpp b/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.cpp index c41cfd40f4..af16a24ee3 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.cpp +++ b/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.cpp @@ -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 #include @@ -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(attribute); + caf::PdmUiPickableLineEditorAttribute* attr = dynamic_cast(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(attribute); + if (pbAttribute) + { + auto boolField = static_cast*>(field); + if (boolField->v()) + { + pbAttribute->m_buttonText = "Stop"; + } + else + { + pbAttribute->m_buttonText = "Pick"; + } + } + } + } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.h b/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.h index 607a889e3b..03b5612422 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.h +++ b/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.h @@ -84,7 +84,9 @@ private: QString extractNameFromText() const; caf::PdmField m_anchorPointXyd; + caf::PdmField m_anchorPointPickEnabledButtonField; caf::PdmField m_labelPointXyd; + caf::PdmField m_labelPointPickEnabledButtonField; caf::PdmField m_text; caf::PdmField m_isActive; diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimUserDefinedPolylinesAnnotation.cpp b/ApplicationCode/ProjectDataModel/Annotations/RimUserDefinedPolylinesAnnotation.cpp index ce9e0f96f8..358cfd985b 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimUserDefinedPolylinesAnnotation.cpp +++ b/ApplicationCode/ProjectDataModel/Annotations/RimUserDefinedPolylinesAnnotation.cpp @@ -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(attribute); + if (attrib) + { + attrib->pickEventHandler = m_pickTargetsEventHandler; + attrib->enablePicking = m_enablePicking; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimUserDefinedPolylinesAnnotation.h b/ApplicationCode/ProjectDataModel/Annotations/RimUserDefinedPolylinesAnnotation.h index 4be8695567..2920cbe2f9 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimUserDefinedPolylinesAnnotation.h +++ b/ApplicationCode/ProjectDataModel/Annotations/RimUserDefinedPolylinesAnnotation.h @@ -22,6 +22,8 @@ #include "cafPdmFieldCvfVec3d.h" #include "cafPdmChildArrayField.h" +#include + 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 m_name; caf::PdmField m_enablePicking; caf::PdmChildArrayField m_targets; - RicPolylineTargetsPickEventHandler* m_pickTargetsEventHandler; + + std::shared_ptr m_pickTargetsEventHandler; }; diff --git a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp index 70b43ba4fc..2721af9302 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp @@ -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(attribute); + if (attrib) + { + attrib->pickEventHandler = m_pickTargetsEventHandler; + attrib->enablePicking = m_pickPointsEnabled; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.h b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.h index b43a2627dd..522545d401 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.h +++ b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.h @@ -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 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 > m_wellStartType; caf::PdmField m_kickoffDepthOrMD; caf::PdmPtrField m_parentWell; + + std::shared_ptr m_pickTargetsEventHandler; }; diff --git a/Fwk/AppFwk/cafPdmCvf/CMakeLists.txt b/Fwk/AppFwk/cafPdmCvf/CMakeLists.txt index 0f84bf0ddf..b5723987c4 100644 --- a/Fwk/AppFwk/cafPdmCvf/CMakeLists.txt +++ b/Fwk/AppFwk/cafPdmCvf/CMakeLists.txt @@ -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} diff --git a/Fwk/AppFwk/cafPdmCvf/cafPdmUiVec3dEditor.cpp b/Fwk/AppFwk/cafPdmCvf/cafPdmUiVec3dEditor.cpp deleted file mode 100644 index e3dab9117b..0000000000 --- a/Fwk/AppFwk/cafPdmCvf/cafPdmUiVec3dEditor.cpp +++ /dev/null @@ -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 <> -// 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 <> -// 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 -#include -#include -#include - -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 fieldsToUpdate; - fieldsToUpdate.push_back(editorField); - - // For current selection, find all fields with same keyword - std::vector items; - SelectionManager::instance()->selectedItems(items, SelectionManager::FIRST_LEVEL); - - for (size_t i = 0; i < items.size(); i++) - { - PdmUiFieldHandle* uiField = dynamic_cast(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); diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index ddf3f1e6b3..64fff3d740 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -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} diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h index 555cde5c41..1440dd1dc9 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiLineEditor.h @@ -116,7 +116,7 @@ protected slots: private: bool isMultipleFieldsWithSameKeywordSelected(PdmFieldHandle* editorField) const; -private: +protected: QPointer m_lineEdit; QPointer m_label; diff --git a/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiPickableLineEditor.cpp similarity index 50% rename from Fwk/AppFwk/cafUserInterface/cafPickEventHandler.cpp rename to Fwk/AppFwk/cafUserInterface/cafPdmUiPickableLineEditor.cpp index 835a8b5f17..5078a5fca1 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiPickableLineEditor.cpp @@ -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); diff --git a/Fwk/AppFwk/cafPdmCvf/cafPdmUiVec3dEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiPickableLineEditor.h similarity index 69% rename from Fwk/AppFwk/cafPdmCvf/cafPdmUiVec3dEditor.h rename to Fwk/AppFwk/cafUserInterface/cafPdmUiPickableLineEditor.h index 3ff2b320d3..53c47f2d8f 100644 --- a/Fwk/AppFwk/cafPdmCvf/cafPdmUiVec3dEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiPickableLineEditor.h @@ -36,15 +36,8 @@ #pragma once #include "cafPdmUiLineEditor.h" -#include "cafPdmCoreVec3d.h" - -#include "cvfAssert.h" -#include "cvfVector3.h" #include -#include - -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; }; //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -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 m_lineEdit; - QPointer m_pickButton; - QPointer m_label; - - PdmUiVec3dEditorAttribute m_attribute; + PdmUiPickableLineEditorAttribute m_attribute; }; } // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.h b/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.h index 3c6f5fd860..0e64ca667f 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.h +++ b/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.h @@ -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; }; }