Exemplo n.º 1
0
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
	ID *id;
	bAction *action;
	FCurve *fcu;
	bool driven;
	bool special;

	fcu = ui_but_get_fcurve(but, NULL, &action, &driven, &special);
	
	if (fcu == NULL)
		return;
	
	if (special) {
		/* NLA Strip property */
		if (IS_AUTOKEY_ON(scene)) {
			ReportList *reports = CTX_wm_reports(C);
			ToolSettings *ts = scene->toolsettings;
			
			insert_keyframe_direct(reports, but->rnapoin, but->rnaprop, fcu, cfra, ts->keyframe_type, 0);
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
	else if (driven) {
		/* Driver - Try to insert keyframe using the driver's input as the frame,
		 * making it easier to set up corrective drivers
		 */
		if (IS_AUTOKEY_ON(scene)) {
			ReportList *reports = CTX_wm_reports(C);
			ToolSettings *ts = scene->toolsettings;
			
			insert_keyframe_direct(reports, but->rnapoin, but->rnaprop, fcu, cfra, ts->keyframe_type, INSERTKEY_DRIVER);
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
	else {
		id = but->rnapoin.id.data;
		
		/* TODO: this should probably respect the keyingset only option for anim */
		if (autokeyframe_cfra_can_key(scene, id)) {
			ReportList *reports = CTX_wm_reports(C);
			ToolSettings *ts = scene->toolsettings;
			short flag = ANIM_get_keyframing_flags(scene, 1);
			
			fcu->flag &= ~FCURVE_SELECTED;
			
			/* Note: We use but->rnaindex instead of fcu->array_index,
			 *       because a button may control all items of an array at once.
			 *       E.g., color wheels (see T42567). */
			BLI_assert((fcu->array_index == but->rnaindex) || (but->rnaindex == -1));
			insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)),
			                fcu->rna_path, but->rnaindex, cfra, ts->keyframe_type, flag);
			
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
}
Exemplo n.º 2
0
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
	ID *id;
	bAction *action;
	FCurve *fcu;
	bool driven;
	bool special;

	fcu = ui_but_get_fcurve(but, NULL, &action, &driven, &special);
	
	if (fcu == NULL)
		return;
	
	if (special) {
		/* NLA Strip property */
		if (IS_AUTOKEY_ON(scene)) {
			ReportList *reports = CTX_wm_reports(C);
			PointerRNA ptr = {{NULL}};
			PropertyRNA *prop = NULL;
			int index;
			
			UI_context_active_but_prop_get(C, &ptr, &prop, &index);
			
			insert_keyframe_direct(reports, ptr, prop, fcu, cfra, 0);
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
	else if (!driven) {
		id = but->rnapoin.id.data;

		/* TODO: this should probably respect the keyingset only option for anim */
		if (autokeyframe_cfra_can_key(scene, id)) {
			ReportList *reports = CTX_wm_reports(C);
			short flag = ANIM_get_keyframing_flags(scene, 1);

			fcu->flag &= ~FCURVE_SELECTED;

			/* Note: We use but->rnaindex instead of fcu->array_index,
			 *       because a button may control all items of an array at once.
			 *       E.g., color wheels (see T42567). */
			BLI_assert((fcu->array_index == but->rnaindex) || (but->rnaindex == -1));
			insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)),
			                fcu->rna_path, but->rnaindex, cfra, flag);

			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
}
Exemplo n.º 3
0
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static int do_mat_livedb_item_rename(bContext *C, ARegion *ar, SpaceLDB *slivedb, LiveDbTreeElement *te, const float mval[2])
{	
    ReportList  *reports;
    int         CUR_UNIT_Y;

    if(TE_GET_TYPE(te->item->type) == MAT_LDB_TREE_ITEM_TYPE_CATEGORY)
        CUR_UNIT_Y = UI_UNIT_Y;
    else
        CUR_UNIT_Y = MAT_LIVEDB_UI_UNIT_Y;

    reports = CTX_wm_reports(C);
    
    if (mval[1] > te->ys && mval[1] < te->ys + CUR_UNIT_Y) {
        /* click on name */
        if (mval[0] > te->xs + UI_UNIT_X * 2 && mval[0] < te->xend) {
            do_item_rename(ar, te, reports);
            return 1;
        }
        return 0;
    }
    for (te = te->subtree.first; te; te = te->next) {
        if (do_mat_livedb_item_rename(C, ar, slivedb, te, mval)) return 1;
    }
    return 0;
} /* do_mat_livedb_item_rename() */
Exemplo n.º 4
0
/**
 * \return success
 */
bool BPY_execute_string_as_number(bContext *C, const char *expr, double *value, const bool verbose)
{
	PyGILState_STATE gilstate;
	bool ok = true;

	if (!value || !expr) return -1;

	if (expr[0] == '\0') {
		*value = 0.0;
		return ok;
	}

	bpy_context_set(C, &gilstate);

	ok = PyC_RunString_AsNumber(expr, value, "<blender button>");

	if (ok == false) {
		if (verbose) {
			BPy_errors_to_report_ex(CTX_wm_reports(C), false, false);
		}
		else {
			PyErr_Clear();
		}
	}

	bpy_context_clear(C, &gilstate);

	return ok;
}
Exemplo n.º 5
0
static int reports_to_text_exec(bContext *C, wmOperator *UNUSED(op))
{
	ReportList *reports = CTX_wm_reports(C);
	Text *txt;
	char *str;
	
	/* create new text-block to write to */
	txt = add_empty_text("Recent Reports");
	
	/* convert entire list to a display string, and add this to the text-block
	 *	- if commandline debug option enabled, show debug reports too
	 *	- otherwise, up to info (which is what users normally see)
	 */
	str = BKE_reports_string(reports, (G.f & G_DEBUG)? RPT_DEBUG : RPT_INFO);

	if (str) {
		write_text(txt, str);
		MEM_freeN(str);

		return OPERATOR_FINISHED;
	}
	else {
		return OPERATOR_CANCELLED;
	}
}
Exemplo n.º 6
0
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
	ID *id;
	bAction *action;
	FCurve *fcu;
	bool driven;

	fcu = ui_but_get_fcurve(but, NULL, &action, &driven);

	if (fcu && !driven) {
		id = but->rnapoin.id.data;

		/* TODO: this should probably respect the keyingset only option for anim */
		if (autokeyframe_cfra_can_key(scene, id)) {
			ReportList *reports = CTX_wm_reports(C);
			short flag = ANIM_get_keyframing_flags(scene, 1);

			fcu->flag &= ~FCURVE_SELECTED;

			/* Note: We use but->rnaindex instead of fcu->array_index,
			 *       because a button may control all items of an array at once.
			 *       E.g., color wheels (see T42567). */
			BLI_assert((fcu->array_index == but->rnaindex) || (but->rnaindex == -1));
			insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)),
			                fcu->rna_path, but->rnaindex, cfra, flag);

			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
}
Exemplo n.º 7
0
static int report_delete_exec(bContext *C, wmOperator *UNUSED(op))
{
	SpaceInfo *sinfo = CTX_wm_space_info(C);
	ReportList *reports = CTX_wm_reports(C);
	int report_mask = info_report_mask(sinfo);


	Report *report, *report_next;

	for (report = reports->list.first; report; ) {

		report_next = report->next;

		if ((report->type & report_mask) && (report->flag & SELECT)) {
			BLI_remlink(&reports->list, report);
			MEM_freeN((void *)report->message);
			MEM_freeN(report);
		}

		report = report_next;
	}

	ED_area_tag_redraw(CTX_wm_area(C));

	return OPERATOR_FINISHED;
}
Exemplo n.º 8
0
/* This function is used to process the necessary updates for */
void ED_armature_enter_posemode(bContext *C, Base *base)
{
	ReportList *reports = CTX_wm_reports(C);
	Object *ob = base->object;
	
	if (ob->id.lib) {
		BKE_report(reports, RPT_WARNING, "Cannot pose libdata");
		return;
	}
	
	switch (ob->type) {
		case OB_ARMATURE:
			ob->restore_mode = ob->mode;
			ob->mode |= OB_MODE_POSE;
			
			WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_POSE, NULL);
			
			break;
		default:
			return;
	}
	
	/* XXX: disabled as this would otherwise cause a nasty loop... */
	//ED_object_toggle_modes(C, ob->mode);
}
Exemplo n.º 9
0
static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
{
	SpaceInfo *sinfo = CTX_wm_space_info(C);
	ReportList *reports = CTX_wm_reports(C);
	int report_mask = info_report_mask(sinfo);

	Report *report;

	DynStr *buf_dyn = BLI_dynstr_new();
	char *buf_str;

	for (report = reports->list.first; report; report = report->next) {
		if ((report->type & report_mask) && (report->flag & SELECT)) {
			BLI_dynstr_append(buf_dyn, report->message);
			BLI_dynstr_append(buf_dyn, "\n");
		}
	}

	buf_str = BLI_dynstr_get_cstring(buf_dyn);
	BLI_dynstr_free(buf_dyn);

	WM_clipboard_text_set(buf_str, 0);

	MEM_freeN(buf_str);
	return OPERATOR_FINISHED;
}
Exemplo n.º 10
0
void wm_file_read_report(bContext *C)
{
	ReportList *reports = NULL;
	Scene *sce;

	for (sce = G.main->scene.first; sce; sce = sce->id.next) {
		if (sce->r.engine[0] &&
		    BLI_findstring(&R_engines, sce->r.engine, offsetof(RenderEngineType, idname)) == NULL)
		{
			if (reports == NULL) {
				reports = CTX_wm_reports(C);
			}

			BKE_reportf(reports, RPT_ERROR,
			            "Engine '%s' not available for scene '%s' "
			            "(an addon may need to be installed or enabled)",
			            sce->r.engine, sce->id.name + 2);
		}
	}

	if (reports) {
		if (!G.background) {
			WM_report_banner_show();
		}
	}
}
Exemplo n.º 11
0
static int report_select_all_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
	SpaceInfo *sinfo = CTX_wm_space_info(C);
	ReportList *reports = CTX_wm_reports(C);
	int report_mask = info_report_mask(sinfo);
	int deselect = 0;

	Report *report;

	for (report = reports->list.last; report; report = report->prev) {
		if ((report->type & report_mask) && (report->flag & SELECT)) {
			deselect = 1;
			break;
		}
	}


	if (deselect) {
		for (report = reports->list.last; report; report = report->prev)
			if (report->type & report_mask)
				report->flag &= ~SELECT;
	}
	else {
		for (report = reports->list.last; report; report = report->prev)
			if (report->type & report_mask)
				report->flag |= SELECT;
	}

	ED_area_tag_redraw(CTX_wm_area(C));

	return OPERATOR_FINISHED;
}
Exemplo n.º 12
0
static void wm_init_reports(bContext *C)
{
	ReportList *reports = CTX_wm_reports(C);

	BLI_assert(!reports || BLI_listbase_is_empty(&reports->list));

	BKE_reports_init(reports, RPT_STORE);
}
Exemplo n.º 13
0
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
void mat_livedb_item_rename_cb(bContext *C, LiveDbTreeElement *te)
{
    ARegion     *ar         = CTX_wm_region(C);
    ReportList  *reports    = CTX_wm_reports(C);

    if(*te->flag & TE_ACTIVE) {
        *te->flag &= ~TE_ACTIVE;
        do_item_rename(ar, te, reports);
    }
} /* mat_livedb_item_rename_cb() */
Exemplo n.º 14
0
static int select_report_pick_exec(bContext *C, wmOperator *op)
{
	int report_index = RNA_int_get(op->ptr, "report_index");
	Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index);

	if (!report)
		return OPERATOR_CANCELLED;

	report->flag ^= SELECT; /* toggle */

	ED_area_tag_redraw(CTX_wm_area(C));

	return OPERATOR_FINISHED;
}
Exemplo n.º 15
0
/* callback to remove the active driver */
static void driver_remove_cb(bContext *C, void *ale_v, void *UNUSED(arg))
{
	bAnimListElem *ale = (bAnimListElem *)ale_v;
	ID *id = ale->id;
	FCurve *fcu = ale->data;
	ReportList *reports = CTX_wm_reports(C);
	
	/* try to get F-Curve that driver lives on, and ID block which has this AnimData */
	if (ELEM(NULL, id, fcu))
		return;
	
	/* call API method to remove this driver  */	
	ANIM_remove_driver(reports, id, fcu->rna_path, fcu->array_index, 0);
}
Exemplo n.º 16
0
static int select_report_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
	SpaceInfo *sinfo = CTX_wm_space_info(C);
	ARegion *ar = CTX_wm_region(C);
	ReportList *reports = CTX_wm_reports(C);
	Report *report;

	/* uses opengl */
	wmSubWindowSet(CTX_wm_window(C), ar->swinid);
	
	report = info_text_pick(sinfo, ar, reports, event->mval[1]);

	RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));

	return select_report_pick_exec(C, op);
}
Exemplo n.º 17
0
static FCurve *rna_Driver_from_existing(AnimData *adt, bContext *C, FCurve *src_driver)
{
	/* verify that we've got a driver to duplicate */
	if (ELEM(NULL, src_driver, src_driver->driver)) {
		BKE_report(CTX_wm_reports(C), RPT_ERROR, "No valid driver data to create copy of");
		return NULL;
	}
	else {
		/* just make a copy of the existing one and add to self */
		FCurve *new_fcu = copy_fcurve(src_driver);
		
		/* XXX: if we impose any ordering on these someday, this will be problematic */
		BLI_addtail(&adt->drivers, new_fcu);
		return new_fcu;
	}
}
Exemplo n.º 18
0
int BPY_string_exec(bContext *C, const char *expr)
{
	PyGILState_STATE gilstate;
	PyObject *main_mod = NULL;
	PyObject *py_dict, *retval;
	int error_ret = 0;
	Main *bmain_back; /* XXX, quick fix for release (Copy Settings crash), needs further investigation */

	if (!expr) return -1;

	if (expr[0] == '\0') {
		return error_ret;
	}

	bpy_context_set(C, &gilstate);

	PyC_MainModule_Backup(&main_mod);

	py_dict = PyC_DefaultNameSpace("<blender string>");

	bmain_back = bpy_import_main_get();
	bpy_import_main_set(CTX_data_main(C));

	retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);

	bpy_import_main_set(bmain_back);

	if (retval == NULL) {
		error_ret = -1;

		BPy_errors_to_report(CTX_wm_reports(C));
	}
	else {
		Py_DECREF(retval);
	}

	PyC_MainModule_Restore(main_mod);

	bpy_context_clear(C, &gilstate);
	
	return error_ret;
}
Exemplo n.º 19
0
static int do_outliner_item_rename(bContext *C, ARegion *ar, SpaceOops *soops, TreeElement *te, const float mval[2])
{	
	ReportList *reports= CTX_wm_reports(C); // XXX
	
	if(mval[1]>te->ys && mval[1]<te->ys+UI_UNIT_Y) {
		TreeStoreElem *tselem= TREESTORE(te);
		
		/* name and first icon */
		if(mval[0]>te->xs+UI_UNIT_X && mval[0]<te->xend) {
			
			do_item_rename(ar, te, tselem, reports) ;
		}
		return 1;
	}
	
	for(te= te->subtree.first; te; te= te->next) {
		if(do_outliner_item_rename(C, ar, soops, te, mval)) return 1;
	}
	return 0;
}
Exemplo n.º 20
0
void ED_editors_init(bContext *C)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	Main *bmain = CTX_data_main(C);
	Scene *sce = CTX_data_scene(C);
	Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL;
	ID *data;

	if (wm->undo_stack == NULL) {
		wm->undo_stack = BKE_undosys_stack_create();
	}

	/* This is called during initialization, so we don't want to store any reports */
	ReportList *reports = CTX_wm_reports(C);
	int reports_flag_prev = reports->flag & ~RPT_STORE;

	SWAP(int, reports->flag, reports_flag_prev);

	/* toggle on modes for objects that were saved with these enabled. for
	 * e.g. linked objects we have to ensure that they are actually the
	 * active object in this scene. */
	for (ob = bmain->object.first; ob; ob = ob->id.next) {
		int mode = ob->mode;

		if (!ELEM(mode, OB_MODE_OBJECT, OB_MODE_POSE)) {
			ob->mode = OB_MODE_OBJECT;
			data = ob->data;

			if (ob == obact && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data)))
				ED_object_mode_toggle(C, mode);
		}
	}

	/* image editor paint mode */
	if (sce) {
		ED_space_image_paint_update(bmain, wm, sce);
	}

	SWAP(int, reports->flag, reports_flag_prev);
}
Exemplo n.º 21
0
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
{
	ID *id;
	bAction *action;
	FCurve *fcu;
	bool driven;

	fcu = ui_but_get_fcurve(but, &action, &driven);

	if (fcu && !driven) {
		id = but->rnapoin.id.data;

		/* TODO: this should probably respect the keyingset only option for anim */
		if (autokeyframe_cfra_can_key(scene, id)) {
			ReportList *reports = CTX_wm_reports(C);
			short flag = ANIM_get_keyframing_flags(scene, 1);

			fcu->flag &= ~FCURVE_SELECTED;
			insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
			WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
		}
	}
}
Exemplo n.º 22
0
static int reports_to_text_poll(bContext *C)
{
	return CTX_wm_reports(C) != NULL;
}
Exemplo n.º 23
0
/* borderselect operator */
static int borderselect_exec(bContext *C, wmOperator *op)
{
	SpaceInfo *sinfo = CTX_wm_space_info(C);
	ARegion *ar = CTX_wm_region(C);
	ReportList *reports = CTX_wm_reports(C);
	int report_mask = info_report_mask(sinfo);
	int extend = RNA_boolean_get(op->ptr, "extend");
	Report *report_min, *report_max, *report;

	//View2D *v2d = UI_view2d_fromcontext(C);


	rcti rect;
	//rctf rectf, rq;
	short selecting = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT);
	//int mval[2];

	WM_operator_properties_border_to_rcti(op, &rect);

