[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24584] trunk/blender/source/blender: - fcurve modifiers.new()/remove()/active

Campbell Barton ideasman42 at gmail.com
Mon Nov 16 12:11:16 CET 2009


Revision: 24584
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24584
Author:   campbellbarton
Date:     2009-11-16 12:11:16 +0100 (Mon, 16 Nov 2009)

Log Message:
-----------
- fcurve modifiers.new()/remove()/active
- renamed .add() to .new() for rna collection functions since they dont add an existing item.
- remove 'name' as an argument from the new driver target function, better to keep the api minimal and let scripters use the data api for editing values after.
- added some api functions to keep rna api from becoming a mess.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_constraint.h
    trunk/blender/source/blender/blenkernel/BKE_fcurve.h
    trunk/blender/source/blender/blenkernel/intern/constraint.c
    trunk/blender/source/blender/blenkernel/intern/fmodifier.c
    trunk/blender/source/blender/editors/object/object_constraint.c
    trunk/blender/source/blender/makesrna/intern/rna_armature.c
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
    trunk/blender/source/blender/makesrna/intern/rna_group.c
    trunk/blender/source/blender/makesrna/intern/rna_object.c
    trunk/blender/source/blender/makesrna/intern/rna_pose.c
    trunk/blender/source/blender/makesrna/intern/rna_scene.c

Modified: trunk/blender/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_constraint.h	2009-11-16 10:10:29 UTC (rev 24583)
+++ trunk/blender/source/blender/blenkernel/BKE_constraint.h	2009-11-16 11:11:16 UTC (rev 24584)
@@ -105,6 +105,13 @@
 struct bConstraint *add_ob_constraint(struct Object *ob, const char *name, short type);
 struct bConstraint *add_pose_constraint(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type);
 
+struct bConstraint *find_active_constraint(ListBase *constraints);
+void set_active_constraint(ListBase *constraints, struct bConstraint *con);
+
+
+int remove_constraint(ListBase *constraints, struct bConstraint *con);
+int remove_constraint_index(ListBase *constraints, int index);
+
 /* ---------------------------------------------------------------------------- */
 /* Useful macros for testing various common flag combinations */
 

Modified: trunk/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_fcurve.h	2009-11-16 10:10:29 UTC (rev 24583)
+++ trunk/blender/source/blender/blenkernel/BKE_fcurve.h	2009-11-16 11:11:16 UTC (rev 24584)
@@ -130,7 +130,8 @@
 
 struct FModifier *add_fmodifier(ListBase *modifiers, int type);
 void copy_fmodifiers(ListBase *dst, ListBase *src);
-void remove_fmodifier(ListBase *modifiers, struct FModifier *fcm);
+int remove_fmodifier(ListBase *modifiers, struct FModifier *fcm);
+int remove_fmodifier_index(ListBase *modifiers, int index);
 void free_fmodifiers(ListBase *modifiers);
 
 struct FModifier *find_active_fmodifier(ListBase *modifiers);

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2009-11-16 10:10:29 UTC (rev 24583)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2009-11-16 11:11:16 UTC (rev 24584)
@@ -3690,6 +3690,52 @@
 	return add_new_constraint(ob, NULL, name, type);
 }
 
+struct bConstraint *find_active_constraint(ListBase *constraints)
+{
+	bConstraint *con;
+	if (constraints==NULL)
+		return NULL;
+
+	for(con= constraints->first; con; con= con->next) {
+		if(con->flag & CONSTRAINT_ACTIVE)
+			return con;
+	}
+
+	return NULL;
+}
+
+void set_active_constraint(ListBase *constraints, struct bConstraint *con)
+{
+	bConstraint *con_i;
+	for(con_i= constraints->first; con_i; con_i= con_i->next) {
+		if(con_i==con) con->flag |= CONSTRAINT_ACTIVE;
+		else con->flag &= ~CONSTRAINT_ACTIVE;
+	}
+}
+
+int remove_constraint(ListBase *constraints, struct bConstraint *con)
+{
+	if(con) {
+		free_constraint_data(con);
+		BLI_freelinkN(constraints, con);
+		return 1;
+	}
+	else {
+		return 0;
+	}
+}
+
+int remove_constraint_index(ListBase *constraints, int index)
+{
+	bConstraint *con= BLI_findlink(constraints, index);
+	if(con) {
+		return remove_constraint(constraints, con);
+	}
+	else {
+		return 0;
+	}
+}
+
 /* ************************* General Constraints API ************************** */
 /* The functions here are called by various parts of Blender. Very few (should be none if possible)
  * constraint-specific code should occur here.

Modified: trunk/blender/source/blender/blenkernel/intern/fmodifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fmodifier.c	2009-11-16 10:10:29 UTC (rev 24583)
+++ trunk/blender/source/blender/blenkernel/intern/fmodifier.c	2009-11-16 11:11:16 UTC (rev 24584)
@@ -992,13 +992,13 @@
 }
 
 /* Remove and free the given F-Modifier from the given stack  */
