Refactor: Anim selectmode flags #118554

Open
Pratik Borhade wants to merge 2 commits from PratikPB2123/blender:anim-selectmode-refactor into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Use eEditKeyframes_Select enum variable type for selectmode.
This was discussed in !118429

Use `eEditKeyframes_Select` enum variable type for `selectmode`. This was discussed in !118429
Pratik Borhade added 1 commit 2024-02-21 11:12:17 +01:00
48bfb81c6a Refactor: Anim selectmode flags
Use `eEditKeyframes_Select` enum variable type for `selectmode`.
This was discussed in !118429
Pratik Borhade added 1 commit 2024-02-21 11:13:30 +01:00
Pratik Borhade requested review from Sybren A. Stüvel 2024-02-21 11:17:17 +01:00
Pratik Borhade requested review from Christoph Lendenfeld 2024-02-21 11:17:18 +01:00
Pratik Borhade added the
Module
Animation & Rigging
label 2024-02-21 11:17:31 +01:00
Sybren A. Stüvel requested changes 2024-02-22 11:52:17 +01:00
Sybren A. Stüvel left a comment
Member

Good job, I'm glad to see the /* eEditKeyframes_Select or -1 */ go!

Right now, having worked through this code the way you have, I'm guessing you're the person with the most knowledge on the planet about what these flags actually do. I'm hoping we can capture as much of that knowledge as possible and get it into comments & code clarity. That's the context for my remaining comments :)

Please edit the PR description so that it's a complete commit message, including whether this introduces (or at least is expected to introduce) functional changes or not. I can imagine that changing (selectmode == SELECT_INVERT) to (selectmode & SELECT_INVERT) can produce some subtle unintended changes. Having it written down what the intent is of this PR/commit will help debugging things when these do show up (but oh boy do I hope they don't).

