[Bf-blender-cvs] [3dab6f8b7b8] master: Spreadsheet: new spreadsheet editor

Jacques Lucke noreply at git.blender.org
Wed Mar 10 11:36:37 CET 2021


Commit: 3dab6f8b7b8988b727719e7487e793262669f2ee
Author: Jacques Lucke
Date:   Wed Mar 10 11:34:36 2021 +0100
Branches: master
https://developer.blender.org/rB3dab6f8b7b8988b727719e7487e793262669f2ee

Spreadsheet: new spreadsheet editor

This implements the MVP for the new spreadsheet editor (T85879). The functionality
is still very limited, but it proved to be useful already. A more complete picture
of where we want to go with the new editor can be found in T86279.

Supported features:
* Show point attributes of evaluated meshes (no original data, no other domains,
  no other geometry types, yet). Since only meshes are supported right now, the
  output of the Point Distribute is not shown, because it is a point cloud.
* Only show data for selected vertices when the mesh is in edit mode.
  Different parts of Blender keep track of selection state and original-indices with
  varying degrees of success. Therefore, when the selected-only filter is used, the
  result might be a bit confusing when using some modifiers or nodes. This will
  be improved in the future.
* All data is readonly. Since only evaluated data is displayed currently, it has to
  be readonly. However, this is not an inherent limitation of the spreadsheet editor.
  In the future editable data will be displayed as well.

Some boilerplate code for the new editor has been committed before in
rB9cb5f0a2282a7a84f7f8636b43a32bdc04b51cd5.

It would be good to let the spreadsheet editor mature for a couple of weeks as part
of the geometry nodes project. Then other modules are invited to show their own data
in the new editor!

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

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

M	release/scripts/startup/bl_operators/__init__.py
A	release/scripts/startup/bl_operators/spreadsheet.py
M	release/scripts/startup/bl_ui/space_spreadsheet.py
M	source/blender/blenkernel/intern/screen.c
M	source/blender/editors/space_spreadsheet/CMakeLists.txt
M	source/blender/editors/space_spreadsheet/space_spreadsheet.cc
A	source/blender/editors/space_spreadsheet/spreadsheet_draw.cc
A	source/blender/editors/space_spreadsheet/spreadsheet_draw.hh
A	source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
A	source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.hh
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_screen.c
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_operators/__init__.py b/release/scripts/startup/bl_operators/__init__.py
index 7e6f14a0a51..078b32f5e2a 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -45,6 +45,7 @@ _modules = [
     "rigidbody",
     "screen_play_rendered_anim",
     "sequencer",
+    "spreadsheet",
     "userpref",
     "uvcalc_follow_active",
     "uvcalc_lightmap",
diff --git a/release/scripts/startup/bl_ui/space_spreadsheet.py b/release/scripts/startup/bl_operators/spreadsheet.py
similarity index 63%
copy from release/scripts/startup/bl_ui/space_spreadsheet.py
copy to release/scripts/startup/bl_operators/spreadsheet.py
index e433ead070c..a2f9b2ad412 100644
--- a/release/scripts/startup/bl_ui/space_spreadsheet.py
+++ b/release/scripts/startup/bl_operators/spreadsheet.py
@@ -16,21 +16,34 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
+from __future__ import annotations
+
 import bpy
 
+class SPREADSHEET_OT_toggle_pin(bpy.types.Operator):
+    '''Turn on or off pinning'''
+    bl_idname = "spreadsheet.toggle_pin"
+    bl_label = "Toggle Pin"
+    bl_options = {'REGISTER', 'UNDO'}
 
-class SPREADSHEET_HT_header(bpy.types.Header):
-    bl_space_type = 'SPREADSHEET'
+    @classmethod
+    def poll(cls, context):
+        space = context.space_data
+        return space and space.type == 'SPREADSHEET'
 
-    def draw(self, context):
-        layout = self.layout
+    def execute(self, context):
         space = context.space_data
 
-        layout.template_header()
+        if space.pinned_id:
+            space.pinned_id = None
+        else:
+            space.pinned_id = context.active_object
+
+        return {'FINISHED'}
 
 
 classes = (
-    SPREADSHEET_HT_header,
+    SPREADSHEET_OT_toggle_pin,
 )
 
 if __name__ == "__main__":  # Only for live edit.
diff --git a/release/scripts/startup/bl_ui/space_spreadsheet.py b/release/scripts/startup/bl_ui/space_spreadsheet.py
index e433ead070c..1d124019ce8 100644
--- a/release/scripts/startup/bl_ui/space_spreadsheet.py
+++ b/release/scripts/startup/bl_ui/space_spreadsheet.py
@@ -28,6 +28,19 @@ class SPREADSHEET_HT_header(bpy.types.Header):
 
         layout.template_header()
 
+        pinned_id = space.pinned_id
+        used_id = pinned_id if pinned_id else context.active_object
+
+        if used_id:
+            layout.label(text=used_id.name, icon="OBJECT_DATA")
+
+        layout.operator("spreadsheet.toggle_pin", text="", icon='PINNED' if pinned_id else 'UNPINNED', emboss=False)
+
+        layout.separator_spacer()
+
+        if isinstance(used_id, bpy.types.Object) and used_id.mode == 'EDIT':
+            layout.prop(space, "show_only_selected", text="Selected Only")
+
 
 classes = (
     SPREADSHEET_HT_header,
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index f0220373678..fd7f1acb456 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -224,6 +224,12 @@ void BKE_screen_foreach_id_screen_area(LibraryForeachIDData *data, ScrArea *area
         BKE_LIB_FOREACHID_PROCESS(data, sclip->mask_info.mask, IDWALK_CB_USER_ONE);
         break;
       }
+      case SPACE_SPREADSHEET: {
+        SpaceSpreadsheet *sspreadsheet = (SpaceSpreadsheet *)sl;
+
+        BKE_LIB_FOREACHID_PROCESS_ID(data, sspreadsheet->pinned_id, IDWALK_CB_NOP);
+        break;
+      }
       default:
         break;
     }
@@ -1908,6 +1914,11 @@ void BKE_screen_area_blend_read_lib(BlendLibReader *reader, ID *parent_id, ScrAr
         BLO_read_id_address(reader, parent_id->lib, &sclip->mask_info.mask);
         break;
       }
+      case SPACE_SPREADSHEET: {
+        SpaceSpreadsheet *sspreadsheet = (SpaceSpreadsheet *)sl;
+        BLO_read_id_address(reader, parent_id->lib, &sspreadsheet->pinned_id);
+        break;
+      }
       default:
         break;
     }
