source: branches/ali/SL/ITEMS/species.cxx

Last change on this file was 18211, checked in by westram, 5 years ago
  • add new QUERY_ITEM_TYPE for organisms: QUERY_ITEM_ORGANISM
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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 NULp; // 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}
28static void select_organism(GBDATA*,  AW_root *aw_root, const char *item_name) {
29    aw_root->awar(AWAR_ORGANISM_NAME)->write_string(item_name);
30}
31
32static GBDATA* get_selected_species(GBDATA *gb_main, AW_root *aw_root) {
33    const char *species_name = aw_root->awar(AWAR_SPECIES_NAME)->read_char_pntr();
34    return species_name[0] ? GBT_find_species(gb_main, species_name) : NULp;
35}
36static GBDATA* get_selected_organism(GBDATA *gb_main, AW_root *aw_root) {
37    const char *organism_name = aw_root->awar(AWAR_ORGANISM_NAME)->read_char_pntr();
38    return organism_name[0] ? GEN_find_organism(gb_main, organism_name) : NULp;
39}
40
41static void add_selected_species_changed_cb(AW_root *aw_root, const RootCallback& cb) {
42    aw_root->awar(AWAR_SPECIES_NAME)->add_callback(cb);
43}
44
45static char* get_species_id(GBDATA *, GBDATA *gb_species) {
46    GBDATA *gb_name = GB_entry(gb_species, "name");
47    if (!gb_name) return NULp; // species w/o name -> skip
48    return GB_read_as_string(gb_name);
49}
50
51static GBDATA *find_species_by_id(GBDATA *gb_main, const char *id) {
52    return GBT_find_species(gb_main, id); // id is 'name' field
53}
54
55static GBDATA *get_first_species(GBDATA *gb_species_data, QUERY_RANGE range) {
56    GBDATA *gb_first = NULp;
57    switch (range) {
58        case QUERY_ALL_ITEMS:    gb_first = GBT_first_species_rel_species_data(gb_species_data); break;
59        case QUERY_MARKED_ITEMS: gb_first = GBT_first_marked_species_rel_species_data(gb_species_data); break;
60        case QUERY_CURRENT_ITEM: gb_first = get_selected_species(GB_get_root(gb_species_data), AW_root::SINGLETON); break;
61    }
62    return gb_first;
63}
64static GBDATA *get_next_species(GBDATA *gb_prev, QUERY_RANGE range) {
65    GBDATA *gb_next = NULp;
66    switch (range) {
67        case QUERY_ALL_ITEMS:    gb_next = GBT_next_species(gb_prev); break;
68        case QUERY_MARKED_ITEMS: gb_next = GBT_next_marked_species(gb_prev); break;
69        case QUERY_CURRENT_ITEM: gb_next = NULp; break;
70    }
71    return gb_next;
72}
73static GBDATA *get_first_organism(GBDATA *gb_species_data, QUERY_RANGE range) {
74    GBDATA *gb_first = NULp;
75    GBDATA *gb_main  = GB_get_root(gb_species_data);
76    switch (range) {
77        case QUERY_ALL_ITEMS:    gb_first = GEN_first_organism(gb_main); break;
78        case QUERY_MARKED_ITEMS: gb_first = GEN_first_marked_organism(gb_main); break;
79        case QUERY_CURRENT_ITEM: gb_first = get_selected_organism(gb_main, AW_root::SINGLETON); break;
80    }
81    return gb_first;
82}
83static GBDATA *get_next_organism(GBDATA *gb_prev, QUERY_RANGE range) {
84    GBDATA *gb_next = NULp;
85    switch (range) {
86        case QUERY_ALL_ITEMS:    gb_next = GEN_next_organism(gb_prev); break;
87        case QUERY_MARKED_ITEMS: gb_next = GEN_next_marked_organism(gb_prev); break;
88        case QUERY_CURRENT_ITEM: gb_next = NULp; break;
89    }
90    return gb_next;
91}
92
93static void refresh_displayed_species() {
94    AW_root::SINGLETON->awar(AWAR_TREE_REFRESH)->touch();
95}
96
97static struct MutableItemSelector ITEM_species = {
98    QUERY_ITEM_SPECIES,
99    select_species,
100    get_species_id,
101    find_species_by_id,
102    species_field_selection_list_update_cb,
103    12,
104    CHANGE_KEY_PATH,
105    "species",
106    "species",
107    "name",
108    get_first_species_data,
109    get_next_species_data,
110    get_first_species,
111    get_next_species,
112    get_selected_species,
113    add_selected_species_changed_cb,
114    NULp, NULp,
115    refresh_displayed_species,
116};
117
118static struct MutableItemSelector ITEM_organism = {
119    QUERY_ITEM_ORGANISM,
120    select_organism,
121    get_species_id,
122    find_species_by_id,
123    species_field_selection_list_update_cb,
124    12,
125    CHANGE_KEY_PATH,
126    "organism",
127    "organisms",
128    "name",
129    get_first_species_data,
130    get_next_species_data,
131    get_first_organism,
132    get_next_organism,
133    get_selected_organism,
134    add_selected_species_changed_cb,
135    NULp, NULp,
136    refresh_displayed_species,
137};
138
139ItemSelector& SPECIES_get_selector() { return ITEM_species; }
140ItemSelector& ORGANISM_get_selector() { return ITEM_organism; }
141
Note: See TracBrowser for help on using the repository browser.