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" );
|
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>();
|
auto cellFilterCollection = caf::SelectionManager::instance()->selectedItemOfType<RimCellFilterCollection>();
|
||||||
|
|
||||||
if ( !cellFilterCollection )
|
if ( !cellFilterCollection )
|
||||||
{
|
{
|
||||||
RimGridView* activeView = RiaApplication::instance()->activeMainOrComparisonGridView();
|
RimGridView* activeView = RiaApplication::instance()->activeMainOrComparisonGridView();
|
||||||
@ -59,31 +66,40 @@ void RicNewPolygonFilterFeature::onActionTriggered( bool isChecked )
|
|||||||
cellFilterCollection = activeView->cellFilterCollection();
|
cellFilterCollection = activeView->cellFilterCollection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !cellFilterCollection ) return;
|
if ( !cellFilterCollection ) return;
|
||||||
|
|
||||||
if ( !polygonDataSource )
|
auto sourceCase = cellFilterCollection->firstAncestorOrThisOfTypeAsserted<Rim3dView>()->ownerCase();
|
||||||
{
|
if ( !sourceCase ) return;
|
||||||
auto selectedPolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
|
|
||||||
if ( !selectedPolygon )
|
|
||||||
{
|
|
||||||
if ( auto polygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>() )
|
|
||||||
{
|
|
||||||
selectedPolygon = polygonInView->polygon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
polygonDataSource = selectedPolygon;
|
std::vector<RimPolygon*> polygons;
|
||||||
|
|
||||||
|
if ( polygonDataSource )
|
||||||
|
{
|
||||||
|
polygons.push_back( polygonDataSource );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
polygons = selectedPolygons();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sourceCase = cellFilterCollection->firstAncestorOrThisOfTypeAsserted<Rim3dView>()->ownerCase();
|
RimPolygonFilter* lastItem = nullptr;
|
||||||
if ( sourceCase )
|
|
||||||
|
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->setIcon( QIcon( ":/CellFilter_Polygon.png" ) );
|
||||||
actionToSetup->setText( "User Defined Polygon Filter" );
|
actionToSetup->setText( "User Defined Polygon Filter" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RicNewPolygonFilterFeature::isCommandEnabled() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -18,16 +18,20 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cafCmdFeature.h"
|
#include "PolygonCommands/RicBasicPolygonFeature.h"
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RicNewPolygonFilterFeature : public caf::CmdFeature
|
class RicNewPolygonFilterFeature : public RicBasicPolygonFeature
|
||||||
{
|
{
|
||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RicNewPolygonFilterFeature();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onActionTriggered( bool isChecked ) override;
|
void onActionTriggered( bool isChecked ) override;
|
||||||
void setupActionLook( QAction* actionToSetup ) override;
|
void setupActionLook( QAction* actionToSetup ) override;
|
||||||
|
bool isCommandEnabled() const override;
|
||||||
};
|
};
|
||||||
|
@ -27,12 +27,22 @@
|
|||||||
#include "Polygons/RimPolygon.h"
|
#include "Polygons/RimPolygon.h"
|
||||||
#include "Polygons/RimPolygonInView.h"
|
#include "Polygons/RimPolygonInView.h"
|
||||||
|
|
||||||
|
#include "Riu3DMainWindowTools.h"
|
||||||
|
|
||||||
#include "cafSelectionManager.h"
|
#include "cafSelectionManager.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
CAF_CMD_SOURCE_INIT( RicNewPolygonIntersectionFeature, "RicNewPolygonIntersectionFeature" );
|
CAF_CMD_SOURCE_INIT( RicNewPolygonIntersectionFeature, "RicNewPolygonIntersectionFeature" );
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RicNewPolygonIntersectionFeature::RicNewPolygonIntersectionFeature()
|
||||||
|
: RicBasicPolygonFeature( true /*multiselect*/ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -44,18 +54,21 @@ void RicNewPolygonIntersectionFeature::onActionTriggered( bool isChecked )
|
|||||||
auto collection = activeView->intersectionCollection();
|
auto collection = activeView->intersectionCollection();
|
||||||
if ( !collection ) return;
|
if ( !collection ) return;
|
||||||
|
|
||||||
auto polygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
|
auto polygons = selectedPolygons();
|
||||||
if ( !polygon )
|
|
||||||
|
RimExtrudedCurveIntersection* lastItem = nullptr;
|
||||||
|
|
||||||
|
for ( auto polygon : polygons )
|
||||||
{
|
{
|
||||||
if ( auto polygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>() )
|
auto intersection = new RimExtrudedCurveIntersection();
|
||||||
{
|
intersection->configureForProjectPolyLine( polygon );
|
||||||
polygon = polygonInView->polygon();
|
collection->appendIntersectionAndUpdate( intersection );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto intersection = new RimExtrudedCurveIntersection();
|
if ( lastItem != nullptr )
|
||||||
intersection->configureForProjectPolyLine( polygon );
|
{
|
||||||
collection->appendIntersectionAndUpdate( intersection );
|
Riu3DMainWindowTools::selectAsCurrentItem( lastItem );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -18,15 +18,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cafCmdFeature.h"
|
#include "PolygonCommands/RicBasicPolygonFeature.h"
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RicNewPolygonIntersectionFeature : public caf::CmdFeature
|
class RicNewPolygonIntersectionFeature : public RicBasicPolygonFeature
|
||||||
{
|
{
|
||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RicNewPolygonIntersectionFeature();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onActionTriggered( bool isChecked ) override;
|
void onActionTriggered( bool isChecked ) override;
|
||||||
void setupActionLook( QAction* actionToSetup ) 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}/RicExportPolygonCsvFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RicBasicPolygonFeature.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCE_GROUP_SOURCE_FILES
|
set(SOURCE_GROUP_SOURCE_FILES
|
||||||
@ -16,6 +17,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonCsvFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonCsvFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicExportPolygonPolFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicSimplifyPolygonFeature.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RicBasicPolygonFeature.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
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 "Riu3DMainWindowTools.h"
|
||||||
|
|
||||||
#include "cafSelectionManager.h"
|
#include "cafSelectionManager.h"
|
||||||
|
#include "cafSelectionManagerTools.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
CAF_CMD_SOURCE_INIT( RicDuplicatePolygonFeature, "RicDuplicatePolygonFeature" );
|
CAF_CMD_SOURCE_INIT( RicDuplicatePolygonFeature, "RicDuplicatePolygonFeature" );
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RicDuplicatePolygonFeature::RicDuplicatePolygonFeature()
|
||||||
|
: RicBasicPolygonFeature( false /*multiselect*/ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicDuplicatePolygonFeature::onActionTriggered( bool isChecked )
|
void RicDuplicatePolygonFeature::onActionTriggered( bool isChecked )
|
||||||
{
|
{
|
||||||
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
|
auto selPolygons = selectedPolygons();
|
||||||
if ( !sourcePolygon )
|
if ( selPolygons.empty() ) return;
|
||||||
{
|
|
||||||
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
|
|
||||||
if ( sourcePolygonInView )
|
|
||||||
{
|
|
||||||
sourcePolygon = sourcePolygonInView->polygon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !sourcePolygon ) return;
|
auto sourcePolygon = selPolygons[0];
|
||||||
|
|
||||||
auto proj = RimProject::current();
|
auto proj = RimProject::current();
|
||||||
auto polygonCollection = proj->activeOilField()->polygonCollection();
|
auto polygonCollection = proj->activeOilField()->polygonCollection();
|
||||||
|
@ -18,15 +18,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cafCmdFeature.h"
|
#include "RicBasicPolygonFeature.h"
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RicDuplicatePolygonFeature : public caf::CmdFeature
|
class RicDuplicatePolygonFeature : public RicBasicPolygonFeature
|
||||||
{
|
{
|
||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RicDuplicatePolygonFeature();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onActionTriggered( bool isChecked ) override;
|
void onActionTriggered( bool isChecked ) override;
|
||||||
void setupActionLook( QAction* actionToSetup ) override;
|
void setupActionLook( QAction* actionToSetup ) override;
|
||||||
|
@ -27,29 +27,28 @@
|
|||||||
|
|
||||||
#include "RiuFileDialogTools.h"
|
#include "RiuFileDialogTools.h"
|
||||||
|
|
||||||
#include "cafSelectionManager.h"
|
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
CAF_CMD_SOURCE_INIT( RicExportPolygonCsvFeature, "RicExportPolygonCsvFeature" );
|
CAF_CMD_SOURCE_INIT( RicExportPolygonCsvFeature, "RicExportPolygonCsvFeature" );
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RicExportPolygonCsvFeature::RicExportPolygonCsvFeature()
|
||||||
|
: RicBasicPolygonFeature( false /*multiselect*/ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicExportPolygonCsvFeature::onActionTriggered( bool isChecked )
|
void RicExportPolygonCsvFeature::onActionTriggered( bool isChecked )
|
||||||
{
|
{
|
||||||
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
|
auto selPolygons = selectedPolygons();
|
||||||
if ( !sourcePolygon )
|
if ( selPolygons.empty() ) return;
|
||||||
{
|
|
||||||
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
|
|
||||||
if ( sourcePolygonInView )
|
|
||||||
{
|
|
||||||
sourcePolygon = sourcePolygonInView->polygon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !sourcePolygon ) return;
|
auto sourcePolygon = selPolygons[0];
|
||||||
|
|
||||||
auto app = RiaGuiApplication::instance();
|
auto app = RiaGuiApplication::instance();
|
||||||
auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" );
|
auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" );
|
||||||
|
@ -18,15 +18,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cafCmdFeature.h"
|
#include "RicBasicPolygonFeature.h"
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RicExportPolygonCsvFeature : public caf::CmdFeature
|
class RicExportPolygonCsvFeature : public RicBasicPolygonFeature
|
||||||
{
|
{
|
||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RicExportPolygonCsvFeature();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onActionTriggered( bool isChecked ) override;
|
void onActionTriggered( bool isChecked ) override;
|
||||||
void setupActionLook( QAction* actionToSetup ) override;
|
void setupActionLook( QAction* actionToSetup ) override;
|
||||||
|
@ -34,36 +34,35 @@
|
|||||||
|
|
||||||
CAF_CMD_SOURCE_INIT( RicExportPolygonPolFeature, "RicExportPolygonPolFeature" );
|
CAF_CMD_SOURCE_INIT( RicExportPolygonPolFeature, "RicExportPolygonPolFeature" );
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RicExportPolygonPolFeature::RicExportPolygonPolFeature()
|
||||||
|
: RicBasicPolygonFeature( true /*multiselect*/ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicExportPolygonPolFeature::onActionTriggered( bool isChecked )
|
void RicExportPolygonPolFeature::onActionTriggered( bool isChecked )
|
||||||
{
|
{
|
||||||
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
|
auto selPolygons = selectedPolygons();
|
||||||
if ( !sourcePolygon )
|
if ( selPolygons.empty() ) return;
|
||||||
{
|
|
||||||
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
|
|
||||||
if ( sourcePolygonInView )
|
|
||||||
{
|
|
||||||
sourcePolygon = sourcePolygonInView->polygon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !sourcePolygon ) return;
|
|
||||||
|
|
||||||
auto app = RiaGuiApplication::instance();
|
auto app = RiaGuiApplication::instance();
|
||||||
auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" );
|
auto fallbackPath = app->lastUsedDialogDirectory( "BINARY_GRID" );
|
||||||
auto polygonPath = app->lastUsedDialogDirectoryWithFallback( RimPolygonTools::polygonCacheName(), fallbackPath );
|
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,
|
auto fileName = RiuFileDialogTools::getSaveFileName( nullptr,
|
||||||
"Select File for Polygon Export to POL",
|
"Select File for Polygon Export to POL",
|
||||||
polygonFileName,
|
polygonFileName,
|
||||||
"POL Files (*.pol);;All files(*.*)" );
|
"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
|
else
|
||||||
{
|
{
|
||||||
|
@ -18,15 +18,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cafCmdFeature.h"
|
#include "RicBasicPolygonFeature.h"
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RicExportPolygonPolFeature : public caf::CmdFeature
|
class RicExportPolygonPolFeature : public RicBasicPolygonFeature
|
||||||
{
|
{
|
||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RicExportPolygonPolFeature();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onActionTriggered( bool isChecked ) override;
|
void onActionTriggered( bool isChecked ) override;
|
||||||
void setupActionLook( QAction* actionToSetup ) override;
|
void setupActionLook( QAction* actionToSetup ) override;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "Polygons/RimPolygonFile.h"
|
#include "Polygons/RimPolygonFile.h"
|
||||||
|
|
||||||
#include "cafSelectionManager.h"
|
#include "cafSelectionManager.h"
|
||||||
|
#include <cafSelectionManagerTools.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
@ -31,13 +32,13 @@ CAF_CMD_SOURCE_INIT( RicReloadPolygonFileFeature, "RicReloadPolygonFileFeature"
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicReloadPolygonFileFeature::onActionTriggered( bool isChecked )
|
void RicReloadPolygonFileFeature::onActionTriggered( bool isChecked )
|
||||||
{
|
{
|
||||||
auto polygonFile = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonFile>();
|
auto polygonFiles = caf::selectedObjectsByType<RimPolygonFile*>();
|
||||||
if ( polygonFile )
|
|
||||||
{
|
|
||||||
polygonFile->loadData();
|
|
||||||
polygonFile->objectChanged.send();
|
|
||||||
|
|
||||||
polygonFile->updateConnectedEditors();
|
for ( auto p : polygonFiles )
|
||||||
|
{
|
||||||
|
p->loadData();
|
||||||
|
p->objectChanged.send();
|
||||||
|
p->updateConnectedEditors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,22 +30,21 @@
|
|||||||
|
|
||||||
CAF_CMD_SOURCE_INIT( RicSimplifyPolygonFeature, "RicSimplifyPolygonFeature" );
|
CAF_CMD_SOURCE_INIT( RicSimplifyPolygonFeature, "RicSimplifyPolygonFeature" );
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RicSimplifyPolygonFeature::RicSimplifyPolygonFeature()
|
||||||
|
: RicBasicPolygonFeature( true /*multiselect*/ )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicSimplifyPolygonFeature::onActionTriggered( bool isChecked )
|
void RicSimplifyPolygonFeature::onActionTriggered( bool isChecked )
|
||||||
{
|
{
|
||||||
auto sourcePolygon = caf::SelectionManager::instance()->selectedItemOfType<RimPolygon>();
|
auto selPolygons = selectedPolygons();
|
||||||
if ( !sourcePolygon )
|
if ( selPolygons.empty() ) return;
|
||||||
{
|
|
||||||
auto sourcePolygonInView = caf::SelectionManager::instance()->selectedItemOfType<RimPolygonInView>();
|
|
||||||
if ( sourcePolygonInView )
|
|
||||||
{
|
|
||||||
sourcePolygon = sourcePolygonInView->polygon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !sourcePolygon ) return;
|
|
||||||
|
|
||||||
const double defaultEpsilon = 10.0;
|
const double defaultEpsilon = 10.0;
|
||||||
|
|
||||||
@ -53,7 +52,9 @@ void RicSimplifyPolygonFeature::onActionTriggered( bool isChecked )
|
|||||||
auto epsilon =
|
auto epsilon =
|
||||||
QInputDialog::getDouble( nullptr, "Simplify Polygon Threshold", "Threshold:", defaultEpsilon, 1.0, 1000.0, 1, &ok, Qt::WindowFlags(), 1 );
|
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();
|
auto coords = sourcePolygon->pointsInDomainCoords();
|
||||||
RigCellGeometryTools::simplifyPolygon( &coords, epsilon );
|
RigCellGeometryTools::simplifyPolygon( &coords, epsilon );
|
||||||
|
@ -18,15 +18,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cafCmdFeature.h"
|
#include "RicBasicPolygonFeature.h"
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
///
|
///
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RicSimplifyPolygonFeature : public caf::CmdFeature
|
class RicSimplifyPolygonFeature : public RicBasicPolygonFeature
|
||||||
{
|
{
|
||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RicSimplifyPolygonFeature();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onActionTriggered( bool isChecked ) override;
|
void onActionTriggered( bool isChecked ) override;
|
||||||
void setupActionLook( QAction* actionToSetup ) override;
|
void setupActionLook( QAction* actionToSetup ) override;
|
||||||
|
@ -37,7 +37,7 @@ CAF_PDM_SOURCE_INIT( RimPolygonFile, "RimPolygonFileFile" );
|
|||||||
RimPolygonFile::RimPolygonFile()
|
RimPolygonFile::RimPolygonFile()
|
||||||
: objectChanged( this )
|
: 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_fileName, "StimPlanFileName", "File Name" );
|
||||||
CAF_PDM_InitFieldNoDefault( &m_polygons, "Polygons", "Polygons" );
|
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 );
|
QFile file( filePath );
|
||||||
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) return false;
|
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 ) );
|
header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
|
||||||
formatter.header( header );
|
formatter.header( header );
|
||||||
|
|
||||||
for ( const auto& point : polygon->pointsInDomainCoords() )
|
for ( auto polygon : polygons )
|
||||||
{
|
{
|
||||||
formatter.add( point.x() );
|
for ( const auto& point : polygon->pointsInDomainCoords() )
|
||||||
formatter.add( point.y() );
|
{
|
||||||
formatter.add( -point.z() );
|
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.rowCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
const double endOfPolygon = 999.0;
|
|
||||||
formatter.add( endOfPolygon );
|
|
||||||
formatter.add( endOfPolygon );
|
|
||||||
formatter.add( endOfPolygon );
|
|
||||||
formatter.rowCompleted();
|
|
||||||
|
|
||||||
formatter.tableCompleted();
|
formatter.tableCompleted();
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
@ -23,6 +23,8 @@ class RimPolygonInView;
|
|||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace caf
|
namespace caf
|
||||||
{
|
{
|
||||||
class PdmObject;
|
class PdmObject;
|
||||||
@ -34,7 +36,7 @@ public:
|
|||||||
static void activate3dEditOfPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
|
static void activate3dEditOfPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
|
||||||
static void selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
|
static void selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
|
||||||
static bool exportPolygonCsv( const RimPolygon* polygon, const QString& filePath );
|
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();
|
static QString polygonCacheName();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user