source: tags/svn.1.5.4/PHYLO/PH_display.cxx

Last change on this file was 8313, checked in by westram, 14 years ago
  • removed dead code

(partly reverted by [8316])

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