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:
RimSurfaceCollection → PdmNestedCollection
RimPolygonCollection → PdmNestedCollection
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.
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 typedPdmChildArrayField<SelfT*> m_subCollectionsand inheritsPdmChildArrayField<ItemT*> m_itemsfromPdmObjectCollection<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
RicNewNestedCollectionFeaturereplaces per-domain "new folder" features and works against anyPdmNestedCollectionInterface.Migration scope
This issue tracks the framework introduction plus the first wave of migrations:
RimSurfaceCollection→PdmNestedCollectionRimPolygonCollection→PdmNestedCollectionRimPolygonInViewCollection(mirror of the in-view tree) via a newRimNestedMirrorCollectionInViewhelperRicNewSurfaceCollectionFeaturein favour of the generic featureRimPolygonContainerto support the polygon-in-view mirrorFollow-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 indocs/pdm-nested-collection-design.md.