[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13573] branches/pynodes/source/blender: = = Pynodes ==

Willian Padovani Germano wpgermano at gmail.com
Tue Feb 5 04:07:42 CET 2008


Revision: 13573
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13573
Author:   ianwill
Date:     2008-02-05 04:07:41 +0100 (Tue, 05 Feb 2008)

Log Message:
-----------
== Pynodes ==

Now pynodes are properly updated (reset) if their script text file is deleted from Blender.

Modified Paths:
--------------
    branches/pynodes/source/blender/blenkernel/BKE_node.h
    branches/pynodes/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c
    branches/pynodes/source/blender/src/drawnode.c
    branches/pynodes/source/blender/src/drawtext.c

Modified: branches/pynodes/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/pynodes/source/blender/blenkernel/BKE_node.h	2008-02-05 02:47:00 UTC (rev 13572)
+++ branches/pynodes/source/blender/blenkernel/BKE_node.h	2008-02-05 03:07:41 UTC (rev 13573)
@@ -150,7 +150,7 @@
 void			nodeRegisterType(struct ListBase *typelist, const struct bNodeType *ntype) ;
 void			nodeUpdateType(struct bNodeTree *ntree, struct bNode* node, struct bNodeType *ntype);
 void			nodeMakeDynamicType(struct bNode *node);
-//wvoid			nodeDynamicParse(struct bNode *node);
+int				nodeDynamicUnlinkText(struct ID *txtid);
 void			nodeFreeNode(struct bNodeTree *ntree, struct bNode *node);
 struct bNode	*nodeCopyNode(struct bNodeTree *ntree, struct bNode *node);
 

Modified: branches/pynodes/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c
===================================================================
--- branches/pynodes/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c	2008-02-05 02:47:00 UTC (rev 13572)
+++ branches/pynodes/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c	2008-02-05 03:07:41 UTC (rev 13573)
@@ -107,9 +107,6 @@
 
 	if (tinfo->name) { MEM_freeN(tinfo->name); }
 
-	//wif (tinfo->pynode) { Py_DECREF((PyObject *)tinfo->pynode); }
-	//wif (tinfo->pydict) { Py_DECREF((PyObject *)tinfo->pydict); }
-
 	MEM_freeN(tinfo);
 }
 
