Add operations on polygon : Duplicate, exportCsv, exportPol and simplify

SimplfyPolygon applies an operation on polygon to reduce the number of points in a way that the shape of the polygon is conserved.
This commit is contained in:
Magne Sjaastad
2024-03-04 07:28:04 +01:00
parent 5217ab5c8b
commit 3689cccae7
19 changed files with 621 additions and 19 deletions

View File

@@ -2,12 +2,20 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicCreatePolygonFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportPolygonFileFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicReloadPolygonFileFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDuplicatePolygonFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonCsvFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.h
)
set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicCreatePolygonFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportPolygonFileFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicReloadPolygonFileFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDuplicatePolygonFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonCsvFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.cpp
)
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@@ -47,7 +47,7 @@ void RicCreatePolygonFeature::onActionTriggered( bool isChecked )
Riu3DMainWindowTools::setExpanded( newPolygon );
auto activeView = RiaApplication::instance()->activeReservoirView();
RimPolygonTools::selectAndActivatePolygonInView( newPolygon, activeView );
RimPolygonTools::activate3dEditOfPolygonInView( newPolygon, activeView );
}
//--------------------------------------------------------------------------------------------------

View File

@@ -0,0 +1,79 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicDuplicatePolygonFeature.h"
#include "RiaApplication.h"
#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonCollection.h"
#include "Polygons/RimPolygonInView.h"
#include "Polygons/RimPolygonTools.h"
#include "Rim3dView.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "Riu3DMainWindowTools.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicDuplicatePolygonFeature, "RicDuplicatePolygonFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDuplicatePolygonFeature::onActionTriggered( bool isChecked )
{
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
if ( !sourcePolygon )
{
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
if ( sourcePolygonInView )
{
sourcePolygon = sourcePolygonInView->polygon();
}
}
if ( !sourcePolygon ) return;
auto proj = RimProject::current();
auto polygonCollection = proj->activeOilField()->polygonCollection();
auto newPolygon = polygonCollection->createUserDefinedPolygon();
newPolygon->setPointsInDomainCoords( sourcePolygon->pointsInDomainCoords() );
auto sourceName = sourcePolygon->name();
newPolygon->setName( "Copy of " + sourceName );
polygonCollection->addUserDefinedPolygon( newPolygon );
polygonCollection->uiCapability()->updateAllRequiredEditors();
Riu3DMainWindowTools::setExpanded( newPolygon );
auto activeView = RiaApplication::instance()->activeReservoirView();
RimPolygonTools::selectPolygonInView( newPolygon, activeView );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicDuplicatePolygonFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Duplicate Polygon" );
actionToSetup->setIcon( QIcon( ":/caf/duplicate.svg" ) );
}

View File

