mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-27 07:30:20 -05:00
#14411 Enforce name uniqueness for surfaces, polygons and folders
* #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.
This commit is contained in:
1 parent
5e791353b2
commit
ebf75c09a1
28 files changed
+889
-26
No files matched your search
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaColorTools.h"
|
||||
#include "RiaNameUniquenessTools.h"
|
||||
#include "RiaVec3Tools.h"
|
||||
|
||||
#include "RigPolyLinesData.h"
|
||||
@@ -223,6 +224,11 @@ void RimPolygon::fieldChangedByUi( const caf::PdmFieldHandle* changedField, cons
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "RimPolygonCollection.h"
|
||||
|
||||
#include "RiaColorTables.h"
|
||||
#include "RiaNameUniquenessTools.h"
|
||||
|
||||
#include "Rim3dView.h"
|
||||
#include "RimPolygon.h"
|
||||
@@ -69,7 +70,7 @@ RimPolygonCollection* RimPolygonCollection::createTopmost()
|
||||
RimPolygon* RimPolygonCollection::createUserDefinedPolygon()
|
||||
{
|
||||
auto newPolygon = new RimPolygon();
|
||||
newPolygon->setName( "Polygon " + QString::number( allPolygons().size() + 1 ) );
|
||||
newPolygon->setName( "Polygon " + QString::number( items().size() + 1 ) );
|
||||
|
||||
auto colorCandidates = RiaColorTables::summaryCurveDefaultPaletteColors();
|
||||
newPolygon->setColor( colorCandidates.cycledColor3f( allPolygons().size() ) );
|
||||
@@ -94,6 +95,7 @@ RimPolygon* RimPolygonCollection::appendUserDefinedPolygon()
|
||||
void RimPolygonCollection::addUserDefinedPolygon( RimPolygon* polygon )
|
||||
{
|
||||
m_items.push_back( polygon );
|
||||
ensureUniquePolygonName( polygon );
|
||||
|
||||
connectPolygonSignals( polygon );
|
||||
|
||||
@@ -140,6 +142,7 @@ void RimPolygonCollection::addPolygonFile( RimPolygonFile* polygonFile )
|
||||
if ( !polygonFile ) return;
|
||||
|
||||
addSubCollection( polygonFile );
|
||||
RiaNameUniquenessTools::ensureUniqueAmongSiblings( polygonFile );
|
||||
connectPolygonFileSignals( polygonFile );
|
||||
|
||||
updateViewTreeItems();
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "RimPolygonContainer.h"
|
||||
|
||||
#include "RiaNameUniquenessTools.h"
|
||||
|
||||
#include "RimPolygon.h"
|
||||
#include "RimPolygonCollection.h"
|
||||
|
||||
@@ -44,6 +46,20 @@ RimPolygonContainer* RimPolygonContainer::addNewSubCollection()
|
||||
return sub;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonContainer::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
||||
{
|
||||
if ( changedField == &m_collectionName )
|
||||
{
|
||||
// Keep the name unique among the folders in the same parent folder
|
||||
m_collectionName = RiaNameUniquenessTools::resolveRenameConflict( this, newValue.toString() );
|
||||
}
|
||||
|
||||
caf::PdmNestedCollection<RimPolygonContainer, RimPolygon>::fieldChangedByUi( changedField, oldValue, newValue );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -54,3 +70,13 @@ void RimPolygonContainer::loadData()
|
||||
if ( sub ) sub->loadData();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPolygonContainer::ensureUniquePolygonName( RimPolygon* polygon )
|
||||
{
|
||||
if ( !polygon ) return;
|
||||
|
||||
RiaNameUniquenessTools::ensureUniqueAmongSiblings( polygon );
|
||||
}
|
||||
@@ -48,4 +48,11 @@ public:
|
||||
// Default behavior recurses into sub-collections. Leaf containers (e.g., file-backed)
|
||||
// override to load their own data; folder containers inherit the recursion.
|
||||
virtual void loadData();
|
||||
|
||||
// Renames the polygon if another polygon in this container already carries the same name.
|
||||
void ensureUniquePolygonName( RimPolygon* polygon );
|
||||
|
||||
protected:
|
||||
// Enforces name uniqueness among sibling folders when the folder is renamed.
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
};
|
||||
@@ -98,6 +98,12 @@ void RimPolygonFile::loadData()
|
||||
m_items.deleteChildren();
|
||||
|
||||
m_items.setValue( polygonsFromFile );
|
||||
|
||||
// A file may contain several polygons sharing the same id, and thus the same generated name
|
||||
for ( auto* polygon : polygonsFromFile )
|
||||
{
|
||||
ensureUniquePolygonName( polygon );
|
||||
}
|
||||
}
|
||||
|
||||
if ( polygonsFromFile.empty() )
|
||||
@@ -179,6 +185,8 @@ void RimPolygonFile::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
||||
loadData();
|
||||
}
|
||||
|
||||
RimPolygonContainer::fieldChangedByUi( changedField, oldValue, newValue );
|
||||
|
||||
objectChanged.send();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "RimSurface.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaNameUniquenessTools.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RimProject.h"
|
||||
@@ -252,6 +253,9 @@ void RimSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField, cons
|
||||
}
|
||||
else if ( changedField == &m_userDescription )
|
||||
{
|
||||
// Keep the name unique among the surfaces in the same folder
|
||||
m_userDescription = RiaNameUniquenessTools::resolveRenameConflict( this, newValue.toString() );
|
||||
|
||||
updateConnectedEditors();
|
||||
}
|
||||
else if ( changedField == &m_depthOffset )
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "RiaColorTables.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaNameUniquenessTools.h"
|
||||
|
||||
#include "Rim2dIntersectionView.h"
|
||||
#include "Rim2dIntersectionViewCollection.h"
|
||||
@@ -92,6 +93,31 @@ RimSurfaceCollection* RimSurfaceCollection::createTopmost()
|
||||
void RimSurfaceCollection::addSurface( RimSurface* surface )
|
||||
{
|
||||
m_items.push_back( surface );
|
||||
ensureUniqueSurfaceName( surface );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSurfaceCollection::ensureUniqueSurfaceName( RimSurface* surface )
|
||||
{
|
||||
if ( !surface ) return;
|
||||
|
||||
RiaNameUniquenessTools::ensureUniqueAmongSiblings( surface );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSurfaceCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
|
||||
{
|
||||
if ( changedField == &m_collectionName )
|
||||
{
|
||||
// Keep the name unique among the folders in the same parent folder
|
||||
m_collectionName = RiaNameUniquenessTools::resolveRenameConflict( this, newValue.toString() );
|
||||
}
|
||||
|
||||
caf::PdmNestedCollection<RimSurfaceCollection, RimSurface>::fieldChangedByUi( changedField, oldValue, newValue );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -234,6 +260,7 @@ RimSurface* RimSurfaceCollection::copySurfaces( std::vector<RimSurface*> surface
|
||||
for ( RimSurface* surface : newsurfaces )
|
||||
{
|
||||
m_items.push_back( surface );
|
||||
ensureUniqueSurfaceName( surface );
|
||||
retsurf = surface;
|
||||
}
|
||||
|
||||
@@ -259,6 +286,7 @@ RimSurface* RimSurfaceCollection::addGridCaseSurface( RimCase* sourceCase, int o
|
||||
}
|
||||
|
||||
m_items.push_back( s );
|
||||
ensureUniqueSurfaceName( s );
|
||||
|
||||
updateConnectedEditors();
|
||||
|
||||
@@ -481,6 +509,12 @@ RimSurface* RimSurfaceCollection::addSurfacesAtIndex( int position, std::vector<
|
||||
}
|
||||
}
|
||||
|
||||
// Surfaces moved in from another folder may collide with the names already present here
|
||||
for ( auto surf : surfaces )
|
||||
{
|
||||
ensureUniqueSurfaceName( surf );
|
||||
}
|
||||
|
||||
// make sure the views are in sync with the collection order
|
||||
updateViews();
|
||||
|
||||
|
||||
@@ -64,9 +64,15 @@ public:
|
||||
|
||||
std::vector<RimSurface*> surfaces() const;
|
||||
|
||||
// Renames the surface if another surface in this folder already carries the same name.
|
||||
void ensureUniqueSurfaceName( RimSurface* surface );
|
||||
|
||||
protected:
|
||||
void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override;
|
||||
|
||||
// Enforces name uniqueness among sibling folders when the folder is renamed.
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
|
||||
private:
|
||||
void orderChanged( const caf::SignalEmitter* emitter );
|
||||
};
|
||||
Reference in new issue
Block a user