mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-14 01:12:11 -05: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:
1 parent
04b14cf52a
commit
818c5c0f9c
37 files changed
+1117
-159
No files matched your search
@@ -17,14 +17,25 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RimPolygonFile.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
|
||||
#include "RifPolygonReader.h"
|
||||
|
||||
#include "RimPolygon.h"
|
||||
|
||||
#include "cafCmdFeatureMenuBuilder.h"
|
||||
#include "cafPdmUiTreeAttributes.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimPolygonFile, "RimPolygonFileFile" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimPolygonFile::RimPolygonFile()
|
||||
: objectChanged( this )
|
||||
{
|
||||
CAF_PDM_InitObject( "PolygonFile", ":/PolylinesFromFile16x16.png" );
|
||||
|
||||
@@ -34,12 +45,48 @@ RimPolygonFile::RimPolygonFile()
|
||||
setDeletable( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonFile::setFileName( const QString& fileName )
|
||||
{
|
||||
m_fileName = fileName;
|
||||
|
||||
updateName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonFile::loadData()
|
||||
{
|
||||
loadPolygonsFromFile();
|
||||
auto polygonsFromFile = importDataFromFile( m_fileName().path() );
|
||||
|
||||
if ( m_polygons.size() == polygonsFromFile.size() )
|
||||
{
|
||||
for ( size_t i = 0; i < m_polygons.size(); i++ )
|
||||
{
|
||||
auto projectPoly = m_polygons()[i];
|
||||
auto filePoly = polygonsFromFile[i];
|
||||
projectPoly->setPointsInDomainCoords( filePoly->pointsInDomainCoords() );
|
||||
delete filePoly;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_polygons.deleteChildren();
|
||||
|
||||
m_polygons.setValue( polygonsFromFile );
|
||||
}
|
||||
|
||||
if ( polygonsFromFile.empty() )
|
||||
{
|
||||
RiaLogging::warning( "No polygons found in file: " + m_fileName().path() );
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::info( QString( "Imported %1 polygons from file: " ).arg( polygonsFromFile.size() ) + m_fileName().path() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -50,11 +97,36 @@ std::vector<RimPolygon*> RimPolygonFile::polygons() const
|
||||
return m_polygons.childrenByType();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimPolygonFile::name() const
|
||||
{
|
||||
QString nameCandidate = RimNamedObject::name();
|
||||
|
||||
if ( !nameCandidate.isEmpty() )
|
||||
{
|
||||
return nameCandidate;
|
||||
}
|
||||
|
||||
auto fileName = m_fileName().path();
|
||||
if ( fileName.isEmpty() )
|
||||
{
|
||||
return "Polygon File";
|
||||
}
|
||||
|
||||
QFileInfo fileInfo( fileName );
|
||||
return fileInfo.fileName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonFile::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
||||
{
|
||||
uiOrdering.add( nameField() );
|
||||
uiOrdering.add( &m_fileName );
|
||||
uiOrdering.skipRemainingFields();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -62,21 +134,71 @@ void RimPolygonFile::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonFile::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
||||
{
|
||||
loadPolygonsFromFile();
|
||||
if ( changedField == &m_fileName )
|
||||
{
|
||||
updateName();
|
||||
|
||||
m_polygons.deleteChildren();
|
||||
loadData();
|
||||
}
|
||||
|
||||
objectChanged.send();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonFile::loadPolygonsFromFile()
|
||||
std::vector<RimPolygon*> RimPolygonFile::importDataFromFile( const QString& fileName )
|
||||
{
|
||||
// m_polygons()->deletePolygons();
|
||||
QString errorMessages;
|
||||
auto filePolygons = RifPolygonReader::parsePolygonFile( fileName, &errorMessages );
|
||||
|
||||
auto polygon = new RimPolygon();
|
||||
polygon->setName( "Polygon 1" );
|
||||
m_polygons.push_back( polygon );
|
||||
std::vector<RimPolygon*> polygons;
|
||||
|
||||
polygon = new RimPolygon();
|
||||
polygon->setName( "Polygon 2" );
|
||||
m_polygons.push_back( polygon );
|
||||
for ( const auto& [polygonId, filePolygon] : filePolygons )
|
||||
{
|
||||
auto polygon = new RimPolygon();
|
||||
polygon->disableStorageOfPolygonPoints();
|
||||
polygon->setReadOnly( true );
|
||||
|
||||
int id = ( polygonId != -1 ) ? polygonId : static_cast<int>( polygons.size() + 1 );
|
||||
polygon->setName( QString( "Polygon %1" ).arg( id ) );
|
||||
polygon->setPointsInDomainCoords( filePolygon );
|
||||
polygons.push_back( polygon );
|
||||
}
|
||||
|
||||
if ( !errorMessages.isEmpty() )
|
||||
{
|
||||
RiaLogging::error( errorMessages );
|
||||
}
|
||||
|
||||
return polygons;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonFile::updateName()
|
||||
{
|
||||
QFileInfo fileInfo( m_fileName().path() );
|
||||
setName( fileInfo.fileName() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonFile::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
|
||||
{
|
||||
menuBuilder << "RicReloadPolygonFileFeature";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonFile::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
|
||||
{
|
||||
if ( m_polygons.empty() )
|
||||
{
|
||||
caf::PdmUiTreeViewItemAttribute::appendTagToTreeViewItemAttribute( attribute, ":/warning.svg" );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user