[Bf-blender-cvs] [af02159] object_nodes: Added a simple operator and panel for one-click debug display of bvm node visualizations.

Lukas Tönne noreply at git.blender.org
Tue Jan 12 12:38:34 CET 2016


Commit: af0215918e9cfe37b43f34dff9f9268cd3e86155
Author: Lukas Tönne
Date:   Tue Jan 12 12:17:15 2016 +0100
Branches: object_nodes
https://developer.blender.org/rBaf0215918e9cfe37b43f34dff9f9268cd3e86155

Added a simple operator and panel for one-click debug display of bvm node visualizations.

This was formerly part of an addon, but is useful enough to include directly in the branch
for debugging purposes. It uses the existing graphviz dump functions to write into a
temp dot file, then runs graphviz on it and opens the resulting image in the standard
system image viewer.

This is tailored for linux systems, but that shouldn't be a big issue since most developers
(who are the target audience) use this platform anyway.

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

M	release/scripts/nodes/__init__.py
A	release/scripts/nodes/bvm_debug.py

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

diff --git a/release/scripts/nodes/__init__.py b/release/scripts/nodes/__init__.py
index ffb8c65..775a9b0 100644
--- a/release/scripts/nodes/__init__.py
+++ b/release/scripts/nodes/__init__.py
@@ -24,6 +24,7 @@ if "bpy" in locals():
         reload(val)
     del reload
 _modules = [
+    "bvm_debug",
     "common_nodes",
     "group_nodes",
     "forcefield_nodes",
diff --git a/release/scripts/nodes/bvm_debug.py b/release/scripts/nodes/bvm_debug.py
new file mode 100644
index 0000000..c6d1520
--- /dev/null
+++ b/release/scripts/nodes/bvm_debug.py
@@ -0,0 +1,110 @@
+### BEGIN GPL LICENSE BLOCK #####
+#
+#  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.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import os, subprocess
+import bpy
+from bpy.types import Operator, Panel
+from bpy.props import EnumProperty
+
+dotfile = '/tmp/bvm_nodes.dot'
+imgfile = '/tmp/bvm_nodes.svg'
+dotformat = 'svg'
+
+def enum_property_copy(prop):
+    items = [(i.identifier, i.name, i.description, i.icon, i.value) for i in prop.enum_items]
+    return EnumProperty(name=prop.name,
+                        description=prop.description,
+                        default=prop.default,
+                        items=items)
+
+class BVMNodeGraphvizOperator(Operator):
+    bl_idname = "node.bvm_graphviz_show"
+    bl_label = "Show Debug Graphviz Nodes"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    function_type = enum_property_copy(bpy.types.NodeTree.bl_rna.functions['bvm_debug_graphviz'].parameters['function_type'])
+    debug_mode = enum_property_copy(bpy.types.NodeTree.bl_rna.functions['bvm_debug_graphviz'].parameters['debug_mode'])
+
+    def execute(self, context):
+        if hasattr(context, "debug_nodetree"):
+            ntree = context.debug_nodetree
+            ntree.bvm_debug_graphviz(dotfile, self.function_type, self.debug_mode, label=ntree.name)
+        else:
+            return {'CANCELLED'}
+        
+        process = subprocess.Popen(['dot', '-T'+dotformat, '-o', imgfile, dotfile])
+        process.wait()
+        
+        subprocess.Popen(['xdg-open', imgfile])
+        
+        return {'FINISHED'}
+
+def draw_depshow_op(layout, ntree):
+    if isinstance(ntree, bpy.types.GeometryNodeTree):
+        funtype = 'GEOMETRY'
+    elif isinstance(ntree, bpy.types.InstancingNodeTree):
+        funtype = 'INSTANCING'
+    elif isinstance(ntree, bpy.types.TextureNodeTree):
+        funtype = 'TEXTURE'
+    elif isinstance(ntree, bpy.types.ForceFieldNodeTree):
+        funtype = 'FORCEFIELD'
+    else:
+        return
+
+    layout.context_pointer_set("debug_nodetree", ntree)
+
+    col = layout.column(align=True)
+    props = col.operator(BVMNodeGraphvizOperator.bl_idname, text="Nodes")
+    props.function_type = funtype
+    props.debug_mode = 'NODES'
+    props = col.operator(BVMNodeGraphvizOperator.bl_idname, text="Nodes (unoptimized)")
+    props.function_type = funtype
+    props.debug_mode = 'NODES_UNOPTIMIZED'
+    props = col.operator(BVMNodeGraphvizOperator.bl_idname, text="Code")
+    props.function_type = funtype
+    props.debug_mode = 'CODEGEN'
+
+class BVMNodeGraphvizPanel(Panel):
+    bl_idname = "node.bvm_graphviz_panel"
+    bl_label = "Debug Nodes"
+    bl_space_type = 'NODE_EDITOR'
+    bl_region_type = 'UI'
+
+    @classmethod
+    def poll(cls, context):
+        # XXX should use a bpy.app.debug_*** option to enable this
+
+        if context.space_data.edit_tree is None:
+            return False
+        return True
+
+    def draw(self, context):
+        space = context.space_data
+        ntree = space.edit_tree
+        layout = self.layout
+        draw_depshow_op(layout, ntree)
+
+def register():
+    bpy.utils.register_class(BVMNodeGraphvizOperator)
+    bpy.utils.register_class(BVMNodeGraphvizPanel)
+
+def unregister():
+    bpy.utils.unregister_class(BVMNodeGraphvizPanel)
+    bpy.utils.unregister_class(BVMNodeGraphvizOperator)




More information about the Bf-blender-cvs mailing list