ARB
PH_display.cxx
Go to the documentation of this file.
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 
19 static void vertical_change_cb(AW_window *aww) {
21 }
22 
23 static void horizontal_change_cb(AW_window *aww) {
25 }
26 
29 
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)
37 }
38 
40  if (!PHDATA::ROOT) return "Please select alignment and press DONE";
41  return NULp;
42 }
43 
46  if (err) {
47  aw_message(err);
48  }
49  else {
51  PH_filter *ph_filter = new PH_filter;
52 
53  ph_filter->init(PHDATA::ROOT->get_seq_len());
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 
64  memset((char *) this, 0, sizeof(PH_display));
65  this->display_what = DISP_NONE;
66 }
67 
68 
70  display_what = dpyt;
72  if (!device) {
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  case DISP_NONE:
79  return;
80 
81  case DISP_SPECIES:
82  case DISP_FILTER:
83  cell_width = lim.width;
84  cell_height = lim.get_height()+5;
85  cell_offset = 3;
86 
87  off_dx = SPECIES_NAME_LEN*lim.width+20;
88  off_dy = cell_height*3;
89 
90  total_cells_vert = PHDATA::ROOT->nentries;
91  set_scrollbar_steps(PH_used_windows::windowList->phylo_main_window, cell_width, cell_height, 50, 50);
92  break;
93  }
94  resized(); // initialize window_size dependent parameters
95 }
96 
97 
100  screen_width = squ.r-squ.l;
101  screen_height = squ.b-squ.t;
102 
103  AW_screen_area rect = { 0, 0, 0, 0 };
104  long horiz_paint_size, vert_paint_size;
105  switch (display_what) {
106  case DISP_NONE:
107  return;
108 
109  case DISP_SPECIES:
110  horiz_paint_size = (squ.r-off_dx)/cell_width;
111  vert_paint_size = (squ.b-off_dy)/cell_height;
112  horiz_page_size = (PHDATA::ROOT->get_seq_len() > horiz_paint_size) ? horiz_paint_size : PHDATA::ROOT->get_seq_len();
113  vert_page_size = (long(PHDATA::ROOT->nentries) > vert_paint_size) ? vert_paint_size : PHDATA::ROOT->nentries;
114  rect.l = 0;
115  rect.t = 0;
116  rect.r = (int) ((PHDATA::ROOT->get_seq_len()-horiz_page_size)*cell_width+squ.r);
117  rect.b = (int) ((PHDATA::ROOT->nentries-vert_page_size)*cell_height+squ.b);
118  break;
119 
120  case DISP_FILTER:
121  horiz_paint_size = (squ.r-off_dx)/cell_width;
122  vert_paint_size = (squ.b-off_dy)/cell_height;
123  vert_paint_size -= (3/8)/cell_height + 2;
124  horiz_page_size = (PHDATA::ROOT->get_seq_len() > horiz_paint_size) ? horiz_paint_size : PHDATA::ROOT->get_seq_len();
125  vert_page_size = (long(PHDATA::ROOT->nentries) > vert_paint_size) ? vert_paint_size : PHDATA::ROOT->nentries;
126  rect.l = 0;
127  rect.t = 0;
128  rect.r = (int) ((PHDATA::ROOT->get_seq_len()-horiz_page_size)*cell_width+squ.r);
129  rect.b = (int) ((PHDATA::ROOT->nentries-vert_page_size)*cell_height+squ.b);
130  break;
131  }
132 
133  horiz_page_start = 0; horiz_last_view_start = 0;
134  vert_page_start = 0; vert_last_view_start = 0;
135 
136  device->reset(); // clip_size == device_size
137  device->clear(-1);
138  device->set_right_clip_border((int)(off_dx+cell_width*horiz_page_size));
139  device->reset(); // reset shift_x and shift_y
140 
144  pmw->tell_scrolled_picture_size(rect);
145  pmw->calculate_scrollbars();
146 }
147 
148 
149 
150 void PH_display::display() { // draw area
151  char buf[50], cbuf[2];
152  long x, y, xpos, ypos;
154  long minhom;
155  long maxhom;
156  long startcol, stopcol;
157 
158  if (!PHDATA::ROOT) return; // not correctly initialized yet
159 
160  float *markerline = PHDATA::ROOT->markerline;
161 
162  if (!device) return;
163 
165  // be careful: text origin is lower left
166  if (display_what != DISP_NONE) {
167  device->shift(AW::Vector(off_dx, off_dy));
168  ypos = 0;
169  long ymax = std::min(vert_page_start+vert_page_size, total_cells_vert);
170  for (y=vert_page_start; y<ymax; y++) {
171  // species names
172  device->text(PH_GC_SEQUENCE, PHDATA::ROOT->hash_elements[y]->name, -off_dx, ypos*cell_height-cell_offset);
173 
174  // alignment
175  GBDATA *gb_seq_data = PHDATA::ROOT->hash_elements[y]->gb_species_data_ptr;
176  const char *seq_data = GB_read_char_pntr(gb_seq_data);
177  long seq_len = GB_read_count(gb_seq_data);
178 
179  device->text(PH_GC_SEQUENCE, (horiz_page_start >= seq_len) ? "" : (seq_data+horiz_page_start), 0, ypos*cell_height-cell_offset);
180  ypos++;
181  }
182 
183  if (display_what == DISP_FILTER) {
184  xpos = 0;
185  cbuf[0] = '\0';
186  cbuf[1] = '\0';
187 
188  const AW_font_limits& lim = device->get_font_limits(0, 0);
189 
190  minhom = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MINHOM)->read_int();
191  maxhom = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MAXHOM)->read_int();
192  startcol = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STARTCOL)->read_int();
193  stopcol = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STOPCOL)->read_int();
194 
195  for (x = horiz_page_start; x < horiz_page_start + horiz_page_size; x++) {
196  int gc = PH_GC_MARKER;
197  float ml = markerline[x];
198 
199  if (x < startcol || x>stopcol) {
200  gc = PH_GC_NOT_MARKER;
201  }
202  if (markerline[x] >= 0.0) {
203  if (ml < minhom || ml > maxhom) {
204  gc = PH_GC_NOT_MARKER;
205  }
206  sprintf(buf, "%3.0f", ml);
207  }
208  else {
209  gc = PH_GC_NOT_MARKER;
210  sprintf(buf, "XXX");
211  }
212 
213  for (y = 0; y < 3; y++) {
214  strncpy(cbuf, buf + y, 1);
215  device->text(gc, cbuf, xpos * cell_width + 1, vert_page_size * cell_height + y * lim.get_height());
216  }
217  xpos++;
218  }
219  }
220  device->shift(-AW::Vector(off_dx, off_dy));
221  }
222 }
223 
224 
225 void PH_display::set_scrollbar_steps(AW_window *aww, long width_h, long width_v, long page_h, long page_v) {
226  aww->window_local_awar("scroll_width_horizontal") ->write_int(width_h);
227  aww->window_local_awar("scroll_width_vertical") ->write_int(width_v);
228  aww->window_local_awar("horizontal_page_increment")->write_int(page_h);
229  aww->window_local_awar("vertical_page_increment") ->write_int(page_v);
230 }
231 
232 
234  long diff;
235 
236  if (!device) return;
237  if (vert_last_view_start==aww->slider_pos_vertical) return;
238 
239  diff = (aww->slider_pos_vertical-vert_last_view_start)/cell_height;
240  // fast scroll: be careful: no transformation in move_region
241  if (diff==1) { // scroll one position up (== \/ arrow pressed)
242  device->move_region(0, off_dy, screen_width, vert_page_size*cell_height, 0, off_dy-cell_height);
243  device->clear_part(0, off_dy-cell_height+(vert_page_size-1)*cell_height+1, screen_width, cell_height, -1);
244  device->push_clip_scale();
245  device->set_top_clip_border((int)(off_dy+(vert_page_size-2)*cell_height));
246  }
247  else if (diff==-1) { // scroll one position down (== /\ arrow pressed)
248  device->move_region(0, off_dy-cell_height, screen_width, (vert_page_size-1)*cell_height+1, 0, off_dy);
249  device->clear_part(0, off_dy-cell_height, screen_width, cell_height, -1);
250  device->push_clip_scale();
251  device->set_bottom_clip_border((int)off_dy);
252  }
253  else device->clear(-1);
254 
255  vert_last_view_start = aww->slider_pos_vertical;
256  vert_page_start = aww->slider_pos_vertical/cell_height;
257 
258  display();
259  if ((diff==1) || (diff==-1)) device->pop_clip_scale();
260 }
261 
263  long diff;
264 
265  if (!device) return;
266  if (horiz_last_view_start==aww->slider_pos_horizontal) return;
267  diff=(aww->slider_pos_horizontal- horiz_last_view_start)/cell_width;
268  // fast scroll
269  if (diff==1) { // scroll one position left ( > arrow pressed)
270  device->move_region(off_dx+cell_width, 0, horiz_page_size*cell_width, screen_height, off_dx, 0);
271  device->clear_part(off_dx+(horiz_page_size-1)*cell_width, 0, cell_width, screen_height, -1);
272  device->push_clip_scale();
273  device->set_left_clip_border((int)((horiz_page_size-1)*cell_width));
274  }
275  else if (diff==-1) { // scroll one position right ( < arrow pressed)
276  device->move_region(off_dx, 0, (horiz_page_size-1)*cell_width, screen_height, off_dx+cell_width, 0);
277  device->clear_part(off_dx, 0, cell_width, screen_height, -1);
278  device->push_clip_scale();
279  device->set_right_clip_border((int)(off_dx+cell_width));
280  }
281  else device->clear(-1);
282 
283  horiz_last_view_start=aww->slider_pos_horizontal;
284  horiz_page_start=aww->slider_pos_horizontal/cell_width;
285  display();
286  if ((diff==1) || (diff==-1)) device->pop_clip_scale();
287 }
288 
290  device = awd;
291  if (!device) return;
292 
293  const AW_font_limits& lim = device->get_font_limits(0, 0);
294 
295  font_width = lim.width;
296  font_height = lim.get_height();
297 
298  device->reset();
299 
300  const AW_screen_area& rect = device->get_area_size();
301 
303  max_x = (rect.r-rect.l)/font_width;
304  max_y = (rect.b-rect.t)/font_height;
305  x_pos = 0.0;
306  y_pos = 0.0;
307  tab_pos = x_pos;
308 }
309 
310 void PH_display_status::write(const char *text) {
311  device->text(PH_GC_BOTTOM_TEXT, text, x_pos*font_width, y_pos*font_height);
312  x_pos+=strlen(text);
313 }
314 
315 void PH_display_status::writePadded(const char *text, size_t len) {
316  device->text(PH_GC_BOTTOM_TEXT, text, x_pos*font_width, y_pos*font_height);
317  x_pos += len;
318 }
319 
320 void PH_display_status::write(long numl) {
321  char buf[20];
322 
323  sprintf(buf, "%ld", numl);
324  write(buf);
325 }
326 
328  device->clear(-1);
329 }
330 
332  // bottom area
333  if (!PH_display::ph_display) return;
334  if (!PH_used_windows::windowList) return;
335 
336  AW_root *aw_root = AW_root::SINGLETON;
337 
338  {
339  static PH_display_status phds(PH_used_windows::windowList->phylo_main_window->get_device (AW_BOTTOM_AREA));
340  phds.clear();
341 
342  const int LABEL_LEN = 21;
343 
344  switch (PH_display::ph_display->displayed()) {
345  case DISP_NONE:
346  break;
347 
348  case DISP_FILTER:
349  case DISP_SPECIES:
350  phds.set_origin();
351  phds.set_cursor(0, 0);
352  phds.write("FILTER STATUS REPORT:");
353  phds.newline();
354 
355  phds.writePadded("Start at column:", LABEL_LEN);
356  phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_STARTCOL)->read_int());
357  phds.move_x(15);
358  phds.set_tab();
359  phds.writePadded("Stop at column:", LABEL_LEN);
360  phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_STOPCOL)->read_int());
361  phds.newline();
362 
363  phds.writePadded("Minimal similarity:", LABEL_LEN);
364  phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_MINHOM)->read_int());
365  phds.set_cursor_x(phds.get_tab());
366  phds.writePadded("Maximal similarity:", LABEL_LEN);
367  phds.write((long)aw_root->awar(AWAR_PHYLO_FILTER_MAXHOM)->read_int());
368  phds.newline();
369  phds.newline();
370 
371  phds.writePadded("'.':", LABEL_LEN);
372  phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_DOT)->read_int()]);
373  phds.newline();
374 
375  phds.writePadded("'-':", LABEL_LEN);
376  phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_MINUS)->read_int()]);
377  phds.newline();
378 
379  phds.writePadded("ambiguity codes:", LABEL_LEN);
380  phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_AMBIG)->read_int()]);
381  phds.newline();
382 
383  phds.writePadded("lowercase chars:", LABEL_LEN);
384  phds.write(filter_text[aw_root->awar(AWAR_PHYLO_FILTER_LOWER)->read_int()]);
385  break;
386  }
387  }
388 }
389 
const char * filter_text[]
Definition: PH_main.cxx:29
#define AWAR_PHYLO_FILTER_STARTCOL
Definition: phylo.hxx:29
void display_status_cb()
Definition: PH_display.cxx:331
virtual void clear(AW_bitset filteri)
Definition: AW_device.cxx:313
const char * GB_ERROR
Definition: arb_core.h:25
static PH_display * ph_display
Definition: PH_display.hxx:44
AW_device * get_device(AW_area area)
Definition: AW_window.cxx:537
PH_display_status(AW_device *)
Definition: PH_display.cxx:289
short get_height() const
const AW_screen_area & get_area_size() const
Definition: AW_device.cxx:57
static char * y[maxsp+1]
#define AWAR_PHYLO_FILTER_AMBIG
Definition: phylo.hxx:35
void set_left_clip_border(int left, bool allow_oversize=false)
AW_window * phylo_main_window
Definition: phwin.hxx:21
char * init(long size)
Definition: PH_filt.cxx:31
void shift(const AW::Vector &doff)
Definition: aw_device.hxx:131
void writePadded(const char *, size_t len)
Definition: PH_display.cxx:315
virtual void clear_part(const AW::Rectangle &rect, AW_bitset filteri)
Definition: AW_device.cxx:317
display_type
Definition: phylo.hxx:72
long
Definition: AW_awar.cxx:152
long read_int() const
Definition: AW_awar.cxx:184
void set_top_clip_border(int top, bool allow_oversize=false)
void monitor_horizontal_scroll_cb(AW_window *)
Definition: PH_display.cxx:262
int slider_pos_horizontal
current position of the vertical slider
Definition: aw_window.hxx:350
#define AWAR_PHYLO_FILTER_DOT
Definition: phylo.hxx:33
const AW_font_limits & get_font_limits(int gc, char c) const
Definition: AW_device.cxx:399
static AW_root * SINGLETON
Definition: aw_root.hxx:102
static int diff(int v1, int v2, int v3, int v4, int st, int en)
Definition: ClustalV.cxx:534
void initialize_display(display_type)
Definition: PH_display.cxx:69
long GB_read_count(GBDATA *gbd)
Definition: arbdb.cxx:758
void set_foreground_color(int gc, AW_color_idx color)
Definition: AW_device.cxx:471
unsigned int nentries
Definition: phylo.hxx:149
void push_clip_scale()
Definition: AW_device.cxx:91
#define AWAR_PHYLO_FILTER_STOPCOL
Definition: phylo.hxx:30
#define AWAR_PHYLO_FILTER_LOWER
Definition: phylo.hxx:36
void ph_calc_filter_cb()
Definition: PH_display.cxx:44
void set_bottom_clip_border(int bottom, bool allow_oversize=false)
static PH_used_windows * windowList
Definition: phwin.hxx:20
float * markerline
Definition: phylo.hxx:153
void calculate_scrollbars()
Definition: AW_window.cxx:873
PHENTRY ** hash_elements
Definition: phylo.hxx:148
float * calculate_column_homology()
Definition: PH_filt.cxx:52
void pop_clip_scale()
Definition: AW_device.cxx:62
void touch()
Definition: AW_awar.cxx:207
void ph_view_species_cb()
Definition: PH_display.cxx:27
#define AWAR_PHYLO_FILTER_MAXHOM
Definition: phylo.hxx:32
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
#define AWAR_PHYLO_FILTER_MINHOM
Definition: phylo.hxx:31
class AW_awar * window_local_awar(const char *localname, bool tmp=true)
Definition: AW_window.cxx:973
void tell_scrolled_picture_size(AW_screen_area rectangle)
Definition: AW_window.cxx:823
void set_right_clip_border(int right, bool allow_oversize=false)
void display()
Definition: PH_display.cxx:150
void write(const char *)
Definition: PH_display.cxx:310
#define AWAR_PHYLO_FILTER_MINUS
Definition: phylo.hxx:34
void resized()
Definition: PH_display.cxx:98
static void horizontal_change_cb(AW_window *aww)
Definition: PH_display.cxx:23
void set_horizontal_scrollbar_position(int position)
Definition: AW_window.cxx:998
void reset()
Definition: AW_device.cxx:280
static void vertical_change_cb(AW_window *aww)
Definition: PH_display.cxx:19
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
AW_root * get_root()
Definition: aw_window.hxx:359
#define AWAR_PHYLO_FILTER_AUTOCALC
Definition: phylo.hxx:37
#define NULp
Definition: cxxforward.h:116
#define SPECIES_NAME_LEN
Definition: PH_display.hxx:18
virtual void move_region(AW_pos src_x, AW_pos src_y, AW_pos width, AW_pos height, AW_pos dest_x, AW_pos dest_y)
Definition: AW_device.cxx:263
void set_vertical_scrollbar_position(int position)
Definition: AW_window.cxx:989
static PHDATA * ROOT
Definition: phylo.hxx:151
GB_transaction ta(gb_var)
void set_horizontal_change_callback(const WindowCallback &wcb)
Definition: AW_window.cxx:1049
long get_seq_len()
Definition: phylo.hxx:172
void set_vertical_change_callback(const WindowCallback &wcb)
Definition: AW_window.cxx:1033
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:904
#define min(a, b)
Definition: f2c.h:153
GBDATA * get_gb_main(DbSel db)
Definition: merge.hxx:88
int slider_pos_vertical
window id
Definition: aw_window.hxx:349
GB_ERROR ph_check_initialized()
Definition: PH_display.cxx:39
GB_ERROR write_int(long aw_int)
bool text(int gc, const SizedCstr &cstr, const AW::Position &pos, AW_pos alignment=0.0, AW_bitset filteri=AW_ALL_DEVICES_UNSCALED)
Definition: aw_device.hxx:440
void monitor_vertical_scroll_cb(AW_window *)
Definition: PH_display.cxx:233