[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29518] trunk/blender/source/blender/ editors/space_logic/logic_ops.c: Logics ops: add s/c/ a can now be called with an object parameter (e.g.

Dalai Felinto dfelinto at gmail.com
Thu Jun 17 10:42:15 CEST 2010


Revision: 29518
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29518
Author:   dfelinto
Date:     2010-06-17 10:42:15 +0200 (Thu, 17 Jun 2010)

Log Message:
-----------
Logics ops: add s/c/a can now be called with an object parameter (e.g. bpy.ops.logic.controller_add_exec(name="name", object="non_active_object")
If no parameter is passed it uses the active object.

To do: make logic_window set "active object" in context before calling add s/c/a operator
So far I tried this before uiItemMenuEnumO(row, "LOGIC_OT_controller_add", "type", "Add Controller", 0); :

+RNA_pointer_create((ID *)ob, &RNA_Object, ob, &ob_ptr);
+uiLayoutSetContextPointer(row, "object", &ob_ptr);

Not working though :) (not committed either). to be investigated.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_logic/logic_ops.c

Modified: trunk/blender/source/blender/editors/space_logic/logic_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_logic/logic_ops.c	2010-06-17 07:33:57 UTC (rev 29517)
+++ trunk/blender/source/blender/editors/space_logic/logic_ops.c	2010-06-17 08:42:15 UTC (rev 29518)
@@ -102,25 +102,33 @@
 	return 0;
 }
 
-static bSensor *edit_sensor_property_get(bContext *C, wmOperator *op, Object **ob)
+static Object *edit_object_property_get(bContext *C, wmOperator *op)
 {
-	char sensor_name[32];
 	char ob_name[32];
-	bSensor *sens;
-	
-	RNA_string_get(op->ptr, "sensor", sensor_name);
+	Object *ob;
+
 	RNA_string_get(op->ptr, "object", ob_name);
 
 	/* if ob_name is valid try to find the object with this name
 	otherwise gets the active object */
-	if (ob_name[0] != '\0' )
-		*ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2);
+	if (BLI_strnlen(ob_name, 32) > 0)
+		ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2);
 	else
-		*ob= ED_object_active_context(C);
+		ob= ED_object_active_context(C);
 
-	if (!*ob)
-		return NULL;
+	return ob;
+}
+
+static bSensor *edit_sensor_property_get(bContext *C, wmOperator *op, Object **ob)
+{
+	char sensor_name[32];
+	bSensor *sens;
 	
+	RNA_string_get(op->ptr, "sensor", sensor_name);
+
+	*ob= edit_object_property_get(C, op);
+	if (!*ob) return NULL;
+	
 	sens = BLI_findstring(&((*ob)->sensors), sensor_name, offsetof(bSensor, name));	
 	return sens;
 }
@@ -153,21 +161,12 @@
 static bController *edit_controller_property_get(bContext *C, wmOperator *op, Object **ob)
 {
 	char controller_name[32];
-	char ob_name[32];
 	bController *cont;
 	
 	RNA_string_get(op->ptr, "controller", controller_name);
-	RNA_string_get(op->ptr, "object", ob_name);
 
-	/* if ob_name is valid try to find the object with this name
-	otherwise gets the active object */
-	if (ob_name[0] != '\0' )
-		*ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2);
-	else
-		*ob= ED_object_active_context(C);
-
-	if (!*ob)
-		return NULL;
+	*ob= edit_object_property_get(C, op);
+	if (!*ob) return NULL;
 	
 	cont = BLI_findstring(&((*ob)->controllers), controller_name, offsetof(bController, name));	
 	return cont;
@@ -198,24 +197,15 @@
 	return 0;
 }
 
-static bController *edit_actuator_property_get(bContext *C, wmOperator *op, Object **ob)
+static bActuator *edit_actuator_property_get(bContext *C, wmOperator *op, Object **ob)
 {
 	char actuator_name[32];
-	char ob_name[32];
 	bActuator *act;
 	
 	RNA_string_get(op->ptr, "actuator", actuator_name);
-	RNA_string_get(op->ptr, "object", ob_name);
 
-	/* if ob_name is valid try to find the object with this name
-	otherwise gets the active object */
-	if (ob_name[0] != '\0' )
-		*ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2);
-	else
-		*ob= ED_object_active_context(C);
-
-	if (!*ob)
-		return NULL;
+	*ob= edit_object_property_get(C, op);
+	if (!*ob) return NULL;
 	
 	act = BLI_findstring(&((*ob)->actuators), actuator_name, offsetof(bActuator, name));	
 	return act;
