ARB
ED4_colStat.cxx
Go to the documentation of this file.
1 // =========================================================== //
2 // //
3 // File : ED4_colStat.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =========================================================== //
10 
11 #include "ed4_colStat.hxx"
12 #include "ed4_class.hxx"
13 #include "ed4_extern.hxx"
14 
15 #include <st_window.hxx>
16 #include <aw_root.hxx>
17 #include <aw_msg.hxx>
18 
19 static void toggle_detailed_column_stat(ED4_sequence_terminal *seq_term, bool force_off) {
20  ED4_base *ms_man = seq_term->get_parent(LEV_MULTI_SEQUENCE);
21  if (ms_man) {
22  ED4_multi_sequence_manager *multi_seq_man = ms_man->to_multi_sequence_manager();
23  ED4_base *existing_colstat = multi_seq_man->search_spec_child_rek(LEV_COL_STAT);
24 
25  if (existing_colstat) {
26  ED4_manager *colstat_seq_man = existing_colstat->get_parent(LEV_SEQUENCE);
27  colstat_seq_man->Delete();
28  }
29  else { // add
30  if (!force_off) {
31  char namebuffer[NAME_BUFFERSIZE];
32  int count = 1;
33 
34  sprintf(namebuffer, "Sequence_Manager.%ld.%d", ED4_counter, count++);
35 
36  ED4_sequence_manager *new_seq_man = new ED4_sequence_manager(namebuffer, 0, 0, multi_seq_man);
37  new_seq_man->set_property(PROP_MOVABLE);
38  multi_seq_man->append_member(new_seq_man);
39 
40  int pixel_length = max_seq_terminal_length;
42  AW_pos columnStatHeight = ceil((COLUMN_STAT_ROWS+0.5 /* reserve a bit more space */)*COLUMN_STAT_ROW_HEIGHT(font_height));
43 
44  ED4_columnStat_terminal *ref_colStat = ED4_ROOT->ref_terminals.column_stat();
45  ED4_sequence_info_terminal *ref_colStat_info = ED4_ROOT->ref_terminals.column_stat_info();
46 
47  ref_colStat->extension.size[HEIGHT] = columnStatHeight;
48  ref_colStat->extension.size[WIDTH] = pixel_length;
49 
50  ED4_sequence_info_terminal *new_colStat_info_term = new ED4_sequence_info_terminal("CStat", SEQUENCE_INFO_WIDTH, columnStatHeight, new_seq_man);
51  new_colStat_info_term->set_property((ED4_properties) (PROP_SELECTABLE | PROP_DRAGABLE | PROP_IS_HANDLE));
52  new_colStat_info_term->set_links(ref_colStat_info, ref_colStat);
53  new_seq_man->append_member(new_colStat_info_term);
54 
55  sprintf(namebuffer, "Column_Statistic_Terminal.%ld.%d", ED4_counter, count++);
56  ED4_columnStat_terminal *new_colStat_term = new ED4_columnStat_terminal(namebuffer, 0, columnStatHeight, new_seq_man);
57  new_colStat_term->set_both_links(ref_colStat);
58  new_seq_man->append_member(new_colStat_term);
59 
60  ED4_counter++;
61 
62  new_seq_man->resize_requested_by_child();
63  }
64  }
65  }
66 }
67 
69  if (base->is_sequence_terminal()) {
70  ED4_sequence_terminal *seqTerm = base->to_sequence_terminal();
71  toggle_detailed_column_stat(seqTerm, true);
72  seqTerm->st_ml_node = NULp;
73  }
74  return NULp;
75 }
76 
77 inline void set_col_stat_activated_and_refresh(bool activated) {
78  ED4_ROOT->column_stat_activated = activated;
80 }
81 
82 static void col_stat_activated(AW_window *) {
85 }
86 
87 static void configureColumnStat(bool forceConfig, WindowCallbackSimple post_config_cb, AW_window *cb_win) {
88  STAT_set_postcalc_callback(ED4_ROOT->st_ml, post_config_cb, cb_win);
89 
90  static AW_window *aw_config = NULp;
91  bool do_config = forceConfig;
92  if (!aw_config) {
94  do_config = true; // always configure on first call
95  }
96  if (do_config) aw_config->activate();
97 }
98 
102  // re-initialize column-stat! first cleanup old column stat data
103  ED4_ROOT->main_manager->route_down_hierarchy(makeED4_route_cb(forget_cached_column_stat)).expect_no_error();
104  }
106  }
107 }
111  }
112 }
113 
117 }
118 
119 double ED4_columnStat_terminal::threshold = -1;
120 int ED4_columnStat_terminal::threshold_is_set() {
121  return threshold>=0 && threshold<=100;
122 }
123 void ED4_columnStat_terminal::set_threshold(double aThreshold) {
124  threshold = aThreshold;
125  e4_assert(threshold_is_set());
126 }
127 
129  double default_threshold = 90.0;
130  if (ED4_columnStat_terminal::threshold_is_set()) {
131  default_threshold = ED4_columnStat_terminal::get_threshold();
132  }
133  char default_input[40];
134  sprintf(default_input, "%6.2f", default_threshold);
135 
136  char *input = aw_input("Please insert threshold value for marking:", default_input);
137  if (input) {
138  double input_threshold = atof(input);
139 
140  if (input_threshold<0 || input_threshold>100) {
141  aw_message("Illegal threshold value (allowed: 0..100)");
142  }
143  else {
144  ED4_columnStat_terminal::set_threshold(input_threshold);
146  }
147  free(input);
148  }
149 }
150 
152  while (!ED4_columnStat_terminal::threshold_is_set()) {
154  }
155 
156  ED4_LocalWinContext uses(aww);
157  ED4_cursor *cursor = &current_cursor();
158 
159  GB_ERROR error = NULp;
160  if (!cursor->owner_of_cursor) {
161  error = "First you have to place your cursor";
162  }
163  else if (!cursor->in_species_seq_terminal()) {
164  error = "Display of column-statistic-details is only possible for species!";
165  }
166  else {
167  ED4_sequence_terminal *seq_term = cursor->owner_of_cursor->to_sequence_terminal();
168  if (!seq_term->st_ml_node && !(seq_term->st_ml_node = STAT_find_node_by_name(ED4_ROOT->st_ml, seq_term->species_name))) {
170  error = "Cannot display column statistics for this species (internal error?)";
171  }
172  else {
174  }
175  }
176  else {
177  toggle_detailed_column_stat(seq_term, false);
178  }
179  }
180 
181  if (error) aw_message(error);
182 }
183 
184 
bool column_stat_activated
Definition: ed4_class.hxx:1453
const char * GB_ERROR
Definition: arb_core.h:25
ED4_sequence_info_terminal * column_stat_info()
Definition: ed4_class.hxx:1361
void resize_requested_by_child()
Definition: ed4_class.hxx:2192
AW_font_group font_group
Definition: ed4_class.hxx:1467
AW_window * STAT_create_main_window(AW_root *root, ST_ML *st_ml)
Definition: ST_window.cxx:70
#define COLUMN_STAT_ROWS
Definition: ed4_defs.hxx:84
#define COLUMN_STAT_ROW_HEIGHT(font_height)
Definition: ed4_defs.hxx:83
void ED4_activate_col_stat(AW_window *aww)
Definition: ED4_colStat.cxx:99
void(* WindowCallbackSimple)(AW_window *)
Definition: cb.h:29
void STAT_set_postcalc_callback(ST_ML *st_ml, WindowCallbackSimple postcalc_cb, AW_window *cb_win)
Definition: ST_window.cxx:66
bool in_species_seq_terminal() const
Definition: ed4_class.hxx:1852
static void show_detailed_column_stats_activated(AW_window *aww)
static void toggle_detailed_column_stat(ED4_sequence_terminal *seq_term, bool force_off)
Definition: ED4_colStat.cxx:19
int get_height(int gc) const
bool column_stat_initialized
Definition: ed4_class.hxx:1454
ED4_root * ED4_ROOT
Definition: ED4_main.cxx:49
static void col_stat_activated(AW_window *)
Definition: ED4_colStat.cxx:82
ED4_terminal * owner_of_cursor
Definition: ed4_class.hxx:644
void ED4_disable_col_stat(AW_window *)
ED4_reference_terminals ref_terminals
Definition: ed4_class.hxx:1436
void activate()
Definition: aw_window.hxx:365
long ED4_counter
Definition: ED4_main.cxx:61
#define e4_assert(bed)
Definition: ed4_class.hxx:14
const int WIDTH
void request_refresh_for_specific_terminals(ED4_level lev)
Definition: ED4_root.cxx:88
#define SEQUENCE_INFO_WIDTH
Definition: ed4_defs.hxx:80
void ED4_toggle_detailed_column_stats(AW_window *aww)
double AW_pos
Definition: aw_base.hxx:29
void append_member(ED4_base *new_member)
static void error(const char *msg)
Definition: mkptypes.cxx:96
ED4_columnStat_terminal * column_stat()
Definition: ed4_class.hxx:1360
ED4_main_manager * main_manager
Definition: ed4_class.hxx:1429
static void configureColumnStat(bool forceConfig, WindowCallbackSimple post_config_cb, AW_window *cb_win)
Definition: ED4_colStat.cxx:87
#define NAME_BUFFERSIZE
Definition: ed4_defs.hxx:111
void Delete() FINAL_OVERRIDE
ED4_base * search_spec_child_rek(ED4_level level)
Definition: ED4_base.cxx:434
ED4_cursor & current_cursor()
Definition: ed4_class.hxx:1400
void set_property(ED4_properties prop)
Definition: ed4_class.hxx:975
AW_root * aw_root
Definition: ed4_class.hxx:1425
void set_col_stat_activated_and_refresh(bool activated)
Definition: ED4_colStat.cxx:77
ED4_properties
Definition: ed4_defs.hxx:174
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
long max_seq_terminal_length
Definition: ED4_main.cxx:66
#define NULp
Definition: cxxforward.h:116
void request_refresh_for_sequence_terminals()
Definition: ED4_root.cxx:107
int is_sequence_terminal() const
Definition: ed4_class.hxx:1083
AP_tree * STAT_find_node_by_name(ST_ML *st_ml, const char *species_name)
Definition: ST_window.cxx:127
static ARB_ERROR forget_cached_column_stat(ED4_base *base)
Definition: ED4_colStat.cxx:68
char * aw_input(const char *title, const char *prompt, const char *default_input)
Definition: AW_modal.cxx:251
ED4_manager * get_parent(ED4_level lev) const
Definition: ed4_class.hxx:1821
#define HEIGHT
Definition: ed4_defs.hxx:74
void ED4_set_col_stat_threshold()
ST_ML * st_ml
Definition: ed4_class.hxx:1444