Blender V2.61 - r43446

info_report.c

Go to the documentation of this file.
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  * Contributor(s): Campbell Barton
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <limits.h>
00031 
00032 #include "MEM_guardedalloc.h"
00033 
00034 #include "BLI_blenlib.h"
00035 #include "BLI_dynstr.h"
00036 #include "BLI_utildefines.h"
00037 
00038 #include "BKE_context.h"
00039 
00040 #include "WM_api.h"
00041 #include "WM_types.h"
00042 
00043 #include "ED_screen.h"
00044 #include "ED_types.h"
00045 
00046 #include "RNA_access.h"
00047 #include "RNA_define.h"
00048 
00049 #include "info_intern.h"
00050 
00051 int info_report_mask(SpaceInfo *UNUSED(sinfo))
00052 {
00053 #if 0
00054     int report_mask = 0;
00055 
00056     if(sinfo->rpt_mask & INFO_RPT_DEBUG)    report_mask |= RPT_DEBUG_ALL;
00057     if(sinfo->rpt_mask & INFO_RPT_INFO)     report_mask |= RPT_INFO_ALL;
00058     if(sinfo->rpt_mask & INFO_RPT_OP)       report_mask |= RPT_OPERATOR_ALL;
00059     if(sinfo->rpt_mask & INFO_RPT_WARN)     report_mask |= RPT_WARNING_ALL;
00060     if(sinfo->rpt_mask & INFO_RPT_ERR)      report_mask |= RPT_ERROR_ALL;
00061 
00062     return report_mask;
00063 #endif
00064 
00065     return RPT_DEBUG_ALL|RPT_INFO_ALL|RPT_OPERATOR_ALL|RPT_WARNING_ALL|RPT_ERROR_ALL;
00066 }
00067 
00068 // TODO, get this working again!
00069 static int report_replay_exec(bContext *C, wmOperator *UNUSED(op))
00070 {
00071 //  SpaceInfo *sc= CTX_wm_space_info(C);
00072 //  ReportList *reports= CTX_wm_reports(C);
00073 //  int report_mask= info_report_mask(sc);
00074 //  Report *report;
00075 
00076 #if 0
00077     sc->type= CONSOLE_TYPE_PYTHON;
00078 
00079     for(report=reports->list.last; report; report=report->prev) {
00080         if((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL) && (report->flag & SELECT)) {
00081             console_history_add_str(sc, report->message, 0);
00082             WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
00083 
00084             ED_area_tag_redraw(CTX_wm_area(C));
00085         }
00086     }
00087 
00088     sc->type= CONSOLE_TYPE_REPORT;
00089 #endif
00090     ED_area_tag_redraw(CTX_wm_area(C));
00091 
00092     return OPERATOR_FINISHED;
00093 }
00094 
00095 void INFO_OT_report_replay(wmOperatorType *ot)
00096 {
00097     /* identifiers */
00098     ot->name= "Replay Operators";
00099     ot->description= "Replay selected reports";
00100     ot->idname= "INFO_OT_report_replay";
00101 
00102     /* api callbacks */
00103     ot->poll= ED_operator_info_active;
00104     ot->exec= report_replay_exec;
00105 
00106     /* flags */
00107     /* ot->flag= OPTYPE_REGISTER; */
00108 
00109     /* properties */
00110 }
00111 
00112 static int select_report_pick_exec(bContext *C, wmOperator *op)
00113 {
00114     int report_index= RNA_int_get(op->ptr, "report_index");
00115     Report *report= BLI_findlink(&CTX_wm_reports(C)->list, report_index);
00116 
00117     if(!report)
00118         return OPERATOR_CANCELLED;
00119 
00120     report->flag ^= SELECT; /* toggle */
00121 
00122     ED_area_tag_redraw(CTX_wm_area(C));
00123 
00124     return OPERATOR_FINISHED;
00125 }
00126 
00127 static int select_report_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
00128 {
00129     SpaceInfo *sinfo= CTX_wm_space_info(C);
00130     ARegion *ar= CTX_wm_region(C);
00131     ReportList *reports= CTX_wm_reports(C);
00132     Report *report;
00133 
00134     /* uses opengl */
00135     wmSubWindowSet(CTX_wm_window(C), ar->swinid);
00136     
00137     report= info_text_pick(sinfo, ar, reports, event->mval[1]);
00138 
00139     RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
00140 
00141     return select_report_pick_exec(C, op);
00142 }
00143 
00144 
00145 void INFO_OT_select_pick(wmOperatorType *ot)
00146 {
00147     /* identifiers */
00148     ot->name= "Select report";
00149     ot->description= "Select reports by index";
00150     ot->idname= "INFO_OT_select_pick";
00151 
00152     /* api callbacks */
00153     ot->poll= ED_operator_info_active;
00154     ot->invoke= select_report_pick_invoke;
00155     ot->exec= select_report_pick_exec;
00156 
00157     /* flags */
00158     /* ot->flag= OPTYPE_REGISTER; */
00159 
00160     /* properties */
00161     RNA_def_int(ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX);
00162 }
00163 
00164 
00165 
00166 static int report_select_all_toggle_exec(bContext *C, wmOperator *UNUSED(op))
00167 {
00168     SpaceInfo *sinfo= CTX_wm_space_info(C);
00169     ReportList *reports= CTX_wm_reports(C);
00170     int report_mask= info_report_mask(sinfo);
00171     int deselect= 0;
00172 
00173     Report *report;
00174 
00175     for(report=reports->list.last; report; report=report->prev) {
00176         if((report->type & report_mask) && (report->flag & SELECT)) {
00177             deselect= 1;
00178             break;
00179         }
00180     }
00181 
00182 
00183     if(deselect) {
00184         for(report=reports->list.last; report; report=report->prev)
00185             if(report->type & report_mask)
00186                 report->flag &= ~SELECT;
00187     }
00188     else {
00189         for(report=reports->list.last; report; report=report->prev)
00190             if(report->type & report_mask)
00191                 report->flag |= SELECT;
00192     }
00193 
00194     ED_area_tag_redraw(CTX_wm_area(C));
00195 
00196     return OPERATOR_FINISHED;
00197 }
00198 
00199 void INFO_OT_select_all_toggle(wmOperatorType *ot)
00200 {
00201     /* identifiers */
00202     ot->name= "(De)Select All";
00203     ot->description= "(de)select all reports";
00204     ot->idname= "INFO_OT_select_all_toggle";
00205 
00206     /* api callbacks */
00207     ot->poll= ED_operator_info_active;
00208     ot->exec= report_select_all_toggle_exec;
00209 
00210     /* flags */
00211     /*ot->flag= OPTYPE_REGISTER;*/
00212 
00213     /* properties */
00214 }
00215 
00216 /* borderselect operator */
00217 static int borderselect_exec(bContext *C, wmOperator *op)
00218 {
00219     SpaceInfo *sinfo= CTX_wm_space_info(C);
00220     ARegion *ar= CTX_wm_region(C);
00221     ReportList *reports= CTX_wm_reports(C);
00222     int report_mask= info_report_mask(sinfo);
00223     int extend= RNA_boolean_get(op->ptr, "extend");
00224     Report *report_min, *report_max, *report;
00225 
00226     //View2D *v2d= UI_view2d_fromcontext(C);
00227 
00228 
00229     rcti rect;
00230     //rctf rectf, rq;
00231     short selecting= (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
00232     //int mval[2];
00233 
00234     rect.xmin= RNA_int_get(op->ptr, "xmin");
00235     rect.ymin= RNA_int_get(op->ptr, "ymin");
00236     rect.xmax= RNA_int_get(op->ptr, "xmax");
00237     rect.ymax= RNA_int_get(op->ptr, "ymax");
00238 
00239     /*
00240     mval[0]= rect.xmin;
00241     mval[1]= rect.ymin;
00242     UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin);
00243     mval[0]= rect.xmax;
00244     mval[1]= rect.ymax;
00245     UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax);
00246 */
00247 
00248     if(!extend) {
00249         for(report= reports->list.first; report; report= report->next) {
00250 
00251             if((report->type & report_mask)==0)
00252                 continue;
00253 
00254             report->flag &= ~SELECT;
00255         }
00256     }
00257 
00258     report_min= info_text_pick(sinfo, ar, reports, rect.ymax);
00259     report_max= info_text_pick(sinfo, ar, reports, rect.ymin);
00260 
00261     /* get the first report if none found */
00262     if(report_min==NULL) {
00263         // printf("find_min\n");
00264         for(report=reports->list.first; report; report=report->next) {
00265             if(report->type & report_mask) {
00266                 report_min= report;
00267                 break;
00268             }
00269         }
00270     }
00271 
00272     if(report_max==NULL) {
00273         // printf("find_max\n");
00274         for(report=reports->list.last; report; report=report->prev) {
00275             if(report->type & report_mask) {
00276                 report_max= report;
00277                 break;
00278             }
00279         }
00280     }
00281 
00282     if(report_min==NULL || report_max==NULL)
00283         return OPERATOR_CANCELLED;
00284 
00285     for(report= report_min; (report != report_max->next); report= report->next) {
00286 
00287         if((report->type & report_mask)==0)
00288             continue;
00289 
00290         if(selecting)
00291             report->flag |= SELECT;
00292         else
00293             report->flag &= ~SELECT;
00294     }
00295 
00296     ED_area_tag_redraw(CTX_wm_area(C));
00297 
00298     return OPERATOR_FINISHED;
00299 }
00300 
00301 
00302 /* ****** Border Select ****** */
00303 void INFO_OT_select_border(wmOperatorType *ot)
00304 {
00305     /* identifiers */
00306     ot->name= "Border Select";
00307     ot->description= "Toggle border selection";
00308     ot->idname= "INFO_OT_select_border";
00309 
00310     /* api callbacks */
00311     ot->invoke= WM_border_select_invoke;
00312     ot->exec= borderselect_exec;
00313     ot->modal= WM_border_select_modal;
00314     ot->cancel= WM_border_select_cancel;
00315 
00316     ot->poll= ED_operator_info_active;
00317 
00318     /* flags */
00319     /* ot->flag= OPTYPE_REGISTER; */
00320 
00321     /* rna */
00322     WM_operator_properties_gesture_border(ot, TRUE);
00323 }
00324 
00325 
00326 
00327 static int report_delete_exec(bContext *C, wmOperator *UNUSED(op))
00328 {
00329     SpaceInfo *sinfo= CTX_wm_space_info(C);
00330     ReportList *reports= CTX_wm_reports(C);
00331     int report_mask= info_report_mask(sinfo);
00332 
00333 
00334     Report *report, *report_next;
00335 
00336     for(report=reports->list.first; report; ) {
00337 
00338         report_next=report->next;
00339 
00340         if((report->type & report_mask) && (report->flag & SELECT)) {
00341             BLI_remlink(&reports->list, report);
00342             MEM_freeN((void *)report->message);
00343             MEM_freeN(report);
00344         }
00345 
00346         report= report_next;
00347     }
00348 
00349     ED_area_tag_redraw(CTX_wm_area(C));
00350 
00351     return OPERATOR_FINISHED;
00352 }
00353 
00354 void INFO_OT_report_delete(wmOperatorType *ot)
00355 {
00356     /* identifiers */
00357     ot->name= "Delete Reports";
00358     ot->description= "Delete selected reports";
00359     ot->idname= "INFO_OT_report_delete";
00360 
00361     /* api callbacks */
00362     ot->poll= ED_operator_info_active;
00363     ot->exec= report_delete_exec;
00364 
00365     /* flags */
00366     /*ot->flag= OPTYPE_REGISTER;*/
00367 
00368     /* properties */
00369 }
00370 
00371 
00372 static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
00373 {
00374     SpaceInfo *sinfo= CTX_wm_space_info(C);
00375     ReportList *reports= CTX_wm_reports(C);
00376     int report_mask= info_report_mask(sinfo);
00377 
00378     Report *report;
00379 
00380     DynStr *buf_dyn= BLI_dynstr_new();
00381     char *buf_str;
00382 
00383     for(report=reports->list.first; report; report= report->next) {
00384         if((report->type & report_mask) && (report->flag & SELECT)) {
00385             BLI_dynstr_append(buf_dyn, report->message);
00386             BLI_dynstr_append(buf_dyn, "\n");
00387         }
00388     }
00389 
00390     buf_str= BLI_dynstr_get_cstring(buf_dyn);
00391     BLI_dynstr_free(buf_dyn);
00392 
00393     WM_clipboard_text_set(buf_str, 0);
00394 
00395     MEM_freeN(buf_str);
00396     return OPERATOR_FINISHED;
00397 }
00398 
00399 void INFO_OT_report_copy(wmOperatorType *ot)
00400 {
00401     /* identifiers */
00402     ot->name= "Copy Reports to Clipboard";
00403     ot->description= "Copy selected reports to Clipboard";
00404     ot->idname= "INFO_OT_report_copy";
00405 
00406     /* api callbacks */
00407     ot->poll= ED_operator_info_active;
00408     ot->exec= report_copy_exec;
00409 
00410     /* flags */
00411     /*ot->flag= OPTYPE_REGISTER;*/
00412 
00413     /* properties */
00414 }