source: tags/arb-6.0.5/SL/ITEMS/species.cxx

Last change on this file was 12267, checked in by westram, 10 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1// ================================================================ //
2//                                                                  //
3//   File      : species.cxx                                        //
4//   Purpose   :                                                    //
5//                                                                  //
6//   Institute of Microbiology (Technical University Munich)        //
7//   http://www.arb-home.de/                                        //
8//                                                                  //
9// ================================================================ //
10
11#include "item_sel_list.h"
12
13#include <arbdbt.h>
14#include <aw_root.hxx>
15#include <aw_awars.hxx>
16
17
18static GBDATA *get_first_species_data(GBDATA *gb_main, AW_root *, QUERY_RANGE) {
19    return GBT_get_species_data(gb_main);
20}
21static GBDATA *get_next_species_data(GBDATA *, QUERY_RANGE) {
22    return 0; // there is only ONE species_data
23}
24
25static void select_species(GBDATA*,  AW_root *aw_root, const char *item_name) {
26    aw_root->awar(AWAR_SPECIES_NAME)->write_string(item_name);
27}
28
29static GBDATA* get_selected_species(GBDATA *gb_main, AW_root *aw_root) {
30    char   *species_name = aw_root->awar(AWAR_SPECIES_NAME)->read_string();
31    GBDATA *gb_species   = 0;
32    if (species_name[0]) {
33        gb_species = GBT_find_species(gb_main, species_name);
34    }
35    free(species_name);
36    return gb_species;
37}
38
39static void add_selected_species_changed_cb(AW_root *aw_root, const RootCallback& cb) {
40    aw_root->awar(AWAR_SPECIES_NAME)->add_callback(cb);
41}
42
43static char* get_species_id(GBDATA *, GBDATA *gb_species) {
44    GBDATA *gb_name = GB_entry(gb_species, "name");
45    if (!gb_name) return 0;     // species w/o name -> skip
46    return GB_read_as_string(gb_name);
47}
48
49static GBDATA *find_species_by_id(GBDATA *gb_main, const char *id) {
50    return GBT_find_species(gb_main, id); // id is 'name' field
51}
52
53static GBDATA *get_first_species(GBDATA *gb_species_data, QUERY_RANGE range) {
54    GBDATA *gb_first = NULL;
55    switch (range) {
56        case QUERY_ALL_ITEMS:    gb_first = GBT_first_species_rel_species_data(gb_species_data); break;
57        case QUERY_MARKED_ITEMS: gb_first = GBT_first_marked_species_rel_species_data(gb_species_data); break;
58        case QUERY_CURRENT_ITEM: gb_first = get_selected_species(GB_get_root(gb_species_data), AW_root::SINGLETON); break;
59    }
60    return gb_first;
61}
62static GBDATA *get_next_species(GBDATA *gb_prev, QUERY_RANGE range) {
63    GBDATA *gb_next = NULL;
64    switch (range) {
65        case QUERY_ALL_ITEMS:    gb_next = GBT_next_species(gb_prev); break;
66        case QUERY_MARKED_ITEMS: gb_next = GBT_next_marked_species(gb_prev); break;
67        case QUERY_CURRENT_ITEM: gb_next = NULL; break;
68    }
69    return gb_next;
70}
71
72static struct MutableItemSelector ITEM_species = {
73    QUERY_ITEM_SPECIES,
74    select_species,
75    get_species_id,
76    find_species_by_id,
77    species_field_selection_list_update_cb,
78    12,
79    CHANGE_KEY_PATH,
80    "species",
81    "species",
82    "name",
83    get_first_species_data,
84    get_next_species_data,
85    get_first_species,
86    get_next_species,
87    get_selected_species,
88    add_selected_species_changed_cb,
89    0, 0,
90};
91
92static struct MutableItemSelector ITEM_organism = {
93    QUERY_ITEM_SPECIES,
94    select_species,
95    get_species_id,
96    find_species_by_id,
97    species_field_selection_list_update_cb,
98    12,
99    CHANGE_KEY_PATH,
100    "organism",
101    "organism",
102    "name",
103    get_first_species_data,
104    get_next_species_data,
105    get_first_species,
106    get_next_species,
107    get_selected_species,
108    add_selected_species_changed_cb,
109    0, 0,
110};
111
112ItemSelector& SPECIES_get_selector() { return ITEM_species; }
113ItemSelector& ORGANISM_get_selector() { return ITEM_organism; }
114
115// ----------------------------------------
116
117static void popdown_select_species_field_window(AW_root*, AW_window *aww) { aww->hide(); }
118
119void popup_select_species_field_window(AW_window *aww, FieldSelectionParam *fsp) {
120    static AW_window_simple *aws = 0;
121
122    // everytime map selection awar to latest user awar:
123    AW_root *aw_root     = aww->get_root();
124    AW_awar *common_awar = aw_root->awar(AWAR_KEY_SELECT);
125    common_awar->map(fsp->awar_name);
126
127    if (!aws) {
128        aws = new AW_window_simple;
129
130        aws->init(aw_root, "SELECT_SPECIES_FIELD", "Select species field");
131        aws->load_xfig("awt/nds_sel.fig");
132        aws->button_length(13);
133
134        aws->callback(AW_POPDOWN);
135        aws->at("close");
136        aws->create_button("CLOSE", "CLOSE", "C");
137
138        create_selection_list_on_itemfields(fsp->gb_main, aws, AWAR_KEY_SELECT, fsp->fallback2default, FIELD_FILTER_NDS, "scandb", "rescandb", SPECIES_get_selector(), 20, 10, SF_STANDARD, NULL);
139        aws->recalc_pos_atShow(AW_REPOS_TO_MOUSE);
140
141        common_awar->add_callback(makeRootCallback(popdown_select_species_field_window, static_cast<AW_window*>(aws)));
142    }
143    aws->activate();
144}
145
Note: See TracBrowser for help on using the repository browser.