AppFwk: Moved PdmUi3dObjectEditorHandle and PdmUiSelection3dEditorVisualizer into correct place in PdmUiCore

This commit is contained in:
Jacob Støren 2018-11-27 10:31:54 +01:00
parent 318cd76b64
commit 3c32595e25
8 changed files with 376 additions and 209 deletions

View File

@ -566,129 +566,8 @@ cvf::ref<cvf::Part> RicPointTangentManipulatorPartMgr::createPart(cvf::DrawableG
return part; return part;
} }
//==================================================================================================
///
///
///
//==================================================================================================
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUi3dObjectEditorHandle::PdmUi3dObjectEditorHandle()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUi3dObjectEditorHandle::~PdmUi3dObjectEditorHandle()
{
}
//--------------------------------------------------------------------------------------------------
/// Not allowed to change viewer. Should be constructor argument, but makes factory stuff difficult.
//--------------------------------------------------------------------------------------------------
void PdmUi3dObjectEditorHandle::setViewer(QWidget* ownerViewer)
{
CAF_ASSERT(m_ownerViewer.isNull());
m_ownerViewer = ownerViewer;
}
}
//==================================================================================================
///
///
///
//==================================================================================================
#include "cafSelectionManager.h"
#include "RimWellPathGeometryDef.h"
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUiSelection3dEditorVisualizer::PdmUiSelection3dEditorVisualizer(QWidget* ownerViewer)
: m_ownerViewer(ownerViewer)
{
this->setParent(ownerViewer); // Makes this owned by the viewer.
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUiSelection3dEditorVisualizer::~PdmUiSelection3dEditorVisualizer()
{
for (auto editor: m_active3DEditors)
{
delete editor;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiSelection3dEditorVisualizer::updateVisibleEditors()
{
for (auto editor: m_active3DEditors)
{
if (editor) editor->updateUi();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiSelection3dEditorVisualizer::onSelectionManagerSelectionChanged( const std::set<int>& changedSelectionLevels )
{
if (!changedSelectionLevels.count(0)) return;
for (auto editor: m_active3DEditors)
{
delete editor;
}
m_active3DEditors.clear();
if (!m_ownerViewer) return;
std::vector<RimWellPathGeometryDef*> wellPathGeomDefs;
caf::SelectionManager::instance()->objectsByType(&wellPathGeomDefs);
std::set<PdmUiItem*> totalSelection;
for ( int selLevel: changedSelectionLevels )
{
std::vector<PdmUiItem*> 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<PdmObjectHandle*>(item);
if (itemObject)
{
PdmUi3dObjectEditorHandle* editor3d = caf::Factory<PdmUi3dObjectEditorHandle, QString>::instance()->create(editor3dTypeName);
editor3d->setViewer(m_ownerViewer);
editor3d->setPdmObject(itemObject);
m_active3DEditors.push_back(editor3d);
editor3d->updateUi();
}
}
}
m_ownerViewer->update();
}
} // caf
//================================================================================================== //==================================================================================================
/// ///
@ -697,6 +576,7 @@ void PdmUiSelection3dEditorVisualizer::onSelectionManagerSelectionChanged( const
//================================================================================================== //==================================================================================================
#include "RimWellPathTarget.h" #include "RimWellPathTarget.h"
#include "RimWellPathGeometryDef.h"
CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicWellPathGeometry3dEditor); CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicWellPathGeometry3dEditor);

View File

@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2018- Statoil ASA // Copyright (C) 2018- equinor ASA
// //
// ResInsight is free software: you can redistribute it and/or modify // ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -171,88 +171,7 @@ private:
/// ///
/// ///
//================================================================================================== //==================================================================================================
#include "cafPdmUi3dObjectEditorHandle.h"
#include "cafSelectionChangedReceiver.h"
#include "cafPdmUiObjectEditorHandle.h"
#include "cafFactory.h"
#include <QWidget>
// PdmUiObjectEditorHandle -<| PdmUiWidgetObjectEditorHandle --<| PdmUiFormLayoutObjectEditor
// -<| PdmUi3dObjectEditorHandle
namespace caf
{
//==================================================================================================
/// Macros helping in development of PDM UI 3d editors
//==================================================================================================
/// CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT assists the factory used when creating editors
/// Place this in the header file inside the class definition of your PdmUiEditor
#define CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT \
public: \
static QString uiEditorTypeName()
/// CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT implements editorTypeName() and registers the field editor in the field editor factory
/// Place this in the cpp file, preferably above the constructor
#define CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(EditorClassName) \
QString EditorClassName::uiEditorTypeName() { return #EditorClassName; } \
CAF_FACTORY_REGISTER(caf::PdmUi3dObjectEditorHandle, EditorClassName, QString, EditorClassName::uiEditorTypeName())
class PdmUi3dObjectEditorHandle : public caf::PdmUiObjectEditorHandle
{
public:
PdmUi3dObjectEditorHandle();
~PdmUi3dObjectEditorHandle() override;
void setViewer(QWidget* ownerViewer);
protected:
QWidget* ownerViewer() { return m_ownerViewer;}
private:
QPointer<QWidget> m_ownerViewer;
};
//==================================================================================================
///
///
///
//==================================================================================================
// Selected object 3D editor visualizer
class PdmUiSelection3dEditorVisualizer : public QObject, caf::SelectionChangedReceiver
{
Q_OBJECT
public:
PdmUiSelection3dEditorVisualizer(QWidget* ownerViewer);
~PdmUiSelection3dEditorVisualizer() override;
void setConfigName(const QString& configName) { m_configName = configName; }
void updateVisibleEditors();
private:
void onSelectionManagerSelectionChanged( const std::set<int>& changedSelectionLevels ) override;
std::vector< QPointer<PdmUi3dObjectEditorHandle> > m_active3DEditors;
QPointer<QWidget> m_ownerViewer;
QString m_configName;
};
}
//==================================================================================================
///
///
///
//==================================================================================================
class RicWellTarget3dEditor; class RicWellTarget3dEditor;
@ -277,6 +196,7 @@ private:
/// ///
/// ///
//================================================================================================== //==================================================================================================
#include "cafPdmUi3dObjectEditorHandle.h"
class RicWellTarget3dEditor : public caf::PdmUi3dObjectEditorHandle class RicWellTarget3dEditor : public caf::PdmUi3dObjectEditorHandle
@ -299,7 +219,3 @@ private:
QPointer<RicPointTangentManipulator> m_manipulator; QPointer<RicPointTangentManipulator> m_manipulator;
cvf::ref<cvf::ModelBasicList> m_cvfModel; cvf::ref<cvf::ModelBasicList> m_cvfModel;
}; };
class RiuViewer;
// 3D editor manager

View File

@ -41,6 +41,8 @@
#include "RiuSimpleHistogramWidget.h" #include "RiuSimpleHistogramWidget.h"
#include "RiuViewerCommands.h" #include "RiuViewerCommands.h"
#include "cafPdmUiSelection3dEditorVisualizer.h"
#include "cafTitledOverlayFrame.h" #include "cafTitledOverlayFrame.h"
#include "cafCategoryLegend.h" #include "cafCategoryLegend.h"
#include "cafOverlayScalarMapperLegend.h" #include "cafOverlayScalarMapperLegend.h"
@ -68,7 +70,6 @@
#include "WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.h" #include "WindowEdgeAxesOverlayItem/RivWindowEdgeAxesOverlayItem.h"
#include <algorithm> #include <algorithm>
#include "WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h"
using cvf::ManipulatorTrackball; using cvf::ManipulatorTrackball;

View File

@ -13,6 +13,7 @@ include_directories (
# These headers need to go through Qt's MOC compiler # These headers need to go through Qt's MOC compiler
set( QOBJECT_HEADERS set( QOBJECT_HEADERS
cafPdmUiFieldEditorHandle.h cafPdmUiFieldEditorHandle.h
cafPdmUiSelection3dEditorVisualizer.h
) )
if ( NOT CMAKE_AUTOMOC ) if ( NOT CMAKE_AUTOMOC )
@ -41,6 +42,8 @@ set( PROJECT_FILES
cafPdmUiObjectEditorHandle.h cafPdmUiObjectEditorHandle.h
cafPdmUiWidgetObjectEditorHandle.cpp cafPdmUiWidgetObjectEditorHandle.cpp
cafPdmUiWidgetObjectEditorHandle.h cafPdmUiWidgetObjectEditorHandle.h
cafPdmUi3dObjectEditorHandle.cpp
cafPdmUi3dObjectEditorHandle.h
cafPdmUiObjectHandle.cpp cafPdmUiObjectHandle.cpp
cafPdmUiObjectHandle.h cafPdmUiObjectHandle.h
cafPdmUiOrdering.cpp cafPdmUiOrdering.cpp
@ -58,6 +61,8 @@ set( PROJECT_FILES
cafSelectionChangedReceiver.h cafSelectionChangedReceiver.h
cafSelectionChangedReceiver.cpp cafSelectionChangedReceiver.cpp
cafSelectionManagerTools.h cafSelectionManagerTools.h
cafPdmUiSelection3dEditorVisualizer.h
cafPdmUiSelection3dEditorVisualizer.cpp
) )
add_library( ${PROJECT_NAME} add_library( ${PROJECT_NAME}

View File

@ -0,0 +1,72 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 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 "cafPdmUi3dObjectEditorHandle.h"
//==================================================================================================
///
///
///
//==================================================================================================
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUi3dObjectEditorHandle::PdmUi3dObjectEditorHandle()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUi3dObjectEditorHandle::~PdmUi3dObjectEditorHandle()
{
}
//--------------------------------------------------------------------------------------------------
/// The viewer widget set here is provided by the PdmUiSelection3dEditorVisualizer and is expected
/// to be cast able to whatever is needed in subclasses.
/// Not allowed to change. Should be constructor argument, but makes factory stuff difficult.
//--------------------------------------------------------------------------------------------------
void PdmUi3dObjectEditorHandle::setViewer(QWidget* ownerViewer)
{
CAF_ASSERT(m_ownerViewer.isNull());
m_ownerViewer = ownerViewer;
}
}

View File

@ -0,0 +1,89 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 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.
//
//##################################################################################################
#pragma once
#include "cafPdmUiObjectEditorHandle.h"
#include "cafFactory.h"
#include <QWidget>
#include <QPointer>
// PdmUiObjectEditorHandle -<| PdmUiWidgetObjectEditorHandle --<| PdmUiFormLayoutObjectEditor
// -<| PdmUi3dObjectEditorHandle
namespace caf
{
//==================================================================================================
/// Macros helping in development of PDM UI 3d editors
//==================================================================================================
/// CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT assists the factory used when creating editors
/// Place this in the header file inside the class definition of your PdmUiEditor
#define CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT \
public: \
static QString uiEditorTypeName()
/// CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT implements editorTypeName() and registers the field editor in the field editor factory
/// Place this in the cpp file, preferably above the constructor
#define CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(EditorClassName) \
QString EditorClassName::uiEditorTypeName() { return #EditorClassName; } \
CAF_FACTORY_REGISTER(caf::PdmUi3dObjectEditorHandle, EditorClassName, QString, EditorClassName::uiEditorTypeName())
//==================================================================================================
/// Abstract class for 3D editors editing complete PdmObjects
//==================================================================================================
class PdmUi3dObjectEditorHandle : public caf::PdmUiObjectEditorHandle
{
public:
PdmUi3dObjectEditorHandle();
~PdmUi3dObjectEditorHandle() override;
void setViewer(QWidget* ownerViewer);
protected:
QWidget* ownerViewer() { return m_ownerViewer;}
private:
QPointer<QWidget> m_ownerViewer;
};
}

View File

@ -0,0 +1,127 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 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 "cafPdmUiSelection3dEditorVisualizer.h"
//==================================================================================================
///
///
///
//==================================================================================================
#include "cafSelectionManager.h"
namespace caf
{
//--------------------------------------------------------------------------------------------------
/// The ownerViewer will take over ownership of this class. The ownerViewer is also the viewer distributed to
/// the 3dEditors created by this class to make them know where to exist.
//--------------------------------------------------------------------------------------------------
PdmUiSelection3dEditorVisualizer::PdmUiSelection3dEditorVisualizer(QWidget* ownerViewer)
: m_ownerViewer(ownerViewer)
{
this->setParent(ownerViewer); // Makes this owned by the viewer.
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUiSelection3dEditorVisualizer::~PdmUiSelection3dEditorVisualizer()
{
for (auto editor: m_active3DEditors)
{
delete editor;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiSelection3dEditorVisualizer::updateVisibleEditors()
{
for (auto editor: m_active3DEditors)
{
if (editor) editor->updateUi();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiSelection3dEditorVisualizer::onSelectionManagerSelectionChanged( const std::set<int>& changedSelectionLevels )
{
if (!changedSelectionLevels.count(0)) return;
for (auto editor: m_active3DEditors)
{
delete editor;
}
m_active3DEditors.clear();
if (!m_ownerViewer) return;
std::set<PdmUiItem*> totalSelection;
for ( int selLevel: changedSelectionLevels )
{
std::vector<PdmUiItem*> 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<PdmObjectHandle*>(item);
if (itemObject)
{
PdmUi3dObjectEditorHandle* editor3d = caf::Factory<PdmUi3dObjectEditorHandle, QString>::instance()->create(editor3dTypeName);
editor3d->setViewer(m_ownerViewer);
editor3d->setPdmObject(itemObject);
m_active3DEditors.push_back(editor3d);
editor3d->updateUi();
}
}
}
m_ownerViewer->update();
}
} // end namespace caf

View File

@ -0,0 +1,77 @@
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 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.
//
//##################################################################################################
#pragma once
#include "cafSelectionChangedReceiver.h"
#include "cafPdmUi3dObjectEditorHandle.h"
#include <QObject>
#include <QPointer>
#include <QString>
#include <vector>
namespace caf
{
//==================================================================================================
///
///
///
//==================================================================================================
// Selected object 3D editor visualizer
class PdmUiSelection3dEditorVisualizer : public QObject, caf::SelectionChangedReceiver
{
Q_OBJECT
public:
PdmUiSelection3dEditorVisualizer(QWidget* ownerViewer);
~PdmUiSelection3dEditorVisualizer() override;
void setConfigName(const QString& configName) { m_configName = configName; }
void updateVisibleEditors();
private:
void onSelectionManagerSelectionChanged( const std::set<int>& changedSelectionLevels ) override;
std::vector< QPointer<PdmUi3dObjectEditorHandle> > m_active3DEditors;
QPointer<QWidget> m_ownerViewer;
QString m_configName;
};
}