mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add polygon file readers and make sure UI items are in sync
* Add polygon reader for POL file format * Add CSV import * Add helper function to create tag with color and text * Show polygon color as tag, allow color edit by clicking on tag * Support optional header in csv file * Add Reload on polygon file * Show warning icon if no polygons * Improve logging text * Do not show file polygon in view if no polygons are imported * Use appendMenuItems * Set default polygon color to orange * Enter edit state when creating a new polygon * Fix missing UI text in menu builder
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "Rim3dView.h"
|
||||
#include "RimPolygon.h"
|
||||
#include "RimPolygonCollection.h"
|
||||
#include "RimPolygonFile.h"
|
||||
#include "RimPolygonInView.h"
|
||||
#include "RimTools.h"
|
||||
|
||||
@@ -31,58 +32,74 @@ CAF_PDM_SOURCE_INIT( RimPolygonInViewCollection, "RimPolygonInViewCollection" );
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimPolygonInViewCollection::RimPolygonInViewCollection()
|
||||
{
|
||||
CAF_PDM_InitObject( "Polygons (Under construction)", ":/PolylinesFromFile16x16.png" );
|
||||
CAF_PDM_InitObject( "Polygons", ":/PolylinesFromFile16x16.png" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_polygons, "Polygons", "Polygons" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_polygonsInView, "Polygons", "Polygons" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_collectionsInView, "Collections", "Collections" );
|
||||
|
||||
nameField()->uiCapability()->setUiHidden( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonInViewCollection::syncPolygonsInView()
|
||||
void RimPolygonInViewCollection::updateFromPolygonCollection()
|
||||
{
|
||||
std::vector<RimPolygonInView*> existingPolygonsInView = m_polygons.childrenByType();
|
||||
m_polygons.clearWithoutDelete();
|
||||
|
||||
auto polygonCollection = RimTools::polygonCollection();
|
||||
if ( polygonCollection )
|
||||
{
|
||||
std::vector<RimPolygonInView*> newPolygonsInView;
|
||||
|
||||
for ( auto polygon : polygonCollection->allPolygons() )
|
||||
{
|
||||
auto it = std::find_if( existingPolygonsInView.begin(),
|
||||
existingPolygonsInView.end(),
|
||||
[polygon]( auto* polygonInView ) { return polygonInView->polygon() == polygon; } );
|
||||
|
||||
if ( it != existingPolygonsInView.end() )
|
||||
{
|
||||
newPolygonsInView.push_back( *it );
|
||||
existingPolygonsInView.erase( it );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto polygonInView = new RimPolygonInView();
|
||||
polygonInView->setPolygon( polygon );
|
||||
newPolygonsInView.push_back( polygonInView );
|
||||
}
|
||||
}
|
||||
|
||||
m_polygons.setValue( newPolygonsInView );
|
||||
}
|
||||
|
||||
for ( auto polyInView : existingPolygonsInView )
|
||||
{
|
||||
delete polyInView;
|
||||
}
|
||||
updateAllViewItems();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimPolygonInView*> RimPolygonInViewCollection::polygonsInView() const
|
||||
std::vector<RimPolygonInView*> RimPolygonInViewCollection::visiblePolygonsInView() const
|
||||
{
|
||||
return m_polygons.childrenByType();
|
||||
if ( !m_isChecked ) return {};
|
||||
|
||||
std::vector<RimPolygonInView*> polys = m_polygonsInView.childrenByType();
|
||||
|
||||
for ( auto coll : m_collectionsInView )
|
||||
{
|
||||
if ( coll->isChecked() == false ) 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_polygonsInView.childrenByType();
|
||||
|
||||
for ( auto coll : m_collectionsInView )
|
||||
{
|
||||
auto other = coll->visiblePolygonsInView();
|
||||
polys.insert( polys.end(), other.begin(), other.end() );
|
||||
}
|
||||
|
||||
return polys;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonInViewCollection::setPolygonFile( RimPolygonFile* polygonFile )
|
||||
{
|
||||
m_polygonFile = polygonFile;
|
||||
|
||||
updateName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimPolygonFile* RimPolygonInViewCollection::polygonFile() const
|
||||
{
|
||||
return m_polygonFile;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -90,11 +107,11 @@ std::vector<RimPolygonInView*> RimPolygonInViewCollection::polygonsInView() cons
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonInViewCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
||||
{
|
||||
RimCheckableObject::fieldChangedByUi( changedField, oldValue, newValue );
|
||||
RimCheckableNamedObject::fieldChangedByUi( changedField, oldValue, newValue );
|
||||
|
||||
if ( changedField == &m_isChecked )
|
||||
{
|
||||
for ( auto poly : polygonsInView() )
|
||||
for ( auto poly : visiblePolygonsInView() )
|
||||
{
|
||||
poly->updateConnectedEditors();
|
||||
}
|
||||
@@ -105,3 +122,151 @@ void RimPolygonInViewCollection::fieldChangedByUi( const caf::PdmFieldHandle* ch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonInViewCollection::updateAllViewItems()
|
||||
{
|
||||
// Based on the same concept as RimSurfaceInViewCollection
|
||||
|
||||
syncCollectionsWithView();
|
||||
syncPolygonsWithView();
|
||||
updateConnectedEditors();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonInViewCollection::syncCollectionsWithView()
|
||||
{
|
||||
// Based on the same concept as RimSurfaceInViewCollection
|
||||
|
||||
auto colls = m_collectionsInView.childrenByType();
|
||||
|
||||
for ( auto coll : colls )
|
||||
{
|
||||
if ( !coll->polygonFile() )
|
||||
{
|
||||
m_collectionsInView.removeChild( coll );
|
||||
delete coll;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !m_polygonFile )
|
||||
{
|
||||
std::vector<RimPolygonInViewCollection*> orderedColls;
|
||||
|
||||
if ( auto polygonCollection = RimTools::polygonCollection() )
|
||||
{
|
||||
std::vector<RimPolygonInView*> newPolygonsInView;
|
||||
|
||||
for ( auto polygonFile : polygonCollection->polygonFiles() )
|
||||
{
|
||||
if ( polygonFile->polygons().empty() ) continue;
|
||||
|
||||
auto viewPolygonFile = getCollectionInViewForPolygonFile( polygonFile );
|
||||
if ( viewPolygonFile == nullptr )
|
||||
{
|
||||
auto newColl = new RimPolygonInViewCollection();
|
||||
newColl->setPolygonFile( polygonFile );
|
||||
orderedColls.push_back( newColl );
|
||||
}
|
||||
else
|
||||
{
|
||||
viewPolygonFile->updateName();
|
||||
orderedColls.push_back( viewPolygonFile );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_collectionsInView.clearWithoutDelete();
|
||||
for ( auto viewColl : orderedColls )
|
||||
{
|
||||
m_collectionsInView.push_back( viewColl );
|
||||
viewColl->updateAllViewItems();
|
||||
}
|
||||
}
|
||||
|
||||
updateName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonInViewCollection::syncPolygonsWithView()
|
||||
{
|
||||
std::vector<RimPolygonInView*> existingPolygonsInView = m_polygonsInView.childrenByType();
|
||||
m_polygonsInView.clearWithoutDelete();
|
||||
|
||||
std::vector<RimPolygon*> polygons;
|
||||
|
||||
if ( m_polygonFile )
|
||||
{
|
||||
polygons = m_polygonFile->polygons();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto polygonCollection = RimTools::polygonCollection();
|
||||
polygons = polygonCollection->userDefinedPolygons();
|
||||
}
|
||||
|
||||
std::vector<RimPolygonInView*> newPolygonsInView;
|
||||
|
||||
for ( auto polygon : polygons )
|
||||
{
|
||||
auto it = std::find_if( existingPolygonsInView.begin(),
|
||||
existingPolygonsInView.end(),
|
||||
[polygon]( auto* polygonInView ) { return polygonInView->polygon() == polygon; } );
|
||||
|
||||
if ( it != existingPolygonsInView.end() )
|
||||
{
|
||||
newPolygonsInView.push_back( *it );
|
||||
existingPolygonsInView.erase( it );
|
||||
}
|
||||
else
|
||||
{
|
||||
auto polygonInView = new RimPolygonInView();
|
||||
polygonInView->setPolygon( polygon );
|
||||
newPolygonsInView.push_back( polygonInView );
|
||||
}
|
||||
}
|
||||
|
||||
m_polygonsInView.setValue( newPolygonsInView );
|
||||
|
||||
for ( auto polyInView : existingPolygonsInView )
|
||||
{
|
||||
delete polyInView;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonInViewCollection::updateName()
|
||||
{
|
||||
QString name = "Polygons";
|
||||
|
||||
if ( m_polygonFile )
|
||||
{
|
||||
name = m_polygonFile->name();
|
||||
}
|
||||
|
||||
setName( name );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimPolygonInViewCollection* RimPolygonInViewCollection::getCollectionInViewForPolygonFile( const RimPolygonFile* polygonFile ) const
|
||||
{
|
||||
for ( auto collInView : m_collectionsInView )
|
||||
{
|
||||
if ( collInView->polygonFile() == polygonFile )
|
||||
{
|
||||
return collInView;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user