source: tags/arb-6.0/PHYLO/PH_display.cxx

Last change on this file was 11464, checked in by westram, 10 years ago
  • un-dummy-fied transaction (renames only)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.5 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : PH_display.cxx                                    //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#include <arbdb.h>
12#include "phylo.hxx"
13#include "phwin.hxx"
14#include "PH_display.hxx"
15#include <aw_awar.hxx>
16#include <aw_msg.hxx>
17#include <aw_root.hxx>
18
19static void vertical_change_cb(AW_window *aww) {
20    PH_display::ph_display->monitor_vertical_scroll_cb(aww);
21}
22
23static void horizontal_change_cb(AW_window *aww) {
24    PH_display::ph_display->monitor_horizontal_scroll_cb(aww);
25}
26
27void ph_view_species_cb() {
28    AW_window *main_win = PH_used_windows::windowList->phylo_main_window;
29
30    PH_display::ph_display->initialize(species_dpy);
31    PH_display::ph_display->display();
32    main_win->set_vertical_change_callback(makeWindowCallback(vertical_change_cb));
33    main_win->set_horizontal_change_callback(makeWindowCallback(horizontal_change_cb));
34}
35
36GB_ERROR ph_check_initialized() {
37    if (!PHDATA::ROOT) return "Please select alignment and press DONE";
38    return 0;
39}
40
41void ph_view_filter_cb() {
42    GB_ERROR err = ph_check_initialized();
43    if (err) {
44        aw_message(err);
45    }
46    else {
47        AW_window *main_win  = PH_used_windows::windowList->phylo_main_window;
48        PH_filter *ph_filter = new PH_filter;
49
50        ph_filter->init(PHDATA::ROOT->get_seq_len());
51        PHDATA::ROOT->markerline=ph_filter->calculate_column_homology();
52        PH_display::ph_display->initialize(filter_dpy);
53        PH_display::ph_display->display();
54        main_win->set_vertical_change_callback(makeWindowCallback(vertical_change_cb));
55        main_win->set_horizontal_change_callback(makeWindowCallback(horizontal_change_cb));
56    }
57}
58
59
60PH_display::PH_display()
61{
62    memset((char *) this, 0, sizeof(PH_display));
63    this->display_what = NONE;
64}
65
66
67void PH_display::initialize (display_type dpyt)
68{
69    display_what = dpyt;
70    device=PH_used_windows::windowList->phylo_main_window->get_device(AW_MIDDLE_AREA);
71    if (!device)
72    {
73        aw_message("could not get device !!");
74        return;
75    }
76    const AW_font_limits& lim = device->get_font_limits(0, 0);
77    switch (display_what)
78    {
79        case NONE:
80            return;
81
82        case species_dpy:
83        case filter_dpy:
84            cell_width  = lim.width;
85            cell_height = lim.height+5;
86            cell_offset = 3;
87
88            off_dx = SPECIES_NAME_LEN*lim.width+20;
89            off_dy = cell_height*3;
90
91            total_cells_horiz = PHDATA::ROOT->get_seq_len();
92            total_cells_vert  = PHDATA::ROOT->nentries;
93            set_scrollbar_steps(PH_used_windows::windowList->phylo_main_window, cell_width, cell_height, 50, 50);
94            break;
95
96        case matrix_dpy:
97            cell_width  = lim.width*SPECIES_NAME_LEN;
98            cell_height = lim.height*2;
99            cell_offset = 10;   // draw cell_offset pixels above cell base_line
100
101            off_dx = SPECIES_NAME_LEN*lim.width+20;
102            off_dy = 3*cell_height;
103
104            total_cells_horiz = PHDATA::ROOT->nentries;
105            total_cells_vert  = PHDATA::ROOT->nentries;
106            set_scrollbar_steps(PH_used_windows::windowList->phylo_main_window, cell_width, cell_height, 50, 50);
107            break;
108
109        default:
110            aw_message("init: unknown display type (maybe not implemented yet)");
111            break;
112    }
113    resized();  // initialize window_size dependent parameters
114}
115
116
117void PH_display::resized() {
118    const AW_screen_area& squ = PH_used_windows::windowList->phylo_main_window->get_device(AW_MIDDLE_AREA)-> get_area_size();
119    screen_width              = squ.r-squ.l;
120    screen_height             = squ.b-squ.t;
121
122    AW_screen_area rect =  { 0, 0, 0, 0 };
123    long         horiz_paint_size, vert_paint_size;
124    switch (display_what) {
125        case NONE:
126            return;
127
128        case species_dpy:
129            horiz_paint_size = (squ.r-off_dx)/cell_width;
130            vert_paint_size  = (squ.b-off_dy)/cell_height;
131            horiz_page_size  = (PHDATA::ROOT->get_seq_len() > horiz_paint_size) ? horiz_paint_size : PHDATA::ROOT->get_seq_len();
132            vert_page_size   = (long(PHDATA::ROOT->nentries) > vert_paint_size) ? vert_paint_size : PHDATA::ROOT->nentries;
133            rect.l           = 0;
134            rect.t           = 0;
135            rect.r           = (int) ((PHDATA::ROOT->get_seq_len()-horiz_page_size)*cell_width+squ.r);
136            rect.b           = (int) ((PHDATA::ROOT->nentries-vert_page_size)*cell_height+squ.b);
137            break;
138
139        case matrix_dpy: {
140            const AW_font_limits& lim = device->get_font_limits(0, 0);
141
142            horiz_paint_size = (squ.r-lim.width-off_dx)/cell_width;
143            vert_paint_size  = (squ.b-off_dy)/cell_height;
144            horiz_page_size  = (long(PHDATA::ROOT->nentries) > horiz_paint_size) ? horiz_paint_size : PHDATA::ROOT->nentries;
145            vert_page_size   = (long(PHDATA::ROOT->nentries) > vert_paint_size) ? vert_paint_size : PHDATA::ROOT->nentries;
146            rect.l           = 0;
147            rect.t           = 0;
148            rect.r           = (int) ((PHDATA::ROOT->nentries-horiz_page_size)*cell_width+squ.r);
149            rect.b           = (int) ((PHDATA::ROOT->nentries-vert_page_size)*cell_height+squ.b);
150            break;
151        }
152        case filter_dpy:
153            horiz_paint_size  = (squ.r-off_dx)/cell_width;
154            vert_paint_size   = (squ.b-off_dy)/cell_height;
155            vert_paint_size  -= (3/8)/cell_height + 2;
156            horiz_page_size   = (PHDATA::ROOT->get_seq_len() > horiz_paint_size) ? horiz_paint_size : PHDATA::ROOT->get_seq_len();
157            vert_page_size    = (long(PHDATA::ROOT->nentries) > vert_paint_size) ? vert_paint_size : PHDATA::ROOT->nentries;
158            rect.l            = 0;
159            rect.t            = 0;
160            rect.r            = (int) ((PHDATA::ROOT->get_seq_len()-horiz_page_size)*cell_width+squ.r);
161            rect.b            = (int) ((PHDATA::ROOT->nentries-vert_page_size)*cell_height+squ.b);
162            break;
163
164        default:
165            aw_message("resized: unknown display type (maybe not implemented yet)");
166            break;
167    }
168
169    horiz_page_start = 0; horiz_last_view_start=0;
170    vert_page_start  = 0; vert_last_view_start=0;
171
172    device->reset();            // clip_size == device_size
173    device->clear(-1);
174    device->set_right_clip_border((int)(off_dx+cell_width*horiz_page_size));
175    device->reset();            // reset shift_x and shift_y
176
177    PH_used_windows::windowList->phylo_main_window->set_vertical_scrollbar_position(0);
178    PH_used_windows::windowList->phylo_main_window->set_horizontal_scrollbar_position(0);
179    PH_used_windows::windowList->phylo_main_window->tell_scrolled_picture_size(rect);
180    PH_used_windows::windowList->phylo_main_window->calculate_scrollbars();
181}
182
183
184
185void PH_display::display()       // draw area
186{
187    char buf[50], cbuf[2];
188    long x, y, xpos, ypos;
189    AW_window *main_win = PH_used_windows::windowList->phylo_main_window;
190    long minhom;
191    long maxhom;
192    long startcol, stopcol;
193
194    if (!PHDATA::ROOT) return; // not correctly initialized yet
195
196    float *markerline = PHDATA::ROOT->markerline;
197
198    if (!device) return;
199   
200    GB_transaction ta(PHDATA::ROOT->get_gb_main());
201    switch (display_what) // be careful: text origin is lower left
202    {
203        case NONE: return;
204        case species_dpy:
205            device->shift(AW::Vector(off_dx, off_dy));
206            ypos=0;
207            for (y=vert_page_start; y<(vert_page_start+vert_page_size) && (y<total_cells_vert); y++) {
208                // species names
209                device->text(0, PHDATA::ROOT->hash_elements[y]->name, -off_dx, ypos*cell_height-cell_offset);
210
211                // alignment
212                GBDATA     *gb_seq_data = PHDATA::ROOT->hash_elements[y]->gb_species_data_ptr;
213                const char *seq_data    = GB_read_char_pntr(gb_seq_data);
214                long        seq_len     = GB_read_count(gb_seq_data);
215
216                device->text(0, (horiz_page_start >= seq_len) ? "" : (seq_data+horiz_page_start), 0, ypos*cell_height-cell_offset);
217                ypos++;
218            }
219            device->shift(-AW::Vector(off_dx, off_dy));
220            break;
221
222        case matrix_dpy:
223            device->shift(AW::Vector(off_dx, off_dy));
224            xpos=0;
225            for (x=horiz_page_start; x<(horiz_page_start+horiz_page_size) &&
226                    (x<total_cells_horiz); x++)
227            {
228                ypos=0;
229                for (y=vert_page_start; y<(vert_page_start+vert_page_size) &&
230                        (y<total_cells_vert); y++)
231                {
232                    sprintf(buf, "%3.4f", PHDATA::ROOT->matrix->get(x, y));
233                    device->text(0, buf, xpos*cell_width, ypos*cell_height-cell_offset);
234                    ypos++;
235                }
236                // display horizontal speciesnames :
237                device->text(0, PHDATA::ROOT->hash_elements[x]->name, xpos*cell_width, cell_height-off_dy-cell_offset);
238                xpos++;
239            }
240            device->shift(AW::Vector(-off_dx, 0));
241            // display vertical speciesnames
242            ypos=0;
243            for (y=vert_page_start; y<vert_page_start+vert_page_size; y++)
244            {
245                device->text(0, PHDATA::ROOT->hash_elements[y]->name, 0, ypos*cell_height-cell_offset);
246                ypos++;
247            }
248            device->shift(AW::Vector(0, -off_dy));
249            break;
250
251
252
253
254        case filter_dpy: {
255            device->shift(AW::Vector(off_dx, off_dy));
256            ypos=0;
257            for (y=vert_page_start; y<(vert_page_start+vert_page_size) && (y<total_cells_vert); y++) {
258                // species names
259                device->text(0, PHDATA::ROOT->hash_elements[y]->name, -off_dx, ypos*cell_height-cell_offset);
260
261                // alignment
262                GBDATA     *gb_seq_data = PHDATA::ROOT->hash_elements[y]->gb_species_data_ptr;
263                const char *seq_data    = GB_read_char_pntr(gb_seq_data);
264                long        seq_len     = GB_read_count(gb_seq_data);
265
266                device->text(0, (horiz_page_start >= seq_len) ? "" : (seq_data+horiz_page_start), 0, ypos*cell_height-cell_offset);
267                ypos++;
268            }
269            xpos=0;
270            cbuf[0]='\0'; cbuf[1]='\0';
271
272            const AW_font_limits& lim = device->get_font_limits(0, 0);
273
274            minhom   = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MINHOM)->read_int();
275            maxhom   = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MAXHOM)->read_int();
276            startcol = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STARTCOL)->read_int();
277            stopcol  = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STOPCOL)->read_int();
278
279            for (x = horiz_page_start; x < horiz_page_start + horiz_page_size; x++) {
280                int             gc = 1;
281                float       ml = markerline[x];
282                if (x < startcol || x>stopcol) {
283                    gc = 2;
284                }
285                if (markerline[x] >= 0.0) {
286                    if (ml < minhom ||
287                            ml > maxhom) {
288                        gc = 2;
289                    }
290                    sprintf(buf, "%3.0f", ml);
291                }
292                else {
293                    gc = 2;
294                    sprintf(buf, "XXX");
295                }
296
297                for (y = 0; y < 3; y++) {
298                    strncpy(cbuf, buf + y, 1);
299                    device->text(gc, cbuf, xpos * cell_width + 1, vert_page_size * cell_height + y * lim.height);
300                }
301                xpos++;
302            }
303            device->shift(-AW::Vector(off_dx, off_dy));
304            break;
305        }
306
307        default:
308            printf("\ndisplay: unknown display type (maybe not implemented yet)\n");
309    }
310}
311
312
313void PH_display::set_scrollbar_steps(AW_window *aww, long width_h, long width_v, long page_h, long page_v) {
314    aww->window_local_awar("scroll_width_horizontal")  ->write_int(width_h);
315    aww->window_local_awar("scroll_width_vertical")    ->write_int(width_v);
316    aww->window_local_awar("horizontal_page_increment")->write_int(page_h);
317    aww->window_local_awar("vertical_page_increment")  ->write_int(page_v);
318}
319
320
321void PH_display::monitor_vertical_scroll_cb(AW_window *aww)    // draw area
322{
323    long diff;
324
325    if (!device) return;
326    if (vert_last_view_start==aww->slider_pos_vertical) return;
327    diff=(aww->slider_pos_vertical-vert_last_view_start)/cell_height;
328    // fast scroll: be careful: no transformation in move_region
329    if (diff==1) // scroll one position up (== \/ arrow pressed)
330    {
331        device->move_region(0, off_dy, screen_width, vert_page_size*cell_height, 0, off_dy-cell_height);
332        device->clear_part(0, off_dy-cell_height+(vert_page_size-1)*cell_height+1, screen_width, cell_height, -1);
333        device->push_clip_scale();
334        device->set_top_clip_border((int)(off_dy+(vert_page_size-2)*cell_height));
335    }
336    else if (diff==-1) // scroll one position down (== /\ arrow pressed)
337    {
338        device->move_region(0, off_dy-cell_height, screen_width, (vert_page_size-1)*cell_height+1, 0, off_dy);
339        device->clear_part(0, off_dy-cell_height, screen_width, cell_height, -1);
340        device->push_clip_scale();
341        device->set_bottom_clip_border((int)off_dy);
342    }
343    else  device->clear(-1);
344
345    vert_last_view_start=aww->slider_pos_vertical;
346    vert_page_start=aww->slider_pos_vertical/cell_height;
347    display();
348    if ((diff==1) || (diff==-1)) device->pop_clip_scale();
349}
350
351void PH_display::monitor_horizontal_scroll_cb(AW_window *aww)  // draw area
352{
353    long diff;
354
355    if (!device) return;
356    if (horiz_last_view_start==aww->slider_pos_horizontal) return;
357    diff=(aww->slider_pos_horizontal- horiz_last_view_start)/cell_width;
358    // fast scroll
359    if (diff==1)  // scroll one position left ( > arrow pressed)
360    {
361        device->move_region(off_dx+cell_width, 0, horiz_page_size*cell_width, screen_height, off_dx, 0);
362        device->clear_part(off_dx+(horiz_page_size-1)*cell_width, 0, cell_width, screen_height, -1);
363        device->push_clip_scale();
364        device->set_left_clip_border((int)((horiz_page_size-1)*cell_width));
365    }
366    else if (diff==-1) // scroll one position right ( < arrow pressed)
367    {
368        device->move_region(off_dx, 0, (horiz_page_size-1)*cell_width, screen_height, off_dx+cell_width,
369                            0);
370        device->clear_part(off_dx, 0, cell_width, screen_height, -1);
371        device->push_clip_scale();
372        device->set_right_clip_border((int)(off_dx+cell_width));
373    }
374    else device->clear(-1);
375
376    horiz_last_view_start=aww->slider_pos_horizontal;
377    horiz_page_start=aww->slider_pos_horizontal/cell_width;
378    display();
379    if ((diff==1) || (diff==-1)) device->pop_clip_scale();
380}
381
382PH_display_status::PH_display_status(AW_device *awd) {
383    device = awd;
384    if (!device) return;
385
386    const AW_font_limits& lim = device->get_font_limits(0, 0);
387
388    font_width  = lim.width;
389    font_height = lim.height;
390
391    device->reset();
392
393    const AW_screen_area& rect = device->get_area_size();
394
395    device->set_foreground_color(0, AW_WINDOW_FG);
396    max_x   = (rect.r-rect.l)/font_width;
397    max_y   = (rect.b-rect.t)/font_height;
398    x_pos   = 0.0;
399    y_pos   = 0.0;
400    tab_pos = x_pos;
401}
402
403void PH_display_status::write(const char *text)
404{
405    device->text(0, text, x_pos*font_width, y_pos*font_height);
406    x_pos+=strlen(text);
407}
408
409void PH_display_status::writePadded(const char *text, size_t len)
410{
411    device->text(0, text, x_pos*font_width, y_pos*font_height);
412    x_pos += len;
413}
414
415void PH_display_status::write(long numl)
416{
417    char buf[20];
418
419    sprintf(buf, "%ld", numl);
420    write(buf);
421}
422
423void PH_display_status::write(AW_pos numA)
424{
425    char buf[20];
426
427    sprintf(buf, "%3.3G", numA);
428    write(buf);
429}
430
431void PH_display_status::clear() {
432    device->clear(-1);
433}
434
435void display_status_cb() {
436    // bottom area
437    if (!PH_display::ph_display) return;
438    if (!PH_used_windows::windowList) return;
439
440    AW_root *aw_root = AW_root::SINGLETON;
441
442    {
443        static PH_display_status phds(PH_used_windows::windowList->phylo_main_window->get_device (AW_BOTTOM_AREA));
444        phds.clear();
445
446        const int LABEL_LEN = 21;
447
448        switch (PH_display::ph_display->displayed())
449        {
450            case NONE: return;
451            case filter_dpy:
452            case species_dpy: phds.set_origin();
453                phds.set_cursor((phds.get_size('x')/2)-10, 0);
454                phds.write("STATUS REPORT FILTER");
455                phds.newline();
456
457                phds.writePadded("Start at column:", LABEL_LEN);
458                phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_STARTCOL)->read_int());
459                phds.move_x(15);
460                phds.set_tab();
461                phds.writePadded("Stop at column:", LABEL_LEN);
462                phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_STOPCOL)->read_int());
463                phds.newline();
464
465                phds.writePadded("Minimal similarity:", LABEL_LEN);
466                phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_MINHOM)->read_int());
467                phds.set_cursor_x(phds.get_tab());
468                phds.writePadded("Maximal similarity:", LABEL_LEN);
469                phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_MAXHOM)->read_int());
470                phds.newline();
471                phds.newline();
472
473                phds.writePadded("'.':", LABEL_LEN);
474                phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_POINT)->read_int()]);
475                phds.newline();
476
477                phds.writePadded("'-':", LABEL_LEN);
478                phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_MINUS)->read_int()]);
479                phds.newline();
480
481                phds.writePadded("ambiguity codes:", LABEL_LEN);
482                phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_REST)->read_int()]);
483                phds.newline();
484
485                phds.writePadded("lowercase chars:", LABEL_LEN);
486                phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_LOWER)->read_int()]);
487                break;
488
489            case matrix_dpy: phds.set_origin();
490                phds.set_cursor((phds.get_size('x')/2)-10, 0);
491                phds.write("STATUS REPORT MATRIX");
492                break;
493
494            default: printf("\nstatus: unknown display type (maybe not implemented yet)\n");
495        }
496    }
497}
498
Note: See TracBrowser for help on using the repository browser.