[Bf-blender-cvs] [925b0b732cc] functions: show problems in separate problems panel

Jacques Lucke noreply at git.blender.org
Wed Mar 27 12:19:05 CET 2019


Commit: 925b0b732ccfc9fe88d9f69a31acd7b9760d3511
Author: Jacques Lucke
Date:   Wed Mar 27 11:36:26 2019 +0100
Branches: functions
https://developer.blender.org/rB925b0b732ccfc9fe88d9f69a31acd7b9760d3511

show problems in separate problems panel

===================================================================

M	release/scripts/startup/function_nodes/base.py
M	release/scripts/startup/function_nodes/node_operators.py
A	release/scripts/startup/function_nodes/problems.py
M	release/scripts/startup/function_nodes/tree_panel.py
A	release/scripts/startup/function_nodes/ui.py
M	source/blender/functions/CMakeLists.txt
M	source/blender/functions/frontends/data_flow_nodes/builder.cpp
M	source/blender/functions/functions/lists.cpp

===================================================================

diff --git a/release/scripts/startup/function_nodes/base.py b/release/scripts/startup/function_nodes/base.py
index d2f552f9dae..5b02bfa1cb6 100644
--- a/release/scripts/startup/function_nodes/base.py
+++ b/release/scripts/startup/function_nodes/base.py
@@ -71,8 +71,6 @@ class BaseNode:
     search_terms = tuple()
     search_terms_only = False
 
-    warning_msg: StringProperty(default="")
-
     def init(self, context):
         from . update import managed_update
         with managed_update():
@@ -145,8 +143,6 @@ class BaseNode:
         return [], []
 
     def draw_buttons(self, context, layout):
-        if self.warning_msg != "":
-            layout.label(text=self.warning_msg)
         self.draw(layout)
         for decl in self.storage.sockets_per_decl.keys():
             decl.draw_node(layout, self)
diff --git a/release/scripts/startup/function_nodes/node_operators.py b/release/scripts/startup/function_nodes/node_operators.py
index 9da4da77eda..27a0461b60d 100644
--- a/release/scripts/startup/function_nodes/node_operators.py
+++ b/release/scripts/startup/function_nodes/node_operators.py
@@ -2,6 +2,12 @@ import bpy
 from bpy.props import *
 from . types import type_infos
 
+def try_find_node(tree_name, node_name):
+    tree = bpy.data.node_groups.get(tree_name)
+    if tree is not None:
+        return tree.nodes.get(node_name)
+    return None
+
 class NodeOperatorBase:
     tree_name: StringProperty()
     node_name: StringProperty()
@@ -9,11 +15,7 @@ class NodeOperatorBase:
     settings_repr: StringProperty()
 
     def call(self, *args):
-        tree = bpy.data.node_groups.get(self.tree_name)
-        if tree is None:
-            return {'CANCELLED'}
-
-        node = tree.nodes.get(self.node_name)
+        node = try_find_node(self.tree_name, self.node_name)
         if node is None:
             return {'CANCELLED'}
 
@@ -59,3 +61,26 @@ class NodeDataTypeSelector(bpy.types.Operator, NodeOperatorBase):
     def execute(self, context):
         return self.call(self.item)
 
+class MoveViewToNode(bpy.types.Operator):
+    bl_idname = "fn.move_view_to_node"
+    bl_label = "Move View to Node"
+    bl_options = {'INTERNAL'}
+
+    tree_name: StringProperty()
+    node_name: StringProperty()
+
+    def execute(self, context):
+        target_node = try_find_node(self.tree_name, self.node_name)
+        if target_node is None:
+            return {'CANCELLED'}
+
+        tree = target_node.tree
+        context.space_data.node_tree = tree
+        for node in tree.nodes:
+            node.select = False
+
+        target_node.select = True
+        tree.nodes.active = target_node
+
+        bpy.ops.node.view_selected('INVOKE_DEFAULT')
+        return {'FINISHED'}
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/problems.py b/release/scripts/startup/function_nodes/problems.py
new file mode 100644
index 00000000000..b8082877710
--- /dev/null
+++ b/release/scripts/startup/function_nodes/problems.py
@@ -0,0 +1,34 @@
+import bpy
+from bpy.props import *
+from . ui import NodeSidebarPanel
+
+warnings = []
+
+def report_warning(node, msg):
+    warnings.append((node, msg))
+
+class ProblemsPanel(bpy.types.Panel, NodeSidebarPanel):
+    bl_idname = "FN_PT_problems"
+    bl_label = "Problems"
+
+    def draw(self, context):
+        layout = self.layout
+        for i, (node, msg) in enumerate(warnings):
+            row = layout.row(align=True)
+            row.label(text=msg)
+            props = row.operator("fn.move_view_to_node", text="Find")
+            props.tree_name = node.tree.name
+            props.node_name = node.name
+            props = row.operator("fn.remove_warning", text="", icon='X')
+            props.index = i
+
+class RemoveWarning(bpy.types.Operator):
+    bl_idname = "fn.remove_warning"
+    bl_label = "Remove Warning"
+    bl_options = {'INTERNAL'}
+
+    index: IntProperty()
+
+    def execute(self, context):
+        del warnings[self.index]
+        return {'FINISHED'}
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/tree_panel.py b/release/scripts/startup/function_nodes/tree_panel.py
index ce1556920c3..2dd622238f3 100644
--- a/release/scripts/startup/function_nodes/tree_panel.py
+++ b/release/scripts/startup/function_nodes/tree_panel.py
@@ -1,12 +1,10 @@
 import bpy
