source: tags/arb_5.0/AWT/AWT_changekey.cxx

Last change on this file was 5953, checked in by westram, 15 years ago
  • awt_create_selection_list_on_scand
    • pass label for popup button - currently there are multiple buttons with same remote-command-id in query window, this offers a way to fix it.
    • packed two bool params ('add_all_fields_pseudo_field' and 'include_hidden_fields') into enum 'awt_selected_fields'
  • moved awt_changekey.hxx to (empty) awt_item_sel_list.hxx
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1// ==================================================================== //
2//                                                                      //
3//   File      : AWT_changekey.cxx                                      //
4//   Purpose   : changekey management                                   //
5//                                                                      //
6//                                                                      //
7// Coded by Ralf Westram (coder@reallysoft.de) in May 2005              //
8// Copyright Department of Microbiology (Technical University Munich)   //
9//                                                                      //
10// Visit our web site at: http://www.arb-home.de/                       //
11//                                                                      //
12// ==================================================================== //
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17
18#include <aw_awars.hxx>
19#include <arbdb.h>
20#include <arbdbt.h>
21
22#include "awt.hxx"
23#include "awt_item_sel_list.hxx"
24
25static const char GENE_DATA_PATH[]       = "gene_data/gene/";
26static const char EXPERIMENT_DATA_PATH[] = "experiment_data/experiment/";
27
28#define GENE_DATA_PATH_LEN       (sizeof(GENE_DATA_PATH)-1)
29#define EXPERIMENT_DATA_PATH_LEN (sizeof(EXPERIMENT_DATA_PATH)-1)
30
31inline bool is_in_GENE_path(const char *fieldpath)          { return strncmp(fieldpath, GENE_DATA_PATH,         GENE_DATA_PATH_LEN) == 0; }
32inline bool is_in_EXPERIMENT_path(const char *fieldpath)    { return strncmp(fieldpath, EXPERIMENT_DATA_PATH,   EXPERIMENT_DATA_PATH_LEN) == 0; }
33
34inline bool is_in_reserved_path(const char *fieldpath)  {
35    return
36        is_in_GENE_path(fieldpath) ||
37        is_in_EXPERIMENT_path(fieldpath);
38}
39
40// --------------------------------------------------------------------------------
41
42
43static void awt_delete_unused_changekeys(GBDATA *gb_main, const char **names, const char *change_key_path) {
44    // deletes all keys from 'change_key_path' which are not listed in 'names'
45    GBDATA *gb_key_data = GB_search(gb_main, change_key_path, GB_CREATE_CONTAINER);
46    GBDATA *gb_key      = gb_key_data ? GB_entry(gb_key_data, CHANGEKEY) : 0;
47
48    while (gb_key) {
49        bool        found    = false;
50        int         key_type = *GBT_read_int(gb_key, CHANGEKEY_TYPE);
51        const char *key_name = GBT_read_char_pntr(gb_key, CHANGEKEY_NAME);
52
53        for (const char **name = names; *name; ++name) {
54            if (strcmp(key_name, (*name)+1) == 0) { // key with this name exists
55                if (key_type == (*name)[0]) {
56                    found = true;
57                }
58                // otherwise key exists, but type mismatches = > delete this key
59                break;
60            }
61        }
62
63        awt_assert(GB_has_key(gb_key, CHANGEKEY));
64        GBDATA *gb_next_key = GB_nextEntry(gb_key);
65
66        if (!found) {
67            if (key_type == GB_DB) { // it's a container
68                // test if any subkey is used
69                int keylen = strlen(key_name);
70                for (const char **name = names; *name; ++name) {
71                    const char *n = (*name)+1;
72
73                    if (strncmp(key_name, n, keylen) == 0 && n[keylen] == '/') { // found a subkey -> do not delete
74                        found = true;
75                        break;
76                    }
77                }
78            }
79
80            if (!found) {       // key no longer exists = > delete from key list
81                GB_delete(gb_key);
82            }
83        }
84
85        gb_key = gb_next_key;
86    }
87}
88
89static void awt_show_all_changekeys(GBDATA *gb_main, const char *change_key_path) {
90    GBDATA *gb_key_data = GB_search(gb_main, change_key_path, GB_CREATE_CONTAINER);
91    for (GBDATA *gb_key = gb_key_data ? GB_entry(gb_key_data, CHANGEKEY) : 0;
92         gb_key;
93         gb_key = GB_nextEntry(gb_key))
94    {
95        GBDATA *gb_key_hidden = GB_entry(gb_key, CHANGEKEY_HIDDEN);
96        if (gb_key_hidden) {
97            if (GB_read_int(gb_key_hidden)) GB_write_int(gb_key_hidden, 0); // unhide
98        }
99    }
100}
101
102void awt_selection_list_rescan(GBDATA *gb_main, long bitfilter, awt_rescan_mode mode) {
103    GB_push_transaction(gb_main);
104    char   **names;
105    char   **name;
106    GBDATA  *gb_species_data = GB_search(gb_main,"species_data",GB_CREATE_CONTAINER);
107
108    names = GBT_scan_db(gb_species_data, 0);
109
110    if (mode & AWT_RS_DELETE_UNUSED_FIELDS) awt_delete_unused_changekeys(gb_main, const_cast<const char **>(names), CHANGE_KEY_PATH);
111    if (mode & AWT_RS_SHOW_ALL) awt_show_all_changekeys(gb_main, CHANGE_KEY_PATH);
112
113    if (mode & AWT_RS_SCAN_UNKNOWN_FIELDS) {
114        GBT_add_new_changekey(gb_main,"name",GB_STRING);
115        GBT_add_new_changekey(gb_main,"acc",GB_STRING);
116        GBT_add_new_changekey(gb_main,"full_name",GB_STRING);
117        GBT_add_new_changekey(gb_main,"group_name",GB_STRING);
118        GBT_add_new_changekey(gb_main,"tmp",GB_STRING);
119
120        for (name = names; *name; name++) {
121            if ( (1<<(**name)) & bitfilter ) {  // look if already exists
122                if (!is_in_reserved_path((*name)+1)) { // ignore gene, experiment, ... entries
123                    GBT_add_new_changekey(gb_main,(*name)+1,(int)*name[0]);
124                }
125            }
126        }
127    }
128
129    GBT_free_names(names);
130    GB_pop_transaction(gb_main);
131}
132
133
134
135void awt_gene_field_selection_list_rescan(GBDATA *gb_main, long bitfilter, awt_rescan_mode mode) {
136    GB_push_transaction(gb_main);
137    char   **names;
138    char   **name;
139    GBDATA  *gb_species_data = GB_search(gb_main,"species_data",GB_CREATE_CONTAINER);
140
141    names = GBT_scan_db(gb_species_data, GENE_DATA_PATH);
142
143    if (mode & AWT_RS_DELETE_UNUSED_FIELDS) awt_delete_unused_changekeys(gb_main, const_cast<const char **>(names), CHANGE_KEY_PATH_GENES);
144    if (mode & AWT_RS_SHOW_ALL) awt_show_all_changekeys(gb_main, CHANGE_KEY_PATH_GENES);
145
146    if (mode & AWT_RS_SCAN_UNKNOWN_FIELDS) {
147        GBT_add_new_gene_changekey(gb_main,"name", GB_STRING);
148
149        GBT_add_new_gene_changekey(gb_main,"pos_start", GB_STRING);
150        GBT_add_new_gene_changekey(gb_main,"pos_stop", GB_STRING);
151        GBT_add_new_gene_changekey(gb_main,"pos_complement", GB_STRING);
152       
153        GBT_add_new_gene_changekey(gb_main,"pos_joined", GB_INT);
154        GBT_add_new_gene_changekey(gb_main,"pos_certain", GB_STRING);
155
156        for (name = names; *name; name++) {
157            if ( (1<<(**name)) & bitfilter ) {          // look if already exists
158                GBT_add_new_gene_changekey(gb_main,(*name)+1,(int)*name[0]);
159            }
160        }
161    }
162
163    GBT_free_names(names);
164    GB_pop_transaction(gb_main);
165}
166
167void awt_experiment_field_selection_list_rescan(GBDATA *gb_main, long bitfilter, awt_rescan_mode mode) {
168    GB_push_transaction(gb_main);
169    char   **names;
170    char   **name;
171    GBDATA  *gb_species_data = GB_search(gb_main,"species_data",GB_CREATE_CONTAINER);
172
173    names = GBT_scan_db(gb_species_data, EXPERIMENT_DATA_PATH);
174
175    if (mode & AWT_RS_DELETE_UNUSED_FIELDS) awt_delete_unused_changekeys(gb_main, const_cast<const char **>(names), CHANGE_KEY_PATH_EXPERIMENTS);
176    if (mode & AWT_RS_SHOW_ALL) awt_show_all_changekeys(gb_main, CHANGE_KEY_PATH_EXPERIMENTS);
177
178    if (mode & AWT_RS_SCAN_UNKNOWN_FIELDS) {
179        GBT_add_new_experiment_changekey(gb_main,"name", GB_STRING);
180
181        for (name = names; *name; name++) {
182            if ( (1<<(**name)) & bitfilter ) { // look if already exists
183                if (is_in_EXPERIMENT_path((*name)+1)) {
184                    GBT_add_new_experiment_changekey(gb_main,(*name)+1+EXPERIMENT_DATA_PATH_LEN,(int)*name[0]);
185                }
186            }
187        }
188    }
189
190    GBT_free_names(names);
191    GB_pop_transaction(gb_main);
192}
193
194void awt_selection_list_scan_unknown_cb(AW_window *,GBDATA *gb_main, long bitfilter)    { awt_selection_list_rescan(gb_main,bitfilter, AWT_RS_SCAN_UNKNOWN_FIELDS); }
195void awt_selection_list_delete_unused_cb(AW_window *,GBDATA *gb_main, long bitfilter)   { awt_selection_list_rescan(gb_main,bitfilter, AWT_RS_DELETE_UNUSED_FIELDS); }
196void awt_selection_list_unhide_all_cb(AW_window *,GBDATA *gb_main, long bitfilter)      { awt_selection_list_rescan(gb_main,bitfilter, AWT_RS_SHOW_ALL); }
197void awt_selection_list_update_cb(AW_window *,GBDATA *gb_main, long bitfilter)          { awt_selection_list_rescan(gb_main,bitfilter, AWT_RS_UPDATE_FIELDS); }
198
199void awt_gene_field_selection_list_scan_unknown_cb(AW_window *,GBDATA *gb_main, long bitfilter)     { awt_gene_field_selection_list_rescan(gb_main,bitfilter, AWT_RS_SCAN_UNKNOWN_FIELDS); }
200void awt_gene_field_selection_list_delete_unused_cb(AW_window *,GBDATA *gb_main, long bitfilter)    { awt_gene_field_selection_list_rescan(gb_main,bitfilter, AWT_RS_DELETE_UNUSED_FIELDS); }
201void awt_gene_field_selection_list_unhide_all_cb(AW_window *,GBDATA *gb_main, long bitfilter)    { awt_gene_field_selection_list_rescan(gb_main,bitfilter, AWT_RS_SHOW_ALL); }
202void awt_gene_field_selection_list_update_cb(AW_window *,GBDATA *gb_main, long bitfilter)           { awt_gene_field_selection_list_rescan(gb_main,bitfilter, AWT_RS_UPDATE_FIELDS); }
203
204void awt_experiment_field_selection_list_scan_unknown_cb(AW_window *,GBDATA *gb_main, long bitfilter)   { awt_experiment_field_selection_list_rescan(gb_main,bitfilter, AWT_RS_SCAN_UNKNOWN_FIELDS); }
205void awt_experiment_field_selection_list_delete_unused_cb(AW_window *,GBDATA *gb_main, long bitfilter)  { awt_experiment_field_selection_list_rescan(gb_main,bitfilter, AWT_RS_DELETE_UNUSED_FIELDS); }
206void awt_experiment_field_selection_list_unhide_all_cb(AW_window *,GBDATA *gb_main, long bitfilter)  { awt_experiment_field_selection_list_rescan(gb_main,bitfilter, AWT_RS_SHOW_ALL); }
207void awt_experiment_field_selection_list_update_cb(AW_window *,GBDATA *gb_main, long bitfilter)         { awt_experiment_field_selection_list_rescan(gb_main,bitfilter, AWT_RS_UPDATE_FIELDS); }
Note: See TracBrowser for help on using the repository browser.