Blender  V2.93
node_fn_float_compare.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #include <cmath>
18 
19 #include "BLI_listbase.h"
20 #include "BLI_string.h"
21 
22 #include "RNA_enum_types.h"
23 
24 #include "UI_interface.h"
25 #include "UI_resources.h"
26 
27 #include "node_function_util.hh"
28 
30  {SOCK_FLOAT, N_("A"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
31  {SOCK_FLOAT, N_("B"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
32  {SOCK_FLOAT, N_("Epsilon"), 0.001f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
33  {-1, ""},
34 };
35 
37  {SOCK_BOOLEAN, N_("Result")},
38  {-1, ""},
39 };
40 
42 {
43  uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
44 }
45 
47 {
48  bNodeSocket *sockEpsilon = (bNodeSocket *)BLI_findlink(&node->inputs, 2);
49 
52 }
53 
55  bNode *node,
56  char *label,
57  int maxlen)
58 {
59  const char *name;
60  bool enum_label = RNA_enum_name(rna_enum_node_float_compare_items, node->custom1, &name);
61  if (!enum_label) {
62  name = "Unknown";
63  }
64  BLI_strncpy(label, IFACE_(name), maxlen);
65 }
66 
68 {
70  "Less Than", [](float a, float b) { return a < b; }};
72  "Less Equal", [](float a, float b) { return a <= b; }};
74  "Greater Than", [](float a, float b) { return a > b; }};
76  "Greater Equal", [](float a, float b) { return a >= b; }};
78  "Equal", [](float a, float b, float epsilon) { return std::abs(a - b) <= epsilon; }};
80  "Not Equal", [](float a, float b, float epsilon) { return std::abs(a - b) > epsilon; }};
81 
82  switch (node.custom1) {
84  return less_than_fn;
86  return less_equal_fn;
88  return greater_than_fn;
90  return greater_equal_fn;
92  return equal_fn;
94  return not_equal_fn;
95  }
96 
97  BLI_assert(false);
99 }
100 
102 {
103  const blender::fn::MultiFunction &fn = get_multi_function(builder.bnode());
104  builder.set_matching_fn(fn);
105 }
106 
108 {
109  static bNodeType ntype;
110 
111  fn_node_type_base(&ntype, FN_NODE_FLOAT_COMPARE, "Float Compare", NODE_CLASS_CONVERTOR, 0);
117  nodeRegisterType(&ntype);
118 }
void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3726
#define FN_NODE_FLOAT_COMPARE
Definition: BKE_node.h:1427
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4623
#define NODE_CLASS_CONVERTOR
Definition: BKE_node.h:341
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
void node_type_label(struct bNodeType *ntype, void(*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen))
#define BLI_assert(a)
Definition: BLI_assert.h:58
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, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
#define UNUSED(x)
#define ELEM(...)
#define IFACE_(msgid)
#define N_(msgid)
@ SOCK_BOOLEAN
@ SOCK_FLOAT
@ NODE_FLOAT_COMPARE_GREATER_THAN
@ NODE_FLOAT_COMPARE_GREATER_EQUAL
@ NODE_FLOAT_COMPARE_EQUAL
@ NODE_FLOAT_COMPARE_LESS_EQUAL
@ NODE_FLOAT_COMPARE_LESS_THAN
@ NODE_FLOAT_COMPARE_NOT_EQUAL
#define C
Definition: RandGen.cpp:39
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void set_matching_fn(const fn::MultiFunction &function)
OperationNode * node
const char * label
bNodeTree * ntree
static unsigned a[3]
Definition: RandGen.cpp:92
const MultiFunction & dummy_multi_function
static double epsilon
static void node_float_compare_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
static const blender::fn::MultiFunction & get_multi_function(bNode &node)
static void geo_node_float_compare_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
void register_node_type_fn_float_compare()
static bNodeSocketTemplate fn_node_float_compare_in[]
static void node_float_compare_update(bNodeTree *UNUSED(ntree), bNode *node)
static bNodeSocketTemplate fn_node_float_compare_out[]
static void node_float_compare_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
void fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
Definition: rna_access.c:1854
const EnumPropertyItem rna_enum_node_float_compare_items[]
Definition: rna_nodetree.c:273
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
NodeExpandInMFNetworkFunction expand_in_mf_network
Definition: BKE_node.h:324
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:253
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
PointerRNA * ptr
Definition: wm_files.c:3157