diff --git a/source/blender/editors/space_spreadsheet/CMakeLists.txt b/source/blender/editors/space_spreadsheet/CMakeLists.txt
index 8be5f506dd7..e270ce9676c 100644
--- a/source/blender/editors/space_spreadsheet/CMakeLists.txt
+++ b/source/blender/editors/space_spreadsheet/CMakeLists.txt
@@ -19,6 +19,11 @@ set(INC
   ../include
   ../../blenkernel
   ../../blenlib
+  ../../blenfont
+  ../../bmesh
+  ../../depsgraph
+  ../../functions
+  ../../gpu
   ../../makesdna
   ../../makesrna
   ../../windowmanager
@@ -28,8 +33,12 @@ set(INC
 
 set(SRC
   space_spreadsheet.cc
+  spreadsheet_draw.cc
+  spreadsheet_from_geometry.cc
   spreadsheet_ops.cc
 
+  spreadsheet_draw.hh
+  spreadsheet_from_geometry.hh
   spreadsheet_intern.hh
 )
 
diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
index 27276b4bedc..53424c60d59 100644
--- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
+++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
@@ -32,6 +32,8 @@
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "RNA_access.h"
 
 #include "WM_api.h"
@@ -39,6 +41,11 @@
 
 #include "spreadsheet_intern.hh"
 
+#include "spreadsheet_from_geometry.hh"
+#include "spreadsheet_intern.hh"
+
+using namespace blender::ed::spreadsheet;
+
 static SpaceLink *spreadsheet_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
 {
   SpaceSpreadsheet *spreadsheet_space = (SpaceSpreadsheet *)MEM_callocN(sizeof(SpaceSpreadsheet),
@@ -94,9 +101,49 @@ static void spreadsheet_main_region_init(wmWindowManager *wm, ARegion *region)
   WM_event_add_keymap_handler(&region->handlers, keymap);
 }
 
-static void spreadsheet_main_region_draw(const bContext *UNUSED(C), ARegion *UNUSED(region))
+static ID *get_used_id(const bContext *C)
+{
+  SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C);
+  if (sspreadsheet->pinned_id != nullptr) {
+    return sspreadsheet->pinned_id;
+  }
+  Object *active_object = CTX_data_active_object(C);
+  return (ID *)active_object;
+}
+
+class FallbackSpreadsheetDrawer : public SpreadsheetDrawer {
+};
+
+static std::unique_ptr<SpreadsheetDrawer> generate_spreadsheet_drawer(const bContext *C)
+{
+  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
+  ID *used_id = get_used_id(C);
+  if (used_id == nullptr) {
+    return {};
+  }
+  const ID_Type id_type = GS(used_id->name);
+  if (id_type != ID_OB) {
+    return {};
+  }
+  Object *object_orig = (Object *)used_id;
+  if (object_orig->type != OB_MESH) {
+    return {};
+  }
+  Object *object_eval = DEG_get_evaluated_object(depsgraph, object_orig);
+  if (object_eval == nullptr) {
+    return {};
+  }
+
+  return spreadsheet_drawer_from_geometry_attributes(C, object_eval);
+}
+
+static void spreadsheet_main_region_draw(const bContext *C, ARegion *region)
 {
-  UI_ThemeClearColor(TH_BACK);
+  std::unique_ptr<SpreadsheetDrawer> drawer = generate_spreadsheet_drawer(C);
+  if (!drawer) {
+    drawer = std::make_unique<FallbackSpreadsheetDrawer>();
+  }
+  draw_spreadsheet_in_region(C, region, *drawer);
 }
 
 static void spreadsheet_main_region_listener(const wmRegionListenerParams *params)
@@ -108,6 +155,7 @@ static void spreadsheet_main_region_listener(const wmRegionListenerParams *param
     case NC_SCENE: {
       switch (wmn->data) {
         case ND_MODE:
+        case ND_FRAME:
         case ND_OB_ACTIVE: {
           ED_region_tag_redraw(region);
           break;
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_draw.cc b/source/blender/editors/space_spreadsheet/spreadsheet_draw.cc
new file mode 100644
index 00000000000..d6379c740e8
--- /dev/null
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_draw.cc
@@ -0,0 +1,304 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+#include "UI_view2d.h"
+
+#include "GPU_immediate.h"
+
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+
+#include "BLI_rect.h"
+
+#include "spreadsheet_draw.hh"
+
+namespace blender::ed::spreadsheet {
+
+SpreadsheetDrawer::SpreadsheetDrawer()
+{
+  left_column_width = UI_UNIT_X * 2;
+  top_row_height = UI_UNIT_Y * 1.1f;
+  row_height = UI_UNIT_Y;
+}
+
+SpreadsheetDrawer::~SpreadsheetDrawer() = default;
+
+void SpreadsheetDrawer::draw_top_row_cell(int UNUSED(column_index),
+                                          const CellDrawParams &UNUSED(params)) const
+{
+}
+
+void SpreadsheetDrawer::draw_left_column_cell(int UNUSED(row_index),
+                                              const CellDrawParams &UNUSED(params)) const
+{
+}
+
+void SpreadsheetDrawer::draw_content_cell(int UNUSED(row_index),
+                                          int UNUSED(column_index),
+                                          const CellDrawParams &UNUSED(params)) const
+{
+}
+
+int SpreadsheetDrawer::column_width(int UNUSED(column_index)) const
+{
+  return 5 * UI_UNIT_X;
+}
+
+static void draw_index_column_background(const uint pos,
+                                         const ARegion *region,
+                                         const SpreadsheetDrawer &drawer)
+{
+  immUniformThemeColorShade(TH_BACK, 11);
+  immRecti(pos, 0, region->winy - drawer.top_row_height, drawer.left_column_width, 0);
+}
+
+static void draw_alternating_row_overlay(const uint pos,
+                                         const int scroll_offset_y,
+                                         const ARegion *region,
+                                         const SpreadsheetDrawer &dra

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list