Blender  V3.3
node_fn_boolean_math.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "BLI_listbase.h"
4 #include "BLI_string.h"
5 
6 #include "RNA_enum_types.h"
7 
8 #include "UI_interface.h"
9 #include "UI_resources.h"
10 
12 
13 #include "node_function_util.hh"
14 
16 
18 {
19  b.is_function_node();
20  b.add_input<decl::Bool>(N_("Boolean"), "Boolean");
21  b.add_input<decl::Bool>(N_("Boolean"), "Boolean_001");
22  b.add_output<decl::Bool>(N_("Boolean"));
23 }
24 
26 {
27  uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
28 }
29 
31 {
32  bNodeSocket *sockB = (bNodeSocket *)BLI_findlink(&node->inputs, 1);
33 
35 }
36 
38  const bNode *node,
39  char *label,
40  int maxlen)
41 {
42  const char *name;
43  bool enum_label = RNA_enum_name(rna_enum_node_boolean_math_items, node->custom1, &name);
44  if (!enum_label) {
45  name = "Unknown";
46  }
47  BLI_strncpy(label, IFACE_(name), maxlen);
48 }
49 
51 {
52  if (!params.node_tree().typeinfo->validate_link(
53  static_cast<eNodeSocketDatatype>(params.other_socket().type), SOCK_BOOLEAN)) {
54  return;
55  }
56 
58  item->identifier != nullptr;
59  item++) {
60  if (item->name != nullptr && item->identifier[0] != '\0') {
61  NodeBooleanMathOperation operation = static_cast<NodeBooleanMathOperation>(item->value);
62  params.add_item(IFACE_(item->name), [operation](LinkSearchOpParams &params) {
63  bNode &node = params.add_node("FunctionNodeBooleanMath");
64  node.custom1 = operation;
65  params.update_and_connect_available_socket(node, "Boolean");
66  });
67  }
68  }
69 }
70 
72 {
73  static auto exec_preset = fn::CustomMF_presets::AllSpanOrSingle();
75  "And", [](bool a, bool b) { return a && b; }, exec_preset};
77  "Or", [](bool a, bool b) { return a || b; }, exec_preset};
78  static fn::CustomMF_SI_SO<bool, bool> not_fn{"Not", [](bool a) { return !a; }, exec_preset};
80  "Not And", [](bool a, bool b) { return !(a && b); }, exec_preset};
82  "Nor", [](bool a, bool b) { return !(a || b); }, exec_preset};
84  "Equal", [](bool a, bool b) { return a == b; }, exec_preset};
86  "Not Equal", [](bool a, bool b) { return a != b; }, exec_preset};
88  "Imply", [](bool a, bool b) { return !a || b; }, exec_preset};
90  "Subtract", [](bool a, bool b) { return a && !b; }, exec_preset};
91 
92  switch (bnode.custom1) {
94  return &and_fn;
96  return &or_fn;
98  return &not_fn;
100  return &nand_fn;
102  return &nor_fn;
104  return &xnor_fn;
106  return &xor_fn;
108  return &imply_fn;
110  return &nimply_fn;
111  }
112 
114  return nullptr;
115 }
116 
118 {
119  const fn::MultiFunction *fn = get_multi_function(builder.node());
120  builder.set_matching_fn(fn);
121 }
122 
123 } // namespace blender::nodes::node_fn_boolean_math_cc
124 
126 {
127  namespace file_ns = blender::nodes::node_fn_boolean_math_cc;
128 
129  static bNodeType ntype;
130 
138  nodeRegisterType(&ntype);
139 }
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4443
#define NODE_CLASS_CONVERTER
Definition: BKE_node.h:351
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
#define FN_NODE_BOOLEAN_MATH
Definition: BKE_node.h:1519
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
#define UNUSED(x)
#define ELEM(...)
#define IFACE_(msgid)
eNodeSocketDatatype
@ SOCK_BOOLEAN
NodeBooleanMathOperation
@ NODE_BOOLEAN_MATH_IMPLY
@ NODE_BOOLEAN_MATH_AND
@ NODE_BOOLEAN_MATH_NAND
@ NODE_BOOLEAN_MATH_XOR
@ NODE_BOOLEAN_MATH_NOT
@ NODE_BOOLEAN_MATH_OR
@ NODE_BOOLEAN_MATH_NIMPLY
@ NODE_BOOLEAN_MATH_XNOR
@ NODE_BOOLEAN_MATH_NOR
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void set_matching_fn(const MultiFunction *fn)
OperationNode * node
const char * label
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static unsigned a[3]
Definition: RandGen.cpp:78
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void fn_node_boolean_math_declare(NodeDeclarationBuilder &b)
static const fn::MultiFunction * get_multi_function(bNode &bnode)
static void node_boolean_math_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
static void fn_node_boolean_math_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_boolean_math_update(bNodeTree *ntree, bNode *node)
static void fn_node_boolean_math_build_multi_function(NodeMultiFunctionBuilder &builder)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_fn_boolean_math()
void fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
Definition: rna_access.c:1692
const EnumPropertyItem rna_enum_node_boolean_math_items[]
Definition: rna_nodetree.c:288
const char * identifier
Definition: RNA_types.h:461
Defines a node type.
Definition: BKE_node.h:226
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition: BKE_node.h:335
void(* labelfunc)(const struct bNodeTree *ntree, const struct bNode *node, char *label, int maxlen)
Definition: BKE_node.h:256
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeMultiFunctionBuildFunction build_multi_function
Definition: BKE_node.h:313
NodeDeclareFunction declare
Definition: BKE_node.h:324
short custom1
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480