source: tags/ms_r16q2/EDIT4/ED4_colStat.cxx

Last change on this file was 14483, checked in by westram, 8 years ago
  • use typed callbacks in route_down_hierarchy
File size: 7.4 KB
Line 
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
19static void toggle_detailed_column_stat(ED4_sequence_terminal *seq_term, bool force_off) {
20    ED4_base *ms_man = seq_term->get_parent(ED4_L_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(ED4_L_COL_STAT);
24
25        if (existing_colstat) {
26            ED4_manager *colstat_seq_man = existing_colstat->get_parent(ED4_L_SEQUENCE)->to_manager();
27            colstat_seq_man->Delete();
28        }
29        else { // add
30            if (!force_off) {
31                char buffer[35];
32                int count = 1;
33                sprintf(buffer, "Sequence_Manager.%ld.%d", ED4_counter, count++);
34
35                ED4_sequence_manager *new_seq_man = new ED4_sequence_manager(buffer, 0, 0, 0, 0, multi_seq_man);
36                new_seq_man->set_property(ED4_P_MOVABLE);
37                multi_seq_man->children->append_member(new_seq_man);
38
39                int    pixel_length     = max_seq_terminal_length;
40                AW_pos font_height      = ED4_ROOT->font_group.get_height(ED4_G_SEQUENCES);
41                AW_pos columnStatHeight = ceil((COLUMN_STAT_ROWS+0.5 /* reserve a bit more space */)*COLUMN_STAT_ROW_HEIGHT(font_height));
42
43                ED4_columnStat_terminal    *ref_colStat_terminal      = ED4_ROOT->ref_terminals.get_ref_column_stat();
44                ED4_sequence_info_terminal *ref_colStat_info_terminal = ED4_ROOT->ref_terminals.get_ref_column_stat_info();
45
46                ref_colStat_terminal->extension.size[HEIGHT] = columnStatHeight;
47                ref_colStat_terminal->extension.size[WIDTH]  = pixel_length;
48
49                ED4_sequence_info_terminal *new_colStat_info_term = new ED4_sequence_info_terminal("CStat", 0, 0, SEQUENCEINFOSIZE, columnStatHeight, new_seq_man);
50                new_colStat_info_term->set_property((ED4_properties) (ED4_P_SELECTABLE | ED4_P_DRAGABLE | ED4_P_IS_HANDLE));
51                new_colStat_info_term->set_links(ref_colStat_info_terminal, ref_colStat_terminal);
52                new_seq_man->children->append_member(new_colStat_info_term);
53
54                sprintf(buffer, "Column_Statistic_Terminal.%ld.%d", ED4_counter, count++);
55                ED4_columnStat_terminal *new_colStat_term = new ED4_columnStat_terminal(buffer, SEQUENCEINFOSIZE, 0, 0, columnStatHeight, new_seq_man);
56                new_colStat_term->set_links(ref_colStat_terminal, ref_colStat_terminal);
57                new_seq_man->children->append_member(new_colStat_term);
58
59                ED4_counter++;
60
61                new_seq_man->resize_requested_by_child();
62            }
63        }
64    }
65}
66
67static ARB_ERROR forget_cached_column_stat(ED4_base *base) {
68    if (base->is_sequence_terminal()) {
69        ED4_sequence_terminal *seqTerm = base->to_sequence_terminal();
70        toggle_detailed_column_stat(seqTerm, true);
71        seqTerm->st_ml_node = NULL;
72    }
73    return NULL;
74}
75
76inline void set_col_stat_activated_and_refresh(bool activated) {
77    ED4_ROOT->column_stat_activated = activated;
78    ED4_ROOT->request_refresh_for_sequence_terminals();
79}
80
81static void col_stat_activated(AW_window *) {
82    ED4_ROOT->column_stat_initialized  = true;
83    set_col_stat_activated_and_refresh(true);
84}
85
86static void configureColumnStat(bool forceConfig, WindowCallbackSimple post_config_cb, AW_window *cb_win) {
87    STAT_set_postcalc_callback(ED4_ROOT->st_ml, post_config_cb, cb_win);
88
89    static AW_window *aw_config = NULL;
90    bool              do_config = forceConfig;
91    if (!aw_config) {
92        aw_config = STAT_create_main_window(ED4_ROOT->aw_root, ED4_ROOT->st_ml);
93        do_config = true; // always configure on first call
94    }
95    if (do_config) aw_config->activate();
96}
97
98void ED4_activate_col_stat(AW_window *aww) {
99    if (!ED4_ROOT->column_stat_activated || !ED4_ROOT->column_stat_initialized) {
100        if (ED4_ROOT->column_stat_initialized) {
101            // re-initialize column-stat! first cleanup old column stat data
102            ED4_ROOT->main_manager->route_down_hierarchy(makeED4_route_cb(forget_cached_column_stat)).expect_no_error();
103        }
104        configureColumnStat(true, col_stat_activated, aww);
105    }
106}
107void ED4_disable_col_stat(AW_window *) {
108    if (ED4_ROOT->column_stat_initialized && ED4_ROOT->column_stat_activated) {
109        set_col_stat_activated_and_refresh(false);
110    }
111}
112
113static void show_detailed_column_stats_activated(AW_window *aww) {
114    ED4_ROOT->column_stat_initialized = true;
115    ED4_toggle_detailed_column_stats(aww);
116}
117
118double ED4_columnStat_terminal::threshold = -1;
119int ED4_columnStat_terminal::threshold_is_set() {
120    return threshold>=0 && threshold<=100;
121}
122void ED4_columnStat_terminal::set_threshold(double aThreshold) {
123    threshold = aThreshold;
124    e4_assert(threshold_is_set());
125}
126
127void ED4_set_col_stat_threshold() {
128    double default_threshold = 90.0;
129    if (ED4_columnStat_terminal::threshold_is_set()) {
130        default_threshold = ED4_columnStat_terminal::get_threshold();
131    }
132    char default_input[40];
133    sprintf(default_input, "%6.2f", default_threshold);
134
135    char *input = aw_input("Please insert threshold value for marking:", default_input);
136    if (input) {
137        double input_threshold = atof(input);
138
139        if (input_threshold<0 || input_threshold>100) {
140            aw_message("Illegal threshold value (allowed: 0..100)");
141        }
142        else {
143            ED4_columnStat_terminal::set_threshold(input_threshold);
144            ED4_ROOT->request_refresh_for_specific_terminals(ED4_L_COL_STAT);
145        }
146        free(input);
147    }
148}
149
150void ED4_toggle_detailed_column_stats(AW_window *aww) {
151    while (!ED4_columnStat_terminal::threshold_is_set()) {
152        ED4_set_col_stat_threshold();
153    }
154
155    ED4_LocalWinContext  uses(aww);
156    ED4_cursor          *cursor = &current_cursor();
157
158    GB_ERROR error = NULL;
159    if (!cursor->owner_of_cursor) {
160        error = "First you have to place your cursor";
161    }
162    else if (!cursor->in_species_seq_terminal()) {
163        error = "Display of column-statistic-details is only possible for species!";
164    }
165    else {
166        ED4_sequence_terminal *seq_term = cursor->owner_of_cursor->to_sequence_terminal();
167        if (!seq_term->st_ml_node && !(seq_term->st_ml_node = STAT_find_node_by_name(ED4_ROOT->st_ml, seq_term->species_name))) {
168            if (ED4_ROOT->column_stat_initialized) {
169                error = "Cannot display column statistics for this species (internal error?)";
170            }
171            else {
172                configureColumnStat(false, show_detailed_column_stats_activated, aww);
173            }
174        }
175        else {
176            toggle_detailed_column_stat(seq_term, false);
177        }
178    }
179
180    if (error) aw_message(error);
181}
182
183
Note: See TracBrowser for help on using the repository browser.