From fb93ad7ca750ae9a538315fe4557290cd9d35562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 26 Nov 2018 21:50:46 +0100 Subject: [PATCH] AppFwk: Make PdmUiSelection3dEditorVisualizer generic, ready to be moved to a separate file --- .../RicPointTangentManipulator.cpp | 43 ++++++++++++------- .../RicPointTangentManipulator.h | 12 +++--- .../RimWellPathGeometryDef.cpp | 2 + ApplicationCode/UserInterface/RiuViewer.cpp | 2 +- ApplicationCode/UserInterface/RiuViewer.h | 4 +- .../cafPdmUiCore/cafPdmUiItem.cpp | 24 +++++++++++ .../cafPdmUiCore/cafPdmUiItem.h | 24 +++++++++-- 7 files changed, 84 insertions(+), 27 deletions(-) diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.cpp b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.cpp index 10a8fa81f0..62017208c6 100644 --- a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.cpp +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.cpp @@ -614,7 +614,7 @@ namespace caf //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -PdmUiSelectionVisualizer3d::PdmUiSelectionVisualizer3d(caf::Viewer* ownerViewer) +PdmUiSelection3dEditorVisualizer::PdmUiSelection3dEditorVisualizer(caf::Viewer* ownerViewer) : m_ownerViewer(ownerViewer) { this->setParent(ownerViewer); // Makes this owned by the viewer. @@ -623,7 +623,7 @@ PdmUiSelectionVisualizer3d::PdmUiSelectionVisualizer3d(caf::Viewer* ownerViewer) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -PdmUiSelectionVisualizer3d::~PdmUiSelectionVisualizer3d() +PdmUiSelection3dEditorVisualizer::~PdmUiSelection3dEditorVisualizer() { for (auto editor: m_active3DEditors) { @@ -634,7 +634,7 @@ PdmUiSelectionVisualizer3d::~PdmUiSelectionVisualizer3d() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void PdmUiSelectionVisualizer3d::updateVisibleEditors() +void PdmUiSelection3dEditorVisualizer::updateVisibleEditors() { for (auto editor: m_active3DEditors) { @@ -645,7 +645,7 @@ void PdmUiSelectionVisualizer3d::updateVisibleEditors() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void PdmUiSelectionVisualizer3d::onSelectionManagerSelectionChanged( const std::set& changedSelectionLevels ) +void PdmUiSelection3dEditorVisualizer::onSelectionManagerSelectionChanged( const std::set& changedSelectionLevels ) { if (!changedSelectionLevels.count(0)) return; @@ -658,23 +658,34 @@ void PdmUiSelectionVisualizer3d::onSelectionManagerSelectionChanged( const std:: if (!m_ownerViewer) return; - // Todo: How do we deduce the editor from the selected object ? - // Alt 1: Register the rim object type name as key in the factory as well - // Alt 2: Set the editor type name as PdmUiItem::setUiEditorTypeName - // Alt 3: Use a specific config-name in alt 2. - // Alt 4: Introduce a PdmUiItem::editorTypeName3d - std::vector wellPathGeomDefs; caf::SelectionManager::instance()->objectsByType(&wellPathGeomDefs); - for (auto geomDef: wellPathGeomDefs) + std::set totalSelection; + for ( int selLevel: changedSelectionLevels ) { - auto editor = new RicWellPathGeometry3dEditor(); - editor->setViewer(m_ownerViewer); - editor->setPdmObject(geomDef); - m_active3DEditors.push_back(editor); - editor->updateUi(); + std::vector items; + caf::SelectionManager::instance()->selectedItems(items, selLevel ); + totalSelection.insert(items.begin(), items.end()); } + + for (PdmUiItem* item: totalSelection) + { + QString editor3dTypeName = item->ui3dEditorTypeName(m_configName); + if (!editor3dTypeName.isEmpty()) + { + PdmObjectHandle* itemObject = dynamic_cast(item); + if (itemObject) + { + PdmUi3dObjectEditorHandle* editor3d = caf::Factory::instance()->create(editor3dTypeName); + editor3d->setViewer(m_ownerViewer); + editor3d->setPdmObject(itemObject); + m_active3DEditors.push_back(editor3d); + editor3d->updateUi(); + } + } + } + m_ownerViewer->update(); } diff --git a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h index 0326cd7fcd..2c4ec00b6e 100644 --- a/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h +++ b/ApplicationCode/Commands/WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h @@ -223,20 +223,22 @@ protected: // Selected object 3D editor visualizer -class PdmUiSelectionVisualizer3d : public QObject, caf::SelectionChangedReceiver +class PdmUiSelection3dEditorVisualizer : public QObject, caf::SelectionChangedReceiver { Q_OBJECT public: - PdmUiSelectionVisualizer3d(caf::Viewer* ownerViewer); - ~PdmUiSelectionVisualizer3d() override; + PdmUiSelection3dEditorVisualizer(caf::Viewer* ownerViewer); + ~PdmUiSelection3dEditorVisualizer() override; + + void setConfigName(const QString& configName) { m_configName = configName; } void updateVisibleEditors(); protected: void onSelectionManagerSelectionChanged( const std::set& changedSelectionLevels ) override; std::vector< QPointer > m_active3DEditors; - - QPointer m_ownerViewer; + QPointer m_ownerViewer; + QString m_configName; }; diff --git a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp index 290636bc0b..6cc5df78b7 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp @@ -38,6 +38,7 @@ #include "cafPdmUiTableViewEditor.h" #include "cafPdmUiTreeOrdering.h" #include "cvfGeometryTools.h" +#include "WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h" namespace caf @@ -64,6 +65,7 @@ RimWellPathGeometryDef::RimWellPathGeometryDef() { CAF_PDM_InitObject("Well Targets", ":/WellTargets.png", "", ""); + this->setUi3dEditorTypeName(RicWellPathGeometry3dEditor::uiEditorTypeName()); CAF_PDM_InitField(&m_referencePointUtmXyd, "ReferencePosUtmXyd", cvf::Vec3d(0,0,0), "UTM Reference Point", "", "", ""); CAF_PDM_InitField(&m_mdrkbAtFirstTarget, "MdrkbAtFirstTarget", 0.0, "MDRKB at First Target", "", "", ""); diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 02b36ea3b7..5bde89251c 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -189,7 +189,7 @@ RiuViewer::RiuViewer(const QGLFormat& format, QWidget* parent) m_windowEdgeAxisOverlay = new RivWindowEdgeAxesOverlayItem(standardFont); m_showWindowEdgeAxes = false; - m_selectionVisualizerManager = new caf::PdmUiSelectionVisualizer3d(this); + m_selectionVisualizerManager = new caf::PdmUiSelection3dEditorVisualizer(this); m_scaleLegend = new caf::OverlayScaleLegend(standardFont); m_scaleLegend->setOrientation(caf::OverlayScaleLegend::HORIZONTAL); diff --git a/ApplicationCode/UserInterface/RiuViewer.h b/ApplicationCode/UserInterface/RiuViewer.h index c0d9dc1a36..15d62a4b3c 100644 --- a/ApplicationCode/UserInterface/RiuViewer.h +++ b/ApplicationCode/UserInterface/RiuViewer.h @@ -46,7 +46,7 @@ namespace caf { class OverlayScaleLegend; class TitledOverlayFrame; - class PdmUiSelectionVisualizer3d; + class PdmUiSelection3dEditorVisualizer; } namespace cvf @@ -172,7 +172,7 @@ private: cvf::ref m_windowEdgeAxisOverlay; bool m_showWindowEdgeAxes; - caf::PdmUiSelectionVisualizer3d* m_selectionVisualizerManager; + caf::PdmUiSelection3dEditorVisualizer* m_selectionVisualizerManager; cvf::Vec3d m_cursorPositionDomainCoords; bool m_isNavigationRotationEnabled; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp index 7b2a30549a..cca07972ea 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp @@ -418,6 +418,30 @@ void PdmUiItem::setUiEditorTypeName(const QString& editorTypeName, const QString m_configItemInfos[uiConfigName].m_editorTypeName = editorTypeName; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString PdmUiItem::ui3dEditorTypeName(const QString& uiConfigName) const +{ + const PdmUiItemInfo* conInfo = configInfo(uiConfigName); + const PdmUiItemInfo* defInfo = defaultInfo(); + const PdmUiItemInfo* sttInfo = m_staticItemInfo; + + if (conInfo && !(conInfo->m_3dEditorTypeName.isEmpty())) return conInfo->m_3dEditorTypeName; + if (defInfo && !(defInfo->m_3dEditorTypeName.isEmpty())) return defInfo->m_3dEditorTypeName; + if (sttInfo && !(sttInfo->m_3dEditorTypeName.isEmpty())) return sttInfo->m_3dEditorTypeName; + + return QString(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiItem::setUi3dEditorTypeName(const QString& editorTypeName, const QString& uiConfigName /*= ""*/) +{ + m_configItemInfos[uiConfigName].m_3dEditorTypeName = editorTypeName; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h index 9b67ecfd25..f1bcc325fa 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h @@ -56,12 +56,26 @@ class PdmUiItemInfo { public: PdmUiItemInfo() - : m_editorTypeName(""), m_isHidden(-1), m_isTreeChildrenHidden(-1), m_isReadOnly(-1), m_labelAlignment(LEFT), m_isCustomContextMenuEnabled(-1) + : m_editorTypeName("") + , m_isHidden(-1) + , m_isTreeChildrenHidden(-1) + , m_isReadOnly(-1) + , m_labelAlignment(LEFT) + , m_isCustomContextMenuEnabled(-1) {} PdmUiItemInfo(const QString& uiName, QIcon icon = QIcon(), QString toolTip = "", QString whatsThis = "", QString extraDebugText = "") - : m_uiName(uiName), m_icon(icon), m_toolTip(toolTip), m_whatsThis(whatsThis), m_extraDebugText(extraDebugText), - m_editorTypeName(""), m_isHidden(false), m_isTreeChildrenHidden(false), m_isReadOnly(false), m_labelAlignment(LEFT), m_isCustomContextMenuEnabled(false) + : m_uiName(uiName) + , m_icon(icon) + , m_toolTip(toolTip) + , m_whatsThis(whatsThis) + , m_extraDebugText(extraDebugText) + , m_editorTypeName("") + , m_isHidden(false) + , m_isTreeChildrenHidden(false) + , m_isReadOnly(false) + , m_labelAlignment(LEFT) + , m_isCustomContextMenuEnabled(false) { } enum LabelPosType { LEFT, TOP, HIDDEN }; @@ -75,6 +89,7 @@ private: QString m_whatsThis; QString m_extraDebugText; QString m_editorTypeName; ///< Use this exact type of editor to edit this UiItem + QString m_3dEditorTypeName; ///< If set, use this editor type to edit this UiItem in 3D int m_isHidden; ///< UiItem should be hidden. -1 means not set int m_isTreeChildrenHidden; ///< Children of UiItem should be hidden. -1 means not set int m_isReadOnly; ///< UiItem should be insensitive, or read only. -1 means not set. @@ -236,6 +251,9 @@ public: QString uiEditorTypeName(const QString& uiConfigName) const; void setUiEditorTypeName(const QString& editorTypeName, const QString& uiConfigName = ""); + QString ui3dEditorTypeName(const QString& uiConfigName) const; + void setUi3dEditorTypeName(const QString& editorTypeName, const QString& uiConfigName = ""); + virtual bool isUiGroup() const; /// Intended to be called when fields in an object has been changed