Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2008 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * 00022 * Contributor(s): Blender Foundation 00023 * 00024 * ***** END GPL LICENSE BLOCK ***** 00025 */ 00026 00032 #include <string.h> 00033 #include <stdio.h> 00034 00035 #include "DNA_packedFile_types.h" 00036 #include "DNA_space_types.h" 00037 #include "DNA_windowmanager_types.h" 00038 00039 #include "MEM_guardedalloc.h" 00040 00041 #include "BLI_blenlib.h" 00042 #include "BLI_math.h" 00043 #include "BLI_bpath.h" 00044 #include "BLI_utildefines.h" 00045 00046 #include "BKE_context.h" 00047 #include "BKE_global.h" 00048 #include "BKE_image.h" 00049 #include "BKE_main.h" 00050 #include "BKE_packedFile.h" 00051 #include "BKE_report.h" 00052 00053 00054 #include "WM_api.h" 00055 #include "WM_types.h" 00056 00057 00058 #include "UI_interface.h" 00059 #include "UI_resources.h" 00060 00061 #include "IMB_imbuf_types.h" 00062 00063 #include "RNA_access.h" 00064 #include "RNA_define.h" 00065 00066 00067 #include "info_intern.h" 00068 00069 /********************* pack all operator *********************/ 00070 00071 static int pack_all_exec(bContext *C, wmOperator *op) 00072 { 00073 Main *bmain= CTX_data_main(C); 00074 00075 packAll(bmain, op->reports); 00076 G.fileflags |= G_AUTOPACK; 00077 00078 return OPERATOR_FINISHED; 00079 } 00080 00081 static int pack_all_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) 00082 { 00083 Main *bmain= CTX_data_main(C); 00084 Image *ima; 00085 ImBuf *ibuf; 00086 00087 // first check for dirty images 00088 for(ima=bmain->image.first; ima; ima=ima->id.next) { 00089 if(ima->ibufs.first) { /* XXX FIX */ 00090 ibuf= BKE_image_get_ibuf(ima, NULL); 00091 00092 if(ibuf && (ibuf->userflags & IB_BITMAPDIRTY)) 00093 break; 00094 } 00095 } 00096 00097 if(ima) { 00098 uiPupMenuOkee(C, "FILE_OT_pack_all", "Some images are painted on. These changes will be lost. Continue?"); 00099 return OPERATOR_CANCELLED; 00100 } 00101 00102 return pack_all_exec(C, op); 00103 } 00104 00105 void FILE_OT_pack_all(wmOperatorType *ot) 00106 { 00107 /* identifiers */ 00108 ot->name= "Pack All"; 00109 ot->idname= "FILE_OT_pack_all"; 00110 00111 /* api callbacks */ 00112 ot->exec= pack_all_exec; 00113 ot->invoke= pack_all_invoke; 00114 00115 /* flags */ 00116 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00117 } 00118 00119 /********************* unpack all operator *********************/ 00120 00121 static const EnumPropertyItem unpack_all_method_items[] = { 00122 {PF_USE_LOCAL, "USE_LOCAL", 0, "Use files in current directory (create when necessary)", ""}, 00123 {PF_WRITE_LOCAL, "WRITE_LOCAL", 0, "Write files to current directory (overwrite existing files)", ""}, 00124 {PF_USE_ORIGINAL, "USE_ORIGINAL", 0, "Use files in original location (create when necessary)", ""}, 00125 {PF_WRITE_ORIGINAL, "WRITE_ORIGINAL", 0, "Write files to original location (overwrite existing files)", ""}, 00126 {PF_KEEP, "KEEP", 0, "Disable AutoPack, keep all packed files", ""}, 00127 {PF_ASK, "ASK", 0, "Ask for each file", ""}, 00128 {0, NULL, 0, NULL, NULL}}; 00129 00130 static int unpack_all_exec(bContext *C, wmOperator *op) 00131 { 00132 Main *bmain= CTX_data_main(C); 00133 int method= RNA_enum_get(op->ptr, "method"); 00134 00135 if(method != PF_KEEP) unpackAll(bmain, op->reports, method); /* XXX PF_ASK can't work here */ 00136 G.fileflags &= ~G_AUTOPACK; 00137 00138 return OPERATOR_FINISHED; 00139 } 00140 00141 static int unpack_all_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) 00142 { 00143 Main *bmain= CTX_data_main(C); 00144 uiPopupMenu *pup; 00145 uiLayout *layout; 00146 char title[64]; 00147 int count = 0; 00148 00149 count = countPackedFiles(bmain); 00150 00151 if(!count) { 00152 BKE_report(op->reports, RPT_WARNING, "No packed files. Autopack disabled"); 00153 G.fileflags &= ~G_AUTOPACK; 00154 return OPERATOR_CANCELLED; 00155 } 00156 00157 if(count == 1) 00158 strcpy(title, "Unpack 1 file"); 00159 else 00160 BLI_snprintf(title, sizeof(title), "Unpack %d files", count); 00161 00162 pup= uiPupMenuBegin(C, title, ICON_NONE); 00163 layout= uiPupMenuLayout(pup); 00164 00165 uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); 00166 uiItemsEnumO(layout, "FILE_OT_unpack_all", "method"); 00167 00168 uiPupMenuEnd(C, pup); 00169 00170 return OPERATOR_CANCELLED; 00171 } 00172 00173 void FILE_OT_unpack_all(wmOperatorType *ot) 00174 { 00175 /* identifiers */ 00176 ot->name= "Unpack All"; 00177 ot->idname= "FILE_OT_unpack_all"; 00178 00179 /* api callbacks */ 00180 ot->exec= unpack_all_exec; 00181 ot->invoke= unpack_all_invoke; 00182 00183 /* flags */ 00184 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00185 00186 /* properties */ 00187 RNA_def_enum(ot->srna, "method", unpack_all_method_items, PF_USE_LOCAL, "Method", "How to unpack"); 00188 } 00189 00190 /********************* make paths relative operator *********************/ 00191 00192 static int make_paths_relative_exec(bContext *C, wmOperator *op) 00193 { 00194 Main *bmain= CTX_data_main(C); 00195 00196 if(!G.relbase_valid) { 00197 BKE_report(op->reports, RPT_WARNING, "Can't set relative paths with an unsaved blend file"); 00198 return OPERATOR_CANCELLED; 00199 } 00200 00201 makeFilesRelative(bmain, bmain->name, op->reports); 00202 00203 /* redraw everything so any changed paths register */ 00204 WM_main_add_notifier(NC_WINDOW, NULL); 00205 00206 return OPERATOR_FINISHED; 00207 } 00208 00209 void FILE_OT_make_paths_relative(wmOperatorType *ot) 00210 { 00211 /* identifiers */ 00212 ot->name= "Make All Paths Relative"; 00213 ot->idname= "FILE_OT_make_paths_relative"; 00214 00215 /* api callbacks */ 00216 ot->exec= make_paths_relative_exec; 00217 00218 /* flags */ 00219 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00220 } 00221 00222 /********************* make paths absolute operator *********************/ 00223 00224 static int make_paths_absolute_exec(bContext *C, wmOperator *op) 00225 { 00226 Main *bmain= CTX_data_main(C); 00227 00228 if(!G.relbase_valid) { 00229 BKE_report(op->reports, RPT_WARNING, "Can't set absolute paths with an unsaved blend file"); 00230 return OPERATOR_CANCELLED; 00231 } 00232 00233 makeFilesAbsolute(bmain, bmain->name, op->reports); 00234 00235 /* redraw everything so any changed paths register */ 00236 WM_main_add_notifier(NC_WINDOW, NULL); 00237 00238 return OPERATOR_FINISHED; 00239 } 00240 00241 void FILE_OT_make_paths_absolute(wmOperatorType *ot) 00242 { 00243 /* identifiers */ 00244 ot->name= "Make All Paths Absolute"; 00245 ot->idname= "FILE_OT_make_paths_absolute"; 00246 00247 /* api callbacks */ 00248 ot->exec= make_paths_absolute_exec; 00249 00250 /* flags */ 00251 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00252 } 00253 00254 /********************* report missing files operator *********************/ 00255 00256 static int report_missing_files_exec(bContext *C, wmOperator *op) 00257 { 00258 Main *bmain= CTX_data_main(C); 00259 00260 /* run the missing file check */ 00261 checkMissingFiles(bmain, op->reports); 00262 00263 return OPERATOR_FINISHED; 00264 } 00265 00266 void FILE_OT_report_missing_files(wmOperatorType *ot) 00267 { 00268 /* identifiers */ 00269 ot->name= "Report Missing Files"; 00270 ot->idname= "FILE_OT_report_missing_files"; 00271 00272 /* api callbacks */ 00273 ot->exec= report_missing_files_exec; 00274 00275 /* flags */ 00276 ot->flag= 0; /* only reports so no need to undo/register */ 00277 } 00278 00279 /********************* find missing files operator *********************/ 00280 00281 static int find_missing_files_exec(bContext *C, wmOperator *op) 00282 { 00283 Main *bmain= CTX_data_main(C); 00284 const char *searchpath= RNA_string_get_alloc(op->ptr, "filepath", NULL, 0); 00285 findMissingFiles(bmain, searchpath, op->reports); 00286 MEM_freeN((void *)searchpath); 00287 00288 return OPERATOR_FINISHED; 00289 } 00290 00291 static int find_missing_files_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) 00292 { 00293 /* XXX file open button text "Find Missing Files" */ 00294 WM_event_add_fileselect(C, op); 00295 return OPERATOR_RUNNING_MODAL; 00296 } 00297 00298 void FILE_OT_find_missing_files(wmOperatorType *ot) 00299 { 00300 /* identifiers */ 00301 ot->name= "Find Missing Files"; 00302 ot->idname= "FILE_OT_find_missing_files"; 00303 00304 /* api callbacks */ 00305 ot->exec= find_missing_files_exec; 00306 ot->invoke= find_missing_files_invoke; 00307 00308 /* flags */ 00309 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00310 00311 /* properties */ 00312 WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH); 00313 } 00314 00315 /********************* report box operator *********************/ 00316 00317 /* Hard to decide whether to keep this as an operator, 00318 * or turn it into a hardcoded ui control feature, 00319 * handling TIMER events for all regions in interface_handlers.c 00320 * Not sure how good that is to be accessing UI data from 00321 * inactive regions, so use this for now. --matt 00322 */ 00323 00324 #define INFO_TIMEOUT 5.0f 00325 #define INFO_COLOR_TIMEOUT 3.0f 00326 #define ERROR_TIMEOUT 10.0f 00327 #define ERROR_COLOR_TIMEOUT 6.0f 00328 #define COLLAPSE_TIMEOUT 0.25f 00329 static int update_reports_display_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) 00330 { 00331 wmWindowManager *wm= CTX_wm_manager(C); 00332 ReportList *reports= CTX_wm_reports(C); 00333 Report *report; 00334 ReportTimerInfo *rti; 00335 float progress=0.0, color_progress=0.0; 00336 float neutral_col[3] = {0.35, 0.35, 0.35}; 00337 float neutral_grey= 0.6; 00338 float timeout=0.0, color_timeout=0.0; 00339 int send_note= 0; 00340 00341 /* escape if not our timer */ 00342 if( (reports->reporttimer==NULL) || 00343 (reports->reporttimer != event->customdata) || 00344 ((report= BKE_reports_last_displayable(reports))==NULL) /* may have been deleted */ 00345 ) { 00346 return OPERATOR_PASS_THROUGH; 00347 } 00348 00349 rti = (ReportTimerInfo *)reports->reporttimer->customdata; 00350 00351 timeout = (report->type & RPT_ERROR_ALL)?ERROR_TIMEOUT:INFO_TIMEOUT; 00352 color_timeout = (report->type & RPT_ERROR_ALL)?ERROR_COLOR_TIMEOUT:INFO_COLOR_TIMEOUT; 00353 00354 /* clear the report display after timeout */ 00355 if ((float)reports->reporttimer->duration > timeout) { 00356 WM_event_remove_timer(wm, NULL, reports->reporttimer); 00357 reports->reporttimer = NULL; 00358 00359 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_INFO, NULL); 00360 00361 return (OPERATOR_FINISHED|OPERATOR_PASS_THROUGH); 00362 } 00363 00364 if (rti->widthfac == 0.0f) { 00365 /* initialise colors based on report type */ 00366 if(report->type & RPT_ERROR_ALL) { 00367 rti->col[0] = 1.0; 00368 rti->col[1] = 0.2; 00369 rti->col[2] = 0.0; 00370 } else if(report->type & RPT_WARNING_ALL) { 00371 rti->col[0] = 1.0; 00372 rti->col[1] = 1.0; 00373 rti->col[2] = 0.0; 00374 } else if(report->type & RPT_INFO_ALL) { 00375 rti->col[0] = 0.3; 00376 rti->col[1] = 0.45; 00377 rti->col[2] = 0.7; 00378 } 00379 rti->greyscale = 0.75; 00380 rti->widthfac=1.0; 00381 } 00382 00383 progress = (float)reports->reporttimer->duration / timeout; 00384 color_progress = (float)reports->reporttimer->duration / color_timeout; 00385 00386 /* save us from too many draws */ 00387 if(color_progress <= 1.0f) { 00388 send_note= 1; 00389 00390 /* fade colors out sharply according to progress through fade-out duration */ 00391 interp_v3_v3v3(rti->col, rti->col, neutral_col, color_progress); 00392 rti->greyscale = interpf(neutral_grey, rti->greyscale, color_progress); 00393 } 00394 00395 /* collapse report at end of timeout */ 00396 if (progress*timeout > timeout - COLLAPSE_TIMEOUT) { 00397 rti->widthfac = (progress*timeout - (timeout - COLLAPSE_TIMEOUT)) / COLLAPSE_TIMEOUT; 00398 rti->widthfac = 1.0f - rti->widthfac; 00399 send_note= 1; 00400 } 00401 00402 if(send_note) { 00403 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_INFO, NULL); 00404 } 00405 00406 return (OPERATOR_FINISHED|OPERATOR_PASS_THROUGH); 00407 } 00408 00409 void INFO_OT_reports_display_update(wmOperatorType *ot) 00410 { 00411 /* identifiers */ 00412 ot->name= "Update Reports Display"; 00413 ot->idname= "INFO_OT_reports_display_update"; 00414 00415 /* api callbacks */ 00416 ot->invoke= update_reports_display_invoke; 00417 00418 /* flags */ 00419 ot->flag= 0; 00420 00421 /* properties */ 00422 } 00423 00424 /* report operators */