mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#884) Refactor and cleanup
This commit is contained in:
@@ -7,7 +7,6 @@ endif()
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RicBoxManipulatorEventHandler.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxEventFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicAppendIntersectionBoxFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicIntersectionBoxXSliceFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicIntersectionBoxYSliceFeature.h
|
||||
@@ -17,7 +16,6 @@ ${CEE_CURRENT_LIST_DIR}RicIntersectionBoxZSliceFeature.h
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CEE_CURRENT_LIST_DIR}RicBoxManipulatorEventHandler.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxEventFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicAppendIntersectionBoxFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicIntersectionBoxXSliceFeature.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicIntersectionBoxYSliceFeature.cpp
|
||||
@@ -35,7 +33,7 @@ ${SOURCE_GROUP_SOURCE_FILES}
|
||||
set (QT_MOC_HEADERS
|
||||
${QT_MOC_HEADERS}
|
||||
${CEE_CURRENT_LIST_DIR}RicBoxManipulatorEventHandler.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxEventFeature.h
|
||||
${CEE_CURRENT_LIST_DIR}RicEditIntersectionBoxFeature.h
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
|
||||
#include "RicBoxManipulatorEventHandler.h"
|
||||
|
||||
#include "cafBoxManipulatorPartManager.h"
|
||||
#include "cafEffectGenerator.h"
|
||||
#include "cafViewer.h"
|
||||
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfHitItemCollection.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cafEffectGenerator.h"
|
||||
|
||||
|
||||
#include "cvfHitItemCollection.h"
|
||||
|
||||
#include "cafViewer.h"
|
||||
#include "cafBoxManipulatorPartManager.h"
|
||||
#include "cvfRay.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -19,11 +20,12 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicBoxManipulatorEventHandler::RicBoxManipulatorEventHandler(caf::Viewer* viewer)
|
||||
: m_viewer(viewer),
|
||||
m_scaleZ(1.0),
|
||||
m_isGeometryCreated(false)
|
||||
m_currentPartIndex(cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
m_partManager = new caf::BoxManipulatorPartManager;
|
||||
m_model = new cvf::ModelBasicList;
|
||||
|
||||
m_viewer->installEventFilter(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -31,36 +33,21 @@ RicBoxManipulatorEventHandler::RicBoxManipulatorEventHandler(caf::Viewer* viewer
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicBoxManipulatorEventHandler::~RicBoxManipulatorEventHandler()
|
||||
{
|
||||
m_viewer->removeEventFilter(this);
|
||||
|
||||
// Make sure the model owned by this manipulator is not used anywhere else
|
||||
CVF_ASSERT(m_model->refCount() == 1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::setScaleZ(double scaleZ)
|
||||
void RicBoxManipulatorEventHandler::setOrigin(const cvf::Vec3d& origin)
|
||||
{
|
||||
m_scaleZ = scaleZ;
|
||||
m_partManager->setOrigin(origin);
|
||||
|
||||
updatePartManagerCoords();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::setDisplayModelOffset(cvf::Vec3d offset)
|
||||
{
|
||||
m_displayModelOffset = offset;
|
||||
|
||||
updatePartManagerCoords();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::setOrigin(const cvf::Mat4d& origin)
|
||||
{
|
||||
m_domainCoordOrigin = origin;
|
||||
|
||||
updatePartManagerCoords();
|
||||
updateParts();
|
||||
emit notifyRedraw();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -68,9 +55,10 @@ void RicBoxManipulatorEventHandler::setOrigin(const cvf::Mat4d& origin)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::setSize(const cvf::Vec3d& size)
|
||||
{
|
||||
m_domainCoordSize = size;
|
||||
|
||||
updatePartManagerCoords();
|
||||
m_partManager->setSize(size);
|
||||
|
||||
updateParts();
|
||||
emit notifyRedraw();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -86,93 +74,79 @@ cvf::Model* RicBoxManipulatorEventHandler::model()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicBoxManipulatorEventHandler::eventFilter(QObject *obj, QEvent* inputEvent)
|
||||
{
|
||||
if (!m_isGeometryCreated)
|
||||
{
|
||||
updateParts();
|
||||
|
||||
emit geometryUpdated();
|
||||
|
||||
inputEvent->setAccepted(true);
|
||||
|
||||
m_isGeometryCreated = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
/*
|
||||
if (inputEvent->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(inputEvent);
|
||||
|
||||
cvf::HitItemCollection hitItems;
|
||||
if (m_viewer->rayPick(mouseEvent->x(), mouseEvent->y(), &hitItems))
|
||||
if (mouseEvent->button() == Qt::LeftButton)
|
||||
{
|
||||
// TODO: Test if the first hit item is part of the manipulator
|
||||
/ *
|
||||
if (hitItems.firstItem() && hitItems.firstItem()->part())
|
||||
cvf::HitItemCollection hitItems;
|
||||
if (m_viewer->rayPick(mouseEvent->x(), mouseEvent->y(), &hitItems))
|
||||
{
|
||||
const cvf::Object* siConstObj = hitItems.firstItem()->part()->sourceInfo();
|
||||
cvf::Object* siObj = const_cast<cvf::Object*>(siConstObj);
|
||||
|
||||
caf::BoxManipulatorSourceInfo* sourceInfo = dynamic_cast<caf::BoxManipulatorSourceInfo*>(siObj);
|
||||
if (sourceInfo)
|
||||
if (hitItems.firstItem() && hitItems.firstItem()->part())
|
||||
{
|
||||
m_currentPartIndex = m_partManager->partIndexFromSourceInfo(hitItems.firstItem()->part(), hitItems.firstItem()->intersectionPoint());
|
||||
|
||||
if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
updateParts();
|
||||
emit notifyRedraw();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
* /
|
||||
}
|
||||
}
|
||||
else if (inputEvent->type() == QEvent::MouseMove)
|
||||
{
|
||||
if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(inputEvent);
|
||||
|
||||
switch (inputEvent->type())
|
||||
//qDebug() << "Inside mouse move";
|
||||
//qDebug() << mouseEvent->pos();
|
||||
|
||||
int translatedMousePosX = mouseEvent->pos().x();
|
||||
int translatedMousePosY = m_viewer->height() - mouseEvent->pos().y();
|
||||
|
||||
cvf::ref<cvf::Ray> ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
||||
{
|
||||
case QEvent::MouseButtonPress:
|
||||
mouseMoveEvent(static_cast<QMouseEvent*>(inputEvent));
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
mouseReleaseEvent(static_cast<QMouseEvent*>(inputEvent));
|
||||
break;
|
||||
case QEvent::MouseMove:
|
||||
mouseMoveEvent(static_cast<QMouseEvent*>(inputEvent));
|
||||
break;
|
||||
m_partManager->updateFromPartIndexAndRay(m_currentPartIndex, ray.p());
|
||||
|
||||
updateParts();
|
||||
|
||||
cvf::Vec3d origin;
|
||||
cvf::Vec3d size;
|
||||
m_partManager->originAndSize(&origin, &size);
|
||||
|
||||
emit notifyUpdate(origin, size);
|
||||
|
||||
emit notifyRedraw();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (inputEvent->type() == QEvent::MouseButtonRelease)
|
||||
{
|
||||
if (m_currentPartIndex != cvf::UNDEFINED_SIZE_T)
|
||||
{
|
||||
m_currentPartIndex = cvf::UNDEFINED_SIZE_T;
|
||||
|
||||
updateParts();
|
||||
cvf::Vec3d origin;
|
||||
cvf::Vec3d size;
|
||||
m_partManager->originAndSize(&origin, &size);
|
||||
|
||||
emit geometryUpdated();
|
||||
emit notifyUpdate(origin, size);
|
||||
|
||||
inputEvent->setAccepted(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -184,29 +158,3 @@ void RicBoxManipulatorEventHandler::updateParts()
|
||||
m_partManager->appendPartsToModel(m_model.p());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicBoxManipulatorEventHandler::updatePartManagerCoords()
|
||||
{
|
||||
cvf::Mat4d displayCoordOrigin = m_domainCoordOrigin;
|
||||
cvf::Vec3d domainCoordTrans = m_domainCoordOrigin.translation();
|
||||
displayCoordOrigin.setTranslation(displayModelCoordFromDomainCoord(domainCoordTrans));
|
||||
|
||||
m_partManager->setOrigin(displayCoordOrigin);
|
||||
|
||||
cvf::Vec3d domainCoordSize = m_domainCoordSize;
|
||||
domainCoordSize.z() *= m_scaleZ;
|
||||
m_partManager->setSize(domainCoordSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec3d RicBoxManipulatorEventHandler::displayModelCoordFromDomainCoord(const cvf::Vec3d& domainCoord) const
|
||||
{
|
||||
cvf::Vec3d coord = domainCoord - m_displayModelOffset;
|
||||
coord.z() *= m_scaleZ;
|
||||
|
||||
return coord;
|
||||
}
|
||||
|
||||
@@ -36,45 +36,27 @@ public:
|
||||
RicBoxManipulatorEventHandler(caf::Viewer* viewer);
|
||||
~RicBoxManipulatorEventHandler();
|
||||
|
||||
void setScaleZ(double scaleZ);
|
||||
void setDisplayModelOffset(cvf::Vec3d offset);
|
||||
|
||||
void setOrigin(const cvf::Mat4d& origin);
|
||||
void setOrigin(const cvf::Vec3d& origin);
|
||||
void setSize(const cvf::Vec3d& size);
|
||||
|
||||
cvf::Model* model();
|
||||
|
||||
signals:
|
||||
void geometryUpdated();
|
||||
void notifyRedraw();
|
||||
void notifyUpdate(const cvf::Vec3d& origin, const cvf::Vec3d& size);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
private:
|
||||
void updateParts();
|
||||
|
||||
void updatePartManagerCoords();
|
||||
|
||||
cvf::Vec3d displayModelCoordFromDomainCoord(const cvf::Vec3d& domainCoord) const;
|
||||
void updateParts();
|
||||
|
||||
private:
|
||||
cvf::ref<cvf::ModelBasicList> m_model;
|
||||
QPointer<caf::Viewer> m_viewer;
|
||||
|
||||
size_t m_currentPartIndex;
|
||||
|
||||
cvf::ref<caf::BoxManipulatorPartManager> m_partManager;
|
||||
|
||||
cvf::ref<cvf::ModelBasicList> m_model;
|
||||
QPointer<caf::Viewer> m_viewer;
|
||||
|
||||
double m_scaleZ;
|
||||
cvf::Vec3d m_displayModelOffset;
|
||||
|
||||
cvf::Mat4d m_domainCoordOrigin;
|
||||
cvf::Vec3d m_domainCoordSize;
|
||||
|
||||
bool m_isGeometryCreated;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016- Statoil ASA
|
||||
//
|
||||
// ResInsight 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.
|
||||
//
|
||||
// ResInsight 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicEditIntersectionBoxEventFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RicBoxManipulatorEventHandler.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RimIntersectionBox.h"
|
||||
#include "RimView.h"
|
||||
|
||||
|
||||
#include "RiuViewer.h"
|
||||
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicEditIntersectionBoxEventFeature, "RicEditIntersectionBoxEventFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicEditIntersectionBoxEventFeature::RicEditIntersectionBoxEventFeature()
|
||||
: m_eventHandler(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxEventFeature::updateGeometry()
|
||||
{
|
||||
RimView* activeView = RiaApplication::instance()->activeReservoirView();
|
||||
if (activeView && activeView->viewer())
|
||||
{
|
||||
activeView->viewer()->addStaticModelOnce(m_eventHandler->model());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicEditIntersectionBoxEventFeature::isCommandEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxEventFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
RiuViewer* viewer = nullptr;
|
||||
|
||||
RimView* activeView = RiaApplication::instance()->activeReservoirView();
|
||||
if (activeView && activeView->viewer())
|
||||
{
|
||||
viewer = activeView->viewer();
|
||||
}
|
||||
|
||||
if (isCommandChecked() && m_eventHandler)
|
||||
{
|
||||
if (viewer)
|
||||
{
|
||||
viewer->removeEventFilter(m_eventHandler);
|
||||
viewer->removeStaticModel(m_eventHandler->model());
|
||||
}
|
||||
|
||||
m_eventHandler->deleteLater();
|
||||
m_eventHandler = nullptr;
|
||||
}
|
||||
else if (viewer)
|
||||
{
|
||||
RimIntersectionBox* intersectionBox = dynamic_cast<RimIntersectionBox*>(viewer->lastPickedObject());
|
||||
if (intersectionBox)
|
||||
{
|
||||
m_eventHandler = new RicBoxManipulatorEventHandler(viewer);
|
||||
|
||||
cvf::Mat4d myMat = cvf::Mat4d::fromRotation(cvf::Vec3d::X_AXIS, 0.0);
|
||||
myMat.setTranslation(intersectionBox->boxOrigin().translation());
|
||||
m_eventHandler->setOrigin(myMat);
|
||||
|
||||
m_eventHandler->setSize(intersectionBox->boxSize());
|
||||
m_eventHandler->setScaleZ(activeView->scaleZ());
|
||||
|
||||
RimCase* rimCase = activeView->ownerCase();
|
||||
m_eventHandler->setDisplayModelOffset(rimCase->displayModelOffset());
|
||||
|
||||
viewer->installEventFilter(m_eventHandler);
|
||||
connect(m_eventHandler, SIGNAL(geometryUpdated()), this, SLOT(updateGeometry()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxEventFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setIcon(QIcon(":/IntersectionBox16x16.png"));
|
||||
actionToSetup->setText("Edit Intersection Box (event handler)");
|
||||
actionToSetup->setCheckable(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicEditIntersectionBoxEventFeature::isCommandChecked()
|
||||
{
|
||||
return m_eventHandler != NULL;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2016- Statoil ASA
|
||||
//
|
||||
// ResInsight 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.
|
||||
//
|
||||
// ResInsight 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
|
||||
|
||||
class RicBoxManipulatorEventHandler;
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicEditIntersectionBoxEventFeature : public caf::CmdFeature
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicEditIntersectionBoxEventFeature();
|
||||
|
||||
public slots:
|
||||
void updateGeometry();
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled() override;
|
||||
virtual void onActionTriggered( bool isChecked ) override;
|
||||
virtual void setupActionLook( QAction* actionToSetup ) override;
|
||||
virtual bool isCommandChecked() override;
|
||||
|
||||
private:
|
||||
RicBoxManipulatorEventHandler* m_eventHandler;
|
||||
};
|
||||
|
||||
@@ -20,25 +20,63 @@
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RicBoxManipulatorEventHandler.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RimIntersectionBox.h"
|
||||
#include "RimView.h"
|
||||
|
||||
#include "RiuViewer.h"
|
||||
|
||||
#include "cafBoxManipulatorGeometryGenerator.h"
|
||||
#include "cafEffectGenerator.h"
|
||||
|
||||
#include "cvfDrawableGeo.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
#include "cvfPart.h"
|
||||
#include "cvfTransform.h"
|
||||
#include "cafDisplayCoordTransform.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT(RicEditIntersectionBoxFeature, "RicEditIntersectionBoxFeature");
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicEditIntersectionBoxFeature::RicEditIntersectionBoxFeature()
|
||||
: m_eventHandler(nullptr),
|
||||
m_intersectionBox(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxFeature::slotScheduleRedraw()
|
||||
{
|
||||
RimView* activeView = RiaApplication::instance()->activeReservoirView();
|
||||
if (activeView && activeView->viewer())
|
||||
{
|
||||
activeView->viewer()->addStaticModelOnce(m_eventHandler->model());
|
||||
|
||||
activeView->scheduleCreateDisplayModelAndRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicEditIntersectionBoxFeature::slotUpdateGeometry(const cvf::Vec3d& origin, const cvf::Vec3d& size)
|
||||
{
|
||||
if (m_intersectionBox)
|
||||
{
|
||||
RimView* activeView = RiaApplication::instance()->activeReservoirView();
|
||||
if (activeView)
|
||||
{
|
||||
cvf::ref<caf::DisplayCoordTransform> transForm = activeView->displayCoordTransform();
|
||||
|
||||
cvf::Vec3d domainOrigin = transForm->transformToDomainCoord(origin);
|
||||
cvf::Vec3d domainSize = transForm->scaleToDomainSize(size);
|
||||
|
||||
m_intersectionBox->setFromOriginAndSize(domainOrigin, domainSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -60,42 +98,31 @@ void RicEditIntersectionBoxFeature::onActionTriggered(bool isChecked)
|
||||
viewer = activeView->viewer();
|
||||
}
|
||||
|
||||
if (isCommandChecked() && m_model.notNull())
|
||||
if (isCommandChecked() && m_eventHandler)
|
||||
{
|
||||
if (viewer) viewer->removeStaticModel(m_model.p());
|
||||
m_model = nullptr;
|
||||
if (viewer)
|
||||
{
|
||||
viewer->removeStaticModel(m_eventHandler->model());
|
||||
}
|
||||
|
||||
m_eventHandler->deleteLater();
|
||||
m_eventHandler = nullptr;
|
||||
|
||||
m_intersectionBox = nullptr;
|
||||
}
|
||||
else if (viewer)
|
||||
{
|
||||
RimIntersectionBox* intersectionBox = dynamic_cast<RimIntersectionBox*>(viewer->lastPickedObject());
|
||||
if (intersectionBox)
|
||||
m_intersectionBox = dynamic_cast<RimIntersectionBox*>(viewer->lastPickedObject());
|
||||
if (m_intersectionBox)
|
||||
{
|
||||
caf::BoxManipulatorGeometryGenerator boxGen;
|
||||
m_eventHandler = new RicBoxManipulatorEventHandler(viewer);
|
||||
connect(m_eventHandler, SIGNAL(notifyRedraw()), this, SLOT(slotScheduleRedraw()));
|
||||
connect(m_eventHandler, SIGNAL(notifyUpdate(const cvf::Vec3d&, const cvf::Vec3d&)), this, SLOT(slotUpdateGeometry(const cvf::Vec3d&, const cvf::Vec3d&)));
|
||||
|
||||
// TODO: boxGen operates in display coordinates, conversion is missing
|
||||
boxGen.setOrigin(intersectionBox->boxOrigin());
|
||||
boxGen.setSize(intersectionBox->boxSize());
|
||||
cvf::ref<caf::DisplayCoordTransform> transForm = activeView->displayCoordTransform();
|
||||
|
||||
cvf::ref<cvf::DrawableGeo> geoMesh = boxGen.createBoundingBoxMeshDrawable();
|
||||
if (geoMesh.notNull())
|
||||
{
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Cross Section mesh");
|
||||
part->setDrawable(geoMesh.p());
|
||||
|
||||
part->updateBoundingBox();
|
||||
// part->setEnableMask(meshFaultBit);
|
||||
// part->setPriority(priMesh);
|
||||
|
||||
cvf::ref<cvf::Effect> eff;
|
||||
caf::MeshEffectGenerator CrossSectionEffGen(cvf::Color3::WHITE);
|
||||
eff = CrossSectionEffGen.generateCachedEffect();
|
||||
part->setEffect(eff.p());
|
||||
|
||||
m_model = new cvf::ModelBasicList;
|
||||
m_model->addPart(part.p());
|
||||
viewer->addStaticModelOnce(m_model.p());
|
||||
}
|
||||
m_eventHandler->setOrigin(transForm->transformToDisplayCoord(m_intersectionBox->boxOrigin().translation()));
|
||||
m_eventHandler->setSize(transForm->scaleToDisplaySize(m_intersectionBox->boxSize()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,5 +142,5 @@ void RicEditIntersectionBoxFeature::setupActionLook(QAction* actionToSetup)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicEditIntersectionBoxFeature::isCommandChecked()
|
||||
{
|
||||
return m_model.notNull();
|
||||
return m_eventHandler != NULL;
|
||||
}
|
||||
|
||||
@@ -19,28 +19,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "cafCmdExecuteCommand.h"
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
|
||||
namespace caf {
|
||||
class BoxManipulatorGeometryGenerator;
|
||||
};
|
||||
class RicBoxManipulatorEventHandler;
|
||||
class RimIntersectionBox;
|
||||
|
||||
namespace cvf {
|
||||
class ModelBasicList;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicEditIntersectionBoxFeature : public caf::CmdFeature
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicEditIntersectionBoxFeature();
|
||||
|
||||
public slots:
|
||||
void slotScheduleRedraw();
|
||||
void slotUpdateGeometry(const cvf::Vec3d& origin, const cvf::Vec3d& size);
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
virtual bool isCommandEnabled() override;
|
||||
@@ -49,7 +49,7 @@ protected:
|
||||
virtual bool isCommandChecked() override;
|
||||
|
||||
private:
|
||||
// cvf::ref<caf::BoxManipulatorGeometryGenerator> m_boxManipulatorGeometryGenerator;
|
||||
cvf::ref<cvf::ModelBasicList> m_model;
|
||||
RicBoxManipulatorEventHandler* m_eventHandler;
|
||||
RimIntersectionBox* m_intersectionBox;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user