[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27366] trunk/blender/source/blender: added relative path option for image load and save, relative path option from the userprefs wasnt being used.

Campbell Barton ideasman42 at gmail.com
Tue Mar 9 17:57:25 CET 2010


Revision: 27366
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27366
Author:   campbellbarton
Date:     2010-03-09 17:57:24 +0100 (Tue, 09 Mar 2010)

Log Message:
-----------
added relative path option for image load and save, relative path option from the userprefs wasnt being used.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_file/file_ops.c
    trunk/blender/source/blender/editors/space_image/image_ops.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/editors/space_file/file_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_ops.c	2010-03-09 16:54:25 UTC (rev 27365)
+++ trunk/blender/source/blender/editors/space_file/file_ops.c	2010-03-09 16:57:24 UTC (rev 27366)
@@ -590,8 +590,8 @@
 		RNA_string_set(op->ptr, "directory", name);
 		strcat(name, sfile->params->file); // XXX unsafe
 
-		if(RNA_struct_find_property(op->ptr, "relative_paths"))
-			if(RNA_boolean_get(op->ptr, "relative_paths"))
+		if(RNA_struct_find_property(op->ptr, "relative_path"))
+			if(RNA_boolean_get(op->ptr, "relative_path"))
 				BLI_makestringcode(G.sce, name);
 
 		RNA_string_set(op->ptr, "path", name);

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2010-03-09 16:54:25 UTC (rev 27365)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2010-03-09 16:57:24 UTC (rev 27366)
@@ -719,6 +719,9 @@
 	SpaceImage *sima= CTX_wm_space_image(C);
 	char *path= (sima && sima->image)? sima->image->name: U.textudir;
 
+	if(!RNA_property_is_set(op->ptr, "relative_path"))
+		RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
 	if(RNA_property_is_set(op->ptr, "path"))
 		return open_exec(C, op);
 	
@@ -745,6 +748,8 @@
 
 	/* properties */
 	WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE);
+
+	RNA_def_boolean(ot->srna, "relative_path", 0, "Relative Path", "Load image with relative path to current .blend file");
 }
 
 /******************** replace image operator ********************/
@@ -804,19 +809,18 @@
 
 /* assumes name is FILE_MAX */
 /* ima->name and ibuf->name should end up the same */
