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; |
---|
41 | AW_pos font_height = ED4_ROOT->font_group.get_height(ED4_G_SEQUENCES); |
---|
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 | |
---|
68 | static ARB_ERROR forget_cached_column_stat(ED4_base *base) { |
---|
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; |
---|
79 | ED4_ROOT->request_refresh_for_sequence_terminals(); |
---|
80 | } |
---|
81 | |
---|
82 | static void col_stat_activated(AW_window *) { |
---|
83 | ED4_ROOT->column_stat_initialized = true; |
---|
84 | set_col_stat_activated_and_refresh(true); |
---|
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) { |
---|
93 | aw_config = STAT_create_main_window(ED4_ROOT->aw_root, ED4_ROOT->st_ml); |
---|
94 | do_config = true; // always configure on first call |
---|
95 | } |
---|
96 | if (do_config) aw_config->activate(); |
---|
97 | } |
---|
98 | |
---|
99 | void ED4_activate_col_stat(AW_window *aww) { |
---|
100 | if (!ED4_ROOT->column_stat_activated || !ED4_ROOT->column_stat_initialized) { |
---|
101 | if (ED4_ROOT->column_stat_initialized) { |
---|
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 | } |
---|
105 | configureColumnStat(true, col_stat_activated, aww); |
---|
106 | } |
---|
107 | } |
---|
108 | void ED4_disable_col_stat(AW_window *) { |
---|
109 | if (ED4_ROOT->column_stat_initialized && ED4_ROOT->column_stat_activated) { |
---|
110 | set_col_stat_activated_and_refresh(false); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | static void show_detailed_column_stats_activated(AW_window *aww) { |
---|
115 | ED4_ROOT->column_stat_initialized = true; |
---|
116 | ED4_toggle_detailed_column_stats(aww); |
---|
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 | |
---|
128 | void ED4_set_col_stat_threshold() { |
---|
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); |
---|
145 | ED4_ROOT->request_refresh_for_specific_terminals(LEV_COL_STAT); |
---|
146 | } |
---|
147 | free(input); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | void ED4_toggle_detailed_column_stats(AW_window *aww) { |
---|
152 | while (!ED4_columnStat_terminal::threshold_is_set()) { |
---|
153 | ED4_set_col_stat_threshold(); |
---|
154 | } |
---|
155 | |
---|
156 | ED4_LocalWinContext uses(aww); |
---|
157 | ED4_cursor *cursor = ¤t_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))) { |
---|
169 | if (ED4_ROOT->column_stat_initialized) { |
---|
170 | error = "Cannot display column statistics for this species (internal error?)"; |
---|
171 | } |
---|
172 | else { |
---|
173 | configureColumnStat(false, show_detailed_column_stats_activated, aww); |
---|
174 | } |
---|
175 | } |
---|
176 | else { |
---|
177 | toggle_detailed_column_stat(seq_term, false); |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | if (error) aw_message(error); |
---|
182 | } |
---|
183 | |
---|
184 | |
---|