@@ -126,10 +123,7 @@
 static void node_dynamic_update_socket_links(bNode *node, bNodeTree *ntree)
 {
 	if (ntree) {
-		bNode *nd;
-		for (nd= ntree->nodes.first; nd; nd = nd->next) {
-			if (nd == node) nodeVerifyType(ntree, node);
-		}
+		nodeVerifyType(ntree, node);
 	}
 	else {
 		Material *ma;
@@ -173,11 +167,54 @@
 	node->custom1 = BSET(node->custom1, NODE_DYNAMIC_ERROR);
 }
 
+static void node_rem_socklist_links(bNodeTree *ntree, ListBase *lb)
+{
+	bNodeLink *link, *next;
+	bNodeSocket *sock;
+
+	if (!lb) return;
+
+	for (sock= lb->first; sock; sock= sock->next) {
+		for (link= ntree->links.first; link; link= next) {
+			next= link->next;
+			if (link->fromsock==sock || link->tosock==sock) {
+				nodeRemLink(ntree, link);
+			}
+		}
+	}
+}
+
+/* XXX hardcoded for shaders */
+static void node_dynamic_rem_all_links(bNodeType *tinfo)
+{
+	Material *ma;
+	int in, out;
+
+	in = tinfo->inputs ? 1 : 0;
+	out = tinfo->outputs ? 1 : 0;
+
+	for (ma= G.main->mat.first; ma; ma= ma->id.next) {
+		if (ma->nodetree) {
+			bNode *nd;
+			bNodeTree *ntree = ma->nodetree;
+			for (nd= ntree->nodes.first; nd; nd= nd->next) {
+				if (nd->typeinfo == tinfo) {
+					if (in)
+						node_rem_socklist_links(ntree, &nd->inputs);
+					if (out)
+						node_rem_socklist_links(ntree, &nd->outputs);
+				}
+			}
+		}
+	}
+}
+
 /* node_dynamic_reset: clean a pynode, getting rid of all
  * data dynamically created for it.
  * ntree is used only in a special case: for working pynodes
  * that were saved on a .blend but fail for some reason when
- * the file is opened. */
+ * the file is opened. We need it because pynodes are initialized
+ * before G.main. */
 static void node_dynamic_reset(bNode *node, bNodeTree *ntree)
 {
 	bNodeType *tinfo, *tinfo_default;
@@ -186,11 +223,12 @@
 	tinfo = node->typeinfo;
 	tinfo_default = node_dynamic_find_typeinfo(&node_all_shaders, NULL);
 
+	node_dynamic_rem_all_links(tinfo);
 	node_dynamic_free_typeinfo_sockets(tinfo);
 
 	if (!ntree) { node_dynamic_free_sockets(node); }
 
-	node_dynamic_update_socket_links(node, ntree);
+	//wnode_dynamic_update_socket_links(node, ntree);
 	node_dynamic_free_storage_cb(node);
 
 	/* XXX hardcoded for shaders: */
@@ -215,6 +253,30 @@
 	node_dynamic_free_typeinfo(tinfo);
 }
 
+int nodeDynamicUnlinkText(ID *txtid) {
+	Material *ma;
+	int unlinked= 0;
+
+	for (ma= G.main->mat.first; ma; ma= ma->id.next) {
+		if (ma->nodetree) {
+			bNode *nd, *nd2 = NULL;
+			for (nd= ma->nodetree->nodes.first; nd; nd = nd->next) {
+				if ((nd->type == NODE_DYNAMIC) && (nd->id == txtid)) {
+					nd->id = NULL;
+					BLI_strncpy(nd->name, "Dynamic", 8);
+					nd2 = nd; /* so we have a ptr to one of them */
+					unlinked++;
+				}
+			}
+			/* clean uneeded dynamic data from all nodes that shared
+			 * this text: */
+			if (nd2) node_dynamic_reset(nd2, NULL);
+		}
+	}
+
+	return unlinked;
+}
+
 static void node_dynamic_pyerror_print(bNode *node)
 {
 	fprintf(stderr, "\nError in dynamic node script \"%s\":\n", node->name);
@@ -260,29 +322,25 @@
 	while (PyDict_Next( (PyObject *)(nsd->dict), &pos, &key, &value)) {
 		/* look for the node object */
 		if (PyObject_TypeCheck(value, &PyType_Type)==1) {
-			//wBPy_DefinitionMap *outputdef = Node_CreateOutputDefMap(node);
 			BPy_NodeSockets *sockets = Node_CreateSockets(node);
 
 			args = Py_BuildValue("(O)", sockets);
 			/* init it to get the input and output sockets */
 			testinst = PyObject_Call(value, args, NULL);
 
-			//wPy_DECREF(outputdef);
 			Py_DECREF(sockets);
 			Py_DECREF(args);
 
 			if (testinst && PyObject_TypeCheck(testinst, &Node_Type)==1) {
 				InitNode((BPy_Node *)(testinst), node);
-				Py_INCREF(testinst); /* XXX uneeded, right? */
+				//wPy_INCREF(testinst); /* XXX uneeded, right? */
 				nsd->node = testinst;
 				node->typeinfo->execfunc = node_dynamic_exec_cb;
 				is_valid_script = 1;
 
 				/* for NEW, LOADED, REPARSE */
 				if (BNTST(node->custom1, NODE_DYNAMIC_ADDEXIST)) {
-					//wPy_INCREF(dict);
 					node->typeinfo->pydict = dict;
-					//wPy_INCREF(testinst);
 					node->typeinfo->pynode = testinst;
 					node->typeinfo->id = node->id;
 					nodeAddSockets(node, node->typeinfo);

Modified: branches/pynodes/source/blender/src/drawnode.c
===================================================================
--- branches/pynodes/source/blender/src/drawnode.c	2008-02-05 02:47:00 UTC (rev 13572)
+++ branches/pynodes/source/blender/src/drawnode.c	2008-02-05 03:07:41 UTC (rev 13573)
@@ -757,7 +757,6 @@
 	if (block) { 
 		uiBut *bt;
 		SpaceNode *snode= curarea->spacedata.first;
-		//short dx= (short)((butr->xmax-butr->xmin)/3.0f), has_us= (node->id && node->id->us>1);
 		short dy= (short)butr->ymin;
 		int xoff=0;
 
@@ -2521,7 +2520,7 @@
 	uiSetRoundBox(8);
 	uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax-NODE_DY, BASIS_RAD);
 	glDisable(GL_BLEND);
-	
+
 	/* scaling indicator */
 	node_scaling_widget(TH_NODE, snode->aspect, rct->xmax-BASIS_RAD*snode->aspect, rct->ymin, rct->xmax, rct->ymin+BASIS_RAD*snode->aspect);
 

Modified: branches/pynodes/source/blender/src/drawtext.c
===================================================================
--- branches/pynodes/source/blender/src/drawtext.c	2008-02-05 02:47:00 UTC (rev 13572)
+++ branches/pynodes/source/blender/src/drawtext.c	2008-02-05 03:07:41 UTC (rev 13573)
@@ -62,6 +62,7 @@
 #include "BKE_text.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
+#include "BKE_node.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -1180,6 +1181,10 @@
 	if (BPY_check_all_scriptlinks (text)) {
 		allqueue(REDRAWBUTSSCRIPT, 0);
 	}
+	/* equivalently for pynodes: */
+	if (nodeDynamicUnlinkText ((ID*)text)) {
+		allqueue(REDRAWNODE, 0);
+	}
 
 	for (scr= G.main->screen.first; scr; scr= scr->id.next) {
 		for (area= scr->areabase.first; area; area= area->next) {





More information about the Bf-blender-cvs mailing list