[Bf-blender-cvs] [792bf82f11a] master: Spreadsheet: Support operations for filtering colors

Angel Bueno noreply at git.blender.org
Thu Jun 23 19:16:30 CEST 2022


Commit: 792bf82f11a57c36734ef16b48137eda87a942cd
Author: Angel Bueno
Date:   Thu Jun 23 12:16:18 2022 -0500
Branches: master
https://developer.blender.org/rB792bf82f11a57c36734ef16b48137eda87a942cd

Spreadsheet: Support operations for filtering colors

Support choosing an operation when filtering colors,
like the other types.

Differential Revision: https://developer.blender.org/D15191

===================================================================

M	source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc

===================================================================

diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc
index e1ff4b59b14..efebe7be491 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter.cc
@@ -195,25 +195,75 @@ static void apply_row_filter(const SpreadsheetRowFilter &row_filter,
   }
   else if (column_data.type().is<ColorGeometry4f>()) {
     const ColorGeometry4f value = row_filter.value_color;
-    const float threshold_sq = pow2f(row_filter.threshold);
-    apply_filter_operation(
-        column_data.typed<ColorGeometry4f>(),
-        [&](const ColorGeometry4f cell) { return len_squared_v4v4(cell, value) <= threshold_sq; },
-        prev_mask,
-        new_indices);
+    switch (row_filter.operation) {
+      case SPREADSHEET_ROW_FILTER_EQUAL: {
+        const float threshold_sq = pow2f(row_filter.threshold);
+        apply_filter_operation(
+            column_data.typed<ColorGeometry4f>(),
+            [&](const ColorGeometry4f cell) { return len_squared_v4v4(cell, value) <= threshold_sq; },
+            prev_mask,
+            new_indices);
+        break;
+      }
+      case SPREADSHEET_ROW_FILTER_GREATER: {
+        apply_filter_operation(
+            column_data.typed<ColorGeometry4f>(),
+            [&](const ColorGeometry4f cell) {
+              return cell.r > value.r && cell.g > value.g && cell.b > value.b && cell.a > value.a;
+            },
+            prev_mask,
+            new_indices);
+        break;
+      }
+      case SPREADSHEET_ROW_FILTER_LESS: {
+        apply_filter_operation(
+            column_data.typed<ColorGeometry4f>(),
+            [&](const ColorGeometry4f cell) {
+              return cell.r < value.r && cell.g < value.g && cell.b < value.b && cell.a < value.a;
+            },
+            prev_mask,
+            new_indices);
+        break;
+      }
+    }
   }
   else if (column_data.type().is<ColorGeometry4b>()) {
     const ColorGeometry4b value = row_filter.value_byte_color;
-    const float4 value_floats = {(float)value.r, (float)value.g, (float)value.b, (float)value.a};
-    const float threshold_sq = pow2f(row_filter.threshold);
-    apply_filter_operation(
-        column_data.typed<ColorGeometry4b>(),
-        [&](const ColorGeometry4b cell) {
-          const float4 cell_floats = {(float)cell.r, (float)cell.g, (float)cell.b, (float)cell.a};
-          return len_squared_v4v4(value_floats, cell_floats) <= threshold_sq;
-        },
+    switch (row_filter.operation) {
+      case SPREADSHEET_ROW_FILTER_EQUAL: {
+        const float4 value_floats = {(float)value.r, (float)value.g, (float)value.b, (float)value.a};
+        const float threshold_sq = pow2f(row_filter.threshold);
+        apply_filter_operation(
+            column_data.typed<ColorGeometry4b>(),
+            [&](const ColorGeometry4b cell) {
+            const float4 cell_floats = {(float)cell.r, (float)cell.g, (float)cell.b, (float)cell.a};
+            return len_squared_v4v4(value_floats, cell_floats) <= threshold_sq;
+            },
         prev_mask,
         new_indices);
+        break;
+      }
+      case SPREADSHEET_ROW_FILTER_GREATER: {
+        apply_filter_operation(
+            column_data.typed<ColorGeometry4b>(),
+            [&](const ColorGeometry4b cell) {
+              return cell.r > value.r && cell.g > value.g && cell.b > value.b && cell.a > value.a;
+            },
+            prev_mask,
+            new_indices);
+        break;
+      }
+      case SPREADSHEET_ROW_FILTER_LESS: {
+        apply_filter_operation(
+            column_data.typed<ColorGeometry4b>(),
+            [&](const ColorGeometry4b cell) {
+              return cell.r < value.r && cell.g < value.g && cell.b < value.b && cell.a < value.a;
+            },
+            prev_mask,
+            new_indices);
+        break;
+      }
+    }
   }
   else if (column_data.type().is<InstanceReference>()) {
     const StringRef value = row_filter.value_string;
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc
index d42a371c666..8ab71fe3416 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_row_filter_ui.cc
@@ -41,9 +41,7 @@ static std::string operation_string(const eSpreadsheetColumnValueType data_type,
 {
   if (ELEM(data_type,
            SPREADSHEET_VALUE_TYPE_BOOL,
-           SPREADSHEET_VALUE_TYPE_INSTANCES,
-           SPREADSHEET_VALUE_TYPE_COLOR,
-           SPREADSHEET_VALUE_TYPE_BYTE_COLOR)) {
+           SPREADSHEET_VALUE_TYPE_INSTANCES)) {
     return "=";
   }
 
@@ -237,15 +235,21 @@ static void spreadsheet_filter_panel_draw(const bContext *C, Panel *panel)
       uiItemR(layout, filter_ptr, "value_string", 0, IFACE_("Value"), ICON_NONE);
       break;
     case SPREADSHEET_VALUE_TYPE_COLOR:
+      uiItemR(layout, filter_ptr, "operation", 0, nullptr, ICON_NONE);
       uiItemR(layout, filter_ptr, "value_color", 0, IFACE_("Value"), ICON_NONE);
-      uiItemR(layout, filter_ptr, "threshold", 0, nullptr, ICON_NONE);
+      if (operation == SPREADSHEET_ROW_FILTER_EQUAL) {
+        uiItemR(layout, filter_ptr, "threshold", 0, nullptr, ICON_NONE);
+      }
       break;
     case SPREADSHEET_VALUE_TYPE_STRING:
       uiItemR(layout, filter_ptr, "value_string", 0, IFACE_("Value"), ICON_NONE);
       break;
     case SPREADSHEET_VALUE_TYPE_BYTE_COLOR:
+      uiItemR(layout, filter_ptr, "operation", 0, nullptr, ICON_NONE);
       uiItemR(layout, filter_ptr, "value_byte_color", 0, IFACE_("Value"), ICON_NONE);
-      uiItemR(layout, filter_ptr, "threshold", 0, nullptr, ICON_NONE);
+      if (operation == SPREADSHEET_ROW_FILTER_EQUAL) {
+        uiItemR(layout, filter_ptr, "threshold", 0, nullptr, ICON_NONE);
+      }
       break;
     case SPREADSHEET_VALUE_TYPE_UNKNOWN:
       uiItemL(layout, IFACE_("Unknown column type"), ICON_ERROR);



More information about the Bf-blender-cvs mailing list