///////////////////////////////////////////////////////////////////////////////// // // 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 // 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 RimPolygonInViewCollection::visiblePolygonsInView() const { if ( !m_isChecked ) return {}; std::vector 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 RimPolygonInViewCollection::allPolygonsInView() const { std::vector 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() ) { view->scheduleCreateDisplayModelAndRedraw(); } } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimPolygonInViewCollection::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const { if ( firstAncestorOfType() ) { menuBuilder << "RicCreateContourMapPolygonFeature"; } RimPolygonCollection::appendPolygonMenuItems( menuBuilder ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RimPolygonInViewCollection::sourceSubCollections() const { if ( auto* src = sourceCollection() ) return src->subCollections(); return {}; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector 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; }