Skip to content

Commit

Permalink
Disable storing polygon edit targets to file as the number of point c…
Browse files Browse the repository at this point in the history
…an be large
  • Loading branch information
magnesj committed Feb 27, 2024
1 parent c7ec781 commit 5496cae
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ void RicNewPolygonFileFeature::onActionTriggered( bool isChecked )
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory( "BINARY_GRID" );
QStringList fileNames =
RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(),
"Import Polygons",
defaultDir,
"Text Files (*.txt);;Polylines (*.dat);;Polylines (*.pol);;All Files (*.*)" );
QStringList fileNames = RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(),
"Import Polygons",
defaultDir,
"Polylines (*.csv *.dat *.pol);;Text Files (*.txt);;Polylines "
"(*.dat);;Polylines (*.pol);;Polylines (*.csv);;All Files (*.*)" );

if ( fileNames.isEmpty() ) return;

Expand Down
37 changes: 37 additions & 0 deletions ApplicationLibCode/FileInterface/RifPolygonReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,45 @@

#include "RifCsvUserDataParser.h"

#include <QFileInfo>
#include <QTextStream>

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<std::pair<int, std::vector<cvf::Vec3d>>> RifPolygonReader::parsePolygonFile( const QString& fileName, QString* errorMessage )
{
QFileInfo fi( fileName );

QFile dataFile( fileName );

if ( !dataFile.open( QFile::ReadOnly ) )
{
if ( errorMessage ) ( *errorMessage ) += "Could not open file: " + fileName + "\n";
return {};
}

QTextStream stream( &dataFile );
auto fileContent = stream.readAll();

if ( fi.suffix().trimmed().toLower() == "csv" )
{
return parseTextCsv( fileContent, errorMessage );
}
else
{
auto polygons = parseText( fileContent, errorMessage );

std::vector<std::pair<int, std::vector<cvf::Vec3d>>> polygonsWithIds;
for ( auto& polygon : polygons )
{
polygonsWithIds.push_back( std::make_pair( -1, polygon ) );
}

return polygonsWithIds;
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions ApplicationLibCode/FileInterface/RifPolygonReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
//==================================================================================================
class RifPolygonReader
{
public:
static std::vector<std::pair<int, std::vector<cvf::Vec3d>>> parsePolygonFile( const QString& fileName, QString* errorMessage );

// Defined public for testing purposes
public:
static std::vector<std::vector<cvf::Vec3d>> parseText( const QString& content, QString* errorMessage );
static std::vector<std::pair<int, std::vector<cvf::Vec3d>>> parseTextCsv( const QString& content, QString* errorMessage );
Expand Down
8 changes: 8 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ bool RimPolygon::isReadOnly() const
return m_isReadOnly();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygon::disableStorageOfPolygonPoints()
{
m_pointsInDomainCoords.xmlCapability()->setIOWritable( false );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class RimPolygon : public RimNamedObject, public RimPolylinesDataInterface
void setReadOnly( bool isReadOnly );
bool isReadOnly() const;

void disableStorageOfPolygonPoints();

cvf::ref<RigPolyLinesData> polyLinesData() const override;

void uiOrderingForLocalPolygon( QString uiConfigName, caf::PdmUiOrdering& uiOrdering );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ RimPolygonCollection::RimPolygonCollection()
//--------------------------------------------------------------------------------------------------
void RimPolygonCollection::loadData()
{
/*
for ( auto& p : m_polygonFiles() )
{
p->loadData();
}
*/
for ( auto& p : m_polygonFiles() )
{
p->loadData();
}
}

//--------------------------------------------------------------------------------------------------
Expand Down
80 changes: 37 additions & 43 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,24 @@ void RimPolygonFile::setFileName( const QString& fileName )
//--------------------------------------------------------------------------------------------------
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 );
}
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -77,62 +94,39 @@ 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 )
{
m_polygons.deleteChildren();
loadData();
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonFile::loadPolygonsFromFile()
std::vector<RimPolygon*> RimPolygonFile::importDataFromFile( const QString& fileName )
{
m_polygons.deleteChildren();

QFileInfo fi( m_fileName().path() );

QFile dataFile( m_fileName().path() );

if ( !dataFile.open( QFile::ReadOnly ) )
{
RiaLogging::error( "Could not open the File: " + ( m_fileName().path() ) + "\n" );
return;
}

QTextStream stream( &dataFile );
auto fileContent = stream.readAll();

QString errorMessages;
auto filePolygons = RifPolygonReader::parsePolygonFile( fileName, &errorMessages );

if ( fi.suffix().trimmed().toLower() == "csv" )
{
auto filePolygons = RifPolygonReader::parseTextCsv( fileContent, &errorMessages );
std::vector<RimPolygon*> polygons;

for ( const auto& [polygonId, filePolygon] : filePolygons )
{
auto polygon = new RimPolygon();

int id = ( polygonId != -1 ) ? polygonId : static_cast<int>( m_polygons.size() + 1 );
polygon->setName( QString( "Polygon %1" ).arg( id ) );
polygon->setPointsInDomainCoords( filePolygon );
m_polygons.push_back( polygon );
}
}
else
for ( const auto& [polygonId, filePolygon] : filePolygons )
{
auto filePolygons = RifPolygonReader::parseText( fileContent, &errorMessages );

for ( const auto& filePolygon : filePolygons )
{
auto polygon = new RimPolygon();

int id = static_cast<int>( m_polygons.size() + 1 );
polygon->setName( QString( "Polygon %1" ).arg( id ) );
polygon->setPointsInDomainCoords( filePolygon );
m_polygons.push_back( polygon );
}
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RimPolygonFile : public RimNamedObject
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;

private:
void loadPolygonsFromFile();
static std::vector<RimPolygon*> importDataFromFile( const QString& fileName );

private:
caf::PdmField<caf::FilePath> m_fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ RimPolygonInView::RimPolygonInView()
m_targets.uiCapability()->setUiTreeChildrenHidden( true );
m_targets.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP );
m_targets.uiCapability()->setCustomContextMenuEnabled( true );
m_targets.xmlCapability()->disableIO();

setUi3dEditorTypeName( RicPolyline3dEditor::uiEditorTypeName() );
}
Expand Down

0 comments on commit 5496cae

Please sign in to comment.