mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make 3d view picker more generic to enable picking cell filter polygon Give cell filters a new, generic interface for updating included/excluded cells from collection Remove old range filter collection and replace with new filter collection that supports both range filters, polyline filters and user defined filters. Update existing range filter code for the new collection and interface Add user defined cell filter type Add polyline cell filter type Implement both Z and K index depth for polyline filters Allow interactive editing of polyline filter node positions. Support both geomech and eclipse views Support view linking with both eclipse and geomech views and the new filter types Support loading old project files with range filter collections into the new collection type Adjust to new world order.
349 lines
14 KiB
C++
349 lines
14 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2018- Equinor 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 "RimUserDefinedPolylinesAnnotation.h"
|
|
|
|
#include "WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.h"
|
|
#include "WellPathCommands/RicPolylineTargetsPickEventHandler.h"
|
|
|
|
#include "RimAnnotationCollection.h"
|
|
#include "RimAnnotationLineAppearance.h"
|
|
#include "RimPolylineTarget.h"
|
|
|
|
#include "RigPolyLinesData.h"
|
|
|
|
#include "RiuViewerCommands.h"
|
|
|
|
#include "cvfBoundingBox.h"
|
|
|
|
#include "cafCmdFeatureMenuBuilder.h"
|
|
#include "cafPdmUiPushButtonEditor.h"
|
|
#include "cafPdmUiTableViewEditor.h"
|
|
#include "cafPdmUiTreeOrdering.h"
|
|
|
|
CAF_PDM_SOURCE_INIT( RimUserDefinedPolylinesAnnotation, "UserDefinedPolylinesAnnotation" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimUserDefinedPolylinesAnnotation::RimUserDefinedPolylinesAnnotation()
|
|
: m_pickTargetsEventHandler( new RicPolylineTargetsPickEventHandler( this ) )
|
|
{
|
|
CAF_PDM_InitObject( "PolyLines Annotation", ":/PolylinesFromFile16x16.png", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_name, "Name", QString( "User Defined Polyline" ), "Name", "", "", "" );
|
|
|
|
CAF_PDM_InitField( &m_enablePicking, "EnablePicking", false, "", "", "", "" );
|
|
caf::PdmUiPushButtonEditor::configureEditorForField( &m_enablePicking );
|
|
m_enablePicking.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::LabelPosType::HIDDEN );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_targets, "Targets", "Targets", "", "", "" );
|
|
m_targets.uiCapability()->setUiEditorTypeName( caf::PdmUiTableViewEditor::uiEditorTypeName() );
|
|
// m_targets.uiCapability()->setUiTreeHidden(true);
|
|
m_targets.uiCapability()->setUiTreeChildrenHidden( true );
|
|
m_targets.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP );
|
|
m_targets.uiCapability()->setCustomContextMenuEnabled( true );
|
|
|
|
this->setUi3dEditorTypeName( RicPolyline3dEditor::uiEditorTypeName() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimUserDefinedPolylinesAnnotation::~RimUserDefinedPolylinesAnnotation()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
cvf::ref<RigPolyLinesData> RimUserDefinedPolylinesAnnotation::polyLinesData()
|
|
{
|
|
cvf::ref<RigPolyLinesData> pld = new RigPolyLinesData;
|
|
std::vector<cvf::Vec3d> line;
|
|
for ( const RimPolylineTarget* target : m_targets )
|
|
{
|
|
line.push_back( target->targetPointXYZ() );
|
|
}
|
|
pld->setPolyLines( { line } );
|
|
|
|
return pld;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimPolylineTarget*> RimUserDefinedPolylinesAnnotation::activeTargets() const
|
|
{
|
|
return m_targets.childObjects();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RimUserDefinedPolylinesAnnotation::isEmpty()
|
|
{
|
|
return m_targets.empty();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::appendTarget( const cvf::Vec3d& defaultPos )
|
|
{
|
|
RimPolylineTarget* target = nullptr;
|
|
|
|
auto targets = m_targets.childObjects();
|
|
if ( targets.empty() )
|
|
{
|
|
target = new RimPolylineTarget();
|
|
target->setAsPointXYZ( defaultPos );
|
|
}
|
|
else
|
|
{
|
|
target = dynamic_cast<RimPolylineTarget*>(
|
|
targets.back()->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
|
|
}
|
|
|
|
if ( target )
|
|
{
|
|
m_targets.push_back( target );
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::insertTarget( const RimPolylineTarget* targetToInsertBefore,
|
|
RimPolylineTarget* targetToInsert )
|
|
{
|
|
size_t index = m_targets.index( targetToInsertBefore );
|
|
if ( index < m_targets.size() )
|
|
m_targets.insert( index, targetToInsert );
|
|
else
|
|
m_targets.push_back( targetToInsert );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::deleteTarget( RimPolylineTarget* targetTodelete )
|
|
{
|
|
m_targets.removeChildObject( targetTodelete );
|
|
delete targetTodelete;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::pair<RimPolylineTarget*, RimPolylineTarget*>
|
|
RimUserDefinedPolylinesAnnotation::findActiveTargetsAroundInsertionPoint( const RimPolylineTarget* targetToInsertBefore )
|
|
{
|
|
RimPolylineTarget* before = nullptr;
|
|
RimPolylineTarget* after = nullptr;
|
|
|
|
bool foundTarget = false;
|
|
for ( const auto& wt : m_targets )
|
|
{
|
|
if ( wt == targetToInsertBefore )
|
|
{
|
|
foundTarget = true;
|
|
}
|
|
|
|
if ( wt->isEnabled() && !after && foundTarget ) after = wt;
|
|
|
|
if ( wt->isEnabled() && !foundTarget ) before = wt;
|
|
}
|
|
|
|
return { before, after };
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::updateEditorsAndVisualization()
|
|
{
|
|
updateConnectedEditors();
|
|
updateVisualization();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::updateVisualization()
|
|
{
|
|
RimAnnotationCollection* annColl = nullptr;
|
|
this->firstAncestorOrThisOfTypeAsserted( annColl );
|
|
if ( annColl ) annColl->scheduleRedrawOfRelevantViews();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::enablePicking( bool enable )
|
|
{
|
|
m_enablePicking = enable;
|
|
updateConnectedEditors();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RimUserDefinedPolylinesAnnotation::pickingEnabled() const
|
|
{
|
|
return m_enablePicking();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
caf::PickEventHandler* RimUserDefinedPolylinesAnnotation::pickEventHandler() const
|
|
{
|
|
return m_pickTargetsEventHandler.get();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
{
|
|
appearance()->setLineFieldsHidden( !m_showLines );
|
|
appearance()->setSphereFieldsHidden( !m_showSpheres );
|
|
|
|
uiOrdering.add( &m_name );
|
|
uiOrdering.add( &m_targets );
|
|
uiOrdering.add( &m_enablePicking );
|
|
|
|
auto appearanceGroup = uiOrdering.addNewGroup( "Appearance" );
|
|
appearanceGroup->add( &m_closePolyline );
|
|
appearanceGroup->add( &m_showLines );
|
|
appearanceGroup->add( &m_showSpheres );
|
|
|
|
appearance()->uiOrdering( uiConfigName, *appearanceGroup );
|
|
|
|
uiOrdering.skipRemainingFields( true );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName )
|
|
{
|
|
uiTreeOrdering.skipRemainingChildren( true );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
|
const QVariant& oldValue,
|
|
const QVariant& newValue )
|
|
{
|
|
if ( changedField == &m_enablePicking )
|
|
{
|
|
this->updateConnectedEditors();
|
|
}
|
|
else if ( changedField == &m_showLines )
|
|
{
|
|
appearance()->setLineFieldsHidden( !m_showLines() );
|
|
}
|
|
else if ( changedField == &m_showSpheres )
|
|
{
|
|
appearance()->setSphereFieldsHidden( !m_showSpheres() );
|
|
}
|
|
|
|
updateVisualization();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::defineObjectEditorAttribute( QString uiConfigName,
|
|
caf::PdmUiEditorAttribute* attribute )
|
|
{
|
|
RicPolyline3dEditorAttribute* attrib = dynamic_cast<RicPolyline3dEditorAttribute*>( attribute );
|
|
if ( attrib )
|
|
{
|
|
attrib->pickEventHandler = m_pickTargetsEventHandler;
|
|
attrib->enablePicking = m_enablePicking;
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::defineCustomContextMenu( const caf::PdmFieldHandle* fieldNeedingMenu,
|
|
QMenu* menu,
|
|
QWidget* fieldEditorWidget )
|
|
{
|
|
caf::CmdFeatureMenuBuilder menuBuilder;
|
|
|
|
menuBuilder << "RicNewPolylineTargetFeature";
|
|
menuBuilder << "Separator";
|
|
menuBuilder << "RicDeletePolylineTargetFeature";
|
|
|
|
menuBuilder.appendToMenu( menu );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimUserDefinedPolylinesAnnotation::defineEditorAttribute( const caf::PdmFieldHandle* field,
|
|
QString uiConfigName,
|
|
caf::PdmUiEditorAttribute* attribute )
|
|
{
|
|
if ( field == &m_enablePicking )
|
|
{
|
|
auto* pbAttribute = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
|
|
if ( pbAttribute )
|
|
{
|
|
if ( !m_enablePicking )
|
|
{
|
|
pbAttribute->m_buttonText = "Start Picking Points";
|
|
}
|
|
else
|
|
{
|
|
pbAttribute->m_buttonText = "Stop Picking Points";
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( field == &m_targets )
|
|
{
|
|
auto tvAttribute = dynamic_cast<caf::PdmUiTableViewEditorAttribute*>( attribute );
|
|
if ( tvAttribute )
|
|
{
|
|
tvAttribute->resizePolicy = caf::PdmUiTableViewEditorAttribute::RESIZE_TO_FIT_CONTENT;
|
|
|
|
if ( m_enablePicking )
|
|
{
|
|
tvAttribute->baseColor.setRgb( 255, 220, 255 );
|
|
tvAttribute->alwaysEnforceResizePolicy = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
caf::PdmFieldHandle* RimUserDefinedPolylinesAnnotation::userDescriptionField()
|
|
{
|
|
return &m_name;
|
|
}
|