Node panels: Enable new node group interfaces #1

Closed
Lukas Tönne wants to merge 14 commits from node-panels-final into node-panels-rna

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 47 additions and 9 deletions
Showing only changes of commit 53c0a3ee04 - Show all commits

View File

@ -852,6 +852,10 @@ bNodeTreeInterfacePanel *bNodeTreeInterfacePanel::find_parent_recursive(
void bNodeTreeInterfacePanel::add_item(bNodeTreeInterfaceItem &item) void bNodeTreeInterfacePanel::add_item(bNodeTreeInterfaceItem &item)
{ {
/* Are child panels allowed? */
BLI_assert(item.item_type != NODE_INTERFACE_PANEL ||
(flag & NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS));
blender::MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items(); blender::MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items();
items_num++; items_num++;
items_array = MEM_cnew_array<bNodeTreeInterfaceItem *>(items_num, __func__); items_array = MEM_cnew_array<bNodeTreeInterfaceItem *>(items_num, __func__);
@ -865,6 +869,10 @@ void bNodeTreeInterfacePanel::add_item(bNodeTreeInterfaceItem &item)
void bNodeTreeInterfacePanel::insert_item(bNodeTreeInterfaceItem &item, int position) void bNodeTreeInterfacePanel::insert_item(bNodeTreeInterfaceItem &item, int position)
{ {
/* Are child panels allowed? */
BLI_assert(item.item_type != NODE_INTERFACE_PANEL ||
(flag & NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS));
position = std::min(std::max(position, 0), items_num); position = std::min(std::max(position, 0), items_num);
blender::MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items(); blender::MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items();
@ -1071,6 +1079,8 @@ void bNodeTreeInterfacePanel::copy_from(
/* Copy buffers. */ /* Copy buffers. */
for (const int i : items_src.index_range()) { for (const int i : items_src.index_range()) {
const bNodeTreeInterfaceItem *item_src = items_src[i]; const bNodeTreeInterfaceItem *item_src = items_src[i];
BLI_assert(item_src->item_type != NODE_INTERFACE_PANEL ||
(flag & NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS));
items_array[i] = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(item_src)); items_array[i] = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(item_src));
item_types::item_copy(*items_array[i], *item_src, flag); item_types::item_copy(*items_array[i], *item_src, flag);
} }
@ -1173,8 +1183,7 @@ bNodeTreeInterfaceSocket *bNodeTreeInterface::add_socket(blender::StringRefNull
return new_socket; return new_socket;
} }
bNodeTreeInterfaceSocket *bNodeTreeInterface::insert_socket( bNodeTreeInterfaceSocket *bNodeTreeInterface::insert_socket(blender::StringRefNull name,
blender::StringRefNull name,
blender::StringRefNull description, blender::StringRefNull description,
blender::StringRefNull socket_type, blender::StringRefNull socket_type,
const NodeTreeInterfaceSocketFlag flag, const NodeTreeInterfaceSocketFlag flag,
@ -1204,6 +1213,11 @@ bNodeTreeInterfacePanel *bNodeTreeInterface::add_panel(blender::StringRefNull na
} }
BLI_assert(this->find_item(parent->item)); BLI_assert(this->find_item(parent->item));
if (!(parent->flag & NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS)) {
/* Parent does not allow adding child panels. */
return nullptr;
}
bNodeTreeInterfacePanel *new_panel = make_panel(next_uid++, name, description, flag); bNodeTreeInterfacePanel *new_panel = make_panel(next_uid++, name, description, flag);
if (new_panel) { if (new_panel) {
parent->add_item(new_panel->item); parent->add_item(new_panel->item);
@ -1222,6 +1236,11 @@ bNodeTreeInterfacePanel *bNodeTreeInterface::insert_panel(blender::StringRefNull
} }
BLI_assert(this->find_item(parent->item)); BLI_assert(this->find_item(parent->item));
if (!(parent->flag & NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS)) {
/* Parent does not allow adding child panels. */
return nullptr;
}
bNodeTreeInterfacePanel *new_panel = make_panel(next_uid++, name, description, flag); bNodeTreeInterfacePanel *new_panel = make_panel(next_uid++, name, description, flag);
if (new_panel) { if (new_panel) {
parent->insert_item(new_panel->item, position); parent->insert_item(new_panel->item, position);
@ -1238,8 +1257,11 @@ bNodeTreeInterfaceItem *bNodeTreeInterface::add_item_copy(const bNodeTreeInterfa
BLI_assert(this->find_item(item)); BLI_assert(this->find_item(item));
BLI_assert(this->find_item(parent->item)); BLI_assert(this->find_item(parent->item));
if (parent == nullptr) { if (item.item_type == NODE_INTERFACE_PANEL &&
parent = &root_panel; !(parent->flag & NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS))
{
/* Parent does not allow adding child panels. */
return nullptr;
} }
bNodeTreeInterfaceItem *citem = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(&item)); bNodeTreeInterfaceItem *citem = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(&item));
@ -1259,6 +1281,13 @@ bNodeTreeInterfaceItem *bNodeTreeInterface::insert_item_copy(const bNodeTreeInte
BLI_assert(this->find_item(item)); BLI_assert(this->find_item(item));
BLI_assert(this->find_item(parent->item)); BLI_assert(this->find_item(parent->item));
if (item.item_type == NODE_INTERFACE_PANEL &&
!(parent->flag & NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS))
{
/* Parent does not allow adding child panels. */
return nullptr;
}
bNodeTreeInterfaceItem *citem = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(&item)); bNodeTreeInterfaceItem *citem = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(&item));
item_types::item_copy(*citem, item, 0); item_types::item_copy(*citem, item, 0);
parent->insert_item(*citem, position); parent->insert_item(*citem, position);
@ -1308,6 +1337,12 @@ bool bNodeTreeInterface::move_item_to_parent(bNodeTreeInterfaceItem &item,
if (parent == nullptr) { if (parent == nullptr) {
return false; return false;
} }
if (item.item_type == NODE_INTERFACE_PANEL &&
!(new_parent->flag & NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS))
{
/* Parent does not allow adding child panels. */
return false;
}
if (parent->remove_item(item, false)) { if (parent->remove_item(item, false)) {
new_parent->insert_item(item, new_position); new_parent->insert_item(item, new_position);
return true; return true;

View File

@ -103,7 +103,10 @@ typedef struct bNodeTreeInterfaceSocket {
/* Panel interface flags */ /* Panel interface flags */
typedef enum NodeTreeInterfacePanelFlag { typedef enum NodeTreeInterfacePanelFlag {
/* Panel starts closed on new node instances. */
NODE_INTERFACE_PANEL_DEFAULT_CLOSED = 1 << 0, NODE_INTERFACE_PANEL_DEFAULT_CLOSED = 1 << 0,
/* Allow child panels inside this panel. */
NODE_INTERFACE_PANEL_ALLOW_CHILD_PANELS = 1 << 1,
} NodeTreeInterfacePanelFlag; } NodeTreeInterfacePanelFlag;
ENUM_OPERATORS(NodeTreeInterfacePanelFlag, NODE_INTERFACE_PANEL_DEFAULT_CLOSED); ENUM_OPERATORS(NodeTreeInterfacePanelFlag, NODE_INTERFACE_PANEL_DEFAULT_CLOSED);