@@ -264,14 +254,18 @@
 
 static int sensor_add_exec(bContext *C, wmOperator *op)
 {
-	Object *ob = ED_object_active_context(C);
+	Object *ob;
 	bSensor *sens;
 	PointerRNA sens_ptr;
 	PropertyRNA *prop;
 	const char *sens_name;
+	char name[32];
 	int type= RNA_enum_get(op->ptr, "type");
-	char name[32];
 
+	ob= edit_object_property_get(C, op);
+	if (!ob)
+		return OPERATOR_CANCELLED;
+
 	sens= new_sensor(type);
 	BLI_addtail(&(ob->sensors), sens);
 	
@@ -315,7 +309,8 @@
 	/* properties */
 	prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, SENS_ALWAYS, "Type", "Type of sensor to add");
 	RNA_def_enum_funcs(prop, rna_Sensor_type_itemf);
-	prop= RNA_def_string(ot->srna, "name", "", 32, "Name", "Name of the Sensor to add");
+	RNA_def_string(ot->srna, "name", "", 32, "Name", "Name of the Sensor to add");
+	RNA_def_string(ot->srna, "object", "", 32, "Object", "Name of the Object to add the Sensor to");
 }
 
 /* ************* Add/Remove Controller Operator ************* */
@@ -337,8 +332,6 @@
 	return OPERATOR_FINISHED;
 }
 
-
-/* commented along with above stuff */
  static int controller_remove_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
 	if (edit_controller_invoke_properties(C, op))
@@ -364,14 +357,18 @@
 
 static int controller_add_exec(bContext *C, wmOperator *op)
 {
-	Object *ob = ED_object_active_context(C);
+	Object *ob;
 	bController *cont;
 	PointerRNA cont_ptr;
 	PropertyRNA *prop;
 	const char *cont_name;
-	int type= RNA_enum_get(op->ptr, "type");
 	int bit;
 	char name[32];
+	int type= RNA_enum_get(op->ptr, "type");
+
+	ob= edit_object_property_get(C, op);
+	if(!ob)
+		return OPERATOR_CANCELLED;
 	
 	cont= new_controller(type);
 	BLI_addtail(&(ob->controllers), cont);
@@ -411,8 +408,6 @@
 
 void LOGIC_OT_controller_add(wmOperatorType *ot)
 {
-	PropertyRNA *prop;
-	
 	/* identifiers */
 	ot->name= "Add Controller";
 	ot->description = "Add a controller to the active object";
@@ -427,8 +422,9 @@
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 	
 	/* properties */
-	prop= RNA_def_enum(ot->srna, "type", controller_type_items, CONT_LOGIC_AND, "Type", "Type of controller to add");
-	prop= RNA_def_string(ot->srna, "name", "", 32, "Name", "Name of the Controller to add");
+	RNA_def_enum(ot->srna, "type", controller_type_items, CONT_LOGIC_AND, "Type", "Type of controller to add");
+	RNA_def_string(ot->srna, "name", "", 32, "Name", "Name of the Controller to add");
+	RNA_def_string(ot->srna, "object", "", 32, "Object", "Name of the Object to add the Controller to");
 }
 
 /* ************* Add/Remove Actuator Operator ************* */
@@ -475,13 +471,17 @@
 
 static int actuator_add_exec(bContext *C, wmOperator *op)
 {
-	Object *ob = ED_object_active_context(C);
+	Object *ob;
 	bActuator *act;
 	PointerRNA act_ptr;
 	PropertyRNA *prop;
 	const char *act_name;
 	char  name[32];
 	int type= RNA_enum_get(op->ptr, "type");
+		
+	ob= edit_object_property_get(C, op);
+	if(!ob)
+		return OPERATOR_CANCELLED;
 
 	act= new_actuator(type);
 	BLI_addtail(&(ob->actuators), act);
@@ -526,7 +526,8 @@
 	/* properties */
 	prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, CONT_LOGIC_AND, "Type", "Type of actuator to add");
 	RNA_def_enum_funcs(prop, rna_Actuator_type_itemf);
-	prop= RNA_def_string(ot->srna, "name", "", 32, "Name", "Name of the Actuator to add");
+	RNA_def_string(ot->srna, "name", "", 32, "Name", "Name of the Actuator to add");
+	RNA_def_string(ot->srna, "object", "", 32, "Object", "Name of the Object to add the Actuator to");
 }
 
 void ED_operatortypes_logic(void)





More information about the Bf-blender-cvs mailing list