Patch #8344:
authorJoshua Leung <aligorith@gmail.com>
Sun, 24 Feb 2008 06:38:42 +0000 (06:38 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sun, 24 Feb 2008 06:38:42 +0000 (06:38 +0000)
Submitted by: Thomas Knight (epat)

Parts committed:
1) Fixed a few misspellings in some error strings.
2) Fixed a (theoretical) bug with pyconstraints where a text object could be deleted from python but would remain linked
to the constraint it was assigned to - causing slight UI usage discontinuities!

Not committed yet:
3) Particle system bugfix in this patch has not been committed. Could jahka or brecht check this.

source/blender/python/BPY_extern.h
source/blender/python/BPY_interface.c
source/blender/python/api2_2x/Text.c
source/blender/python/api2_2x/bpy_data.c
source/blender/src/header_text.c

index 8b4760fe25d892e506b02dcc9a4abcf71401e300..c3aef82751d2a3f9a344acb76655b9e31585cb9a 100644 (file)
@@ -79,6 +79,7 @@ extern "C" {
        void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct);
        void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con);
        int BPY_is_pyconstraint(struct Text *text);
+       void BPY_free_pyconstraint_links(struct Text *text);
        
        void BPY_start_python( int argc, char **argv );
        void BPY_end_python( void );
index b1fd48d87e6f10e5dac71bfb7bb726e04187f621..04d99944ee45541e739d6ec717b189a62c0f88ce 100644 (file)
@@ -1261,6 +1261,45 @@ int BPY_is_pyconstraint(Text *text)
        return 0;
 }
 
+/* This function frees links from pyconstraints to a given text-buffer.
+ * Used when a text-buffer is unlinked!
+ */
+void BPY_free_pyconstraint_links(Text *text)
+{
+       Object *ob;
+       bConstraint *con;
+       short update;
+       
+       /*check all pyconstraints*/
+       for (ob=G.main->object.first; ob; ob=ob->id.next) {
+               update = 0;
+               if(ob->type==OB_ARMATURE && ob->pose) {
+                       bPoseChannel *pchan;
+                       for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+                               for (con = pchan->constraints.first; con; con=con->next) {
+                                       if (con->type==CONSTRAINT_TYPE_PYTHON) {
+                                               bPythonConstraint *data = con->data;
+                                               if (data->text==text) data->text = NULL;
+                                               update = 1;
+                                               
+                                       }
+                               }
+                       }
+               }
+               for (con = ob->constraints.first; con; con=con->next) {
+                       if (con->type==CONSTRAINT_TYPE_PYTHON) {
+                               bPythonConstraint *data = con->data;
+                               if (data->text==text) data->text = NULL;
+                               update = 1;
+                       }
+               }
+               
+               if (update) {
+                       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
+               }
+       }
+}
+
 /* This function is called to update PyConstraint data so that it is compatible with the script. 
  * Some of the allocating/freeing of memory for constraint targets occurs here, espcially
  * if the number of targets changes.
index 29c404f72669f07293d7e05b6f507aaca76439ec..6c5772852663d5c6308e78877046cee3b9e6df52 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * $Id: Text.c 11123 2007-06-29 08:59:26Z campbellbarton $
+ * $Id$
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
@@ -289,6 +289,7 @@ static PyObject *M_Text_unlink( PyObject * self, PyObject * args )
                                              "this text was already unlinked!" );
 
        BPY_clear_bad_scriptlinks( text );
+       BPY_free_pyconstraint_links( text );
        free_text_controllers( text );
        unlink_text( text );
 
index 8ad577bd175be005bbed44fffa38c6b9ffc7d549..3fb58146ca9a30c907cf381364055a6cd4ccd043 100644 (file)
@@ -621,7 +621,7 @@ PyObject *LibBlockSeq_unlink(BPy_LibBlockSeq *self, PyObject * value)
                        
                        if (!data)
                                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
-                                               "This Group has been removed alredy" );
+                                               "This Group has been removed already" );
                        
                        /* Run the removal code */
                        free_group(data);
@@ -642,10 +642,11 @@ PyObject *LibBlockSeq_unlink(BPy_LibBlockSeq *self, PyObject * value)
                        
                        if (!data)
                                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
-                                               "This Group has been removed alredy" );
+                                               "This Group has been removed already" );
                        
                        /* Run the removal code */
                        BPY_clear_bad_scriptlinks( data );
+                       BPY_free_pyconstraint_links( data );
                        free_text_controllers( data );
                        unlink_text( data );
                        free_libblock( &G.main->text, data );
index 728edc76a9c95e06c685c215ffbbddccaf4daa53..ac7f4be9ec078d85049301880fbdf3f08df19412 100644 (file)
@@ -140,10 +140,6 @@ void do_text_buttons(unsigned short event)
                
        case B_TEXTDELETE:
                {
-                       Object *obt;
-                       bConstraint *con;
-                       int update;
-                       
                        text= st->text;
                        if (!text) return;
                        
@@ -156,36 +152,8 @@ void do_text_buttons(unsigned short event)
                                pop_space_text(st);
                        }
                        
-                       /*check all pyconstraints*/
-                       for (obt=G.main->object.first; obt; obt=obt->id.next) {
-                               update = 0;
-                               if(obt->type==OB_ARMATURE && obt->pose) {
-                                       bPoseChannel *pchan;
-                                       for(pchan= obt->pose->chanbase.first; pchan; pchan= pchan->next) {
-                                               for (con = pchan->constraints.first; con; con=con->next) {
-                                                       if (con->type==CONSTRAINT_TYPE_PYTHON) {
-                                                               bPythonConstraint *data = con->data;
-                                                               if (data->text==text) data->text = NULL;
-                                                               update = 1;
-                                                               
-                                                       }
-                                               }
-                                       }
-                               }
-                               for (con = obt->constraints.first; con; con=con->next) {
-                                       if (con->type==CONSTRAINT_TYPE_PYTHON) {
-                                               bPythonConstraint *data = con->data;
-                                               if (data->text==text) data->text = NULL;
-                                               update = 1;
-                                       }
-                               }
-                               
-                               if (update) {
-                                       DAG_object_flush_update(G.scene, obt, OB_RECALC_DATA);
-                               }
-                       }
-                       
                        BPY_clear_bad_scriptlinks(text);
+                       BPY_free_pyconstraint_links(text);
                        free_text_controllers(text);
                        
                        unlink_text(text);