This adds support for showing various stats of volume grids in the spreadsheet: * Extent: Number of voxels in each direction of the bounding box of the grid. * Voxels: Total number of active voxels in the grid. This includes all voxels which are stored in tiles (e.g. one leaf tile contains 512 voxels). * Leaf Voxels: Number of active voxels stored in leaf nodes. This does not contain any voxels that are part of tiles. * Tiles: Number of active tiles in the grid. * Size: Estimated size of the volume grid in memory. All these stats are cached on the volume grid now. A new `tag_tree_changed` method has been added to invalidate the cache. Computing these stats is not cheap (but not more than a few ms even for large grids). That mainly means that we can't do it for socket inspection because that would cause too much overhead. However, doing it just for the grids that are currently visible in the spreadsheet seems fine and useful. This also adds some general improvements to the spreadsheet: * Support `int64_t` and `int3` columns. * Draw ints with thousand separators. * Support showing ints as number of bytes such as `23 MB`. Pull Request: https://projects.blender.org/blender/blender/pulls/147191
85 lines
2.1 KiB
C++
85 lines
2.1 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "BLI_generic_virtual_array.hh"
|
|
#include "BLI_string_ref.hh"
|
|
|
|
namespace blender::ed::spreadsheet {
|
|
|
|
eSpreadsheetColumnValueType cpp_type_to_column_type(const CPPType &type);
|
|
|
|
enum class ColumnValueDisplayHint {
|
|
None,
|
|
Bytes,
|
|
};
|
|
|
|
/**
|
|
* This represents a column in a spreadsheet. It has a name and provides a value for all the cells
|
|
* in the column.
|
|
*/
|
|
class ColumnValues final {
|
|
protected:
|
|
std::string name_;
|
|
|
|
GVArray data_;
|
|
ColumnValueDisplayHint display_hint_;
|
|
|
|
public:
|
|
ColumnValues(std::string name,
|
|
GVArray data,
|
|
const ColumnValueDisplayHint display_hint = ColumnValueDisplayHint::None)
|
|
: name_(std::move(name)), data_(std::move(data)), display_hint_(display_hint)
|
|
{
|
|
/* The array should not be empty. */
|
|
BLI_assert(data_);
|
|
}
|
|
|
|
virtual ~ColumnValues() = default;
|
|
|
|
eSpreadsheetColumnValueType type() const
|
|
{
|
|
return cpp_type_to_column_type(data_.type());
|
|
}
|
|
|
|
StringRefNull name() const
|
|
{
|
|
return name_;
|
|
}
|
|
|
|
int size() const
|
|
{
|
|
return data_.size();
|
|
}
|
|
|
|
const GVArray &data() const
|
|
{
|
|
return data_;
|
|
}
|
|
|
|
ColumnValueDisplayHint display_hint() const
|
|
{
|
|
return display_hint_;
|
|
}
|
|
|
|
/**
|
|
* Get a good column width for the column name and values.
|
|
*
|
|
* \param max_sample_size: If provided, only a subset of the column values are inspected to
|
|
* determine the width. This is useful when there are lots of rows to avoid unnecessarily long
|
|
* computations in drawing code. If provided, there is also an enforced minimum width to avoid
|
|
* very narrow columns when the sampled values all happen to be very short.
|
|
*/
|
|
float fit_column_width_px(const std::optional<int64_t> &max_sample_size = std::nullopt) const;
|
|
|
|
/** Same as above, but only takes the values into account (ignoring the name). */
|
|
float fit_column_values_width_px(
|
|
const std::optional<int64_t> &max_sample_size = std::nullopt) const;
|
|
};
|
|
|
|
} // namespace blender::ed::spreadsheet
|