source: tags/initial/PHYLO/PH_display.cxx

Last change on this file was 2, checked in by oldcode, 23 years ago

Initial revision

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