Exemple #1
0
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;
}
Exemple #2
0
static int sensor_add_exec(bContext *C, wmOperator *op)
{
	Object *ob;
	bSensor *sens;
	PointerRNA sens_ptr;
	PropertyRNA *prop;
	const char *sens_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;

	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 (*name) {
		BLI_strncpy(sens->name, name, sizeof(sens->name));
	}
	else {
		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));
	}

	BLI_uniquename(&ob->sensors, sens, DATA_("Sensor"), '.', offsetof(bSensor, name), sizeof(sens->name));
	ob->scaflag |= OB_SHOWSENS;

	WM_event_add_notifier(C, NC_LOGIC, NULL);
	
	return OPERATOR_FINISHED;
}