mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
* #14411 Enforce name uniqueness for surfaces, polygons and folders Names must be unique among siblings sharing the same parent folder. Items in different folders may keep identical names, and comparison is case sensitive. Siblings are the objects held by the same caf::PdmChildArrayField. Items and folders live in two distinct child arrays in caf::PdmNestedCollection, so a folder and an item may share a name under the same parent. The Python API gets an OnNameConflict flag on AddFolder, CreatePolygon, ImportSurface and NewRegularSurface, supporting FAIL (default), AUTO_RENAME and OVERWRITE. NewSurface is left out, as grid case surfaces derive their tree label from the case and K index and carry no name of their own.
296 lines
12 KiB
C++
296 lines
12 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// 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 "RimPolygon.h"
|
|
|
|
#include "RiaApplication.h"
|
|
#include "RiaColorTools.h"
|
|
#include "RiaNameUniquenessTools.h"
|
|
#include "RiaVec3Tools.h"
|
|
|
|
#include "RigPolyLinesData.h"
|
|
|
|
#include "Rim3dView.h"
|
|
#include "RimPolygonAppearance.h"
|
|
#include "RimPolygonTools.h"
|
|
|
|
#include "RiuGuiTheme.h"
|
|
|
|
#include "cafCmdFeatureMenuBuilder.h"
|
|
#include "cafPdmFieldScriptingCapability.h"
|
|
#include "cafPdmFieldScriptingCapabilityCvfVec3d.h"
|
|
#include "cafPdmObjectScriptingCapability.h"
|
|
#include "cafPdmUiButton.h"
|
|
#include "cafPdmUiColorEditor.h"
|
|
#include "cafPdmUiTreeAttributes.h"
|
|
|
|
CAF_PDM_SOURCE_INIT( RimPolygon, "Polygon", "RimPolygon" );
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
RimPolygon::RimPolygon()
|
|
: objectChanged( this )
|
|
, coordinatesChanged( this )
|
|
{
|
|
CAF_PDM_InitScriptableObject( "Polygon", ":/PolylinesFromFile16x16.png" );
|
|
|
|
CAF_PDM_InitField( &m_isReadOnly, "IsReadOnly", false, "Read Only" );
|
|
CAF_PDM_InitScriptableFieldWithScriptKeywordNoDefault( &m_pointsInDomainCoords, "PointsInDomainCoords", "Coordinates", "Points" );
|
|
m_pointsInDomainCoords.uiCapability()->setUiHidden( true );
|
|
|
|
CAF_PDM_InitFieldNoDefault( &m_pointsInDomainCoordsForUi, "PointsInDomainCoordsUi", "Coordinates" );
|
|
m_pointsInDomainCoordsForUi.registerSetMethod( this, &RimPolygon::setPointsInDomainCoordsFromXyd );
|
|
m_pointsInDomainCoordsForUi.registerGetMethod( this, &RimPolygon::pointsInDomainCoordsXyd );
|
|
m_pointsInDomainCoordsForUi.xmlCapability()->disableIO();
|
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_appearance, "Appearance", "Appearance" );
|
|
m_appearance = new RimPolygonAppearance;
|
|
m_appearance.uiCapability()->setUiTreeChildrenHidden( true );
|
|
|
|
setDeletable( true );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
cvf::ref<RigPolyLinesData> RimPolygon::polyLinesData() const
|
|
{
|
|
cvf::ref<RigPolyLinesData> pld = new RigPolyLinesData;
|
|
|
|
pld->setPolyLine( m_pointsInDomainCoords() );
|
|
m_appearance->applyAppearanceSettings( pld.p() );
|
|
|
|
return pld;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::uiOrderingForLocalPolygon( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
{
|
|
m_appearance->uiOrdering( uiConfigName, uiOrdering );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
|
|
{
|
|
RimPolygon::appendPolygonMenuItems( menuBuilder );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::setPointsInDomainCoords( const std::vector<cvf::Vec3d>& points )
|
|
{
|
|
m_pointsInDomainCoords = points;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<cvf::Vec3d> RimPolygon::pointsInDomainCoords() const
|
|
{
|
|
return m_pointsInDomainCoords();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
std::vector<cvf::Vec3d> RimPolygon::pointsInDomainCoordsXyd() const
|
|
{
|
|
return RiaVec3Tools::invertZSign( m_pointsInDomainCoords() );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::setPointsInDomainCoordsFromXyd( const std::vector<cvf::Vec3d>& pointsXyd )
|
|
{
|
|
m_pointsInDomainCoords = RiaVec3Tools::invertZSign( pointsXyd );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::setIsClosed( bool isClosed )
|
|
{
|
|
m_appearance->setIsClosed( isClosed );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RimPolygon::isClosed() const
|
|
{
|
|
return m_appearance->isClosed();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::setReadOnly( bool isReadOnly )
|
|
{
|
|
m_isReadOnly = isReadOnly;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RimPolygon::isReadOnly() const
|
|
{
|
|
return m_isReadOnly();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::disableStorageOfPolygonPoints()
|
|
{
|
|
m_pointsInDomainCoords.xmlCapability()->setIOWritable( false );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
cvf::Color3f RimPolygon::color() const
|
|
{
|
|
return m_appearance->lineColor();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::setColor( const cvf::Color3f& color )
|
|
{
|
|
m_appearance->setLineColor( color );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool RimPolygon::showLines() const
|
|
{
|
|
return m_appearance->showLines();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
|
{
|
|
uiOrdering.add( nameField() );
|
|
uiOrdering.add( &m_isReadOnly );
|
|
uiOrdering.addNewButton( m_isReadOnly() ? "Select in Active View" : "Edit in Active View",
|
|
[this]()
|
|
{
|
|
auto activeView = RiaApplication::instance()->activeReservoirView();
|
|
RimPolygonTools::activate3dEditOfPolygonInView( this, activeView );
|
|
} );
|
|
|
|
auto groupPoints = uiOrdering.addNewGroup( "Points" );
|
|
groupPoints->setCollapsedByDefault();
|
|
groupPoints->add( &m_pointsInDomainCoordsForUi );
|
|
|
|
m_pointsInDomainCoordsForUi.uiCapability()->setUiReadOnly( m_isReadOnly() );
|
|
|
|
auto group = uiOrdering.addNewGroup( "Appearance" );
|
|
m_appearance->uiOrdering( uiConfigName, *group );
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
|
{
|
|
if ( changedField == &m_pointsInDomainCoords || changedField == &m_pointsInDomainCoordsForUi )
|
|
{
|
|
coordinatesChanged.send();
|
|
}
|
|
else if ( changedField == nameField() )
|
|
{
|
|
// Keep the name unique among the polygons in the same folder
|
|
setName( RiaNameUniquenessTools::resolveRenameConflict( this, newValue.toString() ) );
|
|
}
|
|
|
|
objectChanged.send();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField )
|
|
{
|
|
objectChanged.send();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::onColorTagClicked( const SignalEmitter* emitter, size_t index )
|
|
{
|
|
QColor sourceColor = RiaColorTools::toQColor( color() );
|
|
QColor newColor = caf::PdmUiColorEditor::getColor( sourceColor );
|
|
|
|
if ( newColor.isValid() && newColor != sourceColor )
|
|
{
|
|
setColor( RiaColorTools::fromQColorTo3f( newColor ) );
|
|
objectChanged.send();
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::appendPolygonMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder )
|
|
{
|
|
menuBuilder << "RicNewPolygonIntersectionFeature";
|
|
menuBuilder.addCmdFeature( "RicNewPolygonFilterFeature", "Create Polygon Filter" );
|
|
menuBuilder << "Separator";
|
|
|
|
menuBuilder << "RicDuplicatePolygonFeature";
|
|
menuBuilder << "RicSimplifyPolygonFeature";
|
|
menuBuilder << "Separator";
|
|
menuBuilder << "RicExportPolygonCsvFeature";
|
|
menuBuilder << "RicExportPolygonPolFeature";
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
///
|
|
//--------------------------------------------------------------------------------------------------
|
|
void RimPolygon::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
|
|
{
|
|
if ( auto* treeItemAttribute = dynamic_cast<caf::PdmUiTreeViewItemAttribute*>( attribute ) )
|
|
{
|
|
auto tag = caf::PdmUiTreeViewItemAttribute::createTag( RiaColorTools::toQColor( color() ),
|
|
RiuGuiTheme::getColorByVariableName( "backgroundColor1" ),
|
|
"---" );
|
|
|
|
tag->clicked.connect( this, &RimPolygon::onColorTagClicked );
|
|
|
|
treeItemAttribute->tags.push_back( std::move( tag ) );
|
|
}
|
|
|
|
if ( m_isReadOnly )
|
|
{
|
|
caf::PdmUiTreeViewItemAttribute::appendTagToTreeViewItemAttribute( attribute, ":/padlock.svg" );
|
|
}
|
|
}
|