#if 0
	mval[0] = rect.xmin;
	mval[1] = rect.ymin;
	UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin);
	mval[0] = rect.xmax;
	mval[1] = rect.ymax;
	UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax);
#endif

	if (!extend) {
		for (report = reports->list.first; report; report = report->next) {

			if ((report->type & report_mask) == 0)
				continue;

			report->flag &= ~SELECT;
		}
	}

	report_min = info_text_pick(sinfo, ar, reports, rect.ymax);
	report_max = info_text_pick(sinfo, ar, reports, rect.ymin);

	/* get the first report if none found */
	if (report_min == NULL) {
		// printf("find_min\n");
		for (report = reports->list.first; report; report = report->next) {
			if (report->type & report_mask) {
				report_min = report;
				break;
			}
		}
	}

	if (report_max == NULL) {
		// printf("find_max\n");
		for (report = reports->list.last; report; report = report->prev) {
			if (report->type & report_mask) {
				report_max = report;
				break;
			}
		}
	}

	if (report_min == NULL || report_max == NULL)
		return OPERATOR_CANCELLED;

	for (report = report_min; (report != report_max->next); report = report->next) {

		if ((report->type & report_mask) == 0)
			continue;

		if (selecting)
			report->flag |= SELECT;
		else
			report->flag &= ~SELECT;
	}

	ED_area_tag_redraw(CTX_wm_area(C));

	return OPERATOR_FINISHED;
}
Exemplo n.º 24
0
void item_rename_cb(bContext *C, Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
{
	ARegion *ar= CTX_wm_region(C);
	ReportList *reports= CTX_wm_reports(C); // XXX
	do_item_rename(ar, te, tselem, reports) ;
}
Exemplo n.º 25
0
/* return -1 on error, else 0 */
int BPY_button_exec(bContext *C, const char *expr, double *value, const short verbose)
{
	PyGILState_STATE gilstate;
	PyObject *py_dict, *mod, *retval;
	int error_ret = 0;
	PyObject *main_mod = NULL;
	
	if (!value || !expr) return -1;

	if (expr[0] == '\0') {
		*value = 0.0;
		return error_ret;
	}

	bpy_context_set(C, &gilstate);

	PyC_MainModule_Backup(&main_mod);

	py_dict = PyC_DefaultNameSpace("<blender button>");

	mod = PyImport_ImportModule("math");
	if (mod) {
		PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - don't overwrite existing values */
		Py_DECREF(mod);
	}
	else { /* highly unlikely but possibly */
		PyErr_Print();
		PyErr_Clear();
	}
	
	retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
	
	if (retval == NULL) {
		error_ret = -1;
	}
	else {
		double val;

		if (PyTuple_Check(retval)) {
			/* Users my have typed in 10km, 2m
			 * add up all values */
			int i;
			val = 0.0;

			for (i = 0; i < PyTuple_GET_SIZE(retval); i++) {
				val += PyFloat_AsDouble(PyTuple_GET_ITEM(retval, i));
			}
		}
		else {
			val = PyFloat_AsDouble(retval);
		}
		Py_DECREF(retval);
		
		if (val == -1 && PyErr_Occurred()) {
			error_ret = -1;
		}
		else if (!finite(val)) {
			*value = 0.0;
		}
		else {
			*value = val;
		}
	}
	
	if (error_ret) {
		if (verbose) {
			BPy_errors_to_report(CTX_wm_reports(C));
		}
		else {
			PyErr_Clear();
		}
	}

	PyC_MainModule_Backup(&main_mod);
	
	bpy_context_clear(C, &gilstate);
	
	return error_ret;
}
Exemplo n.º 26
0
static void unlink_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
                             TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
{
	/* just set action to NULL */
	BKE_animdata_set_action(CTX_wm_reports(C), tsep->id, NULL);
}
Exemplo n.º 27
0
static int do_outliner_operation_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops,
                                       TreeElement *te, const wmEvent *event, const float mval[2])
{
	ReportList *reports = CTX_wm_reports(C); // XXX...
	
	if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
		int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
		TreeStoreElem *tselem = TREESTORE(te);
		
		/* select object that's clicked on and popup context menu */
		if (!(tselem->flag & TSE_SELECTED)) {
			
			if (outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1) )
				outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
			
			tselem->flag |= TSE_SELECTED;
			/* redraw, same as outliner_select function */
			soops->storeflag |= SO_TREESTORE_REDRAW;
			ED_region_tag_redraw(ar);
		}
		
		set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
		
		if (scenelevel) {
			//if (objectlevel || datalevel || idlevel) error("Mixed selection");
			//else pupmenu("Scene Operations%t|Delete");
		}
		else if (objectlevel) {
			WM_operator_name_call(C, "OUTLINER_OT_object_operation", WM_OP_INVOKE_REGION_WIN, NULL);
		}
		else if (idlevel) {
			if (idlevel == -1 || datalevel) {
				BKE_report(reports, RPT_WARNING, "Mixed selection");
			}
			else {
				if (idlevel == ID_GR)
					WM_operator_name_call(C, "OUTLINER_OT_group_operation", WM_OP_INVOKE_REGION_WIN, NULL);
				else
					WM_operator_name_call(C, "OUTLINER_OT_id_operation", WM_OP_INVOKE_REGION_WIN, NULL);
			}
		}
		else if (datalevel) {
			if (datalevel == -1) {
				BKE_report(reports, RPT_WARNING, "Mixed selection");
			}
			else {
				if (datalevel == TSE_ANIM_DATA)
					WM_operator_name_call(C, "OUTLINER_OT_animdata_operation", WM_OP_INVOKE_REGION_WIN, NULL);
				else if (datalevel == TSE_DRIVER_BASE) {
					/* do nothing... no special ops needed yet */
				}
				else if (ELEM3(datalevel, TSE_R_LAYER_BASE, TSE_R_LAYER, TSE_R_PASS)) {
					/*WM_operator_name_call(C, "OUTLINER_OT_renderdata_operation", WM_OP_INVOKE_REGION_WIN, NULL)*/
				}
				else {
					WM_operator_name_call(C, "OUTLINER_OT_data_operation", WM_OP_INVOKE_REGION_WIN, NULL);
				}
			}
		}
		
		return 1;
	}
	
	for (te = te->subtree.first; te; te = te->next) {
		if (do_outliner_operation_event(C, scene, ar, soops, te, event, mval))
			return 1;
	}
	return 0;
}
Exemplo n.º 28
0
static int update_reports_display_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	ReportList *reports = CTX_wm_reports(C);
	Report *report;
	ReportTimerInfo *rti;
	float progress = 0.0, color_progress = 0.0;
	float neutral_col[3] = {0.35, 0.35, 0.35};
	float neutral_gray = 0.6;
	float timeout = 0.0, color_timeout = 0.0;
	int send_note = 0;
	
	/* escape if not our timer */
	if ((reports->reporttimer == NULL) ||
	    (reports->reporttimer != event->customdata) ||
	    ((report = BKE_reports_last_displayable(reports)) == NULL) /* may have been deleted */
	    )
	{
		return OPERATOR_PASS_THROUGH;
	}

	rti = (ReportTimerInfo *)reports->reporttimer->customdata;
	
	timeout = (report->type & RPT_ERROR_ALL) ? ERROR_TIMEOUT : INFO_TIMEOUT;
	color_timeout = (report->type & RPT_ERROR_ALL) ? ERROR_COLOR_TIMEOUT : INFO_COLOR_TIMEOUT;
	
	/* clear the report display after timeout */
	if ((float)reports->reporttimer->duration > timeout) {
		WM_event_remove_timer(wm, NULL, reports->reporttimer);
		reports->reporttimer = NULL;
		
		WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL);
		
		return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH);
	}

	if (rti->widthfac == 0.0f) {
		/* initialize colors based on report type */
		if (report->type & RPT_ERROR_ALL) {
			rti->col[0] = 1.0;
			rti->col[1] = 0.2;
			rti->col[2] = 0.0;
		}
		else if (report->type & RPT_WARNING_ALL) {
			rti->col[0] = 1.0;
			rti->col[1] = 1.0;
			rti->col[2] = 0.0;
		}
		else if (report->type & RPT_INFO_ALL) {
			rti->col[0] = 0.3;
			rti->col[1] = 0.45;
			rti->col[2] = 0.7;
		}
		rti->grayscale = 0.75;
		rti->widthfac = 1.0;
	}
	
	progress = (float)reports->reporttimer->duration / timeout;
	color_progress = (float)reports->reporttimer->duration / color_timeout;
	
	/* save us from too many draws */
	if (color_progress <= 1.0f) {
		send_note = 1;
		
		/* fade colors out sharply according to progress through fade-out duration */
		interp_v3_v3v3(rti->col, rti->col, neutral_col, color_progress);
		rti->grayscale = interpf(neutral_gray, rti->grayscale, color_progress);
	}

	/* collapse report at end of timeout */
	if (progress * timeout > timeout - COLLAPSE_TIMEOUT) {
		rti->widthfac = (progress * timeout - (timeout - COLLAPSE_TIMEOUT)) / COLLAPSE_TIMEOUT;
		rti->widthfac = 1.0f - rti->widthfac;
		send_note = 1;
	}
	
	if (send_note) {
		WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL);
	}
	
	return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH);
}
Exemplo n.º 29
0
static void wm_free_reports(bContext *C)
{
	ReportList *reports = CTX_wm_reports(C);

	BKE_reports_clear(reports);
}
Exemplo n.º 30
0
/* Given a KeyingSet and context info (if required), modify keyframes for the channels specified
 * by the KeyingSet. This takes into account many of the different combinations of using KeyingSets.
 * Returns the number of channels that keyframes were added to
 */
