This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/blenkernel/BKE_node_ui_storage.hh
Hans Goudey 71eaf872c2 Geometry Nodes: Add domain and data type to attribute search
This patch adds domain and data type information to each row of the
attribute search menu. The data type is displayed on the right, just
like how the list is exposed for the existing point cloud and hair
attribute panels. The domain is exposed on the left like the menu
hierarchy from menu search.

For the implementation, the attribute hint information is stored as a
set instead of a multi-value map so that every item (which we need to
point to descretely in the search process) contains the necessary data
type and domain information by itself. We also need to allocate a new
struct for every button, which requires a change to allow passing a
newly allocated argument to search buttons.

Note that the search does't yet handle the case where there are two
attributes with the same name but different domains or data types in
the input geometry set. That will be handled as a separate improvement.

Differential Revision: https://developer.blender.org/D10623
2021-04-14 11:11:51 -05:00

134 lines
4.3 KiB
C++

/*
* 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.
*/
#pragma once
#include <mutex>
#include "BLI_hash.hh"
#include "BLI_map.hh"
#include "BLI_session_uuid.h"
#include "BLI_set.hh"
#include "DNA_ID.h"
#include "DNA_customdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_session_uuid_types.h"
#include "BKE_attribute.h"
struct ModifierData;
struct Object;
struct bNode;
struct bNodeTree;
struct bContext;
/**
* Contains the context necessary to determine when to display settings for a certain node tree
* that may be used for multiple modifiers and objects. The object name and modifier session UUID
* are used instead of pointers because they are re-allocated between evaluations.
*
* \note This does not yet handle the context of nested node trees.
*/
class NodeTreeEvaluationContext {
private:
std::string object_name_;
SessionUUID modifier_session_uuid_;
public:
NodeTreeEvaluationContext(const Object &object, const ModifierData &modifier)
{
object_name_ = reinterpret_cast<const ID &>(object).name;
modifier_session_uuid_ = modifier.session_uuid;
}
uint64_t hash() const
{
return blender::get_default_hash_2(object_name_, modifier_session_uuid_);
}
friend bool operator==(const NodeTreeEvaluationContext &a, const NodeTreeEvaluationContext &b)
{
return a.object_name_ == b.object_name_ &&
BLI_session_uuid_is_equal(&a.modifier_session_uuid_, &b.modifier_session_uuid_);
}
};
enum class NodeWarningType {
Error,
Warning,
Info,
};
struct NodeWarning {
NodeWarningType type;
std::string message;
};
struct AvailableAttributeInfo {
std::string name;
AttributeDomain domain;
CustomDataType data_type;
uint64_t hash() const
{
return blender::get_default_hash(name);
}
friend bool operator==(const AvailableAttributeInfo &a, const AvailableAttributeInfo &b)
{
return a.name == b.name;
}
};
struct NodeUIStorage {
blender::Vector<NodeWarning> warnings;
blender::Set<AvailableAttributeInfo> attribute_hints;
};
struct NodeTreeUIStorage {
blender::Map<NodeTreeEvaluationContext, blender::Map<std::string, NodeUIStorage>> context_map;
std::mutex context_map_mutex;
/**
* Attribute search uses this to store the fake info for the string typed into a node, in order
* to pass the info to the execute callback that sets node socket values. This is mutable since
* we can count on only one attribute search being open at a time, and there is no real data
* stored here.
*/
mutable AvailableAttributeInfo dummy_info_for_search;
};
const NodeUIStorage *BKE_node_tree_ui_storage_get_from_context(const bContext *C,
const bNodeTree &ntree,
const bNode &node);
void BKE_nodetree_ui_storage_free_for_context(bNodeTree &ntree,
const NodeTreeEvaluationContext &context);
void BKE_nodetree_error_message_add(bNodeTree &ntree,
const NodeTreeEvaluationContext &context,
const bNode &node,
const NodeWarningType type,
std::string message);
void BKE_nodetree_attribute_hint_add(bNodeTree &ntree,
const NodeTreeEvaluationContext &context,
const bNode &node,
const blender::StringRef attribute_name,
const AttributeDomain domain,
const CustomDataType data_type);