Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2010-06-17 12:42:15 +0400
committerDalai Felinto <dfelinto@gmail.com>2010-06-17 12:42:15 +0400
commit038e674cddc4d526fe6ab09b1ce94cb5c18c2952 (patch)
tree15e4333f708c9149df41bc1350972f24f8e903cc /source/blender/editors/space_logic/logic_ops.c
parent3d562ddaa9d7f07b505a0a25516f06dde6fadcec (diff)
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.
Diffstat (limited to 'source/blender/editors/space_logic/logic_ops.c')
-rw-r--r--source/blender/editors/space_logic/logic_ops.c93
1 files changed, 47 insertions, 46 deletions
diff --git a/source/blender/editors/space_logic/logic_ops.c b/source/blender/editors/space_logic/logic_ops.c
index 5a7a6ba839d..44cc4066b03 100644
--- a/source/blender/editors/space_logic/logic_ops.c
+++ b/source/blender/editors/space_logic/logic_ops.c
@@ -102,24 +102,32 @@ static int edit_sensor_invoke_properties(bContext *C, wmOperator *op)
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);
+
+ 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);
- if (!*ob)
- return NULL;
+ *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 int edit_controller_invoke_properties(bContext *C, wmOperator *op)
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 @@ static int edit_actuator_invoke_properties(bContext *C, wmOperator *op)
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,13 +254,17 @@ void LOGIC_OT_sensor_remove(wmOperatorType *ot)
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;
- int type= RNA_enum_get(op->ptr, "type");
char name[32];
+ int type= RNA_enum_get(op->ptr, "type");
+
+ 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 @@ void LOGIC_OT_sensor_add(wmOperatorType *ot)
/* 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 @@ static int controller_remove_exec(bContext *C, wmOperator *op)
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 @@ void LOGIC_OT_controller_remove(wmOperatorType *ot)
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 @@ static int controller_add_exec(bContext *C, wmOperator *op)
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 @@ void LOGIC_OT_controller_add(wmOperatorType *ot)
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 @@ void LOGIC_OT_actuator_remove(wmOperatorType *ot)
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 @@ void LOGIC_OT_actuator_add(wmOperatorType *ot)
/* 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)