Files
test2/source/blender/blenkernel/intern/node_ui_storage.cc
Hans Goudey 461d4fc1aa Geometry Nodes: Node error messages
This patch adds icons to the right side of nodes when they encounter a
a problem. When hovered, a tooltip displays describing the encountered
while evaluating the node.

Some examples are: attribute doesn't exist, mesh has no faces,
incorrect attribute type, etc. Exposing more messages to the system
will be an ongoing process. Multiple warnings per node are supported.

The system is implemented somewhat generically so that the basic
structure can also be used to store more information from evaluation
for the interface, like a list of available attributes.

Currently the messages are just button tooltips. They could be styled
differently in the future. Another limitation is that every instance of
a node group in a parent node tree will have the same error messages,
the "evaluation context" used to decide when to display the tooltips
must be extended to support node tree paths.

Differential Revision: https://developer.blender.org/D10290
2021-02-16 17:15:08 -06:00

105 lines
3.4 KiB
C++

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "CLG_log.h"
#include "BLI_map.hh"
#include "BLI_string_ref.hh"
#include "BLI_vector.hh"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "BKE_node_ui_storage.hh"
static CLG_LogRef LOG = {"bke.node_ui_storage"};
using blender::Map;
using blender::StringRef;
using blender::Vector;
void BKE_nodetree_ui_storage_ensure(bNodeTree &ntree)
{
if (ntree.ui_storage == nullptr) {
ntree.ui_storage = new NodeTreeUIStorage();
}
}
/**
* Removes only the UI data associated with a particular evaluation context. The same node tree
* can be used for execution in multiple places, but the entire UI storage can't be removed when
* one execution starts, or all of the data associated with the node tree would be lost.
*/
void BKE_nodetree_ui_storage_free_for_context(bNodeTree &ntree,
const NodeTreeEvaluationContext &context)
{
NodeTreeUIStorage *ui_storage = ntree.ui_storage;
if (ui_storage != nullptr) {
ui_storage->context_map.remove(context);
}
}
static void node_error_message_log(bNodeTree &ntree,
const bNode &node,
const StringRef message,
const NodeWarningType type)
{
switch (type) {
case NodeWarningType::Error:
CLOG_ERROR(&LOG,
"Node Tree: \"%s\", Node: \"%s\", %s",
ntree.id.name + 2,
node.name,
message.data());
break;
case NodeWarningType::Warning:
CLOG_WARN(&LOG,
"Node Tree: \"%s\", Node: \"%s\", %s",
ntree.id.name + 2,
node.name,
message.data());
break;
case NodeWarningType::Info:
CLOG_INFO(&LOG,
2,
"Node Tree: \"%s\", Node: \"%s\", %s",
ntree.id.name + 2,
node.name,
message.data());
break;
}
}
void BKE_nodetree_error_message_add(bNodeTree &ntree,
const NodeTreeEvaluationContext &context,
const bNode &node,
const NodeWarningType type,
std::string message)
{
BLI_assert(ntree.ui_storage != nullptr);
NodeTreeUIStorage &ui_storage = *ntree.ui_storage;
node_error_message_log(ntree, node, message, type);
Map<std::string, NodeUIStorage> &node_tree_ui_storage =
ui_storage.context_map.lookup_or_add_default(context);
NodeUIStorage &node_ui_storage = node_tree_ui_storage.lookup_or_add_default_as(
StringRef(node.name));
node_ui_storage.warnings.append({type, std::move(message)});
}