source: tags/ms_r16q3/PHYLO/PH_display.cxx

Last change on this file was 15256, checked in by westram, 8 years ago
  • replace redundant data AW_font_limits::height with get_height()
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.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 <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_display(DISP_SPECIES);
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    // trigger automatic calculation on startup (if autocalc-toggle was saved as checked)
36    main_win->get_root()->awar(AWAR_PHYLO_FILTER_AUTOCALC)->touch();
37}
38
39GB_ERROR ph_check_initialized() {
40    if (!PHDATA::ROOT) return "Please select alignment and press DONE";
41    return 0;
42}
43
44void ph_calc_filter_cb() {
45    GB_ERROR err = ph_check_initialized();
46    if (err) {
47        aw_message(err);
48    }
49    else {
50        AW_window *main_win  = PH_used_windows::windowList->phylo_main_window;
51        PH_filter *ph_filter = new PH_filter;
52
53        ph_filter->init(PHDATA::ROOT->get_seq_len());
54        PHDATA::ROOT->markerline=ph_filter->calculate_column_homology();
55        PH_display::ph_display->initialize_display(DISP_FILTER);
56        PH_display::ph_display->display();
57        main_win->set_vertical_change_callback(makeWindowCallback(vertical_change_cb));
58        main_win->set_horizontal_change_callback(makeWindowCallback(horizontal_change_cb));
59    }
60}
61
62
63PH_display::PH_display() {
64    memset((char *) this, 0, sizeof(PH_display));
65    this->display_what = DISP_NONE;
66}
67
68
69void PH_display::initialize_display(display_type dpyt) {
70    display_what = dpyt;
71    device=PH_used_windows::windowList->phylo_main_window->get_device(AW_MIDDLE_AREA);
72    if (!device)
73    {
74        aw_message("could not get device !!");
75        return;
76    }
77    const AW_font_limits& lim = device->get_font_limits(0, 0);
78    switch (display_what) {
79        case DISP_NONE:
80            return;
81
82        case DISP_SPECIES:
83        case DISP_FILTER:
84            cell_width  = lim.width;
85            cell_height = lim.get_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_vert  = PHDATA::ROOT->nentries;
92            set_scrollbar_steps(PH_used_windows::windowList->phylo_main_window, cell_width, cell_height, 50, 50);
93            break;
94    }
95    resized();  // initialize window_size dependent parameters
96}
97
98
99void PH_display::resized() {
100    const AW_screen_area& squ = PH_used_windows::windowList->phylo_main_window->get_device(AW_MIDDLE_AREA)-> get_area_size();
101    screen_width              = squ.r-squ.l;
102    screen_height             = squ.b-squ.t;
103
104    AW_screen_area rect =  { 0, 0, 0, 0 };
105    long         horiz_paint_size, vert_paint_size;
106    switch (display_what) {
107        case DISP_NONE:
108            return;
109
110        case DISP_SPECIES:
111            horiz_paint_size = (squ.r-off_dx)/cell_width;
112            vert_paint_size  = (squ.b-off_dy)/cell_height;
113            horiz_page_size  = (PHDATA::ROOT->get_seq_len() > horiz_paint_size) ? horiz_paint_size : PHDATA::ROOT->get_seq_len();
114            vert_page_size   = (long(PHDATA::ROOT->nentries) > vert_paint_size) ? vert_paint_size : PHDATA::ROOT->nentries;
115            rect.l           = 0;
116            rect.t           = 0;
117            rect.r           = (int) ((PHDATA::ROOT->get_seq_len()-horiz_page_size)*cell_width+squ.r);
118            rect.b           = (int) ((PHDATA::ROOT->nentries-vert_page_size)*cell_height+squ.b);
119            break;
120
121        case DISP_FILTER:
122            horiz_paint_size  = (squ.r-off_dx)/cell_width;
123            vert_paint_size   = (squ.b-off_dy)/cell_height;
124            vert_paint_size  -= (3/8)/cell_height + 2;
125            horiz_page_size   = (PHDATA::ROOT->get_seq_len() > horiz_paint_size) ? horiz_paint_size : PHDATA::ROOT->get_seq_len();
126            vert_page_size    = (long(PHDATA::ROOT->nentries) > vert_paint_size) ? vert_paint_size : PHDATA::ROOT->nentries;
127            rect.l            = 0;
128            rect.t            = 0;
129            rect.r            = (int) ((PHDATA::ROOT->get_seq_len()-horiz_page_size)*cell_width+squ.r);
130            rect.b            = (int) ((PHDATA::ROOT->nentries-vert_page_size)*cell_height+squ.b);
131            break;
132    }
133
134    horiz_page_start = 0; horiz_last_view_start = 0;
135    vert_page_start  = 0; vert_last_view_start  = 0;
136
137    device->reset();            // clip_size == device_size
138    device->clear(-1);
139    device->set_right_clip_border((int)(off_dx+cell_width*horiz_page_size));
140    device->reset();            // reset shift_x and shift_y
141
142    AW_window *pmw = PH_used_windows::windowList->phylo_main_window;
143    pmw->set_vertical_scrollbar_position(0);
144    pmw->set_horizontal_scrollbar_position(0);
145    pmw->tell_scrolled_picture_size(rect);
146    pmw->calculate_scrollbars();
147}
148
149
150
151void PH_display::display()       // draw area
152{
153    char buf[50], cbuf[2];
154    long x, y, xpos, ypos;
155    AW_window *main_win = PH_used_windows::windowList->phylo_main_window;
156    long minhom;
157    long maxhom;
158    long startcol, stopcol;
159
160    if (!PHDATA::ROOT) return; // not correctly initialized yet
161
162    float *markerline = PHDATA::ROOT->markerline;
163
164    if (!device) return;
165
166    GB_transaction ta(PHDATA::ROOT->get_gb_main());
167    // be careful: text origin is lower left
168    if (display_what != DISP_NONE) {
169        device->shift(AW::Vector(off_dx, off_dy));
170        ypos      = 0;
171        long ymax = std::min(vert_page_start+vert_page_size, total_cells_vert);
172        for (y=vert_page_start; y<ymax; y++) {
173            // species names
174            device->text(PH_GC_SEQUENCE, PHDATA::ROOT->hash_elements[y]->name, -off_dx, ypos*cell_height-cell_offset);
175
176            // alignment
177            GBDATA     *gb_seq_data = PHDATA::ROOT->hash_elements[y]->gb_species_data_ptr;
178            const char *seq_data    = GB_read_char_pntr(gb_seq_data);
179            long        seq_len     = GB_read_count(gb_seq_data);
180
181            device->text(PH_GC_SEQUENCE, (horiz_page_start >= seq_len) ? "" : (seq_data+horiz_page_start), 0, ypos*cell_height-cell_offset);
182            ypos++;
183        }
184
185        if (display_what == DISP_FILTER) {
186            xpos    = 0;
187            cbuf[0] = '\0';
188            cbuf[1] = '\0';
189
190            const AW_font_limits& lim = device->get_font_limits(0, 0);
191
192            minhom   = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MINHOM)->read_int();
193            maxhom   = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MAXHOM)->read_int();
194            startcol = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STARTCOL)->read_int();
195            stopcol  = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STOPCOL)->read_int();
196
197            for (x = horiz_page_start; x < horiz_page_start + horiz_page_size; x++) {
198                int   gc = PH_GC_MARKER;
199                float ml = markerline[x];
200
201                if (x < startcol || x>stopcol) {
202                    gc = PH_GC_NOT_MARKER;
203                }
204                if (markerline[x] >= 0.0) {
205                    if (ml < minhom || ml > maxhom) {
206                        gc = PH_GC_NOT_MARKER;
207                    }
208                    sprintf(buf, "%3.0f", ml);
209                }
210                else {
211                    gc = PH_GC_NOT_MARKER;
212                    sprintf(buf, "XXX");
213                }
214
215                for (y = 0; y < 3; y++) {
216                    strncpy(cbuf, buf + y, 1);
217                    device->text(gc, cbuf, xpos * cell_width + 1, vert_page_size * cell_height + y * lim.get_height());
218                }
219                xpos++;
220            }
221        }
222        device->shift(-AW::Vector(off_dx, off_dy));
223    }
224}
225
226
227void PH_display::set_scrollbar_steps(AW_window *aww, long width_h, long width_v, long page_h, long page_v) {
228    aww->window_local_awar("scroll_width_horizontal")  ->write_int(width_h);
229    aww->window_local_awar("scroll_width_vertical")    ->write_int(width_v);
230    aww->window_local_awar("horizontal_page_increment")->write_int(page_h);
231    aww->window_local_awar("vertical_page_increment")  ->write_int(page_v);
232}
233
234
235void PH_display::monitor_vertical_scroll_cb(AW_window *aww)    // draw area
236{
237    long diff;
238
239    if (!device) return;
240    if (vert_last_view_start==aww->slider_pos_vertical) return;
241
242    diff = (aww->slider_pos_vertical-vert_last_view_start)/cell_height;
243    // fast scroll: be careful: no transformation in move_region
244    if (diff==1) // scroll one position up (== \/ arrow pressed)
245    {
246        device->move_region(0, off_dy, screen_width, vert_page_size*cell_height, 0, off_dy-cell_height);
247        device->clear_part(0, off_dy-cell_height+(vert_page_size-1)*cell_height+1, screen_width, cell_height, -1);
248        device->push_clip_scale();
249        device->set_top_clip_border((int)(off_dy+(vert_page_size-2)*cell_height));
250    }
251    else if (diff==-1) // scroll one position down (== /\ arrow pressed)
252    {
253        device->move_region(0, off_dy-cell_height, screen_width, (vert_page_size-1)*cell_height+1, 0, off_dy);
254        device->clear_part(0, off_dy-cell_height, screen_width, cell_height, -1);
255        device->push_clip_scale();
256        device->set_bottom_clip_border((int)off_dy);
257    }
258    else  device->clear(-1);
259
260    vert_last_view_start = aww->slider_pos_vertical;
261    vert_page_start      = aww->slider_pos_vertical/cell_height;
262
263    display();
264    if ((diff==1) || (diff==-1)) device->pop_clip_scale();
265}
266
267void PH_display::monitor_horizontal_scroll_cb(AW_window *aww)  // draw area
268{
269    long diff;
270
271    if (!device) return;
272    if (horiz_last_view_start==aww->slider_pos_horizontal) return;
273    diff=(aww->slider_pos_horizontal- horiz_last_view_start)/cell_width;
274    // fast scroll
275    if (diff==1)  // scroll one position left ( > arrow pressed)
276    {
277        device->move_region(off_dx+cell_width, 0, horiz_page_size*cell_width, screen_height, off_dx, 0);
278        device->clear_part(off_dx+(horiz_page_size-1)*cell_width, 0, cell_width, screen_height, -1);
279        device->push_clip_scale();
280        device->set_left_clip_border((int)((horiz_page_size-1)*cell_width));
281    }
282    else if (diff==-1) // scroll one position right ( < arrow pressed)
283    {
284        device->move_region(off_dx, 0, (horiz_page_size-1)*cell_width, screen_height, off_dx+cell_width,
285                            0);
286        device->clear_part(off_dx, 0, cell_width, screen_height, -1);
287        device->push_clip_scale();
288        device->set_right_clip_border((int)(off_dx+cell_width));
289    }
290    else device->clear(-1);
291
292    horiz_last_view_start=aww->slider_pos_horizontal;
293    horiz_page_start=aww->slider_pos_horizontal/cell_width;
294    display();
295    if ((diff==1) || (diff==-1)) device->pop_clip_scale();
296}
297
298PH_display_status::PH_display_status(AW_device *awd) {
299    device = awd;
300    if (!device) return;
301
302    const AW_font_limits& lim = device->get_font_limits(0, 0);
303
304    font_width  = lim.width;
305    font_height = lim.get_height();
306
307    device->reset();
308
309    const AW_screen_area& rect = device->get_area_size();
310
311    device->set_foreground_color(0, AW_WINDOW_FG);
312    max_x   = (rect.r-rect.l)/font_width;
313    max_y   = (rect.b-rect.t)/font_height;
314    x_pos   = 0.0;
315    y_pos   = 0.0;
316    tab_pos = x_pos;
317}
318
319void PH_display_status::write(const char *text)
320{
321    device->text(PH_GC_BOTTOM_TEXT, text, x_pos*font_width, y_pos*font_height);
322    x_pos+=strlen(text);
323}
324
325void PH_display_status::writePadded(const char *text, size_t len)
326{
327    device->text(PH_GC_BOTTOM_TEXT, text, x_pos*font_width, y_pos*font_height);
328    x_pos += len;
329}
330
331void PH_display_status::write(long numl)
332{
333    char buf[20];
334
335    sprintf(buf, "%ld", numl);
336    write(buf);
337}
338
339void PH_display_status::clear() {
340    device->clear(-1);
341}
342
343void display_status_cb() {
344    // bottom area
345    if (!PH_display::ph_display) return;
346    if (!PH_used_windows::windowList) return;
347
348    AW_root *aw_root = AW_root::SINGLETON;
349
350    {
351        static PH_display_status phds(PH_used_windows::windowList->phylo_main_window->get_device (AW_BOTTOM_AREA));
352        phds.clear();
353
354        const int LABEL_LEN = 21;
355
356        switch (PH_display::ph_display->displayed()) {
357            case DISP_NONE:
358                break;
359
360            case DISP_FILTER:
361            case DISP_SPECIES:
362                phds.set_origin();
363                phds.set_cursor(0, 0);
364                phds.write("FILTER STATUS REPORT:");
365                phds.newline();
366
367                phds.writePadded("Start at column:", LABEL_LEN);
368                phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_STARTCOL)->read_int());
369                phds.move_x(15);
370                phds.set_tab();
371                phds.writePadded("Stop at column:", LABEL_LEN);
372                phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_STOPCOL)->read_int());
373                phds.newline();
374
375                phds.writePadded("Minimal similarity:", LABEL_LEN);
376                phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_MINHOM)->read_int());
377                phds.set_cursor_x(phds.get_tab());
378                phds.writePadded("Maximal similarity:", LABEL_LEN);
379                phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_MAXHOM)->read_int());
380                phds.newline();
381                phds.newline();
382
383                phds.writePadded("'.':", LABEL_LEN);
384                phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_DOT)->read_int()]);
385                phds.newline();
386
387                phds.writePadded("'-':", LABEL_LEN);
388                phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_MINUS)->read_int()]);
389                phds.newline();
390
391                phds.writePadded("ambiguity codes:", LABEL_LEN);
392                phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_AMBIG)->read_int()]);
393                phds.newline();
394
395                phds.writePadded("lowercase chars:", LABEL_LEN);
396                phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_LOWER)->read_int()]);
397                break;
398        }
399    }
400}
401
Note: See TracBrowser for help on using the repository browser.