-static void save_image_doit(bContext *C, SpaceImage *sima, Scene *scene, wmOperator *op, char *name)
+static void save_image_doit(bContext *C, SpaceImage *sima, Scene *scene, wmOperator *op, char *path)
 {
 	Image *ima= ED_space_image(sima);
 	void *lock;
 	ImBuf *ibuf= ED_space_image_acquire_buffer(sima, &lock);
-	int len;
 
-	if (ibuf) {	
-		BLI_convertstringcode(name, G.sce);
-		BLI_convertstringframe(name, scene->r.cfra, 0);
+	if (ibuf) {
+		int relative= RNA_boolean_get(op->ptr, "relative_path");
+		BLI_convertstringcode(path, G.sce);
 		
 		if(scene->r.scemode & R_EXTENSION)  {
-			BKE_add_image_extension(name, sima->imtypenr);
+			BKE_add_image_extension(path, sima->imtypenr);
 		}
 		
 		/* enforce user setting for RGB or RGBA, but skip BW */
@@ -830,11 +834,14 @@
 		if(sima->imtypenr==R_MULTILAYER) {
 			RenderResult *rr= BKE_image_acquire_renderresult(scene, ima);
 			if(rr) {
-				RE_WriteRenderResult(rr, name, scene->r.quality);
+				RE_WriteRenderResult(rr, path, scene->r.quality);
+
+				if(relative)
+					BLI_makestringcode(G.sce, path); /* only after saving */
+
+				BLI_strncpy(ima->name, path, sizeof(ima->name));
+				BLI_strncpy(ibuf->name, path, sizeof(ibuf->name));
 				
-				BLI_strncpy(ima->name, name, sizeof(ima->name));
-				BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
-				
 				/* should be function? nevertheless, saving only happens here */
 				for(ibuf= ima->ibufs.first; ibuf; ibuf= ibuf->next)
 					ibuf->userflags &= ~IB_BITMAPDIRTY;
@@ -844,9 +851,14 @@
 				BKE_report(op->reports, RPT_ERROR, "Did not write, no Multilayer Image");
 			BKE_image_release_renderresult(scene, ima);
 		}
-		else if (BKE_write_ibuf(scene, ibuf, name, sima->imtypenr, scene->r.subimtype, scene->r.quality)) {
-			BLI_strncpy(ima->name, name, sizeof(ima->name));
-			BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
+		else if (BKE_write_ibuf(scene, ibuf, path, sima->imtypenr, scene->r.subimtype, scene->r.quality)) {
+			char *name;
+
+			if(relative)
+				BLI_makestringcode(G.sce, path); /* only after saving */
+
+			BLI_strncpy(ima->name, path, sizeof(ima->name));
+			BLI_strncpy(ibuf->name, path, sizeof(ibuf->name));
 			
 			ibuf->userflags &= ~IB_BITMAPDIRTY;
 			
@@ -871,13 +883,13 @@
 				ima->type= IMA_TYPE_IMAGE;
 			}
 			
+			name = BLI_last_slash(path);
+
 			/* name image as how we saved it */
-			len= strlen(name);
-			while (len > 0 && name[len - 1] != '/' && name[len - 1] != '\\') len--;
-			rename_id(&ima->id, name+len);
+			rename_id(&ima->id, name ? name + 1 : path);
 		} 
 		else
-			BKE_reportf(op->reports, RPT_ERROR, "Couldn't write image: %s", name);
+			BKE_reportf(op->reports, RPT_ERROR, "Couldn't write image: %s", path);
 
 		WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, sima->image);
 
@@ -913,6 +925,9 @@
 	ImBuf *ibuf;
 	void *lock;
 
+	if(!RNA_property_is_set(op->ptr, "relative_path"))
+		RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
 	if(RNA_property_is_set(op->ptr, "path"))
 		return save_as_exec(C, op);
 	
@@ -928,6 +943,8 @@
 			sima->imtypenr= R_MULTILAYER;
 		else if(ima->type==IMA_TYPE_R_RESULT)
 			sima->imtypenr= scene->r.imtype;
+		else if (ima->source == IMA_SRC_GENERATED)
+			sima->imtypenr= R_PNG;
 		else
 			sima->imtypenr= BKE_ftype_to_imtype(ibuf->ftype);
 
@@ -966,6 +983,8 @@
 	/* properties */
 	RNA_def_enum(ot->srna, "file_type", image_file_type_items, R_PNG, "File Type", "File type to save image as.");
 	WM_operator_properties_filesel(ot, FOLDERFILE|IMAGEFILE|MOVIEFILE, FILE_SPECIAL, FILE_SAVE);
+
+	RNA_def_boolean(ot->srna, "relative_path", 0, "Relative Path", "Save image with relative path to current .blend file");
 }
 
 /******************** save image operator ********************/

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2010-03-09 16:54:25 UTC (rev 27365)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2010-03-09 16:57:24 UTC (rev 27366)
@@ -1390,6 +1390,9 @@
 
 static int wm_link_append_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+	if(!RNA_property_is_set(op->ptr, "relative_path"))
+		RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
 	if(RNA_property_is_set(op->ptr, "path")) {
 		return WM_operator_call(C, op);
 	} 
@@ -1407,7 +1410,7 @@
 
 	if(RNA_boolean_get(op->ptr, "autoselect")) flag |= FILE_AUTOSELECT;
 	if(RNA_boolean_get(op->ptr, "active_layer")) flag |= FILE_ACTIVELAY;
-	if(RNA_boolean_get(op->ptr, "relative_paths")) flag |= FILE_STRINGCODE;
+	if(RNA_boolean_get(op->ptr, "relative_path")) flag |= FILE_STRINGCODE;
 	if(RNA_boolean_get(op->ptr, "link")) flag |= FILE_LINK;
 	if(RNA_boolean_get(op->ptr, "instance_groups")) flag |= FILE_GROUP_INSTANCE;
 	return flag;
@@ -1545,7 +1548,7 @@
 	RNA_def_boolean(ot->srna, "autoselect", 1, "Select", "Select the linked objects");
 	RNA_def_boolean(ot->srna, "active_layer", 1, "Active Layer", "Put the linked objects on the active layer");
 	RNA_def_boolean(ot->srna, "instance_groups", 1, "Instance Groups", "Create instances for each group as a DupliGroup");
-	RNA_def_boolean(ot->srna, "relative_paths", 1, "Relative Paths", "Store the library path as a relative path to current .blend file");
+	RNA_def_boolean(ot->srna, "relative_path", 1, "Relative Paths", "Store the library path as a relative path to current .blend file");
 
 	RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
 }	





More information about the Bf-blender-cvs mailing list