Good job, I'm glad to see the `/* eEditKeyframes_Select or -1 */` go! Right now, having worked through this code the way you have, I'm guessing you're the person with the most knowledge on the planet about what these flags actually do. I'm hoping we can capture as much of that knowledge as possible and get it into comments & code clarity. That's the context for my remaining comments :) Please edit the PR description so that it's a complete commit message, including whether this introduces (or at least is expected to introduce) functional changes or not. I can imagine that changing `(selectmode == SELECT_INVERT)` to `(selectmode & SELECT_INVERT)` can produce some subtle unintended changes. Having it written down what the intent is of this PR/commit will help debugging things when these do show up (but oh boy do I hope they don't).
@ -49,6 +49,7 @@ enum eEditKeyframes_Validate {
/* select modes */
enum eEditKeyframes_Select {
SELECT_NONE = 0,

I think a better name would be SELECT_NOOP, to drive the fact home that this is actually a no-op (otherwise it could be a "deselect everything" flag too).

I think a better name would be `SELECT_NOOP`, to drive the fact home that this is actually a no-op (otherwise it could be a "deselect everything" flag too).
@ -58,7 +59,9 @@ enum eEditKeyframes_Select {
/* flip ok status of keyframes based on key status */
SELECT_INVERT = (1 << 3),
SELECT_EXTEND_RANGE = (1 << 4),
SELECT_CHILDREN_ONLY = (1 << 5),

This should get some documentation as to what it means.

A possible confusion: the name suggests it only selects children (so I'd expect non-children to remain untouched), yet it's used in the code with a comment /* select all in group (and deselect everything else) */, so that means it causes only children to be selected, and the rest to be deselected. It's a subtle but important difference.

Also when reading the enum name I don't know what "children" means, so that might be nice to describe as well. I understand it reflects the RNA property, so the name itself is fine. Something like this would help:

/* Special case for ActionGroups, which selects the channels underneath it, and deselects the rest. */

If that is indeed what it does ;-)

This should get some documentation as to what it means. A possible confusion: the name suggests it only selects children (so I'd expect non-children to remain untouched), yet it's used in the code with a comment `/* select all in group (and deselect everything else) */`, so that means it causes only children to be selected, and the rest to be deselected. It's a subtle but important difference. Also when reading the enum name I don't know what "children" means, so that might be nice to describe as well. I understand it reflects the RNA property, so the name itself is fine. Something like this would help: `/* Special case for ActionGroups, which selects the channels underneath it, and deselects the rest. */` If that is indeed what it does ;-)
Sybren A. Stüvel reviewed 2024-02-22 12:15:05 +01:00
Sybren A. Stüvel left a comment
Member

Thinking about this a bit more, especially with @ChrisLend 's comment about invalid combinations, I think maybe we should drop the whole enum, and turn the "select mode" into a class by itself. It's purely runtime data anwyay, so there's nothing in the blend file we need to stay compatible with.

One of the red flags is that when you search for select mode is either replace (deselect all, then add) or add/extend you can find it repeated 8× across 5 files in 4 different directories. And then there is this code:

  const short selectmode = RNA_boolean_get(op->ptr, "extend") ? SELECT_INVERT : SELECT_REPLACE;

So the RNA concept "extend" maps to the C++ concept "invert".

Some things that come to mind when making such a AnimSelectionMode class:

  • A constructor that takes the parameters from RNA, and returns the appropriate instance.
  • Remove the need to reassign selectmode while doing the selection operation.

The last point is because I found this code:

  /* if select mode is replace, deselect all keyframes (and tracks) first */
  if (select_mode == SELECT_REPLACE) {
    select_mode = SELECT_ADD;

    /* - deselect all other keyframes, so that just the newly selected remain
     * - tracks aren't deselected, since we don't re-select any as a consequence
     */
    deselect_nla_strips(ac, 0, SELECT_SUBTRACT);
  }

This is IMO quite sane: if the selection needs to be replaced, deselect what needs deselecting, and then just continue as if an additive selection mode was chosen. This could also be modeled in the AnimSelectMode class, by having functions should_deselect() and should_select(). A replace could just return true for both, and other modes could result in other return values. That way the code would never have to "fake" that the function received a different selection mode than it actually did.

@PratikPB2123 with all this feedback, and this PR getting a bigger (and also slightly less well-defined) scope, do you still feel comfortable working on this? Otherwise @ChrisLend or me could take over. I do feel that this change would be a welcome one, as it will make implementing selection operations in the new layered animation editor more straight-forward as well.

Thinking about this a bit more, especially with @ChrisLend 's [comment about invalid combinations](https://projects.blender.org/blender/blender/pulls/118429#issuecomment-1127624), I think maybe we should drop the whole enum, and turn the "select mode" into a class by itself. It's purely runtime data anwyay, so there's nothing in the blend file we need to stay compatible with. One of the red flags is that when you search for `select mode is either replace (deselect all, then add) or add/extend` you can find it repeated 8× across 5 files in 4 different directories. And then there is this code: ```cpp const short selectmode = RNA_boolean_get(op->ptr, "extend") ? SELECT_INVERT : SELECT_REPLACE; ``` So the RNA concept "extend" maps to the C++ concept "invert". Some things that come to mind when making such a `AnimSelectionMode` class: - A constructor that takes the parameters from RNA, and returns the appropriate instance. - Remove the need to reassign `selectmode` while doing the selection operation. The last point is because I found this code: ```cpp /* if select mode is replace, deselect all keyframes (and tracks) first */ if (select_mode == SELECT_REPLACE) { select_mode = SELECT_ADD; /* - deselect all other keyframes, so that just the newly selected remain * - tracks aren't deselected, since we don't re-select any as a consequence */ deselect_nla_strips(ac, 0, SELECT_SUBTRACT); } ``` This is IMO quite sane: if the selection needs to be replaced, deselect what needs deselecting, and then just continue as if an additive selection mode was chosen. This could also be modeled in the `AnimSelectMode` class, by having functions `should_deselect()` and `should_select()`. A replace could just return `true` for both, and other modes could result in other return values. That way the code would never have to "fake" that the function received a different selection mode than it actually did. @PratikPB2123 with all this feedback, and this PR getting a bigger (and also slightly less well-defined) scope, do you still feel comfortable working on this? Otherwise @ChrisLend or me could take over. I do feel that this change would be a welcome one, as it will make implementing selection operations in the new layered animation editor more straight-forward as well.
Author
Member

@dr.sybren , thanks for the review 🙂
I'll continue this refactor.

A constructor that takes the parameters from RNA, and returns the appropriate instance.

I didn't quite understand this.

@dr.sybren , thanks for the review 🙂 I'll continue this refactor. > A constructor that takes the parameters from RNA, and returns the appropriate instance. I didn't quite understand this.

@dr.sybren , thanks for the review 🙂
I'll continue this refactor.

🙏

A constructor that takes the parameters from RNA, and returns the appropriate instance.

I didn't quite understand this.

I mean something that replaces this:

  /* select mode is either replace (deselect all, then add) or add/extend */
  if (RNA_boolean_get(op->ptr, "extend")) {
    selectmode = SELECT_INVERT;
  }
  else if (RNA_boolean_get(op->ptr, "extend_range")) {
    selectmode = SELECT_EXTEND_RANGE;
  }
  else if (RNA_boolean_get(op->ptr, "children_only")) {
    /* this is a bit of a special case for ActionGroups only...
     * should it be removed or extended to all instead? */
    selectmode = -1;
  }
  else {
    selectmode = SELECT_REPLACE;
  }

with something like:

SelectMode selectmode = SelectMode::from_rna(op->ptr, "extend", "extend_range", "children_only");

where the from_rna function then can do the whole mapping from the boolean properties in RNA to some SelectMode instance.

> @dr.sybren , thanks for the review 🙂 > I'll continue this refactor. 🙏 > > A constructor that takes the parameters from RNA, and returns the appropriate instance. > > I didn't quite understand this. I mean something that replaces this: ```cpp /* select mode is either replace (deselect all, then add) or add/extend */ if (RNA_boolean_get(op->ptr, "extend")) { selectmode = SELECT_INVERT; } else if (RNA_boolean_get(op->ptr, "extend_range")) { selectmode = SELECT_EXTEND_RANGE; } else if (RNA_boolean_get(op->ptr, "children_only")) { /* this is a bit of a special case for ActionGroups only... * should it be removed or extended to all instead? */ selectmode = -1; } else { selectmode = SELECT_REPLACE; } ``` with something like: ```cpp SelectMode selectmode = SelectMode::from_rna(op->ptr, "extend", "extend_range", "children_only"); ``` where the `from_rna` function then can do the whole mapping from the boolean properties in RNA to some `SelectMode` instance.
Merge conflict checking is in progress. Try again in few moments.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u anim-selectmode-refactor:PratikPB2123-anim-selectmode-refactor
git checkout PratikPB2123-anim-selectmode-refactor
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#118554
No description provided.