2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2008 Blender Foundation. All rights reserved. */
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spnode
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
#include <array>
|
|
|
|
|
#include <cstdlib>
|
2013-04-02 03:51:42 +00:00
|
|
|
|
2008-12-28 00:08:34 +00:00
|
|
|
#include "DNA_node_types.h"
|
2020-05-25 10:43:44 +02:00
|
|
|
#include "DNA_windowmanager_types.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2018-02-18 21:27:33 +11:00
|
|
|
#include "BLI_lasso_2d.h"
|
2020-04-03 17:38:58 +02:00
|
|
|
#include "BLI_listbase.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_rect.h"
|
2013-04-01 15:07:22 +00:00
|
|
|
#include "BLI_string.h"
|
2020-09-09 13:44:39 +02:00
|
|
|
#include "BLI_string_search.h"
|
2014-07-04 14:17:54 +02:00
|
|
|
#include "BLI_string_utf8.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2013-01-24 21:57:13 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_node.h"
|
2020-05-25 10:43:44 +02:00
|
|
|
#include "BKE_workspace.h"
|
2013-01-24 21:57:13 +00:00
|
|
|
|
2012-08-02 23:03:16 +00:00
|
|
|
#include "ED_node.h" /* own include */
|
2008-12-28 00:08:34 +00:00
|
|
|
#include "ED_screen.h"
|
2018-08-14 10:28:41 +10:00
|
|
|
#include "ED_select_utils.h"
|
2021-07-05 10:46:00 +02:00
|
|
|
#include "ED_spreadsheet.h"
|
2020-05-25 10:43:44 +02:00
|
|
|
#include "ED_view3d.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
#include "UI_view2d.h"
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2020-05-11 10:29:41 -03:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
|
2012-08-22 13:34:06 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2021-11-12 12:12:27 -06:00
|
|
|
#include "node_intern.hh" /* own include */
|
2010-01-06 03:00:19 +00:00
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
2021-12-03 16:25:17 -05:00
|
|
|
|
2022-05-18 14:25:05 +10:00
|
|
|
static bool is_event_over_node_or_socket(bContext *C, const wmEvent *event);
|
|
|
|
|
|
2021-01-20 15:15:38 +11:00
|
|
|
/**
|
|
|
|
|
* Function to detect if there is a visible view3d that uses workbench in texture mode.
|
2020-05-25 10:43:44 +02:00
|
|
|
* This function is for fixing T76970 for Blender 2.83. The actual fix should add a mechanism in
|
|
|
|
|
* the depsgraph that can be used by the draw engines to check if they need to be redrawn.
|
|
|
|
|
*
|
|
|
|
|
* We don't want to add these risky changes this close before releasing 2.83 without good testing
|
|
|
|
|
* hence this workaround. There are still cases were too many updates happen. For example when you
|
|
|
|
|
* have both a Cycles and workbench with textures viewport.
|
2021-01-20 15:15:38 +11:00
|
|
|
*/
|
2020-05-25 10:43:44 +02:00
|
|
|
static bool has_workbench_in_texture_color(const wmWindowManager *wm,
|
|
|
|
|
const Scene *scene,
|
|
|
|
|
const Object *ob)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
|
|
|
|
if (win->scene != scene) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
if (area->spacetype == SPACE_VIEW3D) {
|
2021-06-02 17:19:36 +02:00
|
|
|
const View3D *v3d = (const View3D *)area->spacedata.first;
|
2020-05-25 10:43:44 +02:00
|
|
|
|
|
|
|
|
if (ED_view3d_has_workbench_in_texture_color(scene, ob, v3d)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Public Node Selection API
|
|
|
|
|
* \{ */
|
2010-01-06 03:00:19 +00:00
|
|
|
|
2022-01-05 12:32:00 +01:00
|
|
|
rctf node_frame_rect_inside(const bNode &node)
|
|
|
|
|
{
|
|
|
|
|
const float margin = 1.5f * U.widget_unit;
|
|
|
|
|
rctf frame_inside = {
|
|
|
|
|
node.totr.xmin,
|
|
|
|
|
node.totr.xmax,
|
|
|
|
|
node.totr.ymin,
|
|
|
|
|
node.totr.ymax,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BLI_rctf_pad(&frame_inside, -margin, -margin);
|
|
|
|
|
|
|
|
|
|
return frame_inside;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 14:25:05 +10:00
|
|
|
bool node_or_socket_isect_event(bContext *C, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
return is_event_over_node_or_socket(C, event);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 12:32:00 +01:00
|
|
|
static bool node_frame_select_isect_mouse(bNode *node, const float2 &mouse)
|
|
|
|
|
{
|
|
|
|
|
/* Frame nodes are selectable by their borders (including their whole rect - as for other nodes -
|
|
|
|
|
* would prevent e.g. box selection of nodes inside that frame). */
|
|
|
|
|
const rctf frame_inside = node_frame_rect_inside(*node);
|
|
|
|
|
if (BLI_rctf_isect_pt(&node->totr, mouse.x, mouse.y) &&
|
|
|
|
|
!BLI_rctf_isect_pt(&frame_inside, mouse.x, mouse.y)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static bNode *node_under_mouse_select(bNodeTree &ntree, int mx, int my)
|
2010-01-06 03:00:19 +00:00
|
|
|
{
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) {
|
2022-01-05 12:32:00 +01:00
|
|
|
switch (node->type) {
|
|
|
|
|
case NODE_FRAME: {
|
|
|
|
|
const float2 mouse{(float)mx, (float)my};
|
|
|
|
|
if (node_frame_select_isect_mouse(node, mouse)) {
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
if (BLI_rctf_isect_pt(&node->totr, mx, my)) {
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-02 17:19:36 +02:00
|
|
|
return nullptr;
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static bNode *node_under_mouse_tweak(bNodeTree &ntree, const float2 &mouse)
|
2012-06-01 12:38:03 +00:00
|
|
|
{
|
BLI: Refactor vector types & functions to use templates
This patch implements the vector types (i.e:`float2`) by making heavy
usage of templating. All vector functions are now outside of the vector
classes (inside the `blender::math` namespace) and are not vector size
dependent for the most part.
In the ongoing effort to make shaders less GL centric, we are aiming
to share more code between GLSL and C++ to avoid code duplication.
####Motivations:
- We are aiming to share UBO and SSBO structures between GLSL and C++.
This means we will use many of the existing vector types and others
we currently don't have (uintX, intX). All these variations were
asking for many more code duplication.
- Deduplicate existing code which is duplicated for each vector size.
- We also want to share small functions. Which means that vector
functions should be static and not in the class namespace.
- Reduce friction to use these types in new projects due to their
incompleteness.
- The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a
bit of a let down. Most clases are incomplete, out of sync with each
others with different codestyles, and some functions that should be
static are not (i.e: `float3::reflect()`).
####Upsides:
- Still support `.x, .y, .z, .w` for readability.
- Compact, readable and easilly extendable.
- All of the vector functions are available for all the vectors types
and can be restricted to certain types. Also template specialization
let us define exception for special class (like mpq).
- With optimization ON, the compiler unroll the loops and performance
is the same.
####Downsides:
- Might impact debugability. Though I would arge that the bugs are
rarelly caused by the vector class itself (since the operations are
quite trivial) but by the type conversions.
- Might impact compile time. I did not saw a significant impact since
the usage is not really widespread.
- Functions needs to be rewritten to support arbitrary vector length.
For instance, one can't call `len_squared_v3v3` in
`math::length_squared()` and call it a day.
- Type cast does not work with the template version of the `math::`
vector functions. Meaning you need to manually cast `float *` and
`(float *)[3]` to `float3` for the function calls.
i.e: `math::distance_squared(float3(nearest.co), positions[i]);`
- Some parts might loose in readability:
`float3::dot(v1.normalized(), v2.normalized())`
becoming
`math::dot(math::normalize(v1), math::normalize(v2))`
But I propose, when appropriate, to use
`using namespace blender::math;` on function local or file scope to
increase readability.
`dot(normalize(v1), normalize(v2))`
####Consideration:
- Include back `.length()` method. It is quite handy and is more C++
oriented.
- I considered the GLM library as a candidate for replacement. It felt
like too much for what we need and would be difficult to extend / modify
to our needs.
- I used Macros to reduce code in operators declaration and potential
copy paste bugs. This could reduce debugability and could be reverted.
- This touches `delaunay_2d.cc` and the intersection code. I would like
to know @howardt opinion on the matter.
- The `noexcept` on the copy constructor of `mpq(2|3)` is being removed.
But according to @JacquesLucke it is not a real problem for now.
I would like to give a huge thanks to @JacquesLucke who helped during this
and pushed me to reduce the duplication further.
Reviewed By: brecht, sergey, JacquesLucke
Differential Revision: https://developer.blender.org/D13791
2022-01-12 12:57:07 +01:00
|
|
|
using namespace blender::math;
|
|
|
|
|
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) {
|
2022-01-05 12:32:00 +01:00
|
|
|
switch (node->type) {
|
|
|
|
|
case NODE_REROUTE: {
|
|
|
|
|
bNodeSocket *socket = (bNodeSocket *)node->inputs.first;
|
|
|
|
|
const float2 location{socket->locx, socket->locy};
|
|
|
|
|
if (distance(mouse, location) < 24.0f) {
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NODE_FRAME: {
|
|
|
|
|
if (node_frame_select_isect_mouse(node, mouse)) {
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
if (BLI_rctf_isect_pt(&node->totr, mouse.x, mouse.y)) {
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2021-12-05 16:45:41 -05:00
|
|
|
}
|
2010-01-06 03:00:19 +00:00
|
|
|
}
|
2021-06-02 17:19:36 +02:00
|
|
|
return nullptr;
|
2010-01-06 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static bool is_position_over_node_or_socket(SpaceNode &snode, const float2 &mouse)
|
2018-12-20 10:55:30 +01:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node_under_mouse_tweak(*snode.edittree, mouse)) {
|
2018-12-20 10:55:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bNode *node;
|
|
|
|
|
bNodeSocket *sock;
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node_find_indicated_socket(
|
|
|
|
|
snode, &node, &sock, mouse, (eNodeSocketInOut)(SOCK_IN | SOCK_OUT))) {
|
2018-12-20 10:55:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool is_event_over_node_or_socket(bContext *C, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2021-12-03 16:25:17 -05:00
|
|
|
float2 mouse;
|
2022-03-09 08:36:36 +11:00
|
|
|
|
|
|
|
|
int mval[2];
|
|
|
|
|
WM_event_drag_start_mval(event, region, mval);
|
|
|
|
|
|
|
|
|
|
UI_view2d_region_to_view(®ion->v2d, mval[0], mval[1], &mouse.x, &mouse.y);
|
2021-12-03 16:25:17 -05:00
|
|
|
return is_position_over_node_or_socket(*snode, mouse);
|
2018-12-20 10:55:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_socket_select(bNode *node, bNodeSocket &sock)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
sock.flag |= SELECT;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* select node too */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node->flag |= SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_socket_deselect(bNode *node, bNodeSocket &sock, const bool deselect_node)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
sock.flag &= ~SELECT;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
if (node && deselect_node) {
|
2021-06-02 17:19:36 +02:00
|
|
|
bool sel = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* if no selected sockets remain, also deselect the node */
|
2021-12-03 16:25:17 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, input, &node->inputs) {
|
|
|
|
|
if (input->flag & SELECT) {
|
2021-06-02 17:19:36 +02:00
|
|
|
sel = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, output, &node->outputs) {
|
|
|
|
|
if (output->flag & SELECT) {
|
2021-06-02 17:19:36 +02:00
|
|
|
sel = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sel) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static void node_socket_toggle(bNode *node, bNodeSocket &sock, bool deselect_node)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
if (sock.flag & SELECT) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node_socket_deselect(node, sock, deselect_node);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-09 10:16:41 +00:00
|
|
|
node_socket_select(node, sock);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_deselect_all(SpaceNode &snode)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode.edittree->nodes) {
|
2014-04-01 11:34:00 +11:00
|
|
|
nodeSetSelected(node, false);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_deselect_all_input_sockets(SpaceNode &snode, const bool deselect_nodes)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
|
|
|
|
/* XXX not calling node_socket_deselect here each time, because this does iteration
|
|
|
|
|
* over all node sockets internally to check if the node stays selected.
|
|
|
|
|
* We can do that more efficiently here.
|
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode.edittree->nodes) {
|
|
|
|
|
bool sel = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
|
|
|
|
|
socket->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* if no selected sockets remain, also deselect the node */
|
|
|
|
|
if (deselect_nodes) {
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
|
|
|
|
|
if (socket->flag & SELECT) {
|
|
|
|
|
sel = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sel) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_deselect_all_output_sockets(SpaceNode &snode, const bool deselect_nodes)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
|
|
|
|
/* XXX not calling node_socket_deselect here each time, because this does iteration
|
|
|
|
|
* over all node sockets internally to check if the node stays selected.
|
|
|
|
|
* We can do that more efficiently here.
|
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode.edittree->nodes) {
|
2014-02-03 18:55:59 +11:00
|
|
|
bool sel = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
|
|
|
|
|
socket->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* if no selected sockets remain, also deselect the node */
|
|
|
|
|
if (deselect_nodes) {
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
|
|
|
|
|
if (socket->flag & SELECT) {
|
2021-06-02 17:19:36 +02:00
|
|
|
sel = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sel) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select Grouped Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* Return true if we need redraw, otherwise false. */
|
|
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
static bool node_select_grouped_type(bNodeTree &node_tree, bNode &node_act)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2014-07-05 17:58:21 +02:00
|
|
|
bool changed = false;
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2014-07-04 14:17:54 +02:00
|
|
|
if ((node->flag & SELECT) == 0) {
|
2022-01-18 13:32:36 -06:00
|
|
|
if (node->type == node_act.type) {
|
2014-07-04 14:17:54 +02:00
|
|
|
nodeSetSelected(node, true);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
2014-07-04 14:17:54 +02:00
|
|
|
return changed;
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
static bool node_select_grouped_color(bNodeTree &node_tree, bNode &node_act)
|
2014-07-04 14:17:54 +02:00
|
|
|
{
|
|
|
|
|
bool changed = false;
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2014-07-04 14:17:54 +02:00
|
|
|
if ((node->flag & SELECT) == 0) {
|
2022-01-18 13:32:36 -06:00
|
|
|
if (compare_v3v3(node->color, node_act.color, 0.005f)) {
|
2014-07-04 14:17:54 +02:00
|
|
|
nodeSetSelected(node, true);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
2014-07-04 14:17:54 +02:00
|
|
|
}
|
|
|
|
|
return changed;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
static bool node_select_grouped_name(bNodeTree &node_tree, bNode &node_act, const bool from_right)
|
2014-07-04 14:17:54 +02:00
|
|
|
{
|
|
|
|
|
bool changed = false;
|
2020-04-03 16:21:24 +11:00
|
|
|
const uint delims[] = {'.', '-', '_', '\0'};
|
2014-09-24 20:26:21 +02:00
|
|
|
size_t pref_len_act, pref_len_curr;
|
2015-06-27 11:00:47 +02:00
|
|
|
const char *sep, *suf_act, *suf_curr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-27 10:22:29 +02:00
|
|
|
pref_len_act = BLI_str_partition_ex_utf8(
|
2022-01-18 13:32:36 -06:00
|
|
|
node_act.name, nullptr, delims, &sep, &suf_act, from_right);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: in case we are searching for suffix, and found none, use whole name as suffix. */
|
2014-09-24 20:26:21 +02:00
|
|
|
if (from_right && !(sep && suf_act)) {
|
|
|
|
|
pref_len_act = 0;
|
2022-01-18 13:32:36 -06:00
|
|
|
suf_act = node_act.name;
|
2014-09-24 20:26:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2014-09-24 20:26:21 +02:00
|
|
|
if (node->flag & SELECT) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-06-27 10:22:29 +02:00
|
|
|
pref_len_curr = BLI_str_partition_ex_utf8(
|
2021-06-02 17:19:36 +02:00
|
|
|
node->name, nullptr, delims, &sep, &suf_curr, from_right);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-24 20:26:21 +02:00
|
|
|
/* Same as with active node name! */
|
|
|
|
|
if (from_right && !(sep && suf_curr)) {
|
|
|
|
|
pref_len_curr = 0;
|
|
|
|
|
suf_curr = node->name;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-24 20:26:21 +02:00
|
|
|
if ((from_right && STREQ(suf_act, suf_curr)) ||
|
|
|
|
|
(!from_right && (pref_len_act == pref_len_curr) &&
|
2022-01-18 13:32:36 -06:00
|
|
|
STREQLEN(node_act.name, node->name, pref_len_act))) {
|
2014-09-24 20:26:21 +02:00
|
|
|
nodeSetSelected(node, true);
|
|
|
|
|
changed = true;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
return changed;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
enum {
|
|
|
|
|
NODE_SELECT_GROUPED_TYPE = 0,
|
|
|
|
|
NODE_SELECT_GROUPED_COLOR = 1,
|
|
|
|
|
NODE_SELECT_GROUPED_PREFIX = 2,
|
|
|
|
|
NODE_SELECT_GROUPED_SUFIX = 3,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int node_select_grouped_exec(bContext *C, wmOperator *op)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
|
|
|
|
bNode *node_act = nodeGetActive(snode.edittree);
|
2021-03-18 16:47:14 +01:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
if (node_act == nullptr) {
|
2021-03-18 16:47:14 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
bool changed = false;
|
|
|
|
|
const bool extend = RNA_boolean_get(op->ptr, "extend");
|
|
|
|
|
const int type = RNA_enum_get(op->ptr, "type");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
if (!extend) {
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2014-07-04 14:17:54 +02:00
|
|
|
nodeSetSelected(node, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nodeSetSelected(node_act, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
switch (type) {
|
|
|
|
|
case NODE_SELECT_GROUPED_TYPE:
|
2022-01-18 13:32:36 -06:00
|
|
|
changed = node_select_grouped_type(node_tree, *node_act);
|
2014-07-04 14:17:54 +02:00
|
|
|
break;
|
|
|
|
|
case NODE_SELECT_GROUPED_COLOR:
|
2022-01-18 13:32:36 -06:00
|
|
|
changed = node_select_grouped_color(node_tree, *node_act);
|
2014-07-04 14:17:54 +02:00
|
|
|
break;
|
|
|
|
|
case NODE_SELECT_GROUPED_PREFIX:
|
2022-01-18 13:32:36 -06:00
|
|
|
changed = node_select_grouped_name(node_tree, *node_act, false);
|
2014-07-04 14:17:54 +02:00
|
|
|
break;
|
|
|
|
|
case NODE_SELECT_GROUPED_SUFIX:
|
2022-01-18 13:32:36 -06:00
|
|
|
changed = node_select_grouped_name(node_tree, *node_act, true);
|
2014-07-04 14:17:54 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2011-12-18 12:51:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
if (changed) {
|
2022-01-18 13:32:36 -06:00
|
|
|
node_sort(node_tree);
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2014-07-04 14:17:54 +02:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
void NODE_OT_select_grouped(wmOperatorType *ot)
|
|
|
|
|
{
|
2021-08-25 17:59:47 +10:00
|
|
|
PropertyRNA *prop;
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem prop_select_grouped_types[] = {
|
2014-07-04 14:17:54 +02:00
|
|
|
{NODE_SELECT_GROUPED_TYPE, "TYPE", 0, "Type", ""},
|
|
|
|
|
{NODE_SELECT_GROUPED_COLOR, "COLOR", 0, "Color", ""},
|
|
|
|
|
{NODE_SELECT_GROUPED_PREFIX, "PREFIX", 0, "Prefix", ""},
|
|
|
|
|
{NODE_SELECT_GROUPED_SUFIX, "SUFFIX", 0, "Suffix", ""},
|
2021-06-02 17:19:36 +02:00
|
|
|
{0, nullptr, 0, nullptr, nullptr},
|
2014-07-04 14:17:54 +02:00
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Select Grouped";
|
|
|
|
|
ot->description = "Select nodes with similar properties";
|
|
|
|
|
ot->idname = "NODE_OT_select_grouped";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
|
ot->exec = node_select_grouped_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* properties */
|
2021-08-25 17:59:47 +10:00
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
|
"extend",
|
|
|
|
|
false,
|
|
|
|
|
"Extend",
|
|
|
|
|
"Extend selection instead of deselecting everything first");
|
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2014-07-04 14:17:54 +02:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", "");
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select (Cursor Pick) Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_select_single(bContext &C, bNode &node)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
Main *bmain = CTX_data_main(&C);
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(&C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2021-12-03 16:25:17 -05:00
|
|
|
const Object *ob = CTX_data_active_object(&C);
|
|
|
|
|
const Scene *scene = CTX_data_scene(&C);
|
|
|
|
|
const wmWindowManager *wm = CTX_wm_manager(&C);
|
2020-05-25 10:43:44 +02:00
|
|
|
bool active_texture_changed = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node_iter, &node_tree.nodes) {
|
|
|
|
|
if (node_iter != &node) {
|
|
|
|
|
nodeSetSelected(node_iter, false);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
nodeSetSelected(&node, true);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
ED_node_set_active(bmain, &snode, &node_tree, &node, &active_texture_changed);
|
|
|
|
|
ED_node_set_active_viewer_key(&snode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
node_sort(node_tree);
|
2020-05-25 10:43:44 +02:00
|
|
|
if (active_texture_changed && has_workbench_in_texture_color(wm, scene, ob)) {
|
2022-01-18 13:32:36 -06:00
|
|
|
DEG_id_tag_update(&node_tree.id, ID_RECALC_COPY_ON_WRITE);
|
2020-05-25 10:43:44 +02:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
WM_event_add_notifier(&C, NC_NODE | NA_SELECTED, nullptr);
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 22:57:00 +10:00
|
|
|
static bool node_mouse_select(bContext *C,
|
|
|
|
|
wmOperator *op,
|
|
|
|
|
const int mval[2],
|
|
|
|
|
struct SelectPick_Params *params)
|
2008-12-28 00:08:34 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
Main &bmain = *CTX_data_main(C);
|
|
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
ARegion ®ion = *CTX_wm_region(C);
|
2020-05-25 10:43:44 +02:00
|
|
|
const Object *ob = CTX_data_active_object(C);
|
|
|
|
|
const Scene *scene = CTX_data_scene(C);
|
|
|
|
|
const wmWindowManager *wm = CTX_wm_manager(C);
|
2012-03-09 10:16:41 +00:00
|
|
|
bNode *node, *tnode;
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeSocket *sock = nullptr;
|
2019-03-22 17:03:02 +01:00
|
|
|
bNodeSocket *tsock;
|
2013-09-05 13:03:03 +00:00
|
|
|
float cursor[2];
|
2019-05-14 15:51:49 +02:00
|
|
|
|
2019-10-01 21:47:19 +02:00
|
|
|
/* always do socket_select when extending selection. */
|
2022-05-10 22:57:00 +10:00
|
|
|
const bool socket_select = (params->sel_op == SEL_OP_XOR) ||
|
|
|
|
|
RNA_boolean_get(op->ptr, "socket_select");
|
|
|
|
|
bool changed = false;
|
|
|
|
|
bool found = false;
|
|
|
|
|
bool node_was_selected = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-20 04:19:57 +00:00
|
|
|
/* get mouse coordinates in view2d space */
|
2021-12-03 16:25:17 -05:00
|
|
|
UI_view2d_region_to_view(®ion.v2d, mval[0], mval[1], &cursor[0], &cursor[1]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-22 17:03:02 +01:00
|
|
|
/* first do socket selection, these generally overlap with nodes. */
|
|
|
|
|
if (socket_select) {
|
2022-05-10 22:57:00 +10:00
|
|
|
/* NOTE: unlike nodes #SelectPick_Params isn't fully supported. */
|
|
|
|
|
const bool extend = (params->sel_op == SEL_OP_XOR);
|
2013-09-05 13:03:03 +00:00
|
|
|
if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) {
|
2022-05-10 22:57:00 +10:00
|
|
|
found = true;
|
|
|
|
|
node_was_selected = node->flag & SELECT;
|
|
|
|
|
|
2019-05-06 20:34:01 +02:00
|
|
|
/* NOTE: SOCK_IN does not take into account the extend case...
|
|
|
|
|
* This feature is not really used anyway currently? */
|
2021-12-03 16:25:17 -05:00
|
|
|
node_socket_toggle(node, *sock, true);
|
2022-05-10 22:57:00 +10:00
|
|
|
changed = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
2013-09-05 13:03:03 +00:00
|
|
|
else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_OUT)) {
|
2022-05-10 22:57:00 +10:00
|
|
|
found = true;
|
|
|
|
|
node_was_selected = node->flag & SELECT;
|
|
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
if (sock->flag & SELECT) {
|
2019-03-22 17:03:02 +01:00
|
|
|
if (extend) {
|
2021-12-03 16:25:17 -05:00
|
|
|
node_socket_deselect(node, *sock, true);
|
2022-05-10 22:57:00 +10:00
|
|
|
changed = true;
|
2019-03-22 17:03:02 +01:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2019-05-06 20:34:01 +02:00
|
|
|
/* Only allow one selected output per node, for sensible linking.
|
|
|
|
|
* Allow selecting outputs from different nodes though, if extend is true. */
|
2012-03-09 10:16:41 +00:00
|
|
|
if (node) {
|
2021-06-02 17:19:36 +02:00
|
|
|
for (tsock = (bNodeSocket *)node->outputs.first; tsock; tsock = tsock->next) {
|
2019-05-06 20:34:01 +02:00
|
|
|
if (tsock == sock) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
node_socket_deselect(node, *tsock, true);
|
2022-05-10 22:57:00 +10:00
|
|
|
changed = true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
2019-05-06 20:34:01 +02:00
|
|
|
if (!extend) {
|
2021-12-03 16:25:17 -05:00
|
|
|
for (tnode = (bNode *)snode.edittree->nodes.first; tnode; tnode = tnode->next) {
|
2019-05-06 20:34:01 +02:00
|
|
|
if (tnode == node) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-06-02 17:19:36 +02:00
|
|
|
for (tsock = (bNodeSocket *)tnode->outputs.first; tsock; tsock = tsock->next) {
|
2021-12-03 16:25:17 -05:00
|
|
|
node_socket_deselect(tnode, *tsock, true);
|
2022-05-10 22:57:00 +10:00
|
|
|
changed = true;
|
2019-03-22 17:03:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
node_socket_select(node, *sock);
|
2022-05-10 22:57:00 +10:00
|
|
|
changed = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-03-22 17:03:02 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-23 16:23:44 +02:00
|
|
|
if (!sock) {
|
2022-05-10 22:57:00 +10:00
|
|
|
|
2019-05-06 20:34:01 +02:00
|
|
|
/* find the closest visible node */
|
2021-12-03 16:25:17 -05:00
|
|
|
node = node_under_mouse_select(*snode.edittree, (int)cursor[0], (int)cursor[1]);
|
2022-05-10 22:57:00 +10:00
|
|
|
found = (node != nullptr);
|
|
|
|
|
node_was_selected = node && (node->flag & SELECT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-10 22:57:00 +10:00
|
|
|
if (params->sel_op == SEL_OP_SET) {
|
|
|
|
|
if ((found && params->select_passthrough) && (node->flag & SELECT)) {
|
|
|
|
|
found = false;
|
2021-03-24 12:13:14 +01:00
|
|
|
}
|
2022-05-10 22:57:00 +10:00
|
|
|
else if (found || params->deselect_all) {
|
|
|
|
|
/* Deselect everything. */
|
2021-12-03 16:25:17 -05:00
|
|
|
for (tnode = (bNode *)snode.edittree->nodes.first; tnode; tnode = tnode->next) {
|
2021-03-24 12:13:14 +01:00
|
|
|
nodeSetSelected(tnode, false);
|
|
|
|
|
}
|
2022-05-10 22:57:00 +10:00
|
|
|
changed = true;
|
2019-05-14 15:51:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 22:57:00 +10:00
|
|
|
if (found) {
|
|
|
|
|
switch (params->sel_op) {
|
|
|
|
|
case SEL_OP_ADD: {
|
|
|
|
|
nodeSetSelected(node, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEL_OP_SUB: {
|
|
|
|
|
nodeSetSelected(node, false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEL_OP_XOR: {
|
|
|
|
|
/* Check active so clicking on an inactive node activates it. */
|
|
|
|
|
bool is_selected = (node->flag & NODE_SELECT) && (node->flag & NODE_ACTIVE);
|
|
|
|
|
nodeSetSelected(node, !is_selected);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEL_OP_SET: {
|
|
|
|
|
nodeSetSelected(node, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SEL_OP_AND: {
|
|
|
|
|
BLI_assert_unreachable(); /* Doesn't make sense for picking. */
|
|
|
|
|
break;
|
2019-04-29 12:12:50 +02:00
|
|
|
}
|
2013-03-18 18:25:05 +00:00
|
|
|
}
|
2022-05-10 22:57:00 +10:00
|
|
|
|
|
|
|
|
changed = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
2008-12-28 00:08:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-14 17:52:50 +00:00
|
|
|
/* update node order */
|
2022-05-10 22:57:00 +10:00
|
|
|
if (changed || found) {
|
2020-05-25 10:43:44 +02:00
|
|
|
bool active_texture_changed = false;
|
2021-07-05 10:46:00 +02:00
|
|
|
bool viewer_node_changed = false;
|
2022-05-10 22:57:00 +10:00
|
|
|
if ((node != nullptr) && (node_was_selected == false || params->select_passthrough == false)) {
|
2021-07-05 10:46:00 +02:00
|
|
|
viewer_node_changed = (node->flag & NODE_DO_OUTPUT) == 0 && node->type == GEO_NODE_VIEWER;
|
2021-12-03 16:25:17 -05:00
|
|
|
ED_node_set_active(&bmain, &snode, snode.edittree, node, &active_texture_changed);
|
2021-07-05 10:46:00 +02:00
|
|
|
}
|
|
|
|
|
else if (node != nullptr && node->type == GEO_NODE_VIEWER) {
|
2021-12-03 16:25:17 -05:00
|
|
|
ED_spreadsheet_context_paths_set_geometry_node(&bmain, &snode, node);
|
2019-05-06 20:34:01 +02:00
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
ED_node_set_active_viewer_key(&snode);
|
2022-01-18 13:32:36 -06:00
|
|
|
node_sort(*snode.edittree);
|
2021-07-05 10:46:00 +02:00
|
|
|
if ((active_texture_changed && has_workbench_in_texture_color(wm, scene, ob)) ||
|
|
|
|
|
viewer_node_changed) {
|
2021-12-03 16:25:17 -05:00
|
|
|
DEG_id_tag_update(&snode.edittree->id, ID_RECALC_COPY_ON_WRITE);
|
2020-05-25 10:43:44 +02:00
|
|
|
}
|
2019-05-14 15:51:49 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2013-04-24 16:36:50 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-10 22:57:00 +10:00
|
|
|
return changed || found;
|
2008-12-28 00:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_select_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2009-11-20 04:19:57 +00:00
|
|
|
/* get settings from RNA properties for operator */
|
2019-10-01 21:47:19 +02:00
|
|
|
int mval[2];
|
2022-05-10 22:57:00 +10:00
|
|
|
RNA_int_get_array(op->ptr, "location", mval);
|
|
|
|
|
|
|
|
|
|
struct SelectPick_Params params = {};
|
2022-05-13 16:09:04 +10:00
|
|
|
ED_select_pick_params_from_operator(op->ptr, ¶ms);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-20 04:19:57 +00:00
|
|
|
/* perform the select */
|
2022-05-10 22:57:00 +10:00
|
|
|
const bool changed = node_mouse_select(C, op, mval, ¶ms);
|
2019-05-14 15:51:49 +02:00
|
|
|
|
2022-05-10 22:57:00 +10:00
|
|
|
if (changed) {
|
|
|
|
|
return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
/* Nothing selected, just passthrough. */
|
|
|
|
|
return OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
RNA_int_set_array(op->ptr, "location", event->mval);
|
|
|
|
|
|
|
|
|
|
const int retval = node_select_exec(C, op);
|
|
|
|
|
|
|
|
|
|
return WM_operator_flag_only_pass_through_on_press(retval, event);
|
2019-05-14 15:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-28 00:08:34 +00:00
|
|
|
void NODE_OT_select(wmOperatorType *ot)
|
|
|
|
|
{
|
2019-10-04 15:19:30 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
2008-12-28 00:08:34 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Select";
|
|
|
|
|
ot->idname = "NODE_OT_select";
|
|
|
|
|
ot->description = "Select the node under the cursor";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-28 00:08:34 +00:00
|
|
|
/* api callbacks */
|
2013-07-12 08:31:39 +00:00
|
|
|
ot->exec = node_select_exec;
|
2022-05-10 22:57:00 +10:00
|
|
|
ot->invoke = node_select_invoke;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
2022-05-13 16:09:04 +10:00
|
|
|
ot->get_name = ED_select_pick_get_name;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-20 04:19:57 +00:00
|
|
|
/* properties */
|
2022-05-10 22:57:00 +10:00
|
|
|
WM_operator_properties_mouse_select(ot);
|
|
|
|
|
|
|
|
|
|
prop = RNA_def_int_vector(ot->srna,
|
|
|
|
|
"location",
|
|
|
|
|
2,
|
2022-05-15 19:04:07 +02:00
|
|
|
nullptr,
|
2022-05-10 22:57:00 +10:00
|
|
|
INT_MIN,
|
|
|
|
|
INT_MAX,
|
|
|
|
|
"Location",
|
|
|
|
|
"Mouse location",
|
|
|
|
|
INT_MIN,
|
|
|
|
|
INT_MAX);
|
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
|
|
2019-03-22 17:03:02 +01:00
|
|
|
RNA_def_boolean(ot->srna, "socket_select", false, "Socket Select", "");
|
2008-12-28 00:08:34 +00:00
|
|
|
}
|
2009-01-05 23:53:04 +00:00
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Box Select Operator
|
|
|
|
|
* \{ */
|
2009-01-05 23:53:04 +00:00
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
static int node_box_select_exec(bContext *C, wmOperator *op)
|
2009-01-05 23:53:04 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
|
|
|
|
const ARegion ®ion = *CTX_wm_region(C);
|
2009-01-05 23:53:04 +00:00
|
|
|
rctf rectf;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-21 16:47:16 +10:00
|
|
|
WM_operator_properties_border_to_rctf(op, &rectf);
|
2022-01-18 13:32:36 -06:00
|
|
|
UI_view2d_region_to_view_rctf(®ion.v2d, &rectf, &rectf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
const eSelectOp sel_op = (eSelectOp)RNA_enum_get(op->ptr, "mode");
|
2019-03-07 20:33:57 +11:00
|
|
|
const bool select = (sel_op != SEL_OP_SUB);
|
|
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
2022-01-18 13:32:36 -06:00
|
|
|
node_select_all(&node_tree.nodes, SEL_DESELECT);
|
2019-03-07 20:33:57 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2022-01-05 12:32:00 +01:00
|
|
|
bool is_inside = false;
|
|
|
|
|
|
|
|
|
|
switch (node->type) {
|
|
|
|
|
case NODE_FRAME: {
|
|
|
|
|
/* Frame nodes are selectable by their borders (including their whole rect - as for other
|
|
|
|
|
* nodes - would prevent selection of other nodes inside that frame. */
|
|
|
|
|
const rctf frame_inside = node_frame_rect_inside(*node);
|
2022-02-13 13:15:53 -06:00
|
|
|
if (BLI_rctf_isect(&rectf, &node->totr, nullptr) &&
|
2022-01-05 12:32:00 +01:00
|
|
|
!BLI_rctf_inside_rctf(&frame_inside, &rectf)) {
|
|
|
|
|
nodeSetSelected(node, select);
|
|
|
|
|
is_inside = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
is_inside = BLI_rctf_isect(&rectf, &node->totr, nullptr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-10-24 01:06:28 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-16 21:58:51 +11:00
|
|
|
if (is_inside) {
|
|
|
|
|
nodeSetSelected(node, select);
|
2009-01-05 23:53:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
node_sort(node_tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-05 23:53:04 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
static int node_box_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2010-01-06 03:00:19 +00:00
|
|
|
{
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool tweak = RNA_boolean_get(op->ptr, "tweak");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-12-20 10:55:30 +01:00
|
|
|
if (tweak && is_event_over_node_or_socket(C, event)) {
|
|
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
2010-01-06 03:00:19 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
return WM_gesture_box_invoke(C, op, event);
|
2010-01-06 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
void NODE_OT_select_box(wmOperatorType *ot)
|
2009-01-05 23:53:04 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2018-10-05 10:27:04 +10:00
|
|
|
ot->name = "Box Select";
|
|
|
|
|
ot->idname = "NODE_OT_select_box";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->description = "Use box selection to select nodes";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-05 23:53:04 +00:00
|
|
|
/* api callbacks */
|
2018-10-05 10:27:04 +10:00
|
|
|
ot->invoke = node_box_select_invoke;
|
|
|
|
|
ot->exec = node_box_select_exec;
|
|
|
|
|
ot->modal = WM_gesture_box_modal;
|
|
|
|
|
ot->cancel = WM_gesture_box_cancel;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-07 20:33:57 +11:00
|
|
|
/* properties */
|
2010-01-06 03:00:19 +00:00
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
|
"tweak",
|
2021-06-02 17:19:36 +02:00
|
|
|
false,
|
2010-01-06 03:00:19 +00:00
|
|
|
"Tweak",
|
2021-02-24 13:25:44 -06:00
|
|
|
"Only activate when mouse is not over a node (useful for tweak gesture)");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-07 20:33:57 +11:00
|
|
|
WM_operator_properties_gesture_box(ot);
|
|
|
|
|
WM_operator_properties_select_operation_simple(ot);
|
2009-01-16 23:53:11 +00:00
|
|
|
}
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Circle Select Operator
|
|
|
|
|
* \{ */
|
2013-11-06 19:21:42 +00:00
|
|
|
|
|
|
|
|
static int node_circleselect_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2013-11-06 19:21:42 +00:00
|
|
|
bNode *node;
|
|
|
|
|
|
2017-10-16 21:58:51 +11:00
|
|
|
int x, y, radius;
|
2013-11-06 19:21:42 +00:00
|
|
|
float offset[2];
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
float zoom = (float)(BLI_rcti_size_x(®ion->winrct)) /
|
|
|
|
|
(float)(BLI_rctf_size_x(®ion->v2d.cur));
|
2013-11-06 19:21:42 +00:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
const eSelectOp sel_op = ED_select_op_modal(
|
|
|
|
|
(eSelectOp)RNA_enum_get(op->ptr, "mode"),
|
|
|
|
|
WM_gesture_is_modal_first((const wmGesture *)op->customdata));
|
2019-03-05 22:26:45 +11:00
|
|
|
const bool select = (sel_op != SEL_OP_SUB);
|
|
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
2022-01-18 13:07:18 -06:00
|
|
|
node_select_all(&snode->edittree->nodes, SEL_DESELECT);
|
2019-03-05 22:26:45 +11:00
|
|
|
}
|
2013-11-06 19:21:42 +00:00
|
|
|
|
|
|
|
|
/* get operator properties */
|
|
|
|
|
x = RNA_int_get(op->ptr, "x");
|
|
|
|
|
y = RNA_int_get(op->ptr, "y");
|
|
|
|
|
radius = RNA_int_get(op->ptr, "radius");
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
UI_view2d_region_to_view(®ion->v2d, x, y, &offset[0], &offset[1]);
|
2013-11-06 19:21:42 +00:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
for (node = (bNode *)snode->edittree->nodes.first; node; node = node->next) {
|
2022-01-05 12:32:00 +01:00
|
|
|
switch (node->type) {
|
|
|
|
|
case NODE_FRAME: {
|
|
|
|
|
/* Frame nodes are selectable by their borders (including their whole rect - as for other
|
|
|
|
|
* nodes - would prevent selection of _only_ other nodes inside that frame. */
|
|
|
|
|
rctf frame_inside = node_frame_rect_inside(*node);
|
|
|
|
|
const float radius_adjusted = (float)radius / zoom;
|
|
|
|
|
BLI_rctf_pad(&frame_inside, -2.0f * radius_adjusted, -2.0f * radius_adjusted);
|
|
|
|
|
if (BLI_rctf_isect_circle(&node->totr, offset, radius_adjusted) &&
|
|
|
|
|
!BLI_rctf_isect_circle(&frame_inside, offset, radius_adjusted)) {
|
|
|
|
|
nodeSetSelected(node, select);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
if (BLI_rctf_isect_circle(&node->totr, offset, radius / zoom)) {
|
|
|
|
|
nodeSetSelected(node, select);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-11-06 19:21:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2013-11-06 19:21:42 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_circle(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Circle Select";
|
|
|
|
|
ot->idname = "NODE_OT_select_circle";
|
|
|
|
|
ot->description = "Use circle selection to select nodes";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke = WM_gesture_circle_invoke;
|
|
|
|
|
ot->exec = node_circleselect_exec;
|
|
|
|
|
ot->modal = WM_gesture_circle_modal;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2022-05-13 16:09:04 +10:00
|
|
|
ot->get_name = ED_select_circle_get_name;
|
2013-11-06 19:21:42 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
2017-10-16 15:32:09 +11:00
|
|
|
/* properties */
|
2019-03-05 22:26:45 +11:00
|
|
|
WM_operator_properties_gesture_circle(ot);
|
|
|
|
|
WM_operator_properties_select_operation_simple(ot);
|
2013-11-06 19:21:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Lasso Select Operator
|
|
|
|
|
* \{ */
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2018-12-20 10:55:30 +01:00
|
|
|
static int node_lasso_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
const bool tweak = RNA_boolean_get(op->ptr, "tweak");
|
|
|
|
|
|
|
|
|
|
if (tweak && is_event_over_node_or_socket(C, event)) {
|
|
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WM_gesture_lasso_invoke(C, op, event);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 19:50:06 +10:00
|
|
|
static bool do_lasso_select_node(bContext *C,
|
|
|
|
|
const int mcoords[][2],
|
2020-05-05 16:12:36 +10:00
|
|
|
const int mcoords_len,
|
2020-05-04 19:50:06 +10:00
|
|
|
eSelectOp sel_op)
|
2012-08-22 13:34:06 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNode *node;
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
|
|
|
|
rcti rect;
|
2013-11-26 06:39:14 +11:00
|
|
|
bool changed = false;
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2019-03-07 23:41:32 +11:00
|
|
|
const bool select = (sel_op != SEL_OP_SUB);
|
|
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
2022-01-18 13:07:18 -06:00
|
|
|
node_select_all(&snode->edittree->nodes, SEL_DESELECT);
|
2019-03-07 23:41:32 +11:00
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 13:34:06 +00:00
|
|
|
/* get rectangle from operator */
|
2020-05-04 19:50:06 +10:00
|
|
|
BLI_lasso_boundbox(&rect, mcoords, mcoords_len);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
|
|
|
|
/* do actual selection */
|
2021-06-02 17:19:36 +02:00
|
|
|
for (node = (bNode *)snode->edittree->nodes.first; node; node = node->next) {
|
2018-05-13 09:37:53 +02:00
|
|
|
|
2019-03-07 23:41:32 +11:00
|
|
|
if (select && (node->flag & NODE_SELECT)) {
|
2018-05-13 09:37:53 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 12:32:00 +01:00
|
|
|
switch (node->type) {
|
|
|
|
|
case NODE_FRAME: {
|
|
|
|
|
/* Frame nodes are selectable by their borders (including their whole rect - as for other
|
|
|
|
|
* nodes - would prevent selection of other nodes inside that frame. */
|
|
|
|
|
rctf rectf;
|
|
|
|
|
BLI_rctf_rcti_copy(&rectf, &rect);
|
|
|
|
|
UI_view2d_region_to_view_rctf(®ion->v2d, &rectf, &rectf);
|
|
|
|
|
const rctf frame_inside = node_frame_rect_inside(*node);
|
2022-02-13 13:15:53 -06:00
|
|
|
if (BLI_rctf_isect(&rectf, &node->totr, nullptr) &&
|
2022-01-05 12:32:00 +01:00
|
|
|
!BLI_rctf_inside_rctf(&frame_inside, &rectf)) {
|
|
|
|
|
nodeSetSelected(node, select);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
int screen_co[2];
|
|
|
|
|
const float cent[2] = {BLI_rctf_cent_x(&node->totr), BLI_rctf_cent_y(&node->totr)};
|
|
|
|
|
|
|
|
|
|
/* marker in screen coords */
|
|
|
|
|
if (UI_view2d_view_to_region_clip(
|
|
|
|
|
®ion->v2d, cent[0], cent[1], &screen_co[0], &screen_co[1]) &&
|
|
|
|
|
BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
|
|
|
|
|
BLI_lasso_is_point_inside(mcoords, mcoords_len, screen_co[0], screen_co[1], INT_MAX)) {
|
|
|
|
|
nodeSetSelected(node, select);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
if (changed) {
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
return changed;
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_lasso_select_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2020-05-04 19:50:06 +10:00
|
|
|
int mcoords_len;
|
|
|
|
|
const int(*mcoords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcoords_len);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2020-05-04 19:50:06 +10:00
|
|
|
if (mcoords) {
|
2021-06-02 17:19:36 +02:00
|
|
|
const eSelectOp sel_op = (eSelectOp)RNA_enum_get(op->ptr, "mode");
|
2019-03-07 23:41:32 +11:00
|
|
|
|
2020-05-04 19:50:06 +10:00
|
|
|
do_lasso_select_node(C, mcoords, mcoords_len, sel_op);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2020-05-04 19:50:06 +10:00
|
|
|
MEM_freeN((void *)mcoords);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_lasso(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Lasso Select";
|
|
|
|
|
ot->description = "Select nodes using lasso selection";
|
|
|
|
|
ot->idname = "NODE_OT_select_lasso";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-22 13:34:06 +00:00
|
|
|
/* api callbacks */
|
2018-12-20 10:55:30 +01:00
|
|
|
ot->invoke = node_lasso_select_invoke;
|
2012-08-22 13:34:06 +00:00
|
|
|
ot->modal = WM_gesture_lasso_modal;
|
|
|
|
|
ot->exec = node_lasso_select_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
ot->cancel = WM_gesture_lasso_cancel;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-22 13:34:06 +00:00
|
|
|
/* flags */
|
2021-09-17 12:09:26 +10:00
|
|
|
ot->flag = OPTYPE_UNDO | OPTYPE_DEPENDS_ON_CURSOR;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-22 13:34:06 +00:00
|
|
|
/* properties */
|
2018-12-20 10:55:30 +01:00
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
|
"tweak",
|
2021-06-02 17:19:36 +02:00
|
|
|
false,
|
2018-12-20 10:55:30 +01:00
|
|
|
"Tweak",
|
2021-02-24 13:25:44 -06:00
|
|
|
"Only activate when mouse is not over a node (useful for tweak gesture)");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-07 23:41:32 +11:00
|
|
|
WM_operator_properties_gesture_lasso(ot);
|
|
|
|
|
WM_operator_properties_select_operation_simple(ot);
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name (De)select All Operator
|
|
|
|
|
* \{ */
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2012-08-01 13:28:19 +00:00
|
|
|
static int node_select_all_exec(bContext *C, wmOperator *op)
|
2009-09-14 08:47:13 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
ListBase *node_lb = &snode.edittree->nodes;
|
2012-08-01 13:28:19 +00:00
|
|
|
int action = RNA_enum_get(op->ptr, "action");
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2022-01-18 13:07:18 -06:00
|
|
|
node_select_all(node_lb, action);
|
2012-08-01 13:28:19 +00:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
node_sort(*snode.edittree);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2009-09-14 08:47:13 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_all(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-17 19:14:08 +00:00
|
|
|
ot->name = "(De)select All";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "(De)select all nodes";
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->idname = "NODE_OT_select_all";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_select_all_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-08-01 13:28:19 +00:00
|
|
|
|
|
|
|
|
WM_operator_properties_select_all(ot);
|
2009-09-14 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select Linked To Operator
|
|
|
|
|
* \{ */
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_select_linked_to_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-09-14 08:47:13 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2009-09-14 08:47:13 +00:00
|
|
|
node->flag &= ~NODE_TEST;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, &node_tree.links) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (nodeLinkIsHidden(link)) {
|
2013-03-18 16:34:57 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
if (link->fromnode && link->tonode && (link->fromnode->flag & NODE_SELECT)) {
|
2009-09-14 08:47:13 +00:00
|
|
|
link->tonode->flag |= NODE_TEST;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-20 04:19:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node->flag & NODE_TEST) {
|
2014-04-01 11:34:00 +11:00
|
|
|
nodeSetSelected(node, true);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-20 04:19:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
node_sort(node_tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2009-09-14 08:47:13 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_linked_to(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Select Linked To";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Select nodes linked to the selected ones";
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->idname = "NODE_OT_select_linked_to";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_select_linked_to_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-09-14 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select Linked From Operator
|
|
|
|
|
* \{ */
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_select_linked_from_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-09-14 08:47:13 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2009-09-14 08:47:13 +00:00
|
|
|
node->flag &= ~NODE_TEST;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, &node_tree.links) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (nodeLinkIsHidden(link)) {
|
2013-03-18 16:34:57 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
if (link->fromnode && link->tonode && (link->tonode->flag & NODE_SELECT)) {
|
2009-09-14 08:47:13 +00:00
|
|
|
link->fromnode->flag |= NODE_TEST;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-20 04:19:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &node_tree.nodes) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node->flag & NODE_TEST) {
|
2014-04-01 11:34:00 +11:00
|
|
|
nodeSetSelected(node, true);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-20 04:19:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
node_sort(node_tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2009-09-14 08:47:13 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_linked_from(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Select Linked From";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Select nodes linked from the selected ones";
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->idname = "NODE_OT_select_linked_from";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_select_linked_from_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-09-14 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select Same Type Step Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2013-03-27 18:28:25 +00:00
|
|
|
static int node_select_same_type_step_exec(bContext *C, wmOperator *op)
|
2013-03-27 17:22:12 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2013-03-27 17:22:12 +00:00
|
|
|
bNode **node_array;
|
|
|
|
|
bNode *active = nodeGetActive(snode->edittree);
|
|
|
|
|
int totnodes;
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool revert = RNA_boolean_get(op->ptr, "prev");
|
2021-06-02 17:19:36 +02:00
|
|
|
const bool same_type = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
ntreeGetDependencyList(snode->edittree, &node_array, &totnodes);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
if (totnodes > 1) {
|
|
|
|
|
int a;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
for (a = 0; a < totnodes; a++) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node_array[a] == active) {
|
2013-03-27 17:22:12 +00:00
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-27 17:22:12 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
if (same_type) {
|
2021-06-02 17:19:36 +02:00
|
|
|
bNode *node = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
while (node == nullptr) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (revert) {
|
|
|
|
|
a--;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
a++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (a < 0 || a >= totnodes) {
|
2013-03-27 17:22:12 +00:00
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
node = node_array[a];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node->type == active->type) {
|
2013-03-27 17:22:12 +00:00
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2021-06-02 17:19:36 +02:00
|
|
|
node = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node) {
|
2013-03-27 17:22:12 +00:00
|
|
|
active = node;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-27 17:22:12 +00:00
|
|
|
else {
|
|
|
|
|
if (revert) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (a == 0) {
|
2013-03-27 17:22:12 +00:00
|
|
|
active = node_array[totnodes - 1];
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2013-03-27 17:22:12 +00:00
|
|
|
active = node_array[a - 1];
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-27 17:22:12 +00:00
|
|
|
else {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (a == totnodes - 1) {
|
2013-03-27 17:22:12 +00:00
|
|
|
active = node_array[0];
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2013-03-27 17:22:12 +00:00
|
|
|
active = node_array[a + 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
node_select_single(*C, *active);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
/* is note outside view? */
|
2020-03-06 16:56:42 +01:00
|
|
|
if (active->totr.xmax < region->v2d.cur.xmin || active->totr.xmin > region->v2d.cur.xmax ||
|
|
|
|
|
active->totr.ymax < region->v2d.cur.ymin || active->totr.ymin > region->v2d.cur.ymax) {
|
2013-09-16 04:04:44 +00:00
|
|
|
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
|
2021-12-03 16:25:17 -05:00
|
|
|
space_node_view_flag(*C, *snode, *region, NODE_SELECT, smooth_viewtx);
|
2013-03-28 19:33:14 +00:00
|
|
|
}
|
2013-03-27 17:22:12 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node_array) {
|
2013-03-27 17:22:12 +00:00
|
|
|
MEM_freeN(node_array);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 18:28:25 +00:00
|
|
|
void NODE_OT_select_same_type_step(wmOperatorType *ot)
|
2013-03-27 17:22:12 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2013-03-27 18:28:25 +00:00
|
|
|
ot->name = "Activate Same Type Next/Prev";
|
|
|
|
|
ot->description = "Activate and view same node type, step by step";
|
|
|
|
|
ot->idname = "NODE_OT_select_same_type_step";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_select_same_type_step_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
/* flags */
|
2013-03-27 17:22:12 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
RNA_def_boolean(ot->srna, "prev", false, "Previous", "");
|
2013-03-27 17:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Find Node by Name Operator
|
|
|
|
|
* \{ */
|
2013-04-01 15:07:22 +00:00
|
|
|
|
2020-09-09 13:44:39 +02:00
|
|
|
static void node_find_create_label(const bNode *node, char *str, int maxlen)
|
|
|
|
|
{
|
|
|
|
|
if (node->label[0]) {
|
|
|
|
|
BLI_snprintf(str, maxlen, "%s (%s)", node->name, node->label);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_strncpy(str, node->name, maxlen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-23 16:56:00 +10:00
|
|
|
/* Generic search invoke. */
|
2020-05-08 12:01:35 +10:00
|
|
|
static void node_find_update_fn(const struct bContext *C,
|
|
|
|
|
void *UNUSED(arg),
|
|
|
|
|
const char *str,
|
UI: Expose an "is first search" boolean to search button callbacks
Currently when you open an RNA collection search button, like a
vertex group selector, the search filter isn't applied until you
start typing, in order to display every option at the start.
Otherwise they wouldn't be visible, since the search filter would
run for the current text.
Currently this check happens in one place, but it relies on the
`changed` value of `uiBut`. This is fine in the interface directory,
but anywhere else it would require exposing `uiBut.changed`, which
is probably too low-level to expose.
The solution is adding an `is_first` argument to the search callbacks,
which is nice for a few reasons:
- They work at a higher level of abstraction, meaning they don't
have to worry about how exactly to tell if this is the first
search.
- It makes it easier to do special behavior when the search menu
is first opened.
- Then, obviously, it makes that state accessible without including
`interface_intern.h`.
Needed for attribute search: T85658
Differential Revision: https://developer.blender.org/D10528
2021-03-02 11:42:05 -06:00
|
|
|
uiSearchItems *items,
|
|
|
|
|
const bool UNUSED(is_first))
|
2013-04-01 15:07:22 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-09 13:44:39 +02:00
|
|
|
StringSearch *search = BLI_string_search_new();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-09 13:44:39 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
|
|
|
|
|
char name[256];
|
|
|
|
|
node_find_create_label(node, name, ARRAY_SIZE(name));
|
2021-12-13 13:57:55 -06:00
|
|
|
BLI_string_search_add(search, name, node, 0);
|
2020-09-09 13:44:39 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-09 13:44:39 +02:00
|
|
|
bNode **filtered_nodes;
|
|
|
|
|
int filtered_amount = BLI_string_search_query(search, str, (void ***)&filtered_nodes);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < filtered_amount; i++) {
|
|
|
|
|
bNode *node = filtered_nodes[i];
|
|
|
|
|
char name[256];
|
|
|
|
|
node_find_create_label(node, name, ARRAY_SIZE(name));
|
|
|
|
|
if (!UI_search_item_add(items, name, node, ICON_NONE, 0, 0)) {
|
|
|
|
|
break;
|
2013-04-01 15:07:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-09 13:44:39 +02:00
|
|
|
|
|
|
|
|
MEM_freeN(filtered_nodes);
|
|
|
|
|
BLI_string_search_free(search);
|
2013-04-01 15:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-08 12:01:35 +10:00
|
|
|
static void node_find_exec_fn(struct bContext *C, void *UNUSED(arg1), void *arg2)
|
2013-04-01 15:07:22 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2021-06-02 17:19:36 +02:00
|
|
|
bNode *active = (bNode *)arg2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
if (active) {
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2021-12-03 16:25:17 -05:00
|
|
|
node_select_single(*C, *active);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
/* is note outside view? */
|
2020-03-06 16:56:42 +01:00
|
|
|
if (active->totr.xmax < region->v2d.cur.xmin || active->totr.xmin > region->v2d.cur.xmax ||
|
|
|
|
|
active->totr.ymax < region->v2d.cur.ymin || active->totr.ymin > region->v2d.cur.ymax) {
|
2021-12-03 16:25:17 -05:00
|
|
|
space_node_view_flag(*C, *snode, *region, NODE_SELECT, U.smooth_viewtx);
|
2013-04-01 15:07:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
static uiBlock *node_find_menu(bContext *C, ARegion *region, void *arg_op)
|
2013-04-01 15:07:22 +00:00
|
|
|
{
|
|
|
|
|
static char search[256] = "";
|
|
|
|
|
uiBlock *block;
|
|
|
|
|
uiBut *but;
|
|
|
|
|
wmOperator *op = (wmOperator *)arg_op;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
block = UI_block_begin(C, region, "_popup", UI_EMBOSS);
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU);
|
2018-09-11 10:56:08 +10:00
|
|
|
UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-27 12:16:16 +02:00
|
|
|
but = uiDefSearchBut(block,
|
|
|
|
|
search,
|
|
|
|
|
0,
|
|
|
|
|
ICON_VIEWZOOM,
|
|
|
|
|
sizeof(search),
|
|
|
|
|
10,
|
|
|
|
|
10,
|
|
|
|
|
UI_searchbox_size_x(),
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
"");
|
2021-04-14 11:11:51 -05:00
|
|
|
UI_but_func_search_set(
|
2021-06-02 17:19:36 +02:00
|
|
|
but, nullptr, node_find_update_fn, op->type, false, nullptr, node_find_exec_fn, nullptr);
|
2019-03-22 00:54:07 +11:00
|
|
|
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
/* fake button, it holds space for search items */
|
2014-11-09 21:20:40 +01:00
|
|
|
uiDefBut(block,
|
|
|
|
|
UI_BTYPE_LABEL,
|
|
|
|
|
0,
|
|
|
|
|
"",
|
|
|
|
|
10,
|
|
|
|
|
10 - UI_searchbox_size_y(),
|
|
|
|
|
UI_searchbox_size_x(),
|
|
|
|
|
UI_searchbox_size_y(),
|
2021-06-02 17:19:36 +02:00
|
|
|
nullptr,
|
2014-11-09 21:20:40 +01:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
2021-06-02 17:19:36 +02:00
|
|
|
nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-13 16:35:24 +11:00
|
|
|
/* Move it downwards, mouse over button. */
|
2021-06-02 17:19:36 +02:00
|
|
|
std::array<int, 2> bounds_offset = {0, -UI_UNIT_Y};
|
|
|
|
|
UI_block_bounds_set_popup(block, 0.3f * U.widget_unit, bounds_offset.data());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
return block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_find_node_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
UI_popup_block_invoke(C, node_find_menu, op, nullptr);
|
2013-04-01 15:07:22 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_find_node(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Find Node";
|
2020-11-18 16:14:48 -05:00
|
|
|
ot->description = "Search for a node by name and focus and select it";
|
2013-04-01 15:07:22 +00:00
|
|
|
ot->idname = "NODE_OT_find_node";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke = node_find_node_invoke;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
2013-04-01 15:07:22 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
RNA_def_boolean(ot->srna, "prev", false, "Previous", "");
|
2013-04-01 15:07:22 +00:00
|
|
|
}
|
2019-03-08 16:59:48 +11:00
|
|
|
|
|
|
|
|
/** \} */
|
2022-01-20 10:36:56 -06:00
|
|
|
|
2022-01-24 21:15:25 +11:00
|
|
|
} // namespace blender::ed::space_node
|