mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
188 lines
6.8 KiB
C++
188 lines
6.8 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2024 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 "RimPolygonInViewCollection.h"
|
|
|
|
#include "ContourMap/RimEclipseContourMapView.h"
|
|
#include "Rim3dView.h"
|
|
#include "RimPolygon.h"
|
|
#include "RimPolygonCollection.h"
|
|
#include "RimPolygonInView.h"
|
|
#include "RimTools.h"
|
|
|
|
#include "cafCmdFeatureMenuBuilder.h"
|
|
|
|
CAF_PDM_SOURCE_INIT( RimPolygonInViewCollection, "RimPolygonInViewCollection" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimPolygonInViewCollection::RimPolygonInViewCollection()
|
|
{
|
|
CAF_PDM_InitObject( "Polygons", ":/Folder.png" );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_itemsInView, "Polygons", "Polygons" );
|
|
CAF_PDM_InitFieldNoDefault( &m_collectionsInView, "Collections", "Collections" );
|
|
CAF_PDM_InitFieldNoDefault( &m_sourceCollection, "SourceCollection", "Source Collection" );
|
|
m_sourceCollection.uiCapability()->setUiHidden( true );
|
|
|
|
nameField()->uiCapability()->setUiHidden( true );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygonInViewCollection::updateFromPolygonCollection()
|
|
{
|
|
if ( !sourceCollection() )
|
|
{
|
|
setSourceCollection( RimTools::polygonCollection() );
|
|
}
|
|
updateFromSource();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimPolygonInView*> RimPolygonInViewCollection::visiblePolygonsInView() const
|
|
{
|
|
if ( !m_isChecked ) return {};
|
|
|
|
std::vector<RimPolygonInView*> polys = m_itemsInView.childrenByType();
|
|
|
|
for ( auto coll : m_collectionsInView )
|
|
{
|
|
if ( !coll->isChecked() ) continue;
|
|
|
|
auto other = coll->visiblePolygonsInView();
|
|
polys.insert( polys.end(), other.begin(), other.end() );
|
|
}
|
|
|
|
return polys;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimPolygonInView*> RimPolygonInViewCollection::allPolygonsInView() const
|
|
{
|
|
std::vector<RimPolygonInView*> polys = m_itemsInView.childrenByType();
|
|
|
|
for ( auto coll : m_collectionsInView )
|
|
{
|
|
auto other = coll->visiblePolygonsInView();
|
|
polys.insert( polys.end(), other.begin(), other.end() );
|
|
}
|
|
|
|
return polys;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RimPolygonInViewCollection::setPolygonVisible( RimPolygon* polygon, bool visible )
|
|
{
|
|
updateFromPolygonCollection();
|
|
|
|
auto* polygonInView = findPolygonInView( polygon );
|
|
if ( !polygonInView ) return false;
|
|
|
|
polygonInView->setCheckState( visible );
|
|
polygonInView->updateConnectedEditors();
|
|
return true;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimPolygonInView* RimPolygonInViewCollection::findPolygonInView( const RimPolygon* polygon ) const
|
|
{
|
|
for ( auto polygonInView : m_itemsInView )
|
|
{
|
|
if ( polygonInView && polygonInView->polygon() == polygon ) return polygonInView;
|
|
}
|
|
|
|
for ( auto collection : m_collectionsInView )
|
|
{
|
|
if ( auto* polygonInView = collection->findPolygonInView( polygon ) ) return polygonInView;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygonInViewCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
|
{
|
|
RimCheckableNamedObject::fieldChangedByUi( changedField, oldValue, newValue );
|
|
|
|
if ( changedField == &m_isChecked )
|
|
{
|
|
for ( auto poly : visiblePolygonsInView() )
|
|
{
|
|
poly->updateConnectedEditors();
|
|
}
|
|
|
|
if ( auto view = firstAncestorOfType<Rim3dView>() )
|
|
{
|
|
view->scheduleCreateDisplayModelAndRedraw();
|
|
}
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygonInViewCollection::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
|
|
{
|
|
if ( firstAncestorOfType<RimEclipseContourMapView>() )
|
|
{
|
|
menuBuilder << "RicCreateContourMapPolygonFeature";
|
|
}
|
|
RimPolygonCollection::appendPolygonMenuItems( menuBuilder );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimPolygonContainer*> RimPolygonInViewCollection::sourceSubCollections() const
|
|
{
|
|
if ( auto* src = sourceCollection() ) return src->subCollections();
|
|
return {};
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<RimPolygon*> RimPolygonInViewCollection::sourceItems() const
|
|
{
|
|
if ( auto* src = sourceCollection() ) return src->items();
|
|
return {};
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimPolygonInView* RimPolygonInViewCollection::createItemInView( RimPolygon* source )
|
|
{
|
|
auto* viewItem = new RimPolygonInView();
|
|
viewItem->setPolygon( source );
|
|
return viewItem;
|
|
}
|