Skip to content

#14411 Enforce name uniqueness for surfaces, polygons and folders - #14425

Open
magnesj wants to merge 2 commits into
OPM:devfrom
magnesj:feature/14411-name-uniqueness
Open

#14411 Enforce name uniqueness for surfaces, polygons and folders#14425
magnesj wants to merge 2 commits into
OPM:devfrom
magnesj:feature/14411-name-uniqueness

Conversation

@magnesj

@magnesj magnesj commented Jul 31, 2026

Copy link
Copy Markdown
Member

Closes #14411

Names must be unique among siblings sharing the same parent folder. Items in different folders may keep identical names, and comparison is case sensitive.

Approach

Both trees now sit on caf::PdmNestedCollection<SelfT, ItemT>, which keeps items in m_items and folders in m_subCollections. RiaNameUniquenessTools builds on that: siblings are simply the other objects in the same caf::PdmChildArrayField, reached through parentField(). That makes one generic helper enough for surfaces, polygons and folders, and it gives two properties for free — folders and items are separate namespaces, and names in different folders never collide.

Rename

Hooked in fieldChangedByUi on RimSurface, RimPolygon, RimSurfaceCollection and RimPolygonContainer, the last covering polygon folders and RimPolygonFile. Tree-view and property-editor renames both funnel through there, and it is the only place with the old value available for the cancel path.

On a collision RiuNameConflictTools::resolveRenameConflict offers the auto-generated name:

"Top" already exists in this folder. Use "Top_1" instead?    [ Use "Top_1" ] [ Cancel ]

Cancel restores the previous name. When no GUI is running, the unique name is applied without prompting, so console mode, regression tests and gRPC-driven field writes never block on a modal dialog.

Auto-rename

Applied where no user is present to decide: manual creation, Add Folder, surface and polygon file import, polygons generated from one file, create-copy, duplicate, and drag and drop between folders. Drag and drop needed no change in RiuDragDrop, as it routes through addSurfacesAtIndex.

Python API

RiaDefines::NameConflictPolicy with FAIL (default), AUTO_RENAME and OVERWRITE, exposed as on_name_conflict on AddFolder, CreatePolygon, ImportSurface and NewRegularSurface:

root.create_polygon(name="Fence", coordinates=coords)                       # raises on collision
root.create_polygon(name="Fence", coordinates=coords,
                    on_name_conflict=rips.NameConflictPolicy.AUTO_RENAME)   # -> Fence_1

NewSurface is deliberately left out. Grid case surfaces derive their tree label from the case and K index and carry no name of their own, so a flag there would never fire.

Notes

Objects with an empty name are exempt from numbering, for the same reason — otherwise six grid case surfaces would render as _1 - K:3.

Existing projects are not migrated. Project load deserializes straight into the child arrays, so duplicates already stored in a project file survive and are resolved as the user touches them. All in-project references to surfaces and polygons are PdmPtrField, so adding a migration pass later stays safe.

caf::PdmNestedCollectionBase::subCollectionsField() is added so the generic AddFolder can inspect sibling folders without knowing the concrete collection type.

Verification

Full build clean. 960/960 C++ unit tests pass, including 7 new ones for the suffix rule, case sensitivity, per-folder scoping, separate namespaces and the conflict policy. 10/10 rips tests pass, including 3 new ones covering the Python flag across all three modes.

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.

Renaming from the tree or the property editor asks the user to accept an auto-generated unique name, and reverts on cancel. Without a GUI the unique name is applied directly, so console runs and regression tests never block. Creation, import, copy, duplicate and drag and drop between folders auto-rename.

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.

Objects with an empty name are exempt, as they derive their label from other properties.

Existing projects are not migrated. Duplicates already stored in a project file are resolved as the user touches them.
The polygon fixture creates a polygon named "Test Polygon" for every test in the class, but the project was never reset, so all tests after the first collided on the name. This passed while duplicate names were allowed, and now fails on the default FAIL conflict policy.

Depend on the initialize_test fixture, as the other test modules do, so each test starts from a clean polygon collection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce name uniqueness for Surfaces, Polygons, and Folders

1 participant