[Bf-blender-cvs] [4bb331d] master: RNA API: reuse property lookups

Campbell Barton noreply at git.blender.org
Tue Feb 17 03:15:43 CET 2015


Commit: 4bb331dfd5f3d9a42140e8f12bb917c525eeb529
Author: Campbell Barton
Date:   Tue Feb 17 13:09:21 2015 +1100
Branches: master
https://developer.blender.org/rB4bb331dfd5f3d9a42140e8f12bb917c525eeb529

RNA API: reuse property lookups

===================================================================

M	source/blender/editors/object/object_add.c
M	source/blender/editors/render/render_shading.c
M	source/blender/editors/space_buttons/buttons_ops.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/transform/transform.c
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/windowmanager/intern/wm_operators.c

===================================================================

diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 1180c08..e73b724 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -297,18 +297,19 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
 {
 	View3D *v3d = CTX_wm_view3d(C);
 	unsigned int _layer;
+	PropertyRNA *prop;
 
-	/* Switch to Edit mode? */
-	if (RNA_struct_find_property(op->ptr, "enter_editmode")) { /* optional */
+	/* Switch to Edit mode? optional prop */
+	if ((prop = RNA_struct_find_property(op->ptr, "enter_editmode"))) {
 		bool _enter_editmode;
 		if (!enter_editmode)
 			enter_editmode = &_enter_editmode;
 
-		if (RNA_struct_property_is_set(op->ptr, "enter_editmode") && enter_editmode)
-			*enter_editmode = RNA_boolean_get(op->ptr, "enter_editmode");
+		if (RNA_property_is_set(op->ptr, prop) && enter_editmode)
+			*enter_editmode = RNA_property_boolean_get(op->ptr, prop);
 		else {
 			*enter_editmode = (U.flag & USER_ADD_EDITMODE) != 0;
-			RNA_boolean_set(op->ptr, "enter_editmode", *enter_editmode);
+			RNA_property_boolean_set(op->ptr, prop, *enter_editmode);
 		}
 	}
 
@@ -318,8 +319,9 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
 		if (!layer)
 			layer = &_layer;
 
-		if (RNA_struct_property_is_set(op->ptr, "layers")) {
-			RNA_boolean_get_array(op->ptr, "layers", layer_values);
+		prop = RNA_struct_find_property(op->ptr, "layers");
+		if (RNA_property_is_set(op->ptr, prop)) {
+			RNA_property_boolean_get_array(op->ptr, prop, layer_values);
 			*layer = 0;
 			for (a = 0; a < 20; a++) {
 				if (layer_values[a])
@@ -332,7 +334,7 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
 			for (a = 0; a < 20; a++) {
 				layer_values[a] = *layer & (1 << a);
 			}
-			RNA_boolean_set_array(op->ptr, "layers", layer_values);
+			RNA_property_boolean_set_array(op->ptr, prop, layer_values);
 		}
 
 		/* in local view we additionally add local view layers,
diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c
index 94a3def..ff90f48 100644
--- a/source/blender/editors/render/render_shading.c
+++ b/source/blender/editors/render/render_shading.c
@@ -1386,11 +1386,15 @@ void TEXTURE_OT_slot_move(wmOperatorType *ot)
 
 static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *path, const char imtype)
 {
+	PropertyRNA *prop;
 	float layout[12];
-	if (RNA_struct_find_property(op->ptr, "layout") )
-		RNA_float_get_array(op->ptr, "layout", layout);
-	else
+
+	if ((prop = RNA_struct_find_property(op->ptr, "layout"))) {
+		RNA_property_float_get_array(op->ptr, prop, layout);
+	}
+	else {
 		memcpy(layout, default_envmap_layout, sizeof(layout));
+	}
 
 	if (RE_WriteEnvmapResult(op->reports, scene, env, path, imtype, layout)) {
 		return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c
index 0b643cd..ba0c22a 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -205,6 +205,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 		return OPERATOR_CANCELLED;
 	}
 	else {
+		PropertyRNA *prop_relpath;
 		const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
 		fbo = MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
 		fbo->ptr = ptr;
@@ -216,10 +217,10 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 		/* normally ED_fileselect_get_params would handle this but we need to because of stupid
 		 * user-prefs exception - campbell */
-		if (RNA_struct_find_property(op->ptr, "relative_path")) {
-			if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
+		if ((prop_relpath = RNA_struct_find_property(op->ptr, "relative_path"))) {
+			if (!RNA_property_is_set(op->ptr, prop_relpath)) {
 				/* annoying exception!, if were dealing with the user prefs, default relative to be off */
-				RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS && (ptr.data != &U));
+				RNA_property_boolean_set(op->ptr, prop_relpath, U.flag & USER_RELPATHS && (ptr.data != &U));
 			}
 		}
 		WM_event_add_fileselect(C, op);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index fe15863..9e7adaa 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -461,12 +461,13 @@ void FILE_OT_select_all_toggle(wmOperatorType *ot)
 static int bookmark_select_exec(bContext *C, wmOperator *op)
 {
 	SpaceFile *sfile = CTX_wm_space_file(C);
+	PropertyRNA *prop;
 
-	if (RNA_struct_find_property(op->ptr, "dir")) {
+	if ((prop = RNA_struct_find_property(op->ptr, "dir"))) {
 		char entry[256];
 		FileSelectParams *params = sfile->params;
 
-		RNA_string_get(op->ptr, "dir", entry);
+		RNA_property_string_get(op->ptr, prop, entry);
 		BLI_strncpy(params->dir, entry, sizeof(params->dir));
 		BLI_cleanup_dir(G.main->name, params->dir);
 		ED_file_change_dir(C, true);
@@ -830,57 +831,59 @@ void FILE_OT_cancel(struct wmOperatorType *ot)
 
 void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
 {
+	PropertyRNA *prop;
+
 	BLI_join_dirfile(filepath, FILE_MAX, sfile->params->dir, sfile->params->file); /* XXX, not real length */
-	if (RNA_struct_find_property(op->ptr, "relative_path")) {
-		if (RNA_boolean_get(op->ptr, "relative_path")) {
+
+	if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
+		if (RNA_property_boolean_get(op->ptr, prop)) {
 			BLI_path_rel(filepath, G.main->name);
 		}
 	}
 
-	if (RNA_struct_find_property(op->ptr, "filename")) {
-		RNA_string_set(op->ptr, "filename", sfile->params->file);
+	if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
+		RNA_property_string_set(op->ptr, prop, sfile->params->file);
 	}
-	if (RNA_struct_find_property(op->ptr, "directory")) {
-		RNA_string_set(op->ptr, "directory", sfile->params->dir);
+	if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
+		RNA_property_string_set(op->ptr, prop, sfile->params->dir);
 	}
-	if (RNA_struct_find_property(op->ptr, "filepath")) {
-		RNA_string_set(op->ptr, "filepath", filepath);
+	if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
+		RNA_property_string_set(op->ptr, prop, filepath);
 	}
 	
 	/* some ops have multiple files to select */
 	/* this is called on operators check() so clear collections first since
 	 * they may be already set. */
 	{
-		PointerRNA itemptr;
-		PropertyRNA *prop_files = RNA_struct_find_property(op->ptr, "files");
-		PropertyRNA *prop_dirs = RNA_struct_find_property(op->ptr, "dirs");
 		int i, numfiles = filelist_numfiles(sfile->files);
 
-		if (prop_files) {
+		if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
+			PointerRNA itemptr;
 			int num_files = 0;
-			RNA_property_collection_clear(op->ptr, prop_files);
+			RNA_property_collection_clear(op->ptr, prop);
 			for (i = 0; i < numfiles; i++) {
 				if (filelist_is_selected(sfile->files, i, CHECK_FILES)) {
 					struct direntry *file = filelist_file(sfile->files, i);
-					RNA_property_collection_add(op->ptr, prop_files, &itemptr);
+					RNA_property_collection_add(op->ptr, prop, &itemptr);
 					RNA_string_set(&itemptr, "name", file->relname);
 					num_files++;
 				}
 			}
 			/* make sure the file specified in the filename button is added even if no files selected */
 			if (0 == num_files) {
-				RNA_property_collection_add(op->ptr, prop_files, &itemptr);
+				RNA_property_collection_add(op->ptr, prop, &itemptr);
 				RNA_string_set(&itemptr, "name", sfile->params->file);
 			}
 		}
 
-		if (prop_dirs) {
+		if ((prop = RNA_struct_find_property(op->ptr, "dirs"))) {
+			PointerRNA itemptr;
 			int num_dirs = 0;
-			RNA_property_collection_clear(op->ptr, prop_dirs);
+			RNA_property_collection_clear(op->ptr, prop);
 			for (i = 0; i < numfiles; i++) {
 				if (filelist_is_selected(sfile->files, i, CHECK_DIRS)) {
 					struct direntry *file = filelist_file(sfile->files, i);
-					RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
+					RNA_property_collection_add(op->ptr, prop, &itemptr);
 					RNA_string_set(&itemptr, "name", file->relname);
 					num_dirs++;
 				}
@@ -888,7 +891,7 @@ void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
 			
 			/* make sure the directory specified in the button is added even if no directory selected */
 			if (0 == num_dirs) {
-				RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
+				RNA_property_collection_add(op->ptr, prop, &itemptr);
 				RNA_string_set(&itemptr, "name", sfile->params->dir);
 			}
 		}
@@ -952,8 +955,9 @@ void file_draw_check_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
 bool file_draw_check_exists(SpaceFile *sfile)
 {
 	if (sfile->op) { /* fails on reload */
-		if (RNA_struct_find_property(sfile->op->ptr, "check_existing")) {
-			if (RNA_boolean_get(sfile->op->ptr, "check_existing")) {
+		PropertyRNA *prop;
+		if ((prop = RNA_struct_find_property(sfile->op->ptr, "check_existing"))) {
+			if (RNA_property_boolean_get(sfile->op->ptr, prop)) {
 				char filepath[FILE_MAX];
 				BLI_join_dirfile(filepath, sizeof(filepath), sfile->params->dir, sfile->params->file);
 				if (BLI_is_file(filepath)) {
@@ -1291,6 +1295,7 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
 	char name[FILE_MAXFILE];
 	char path[FILE_MAX];
 	int generate_name = 1;
+	PropertyRNA *prop;
 
 	wmWindowManager *wm = CTX_wm_manager(C);
 	SpaceFile *sfile = CTX_wm_space_file(C);
@@ -1302,8 +1307,8 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
 	
 	path[0] = '\0';
 
-	if (RNA_struct_find_property(op->ptr, "directory")) {
-		RNA_string_get(op->ptr, "directory", path);
+	if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
+		RNA_property_string_get(op->ptr, prop, path);
 		if (path[0] != '\0') generate_name = 0;
 	}
 
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 761249e..3206a0f 1006

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list