int ANIM_apply_keyingset(bContext *C, ListBase *dsources, bAction *act, KeyingSet *ks, short mode, float cfra)
{
	Scene *scene = CTX_data_scene(C);
	ReportList *reports = CTX_wm_reports(C);
	KS_Path *ksp;
	int kflag = 0, success = 0;
	char *groupname = NULL;
	
	/* sanity checks */
	if (ks == NULL)
		return 0;
	
	/* get flags to use */
	if (mode == MODIFYKEY_MODE_INSERT) {
		/* use KeyingSet's flags as base */
		kflag = ks->keyingflag;
		
		/* suppliment with info from the context */
		kflag |= ANIM_get_keyframing_flags(scene, 1);
	}
	else if (mode == MODIFYKEY_MODE_DELETE)
		kflag = 0;
	
	/* if relative Keying Sets, poll and build up the paths */
	success = ANIM_validate_keyingset(C, dsources, ks);
	
	if (success != 0) {
		/* return error code if failed */
		return success;
	}
	
	/* apply the paths as specified in the KeyingSet now */
	for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
		int arraylen, i;
		short kflag2;
		
		/* skip path if no ID pointer is specified */
		if (ksp->id == NULL) {
			BKE_reportf(reports, RPT_WARNING,
			            "Skipping path in keying set, as it has no ID (KS = '%s', path = '%s[%d]')",
			            ks->name, ksp->rna_path, ksp->array_index);
			continue;
		}
		
		/* since keying settings can be defined on the paths too, extend the path before using it */
		kflag2 = (kflag | ksp->keyingflag);
		
		/* get pointer to name of group to add channels to */
		if (ksp->groupmode == KSP_GROUP_NONE)
			groupname = NULL;
		else if (ksp->groupmode == KSP_GROUP_KSNAME)
			groupname = ks->name;
		else
			groupname = ksp->group;
		
		/* init arraylen and i - arraylen should be greater than i so that
		 * normal non-array entries get keyframed correctly
		 */
		i = ksp->array_index;
		arraylen = i;
		
		/* get length of array if whole array option is enabled */
		if (ksp->flag & KSP_FLAG_WHOLE_ARRAY) {
			PointerRNA id_ptr, ptr;
			PropertyRNA *prop;
			
			RNA_id_pointer_create(ksp->id, &id_ptr);
			if (RNA_path_resolve_property(&id_ptr, ksp->rna_path, &ptr, &prop))
				arraylen = RNA_property_array_length(&ptr, prop);
		}
		
		/* we should do at least one step */
		if (arraylen == i)
			arraylen++;
		
		/* for each possible index, perform operation 
		 *	- assume that arraylen is greater than index
		 */
		for (; i < arraylen; i++) {
			/* action to take depends on mode */
			if (mode == MODIFYKEY_MODE_INSERT)
				success += insert_keyframe(reports, ksp->id, act, groupname, ksp->rna_path, i, cfra, kflag2);
			else if (mode == MODIFYKEY_MODE_DELETE)
				success += delete_keyframe(reports, ksp->id, act, groupname, ksp->rna_path, i, cfra, kflag2);
		}
		
		/* set recalc-flags */
		switch (GS(ksp->id->name)) {
			case ID_OB: /* Object (or Object-Related) Keyframes */
			{
				Object *ob = (Object *)ksp->id;
				
				// XXX: only object transforms?
				DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
				break;
			}
		}
		
		/* send notifiers for updates (this doesn't require context to work!) */
		WM_main_add_notifier(NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
	}
	
	/* return the number of channels successfully affected */
	return success;
}