-void remove_fmodifier (ListBase *modifiers, FModifier *fcm)
+int remove_fmodifier (ListBase *modifiers, FModifier *fcm)
 {
 	FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
 	
 	/* sanity check */
 	if (fcm == NULL)
-		return;
+		return 0;
 	
 	/* free modifier's special data (stored inside fcm->data) */
 	if (fcm->data) {
@@ -1010,14 +1010,26 @@
 	}
 	
 	/* remove modifier from stack */
-	if (modifiers)
+	if (modifiers) {
 		BLI_freelinkN(modifiers, fcm);
-	else {
+		return 1;
+	} else {
 		// XXX this case can probably be removed some day, as it shouldn't happen...
 		printf("remove_fmodifier() - no modifier stack given \n");
 		MEM_freeN(fcm);
+		return 0;
 	}
 }
+int remove_fmodifier_index (ListBase *modifiers, int index)
+{
+	FModifier *fcm= BLI_findlink(modifiers, index);
+	if(fcm) {
+		return remove_fmodifier(modifiers, fcm);
+	}
+	else {
+		return 0;
+	}
+}
 
 /* Remove all of a given F-Curve's modifiers */
 void free_fmodifiers (ListBase *modifiers)

Modified: trunk/blender/source/blender/editors/object/object_constraint.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_constraint.c	2009-11-16 10:10:29 UTC (rev 24583)
+++ trunk/blender/source/blender/editors/object/object_constraint.c	2009-11-16 11:11:16 UTC (rev 24584)
@@ -101,18 +101,7 @@
 /* single constraint */
 bConstraint *get_active_constraint (Object *ob)
 {
-	ListBase *lb= get_active_constraints(ob);
-
-	if (lb) {
-		bConstraint *con;
-		
-		for (con= lb->first; con; con=con->next) {
-			if (con->flag & CONSTRAINT_ACTIVE)
-				return con;
-		}
-	}
-	
-	return NULL;
+	return find_active_constraint(get_active_constraints(ob));
 }
 /* -------------- Constraint Management (Add New, Remove, Rename) -------------------- */
 /* ------------- PyConstraints ------------------ */
@@ -655,22 +644,12 @@
 
 
 void ED_object_constraint_set_active(Object *ob, bConstraint *con)
-{
-	ListBase *lb;
-	bConstraint *origcon= con;
-	
+{	
 	/* lets be nice and escape if its active already */
 	if(con && (con->flag & CONSTRAINT_ACTIVE))
 		return ;
 	
-	lb= get_active_constraints(ob);
-	if(lb == NULL)
-		return;
-	
-	for(con= lb->first; con; con= con->next) {
-		if(con==origcon) con->flag |= CONSTRAINT_ACTIVE;
-		else con->flag &= ~CONSTRAINT_ACTIVE;
-	}
+	set_active_constraint(get_active_constraints(ob), con);
 }
 
 void ED_object_constraint_update(Object *ob)
@@ -1373,8 +1352,7 @@
 		for (con= pchan->constraints.first; con; con= next) {
 			next= con->next;
 			if (con->type==CONSTRAINT_TYPE_KINEMATIC) {
-				free_constraint_data(con);
-				BLI_freelinkN(&pchan->constraints, con);
+				remove_constraint(&pchan->constraints, con);
 			}
 		}
 		pchan->constflag &= ~(PCHAN_HAS_IK|PCHAN_HAS_TARGET);

Modified: trunk/blender/source/blender/makesrna/intern/rna_armature.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_armature.c	2009-11-16 10:10:29 UTC (rev 24583)
+++ trunk/blender/source/blender/makesrna/intern/rna_armature.c	2009-11-16 11:11:16 UTC (rev 24584)
@@ -633,11 +633,11 @@
 //	FunctionRNA *func;
 //	PropertyRNA *parm;
 
+	RNA_def_property_srna(cprop, "ArmatureBones");
 	srna= RNA_def_struct(brna, "ArmatureBones", NULL);
 	RNA_def_struct_sdna(srna, "bArmature");
 	RNA_def_struct_ui_text(srna, "Armature Bones", "Collection of armature bones.");
 
-	RNA_def_property_srna(cprop, "ArmatureBones");
 
 	prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
 	RNA_def_property_struct_type(prop, "Bone");
@@ -659,12 +659,11 @@
 //	FunctionRNA *func;
 //	PropertyRNA *parm;
 
+	RNA_def_property_srna(cprop, "ArmatureEditBones");
 	srna= RNA_def_struct(brna, "ArmatureEditBones", NULL);
 	RNA_def_struct_sdna(srna, "bArmature");
 	RNA_def_struct_ui_text(srna, "Armature EditBones", "Collection of armature edit bones.");
 
-	RNA_def_property_srna(cprop, "ArmatureEditBones");
-
 	prop= RNA_def_property(srna, "edit_bones", PROP_POINTER, PROP_NONE);
 	RNA_def_property_struct_type(prop, "EditBone");
 	RNA_def_property_pointer_sdna(prop, NULL, "act_edbone");

Modified: trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_fcurve.c	2009-11-16 10:10:29 UTC (rev 24583)
+++ trunk/blender/source/blender/makesrna/intern/rna_fcurve.c	2009-11-16 11:11:16 UTC (rev 24584)
@@ -190,18 +190,9 @@
 		fcu->rna_path= NULL;
 }
 
-DriverTarget *rna_Driver_add_target(ChannelDriver *driver, char *name)
+DriverTarget *rna_Driver_new_target(ChannelDriver *driver)
 {
-	DriverTarget *dtar= driver_add_new_target(driver);
-
-	/* set the name if given */
-	if (name && name[0]) {
-		BLI_strncpy(dtar->name, name, 64);
-		BLI_uniquename(&driver->targets, dtar, "var", '_', offsetof(DriverTarget, name), 64);
-	}
-
-	/* return this target for the users to play with */
-	return dtar;
+	return driver_add_new_target(driver);
 }
 
 void rna_Driver_remove_target(ChannelDriver *driver, DriverTarget *dtar)
@@ -210,9 +201,32 @@
 	driver_free_target(driver, dtar);
 }
 
