Refactor: Nodes: pass tree type to supports_socket_type function for socket items
This allows us to support a different set of sockets per tree type in e.g. the repeat zone as in #141936.
This commit is contained in:
@@ -3912,14 +3912,15 @@ static void rna_Node_ItemArray_item_update(Main *bmain, Scene * /*scene*/, Point
|
||||
|
||||
template<typename Accessor>
|
||||
static const EnumPropertyItem *rna_Node_ItemArray_socket_type_itemf(bContext * /*C*/,
|
||||
PointerRNA * /*ptr*/,
|
||||
PointerRNA *ptr,
|
||||
PropertyRNA * /*prop*/,
|
||||
bool *r_free)
|
||||
{
|
||||
*r_free = true;
|
||||
bNodeTree &ntree = *reinterpret_cast<bNodeTree *>(ptr->owner_id);
|
||||
return itemf_function_check(
|
||||
rna_enum_node_socket_data_type_items, [](const EnumPropertyItem *item) {
|
||||
return Accessor::supports_socket_type(eNodeSocketDatatype(item->value));
|
||||
rna_enum_node_socket_data_type_items, [&](const EnumPropertyItem *item) {
|
||||
return Accessor::supports_socket_type(eNodeSocketDatatype(item->value), ntree.type);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3949,14 +3950,15 @@ typename Accessor::ItemT *rna_Node_ItemArray_new_with_socket_and_name(
|
||||
ID *id, bNode *node, Main *bmain, ReportList *reports, int socket_type, const char *name)
|
||||
{
|
||||
using ItemT = typename Accessor::ItemT;
|
||||
if (!Accessor::supports_socket_type(eNodeSocketDatatype(socket_type))) {
|
||||
|
||||
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(id);
|
||||
if (!Accessor::supports_socket_type(eNodeSocketDatatype(socket_type), ntree->type)) {
|
||||
BKE_report(reports, RPT_ERROR, "Unable to create item with this socket type");
|
||||
return nullptr;
|
||||
}
|
||||
ItemT *new_item = blender::nodes::socket_items::add_item_with_socket_type_and_name<Accessor>(
|
||||
*node, eNodeSocketDatatype(socket_type), name);
|
||||
*ntree, *node, eNodeSocketDatatype(socket_type), name);
|
||||
|
||||
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(id);
|
||||
BKE_ntree_update_tag_node_property(ntree, node);
|
||||
BKE_main_ensure_invariants(*bmain, ntree->id);
|
||||
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
|
||||
|
||||
@@ -193,10 +193,10 @@ template<typename Accessor> inline typename Accessor::ItemT &add_item_to_array(b
|
||||
*/
|
||||
template<typename Accessor>
|
||||
inline typename Accessor::ItemT *add_item_with_socket_type_and_name(
|
||||
bNode &node, const eNodeSocketDatatype socket_type, const char *name)
|
||||
bNodeTree &ntree, bNode &node, const eNodeSocketDatatype socket_type, const char *name)
|
||||
{
|
||||
using ItemT = typename Accessor::ItemT;
|
||||
BLI_assert(Accessor::supports_socket_type(socket_type));
|
||||
BLI_assert(Accessor::supports_socket_type(socket_type, ntree.type));
|
||||
ItemT &new_item = detail::add_item_to_array<Accessor>(node);
|
||||
Accessor::init_with_socket_type_and_name(node, new_item, socket_type, name);
|
||||
return &new_item;
|
||||
@@ -267,14 +267,15 @@ template<typename Accessor>
|
||||
const ItemT *item = nullptr;
|
||||
if constexpr (Accessor::has_name && Accessor::has_type) {
|
||||
const eNodeSocketDatatype socket_type = eNodeSocketDatatype(src_socket->type);
|
||||
if (!Accessor::supports_socket_type(socket_type)) {
|
||||
if (!Accessor::supports_socket_type(socket_type, ntree.type)) {
|
||||
return false;
|
||||
}
|
||||
std::string name = src_socket->name;
|
||||
if constexpr (Accessor::has_custom_initial_name) {
|
||||
name = Accessor::custom_initial_name(storage_node, name);
|
||||
}
|
||||
item = add_item_with_socket_type_and_name<Accessor>(storage_node, socket_type, name.c_str());
|
||||
item = add_item_with_socket_type_and_name<Accessor>(
|
||||
ntree, storage_node, socket_type, name.c_str());
|
||||
}
|
||||
else if constexpr (Accessor::has_name && !Accessor::has_type) {
|
||||
item = add_item_with_name<Accessor>(storage_node, src_socket->name);
|
||||
|
||||
@@ -151,11 +151,14 @@ inline void add_item(wmOperatorType *ot,
|
||||
if constexpr (Accessor::has_custom_initial_name) {
|
||||
name = Accessor::custom_initial_name(node, name);
|
||||
}
|
||||
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(node_ptr.owner_id);
|
||||
socket_items::add_item_with_socket_type_and_name<Accessor>(
|
||||
*ntree,
|
||||
node,
|
||||
active_item ?
|
||||
Accessor::get_socket_type(*active_item) :
|
||||
(Accessor::supports_socket_type(SOCK_GEOMETRY) ? SOCK_GEOMETRY : SOCK_FLOAT),
|
||||
(Accessor::supports_socket_type(SOCK_GEOMETRY, ntree->type) ? SOCK_GEOMETRY :
|
||||
SOCK_FLOAT),
|
||||
/* Empty name so it is based on the type. */
|
||||
name.c_str());
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ struct FormatStringItemsAccessor : public socket_items::SocketItemsAccessorDefau
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return ELEM(socket_type, SOCK_INT, SOCK_FLOAT, SOCK_STRING);
|
||||
}
|
||||
|
||||
@@ -77,9 +77,9 @@ struct BakeItemsAccessor : public socket_items::SocketItemsAccessorDefaults {
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
|
||||
{
|
||||
return SimulationItemsAccessor::supports_socket_type(socket_type);
|
||||
return SimulationItemsAccessor::supports_socket_type(socket_type, ntree_type);
|
||||
}
|
||||
|
||||
static void init_with_socket_type_and_name(bNode &node,
|
||||
|
||||
@@ -82,7 +82,7 @@ struct CombineBundleItemsAccessor : public socket_items::SocketItemsAccessorDefa
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return socket_type_supported_in_bundle(socket_type);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ struct SeparateBundleItemsAccessor : public socket_items::SocketItemsAccessorDef
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return socket_type_supported_in_bundle(socket_type);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ struct CaptureAttributeItemsAccessor : public socket_items::SocketItemsAccessorD
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return bke::socket_type_to_custom_data_type(socket_type).has_value() &&
|
||||
socket_type != SOCK_STRING;
|
||||
|
||||
@@ -82,7 +82,7 @@ struct ClosureInputItemsAccessor : public socket_items::SocketItemsAccessorDefau
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return socket_type_supported_in_closure(socket_type);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ struct ClosureOutputItemsAccessor : public socket_items::SocketItemsAccessorDefa
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return socket_type_supported_in_closure(socket_type);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ struct EvaluateClosureInputItemsAccessor : public socket_items::SocketItemsAcces
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return socket_type_supported_in_closure(socket_type);
|
||||
}
|
||||
@@ -306,7 +306,7 @@ struct EvaluateClosureOutputItemsAccessor : public socket_items::SocketItemsAcce
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return socket_type_supported_in_closure(socket_type);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ struct ForeachGeometryElementInputItemsAccessor
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return ELEM(socket_type,
|
||||
SOCK_FLOAT,
|
||||
@@ -152,7 +152,7 @@ struct ForeachGeometryElementMainItemsAccessor : public socket_items::SocketItem
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return ELEM(socket_type,
|
||||
SOCK_FLOAT,
|
||||
@@ -238,7 +238,7 @@ struct ForeachGeometryElementGenerationItemsAccessor
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return ELEM(socket_type,
|
||||
SOCK_FLOAT,
|
||||
|
||||
@@ -64,7 +64,7 @@ struct RepeatItemsAccessor : public socket_items::SocketItemsAccessorDefaults {
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
return ELEM(socket_type,
|
||||
SOCK_FLOAT,
|
||||
|
||||
@@ -64,7 +64,7 @@ struct SimulationItemsAccessor : public socket_items::SocketItemsAccessorDefault
|
||||
return &item.name;
|
||||
}
|
||||
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type)
|
||||
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int /*ntree_type*/)
|
||||
{
|
||||
/* Data-block types and closures are not supported. */
|
||||
return ELEM(socket_type,
|
||||
|
||||
@@ -239,14 +239,14 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
|
||||
params.connect_available_socket(node, "Geometry");
|
||||
});
|
||||
}
|
||||
if (!CaptureAttributeItemsAccessor::supports_socket_type(type)) {
|
||||
if (!CaptureAttributeItemsAccessor::supports_socket_type(type, params.node_tree().type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
params.add_item(IFACE_("Value"), [type](LinkSearchOpParams ¶ms) {
|
||||
bNode &node = params.add_node("GeometryNodeCaptureAttribute");
|
||||
socket_items::add_item_with_socket_type_and_name<CaptureAttributeItemsAccessor>(
|
||||
node, type, params.socket.name);
|
||||
params.node_tree, node, type, params.socket.name);
|
||||
params.update_and_connect_available_socket(node, params.socket.name);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!BakeItemsAccessor::supports_socket_type(type)) {
|
||||
if (!BakeItemsAccessor::supports_socket_type(type, params.node_tree().type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
|
||||
[type](LinkSearchOpParams ¶ms) {
|
||||
bNode &node = params.add_node("GeometryNodeBake");
|
||||
socket_items::add_item_with_socket_type_and_name<BakeItemsAccessor>(
|
||||
node, type, params.socket.name);
|
||||
params.node_tree, node, type, params.socket.name);
|
||||
params.update_and_connect_available_socket(node, params.socket.name);
|
||||
},
|
||||
-1);
|
||||
|
||||
@@ -232,7 +232,9 @@ static void node_operators()
|
||||
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
|
||||
{
|
||||
const bNodeSocket &other_socket = params.other_socket();
|
||||
if (!RepeatItemsAccessor::supports_socket_type(eNodeSocketDatatype(other_socket.type))) {
|
||||
if (!RepeatItemsAccessor::supports_socket_type(eNodeSocketDatatype(other_socket.type),
|
||||
params.node_tree().type))
|
||||
{
|
||||
return;
|
||||
}
|
||||
params.add_item_full_name(IFACE_("Repeat"), [](LinkSearchOpParams ¶ms) {
|
||||
@@ -245,7 +247,10 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
|
||||
|
||||
socket_items::clear<RepeatItemsAccessor>(output_node);
|
||||
socket_items::add_item_with_socket_type_and_name<RepeatItemsAccessor>(
|
||||
output_node, eNodeSocketDatatype(params.socket.type), params.socket.name);
|
||||
params.node_tree,
|
||||
output_node,
|
||||
eNodeSocketDatatype(params.socket.type),
|
||||
params.socket.name);
|
||||
update_node_declaration_and_sockets(params.node_tree, input_node);
|
||||
update_node_declaration_and_sockets(params.node_tree, output_node);
|
||||
if (params.socket.in_out == SOCK_IN) {
|
||||
|
||||
@@ -882,7 +882,9 @@ static void node_extra_info(NodeExtraInfoParams ¶ms)
|
||||
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
|
||||
{
|
||||
const bNodeSocket &other_socket = params.other_socket();
|
||||
if (!SimulationItemsAccessor::supports_socket_type(eNodeSocketDatatype(other_socket.type))) {
|
||||
if (!SimulationItemsAccessor::supports_socket_type(eNodeSocketDatatype(other_socket.type),
|
||||
params.node_tree().type))
|
||||
{
|
||||
return;
|
||||
}
|
||||
params.add_item_full_name(IFACE_("Simulation"), [](LinkSearchOpParams ¶ms) {
|
||||
@@ -895,7 +897,10 @@ static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
|
||||
|
||||
socket_items::clear<SimulationItemsAccessor>(output_node);
|
||||
socket_items::add_item_with_socket_type_and_name<SimulationItemsAccessor>(
|
||||
output_node, eNodeSocketDatatype(params.socket.type), params.socket.name);
|
||||
params.node_tree,
|
||||
output_node,
|
||||
eNodeSocketDatatype(params.socket.type),
|
||||
params.socket.name);
|
||||
update_node_declaration_and_sockets(params.node_tree, input_node);
|
||||
update_node_declaration_and_sockets(params.node_tree, output_node);
|
||||
if (params.socket.in_out == SOCK_IN) {
|
||||
|
||||
@@ -213,7 +213,7 @@ void sync_sockets_separate_bundle(SpaceNode &snode,
|
||||
for (const nodes::BundleSignature::Item &item : sync_state.source_signature->items) {
|
||||
NodeSeparateBundleItem &new_item = *nodes::socket_items::add_item_with_socket_type_and_name<
|
||||
nodes ::SeparateBundleItemsAccessor>(
|
||||
separate_bundle_node, item.type->type, item.key.c_str());
|
||||
*snode.edittree, separate_bundle_node, item.type->type, item.key.c_str());
|
||||
if (const std::optional<int> old_identifier = old_identifiers.lookup_try(item.key)) {
|
||||
new_item.identifier = *old_identifier;
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void sync_sockets_combine_bundle(SpaceNode &snode,
|
||||
for (const nodes::BundleSignature::Item &item : sync_state.source_signature->items) {
|
||||
NodeCombineBundleItem &new_item = *nodes::socket_items::add_item_with_socket_type_and_name<
|
||||
nodes ::CombineBundleItemsAccessor>(
|
||||
combine_bundle_node, item.type->type, item.key.c_str());
|
||||
*snode.edittree, combine_bundle_node, item.type->type, item.key.c_str());
|
||||
if (const std::optional<int> old_identifier = old_identifiers.lookup_try(item.key)) {
|
||||
new_item.identifier = *old_identifier;
|
||||
}
|
||||
@@ -302,7 +302,7 @@ void sync_sockets_evaluate_closure(SpaceNode &snode,
|
||||
NodeEvaluateClosureInputItem &new_item =
|
||||
*nodes::socket_items::add_item_with_socket_type_and_name<
|
||||
nodes::EvaluateClosureInputItemsAccessor>(
|
||||
evaluate_closure_node, item.type->type, item.key.c_str());
|
||||
*snode.edittree, evaluate_closure_node, item.type->type, item.key.c_str());
|
||||
if (const std::optional<int> old_identifier = old_input_identifiers.lookup_try(item.key)) {
|
||||
new_item.identifier = *old_identifier;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ void sync_sockets_evaluate_closure(SpaceNode &snode,
|
||||
NodeEvaluateClosureOutputItem &new_item =
|
||||
*nodes::socket_items::add_item_with_socket_type_and_name<
|
||||
nodes::EvaluateClosureOutputItemsAccessor>(
|
||||
evaluate_closure_node, item.type->type, item.key.c_str());
|
||||
*snode.edittree, evaluate_closure_node, item.type->type, item.key.c_str());
|
||||
if (const std::optional<int> old_identifier = old_output_identifiers.lookup_try(item.key)) {
|
||||
new_item.identifier = *old_identifier;
|
||||
}
|
||||
@@ -360,7 +360,7 @@ void sync_sockets_closure(SpaceNode &snode,
|
||||
for (const nodes::ClosureSignature::Item &item : signature.inputs) {
|
||||
NodeClosureInputItem &new_item =
|
||||
*nodes::socket_items::add_item_with_socket_type_and_name<nodes::ClosureInputItemsAccessor>(
|
||||
closure_output_node, item.type->type, item.key.c_str());
|
||||
*snode.edittree, closure_output_node, item.type->type, item.key.c_str());
|
||||
if (item.structure_type) {
|
||||
new_item.structure_type = int(*item.structure_type);
|
||||
}
|
||||
@@ -370,7 +370,8 @@ void sync_sockets_closure(SpaceNode &snode,
|
||||
}
|
||||
for (const nodes::ClosureSignature::Item &item : signature.outputs) {
|
||||
NodeClosureOutputItem &new_item = *nodes::socket_items::add_item_with_socket_type_and_name<
|
||||
nodes::ClosureOutputItemsAccessor>(closure_output_node, item.type->type, item.key.c_str());
|
||||
nodes::ClosureOutputItemsAccessor>(
|
||||
*snode.edittree, closure_output_node, item.type->type, item.key.c_str());
|
||||
if (const std::optional<int> old_identifier = old_output_identifiers.lookup_try(item.key)) {
|
||||
new_item.identifier = *old_identifier;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user