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