1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : NT_validManual.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include "NT_local.h" |
---|
12 | #include <aw_awars.hxx> |
---|
13 | #include <aw_root.hxx> |
---|
14 | #include <aw_msg.hxx> |
---|
15 | #include <aw_select.hxx> |
---|
16 | #include <arbdbt.h> |
---|
17 | |
---|
18 | #include <string> |
---|
19 | #include <list> |
---|
20 | #include <vector> |
---|
21 | #include <fstream> |
---|
22 | #include <iostream> |
---|
23 | |
---|
24 | #define AWAR_SELECTED_VALNAME "tmp/validNames/selectedName" |
---|
25 | #define AWAR_INPUT_INITIALS "tmp/validNames/inputInitials" |
---|
26 | |
---|
27 | struct selectValidNameStruct { |
---|
28 | GBDATA *gb_main; |
---|
29 | AW_window *aws; |
---|
30 | AW_root *awr; |
---|
31 | AW_selection_list *validNamesList; |
---|
32 | const char *initials; |
---|
33 | }; |
---|
34 | |
---|
35 | // --------------------------creating and initializing AWARS---------------------------------------- |
---|
36 | void NT_createValidNamesAwars(AW_root *aw_root, AW_default aw_def) { |
---|
37 | aw_root->awar_string(AWAR_SELECTED_VALNAME, "????", aw_def); |
---|
38 | aw_root->awar_string(AWAR_INPUT_INITIALS, "", aw_def); |
---|
39 | } |
---|
40 | |
---|
41 | static void fillSelNamList(selectValidNameStruct* svnp) { |
---|
42 | const char* searchstr = svnp -> initials; |
---|
43 | size_t length = strlen(searchstr); |
---|
44 | svnp->validNamesList->clear(); |
---|
45 | |
---|
46 | GB_begin_transaction(GLOBAL.gb_main); |
---|
47 | |
---|
48 | GBDATA* GB_validNamesCont = GB_entry(GLOBAL.gb_main, "VALID_NAMES"); |
---|
49 | if (!GB_validNamesCont) { std::cout << "validNames Container not found\n"; } |
---|
50 | |
---|
51 | GB_ERROR err = NULp; |
---|
52 | |
---|
53 | // search validNames |
---|
54 | |
---|
55 | for (GBDATA *GB_validNamePair = GB_entry(GB_validNamesCont, "pair"); |
---|
56 | GB_validNamePair && !err; |
---|
57 | GB_validNamePair = GB_nextEntry(GB_validNamePair)) |
---|
58 | { |
---|
59 | // retrieve list of all species names |
---|
60 | GBDATA* actDesc = GB_entry(GB_validNamePair, "DESCTYPE"); |
---|
61 | char* typeString = GB_read_string(actDesc); |
---|
62 | if (strcmp(typeString, "NOTYPE") != 0) { |
---|
63 | GBDATA* newName = GB_entry(GB_validNamePair, "NEWNAME"); |
---|
64 | char* validName = newName ? GB_read_string(newName) : NULp; |
---|
65 | |
---|
66 | if (!validName) { |
---|
67 | err = GBS_global_string("Invalid names entry"); |
---|
68 | } |
---|
69 | else { |
---|
70 | // comparison with searchstr goes here |
---|
71 | // ptr to list, item to display, item value (here: equal) |
---|
72 | |
---|
73 | if (strncmp (validName, searchstr, length) == 0) { |
---|
74 | svnp->validNamesList->insert(validName, validName); |
---|
75 | } |
---|
76 | |
---|
77 | free(validName); |
---|
78 | } |
---|
79 | } |
---|
80 | free(typeString); |
---|
81 | } |
---|
82 | |
---|
83 | err = GB_end_transaction(GLOBAL.gb_main, err); |
---|
84 | if (err) aw_message(err); |
---|
85 | else { |
---|
86 | svnp->validNamesList->insert_default("????", "????"); |
---|
87 | svnp->validNamesList->sort(false, true); |
---|
88 | svnp->validNamesList->update(); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | static void updateValNameList(AW_root *awr, selectValidNameStruct *svnp) { |
---|
93 | const char* selectedName = awr->awar(AWAR_INPUT_INITIALS)->read_string(); |
---|
94 | |
---|
95 | #ifdef DUMP |
---|
96 | aw_message(GBS_global_string("now selected: %s\n", selectedName)); |
---|
97 | #endif |
---|
98 | svnp->initials = selectedName; |
---|
99 | fillSelNamList(svnp); |
---|
100 | #ifdef DUMP |
---|
101 | aw_message(GBS_global_string("SelectionList updated")); |
---|
102 | #endif |
---|
103 | } |
---|
104 | |
---|
105 | static selectValidNameStruct* createValNameList(GBDATA *gb_main, AW_window *aws, const char *awarName) { |
---|
106 | #if defined(DUMP) |
---|
107 | aw_message("ValidNameSelectionList was created"); |
---|
108 | #endif // DUMP |
---|
109 | |
---|
110 | static selectValidNameStruct* svnp = new selectValidNameStruct; // declared static |
---|
111 | |
---|
112 | svnp->aws = aws; |
---|
113 | svnp->gb_main = gb_main; |
---|
114 | svnp->validNamesList = aws->create_selection_list(awarName, 10, 20); |
---|
115 | svnp->initials = ""; |
---|
116 | |
---|
117 | fillSelNamList(svnp); |
---|
118 | return svnp; |
---|
119 | } |
---|
120 | |
---|
121 | static void selectValidNameFromList(AW_window* selManWindowRoot) { |
---|
122 | // transfers the selected valid name to selected species |
---|
123 | char *selectedValName = selManWindowRoot->get_root()->awar(AWAR_SELECTED_VALNAME)->read_string(); |
---|
124 | char *selectedSpeciesName = selManWindowRoot->get_root()->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
125 | |
---|
126 | GB_ERROR err = NULp; |
---|
127 | if (selectedSpeciesName[0] == 0) err = "No species selected"; |
---|
128 | else { |
---|
129 | err = GB_begin_transaction(GLOBAL.gb_main); |
---|
130 | if (!err) { |
---|
131 | GBDATA *gb_selected_species = GBT_find_species(GLOBAL.gb_main, selectedSpeciesName); |
---|
132 | if (!gb_selected_species) { |
---|
133 | err = GBS_global_string("species '%s' not found in database", selectedSpeciesName); |
---|
134 | } |
---|
135 | else { |
---|
136 | GBDATA *gb_name_cont = GB_search(gb_selected_species, "Valid_Name", GB_CREATE_CONTAINER); |
---|
137 | |
---|
138 | if (!gb_name_cont) err = "could not create Valid Name container in database"; |
---|
139 | else { |
---|
140 | err = GBT_write_string(gb_name_cont, "NameString", selectedValName); |
---|
141 | if (!err) err = GBT_write_string(gb_name_cont, "DescType", "MAN"); |
---|
142 | } |
---|
143 | } |
---|
144 | } |
---|
145 | err = GB_end_transaction(GLOBAL.gb_main, err); |
---|
146 | } |
---|
147 | |
---|
148 | if (err) aw_message(err); |
---|
149 | |
---|
150 | free(selectedSpeciesName); |
---|
151 | free(selectedValName); |
---|
152 | } |
---|
153 | |
---|
154 | AW_window *NT_create_searchManuallyNames_window(AW_root *aw_root) { |
---|
155 | AW_window_simple *aws = new AW_window_simple; |
---|
156 | aws->init(aw_root, "SEARCH_VALID_NAMES_MANUALLY", "Search Names Manually"); |
---|
157 | aws->load_xfig("ad_selManNam.fig"); |
---|
158 | |
---|
159 | aws->at("close"); |
---|
160 | aws->callback(AW_POPDOWN); // arb specific close callback, like a constant |
---|
161 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
162 | |
---|
163 | aws->at("help"); |
---|
164 | aws->callback(makeHelpCallback("vn_search.hlp")); |
---|
165 | aws->create_button("HELP", "HELP", "H"); |
---|
166 | |
---|
167 | aws->at("nameList"); |
---|
168 | // creates the selection list and asign AWAR_SELECTED_VALNAME |
---|
169 | |
---|
170 | selectValidNameStruct *vns = createValNameList(GLOBAL.gb_main, aws, AWAR_SELECTED_VALNAME); |
---|
171 | |
---|
172 | aws->at("select"); |
---|
173 | aws->callback(selectValidNameFromList); |
---|
174 | aws->create_button("SELECT", "SELECT"); |
---|
175 | |
---|
176 | aws->at("enterInitial"); |
---|
177 | aws->create_input_field(AWAR_INPUT_INITIALS, 30); |
---|
178 | |
---|
179 | aw_root->awar(AWAR_INPUT_INITIALS)->add_callback(makeRootCallback(updateValNameList, vns)); |
---|
180 | |
---|
181 | |
---|
182 | return aws; |
---|
183 | |
---|
184 | } |
---|