[Bf-blender-cvs] [a17ea1a6691] blender-v2.93-release: Spreadsheet: combine vector/color spreadsheet columns

Jacques Lucke noreply at git.blender.org
Mon Apr 26 09:10:05 CEST 2021


Commit: a17ea1a6691920cc307f3e44dd285b2d8e8bdd35
Author: Jacques Lucke
Date:   Mon Apr 26 09:09:50 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rBa17ea1a6691920cc307f3e44dd285b2d8e8bdd35

Spreadsheet: combine vector/color spreadsheet columns

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

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

M	source/blender/editors/space_spreadsheet/space_spreadsheet.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_cell_value.hh
M	source/blender/editors/space_spreadsheet/spreadsheet_column.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_column.hh
M	source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh
M	source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
M	source/blender/editors/space_spreadsheet/spreadsheet_layout.cc
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
index 190f50ed443..fc9606b1249 100644
--- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
+++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
@@ -304,7 +304,12 @@ static void update_visible_columns(ListBase &columns, DataSource &data_source)
       continue;
     }
 
-    used_ids.add(*column->id);
+    if (!used_ids.add(*column->id)) {
+      /* Remove duplicate columns for now. */
+      BLI_remlink(&columns, column);
+      spreadsheet_column_free(column);
+      continue;
+    }
   }
 
   data_source.foreach_default_column_ids([&](const SpreadsheetColumnID &column_id) {
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_cell_value.hh b/source/blender/editors/space_spreadsheet/spreadsheet_cell_value.hh
index 0627cff7abc..d1e80f1d87e 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_cell_value.hh
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_cell_value.hh
@@ -18,6 +18,10 @@
 
 #include <optional>
 
+#include "BLI_color.hh"
+#include "BLI_float2.hh"
+#include "BLI_float3.hh"
+
 struct Object;
 struct Collection;
 
@@ -44,6 +48,9 @@ class CellValue {
   std::optional<int> value_int;
   std::optional<float> value_float;
   std::optional<bool> value_bool;
+  std::optional<float2> value_float2;
+  std::optional<float3> value_float3;
+  std::optional<Color4f> value_color;
   std::optional<ObjectCellValue> value_object;
   std::optional<CollectionCellValue> value_collection;
 };
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc
index 6c573ce7238..de40545fdae 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_column.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_column.cc
@@ -37,7 +37,6 @@ SpreadsheetColumnID *spreadsheet_column_id_copy(const SpreadsheetColumnID *src_c
 {
   SpreadsheetColumnID *new_column_id = spreadsheet_column_id_new();
   new_column_id->name = BLI_strdup(src_column_id->name);
-  new_column_id->index = src_column_id->index;
   return new_column_id;
 }
 
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column.hh b/source/blender/editors/space_spreadsheet/spreadsheet_column.hh
index 0f74ee0141a..bb245851d55 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_column.hh
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_column.hh
@@ -24,7 +24,7 @@ namespace blender {
 template<> struct DefaultHash<SpreadsheetColumnID> {
   uint64_t operator()(const SpreadsheetColumnID &column_id) const
   {
-    return get_default_hash_2(StringRef(column_id.name), column_id.index);
+    return get_default_hash(StringRef(column_id.name));
   }
 };
 }  // namespace blender
@@ -32,7 +32,7 @@ template<> struct DefaultHash<SpreadsheetColumnID> {
 inline bool operator==(const SpreadsheetColumnID &a, const SpreadsheetColumnID &b)
 {
   using blender::StringRef;
-  return StringRef(a.name) == StringRef(b.name) && a.index == b.index;
+  return StringRef(a.name) == StringRef(b.name);
 }
 
 namespace blender::ed::spreadsheet {
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh b/source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh
index 58a2776e0fc..373c988a41c 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_column_values.hh
@@ -74,11 +74,19 @@ template<typename GetValueF> class LambdaColumnValues : public ColumnValues {
 /* Utility function that simplifies creating a spreadsheet column from a lambda function. */
 template<typename GetValueF>
 std::unique_ptr<ColumnValues> column_values_from_function(std::string name,
-                                                          int size,
-                                                          GetValueF get_value)
+                                                          const int size,
+                                                          GetValueF get_value,
+                                                          const float default_width = 0.0f)
 {
-  return std::make_unique<LambdaColumnValues<GetValueF>>(
+  std::unique_ptr<ColumnValues> column_values = std::make_unique<LambdaColumnValues<GetValueF>>(
       std::move(name), size, std::move(get_value));
+  column_values->default_width = default_width;
+  return column_values;
 }
 
+static constexpr float default_float_column_width = 3;
+static constexpr float default_float2_column_width = 2 * default_float_column_width;
+static constexpr float default_float3_column_width = 3 * default_float_column_width;
+static constexpr float default_color_column_width = 4 * default_float_column_width;
+
 }  // namespace blender::ed::spreadsheet
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
index 520d29ce306..018431225e5 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc
@@ -47,28 +47,7 @@ void GeometryDataSource::foreach_default_column_ids(
     }
     SpreadsheetColumnID column_id;
     column_id.name = (char *)name.c_str();
-    if (meta_data.data_type == CD_PROP_FLOAT3) {
-      for (const int i : {0, 1, 2}) {
-        column_id.index = i;
-        fn(column_id);
-      }
-    }
-    else if (meta_data.data_type == CD_PROP_FLOAT2) {
-      for (const int i : {0, 1}) {
-        column_id.index = i;
-        fn(column_id);
-      }
-    }
-    else if (meta_data.data_type == CD_PROP_COLOR) {
-      for (const int i : {0, 1, 2, 3}) {
-        column_id.index = i;
-        fn(column_id);
-      }
-    }
-    else {
-      column_id.index = -1;
-      fn(column_id);
-    }
+    fn(column_id);
     return true;
   });
 }
@@ -89,9 +68,6 @@ std::unique_ptr<ColumnValues> GeometryDataSource::get_column_values(
   int domain_size = attribute->size();
   switch (attribute->custom_data_type()) {
     case CD_PROP_FLOAT:
-      if (column_id.index != -1) {
-        return {};
-      }
       return column_values_from_function(
           column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) {
             float value;
@@ -99,9 +75,6 @@ std::unique_ptr<ColumnValues> GeometryDataSource::get_column_values(
             r_cell_value.value_float = value;
           });
     case CD_PROP_INT32:
-      if (column_id.index != -1) {
-        return {};
-      }
       return column_values_from_function(
           column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) {
             int value;
@@ -109,9 +82,6 @@ std::unique_ptr<ColumnValues> GeometryDataSource::get_column_values(
             r_cell_value.value_int = value;
           });
     case CD_PROP_BOOL:
-      if (column_id.index != -1) {
-        return {};
-      }
       return column_values_from_function(
           column_id.name, domain_size, [attribute](int index, CellValue &r_cell_value) {
             bool value;
@@ -119,49 +89,37 @@ std::unique_ptr<ColumnValues> GeometryDataSource::get_column_values(
             r_cell_value.value_bool = value;
           });
     case CD_PROP_FLOAT2: {
-      if (column_id.index < 0 || column_id.index > 1) {
-        return {};
-      }
-      const std::array<const char *, 2> suffixes = {" X", " Y"};
-      const std::string name = StringRef(column_id.name) + suffixes[column_id.index];
       return column_values_from_function(
-          name,
+          column_id.name,
           domain_size,
-          [attribute, axis = column_id.index](int index, CellValue &r_cell_value) {
+          [attribute](int index, CellValue &r_cell_value) {
             float2 value;
             attribute->get(index, &value);
-            r_cell_value.value_float = value[axis];
-          });
+            r_cell_value.value_float2 = value;
+          },
+          default_float2_column_width);
     }
     case CD_PROP_FLOAT3: {
-      if (column_id.index < 0 || column_id.index > 2) {
-        return {};
-      }
-      const std::array<const char *, 3> suffixes = {" X", " Y", " Z"};
-      const std::string name = StringRef(column_id.name) + suffixes[column_id.index];
       return column_values_from_function(
-          name,
+          column_id.name,
           domain_size,
-          [attribute, axis = column_id.index](int index, CellValue &r_cell_value) {
+          [attribute](int index, CellValue &r_cell_value) {
             float3 value;
             attribute->get(index, &value);
-            r_cell_value.value_float = value[axis];
-          });
+            r_cell_value.value_float3 = value;
+          },
+          default_float3_column_width);
     }
     case CD_PROP_COLOR: {
-      if (column_id.index < 0 || column_id.index > 3) {
-        return {};
-      }
-      const std::array<const char *, 4> suffixes = {" R", " G", " B", " A"};
-      const std::string name = StringRef(column_id.name) + suffixes[column_id.index];
       return column_values_from_function(
-          name,
+          column_id.name,
           domain_size,
-          [attribute, axis = column_id.index](int index, CellValue &r_cell_value) {
+          [attribute](int index, CellValue &r_cell_value) {
             Color4f value;
             attribute->get(index, &value);
-            r_cell_value.value_float = value[axis];
-          });
+            r_cell_value.value_color = value;
+          },
+          default_color_column_width);
     }
     default:
       break;
@@ -300,15 +258,11 @@ void InstancesDataSource::foreach_default_column_ids(
   }
 
   SpreadsheetColumnID column_id;
-  column_id.index = -1;
   column_id.name = (char *)"Name";
   fn(column_id);
   for (const char *name : {"Position", "Rotation", "Scale"}) {
-    for (const int i : {0, 1, 2}) {
-      column_id.name = (char *)name;
-      column_id.index = i;
-      fn(column_id);
-    }
+    column_id.name = (char *)name;
+    fn(column_id);
   }


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list