Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-10-26 12:25:32 +0300
committerJacques Lucke <jacques@blender.org>2021-10-26 12:25:32 +0300
commit5bfe09df2244cb9de0b6554a378eecef77b1e75d (patch)
treee4315292b81a99f08abe83c02e550ae79e41a8d6 /source/blender/editors/space_spreadsheet/spreadsheet_cache.cc
parentfee2cedb33ccf33f72d0370892dd25faa884968b (diff)
Geometry Nodes: support viewing field values in spreadsheet
The viewer node has been expanded to have a field input next to the geometry input. When both are connected (by ctrl+shift clicking on a node) the spreadsheet will show the evaluated field on the geometry. The operator to link to the viewer has become a bit smarter. It automatically detects if it should link to the geometry or field input. In the future some more smartness could be added, such as automatically relinking the "right" geometry when viewing a field. Internally, there are two major changes: * Refactor of what happens when ctrl+shift clicking on a node to link to a viewer. The behavior of the geometry nodes viewer is a bit more complex than that of the compositor viewers. The behavior in compositing nodes should not have changed. Any change should be reported as a bug (and then we can decide if it's worse than before or if it needs fixing). * Evaluation, display and caching of fields in the spreadsheet editor. Differential Revision: https://developer.blender.org/D12938
Diffstat (limited to 'source/blender/editors/space_spreadsheet/spreadsheet_cache.cc')
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_cache.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_cache.cc b/source/blender/editors/space_spreadsheet/spreadsheet_cache.cc
new file mode 100644
index 00000000000..2a399e018b6
--- /dev/null
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_cache.cc
@@ -0,0 +1,79 @@
+/*
+ * 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 "spreadsheet_cache.hh"
+
+namespace blender::ed::spreadsheet {
+
+void SpreadsheetCache::add(std::unique_ptr<Key> key, std::unique_ptr<Value> value)
+{
+ key->is_used = true;
+ cache_map_.add_overwrite(*key, std::move(value));
+ keys_.append(std::move(key));
+}
+
+SpreadsheetCache::Value *SpreadsheetCache::lookup(const Key &key)
+{
+ std::unique_ptr<Value> *value = cache_map_.lookup_ptr(key);
+ if (value == nullptr) {
+ return nullptr;
+ }
+ const Key &stored_cache_key = cache_map_.lookup_key(key);
+ stored_cache_key.is_used = true;
+ return value->get();
+}
+
+SpreadsheetCache::Value &SpreadsheetCache::lookup_or_add(
+ std::unique_ptr<Key> key, FunctionRef<std::unique_ptr<Value>()> create_value)
+{
+ Value *value = this->lookup(*key);
+ if (value != nullptr) {
+ return *value;
+ }
+ std::unique_ptr<Value> new_value = create_value();
+ value = new_value.get();
+ this->add(std::move(key), std::move(new_value));
+ return *value;
+}
+
+void SpreadsheetCache::set_all_unused()
+{
+ for (std::unique_ptr<Key> &key : keys_) {
+ key->is_used = false;
+ }
+}
+
+void SpreadsheetCache::remove_all_unused()
+{
+ /* First remove the keys from the map and free the values. */
+ for (auto it = cache_map_.keys().begin(); it != cache_map_.keys().end(); ++it) {
+ const Key &key = *it;
+ if (!key.is_used) {
+ cache_map_.remove(it);
+ }
+ }
+ /* Then free the keys. */
+ for (int i = 0; i < keys_.size();) {
+ if (keys_[i]->is_used) {
+ i++;
+ }
+ else {
+ keys_.remove_and_reorder(i);
+ }
+ }
+}
+
+} // namespace blender::ed::spreadsheet