+from . ui import NodeSidebarPanel
 from . function_tree import FunctionTree
 
-class TreePanel(bpy.types.Panel):
+class TreePanel(bpy.types.Panel, NodeSidebarPanel):
     bl_idname = "FN_PT_tree_panel"
     bl_label = "Functions Tree"
-    bl_space_type = 'NODE_EDITOR'
-    bl_region_type = 'UI'
-    bl_category = "Node"
 
     @classmethod
     def poll(self, context):
diff --git a/release/scripts/startup/function_nodes/ui.py b/release/scripts/startup/function_nodes/ui.py
new file mode 100644
index 00000000000..a5840d99b44
--- /dev/null
+++ b/release/scripts/startup/function_nodes/ui.py
@@ -0,0 +1,6 @@
+import bpy
+
+class NodeSidebarPanel:
+    bl_space_type = 'NODE_EDITOR'
+    bl_region_type = 'UI'
+    bl_category = "Node"
\ No newline at end of file
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 76c0b2d9a54..41b591076f5 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -11,8 +11,16 @@ set(INC
 
 set(INC_SYS
 	${LLVM_INCLUDE_DIRS}
+	${PYTHON_INCLUDE_DIRS}
 )
 
+if(WITH_PYTHON)
+	add_definitions(-DWITH_PYTHON)
+	list(APPEND INC
+		../python
+	)
+endif()
+
 set(SRC
 	FN_all.hpp
 	FN_core.hpp
diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.cpp b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
index 1f2ce335251..84190c9fd6f 100644
--- a/source/blender/functions/frontends/data_flow_nodes/builder.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
@@ -8,6 +8,14 @@
 
 #include <sstream>
 
+#ifdef WITH_PYTHON
+	#include <Python.h>
+
+	extern "C" {
+		PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr);
+	}
+#endif
+
 namespace FN { namespace DataFlowNodes {
 
 	class NodeSource : public SourceInfo {
@@ -29,12 +37,26 @@ namespace FN { namespace DataFlowNodes {
 
 		void handle_warning(std::string msg) const override
 		{
+#ifdef WITH_PYTHON
+			PyGILState_STATE gilstate;
+			gilstate = PyGILState_Ensure();
+
+			PyObject *module = PyImport_ImportModule("function_nodes.problems");
+			PyObject *globals = PyModule_GetDict(module);
+			PyObject *function = PyDict_GetItemString(globals, "report_warning");
+
 			PointerRNA ptr;
 			RNA_pointer_create(
 				&m_btree->id, &RNA_Node,
 				m_bnode, &ptr);
 
-			RNA_string_set(&ptr, "warning_msg", msg.c_str());
+			PyObject *py_bnode = pyrna_struct_CreatePyObject(&ptr);
+
+			PyObject *args = Py_BuildValue("(Os)", py_bnode, msg.c_str());
+			PyObject_CallObject(function, args);
+
+			PyGILState_Release(gilstate);
+#endif
 		}
 	};
 
diff --git a/source/blender/functions/functions/lists.cpp b/source/blender/functions/functions/lists.cpp
index 1286f04f5ff..fb0ab34cfe7 100644
--- a/source/blender/functions/functions/lists.cpp
+++ b/source/blender/functions/functions/lists.cpp
@@ -33,7 +33,7 @@ namespace FN { namespace Functions {
 
 	template<typename T>
 	class AppendToList : public TupleCallBody {
-		void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &ctx) const override
+		void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
 		{
 			auto list = fn_in.relocate_out<SharedList<T>>(0);
 			T value = fn_in.relocate_out<T>(1);



More information about the Bf-blender-cvs mailing list