[Bf-blender-cvs] [8568bed7523] temp-spreadsheet-editor: write attribute names and row indices
Jacques Lucke
noreply at git.blender.org
Tue Feb 23 17:08:33 CET 2021
Commit: 8568bed75237360de87cccf26f1ad0a1818580f1
Author: Jacques Lucke
Date: Tue Feb 23 13:18:25 2021 +0100
Branches: temp-spreadsheet-editor
https://developer.blender.org/rB8568bed75237360de87cccf26f1ad0a1818580f1
write attribute names and row indices
===================================================================
M source/blender/editors/space_spreadsheet/CMakeLists.txt
M source/blender/editors/space_spreadsheet/space_spreadsheet.cc
===================================================================
diff --git a/source/blender/editors/space_spreadsheet/CMakeLists.txt b/source/blender/editors/space_spreadsheet/CMakeLists.txt
index 8be5f506dd7..960429b7625 100644
--- a/source/blender/editors/space_spreadsheet/CMakeLists.txt
+++ b/source/blender/editors/space_spreadsheet/CMakeLists.txt
@@ -19,6 +19,8 @@ set(INC
../include
../../blenkernel
../../blenlib
+ ../../depsgraph
+ ../../functions
../../makesdna
../../makesrna
../../windowmanager
diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
index 6fa7f9bc4cf..b4b02333e86 100644
--- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
+++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
@@ -21,6 +21,7 @@
#include "BLI_rect.h"
#include "BLI_utildefines.h"
+#include "BKE_geometry_set.hh"
#include "BKE_screen.h"
#include "ED_screen.h"
@@ -38,6 +39,8 @@
#include "UI_resources.h"
#include "UI_view2d.h"
+#include "DEG_depsgraph_query.h"
+
#include "RNA_access.h"
#include "WM_types.h"
@@ -45,6 +48,16 @@
#include "spreadsheet_intern.hh"
using blender::IndexRange;
+using blender::MutableSpan;
+using blender::Set;
+using blender::Span;
+using blender::StringRef;
+using blender::StringRefNull;
+using blender::Vector;
+using blender::bke::ReadAttributePtr;
+using blender::fn::CPPType;
+using blender::fn::GMutableSpan;
+using blender::fn::GSpan;
static SpaceLink *spreadsheet_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
@@ -99,10 +112,83 @@ static void spreadsheet_main_region_init(wmWindowManager *UNUSED(wm), ARegion *r
UI_view2d_region_reinit(®ion->v2d, V2D_COMMONVIEW_LIST, region->winx, region->winy);
}
+static void spreadsheet_draw_readonly_table(uiBlock *block,
+ const GeometryComponent &component,
+ const AttributeDomain domain)
+{
+ Set<std::string> attribute_names = component.attribute_names();
+ struct AttributeWithName {
+ ReadAttributePtr attribute;
+ std::string name;
+ };
+ Vector<AttributeWithName> attribute_columns;
+ for (StringRef attribute_name : attribute_names) {
+ ReadAttributePtr attribute = component.attribute_try_get_for_read(attribute_name);
+ if (!attribute) {
+ continue;
+ }
+ if (attribute->domain() == domain) {
+ attribute_columns.append({std::move(attribute), attribute_name});
+ }
+ }
+ std::sort(
+ attribute_columns.begin(),
+ attribute_columns.end(),
+ [](const AttributeWithName &a, const AttributeWithName &b) { return a.name < b.name; });
+
+ int current_x = UI_UNIT_X * 2;
+ int current_y = -UI_UNIT_Y;
+ for (const AttributeWithName &data : attribute_columns) {
+ const int width = 5 * UI_UNIT_X;
+ const int height = UI_UNIT_Y;
+ uiDefIconTextBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ ICON_NONE,
+ data.name.c_str(),
+ current_x,
+ current_y,
+ width,
+ height,
+ nullptr,
+ 0.0f,
+ 0.0f,
+ 0.0f,
+ 0.0f,
+ nullptr);
+ current_x += width;
+ }
+
+ const int domain_size = component.attribute_domain_size(domain);
+ for (const int i : IndexRange(domain_size)) {
+ const int x = 0;
+ const int y = -UI_UNIT_Y * (i + 2);
+ const int width = UI_UNIT_X;
+ const int height = UI_UNIT_Y;
+ uiDefIconTextBut(block,
+ UI_BTYPE_LABEL,
+ 0,
+ ICON_NONE,
+ std::to_string(i).c_str(),
+ x,
+ y,
+ width,
+ height,
+ nullptr,
+ 0.0f,
+ 0.0f,
+ 0.0f,
+ 0.0f,
+ nullptr);
+ }
+}
+
static void spreadsheet_main_region_draw(const bContext *C, ARegion *region)
{
UI_ThemeClearColor(TH_BACK);
+ Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
+
View2D *v2d = ®ion->v2d;
v2d->flag |= V2D_PIXELOFS_X | V2D_PIXELOFS_Y;
UI_view2d_view_ortho(v2d);
@@ -112,29 +198,35 @@ static void spreadsheet_main_region_draw(const bContext *C, ARegion *region)
uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS_NONE);
- Object *active_object = CTX_data_active_object(C);
- if (active_object != nullptr && active_object->type == OB_MESH) {
-
- Mesh *mesh = (Mesh *)active_object->data;
- for (const int i : IndexRange(mesh->totvert)) {
- const MVert &vert = mesh->mvert[i];
- uiBut *but = uiDefButF(block,
- UI_BTYPE_NUM,
- 0,
- "",
- 0,
- -i * UI_UNIT_Y,
- 150,
- UI_UNIT_Y,
- (float *)vert.co,
- -100.0f,
- 100.0f,
- 0,
- 0,
- "My tip");
- UI_but_number_precision_set(but, 3);
- UI_but_disable(but, "cannot edit");
+ Object *object = CTX_data_active_object(C);
+ if (object != nullptr && object->type == OB_MESH) {
+ Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
+ const GeometrySet &geometry_set = *object_eval->runtime.geometry_set_eval;
+
+ if (geometry_set.has<MeshComponent>()) {
+ const MeshComponent &component = *geometry_set.get_component_for_read<MeshComponent>();
+ spreadsheet_draw_readonly_table(block, component, ATTR_DOMAIN_POINT);
}
+
+ // for (const int i : IndexRange(mesh->totvert)) {
+ // const MVert &vert = mesh->mvert[i];
+ // uiBut *but = uiDefButF(block,
+ // UI_BTYPE_NUM,
+ // 0,
+ // "",
+ // 0,
+ // -i * UI_UNIT_Y,
+ // 150,
+ // UI_UNIT_Y,
+ // (float *)vert.co,
+ // -100.0f,
+ // 100.0f,
+ // 0,
+ // 0,
+ // "My tip");
+ // UI_but_number_precision_set(but, 3);
+ // UI_but_disable(but, "cannot edit");
+ // }
}
UI_block_end(C, block);
More information about the Bf-blender-cvs
mailing list