#884 RimIntersectionBox now manages the box manipulator object

This commit is contained in:
Magne Sjaastad 2016-09-30 12:33:32 +02:00
parent b4ec6b3a81
commit 1537b8c0d1
4 changed files with 161 additions and 13 deletions

View File

@ -214,6 +214,7 @@ set ( QT_MOC_HEADERS
Application/RiaApplication.h
ProjectDataModel/RimMimeData.h
ProjectDataModel/RimIntersectionBox.h
UserInterface/RiuMainWindowBase.h
UserInterface/RiuMainWindow.h

View File

@ -18,13 +18,20 @@
#include "RimIntersectionBox.h"
#include "RimCase.h"
#include "RimEclipseView.h"
#include "RimView.h"
#include "IntersectionBoxCommands/RicBoxManipulatorEventHandler.h"
#include "RiuViewer.h"
#include "RivIntersectionBoxPartMgr.h"
#include "cafPdmUiSliderEditor.h"
#include "RimCase.h"
#include "cafPdmUiDoubleSliderEditor.h"
#include "RimEclipseView.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiSliderEditor.h"
#include "cafDisplayCoordTransform.h"
namespace caf
@ -76,6 +83,12 @@ RimIntersectionBox::RimIntersectionBox()
CAF_PDM_InitField (&showInactiveCells, "ShowInactiveCells", false, "Inactive Cells", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_show3DManipulator, "show3DManipulator", "", "", "", "");
m_show3DManipulator.xmlCapability()->setIOWritable(false);
m_show3DManipulator.xmlCapability()->setIOReadable(false);
m_show3DManipulator.uiCapability()->setUiEditorTypeName(caf::PdmUiPushButtonEditor::uiEditorTypeName());
m_show3DManipulator = false;
}
//--------------------------------------------------------------------------------------------------
@ -83,7 +96,12 @@ RimIntersectionBox::RimIntersectionBox()
//--------------------------------------------------------------------------------------------------
RimIntersectionBox::~RimIntersectionBox()
{
if (m_boxManipulator && viewer())
{
viewer()->removeStaticModel(m_boxManipulator->model());
m_boxManipulator->deleteLater();
}
}
//--------------------------------------------------------------------------------------------------
@ -228,6 +246,61 @@ void RimIntersectionBox::fieldChangedByUi(const caf::PdmFieldHandle* changedFiel
{
m_maxDepth = CVF_MAX(m_maxDepth, m_minDepth);
}
else if (changedField == &m_show3DManipulator)
{
if (m_show3DManipulator)
{
if (viewer())
{
m_boxManipulator = new RicBoxManipulatorEventHandler(viewer());
connect(m_boxManipulator, SIGNAL(notifyRedraw()), this, SLOT(slotScheduleRedraw()));
connect(m_boxManipulator, SIGNAL(notifyUpdate(const cvf::Vec3d&, const cvf::Vec3d&)), this, SLOT(slotUpdateGeometry(const cvf::Vec3d&, const cvf::Vec3d&)));
RimView* rimView = nullptr;
this->firstAncestorOrThisOfType(rimView);
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
m_boxManipulator->setOrigin(transForm->transformToDisplayCoord(boxOrigin().translation()));
m_boxManipulator->setSize(transForm->scaleToDisplaySize(boxSize()));
}
}
else
{
if (m_boxManipulator)
{
if (viewer())
{
viewer()->removeStaticModel(m_boxManipulator->model());
}
m_boxManipulator->deleteLater();
m_boxManipulator = nullptr;
}
}
}
if (changedField == &m_minXCoord ||
changedField == &m_minYCoord ||
changedField == &m_minDepth ||
changedField == &m_maxXCoord ||
changedField == &m_maxYCoord ||
changedField == &m_maxDepth)
{
if (m_boxManipulator)
{
RimView* rimView = nullptr;
this->firstAncestorOrThisOfType(rimView);
if (rimView)
{
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
m_boxManipulator->setOrigin(transForm->transformToDisplayCoord(boxOrigin().translation()));
m_boxManipulator->setSize(transForm->scaleToDisplaySize(boxSize()));
}
}
}
if (changedField != &name)
@ -262,6 +335,20 @@ void RimIntersectionBox::defineEditorAttribute(const caf::PdmFieldHandle* field,
myAttr->m_maximum = -cellsBoundingBox.min().z();
}
}
if (field == &m_show3DManipulator)
{
caf::PdmUiPushButtonEditorAttribute* attrib = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*> (attribute);
if (m_show3DManipulator)
{
attrib->m_buttonText = "Hide3D manipulator";
}
else
{
attrib->m_buttonText = "Show 3D manipulator";
}
}
}
//--------------------------------------------------------------------------------------------------
@ -270,6 +357,7 @@ void RimIntersectionBox::defineEditorAttribute(const caf::PdmFieldHandle* field,
void RimIntersectionBox::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
uiOrdering.add(&name);
uiOrdering.add(&m_show3DManipulator);
uiOrdering.add(&m_singlePlaneState);
cvf::BoundingBox cellsBoundingBox = currentCellBoundingBox();
@ -302,6 +390,41 @@ void RimIntersectionBox::initAfterRead()
updateVisibility();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIntersectionBox::slotScheduleRedraw()
{
if (viewer())
{
viewer()->addStaticModelOnce(m_boxManipulator->model());
RimView* rimView = nullptr;
this->firstAncestorOrThisOfType(rimView);
rimView->scheduleCreateDisplayModelAndRedraw();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimIntersectionBox::slotUpdateGeometry(const cvf::Vec3d& origin, const cvf::Vec3d& size)
{
RimView* rimView = nullptr;
this->firstAncestorOrThisOfType(rimView);
if (rimView)
{
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
cvf::Vec3d domainOrigin = transForm->transformToDomainCoord(origin);
cvf::Vec3d domainSize = transForm->scaleToDomainSize(size);
setFromOriginAndSize(domainOrigin, domainSize);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -451,3 +574,17 @@ cvf::BoundingBox RimIntersectionBox::currentCellBoundingBox()
return rimCase->activeCellsBoundingBox();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuViewer* RimIntersectionBox::viewer()
{
RimView* rimView = nullptr;
this->firstAncestorOrThisOfType(rimView);
RiuViewer* riuViewer = nullptr;
if (rimView) riuViewer = rimView->viewer();
return riuViewer;
}

View File

@ -21,8 +21,15 @@
#include "cafPdmObject.h"
#include "cafPdmField.h"
#include "cvfBase.h"
#include "cvfVector3.h"
#include "cvfBoundingBox.h"
#include <QObject>
#include <QPointer>
class RicBoxManipulatorEventHandler;
class RiuViewer;
class RivIntersectionBoxPartMgr;
//==================================================================================================
@ -30,8 +37,10 @@ class RivIntersectionBoxPartMgr;
//
//
//==================================================================================================
class RimIntersectionBox : public caf::PdmObject
class RimIntersectionBox : public QObject, public caf::PdmObject
{
Q_OBJECT;
CAF_PDM_HEADER_INIT;
public:
@ -71,12 +80,19 @@ protected:
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
virtual void initAfterRead() override;
protected slots:
void slotScheduleRedraw();
void slotUpdateGeometry(const cvf::Vec3d& origin, const cvf::Vec3d& size);
private:
void rebuildGeometryAndScheduleCreateDisplayModel();
void updateVisibility();
void updateLabelsFromBoundingBox();
void clampSinglePlaneValues();
void switchSingelPlaneState();
cvf::BoundingBox currentCellBoundingBox();
RiuViewer* viewer();
private:
caf::PdmField<caf::AppEnum< SinglePlaneState > > m_singlePlaneState;
@ -89,8 +105,8 @@ private:
caf::PdmField<double> m_maxYCoord;
caf::PdmField<double> m_maxDepth;
cvf::BoundingBox currentCellBoundingBox();
caf::PdmField<bool> m_show3DManipulator;
cvf::ref<RivIntersectionBoxPartMgr> m_intersectionBoxPartMgr;
QPointer<RicBoxManipulatorEventHandler> m_boxManipulator;
};

View File

@ -207,12 +207,6 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
m_currentFaceIndex = cvf::StructGridInterface::NO_FACE;
m_currentPickedObject = const_cast<RimIntersectionBox*>(intersectionBoxSourceInfo->intersectionBox());
menu.addAction(caf::CmdFeatureManager::instance()->action("RicEditIntersectionBoxFeature"));
menu.addSeparator();
QStringList commandIdList;
commandIdList << "RicEditIntersectionBoxFeature";
caf::CmdFeatureManager::instance()->refreshCheckedState(commandIdList);
}
// IJK -slice commands