+
+static PointerRNA rna_FCurve_active_modifier_get(PointerRNA *ptr)
+{
+	FCurve *fcu= (FCurve*)ptr->data;
+	FModifier *fcm= find_active_fmodifier(&fcu->modifiers);
+	return rna_pointer_inherit_refine(ptr, &RNA_FModifier, fcm);
+}
+
+static void rna_FCurve_active_modifier_set(PointerRNA *ptr, PointerRNA value)
+{
+	FCurve *fcu= (FCurve*)ptr->data;
+	set_active_fmodifier(&fcu->modifiers, (FModifier *)value.data);
+}
+
+static FModifier *rna_FCurve_modifiers_new(FCurve *fcu, bContext *C, int type)
+{
+	return add_fmodifier(&fcu->modifiers, type);
+}
+
+static int rna_FCurve_modifiers_remove(FCurve *fcu, bContext *C, int index)
+{
+	return remove_fmodifier_index(&fcu->modifiers, index);
+}
+
 #else
 
-
 static void rna_def_fmodifier_generator(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -623,21 +637,18 @@
 	FunctionRNA *func;
 	PropertyRNA *parm;
 
+	RNA_def_property_srna(cprop, "ChannelDriverTargets");
 	srna= RNA_def_struct(brna, "ChannelDriverTargets", NULL);
 	RNA_def_struct_sdna(srna, "ChannelDriver");
 	RNA_def_struct_ui_text(srna, "ChannelDriver Targets", "Collection of channel driver Targets.");
 
-	RNA_def_property_srna(cprop, "ChannelDriverTargets");
 
-
 	/* add target */
-	func= RNA_def_function(srna, "add", "rna_Driver_add_target");
+	func= RNA_def_function(srna, "new", "rna_Driver_new_target");
 	RNA_def_function_ui_description(func, "Add a new target for the driver.");
 		/* return type */
 	parm= RNA_def_pointer(func, "target", "DriverTarget", "", "Newly created Driver Target.");
 		RNA_def_function_return(func, parm);
-		/* optional name parameter */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list