Skip to content

Python: Add option to create discrete grid property#13899

Merged
magnesj merged 4 commits intodevfrom
13806-python-discrete-grid-property
Apr 20, 2026
Merged

Python: Add option to create discrete grid property#13899
magnesj merged 4 commits intodevfrom
13806-python-discrete-grid-property

Conversation

@magnesj
Copy link
Copy Markdown
Member

@magnesj magnesj commented Apr 18, 2026

Closes #13806

@magnesj magnesj requested a review from kriben April 20, 2026 05:56
Comment thread ApplicationLibCode/ProjectDataModel/RimColorLegendCollection.cpp Outdated
Comment thread ApplicationLibCode/ProjectDataModelCommands/RimcColorLegend.h Outdated
Comment thread ApplicationLibCode/ProjectDataModelCommands/RimcColorLegend.h Outdated
magnesj added 3 commits April 20, 2026 15:07
Add a data_type parameter to set_active_cell_property, set_active_cell_property_async
and set_grid_property so callers can upload INTEGER-typed discrete properties in
addition to the existing FLOAT properties. Previously a discrete property required
the result name to end with "NUM"; the explicit data type makes the intent
independent of the name.

The gRPC service now forwards the selected data type to
RigCaseCellResultsData::createCategoryResult, and the Python tests cover both
float and integer property uploads.
Expose RimColorLegendCollection and RimColorLegend to Python via
CAF_PDM_OBJECT_METHOD entries that let callers create a legend, append
category items with a hex-string color, bind a legend to a (case,
resultName) pair and delete that binding.

Scriptable fields on RimColorLegend and RimColorLegendItem make the
created objects inspectable from Python.

The (case, resultName) binding interface in RimColorLegendCollection,
RimRegularLegendConfig and RimEclipseCellColors now takes a const RimCase*
instead of a case id, matching the caller patterns and avoiding ambiguity
when multiple cases share an id domain.
The Python class generator previously emitted cvf::Color3f defaults using
the raw QTextStream operator ("r g b" floats), which is not valid Python
and does not match the hex-string form that scriptable color fields
expect on writeToField.

Convert Color3f defaults to their QColor::name() hex representation and
quote any non-QString value mapped to "str" (e.g. Color3f, caf::FilePath)
so the generated Python is syntactically valid.
@magnesj magnesj force-pushed the 13806-python-discrete-grid-property branch from 0f59a6a to 14bd043 Compare April 20, 2026 13:08
@magnesj magnesj requested a review from kriben April 20, 2026 13:08
Copy link
Copy Markdown
Collaborator

@kriben kriben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Introduce set_discrete_property_category_names on Case to bind integer
result values to text labels and optional colors. Internally it creates a
custom ColorLegend, appends one item per value (with an auto-assigned
palette color when the caller does not provide one) and registers the
legend as the default for the (case, resultName) pair.

Also add Project.color_legend_collection() as a dedicated accessor for
the project's ColorLegendCollection, pytest coverage for legend creation
and the default-legend-for-result binding, and two PythonExamples
demonstrating the end-to-end discrete property + category label flow.

#13806 Python: Silence mypy warnings for category_mapping module
@magnesj magnesj force-pushed the 13806-python-discrete-grid-property branch from 14bd043 to 6586002 Compare April 20, 2026 14:03
@magnesj magnesj merged commit 03409ae into dev Apr 20, 2026
19 checks passed
@magnesj magnesj deleted the 13806-python-discrete-grid-property branch April 20, 2026 16:55
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.

python Add option to create discrete grid property

2 participants