@@ -0,0 +1,33 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicDuplicatePolygonFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -0,0 +1,82 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicExportPolygonCsvFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonInView.h"
#include "Polygons/RimPolygonTools.h"
#include "RiuFileDialogTools.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileInfo>
CAF_CMD_SOURCE_INIT( RicExportPolygonCsvFeature, "RicExportPolygonCsvFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportPolygonCsvFeature::onActionTriggered( bool isChecked )
{
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
if ( !sourcePolygon )
{
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
if ( sourcePolygonInView )
{
sourcePolygon = sourcePolygonInView->polygon();
}
}
if ( !sourcePolygon ) return;
auto app = RiaGuiApplication::instance();
auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" );
auto polygonPath = app->lastUsedDialogDirectoryWithFallback( RimPolygonTools::polygonCacheName(), fallbackPath );
auto polygonFileName = polygonPath + "/" + sourcePolygon->name() + ".csv";
auto fileName = RiuFileDialogTools::getSaveFileName( nullptr,
"Select File for Polygon Export to CSV",
polygonFileName,
"CSV Files (*.csv);;All files(*.*)" );
if ( !RimPolygonTools::exportPolygonCsv( sourcePolygon, fileName ) )
{
RiaLogging::error( "Failed to export polygon to " + fileName );
}
else
{
RiaLogging::info( "Completed polygon export to " + fileName );
app->setLastUsedDialogDirectory( RimPolygonTools::polygonCacheName(), QFileInfo( fileName ).absolutePath() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportPolygonCsvFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Export Polygon CSV" );
actionToSetup->setIcon( QIcon( ":/Save.svg" ) );
}

View File

@@ -0,0 +1,33 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicExportPolygonCsvFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -0,0 +1,82 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicExportPolygonPolFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonInView.h"
#include "Polygons/RimPolygonTools.h"
#include "RiuFileDialogTools.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileInfo>
CAF_CMD_SOURCE_INIT( RicExportPolygonPolFeature, "RicExportPolygonPolFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportPolygonPolFeature::onActionTriggered( bool isChecked )
{
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
if ( !sourcePolygon )
{
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
if ( sourcePolygonInView )
{
sourcePolygon = sourcePolygonInView->polygon();
}
}
if ( !sourcePolygon ) return;
auto app = RiaGuiApplication::instance();
auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" );
auto polygonPath = app->lastUsedDialogDirectoryWithFallback( RimPolygonTools::polygonCacheName(), fallbackPath );
auto polygonFileName = polygonPath + "/" + sourcePolygon->name() + ".pol";
auto fileName = RiuFileDialogTools::getSaveFileName( nullptr,
"Select File for Polygon Export to POL",
polygonFileName,
"POL Files (*.pol);;All files(*.*)" );
if ( !RimPolygonTools::exportPolygonPol( sourcePolygon, fileName ) )
{
RiaLogging::error( "Failed to export polygon to " + fileName );
}
else
{
RiaLogging::info( "Completed polygon export to " + fileName );
RiaApplication::instance()->setLastUsedDialogDirectory( RimPolygonTools::polygonCacheName(), QFileInfo( fileName ).absolutePath() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicExportPolygonPolFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Export Polygon POL" );
actionToSetup->setIcon( QIcon( ":/Save.svg" ) );
}

View File

@@ -0,0 +1,33 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicExportPolygonPolFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -23,6 +23,7 @@
#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonCollection.h"
#include "Polygons/RimPolygonFile.h"
#include "Polygons/RimPolygonTools.h"
#include "RimOilField.h"
#include "RimProject.h"
@@ -39,18 +40,21 @@ CAF_CMD_SOURCE_INIT( RicImportPolygonFileFeature, "RicImportPolygonFileFeature"
//--------------------------------------------------------------------------------------------------
void RicImportPolygonFileFeature::onActionTriggered( bool isChecked )
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory( "BINARY_GRID" );
QStringList fileNames = RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(),
RiaApplication* app = RiaApplication::instance();
auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" );
auto polygonPath = app->lastUsedDialogDirectoryWithFallback( RimPolygonTools::polygonCacheName(), fallbackPath );
QStringList fileNames = RiuFileDialogTools::getOpenFileNames( Riu3DMainWindowTools::mainWindowWidget(),
"Import Polygons",
defaultDir,
polygonPath,
"Polylines (*.csv *.dat *.pol);;Text Files (*.txt);;Polylines "
"(*.dat);;Polylines (*.pol);;Polylines (*.csv);;All Files (*.*)" );
"(*.dat);;Polylines (*.pol);;Polylines (*.csv);;All Files (*.*)" );
if ( fileNames.isEmpty() ) return;
// Remember the path to next time
app->setLastUsedDialogDirectory( "BINARY_GRID", QFileInfo( fileNames.last() ).absolutePath() );
app->setLastUsedDialogDirectory( RimPolygonTools::polygonCacheName(), QFileInfo( fileNames.last() ).absolutePath() );
auto proj = RimProject::current();
auto polygonCollection = proj->activeOilField()->polygonCollection();

View File

@@ -0,0 +1,73 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSimplifyPolygonFeature.h"
#include "Polygons/RimPolygon.h"
#include "Polygons/RimPolygonInView.h"
#include "RigCellGeometryTools.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QInputDialog>
CAF_CMD_SOURCE_INIT( RicSimplifyPolygonFeature, "RicSimplifyPolygonFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSimplifyPolygonFeature::onActionTriggered( bool isChecked )
{
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
if ( !sourcePolygon )
{
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
if ( sourcePolygonInView )
{
sourcePolygon = sourcePolygonInView->polygon();
}
}
if ( !sourcePolygon ) return;
const double defaultEpsilon = 10.0;
bool ok;
auto epsilon =
QInputDialog::getDouble( nullptr, "Simplify Polygon Threshold", "Threshold:", defaultEpsilon, 1.0, 1000.0, 1, &ok, Qt::WindowFlags(), 1 );
if ( ok )
{
auto coords = sourcePolygon->pointsInDomainCoords();
RigCellGeometryTools::simplifyPolygon( &coords, epsilon );
sourcePolygon->setPointsInDomainCoords( coords );
sourcePolygon->coordinatesChanged.send();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSimplifyPolygonFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Simplify Polygon" );
actionToSetup->setIcon( QIcon( ":/PolylinesFromFile16x16.png" ) );
}

View File

@@ -0,0 +1,33 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicSimplifyPolygonFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -118,7 +118,7 @@ void RifCsvDataTableFormatter::tableCompleted()
//--------------------------------------------------------------------------------------------------
void RifCsvDataTableFormatter::outputBuffer()
{
if ( !m_columnHeaders.empty() )
if ( isAnyTextInHeader() )
{
for ( size_t i = 0; i < m_columnHeaders.size(); i++ )
{
@@ -152,3 +152,21 @@ void RifCsvDataTableFormatter::outputBuffer()
m_columnHeaders.clear();
m_buffer.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifCsvDataTableFormatter::isAnyTextInHeader() const
{
for ( auto& header : m_columnHeaders )
{
for ( const auto& titleRow : header.titles )
{
if ( !titleRow.trimmed().isEmpty() )
{
return true;
}
}
}
return false;
}

View File

@@ -42,6 +42,7 @@ public:
private:
void outputBuffer();
bool isAnyTextInHeader() const;
private:
QTextStream& m_out;

View File

@@ -320,7 +320,13 @@ bool RifTextDataTableFormatter::isAllHeadersEmpty( const std::vector<RifTextData
{
for ( auto& header : headers )
{
if ( !header.titles.empty() ) return false;
for ( const auto& titleRow : header.titles )
{
if ( !titleRow.trimmed().isEmpty() )
{
return false;
}
}
}
return true;
}

View File

@@ -92,7 +92,7 @@ struct RifTextDataTableColumn
, alignment( alignment )
, width( width )
{
titles.push_back( title );
titles.emplace_back( title );
}
RifTextDataTableColumn( const QString& title,
@@ -104,8 +104,8 @@ struct RifTextDataTableColumn
, alignment( alignment )
, width( width )
{
titles.push_back( title );
titles.push_back( subTitle );
titles.emplace_back( title );
titles.emplace_back( subTitle );
}
RifTextDataTableColumn( const QString& title,
@@ -118,9 +118,9 @@ struct RifTextDataTableColumn
, alignment( alignment )
, width( width )
{
titles.push_back( title );
titles.push_back( subTitle1 );
titles.push_back( subTitle2 );
titles.emplace_back( title );
titles.emplace_back( subTitle1 );
titles.emplace_back( subTitle2 );
}
QString title() const

View File

@@ -330,7 +330,7 @@ void RimPolygonFilter::fieldChangedByUi( const caf::PdmFieldHandle* changedField
{
if ( changedField == &m_editPolygonButton )
{
RimPolygonTools::selectAndActivatePolygonInView( m_cellFilterPolygon(), this );
RimPolygonTools::activate3dEditOfPolygonInView( m_cellFilterPolygon(), this );
m_editPolygonButton = false;

View File

@@ -522,7 +522,7 @@ void RimExtrudedCurveIntersection::fieldChangedByUi( const caf::PdmFieldHandle*
if ( changedField == &m_editPolygonButton )
{
RimPolygonTools::selectAndActivatePolygonInView( m_projectPolygon(), this );
RimPolygonTools::activate3dEditOfPolygonInView( m_projectPolygon(), this );
m_editPolygonButton = false;

View File

@@ -18,6 +18,10 @@
#include "RimPolygonTools.h"
#include "RiaPreferences.h"
#include "RifCsvDataTableFormatter.h"
#include "RimGridView.h"
#include "RimOilField.h"
#include "RimPolygon.h"
@@ -28,10 +32,13 @@
#include "Riu3DMainWindowTools.h"
#include <QFile>
#include <QTextStream>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonTools::selectAndActivatePolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
void RimPolygonTools::activate3dEditOfPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
{
auto polygonInView = findPolygonInView( polygon, sourceObject );
if ( polygonInView )
@@ -41,6 +48,109 @@ void RimPolygonTools::selectAndActivatePolygonInView( RimPolygon* polygon, caf::
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonTools::selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
{
auto polygonInView = findPolygonInView( polygon, sourceObject );
if ( polygonInView )
{
Riu3DMainWindowTools::selectAsCurrentItem( polygonInView );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPolygonTools::exportPolygonCsv( const RimPolygon* polygon, const QString& filePath )
{
if ( !polygon ) return false;
QFile file( filePath );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
return false;
}
QTextStream out( &file );
QString fieldSeparator = RiaPreferences::current()->csvTextExportFieldSeparator;
RifCsvDataTableFormatter formatter( out, fieldSeparator );
const int precision = 2;
std::vector<RifTextDataTableColumn> header;
header.emplace_back( "X", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
header.emplace_back( "Y", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
header.emplace_back( "Z", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
formatter.header( header );
for ( const auto& point : polygon->pointsInDomainCoords() )
{
formatter.add( point.x() );
formatter.add( point.y() );
formatter.add( -point.z() );
formatter.rowCompleted();
}
formatter.tableCompleted();
file.close();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPolygonTools::exportPolygonPol( const RimPolygon* polygon, const QString& filePath )
{
if ( !polygon ) return false;
QFile file( filePath );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) return false;
QTextStream out( &file );
QString fieldSeparator = " ";
RifCsvDataTableFormatter formatter( out, fieldSeparator );
const int precision = 2;
std::vector<RifTextDataTableColumn> header;
header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
formatter.header( header );
for ( const auto& point : polygon->pointsInDomainCoords() )
{
formatter.add( point.x() );
formatter.add( point.y() );
formatter.add( -point.z() );
formatter.rowCompleted();
}
const double endOfPolygon = 999.0;
formatter.add( endOfPolygon );
formatter.add( endOfPolygon );
formatter.add( endOfPolygon );
formatter.rowCompleted();
formatter.tableCompleted();
file.close();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPolygonTools::polygonCacheName()
{
return "POLYGON";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -21,6 +21,8 @@
class RimPolygon;
class RimPolygonInView;
class QString;
namespace caf
{
class PdmObject;
@@ -29,7 +31,12 @@ class PdmObject;
class RimPolygonTools
{
public:
static void selectAndActivatePolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
static void activate3dEditOfPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
static void selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
static bool exportPolygonCsv( const RimPolygon* polygon, const QString& filePath );
static bool exportPolygonPol( const RimPolygon* polygon, const QString& filePath );
static QString polygonCacheName();
private:
static RimPolygonInView* findPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );