mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Better command support for multi-select of polygons
This commit is contained in:
parent
3fac7d2045
commit
9ec83836ed
@ -37,6 +37,14 @@
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicNewPolygonFilterFeature, "RicNewPolygonFilterFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicNewPolygonFilterFeature::RicNewPolygonFilterFeature()
|
||||
: RicBasicPolygonFeature( true /*multiselect*/ )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -50,7 +58,6 @@ void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked )
|
||||
}
|
||||
|
||||
auto cellFilterCollection = caf::SelectionManager::instance()->selectedItemOfType<RimCellFilterCollection>();
|
||||
|
||||
if ( !cellFilterCollection )
|
||||
{
|
||||
RimGridView* activeView = RiaApplication::instance()->activeMainOrComparisonGridView();
|
||||
@ -59,31 +66,40 @@ void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked )
|
||||
cellFilterCollection = activeView->cellFilterCollection();
|
||||
}
|
||||
}
|
||||
|
||||
if ( !cellFilterCollection ) return;
|
||||
|
||||
if ( !polygonDataSource )
|
||||
{
|
||||
auto selectedPolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
|
||||
if ( !selectedPolygon )
|
||||
{
|
||||
if ( auto polygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>() )
|
||||
{
|
||||
selectedPolygon = polygonInView->polygon();
|
||||
}
|
||||
}
|
||||
auto sourceCase = cellFilterCollection->firstAncestorOrThisOfTypeAsserted<Rim3dView>()->ownerCase();
|
||||
if ( !sourceCase ) return;
|
||||
|
||||
polygonDataSource = selectedPolygon;
|
||||
std::vector<RimPolygon*> polygons;
|
||||
|
||||
if ( polygonDataSource )
|
||||
{
|
||||
polygons.push_back( polygonDataSource );
|
||||
}
|
||||
else
|
||||
{
|
||||
polygons = selectedPolygons();
|
||||
}
|
||||
|
||||
auto sourceCase = cellFilterCollection->firstAncestorOrThisOfTypeAsserted<Rim3dView>()->ownerCase();
|
||||
if ( sourceCase )
|
||||
RimPolygonFilter* lastItem = nullptr;
|
||||
|
||||
if ( polygons.empty() )
|
||||
{
|
||||
if ( auto lastCreatedOrUpdated = cellFilterCollection->addNewPolygonFilter( sourceCase, polygonDataSource ) )
|
||||
lastItem = cellFilterCollection->addNewPolygonFilter( sourceCase, nullptr );
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( auto polygon : polygons )
|
||||
{
|
||||
Riu3DMainWindowTools::selectAsCurrentItem( lastCreatedOrUpdated );
|
||||
lastItem = cellFilterCollection->addNewPolygonFilter( sourceCase, polygon );
|
||||
}
|
||||
}
|
||||
|
||||
if ( lastItem )
|
||||
{
|
||||
Riu3DMainWindowTools::selectAsCurrentItem( lastItem );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -94,3 +110,11 @@ void RicNewPolygonFilterFeature::setupActionLook( QAction* actionToSetup )
|
||||
actionToSetup->setIcon( QIcon( ":/CellFilter_Polygon.png" ) );
|
||||
actionToSetup->setText( "User Defined Polygon Filter" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicNewPolygonFilterFeature::isCommandEnabled() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -18,16 +18,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "PolygonCommands/RicBasicPolygonFeature.h"
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicNewPolygonFilterFeature : public caf::CmdFeature
|
||||
class RicNewPolygonFilterFeature : public RicBasicPolygonFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicNewPolygonFilterFeature();
|
||||
|
||||
protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
bool isCommandEnabled() const override;
|
||||
};
|
||||
|
@ -27,12 +27,22 @@
|
||||
#include "Polygons/RimPolygon.h"
|
||||
#include "Polygons/RimPolygonInView.h"
|
||||
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicNewPolygonIntersectionFeature, "RicNewPolygonIntersectionFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicNewPolygonIntersectionFeature::RicNewPolygonIntersectionFeature()
|
||||
: RicBasicPolygonFeature( true /*multiselect*/ )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -44,18 +54,21 @@ void RicNewPolygonIntersectionFeature::onActionTriggered( bool isChecked )
|
||||
auto collection = activeView->intersectionCollection();
|
||||
if ( !collection ) return;
|
||||
|
||||
auto polygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
|
||||
if ( !polygon )
|
||||
auto polygons = selectedPolygons();
|
||||
|
||||
RimExtrudedCurveIntersection* lastItem = nullptr;
|
||||
|
||||
for ( auto polygon : polygons )
|
||||
{
|
||||
if ( auto polygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>() )
|
||||
{
|
||||
polygon = polygonInView->polygon();
|
||||
}
|
||||
auto intersection = new RimExtrudedCurveIntersection();
|
||||
intersection->configureForProjectPolyLine( polygon );
|
||||
collection->appendIntersectionAndUpdate( intersection );
|
||||
}
|
||||
|
||||
auto intersection = new RimExtrudedCurveIntersection();
|
||||
intersection->configureForProjectPolyLine( polygon );
|
||||
collection->appendIntersectionAndUpdate( intersection );
|
||||
if ( lastItem != nullptr )
|
||||
{
|
||||
Riu3DMainWindowTools::selectAsCurrentItem( lastItem );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -18,15 +18,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "PolygonCommands/RicBasicPolygonFeature.h"
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicNewPolygonIntersectionFeature : public caf::CmdFeature
|
||||
class RicNewPolygonIntersectionFeature : public RicBasicPolygonFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicNewPolygonIntersectionFeature();
|
||||
|
||||
protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
@ -6,6 +6,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonCsvFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicBasicPolygonFeature.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@ -16,6 +17,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonCsvFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicBasicPolygonFeature.cpp
|
||||
)
|
||||
|
||||
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||
|
@ -0,0 +1,74 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RicBasicPolygonFeature.h"
|
||||
|
||||
#include "Polygons/RimPolygon.h"
|
||||
#include "Polygons/RimPolygonInView.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
#include <cafSelectionManagerTools.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicBasicPolygonFeature::RicBasicPolygonFeature( bool multiSelectSupported )
|
||||
: m_multiSelectSupported( multiSelectSupported )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicBasicPolygonFeature::isCommandEnabled() const
|
||||
{
|
||||
auto polygons = selectedPolygons();
|
||||
|
||||
return m_multiSelectSupported ? polygons.size() > 0 : polygons.size() == 1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimPolygon*> RicBasicPolygonFeature::selectedPolygons() const
|
||||
{
|
||||
std::set<RimPolygon*> uniquePolygons;
|
||||
|
||||
auto polygons = caf::selectedObjectsByType<RimPolygon*>();
|
||||
auto polygonivs = caf::selectedObjectsByType<RimPolygonInView*>();
|
||||
for ( auto piv : polygonivs )
|
||||
{
|
||||
polygons.push_back( piv->polygon() );
|
||||
}
|
||||
|
||||
// make sure we avoid duplicates
|
||||
for ( auto p : polygons )
|
||||
{
|
||||
uniquePolygons.insert( p );
|
||||
}
|
||||
|
||||
std::vector<RimPolygon*> returnPolygons;
|
||||
for ( auto p : uniquePolygons )
|
||||
{
|
||||
returnPolygons.push_back( p );
|
||||
}
|
||||
|
||||
return returnPolygons;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RimPolygon;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicBasicPolygonFeature : public caf::CmdFeature
|
||||
{
|
||||
public:
|
||||
RicBasicPolygonFeature( bool multiSelectSupported );
|
||||
|
||||
protected:
|
||||
std::vector<RimPolygon*> selectedPolygons() const;
|
||||
bool isCommandEnabled() const override;
|
||||
|
||||
private:
|
||||
bool m_multiSelectSupported;
|
||||
};
|
@ -31,26 +31,29 @@
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
#include "cafSelectionManagerTools.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicDuplicatePolygonFeature, "RicDuplicatePolygonFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicDuplicatePolygonFeature::RicDuplicatePolygonFeature()
|
||||
: RicBasicPolygonFeature( false /*multiselect*/ )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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();
|
||||
}
|
||||
}
|
||||
auto selPolygons = selectedPolygons();
|
||||
if ( selPolygons.empty() ) return;
|
||||
|
||||
if ( !sourcePolygon ) return;
|
||||
auto sourcePolygon = selPolygons[0];
|
||||
|
||||
auto proj = RimProject::current();
|
||||
auto polygonCollection = proj->activeOilField()->polygonCollection();
|
||||
|
@ -18,15 +18,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "RicBasicPolygonFeature.h"
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicDuplicatePolygonFeature : public caf::CmdFeature
|
||||
class RicDuplicatePolygonFeature : public RicBasicPolygonFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicDuplicatePolygonFeature();
|
||||
|
||||
protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
@ -27,29 +27,28 @@
|
||||
|
||||
#include "RiuFileDialogTools.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileInfo>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicExportPolygonCsvFeature, "RicExportPolygonCsvFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicExportPolygonCsvFeature::RicExportPolygonCsvFeature()
|
||||
: RicBasicPolygonFeature( false /*multiselect*/ )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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();
|
||||
}
|
||||
}
|
||||
auto selPolygons = selectedPolygons();
|
||||
if ( selPolygons.empty() ) return;
|
||||
|
||||
if ( !sourcePolygon ) return;
|
||||
auto sourcePolygon = selPolygons[0];
|
||||
|
||||
auto app = RiaGuiApplication::instance();
|
||||
auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" );
|
||||
|
@ -18,15 +18,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "RicBasicPolygonFeature.h"
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicExportPolygonCsvFeature : public caf::CmdFeature
|
||||
class RicExportPolygonCsvFeature : public RicBasicPolygonFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicExportPolygonCsvFeature();
|
||||
|
||||
protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
@ -34,36 +34,35 @@
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicExportPolygonPolFeature, "RicExportPolygonPolFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicExportPolygonPolFeature::RicExportPolygonPolFeature()
|
||||
: RicBasicPolygonFeature( true /*multiselect*/ )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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 selPolygons = selectedPolygons();
|
||||
if ( selPolygons.empty() ) 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 polygonFileName = polygonPath + "/" + selPolygons[0]->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 ) )
|
||||
if ( !RimPolygonTools::exportPolygonPol( selPolygons, fileName ) )
|
||||
{
|
||||
RiaLogging::error( "Failed to export polygon to " + fileName );
|
||||
RiaLogging::error( "Failed to export polygon(s) to " + fileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -18,15 +18,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "RicBasicPolygonFeature.h"
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicExportPolygonPolFeature : public caf::CmdFeature
|
||||
class RicExportPolygonPolFeature : public RicBasicPolygonFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicExportPolygonPolFeature();
|
||||
|
||||
protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "Polygons/RimPolygonFile.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
#include <cafSelectionManagerTools.h>
|
||||
|
||||
#include <QAction>
|
||||
|
||||
@ -31,13 +32,13 @@ CAF_CMD_SOURCE_INIT( RicReloadPolygonFileFeature, "RicReloadPolygonFileFeature"
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicReloadPolygonFileFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
auto polygonFile = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonFile>();
|
||||
if ( polygonFile )
|
||||
{
|
||||
polygonFile->loadData();
|
||||
polygonFile->objectChanged.send();
|
||||
auto polygonFiles = caf::selectedObjectsByType<RimPolygonFile*>();
|
||||
|
||||
polygonFile->updateConnectedEditors();
|
||||
for ( auto p : polygonFiles )
|
||||
{
|
||||
p->loadData();
|
||||
p->objectChanged.send();
|
||||
p->updateConnectedEditors();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,22 +30,21 @@
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicSimplifyPolygonFeature, "RicSimplifyPolygonFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicSimplifyPolygonFeature::RicSimplifyPolygonFeature()
|
||||
: RicBasicPolygonFeature( true /*multiselect*/ )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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;
|
||||
auto selPolygons = selectedPolygons();
|
||||
if ( selPolygons.empty() ) return;
|
||||
|
||||
const double defaultEpsilon = 10.0;
|
||||
|
||||
@ -53,7 +52,9 @@ void RicSimplifyPolygonFeature::onActionTriggered( bool isChecked )
|
||||
auto epsilon =
|
||||
QInputDialog::getDouble( nullptr, "Simplify Polygon Threshold", "Threshold:", defaultEpsilon, 1.0, 1000.0, 1, &ok, Qt::WindowFlags(), 1 );
|
||||
|
||||
if ( ok )
|
||||
if ( !ok ) return;
|
||||
|
||||
for ( auto sourcePolygon : selPolygons )
|
||||
{
|
||||
auto coords = sourcePolygon->pointsInDomainCoords();
|
||||
RigCellGeometryTools::simplifyPolygon( &coords, epsilon );
|
||||
|
@ -18,15 +18,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "RicBasicPolygonFeature.h"
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicSimplifyPolygonFeature : public caf::CmdFeature
|
||||
class RicSimplifyPolygonFeature : public RicBasicPolygonFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RicSimplifyPolygonFeature();
|
||||
|
||||
protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
@ -37,7 +37,7 @@ CAF_PDM_SOURCE_INIT( RimPolygonFile, "RimPolygonFileFile" );
|
||||
RimPolygonFile::RimPolygonFile()
|
||||
: objectChanged( this )
|
||||
{
|
||||
CAF_PDM_InitObject( "PolygonFile", ":/PolylinesFromFile16x16.png" );
|
||||
CAF_PDM_InitObject( "PolygonFile", ":/Folder.png" );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_fileName, "StimPlanFileName", "File Name" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_polygons, "Polygons", "Polygons" );
|
||||
|
@ -103,9 +103,9 @@ bool RimPolygonTools::exportPolygonCsv( const RimPolygon* polygon, const QString
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimPolygonTools::exportPolygonPol( const RimPolygon* polygon, const QString& filePath )
|
||||
bool RimPolygonTools::exportPolygonPol( const std::vector<RimPolygon*> polygons, const QString& filePath )
|
||||
{
|
||||
if ( !polygon ) return false;
|
||||
if ( polygons.empty() ) return false;
|
||||
|
||||
QFile file( filePath );
|
||||
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) return false;
|
||||
@ -122,20 +122,23 @@ bool RimPolygonTools::exportPolygonPol( const RimPolygon* polygon, const QString
|
||||
header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
|
||||
formatter.header( header );
|
||||
|
||||
for ( const auto& point : polygon->pointsInDomainCoords() )
|
||||
for ( auto polygon : polygons )
|
||||
{
|
||||
formatter.add( point.x() );
|
||||
formatter.add( point.y() );
|
||||
formatter.add( -point.z() );
|
||||
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();
|
||||
}
|
||||
|
||||
const double endOfPolygon = 999.0;
|
||||
formatter.add( endOfPolygon );
|
||||
formatter.add( endOfPolygon );
|
||||
formatter.add( endOfPolygon );
|
||||
formatter.rowCompleted();
|
||||
|
||||
formatter.tableCompleted();
|
||||
|
||||
file.close();
|
||||
|
@ -23,6 +23,8 @@ class RimPolygonInView;
|
||||
|
||||
class QString;
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmObject;
|
||||
@ -34,7 +36,7 @@ public:
|
||||
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 bool exportPolygonPol( const std::vector<RimPolygon*> polygons, const QString& filePath );
|
||||
|
||||
static QString polygonCacheName();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user