Skip to content

Introduce caf::PdmNestedCollection for tree-shaped folder containers #13987

@magnesj

Description

@magnesj

Background

Several ResInsight project-data-model classes implement the same tree-shaped folder pattern: a container that holds a list of leaf items and a list of subcontainers of the same kind. Today this plumbing (m_subCollections, m_items, top-folder flag, add/remove/find sub-collection, XML wiring, factory of sub-collections, generic "new sub folder" command feature) is duplicated and slightly different in each class — RimSurfaceCollection, RimPolygonCollection, RimPolygonInViewCollection, and similar candidates.

Proposal

Introduce a shared base in cafProjectDataModel:

  • caf::PdmNestedCollection<SelfT, ItemT> — CRTP template that owns the typed PdmChildArrayField<SelfT*> m_subCollections and inherits PdmChildArrayField<ItemT*> m_items from PdmObjectCollection<ItemT>. Provides folder-name, topmost-folder handling, add/remove/find sub-collection, allItems(), and a typed factory hook.
  • caf::PdmNestedCollectionInterface — non-templated interface so generic command features can operate on any concrete instance without knowing the template parameters.

A new generic command feature RicNewNestedCollectionFeature replaces per-domain "new folder" features and works against any PdmNestedCollectionInterface.

Migration scope

This issue tracks the framework introduction plus the first wave of migrations:

  • RimSurfaceCollectionPdmNestedCollection
  • RimPolygonCollectionPdmNestedCollection
  • RimPolygonInViewCollection (mirror of the in-view tree) via a new RimNestedMirrorCollectionInView helper
  • Drop RicNewSurfaceCollectionFeature in favour of the generic feature
  • Add RimPolygonContainer to support the polygon-in-view mirror

Follow-up candidates (not in this PR): other folder-style collections that match the pattern (annotations, ensembles, well-folders, etc.).

Design rationale

A non-templated alternative was evaluated — it has a smaller base but adds ~25 lines of boilerplate per derived class. With 8–10 expected derived classes the templated design wins on total lines and gives compile-time type safety for subCollections() / addSubCollection(). Details and break-even analysis are in docs/pdm-nested-collection-design.md.

Metadata

Metadata

Assignees

Labels

EnhancementAn addition that can be observed by the userPendingReleaseIssues is fixed and will be available in next release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions