ARB
NT_validManual.cxx
Go to the documentation of this file.
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 
32  const char *initials;
33 };
34 
35 // --------------------------creating and initializing AWARS----------------------------------------
37  aw_root->awar_string(AWAR_SELECTED_VALNAME, "????", aw_def);
38  aw_root->awar_string(AWAR_INPUT_INITIALS, "", aw_def);
39 }
40 
42  const char* searchstr = svnp -> initials;
43  size_t length = strlen(searchstr);
44  svnp->validNamesList->clear();
45 
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 
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 {
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 
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 
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 }
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
AW_selection_list * validNamesList
const char * GB_ERROR
Definition: arb_core.h:25
void sort(bool backward, bool case_sensitive)
Definition: AW_select.cxx:502
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:720
static void updateValNameList(AW_root *awr, selectValidNameStruct *svnp)
void insert_default(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:385
GBDATA * GB_nextEntry(GBDATA *entry)
Definition: adquery.cxx:339
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
void NT_createValidNamesAwars(AW_root *aw_root, AW_default aw_def)
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:231
void insert(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:380
#define AWAR_SELECTED_VALNAME
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
AW_window * NT_create_searchManuallyNames_window(AW_root *aw_root)
static void fillSelNamList(selectValidNameStruct *svnp)
#define AWAR_INPUT_INITIALS
#define AWAR_SPECIES_NAME
char * read_string() const
Definition: AW_awar.cxx:198
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
static void selectValidNameFromList(AW_window *selManWindowRoot)
GB_ERROR GBT_write_string(GBDATA *gb_container, const char *fieldpath, const char *content)
Definition: adtools.cxx:451
char * GB_read_string(GBDATA *gbd)
Definition: arbdb.cxx:909
AW_selection_list * create_selection_list(const char *awar_name, int columns, int rows)
Definition: AW_button.cxx:1215
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
AW_root * get_root()
Definition: aw_window.hxx:359
#define NULp
Definition: cxxforward.h:116
GBDATA * gb_main
Definition: NT_local.h:37
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:139
GBDATA * gb_main
Definition: adname.cxx:32
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
size_t length
static selectValidNameStruct * createValNameList(GBDATA *gb_main, AW_window *aws, const char *awarName)
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
NT_global GLOBAL
Definition: NT_main.cxx:46