#947 PDM: Add caf::PdmNestedCollection template and migrate surface + polygon collections#949
Open
magnesj wants to merge 6 commits into
Open
#947 PDM: Add caf::PdmNestedCollection template and migrate surface + polygon collections#949magnesj wants to merge 6 commits into
magnesj wants to merge 6 commits into
Conversation
07c3849 to
f834267
Compare
9fe3c1d to
6e1c9d8
Compare
Introduce a shared base for tree-shaped folder containers that hold a list of leaf items together with a list of subcontainers of the same kind. Replaces the per-class plumbing (subcollections field, top-folder flag, add/remove/find sub-collection, factory) that is duplicated across RimSurfaceCollection, RimPolygonCollection and similar candidates. - caf::PdmNestedCollectionBase: non-templated PdmObject base exposing collection-name, add-new-subcollection, leaf-check and topmost-folder marking for generic command features and script methods. - caf::PdmNestedCollection<SelfT, ItemT>: CRTP template that owns the typed m_subCollections field and inherits the m_items array from PdmObjectCollection<ItemT>. Provides allItems(), find-sub-collection, and a typed factory hook. - RimNestedMirrorCollectionInView: view-side analogue for in-view collections that mirror a nested source collection, with orphan-sweep + find-or-create + reorder sync. Design rationale (templated vs non-templated, break-even on derived class count) lives in docs/pdm-nested-collection-design.md. No callers migrated in this commit.
…n test IconProvider::operator= copied a new resource-string but never cleared the existing m_pixmap. icon() prefers the pixmap when present, so a pixmap-based default stamped earlier (e.g. by a base class) would silently shadow a later resource-string-only assignment in a derived class. Reset m_pixmap in operator= so resource-string-only assignments fully replace pixmap-based ones, and cover the replacement semantics with a caf::IconProvider regression test: default-overwriting-pixmap, resource-string-overwriting-pixmap and pixmap-overwriting-pixmap. Needed for the upcoming nested-collection migration where a base class stamps a folder pixmap and the topmost instance applies a branded resource-string icon on top.
…tionBase Generalise the per-domain "Add Folder" command and the scripting-side add-folder method so they work against any container that exposes caf::PdmNestedCollectionBase. - RicNewNestedCollectionFeature: command feature that walks the selected PdmObject up to the nearest PdmNestedCollectionBase ancestor and calls addNewSubCollection(). Hidden via canAddSubCollection() for leaf containers. - RimcNestedCollectionBase: scripting wrapper exposing the same add-sub-collection action through the Python interface, so generated Python bindings get the operation for free on every derived class. Neither is wired to a concrete collection yet; the per-domain features remain in place until the migration commit replaces them.
…llection Port RimSurfaceCollection, RimPolygonCollection and the polygon-in-view side onto the new caf::PdmNestedCollection framework, replacing the per-class folder plumbing (m_subCollections field, topmost-folder flag, add/remove/find sub-collection, factory, "new folder" command) with the shared base. - RimSurfaceCollection and RimPolygonCollection now derive from caf::PdmNestedCollection. Each constructor uses the generic folder icon and exposes a static createTopmost() that marks the top instance and applies the branded domain icon; RimOilField calls the factory. - RimPolygonInViewCollection uses the new RimNestedMirrorCollectionInView helper, and a new RimPolygonContainer carries the source-side polygon link. - RicNewSurfaceCollectionFeature is removed; the generic RicNewNestedCollectionFeature drives the "Add Folder" action against both collections. - Update callers (RimAnnotationCollection, RimEnsembleSurface, polygon command features) and the scripting wrapper (RimcSurfaceCollection), plus the Python add-folder binding and polygon test.
6e1c9d8 to
1e45c68
Compare
Replace the dynamic_cast dispatch in RimPolygonCollection::loadData() with a virtual loadData() on RimPolygonContainer. The base recurses through subCollections; RimPolygonFile overrides to load file data. The folder RimPolygonCollection no longer needs its own loadData(). Move RimPolygonFile::canAddSubCollection() and RimPolygonInView::sourceItem() implementations from headers to .cpp. Simplify std::unexpected calls in RimcNestedCollectionBase by removing redundant explicit QString construction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a CRTP template
caf::PdmNestedCollection<SelfT, ItemT>that extendscaf::PdmObjectCollection<ItemT>with a user-visible collection name and a vector of subcollections of the derived type. This generalizes the "name + items + subcollections-of-self" pattern previously hand-rolled inRimSurfaceCollectionandRimPolygonCollection.A non-templated
caf::PdmNestedCollectionInterfacelets generic command features operate on any nested collection without knowing the template parameters. Includes acanAddSubCollection()query so leaf containers (e.g. file-backed folders) can refuse new sub-collections and let the generic UI hide the corresponding action.A parallel CRTP template
RimNestedMirrorCollectionInView<SelfT, SourceT, ItemViewT>collapses the hand-rolled in-view mirror sync logic inRimPolygonInViewCollectioninto a few small overrides. The same template can drop intoRimSurfaceInViewCollectionnext.XML keywords are kept in the derived constructors so existing project files load unchanged. Legacy
RimPolygonCollection::m_polygonFilesis migrated into the newm_subCollectionsininitAfterRead.Changes
cafframeworkFwk/AppFwk/cafProjectDataModel/cafPdmNestedCollection.{h,inl}— CRTP template providingcollectionName/setCollectionName,subCollections,addSubCollection,addNewSubCollection,findSubCollectionByName,allItems,setAsTopmostFolder, plususerDescriptionFieldanddefineUiOrderingoverrides.Fwk/AppFwk/cafProjectDataModel/cafPdmNestedCollectionInterface.h— non-templated interface for generic features (canAddSubCollection,addNewSubCollection,collectionName/setCollectionName).cafPdmObjectCollection.h/.inl— replaceis_base_ofstatic_assert with a C++20DerivedFromPdmObjectconcept, evaluated lazily inside the constructor so derived types may be forward-declared at the point the class template is instantiated as a base.Generic command
RicNewNestedCollectionFeature.{h,cpp}— generic "Add Folder" command that operates on anyPdmNestedCollectionInterfaceand is disabled on leaves viacanAddSubCollection().RicNewSurfaceCollectionFeature.{h,cpp}— superseded.Surfaces
RimSurfaceCollection.{h,cpp}— inherit fromPdmNestedCollection, drop ~80 lines of duplicated boilerplate; preservessetAsTopmostFoldersemantics.RimEnsembleSurface.cpp—getSubCollection→findSubCollectionByName.Polygons
RimPolygonContainer.{h,cpp}— XML-abstract base for bothRimPolygonCollection(folder) andRimPolygonFile(file-backed leaf folder). Both live polymorphically in the inheritedm_subCollections, so the in-view mirror picks them up uniformly.RimPolygonCollection.{h,cpp}— inherit fromRimPolygonContainer; legacym_polygonFilesfield migrated intom_subCollectionsininitAfterReadand disabled for write.userDefinedPolygons()removed in favor ofallPolygons().RimPolygonFile.{h,cpp}— inherit fromRimPolygonContainer; overridescanAddSubCollection()→ false. Reuses"Name"keyword form_collectionNamefor backward compatibility.In-view mirror
RimNestedMirrorCollectionInView.{h,inl}— CRTP template for view-side mirrors of nested source collections. Derived classes adapt to their source type via three small hooks.RimPolygonInViewCollection.{h,cpp}— migrated to the new template; ~150 lines of hand-rolled sync removed.Docs
docs/pdm-nested-collection-design.md— records the line-count comparison and the trade-off behind keeping the templated design over a non-templated alternative.Closes #947.