static int controller_add_exec(bContext *C, wmOperator *op) { Object *ob; bController *cont; PointerRNA cont_ptr; PropertyRNA *prop; const char *cont_name; int bit; char name[MAX_NAME]; 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); /* set the controller name based on rna type enum */ RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &cont_ptr); prop = RNA_struct_find_property(&cont_ptr, "type"); RNA_string_get(op->ptr, "name", name); if (*name) { BLI_strncpy(cont->name, name, sizeof(cont->name)); } else { RNA_property_enum_name(C, &cont_ptr, prop, RNA_property_enum_get(&cont_ptr, prop), &cont_name); BLI_strncpy(cont->name, cont_name, sizeof(cont->name)); } make_unique_prop_names(C, cont->name); /* set the controller state mask from the current object state. * A controller is always in a single state, so select the lowest bit set * from the object state */ for (bit = 0; bit < OB_MAX_STATES; bit++) { if (ob->state & (1 << bit)) break; } cont->state_mask = (1 << bit); if (cont->state_mask == 0) { /* shouldn't happen, object state is never 0 */ cont->state_mask = 1; } ob->scaflag |= OB_SHOWCONT; WM_event_add_notifier(C, NC_LOGIC, NULL); return OPERATOR_FINISHED; }
static int actuator_add_exec(bContext *C, wmOperator *op) { Object *ob; bActuator *act; PointerRNA act_ptr; PropertyRNA *prop; const char *act_name; char name[MAX_NAME]; 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); /* set the actuator name based on rna type enum */ RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &act_ptr); prop = RNA_struct_find_property(&act_ptr, "type"); RNA_string_get(op->ptr, "name", name); if (*name) { BLI_strncpy(act->name, name, sizeof(act->name)); } else { RNA_property_enum_name(C, &act_ptr, prop, RNA_property_enum_get(&act_ptr, prop), &act_name); BLI_strncpy(act->name, act_name, sizeof(act->name)); } make_unique_prop_names(C, act->name); ob->scaflag |= OB_SHOWACT; WM_event_add_notifier(C, NC_LOGIC, NULL); return OPERATOR_FINISHED; }
static int sensor_add_exec(bContext *C, wmOperator *op) { Object *ob; bSensor *sens; PointerRNA sens_ptr; PropertyRNA *prop; const char *sens_name; 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); /* set the sensor name based on rna type enum */ RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &sens_ptr); prop = RNA_struct_find_property(&sens_ptr, "type"); RNA_string_get(op->ptr, "name", name); if(BLI_strnlen(name, 32) < 1){ RNA_property_enum_name(C, &sens_ptr, prop, RNA_property_enum_get(&sens_ptr, prop), &sens_name); BLI_strncpy(sens->name, sens_name, sizeof(sens->name)); } else BLI_strncpy(sens->name, name, sizeof(sens->name)); make_unique_prop_names(C, sens->name); ob->scaflag |= OB_SHOWSENS; WM_event_add_notifier(C, NC_LOGIC, NULL); return OPERATOR_FINISHED; }