ARB
ui_species.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : ui_species.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include "dbui.h"
12 
13 #include <awtc_next_neighbours.hxx>
14 #include <probe_gui.hxx>
15 #include <item_sel_list.h>
16 #include <info_window.h>
17 #include <db_query.h>
18 
19 #include <awt_sel_boxes.hxx>
20 #include <awt_config_manager.hxx>
21 #include <awt_prompt.hxx>
22 
23 #include <AW_rename.hxx>
24 
25 #include <aw_awar_defs.hxx>
26 #include <aw_root.hxx>
27 #include <aw_msg.hxx>
28 #include <aw_question.hxx>
29 
30 #include <arb_defs.h>
31 #include <arb_strbuf.h>
32 #include <arb_progress.h>
33 
34 #include <algorithm>
35 #include <cmath>
36 #include <map>
37 
38 using namespace DBUI;
39 using namespace QUERY;
40 
41 #define ui_assert(cond) arb_assert(cond)
42 
43 // awars shared between different itemtypes:
44 #define AWAR_FIELD_REORDER_ORDER "tmp/adreorder/order"
45 
46 // separate awars for different itemtypes:
47 #define AWAR_FIELD_REORDER_SOURCE_TMPL "tmp/adreorder/%s/source"
48 #define AWAR_FIELD_REORDER_DEST_TMPL "tmp/adreorder/%s/dest"
49 #define AWAR_FIELD_CREATE_NAME_TMPL "tmp/adfield/%s/name"
50 #define AWAR_FIELD_CREATE_TYPE_TMPL "tmp/adfield/%s/type"
51 #define AWAR_FIELD_DELETE_TMPL "tmp/adfield/%s/source"
52 #define AWAR_FIELD_CONVERT_SOURCE_TMPL "tmp/adconvert/%s/source"
53 #define AWAR_FIELD_CONVERT_TYPE_TMPL "tmp/adconvert/%s/type"
54 
55 // next neighbours of listed and selected:
56 // more defined in ../../AWTC/awtc_next_neighbours.hxx@AWAR_NN_BASE
57 #define AWAR_NN_COMPLEMENT AWAR_NN_BASE "complement"
58 #define AWAR_NN_RANGE_START AWAR_NN_BASE "range_start"
59 #define AWAR_NN_RANGE_END AWAR_NN_BASE "range_end"
60 #define AWAR_NN_MIN_SCORE AWAR_NN_BASE "min_scored"
61 #define AWAR_NN_MAX_HITS AWAR_NN_BASE "max_hits"
62 
63 // next neighbours of selected only:
64 #define AWAR_NN_BASE_SELECTED AWAR_NN_BASE "selected/"
65 #define AWAR_NN_SELECTED_HIT_COUNT "tmp/" AWAR_NN_BASE_SELECTED "hit_count"
66 #define AWAR_NN_SELECTED_AUTO_SEARCH "tmp/" AWAR_NN_BASE_SELECTED "auto_search"
67 #define AWAR_NN_SELECTED_AUTO_MARK "tmp/" AWAR_NN_BASE_SELECTED "auto_mark"
68 
69 // next neighbours of listed only:
70 #define AWAR_NN_BASE_LISTED AWAR_NN_BASE "listed/"
71 #define AWAR_NN_LISTED_DEST_FIELD AWAR_NN_BASE_LISTED "dest_field"
72 #define AWAR_NN_LISTED_SCORED_ENTRIES AWAR_NN_BASE_LISTED "scored_entries"
73 
75  // real orders
79 
80  // special modes
83 };
84 
87 }
88 
89 inline const char *itemAwar(const char *name_template, ItemSelector& itype) {
90  return GBS_global_string(name_template, itype.item_name);
91 }
92 static void init_itemspecific_DBUI_awars(AW_root *aw_root, ItemSelector& itype) {
93  static bool initialized[QUERY_ITEM_TYPES] = { false };
94 
95  if (!initialized[itype.type]) {
103 
104  initialized[itype.type] = true;
105  }
106 }
107 
109  char *source = aww->get_root()->awar(AWAR_SPECIES_NAME)->read_string();
111 
112  if (!error) {
113  GBDATA *gb_sai_data = GBT_get_SAI_data(gb_main);
114  if (!gb_sai_data) error = GB_await_error();
115  else {
116  GBDATA *gb_species = GBT_find_species(gb_main, source);
117  GBDATA *gb_dest = GBT_find_SAI_rel_SAI_data(gb_sai_data, source);
118 
119  if (gb_dest) error = GBS_global_string("SAI '%s' already exists", source);
120  else if (gb_species) {
121  gb_dest = GB_create_container(gb_sai_data, "extended");
122  if (!gb_dest) error = GB_await_error();
123  else {
124  error = GB_copy_dropProtectMarksAndTempstate(gb_dest, gb_species);
125  if (!error) {
126  error = GB_delete(gb_species);
127  if (!error) aww->get_root()->awar(AWAR_SPECIES_NAME)->write_string("");
128  }
129  }
130  }
131  else error = "Please select a species";
132  }
133  }
134  GB_end_transaction_show_error(gb_main, error, aw_message);
135  free(source);
136 }
137 
138 
139 static GB_ERROR species_create_handler(const char *dest, GBDATA *gb_main) {
140  GB_ERROR error = NULp;
141  if (dest[0]) {
142  error = GB_begin_transaction(gb_main);
143  if (!error) {
145  if (!gb_species_data) error = GB_await_error();
146  else {
147  GBDATA *gb_dest = GBT_find_species_rel_species_data(gb_species_data, dest);
148 
149  if (gb_dest) error = GBS_global_string("Species '%s' already exists", dest);
150  else {
151  gb_dest = GBT_find_or_create_species_rel_species_data(gb_species_data, dest, true);
152  if (!gb_dest) error = GB_await_error();
154  }
155  }
156  }
157  error = GB_end_transaction(gb_main, error);
158  }
159  else {
160  error = "Please enter a name for the new species";
161  }
162  return error;
163 }
164 
166  AWT_activate_prompt("Create new species", "Enter shortname (ID) of new species:", "", "Create", makeResultHandler(species_create_handler, gb_main), "spa_create.hlp");
167 }
168 
169 static GBDATA *expect_species_selected(AW_root *aw_root, GBDATA *gb_main, char **give_name = NULp) {
170  GB_transaction ta(gb_main);
171  char *name = aw_root->awar(AWAR_SPECIES_NAME)->read_string();
172  GBDATA *gb_species = GBT_find_species(gb_main, name);
173 
174  if (!gb_species) {
175  if (name && name[0]) aw_message(GBS_global_string("Species '%s' does not exist.", name));
176  else aw_message("Please select a species first");
177  }
178 
179  if (give_name) *give_name = name;
180  else free(name);
181 
182  return gb_species;
183 }
184 
186  AW_root *aw_root = aww->get_root();
187  char *name;
188  GBDATA *gb_species = expect_species_selected(aw_root, gb_main, &name);
189 
190  if (gb_species) {
191  GB_transaction ta(gb_main);
192  GBDATA *gb_species_data = GB_get_father(gb_species);
193  UniqueNameDetector und(gb_species_data);
194  GB_ERROR error = NULp;
195  char *copy_name = AWTC_makeUniqueShortName(GBS_global_string("c%s", name), und);
196 
197  if (!copy_name) error = GB_await_error();
198  else {
199  GBDATA *gb_new_species = GB_create_container(gb_species_data, "species");
200 
201  if (!gb_new_species) error = GB_await_error();
202  else {
203  error = GB_copy_dropProtectMarksAndTempstate(gb_new_species, gb_species);
204  if (!error) {
205  error = GBT_write_string(gb_new_species, "name", copy_name);
206  if (!error) aw_root->awar(AWAR_SPECIES_NAME)->write_string(copy_name); // set focus
207  }
208  }
209 
210  free(copy_name);
211  }
212  if (error) {
213  error = ta.close(error);
214  aw_message(error);
215  }
216  }
217 }
218 
219 static GB_ERROR species_rename_handler(const char *new_fullname, GBDATA *gb_species) {
220  GB_transaction ta(gb_species);
221 
222  GBDATA *gb_full_name = GB_search(gb_species, "full_name", GB_STRING);
223  const char *old_fullname = GB_read_char_pntr(gb_full_name);
224 
225  GB_ERROR error = NULp;
226  if (strcmp(old_fullname, new_fullname) == 0) {
227  error = "[nothing changed]";
228  }
229  else {
230  error = GB_write_string(gb_full_name, new_fullname);
231  }
232 
233  if (!error) {
235  bool recreateID = ARB_in_expert_mode(awr) && // never re-create ID in novice mode
236  aw_ask_sure("recreate_name_field",
237  "Regenerate species identifier ('name')?\n"
238  "(only do this if you know what you're doing)");
239  if (recreateID) {
240  arb_progress progress("Regenerating species ID", 1L);
241  error = AWTC_recreate_name(gb_species);
242  if (!error) awr->awar(AWAR_SPECIES_NAME)->write_string(null2empty(GBT_get_name(gb_species))); // set focus
243  }
244  }
245 
246  error = ta.close(error);
247 
248  return error;
249 }
251  AW_root *aw_root = aww->get_root();
252  GBDATA *gb_species = expect_species_selected(aw_root, gb_main);
253 
254  if (gb_species) {
255  const char *full_name;
256  {
257  GB_transaction ta(gb_main);
258  GBDATA *gb_full_name = GB_search(gb_species, "full_name", GB_STRING);
259 
260  full_name = gb_full_name ? GB_read_char_pntr(gb_full_name) : "";
261  }
262  AWT_activate_prompt("Rename species", "Modify 'full_name' of species:", full_name, "Rename", makeResultHandler(species_rename_handler, gb_species), "spa_rename.hlp");
263  }
264 }
265 
267  AW_root *aw_root = aww->get_root();
268  char *name;
269  GBDATA *gb_species = expect_species_selected(aw_root, gb_main, &name);
270  GB_ERROR error = NULp;
271 
272  if (!gb_species) {
273  error = "Please select a species first";
274  }
275  else if (aw_ask_sure("info_delete_species", GBS_global_string("Are you sure to delete the species '%s'?", name))) {
276  GB_transaction ta(gb_main);
277  error = GB_delete(gb_species);
278  error = ta.close(error);
279  if (!error) aw_root->awar(AWAR_SPECIES_NAME)->write_string("");
280  }
281 
282  if (error) aw_message(error);
283  free(name);
284 }
285 
286 static long count_field_occurrence(BoundItemSel *bsel, const char *field_name) {
288  long count = 0;
289  ItemSelector& sel = bsel->selector;
290 
291  for (GBDATA *gb_container = sel.get_first_item_container(bsel->gb_main, NULp, RANGE);
292  gb_container;
293  gb_container = sel.get_next_item_container(gb_container, RANGE))
294  {
295  for (GBDATA *gb_item = sel.get_first_item(gb_container, RANGE);
296  gb_item;
297  gb_item = sel.get_next_item(gb_item, RANGE))
298  {
299  GBDATA *gb_field = GB_entry(gb_item, field_name);
300  if (gb_field) ++count;
301  }
302  }
303  return count;
304 }
305 
306 class KeySorter : virtual Noncopyable {
307  int key_count;
308  GBDATA **key;
309 
310  int field_count; // = key_count - container_count
311 
312  bool order_changed;
313 
314  // helper variables for sorting
315  static GB_HASH *order_hash;
316  static BoundItemSel *bitem_selector;
317  static arb_progress *sort_progress;
318 
319  bool legal_pos(int p) { return p >= 0 && p<key_count; }
320  bool legal_field_pos(int p) const { return p >= 0 && p<field_count; }
321  bool legal_field_pos(int p1, int p2) const { return legal_field_pos(p1) && legal_field_pos(p2); }
322 
323  void swap(int p1, int p2) {
324  ui_assert(legal_pos(p1));
325  ui_assert(legal_pos(p2));
326 
327  GBDATA *k = key[p1];
328  key[p1] = key[p2];
329  key[p2] = k;
330 
331  order_changed = true;
332  }
333 
334  const char *field_name(int p) const {
335  GBDATA *gb_key_name = GB_entry(key[p], "key_name");
336  if (gb_key_name) return GB_read_char_pntr(gb_key_name);
337  return NULp;
338  }
339  GB_TYPES field_type(int p) const {
340  GBDATA *gb_key_type = GB_entry(key[p], "key_type");
341  if (gb_key_type) return GB_TYPES(GB_read_int(gb_key_type));
342  return GB_NONE;
343  }
344  int field_freq(int p) const {
345  const char *name = field_name(p);
346  if (!order_hash) order_hash = GBS_create_hash(key_count, GB_IGNORE_CASE);
347 
348  long freq = GBS_read_hash(order_hash, name);
349  if (!freq) {
350  freq = 1+count_field_occurrence(bitem_selector, name);
351  GBS_write_hash(order_hash, name, freq);
352  if (sort_progress) sort_progress->inc();
353  }
354  return freq;
355  }
356 
357  int compare(int p1, int p2, ReorderMode mode) {
358  switch (mode) {
359  case RIGHT_BEHIND_LEFT:
360  case REVERSE_ORDER:
361  ui_assert(0); // illegal ReorderMode
362  break;
363 
364  case ORDER_TYPE: return field_type(p2)-field_type(p1);
365  case ORDER_ALPHA: return strcasecmp(field_name(p1), field_name(p2));
366  case ORDER_FREQ: return field_freq(p2)-field_freq(p1);
367  }
368  return p2-p1; // keep order
369  }
370 
371 public:
372  KeySorter(GBDATA *gb_key_data) {
373  key_count = 0;
374  field_count = 0;
375  key = NULp;
376 
377  for (GBDATA *gb_key = GB_child(gb_key_data); gb_key; gb_key = GB_nextChild(gb_key)) {
378  key_count++;
379  }
380 
381  if (key_count) {
382  ARB_alloc(key, key_count);
383 
384  int container_count = 0;
385  for (GBDATA *gb_key = GB_child(gb_key_data); gb_key; gb_key = GB_nextChild(gb_key)) {
386  GBDATA *gb_type = GB_entry(gb_key, CHANGEKEY_TYPE);
387  GB_TYPES type = GB_TYPES(GB_read_int(gb_type));
388 
389  if (type == GB_DB) { // move containers behind fields
390  key[key_count-1-container_count++] = gb_key;
391  }
392  else {
393  key[field_count++] = gb_key;
394  }
395  }
396  ui_assert((container_count+field_count) == key_count);
397  reverse_order(field_count, key_count-1); // of containers
398  }
399  order_changed = false;
400  }
402  ui_assert(!order_changed); // order changed but not written
403  free(key);
404  }
405 
406  int get_field_count() const { return field_count; }
407 
408  void bubble_sort(int p1, int p2, ReorderMode mode, BoundItemSel *selector) {
409  if (p1>p2) std::swap(p1, p2);
410  if (legal_field_pos(p1, p2)) {
411  if (mode == ORDER_FREQ) {
412  sort_progress = new arb_progress("Calculating field frequencies", long(p2-p1+1));
413  }
414  bitem_selector = selector;
415  while (p1<p2) {
416  bool changed = false;
417 
418  int i = p2;
419  while (i>p1) {
420  if (compare(i-1, i, mode)>0) {
421  swap(i-1, i);
422  changed = true;
423  }
424  --i;
425  }
426  if (!changed) break;
427  ++p1;
428  }
429  if (order_hash) {
430  GBS_free_hash(order_hash);
431  order_hash = NULp;
432  }
433  if (sort_progress) {
434  delete sort_progress;
435  sort_progress = NULp;
436  }
437  }
438  }
439  void reverse_order(int p1, int p2) {
440  if (p1>p2) std::swap(p1, p2);
441  if (legal_field_pos(p1, p2)) while (p1<p2) swap(p1++, p2--);
442  }
443 
444  int index_of(GBDATA *gb_key) {
445  int i;
446  for (i = 0; i<key_count; i++) {
447  if (gb_key == key[i]) break;
448  }
449  if (i == key_count) {
450  ui_assert(0);
451  i = -1;
452  }
453  return i;
454  }
455 
456  void move_to(int to_move, int wanted_position) {
457  if (legal_field_pos(to_move, wanted_position)) {
458  while (to_move<wanted_position) {
459  swap(to_move, to_move+1);
460  to_move++;
461  }
462  while (to_move>wanted_position) {
463  swap(to_move, to_move-1);
464  to_move--;
465  }
466  }
467  }
468 
471  if (order_changed) {
472  if (key_count) {
473  GBDATA *gb_main = GB_get_root(key[0]);
474  warning = GB_resort_data_base(gb_main, key, key_count);
475  }
476  order_changed = false;
477  }
478  return warning;
479  }
480 };
481 
482 GB_HASH *KeySorter::order_hash = NULp;
483 BoundItemSel *KeySorter::bitem_selector = NULp;
484 arb_progress *KeySorter::sort_progress = NULp;
485 
486 static void reorder_keys(AW_window *aws, ReorderMode mode, Itemfield_Selection *sel_left, Itemfield_Selection *sel_right) {
487  ItemSelector& selector = sel_left->get_selector();
488  ui_assert(&selector == &sel_right->get_selector());
489 
490  int left_index = sel_left->get_sellist()->get_index_of_selected();
491  int right_index = sel_right->get_sellist()->get_index_of_selected();
492 
494 
495  GBDATA *gb_main = sel_left->get_gb_main();
496  AW_root *awr = aws->get_root();
497 
498  init_itemspecific_DBUI_awars(awr, selector);
499 
500  GB_begin_transaction(gb_main);
501 
502  GBDATA *gb_left_field = GBT_get_changekey(gb_main, awr->awar(itemAwar(AWAR_FIELD_REORDER_SOURCE_TMPL, selector))->read_char_pntr(), selector.change_key_path);
503  GBDATA *gb_right_field = GBT_get_changekey(gb_main, awr->awar(itemAwar(AWAR_FIELD_REORDER_DEST_TMPL, selector))->read_char_pntr(), selector.change_key_path);
504 
505  if (!gb_left_field || !gb_right_field || gb_left_field == gb_right_field) {
506  warning = "Please select different fields in both list";
507  }
508  else {
509  GBDATA *gb_key_data = GB_search(gb_main, selector.change_key_path, GB_CREATE_CONTAINER);
510  KeySorter sorter(gb_key_data);
511 
512  int left_key_idx = sorter.index_of(gb_left_field);
513  int right_key_idx = sorter.index_of(gb_right_field);
514 
515  switch (mode) {
516  case RIGHT_BEHIND_LEFT:
517  sorter.move_to(right_key_idx, left_key_idx+(left_key_idx<right_key_idx));
518  if (right_index>left_index) { left_index++; right_index++; } // make it simple to move several consecutive keys
519  break;
520  case REVERSE_ORDER:
521  sorter.reverse_order(left_key_idx, right_key_idx);
522  std::swap(left_index, right_index);
523  break;
524  default: {
525  BoundItemSel bis(gb_main, selector);
526  sorter.bubble_sort(left_key_idx, right_key_idx, mode, &bis);
527  break;
528  }
529  }
530 
531  warning = sorter.save_changes();
532  }
533  GB_commit_transaction(gb_main);
534 
535  if (warning) {
536  aw_message(warning);
537  }
538  else {
539  sel_left->get_sellist()->select_element_at(left_index);
540  sel_right->get_sellist()->select_element_at(right_index);
541  }
542 }
543 
544 static void reorder_right_behind_left(AW_window *aws, Itemfield_Selection *selleft, Itemfield_Selection *selright) { reorder_keys(aws, RIGHT_BEHIND_LEFT, selleft, selright); }
545 static void reverse_key_order (AW_window *aws, Itemfield_Selection *selleft, Itemfield_Selection *selright) { reorder_keys(aws, REVERSE_ORDER, selleft, selright); }
546 
547 static void sort_keys(AW_window *aws, Itemfield_Selection *selleft, Itemfield_Selection *selright) {
549  reorder_keys(aws, mode, selleft, selright);
550 }
551 
552 static void reorder_up_down(AW_window *aws, Itemfield_Selection *sel_right, int dir) {
553  GBDATA *gb_main = sel_right->get_gb_main();
554 
555  GB_begin_transaction(gb_main);
556  ItemSelector& selector = sel_right->get_selector();
557  int list_index = sel_right->get_sellist()->get_index_of_selected();
558 
559  const char *field_name = aws->get_root()->awar(itemAwar(AWAR_FIELD_REORDER_DEST_TMPL, selector))->read_char_pntr();
560  GBDATA *gb_field = GBT_get_changekey(gb_main, field_name, selector.change_key_path);
562 
563  if (!gb_field) {
564  warning = "Please select the item to move in the right box";
565  }
566  else {
567  GBDATA *gb_key_data = GB_search(gb_main, selector.change_key_path, GB_CREATE_CONTAINER);
568  KeySorter sorter(gb_key_data);
569 
570  int curr_index = sorter.index_of(gb_field);
571  int dest_index = -1;
572  if (abs(dir) == 1) {
573  dest_index = curr_index+dir;
574  list_index = -1;
575  }
576  else {
577  dest_index = dir<0 ? 0 : sorter.get_field_count()-1;
578  }
579 
580  sorter.move_to(curr_index, dest_index);
581  warning = sorter.save_changes();
582 
583  }
584 
585  GB_commit_transaction(gb_main);
586  if (list_index >= 0) sel_right->get_sellist()->select_element_at(list_index);
587  if (warning) aw_message(warning);
588 }
589 
591  ItemSelector& selector = bound_selector->selector;
592 
593  static AW_window_simple *awsa[QUERY_ITEM_TYPES];
594  if (!awsa[selector.type]) {
595  AW_window_simple *aws = new AW_window_simple;
596  awsa[selector.type] = aws;
597 
598  init_itemspecific_DBUI_awars(root, selector);
599  init_itemType_specific_window(root, aws, selector, "REORDER_FIELDS", "Reorder %s fields");
600  aws->load_xfig("ad_kreo.fig");
601 
602  aws->at("close");
603  aws->callback(AW_POPDOWN);
604  aws->create_button("CLOSE", "Close", "C");
605 
606  aws->at("help");
607  const char *HELPFILE = "spaf_reorder.hlp";
608  aws->callback(makeHelpCallback(HELPFILE));
609  aws->create_button("HELP", "Help", "H");
610 
613 
614  aws->button_length(8);
615 
616  aws->at("sort");
617  aws->callback(makeWindowCallback(sort_keys, sel1, sel2));
618  aws->help_text(HELPFILE);
619  aws->create_button("SORT", "Sort by");
620 
621  aws->at("sorttype");
622  aws->create_option_menu(AWAR_FIELD_REORDER_ORDER, true);
623  aws->insert_option("name", "a", ORDER_ALPHA);
624  aws->insert_option("type", "t", ORDER_TYPE);
625  aws->insert_option("frequency", "f", ORDER_FREQ);
626  aws->update_option_menu();
627 
628  aws->at("leftright");
629  aws->callback(makeWindowCallback(reorder_right_behind_left, sel1, sel2));
630  aws->help_text(HELPFILE);
631  aws->create_autosize_button("MOVE_RIGHT_BEHIND_LEFT", "Move right\nbehind left");
632 
633  aws->at("reverse");
634  aws->callback(makeWindowCallback(reverse_key_order, sel1, sel2));
635  aws->help_text(HELPFILE);
636  aws->create_autosize_button("REVERSE", "Reverse");
637 
638  aws->button_length(6);
639  struct {
640  const char *tag;
641  const char *macro;
642  int dir;
643  } reorder[4] = {
644  { "Top", "MOVE_TOP_RIGHT", -2 },
645  { "Up", "MOVE_UP_RIGHT", -1 },
646  { "Down", "MOVE_DOWN_RIGHT", +1 },
647  { "Bottom", "MOVE_BOT_RIGHT", +2 },
648  };
649 
650  for (int i = 0; i<4; ++i) {
651  aws->at(reorder[i].tag);
652  aws->callback(makeWindowCallback(reorder_up_down, sel2, reorder[i].dir));
653  aws->help_text(HELPFILE);
654  aws->create_button(reorder[i].macro, reorder[i].tag);
655  }
656  }
657 
658  return awsa[selector.type];
659 }
660 
661 static void hide_field_cb(AW_window *aws, Itemfield_Selection *item_sel, int hide) {
662  GBDATA *gb_main = item_sel->get_gb_main();
664 
665  if (!error) {
666  ItemSelector& selector = item_sel->get_selector();
667  char *source = aws->get_root()->awar(itemAwar(AWAR_FIELD_DELETE_TMPL, selector))->read_string();
668  GBDATA *gb_source = GBT_get_changekey(gb_main, source, selector.change_key_path);
669 
670  if (!gb_source) error = "Please select the field you want to (un)hide";
671  else error = GBT_write_int(gb_source, CHANGEKEY_HIDDEN, hide);
672 
673  free(source);
674  }
675  GB_end_transaction_show_error(gb_main, error, aw_message);
676  if (!error) item_sel->get_sellist()->move_selection(1);
677 }
678 
679 static void field_delete_cb(AW_window *aws, Itemfield_Selection *item_sel) {
680  GBDATA *gb_main = item_sel->get_gb_main();
682 
683  if (!error) {
684  ItemSelector& selector = item_sel->get_selector();
685  char *source = aws->get_root()->awar(itemAwar(AWAR_FIELD_DELETE_TMPL, selector))->read_string();
686  AW_selection_list *sellist = item_sel->get_sellist();
687  int curr_index = sellist->get_index_of_selected();
688  GBDATA *gb_source = GBT_get_changekey(gb_main, source, selector.change_key_path);
689 
690  if (!gb_source) error = "Please select the field you want to delete";
691  else error = GB_delete(gb_source);
692 
693  for (GBDATA *gb_item_container = selector.get_first_item_container(gb_main, aws->get_root(), QUERY_ALL_ITEMS);
694  !error && gb_item_container;
695  gb_item_container = selector.get_next_item_container(gb_item_container, QUERY_ALL_ITEMS))
696  {
697  for (GBDATA * gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
698  !error && gb_item;
699  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
700  {
701  GBDATA *gbd = GB_search(gb_item, source, GB_FIND);
702 
703  if (gbd) {
704  error = GB_delete(gbd);
705  if (!error) {
706  // item has disappeared, this selects the next one:
707  sellist->select_element_at(curr_index);
708  }
709  }
710  }
711  }
712 
713  free(source);
714  }
715 
716  GB_end_transaction_show_error(gb_main, error, aw_message);
717 }
718 
719 
721  ItemSelector& selector = bound_selector->selector;
722 
723  static AW_window_simple *awsa[QUERY_ITEM_TYPES];
724  if (!awsa[selector.type]) {
725  AW_window_simple *aws = new AW_window_simple;
726  awsa[selector.type] = aws;
727 
728  init_itemspecific_DBUI_awars(root, selector);
729  init_itemType_specific_window(root, aws, selector, "DELETE_FIELD", "Delete %s field");
730  aws->load_xfig("ad_delof.fig");
731  aws->button_length(6);
732 
733  aws->at("close"); aws->callback(AW_POPDOWN);
734  aws->create_button("CLOSE", "Close", "C");
735 
736  aws->at("help"); aws->callback(makeHelpCallback("spaf_delete.hlp"));
737  aws->create_button("HELP", "Help", "H");
738 
739  Itemfield_Selection *item_sel = create_itemfield_selection_list(aws, FieldSelDef(itemAwar(AWAR_FIELD_DELETE_TMPL, selector), bound_selector->gb_main, selector, FIELD_UNFILTERED, "field", SF_HIDDEN), "source");
740 
741  aws->button_length(13);
742  aws->at("hide");
743  aws->callback(makeWindowCallback(hide_field_cb, item_sel, 1));
744  aws->create_button("HIDE_FIELD", "Hide field", "H");
745 
746  aws->at("unhide");
747  aws->callback(makeWindowCallback(hide_field_cb, item_sel, 0));
748  aws->create_button("UNHIDE_FIELD", "Unhide field", "U");
749 
750  aws->at("delf");
751  aws->callback(makeWindowCallback(field_delete_cb, item_sel));
752  aws->create_button("DELETE_FIELD", "Delete field\n(data deleted)", "C");
753  }
754 
755  return awsa[selector.type];
756 }
757 
758 static void field_create_cb(AW_window *aws, BoundItemSel *bound_selector) {
759  ItemSelector& selector = bound_selector->selector;
760 
761  GB_push_transaction(bound_selector->gb_main);
762  char *name = aws->get_root()->awar(itemAwar(AWAR_FIELD_CREATE_NAME_TMPL, selector))->read_string();
763  GB_ERROR error = GB_check_key(name);
764  GB_ERROR error2 = GB_check_hkey(name);
765  if (error && !error2) {
766  aw_message("Warning: Your key contain a '/' character,\n"
767  " that means it is a hierarchical key");
768  error = NULp;
769  }
770 
771  int type = (int)aws->get_root()->awar(itemAwar(AWAR_FIELD_CREATE_TYPE_TMPL, selector))->read_int();
772 
773  if (!error) error = GBT_add_new_changekey_to_keypath(bound_selector->gb_main, name, type, selector.change_key_path);
774  aws->hide_or_notify(error);
775  free(name);
776  GB_pop_transaction(bound_selector->gb_main);
777 }
778 
780  aws->insert_toggle("Ascii text", "s", (int)GB_STRING);
781  aws->insert_toggle("Rounded numerical", "i", (int)GB_INT);
782  aws->insert_toggle("Floating-point n.", "F", (int)GB_FLOAT);
783  aws->insert_toggle("Bitmask (0/1)", "B", (int)GB_BITS);
784  // keep in sync with ../ITEMS/item_sel_list.cxx@FIELD_TYPE_DESCRIPTIONS
785 }
786 
788  ItemSelector& selector = bound_selector->selector;
789 
790  static AW_window_simple *awsa[QUERY_ITEM_TYPES];
791  if (awsa[selector.type]) return awsa[selector.type];
792 
793  AW_window_simple *aws = new AW_window_simple;
794  awsa[selector.type] = aws;
795 
796  init_itemspecific_DBUI_awars(root, selector);
797  init_itemType_specific_window(root, aws, selector, "CREATE_FIELD", "Create new %s field");
798  aws->load_xfig("ad_fcrea.fig");
799 
800  aws->at("close");
801  aws->callback(AW_POPDOWN);
802  aws->create_button("CLOSE", "Close", "C");
803 
804  aws->at("input");
805  aws->label("FIELD NAME");
806  aws->create_input_field(itemAwar(AWAR_FIELD_CREATE_NAME_TMPL, selector), 15);
807 
808  aws->at("type");
809  aws->create_toggle_field(itemAwar(AWAR_FIELD_CREATE_TYPE_TMPL, selector), "FIELD TYPE", "F");
811  aws->update_toggle_field();
812 
813  aws->at("ok");
814  aws->callback(makeWindowCallback(field_create_cb, bound_selector));
815  aws->create_button("CREATE", "Create", "C");
816 
817  return aws;
818 }
819 
820 #if defined(WARN_TODO)
821 #warning GBT_convert_changekey currently only works for species fields, make it work with genes/exp/... as well (use selector)
822 #endif
823 
824 static void field_convert_commit_cb(AW_window *aws, BoundItemSel *bound_selector) {
825  AW_root *root = aws->get_root();
826  GBDATA *gb_main = bound_selector->gb_main;
827 
828  GB_push_transaction(gb_main);
829  ItemSelector& selector = bound_selector->selector;
833 
834  GB_end_transaction_show_error(gb_main, error, aw_message);
835 }
836 
837 static void field_convert_update_typesel_cb(AW_root *root, BoundItemSel *bound_selector) {
838  ItemSelector& selector = bound_selector->selector;
839  int type;
840  {
841  GBDATA *gb_main = bound_selector->gb_main;
842  GB_transaction ta(gb_main);
843 
844  type = GBT_get_type_of_changekey(gb_main,
846  selector.change_key_path);
847  }
848 
849  root->awar(itemAwar(AWAR_FIELD_CONVERT_TYPE_TMPL, selector))->write_int(type);
850 }
851 
853  ItemSelector& selector = bound_selector->selector;
854 
855  static AW_window_simple *awsa[QUERY_ITEM_TYPES];
856  if (awsa[selector.type]) return awsa[selector.type];
857 
858  AW_window_simple *aws = new AW_window_simple;
859  awsa[selector.type] = aws;
860 
861  init_itemspecific_DBUI_awars(root, selector);
862  init_itemType_specific_window(root, aws, selector, "CONVERT_FIELD", "Convert %s field");
863  aws->load_xfig("ad_conv.fig");
864 
865  aws->at("close");
866  aws->callback(AW_POPDOWN);
867  aws->create_button("CLOSE", "Close", "C");
868 
869  aws->at("help");
870  aws->callback(makeHelpCallback("spaf_convert.hlp"));
871  aws->create_button("HELP", "Help", "H");
872 
873  const char *awarname_field = itemAwar(AWAR_FIELD_CONVERT_SOURCE_TMPL, selector);
874  root->awar(awarname_field)->add_callback(makeRootCallback(field_convert_update_typesel_cb, bound_selector));
875  create_itemfield_selection_list(aws, FieldSelDef(awarname_field, bound_selector->gb_main, selector, FIELD_FILTER_STRING_READABLE, "field", SF_SHOW_TYPE), "source");
876 
877  aws->at("typesel");
878  aws->create_toggle_field(itemAwar(AWAR_FIELD_CONVERT_TYPE_TMPL, selector), NULp, "F");
880  aws->update_toggle_field();
881 
882  aws->at("convert");
883  aws->callback(makeWindowCallback(field_convert_commit_cb, bound_selector));
884  aws->create_button("CONVERT", "Convert", "T");
885 
886  return aws;
887 }
888 
890  static BoundItemSel *bis = new BoundItemSel(gb_main, SPECIES_get_selector());
891  ui_assert(bis->gb_main == gb_main);
892 
893  aws->insert_menu_topic(aws->local_id("spec_reorder_fields"), "Reorder fields ...", "R", "spaf_reorder.hlp", AWM_ALL, makeCreateWindowCallback(create_fields_reorder_window, bis));
894  aws->insert_menu_topic(aws->local_id("spec_delete_field"), "Delete/Hide fields ...", "D", "spaf_delete.hlp", AWM_EXP, makeCreateWindowCallback(create_field_delete_window, bis));
895  aws->insert_menu_topic(aws->local_id("spec_create_field"), "Create fields ...", "C", "spaf_create.hlp", AWM_ALL, makeCreateWindowCallback(create_field_create_window, bis));
896  aws->insert_menu_topic(aws->local_id("spec_convert_field"), "Convert fields ...", "t", "spaf_convert.hlp", AWM_EXP, makeCreateWindowCallback(create_field_convert_window, bis));
897  aws->sep______________();
898  aws->insert_menu_topic("spec_unhide_fields", "Show all hidden fields", "S", "scandb.hlp", AWM_ALL, makeWindowCallback(species_field_selection_list_unhide_all_cb, gb_main));
899  aws->insert_menu_topic("spec_refresh_fields", "Refresh fields", "f", "scandb.hlp", AWM_ALL, makeWindowCallback(species_field_selection_list_update_cb, gb_main));
900 }
901 
903  const char *input = awar->read_char_pntr();
904  int bpos = atoi(input);
905  int ipos;
906 
907  if (bpos>0) {
908  awar->write_string(GBS_global_string("%i", bpos));
909  ipos = bio2info(bpos);
910  }
911  else {
912  ipos = -1;
913  awar->write_string("");
914  }
915  return ipos;
916 }
917 
919  DbQuery *query;
920  AW_selection_list *resultList; // result list from create_next_neighbours_selected_window()
921 
922 public:
924  query(NULp),
925  resultList(NULp)
926  {}
927 
928  void set_query(DbQuery *new_query) {
929  if (new_query != query) {
930  ui_assert(!query); // need redesign b4 changing query works
931  query = new_query;
932  }
933  }
934  void set_result_list(AW_selection_list *new_resultList) {
935  if (new_resultList != resultList) {
936  ui_assert(!resultList); // need redesign b4 changing query works
937  resultList = new_resultList;
938  }
939  }
940 
941  DbQuery *get_query() const { ui_assert(query); return query; }
942 
943  AW_selection_list *get_result_list() const { ui_assert(resultList); return resultList; }
944  GBDATA *get_gb_main() const { return query_get_gb_main(get_query()); }
945 };
947 
951 
952  return PosRange(start, end);
953 }
954 
955 inline char *read_sequence_region(GBDATA *gb_data, const PosRange& range) {
956  return range.dup_corresponding_part(GB_read_char_pntr(gb_data), GB_read_count(gb_data));
957 }
958 
960  DbQuery *query = NN_GLOBAL.get_query();
961  GBDATA *gb_main = query_get_gb_main(query);
962 
964 
965  GB_begin_transaction(gb_main);
966 
967  long queriedCount = count_queried_items(query, QUERY_ALL_ITEMS);
968  GB_ERROR error = queriedCount ? NULp : "No species listed in query";
969  const char *dest_field = NULp;
970  AW_root *aw_root = aww->get_root();
971 
972  if (!error) {
974  error = dest_field ? NULp : GB_await_error();
975  }
976 
977  if (!error) {
978  arb_progress progress("Searching next neighbours", queriedCount);
979  progress.auto_subtitles("Species");
980 
981  int pts = aw_root->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int();
982  char *ali_name = aw_root->awar(AWAR_DEFAULT_ALIGNMENT)->read_string();
983  int oligo_len = aw_root->awar(AWAR_NN_OLIGO_LEN)->read_int();
984  int mismatches = aw_root->awar(AWAR_NN_MISMATCHES)->read_int();
985  bool fast_mode = aw_root->awar(AWAR_NN_FAST_MODE)->read_int();
986  bool rel_matches = aw_root->awar(AWAR_NN_REL_MATCHES)->read_int();
987  int wanted_entries = aw_root->awar(AWAR_NN_MAX_HITS)->read_int();
988  bool scored_entries = aw_root->awar(AWAR_NN_LISTED_SCORED_ENTRIES)->read_int();
989  float min_score = aw_root->awar(AWAR_NN_MIN_SCORE)->read_float();
990 
991  FF_complement compl_mode = static_cast<FF_complement>(aw_root->awar(AWAR_NN_COMPLEMENT)->read_int());
992  RelativeScoreScaling rel_scaling = static_cast<RelativeScoreScaling>(aw_root->awar(AWAR_NN_REL_SCALING)->read_int());
993 
994  PosRange org_range = get_nn_range_from_awars(aw_root);
995 
996  for (GBDATA *gb_species = GBT_first_species(gb_main);
997  !error && gb_species;
998  gb_species = GBT_next_species(gb_species))
999  {
1000  if (!IS_QUERIED(gb_species, query)) continue;
1001  GBDATA *gb_data = GBT_find_sequence(gb_species, ali_name);
1002  if (gb_data) {
1003  PosRange range = org_range; // modified by read_sequence_region
1004  char *sequence = read_sequence_region(gb_data, range);
1005  PT_FamilyFinder ff(gb_main, pts, oligo_len, mismatches, fast_mode, rel_matches, rel_scaling);
1006 
1007  ff.restrict_2_region(range);
1008 
1009  error = ff.searchFamily(sequence, compl_mode, wanted_entries, min_score);
1010  if (!error) {
1011  const FamilyList *fm = ff.getFamilyList();
1012 
1013  GBS_strstruct *value = NULp;
1014  while (fm) {
1015  const char *thisValue = NULp;
1016  if (rel_matches) {
1017  ui_assert((fm->rel_matches*100) >= min_score); // filtered by ptserver
1018  thisValue = scored_entries
1019  ? GBS_global_string("%.1f%%:%s", fm->rel_matches*100, fm->name)
1020  : fm->name;
1021  }
1022  else {
1023  ui_assert(fm->matches >= min_score); // filtered by ptserver
1024  thisValue = scored_entries
1025  ? GBS_global_string("%li:%s", fm->matches, fm->name)
1026  : fm->name;
1027  }
1028 
1029  if (thisValue) {
1030  if (!value) { // first entry
1031  value = GBS_stropen(1000);
1032  }
1033  else {
1034  GBS_chrcat(value, ';');
1035  }
1036  GBS_strcat(value, thisValue);
1037  }
1038 
1039  fm = fm->next;
1040  }
1041 
1042  if (value) {
1044  GBDATA *gb_dest = GB_search(gb_species, dest_field, GB_STRING);
1045  error = GB_write_string(gb_dest, GBS_mempntr(value));
1046  GBS_strforget(value);
1047  }
1048  else {
1049  GBDATA *gb_dest = GB_search(gb_species, dest_field, GB_FIND);
1050  if (gb_dest) error = GB_delete(gb_dest);
1051  }
1052  }
1053  free(sequence);
1054  }
1055  progress.inc_and_check_user_abort(error);
1056  }
1057  free(ali_name);
1058  }
1059  GB_end_transaction_show_error(gb_main, error, aw_message);
1060 }
1061 
1062 static void awtc_mark_hits(AW_window *) {
1064  GB_HASH *list_hash = resultList->to_hash(false);
1065  GBDATA *gb_main = NN_GLOBAL.get_gb_main();
1066 
1067  GB_transaction ta(gb_main);
1068  for (GBDATA *gb_species = GBT_first_species(gb_main);
1069  gb_species;
1070  gb_species = GBT_next_species(gb_species))
1071  {
1072  int hit = GBS_read_hash(list_hash, GBT_get_name_or_description(gb_species));
1073  GB_write_flag(gb_species, hit);
1074  }
1075 }
1076 
1077 static void awtc_nn_search(AW_window *) {
1078  AW_root *aw_root = AW_root::SINGLETON;
1079  GBDATA *gb_main = NN_GLOBAL.get_gb_main();
1080  GB_ERROR error = NULp;
1081  PosRange range = get_nn_range_from_awars(aw_root);
1082  char *sequence = NULp;
1083  {
1084  GB_transaction ta(gb_main);
1085 
1086  char *sel_species = aw_root->awar(AWAR_SPECIES_NAME)->read_string();
1087  GBDATA *gb_species = GBT_find_species(gb_main, sel_species);
1088 
1089  if (!gb_species) {
1090  error = "Select a species first";
1091  }
1092  else {
1093  char *ali_name = aw_root->awar(AWAR_DEFAULT_ALIGNMENT)->read_string();
1094  GBDATA *gb_data = GBT_find_sequence(gb_species, ali_name);
1095 
1096  if (gb_data) {
1097  sequence = read_sequence_region(gb_data, range);
1098  }
1099  else {
1100  error = GBS_global_string("Species '%s' has no sequence '%s'", sel_species, ali_name);
1101  }
1102  free(ali_name);
1103  }
1104  free(sel_species);
1105  }
1106 
1107  int pts = aw_root->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int();
1108  int oligo_len = aw_root->awar(AWAR_NN_OLIGO_LEN)->read_int();
1109  int mismatches = aw_root->awar(AWAR_NN_MISMATCHES)->read_int();
1110  bool fast_mode = aw_root->awar(AWAR_NN_FAST_MODE)->read_int();
1111  bool rel_matches = aw_root->awar(AWAR_NN_REL_MATCHES)->read_int();
1112  float min_score = aw_root->awar(AWAR_NN_MIN_SCORE)->read_float();
1113 
1114  RelativeScoreScaling rel_scaling = static_cast<RelativeScoreScaling>(aw_root->awar(AWAR_NN_REL_SCALING)->read_int());
1115 
1116  PT_FamilyFinder ff(gb_main, pts, oligo_len, mismatches, fast_mode, rel_matches, rel_scaling);
1117 
1118  ff.restrict_2_region(range);
1119 
1120  int max_hits = 0; // max wanted hits
1121 
1122  if (!error) {
1123  FF_complement compl_mode = static_cast<FF_complement>(aw_root->awar(AWAR_NN_COMPLEMENT)->read_int());
1124  max_hits = aw_root->awar(AWAR_NN_MAX_HITS)->read_int();
1125 
1126  error = ff.searchFamily(sequence, compl_mode, max_hits, min_score);
1127  }
1128 
1129  // update result list
1130  {
1131  AW_selection_list* sel = NN_GLOBAL.get_result_list();
1132  sel->clear();
1133 
1134  int hits = 0;
1135  if (error) {
1136  aw_message(error);
1137  sel->insert_default("<Error>", "");
1138  }
1139  else {
1140  int count = 1;
1141  int shownHits = max_hits>0 ? max_hits : ff.getRealHits();
1142  int numWidth = log(shownHits)/log(10)+1;
1143 
1144  for (const FamilyList *fm = ff.getFamilyList(); fm; fm = fm->next) {
1145  const char *dis;
1146  if (rel_matches) {
1147  dis = GBS_global_string("#%0*i %-12s Rel.hits: %5.1f%%", numWidth, count, fm->name, fm->rel_matches*100);
1148  }
1149  else {
1150  dis = GBS_global_string("#%0*i %-12s Hits: %4li", numWidth, count, fm->name, fm->matches);
1151  }
1152 
1153  sel->insert(dis, fm->name);
1154  count++;
1155  }
1156 
1157  sel->insert_default(ff.hits_were_truncated() ? "<List truncated>" : "<No more hits>", "");
1158  hits = ff.getRealHits();
1159  }
1160  aw_root->awar(AWAR_NN_SELECTED_HIT_COUNT)->write_int(hits);
1161  if (aw_root->awar(AWAR_NN_SELECTED_AUTO_MARK)->read_int()) {
1163  aw_root->awar(AWAR_TREE_REFRESH)->touch();
1164  }
1165  sel->update();
1166  }
1167 
1168  free(sequence);
1169 }
1170 
1171 static void awtc_move_hits(AW_window *aww) {
1172  AW_root *aw_root = aww->get_root();
1173  char *current_species = aw_root->awar(AWAR_SPECIES_NAME)->read_string();
1174 
1175  if (!current_species) current_species = strdup("<unknown>");
1176 
1177  char *hit_description = GBS_global_string_copy("<neighbour of %s: %%s>", current_species);
1178 
1179  copy_selection_list_2_query_box(NN_GLOBAL.get_query(), NN_GLOBAL.get_result_list(), hit_description);
1180 
1181  free(hit_description);
1182  free(current_species);
1183 }
1184 
1185 static bool autosearch_triggered = false;
1188  autosearch_triggered = false;
1189  return 0;
1190 }
1192  // automatic search is triggered delayed to make sure
1193  // dependencies between involved awars have propagated.
1194  if (!autosearch_triggered) { // ignore multiple triggers (happens when multiple awars change, e.g. when loading config)
1195  autosearch_triggered = true;
1196  awr->add_timed_callback(200, makeTimedCallback(nn_perform_delayed_autosearch_cb));
1197  }
1198 }
1199 
1201  int auto_search = awr->awar(AWAR_NN_SELECTED_AUTO_SEARCH)->read_int();
1202 
1203  AW_awar *awar_sel_species = awr->awar(AWAR_SPECIES_NAME);
1204  if (auto_search) {
1207  }
1208  else {
1210  }
1211 }
1212 
1215  int auto_search = awr->awar(AWAR_NN_SELECTED_AUTO_SEARCH)->read_int();
1216  if (auto_search &&
1217  nn_of_sel_win && nn_of_sel_win->is_shown()) // do not trigger if window is not shown
1218  {
1220  }
1221 }
1222 
1223 static void create_next_neighbours_vars(AW_root *aw_root) {
1224  static bool created = false;
1225 
1226  if (!created) {
1227  RootCallback searchRel_awar_changed_cb = makeRootCallback(nn_searchRel_awar_changed_cb);
1228 
1229  aw_root->awar_int(AWAR_PROBE_ADMIN_PT_SERVER)->add_callback(searchRel_awar_changed_cb);
1230  aw_root->awar_int(AWAR_NN_COMPLEMENT, FF_FORWARD)->add_callback(searchRel_awar_changed_cb);
1231 
1232  aw_root->awar_string(AWAR_NN_RANGE_START, "")->add_callback(searchRel_awar_changed_cb);
1233  aw_root->awar_string(AWAR_NN_RANGE_END, "")->add_callback(searchRel_awar_changed_cb);
1234  aw_root->awar_int (AWAR_NN_MAX_HITS, 10)->set_minmax(0, 1000)->add_callback(searchRel_awar_changed_cb);;
1235  aw_root->awar_float (AWAR_NN_MIN_SCORE, 80)->set_minmax(0, 200)->add_callback(searchRel_awar_changed_cb);;
1236 
1237  aw_root->awar_int(AWAR_NN_SELECTED_HIT_COUNT, 0);
1239  aw_root->awar_int(AWAR_NN_SELECTED_AUTO_MARK, 0);
1240 
1241  aw_root->awar_string(AWAR_NN_LISTED_DEST_FIELD, "tmp");
1243 
1244  AWTC_create_common_next_neighbour_vars(aw_root, searchRel_awar_changed_cb);
1245 
1246  created = true;
1247  }
1248 }
1249 
1251  // same as ../FAST_ALIGNER/fast_aligner.cxx@RELATIVES_CONFIG
1252  { AWAR_NN_OLIGO_LEN, "oligolen" },
1253  { AWAR_NN_MISMATCHES, "mismatches" },
1254  { AWAR_NN_FAST_MODE, "fastmode" },
1255  { AWAR_NN_REL_MATCHES, "relmatches" },
1256  { AWAR_NN_REL_SCALING, "relscaling" },
1257 
1258  { AWAR_NN_COMPLEMENT, "complement" },
1259  { AWAR_NN_RANGE_START, "rangestart" },
1260  { AWAR_NN_RANGE_END, "rangeend" },
1261  { AWAR_NN_MAX_HITS, "maxhits" },
1262  { AWAR_NN_MIN_SCORE, "minscore" },
1263 
1264  { NULp, NULp }
1265 };
1266 
1267 static void setup_next_neighbour_config(AWT_config_definition& cdef, bool for_listed) {
1268  // fields common for 'listed' and 'selected'
1269  cdef.add(next_neighbour_config_mapping);
1270 
1271  if (for_listed) {
1272  cdef.add(AWAR_NN_LISTED_SCORED_ENTRIES, "addscore");
1273  }
1274  else {
1275  cdef.add(AWAR_NN_SELECTED_AUTO_SEARCH, "autosearch");
1276  cdef.add(AWAR_NN_SELECTED_AUTO_MARK, "automark");
1277  }
1278 }
1279 
1280 static void create_common_next_neighbour_fields(AW_window *aws, bool for_listed) {
1281  aws->at("pt_server");
1283 
1284  const int SCALER_LENGTH = 200;
1285 
1286  aws->auto_space(5, 5);
1287  AWTC_create_common_next_neighbour_fields(aws, SCALER_LENGTH);
1288 
1289 
1290  aws->at("range");
1293 
1294  aws->at("compl");
1296  aws->insert_default_option("forward", "", FF_FORWARD);
1297  aws->insert_option ("reverse", "", FF_REVERSE);
1298  aws->insert_option ("complement", "", FF_COMPLEMENT);
1299  aws->insert_option ("reverse-complement", "", FF_REVERSE_COMPLEMENT);
1300  aws->insert_option ("fwd + rev-compl", "", FF_FORWARD|FF_REVERSE_COMPLEMENT);
1301  aws->insert_option ("rev + compl", "", FF_REVERSE|FF_COMPLEMENT);
1303  aws->update_option_menu();
1304 
1305  aws->at("results");
1307 
1308  aws->at("min_score");
1310 
1311  aws->at("config");
1312  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "next_neighbours", makeConfigSetupCallback(setup_next_neighbour_config, for_listed));
1313 }
1314 
1316  static AW_window_simple *aws = NULp;
1317  NN_GLOBAL.set_query(query);
1318  if (!aws) {
1319  create_next_neighbours_vars(aw_root);
1320 
1321  aws = new AW_window_simple;
1322  aws->init(aw_root, "SEARCH_NEXT_NEIGHBOURS_OF_LISTED", "Search Next Neighbours of Listed");
1323  aws->load_xfig("ad_spec_nnm.fig");
1324 
1325  aws->at("close");
1326  aws->callback(AW_POPDOWN);
1327  aws->create_button("CLOSE", "Close", "C");
1328 
1329  aws->at("help");
1330  aws->callback(makeHelpCallback("next_neighbours_listed.hlp"));
1331  aws->create_button("HELP", "Help", "H");
1332 
1334 
1335  aws->at("add_score");
1336  aws->create_toggle(AWAR_NN_LISTED_SCORED_ENTRIES);
1337 
1338  aws->at("field");
1340 
1341  aws->at("go");
1342  aws->callback(awtc_nn_search_all_listed);
1343  aws->button_length(10);
1344  aws->create_button("WRITE_FIELDS", "GO");
1345  }
1346  return aws;
1347 }
1348 
1350  static AW_window_simple *aws = NULp;
1351  NN_GLOBAL.set_query(query);
1352  if (!aws) {
1353  create_next_neighbours_vars(aw_root);
1354 
1355  aws = new AW_window_simple;
1356  aws->init(aw_root, "SEARCH_NEXT_RELATIVE_OF_SELECTED", "Search Next Neighbours of Selected");
1357  aws->load_xfig("ad_spec_nn.fig");
1358 
1359  aws->at("close");
1360  aws->callback(AW_POPDOWN);
1361  aws->create_button("CLOSE", "Close", "C");
1362 
1363  aws->at("help");
1364  aws->callback(makeHelpCallback("next_neighbours.hlp"));
1365  aws->create_button("HELP", "Help", "H");
1366 
1368 
1369  aws->button_length(10);
1370  aws->at("hit_count");
1371  aws->create_button(NULp, AWAR_NN_SELECTED_HIT_COUNT, NULp, "+");
1372 
1373  aws->at("hits");
1374  AW_selection_list *resultList = aws->create_selection_list(AWAR_SPECIES_NAME, false);
1375  NN_GLOBAL.set_result_list(resultList);
1376  resultList->insert_default("No hits found", "");
1377  resultList->update();
1378 
1379  aws->at("go");
1380  aws->callback(awtc_nn_search);
1381  aws->create_button("SEARCH", "Search");
1382 
1383  aws->at("auto_go");
1384  aws->label("Auto search on change");
1385  aws->create_toggle(AWAR_NN_SELECTED_AUTO_SEARCH);
1386 
1387  aws->at("mark");
1388  aws->callback(awtc_mark_hits);
1389  aws->create_autosize_button("MARK_HITS", "Mark hits");
1390 
1391  aws->at("auto_mark");
1392  aws->label("Auto");
1393  aws->create_toggle(AWAR_NN_SELECTED_AUTO_MARK);
1394 
1395  aws->at("move");
1396  aws->callback(awtc_move_hits);
1397  aws->create_autosize_button("MOVE_TO_HITLIST", "Move to hitlist");
1398 
1399  nn_of_sel_win = aws; // store current window (to disable auto search when this window was popped down)
1400  }
1401  return aws;
1402 }
1403 
1404 // ---------------------------------------------
1405 // species/organism specific callbacks
1406 
1407 static AW_window *popup_new_speciesOrganismWindow(AW_root *aw_root, GBDATA *gb_main, bool organismWindow, int detach_id);
1408 
1409 static void popup_detached_speciesOrganismWindow(AW_window *aw_parent, const InfoWindow *infoWin) {
1411  if (reusable) {
1412  reusable->reuse();
1413  }
1414  else { // create a new window if none is reusable
1416  infoWin->get_gbmain(),
1417  infoWin->mapsOrganism(),
1419  }
1420 }
1421 
1422 static AW_window *popup_new_speciesOrganismWindow(AW_root *aw_root, GBDATA *gb_main, bool organismWindow, int detach_id) { // INFO_WINDOW_CREATOR
1423  // if detach_id is MAIN_WINDOW -> create main window (not detached)
1424 
1426  const ItemSelector& itemType = organismWindow ? ORGANISM_get_selector() : SPECIES_get_selector();
1427 
1428  init_info_window(aw_root, aws, itemType, detach_id);
1429 
1430  aws->load_xfig("ad_spec.fig");
1431 
1432  aws->button_length(8);
1433 
1434  aws->at("close");
1435  aws->callback(AW_POPDOWN);
1436  aws->create_button("CLOSE", "Close", "C");
1437 
1438  aws->at("search");
1439  aws->callback(makeCreateWindowCallback(DBUI::create_species_query_window, gb_main));
1440  aws->create_autosize_button("SEARCH", "Search...", "S");
1441 
1442  aws->at("help");
1443  aws->callback(makeHelpCallback(detach_id ? "sp_info_locked.hlp" : "sp_info.hlp")); // uses_hlp_res("sp_info_locked.hlp", "sp_info.hlp"); see ../../SOURCE_TOOLS/check_resources.pl@uses_hlp_res
1444  aws->create_button("HELP", "Help", "H");
1445 
1446  DbScanner *scanner = DbScanner::create(gb_main,
1447  InfoWindowRegistry::localize_scanner_id(organismWindow ? "organism" : "species", detach_id),
1448  aws, "box", "field", "enable", DB_KEYVIEWER, "mark", itemType);
1449 
1450  const InfoWindow& infoWin = InfoWindowRegistry::infowin.registerInfoWindow(aws, scanner, detach_id);
1451 
1452  if (infoWin.is_maininfo()) {
1453  if (organismWindow) aws->create_menu("ORGANISM", "O", AWM_ALL);
1454  else aws->create_menu("SPECIES", "S", AWM_ALL);
1455 
1456  aws->insert_menu_topic("species_delete", "Delete", "D", "spa_delete.hlp", AWM_ALL, makeWindowCallback(species_delete_cb, gb_main));
1457  aws->insert_menu_topic("species_rename", "Rename", "R", "spa_rename.hlp", AWM_ALL, makeWindowCallback(species_rename_cb, gb_main));
1458  aws->insert_menu_topic("species_copy", "Copy", "y", "spa_copy.hlp", AWM_ALL, makeWindowCallback(species_copy_cb, gb_main));
1459  aws->insert_menu_topic("species_create", "Create", "C", "spa_create.hlp", AWM_ALL, makeWindowCallback(species_create_cb, gb_main));
1460  aws->sep______________();
1461  aws->insert_menu_topic("species_convert_2_sai", "Convert to SAI", "S", "sp_sp_2_ext.hlp", AWM_ALL, makeWindowCallback(move_species_to_extended, gb_main));
1462  }
1463 
1464  aws->create_menu("FIELDS", "F", AWM_ALL);
1465  insert_field_admin_menuitems(aws, gb_main);
1466 
1467  aws->at("detach");
1469 
1470  aws->show();
1471  infoWin.attach_selected_item();
1472  return aws;
1473 }
1474 
1475 static void popup_speciesOrganismWindow(AW_root *aw_root, GBDATA *gb_main, bool organismWindow) {
1476  int windowIdx = (int)organismWindow;
1477 
1478  static AW_window *AWS[2] = { NULp, NULp };
1479  if (!AWS[windowIdx]) {
1480  AWS[windowIdx] = popup_new_speciesOrganismWindow(aw_root, gb_main, organismWindow, InfoWindow::MAIN_WINDOW);
1481  }
1482  else {
1483  InfoWindowRegistry::reactivate(AWS[windowIdx]);
1484  }
1485 }
1486 
1489 
1490 static DbQuery *GLOBAL_species_query = NULp; // @@@ fix design
1491 
1493  QUERY::unquery_all(NULp, GLOBAL_species_query);
1494 }
1495 
1497  DbQuery_update_list(GLOBAL_species_query);
1498 }
1499 
1501  static AW_window_simple_menu *aws = NULp;
1502  if (!aws) {
1503  aws = new AW_window_simple_menu;
1504  aws->init(aw_root, "SPECIES_QUERY", "SEARCH and QUERY");
1505  aws->create_menu("More functions", "f");
1506  aws->load_xfig("ad_query.fig");
1507 
1508 
1510 
1511  awtqs.gb_main = gb_main;
1513  awtqs.tree_name = AWAR_TREE;
1514  awtqs.select_bit = GB_USERFLAG_QUERY;
1515  awtqs.use_menu = 1;
1516  awtqs.ere_pos_fig = "ere2";
1517  awtqs.by_pos_fig = "by2";
1518  awtqs.qbox_pos_fig = "qbox";
1519  awtqs.key_pos_fig = NULp;
1520  awtqs.query_pos_fig = "content";
1521  awtqs.result_pos_fig = "result";
1522  awtqs.count_pos_fig = "count";
1523  awtqs.do_query_pos_fig = "doquery";
1524  awtqs.config_pos_fig = "doconfig";
1525  awtqs.do_mark_pos_fig = "domark";
1526  awtqs.do_unmark_pos_fig = "dounmark";
1527  awtqs.do_delete_pos_fig = "dodelete";
1528  awtqs.do_set_pos_fig = "doset";
1529  awtqs.do_refresh_pos_fig = "dorefresh";
1530  awtqs.open_parser_pos_fig = "openparser";
1532 
1533  DbQuery *query = create_query_box(aws, &awtqs, "spec");
1534  GLOBAL_species_query = query;
1535 
1536  aws->create_menu("More search", "s");
1537  aws->insert_menu_topic("spec_search_equal_fields_within_db", "Search For Equal Fields and Mark Duplicates", "E", "search_duplicates.hlp", AWM_ALL, makeWindowCallback (search_duplicated_field_content, query, false));
1538  aws->insert_menu_topic("spec_search_equal_words_within_db", "Search For Equal Words Between Fields and Mark Duplicates", "W", "search_duplicates.hlp", AWM_ALL, makeWindowCallback (search_duplicated_field_content, query, true));
1539  aws->insert_menu_topic("spec_search_next_relativ_of_sel", "Search Next Relatives of SELECTED Species in PT_Server ...", "R", "next_neighbours.hlp", AWM_ALL, makeCreateWindowCallback(create_next_neighbours_selected_window, query));
1540  aws->insert_menu_topic("spec_search_next_relativ_of_listed", "Search Next Relatives of LISTED Species in PT_Server ...", "L", "next_neighbours_listed.hlp", AWM_ALL, makeCreateWindowCallback(create_next_neighbours_listed_window, query));
1541 
1542  aws->button_length(7);
1543 
1544  aws->at("close");
1545  aws->callback(AW_POPDOWN);
1546  aws->create_button("CLOSE", "Close", "C");
1547 
1548  aws->at("help");
1549  aws->callback(makeHelpCallback("sp_search.hlp"));
1550  aws->create_button("HELP", "Help", "H");
1551  }
1552  return aws;
1553 }
1554 
1555 
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2492
GB_ERROR GB_check_key(const char *key) __ATTR__USERESULT
Definition: adstring.cxx:85
void insert_option(AW_label choice_label, const char *mnemonic, const char *var_value, const char *name_of_color=NULp)
void AWTC_create_common_next_neighbour_fields(AW_window *aws, int scaler_length)
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
Definition: arbdb.cxx:2120
Definition: dbui.h:31
static void create_common_next_neighbour_fields(AW_window *aws, bool for_listed)
AW_window * create_species_query_window(AW_root *aw_root, GBDATA *gb_main)
const char * GB_ERROR
Definition: arb_core.h:25
static void awtc_nn_search_all_listed(AW_window *aww)
Definition: ui_species.cxx:959
const InfoWindow * find_reusable_of_same_type_as(const InfoWindow &other)
Definition: info_window.h:172
const char * item_name
Definition: items.h:65
#define AWAR_NN_LISTED_SCORED_ENTRIES
Definition: ui_species.cxx:72
GB_TYPES type
void query_update_list()
void insert_toggle(AW_label toggle_label, const char *mnemonic, const char *var_value)
GB_ERROR GB_commit_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2515
static GB_ERROR species_rename_handler(const char *new_fullname, GBDATA *gb_species)
Definition: ui_species.cxx:219
void popup_organism_info_window(AW_root *aw_root, GBDATA *gb_main)
void button_length(int length)
Definition: AW_at.cxx:283
void add(const char *awar_name, const char *config_name)
#define AWAR_FIELD_REORDER_SOURCE_TMPL
Definition: ui_species.cxx:47
static void nn_trigger_delayed_autosearch_cb(AW_root *awr)
void reverse_order(int p1, int p2)
Definition: ui_species.cxx:439
static bool autosearch_triggered
long GB_read_int(GBDATA *gbd)
Definition: arbdb.cxx:699
GBDATA * GB_child(GBDATA *father)
Definition: adquery.cxx:322
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
Definition: adhash.cxx:457
const char * config_pos_fig
Definition: db_query.h:61
Definition: arbdb.h:69
AwarName species_name
Definition: db_query.h:42
void insert_menu_topic(const char *id, const char *name, const char *mnemonic, const char *help_text_, AW_active mask, const WindowCallback &wcb)
Definition: AW_window.cxx:592
void select_element_at(int wanted_index)
Definition: AW_select.cxx:433
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
Definition: arbdb.cxx:1361
static void reverse_key_order(AW_window *aws, Itemfield_Selection *selleft, Itemfield_Selection *selright)
Definition: ui_species.cxx:545
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:717
void DbQuery_update_list(DbQuery *query)
Definition: db_query.cxx:485
void species_field_selection_list_unhide_all_cb(AW_window *, GBDATA *gb_main)
Definition: changekey.cxx:188
void create_dbui_awars(AW_root *aw_root)
Definition: ui_species.cxx:85
void insert_default(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:385
static void field_create_cb(AW_window *aws, BoundItemSel *bound_selector)
Definition: ui_species.cxx:758
ItemSelector & ORGANISM_get_selector()
Definition: species.cxx:140
static void nn_auto_search_changed_cb(AW_root *awr)
GBDATA * get_gb_main() const
Definition: ui_species.cxx:944
const char * key_pos_fig
Definition: db_query.h:53
static const int MAIN_WINDOW
Definition: info_window.h:67
void popup_species_info_window(AW_root *aw_root, GBDATA *gb_main)
static void species_delete_cb(AW_window *aww, GBDATA *gb_main)
Definition: ui_species.cxx:266
GBDATA * query_get_gb_main(DbQuery *query)
Definition: db_query.cxx:106
int allocate_detach_id(const InfoWindow &other)
Definition: info_window.h:160
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2525
void at(int x, int y)
Definition: AW_at.cxx:93
const char * ere_pos_fig
Definition: db_query.h:48
#define AWAR_FIELD_REORDER_DEST_TMPL
Definition: ui_species.cxx:48
static void init_itemspecific_DBUI_awars(AW_root *aw_root, ItemSelector &itype)
Definition: ui_species.cxx:92
static void field_convert_commit_cb(AW_window *aws, BoundItemSel *bound_selector)
Definition: ui_species.cxx:824
void copy_selection_list_2_query_box(DbQuery *query, AW_selection_list *srclist, const char *hit_description)
Definition: db_query.cxx:1130
static void move_species_to_extended(AW_window *aww, GBDATA *gb_main)
Definition: ui_species.cxx:108
AW_selection_list * resultList
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
#define AWAR_FIELD_CONVERT_TYPE_TMPL
Definition: ui_species.cxx:53
#define AWAR_DEFAULT_ALIGNMENT
Definition: aw_awar_defs.hxx:8
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
Definition: arbdb.cxx:2548
long read_int() const
Definition: AW_awar.cxx:187
#define AWAR_NN_RANGE_START
Definition: ui_species.cxx:58
AW_awar * set_minmax(float min, float max)
Definition: AW_awar.cxx:532
static void hide_field_cb(AW_window *aws, Itemfield_Selection *item_sel, int hide)
Definition: ui_species.cxx:661
static void popup_speciesOrganismWindow(AW_root *aw_root, GBDATA *gb_main, bool organismWindow)
static void species_create_cb(AW_window *, GBDATA *gb_main)
Definition: ui_species.cxx:165
DbQuery * create_query_box(AW_window *aws, query_spec *awtqs, const char *query_id)
Definition: db_query.cxx:2346
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
void warning(int warning_num, const char *warning_message)
Definition: util.cxx:61
const char * result_pos_fig
Definition: db_query.h:57
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
void unquery_all(void *dummy, DbQuery *query)
Definition: db_query.cxx:620
void GBS_free_hash(GB_HASH *hs)
Definition: adhash.cxx:541
void auto_subtitles(const char *prefix)
Definition: arb_progress.h:286
void add_timed_callback(int ms, const TimedCallback &tcb)
Definition: AW_root.cxx:538
int get_index_of_selected()
Definition: AW_select.cxx:316
static void species_rename_cb(AW_window *aww, GBDATA *gb_main)
Definition: ui_species.cxx:250
static void reorder_up_down(AW_window *aws, Itemfield_Selection *sel_right, int dir)
Definition: ui_species.cxx:552
long count_queried_items(DbQuery *query, QUERY_RANGE range)
Definition: db_query.cxx:159
const char * open_parser_pos_fig
Definition: db_query.h:66
KeySorter(GBDATA *gb_key_data)
Definition: ui_species.cxx:372
void insert_field_admin_menuitems(AW_window *aws, GBDATA *gb_main)
Definition: ui_species.cxx:889
static NN_GlobalData NN_GLOBAL
Definition: ui_species.cxx:946
ReorderMode
Definition: ui_species.cxx:74
static AW_window * create_next_neighbours_selected_window(AW_root *aw_root, DbQuery *query)
GBDATA * GB_get_father(GBDATA *gbd)
Definition: arbdb.cxx:1696
void update_option_menu()
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2458
bool speciesOrOrganism(QUERY_ITEM_TYPE type)
Definition: items.h:36
bool mapsOrganism() const
Definition: info_window.h:93
GB_ERROR searchFamily(const char *sequence, FF_complement compl_mode, int max_results, double min_score) OVERRIDE __ATTR__USERESULT
const char * itemAwar(const char *name_template, ItemSelector &itype)
Definition: ui_species.cxx:89
char * AWTC_makeUniqueShortName(const char *prefix, UniqueNameDetector &existingNames)
Definition: AW_rename.cxx:633
int index_of(GBDATA *gb_key)
Definition: ui_species.cxx:444
#define AWAR_NN_REL_SCALING
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1880
#define AWAR_NN_FAST_MODE
void create_input_field_with_scaler(const char *awar_name, int textcolumns=4, int scaler_length=250, AW_ScalerType scalerType=AW_SCALER_LINEAR)
Definition: AW_button.cxx:1140
void insert(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:380
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
static HelixNrInfo * start
static bool initialized
Definition: AW_advice.cxx:36
static void sort_keys(AW_window *aws, Itemfield_Selection *selleft, Itemfield_Selection *selright)
Definition: ui_species.cxx:547
GB_ERROR GB_check_hkey(const char *key) __ATTR__USERESULT
Definition: adstring.cxx:92
const char * read_char_pntr() const
Definition: AW_awar.cxx:171
RelativeScoreScaling
static void reorder_keys(AW_window *aws, ReorderMode mode, Itemfield_Selection *sel_left, Itemfield_Selection *sel_right)
Definition: ui_species.cxx:486
static AWT_config_mapping_def next_neighbour_config_mapping[]
GB_ERROR GBT_convert_changekey(GBDATA *gb_main, const char *name, GB_TYPES target_type)
GBS_strstruct * GBS_stropen(long init_size)
Definition: arb_strbuf.cxx:39
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:353
static void popup_detached_speciesOrganismWindow(AW_window *aw_parent, const InfoWindow *infoWin)
static AW_root * SINGLETON
Definition: aw_root.hxx:102
DbQuery * get_query() const
Definition: ui_species.cxx:941
void show()
Definition: AW_window.cxx:1658
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1803
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
Definition: arbdb.h:67
long GB_read_count(GBDATA *gbd)
Definition: arbdb.cxx:728
Definition: arbdb.h:78
TYPE * ARB_alloc(size_t nelem)
Definition: arb_mem.h:56
#define CHANGEKEY_HIDDEN
Definition: arbdbt.h:93
void reuse() const
Definition: info_window.h:114
static void species_copy_cb(AW_window *aww, GBDATA *gb_main)
Definition: ui_species.cxx:185
void restrict_2_region(const PosRange &range_)
AW_awar * awar_float(const char *var_name, float default_value=0.0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:560
GB_HASH * to_hash(bool case_sens)
Definition: AW_select.cxx:532
GBDATA * get_gb_main()
Definition: AW_select.cxx:592
GBDATA * gb_species_data
Definition: adname.cxx:34
ItemSelector & get_queried_itemtype(DbQuery *query)
Definition: db_query.cxx:110
const char * change_key_path
Definition: items.h:64
void init_itemType_specific_window(AW_root *aw_root, class AW_window_simple *aws, const ItemSelector &itemType, const char *id, const char *title_format, bool plural=false)
Definition: itemtools.cxx:32
ItemSelector & selector
Definition: items.h:86
GBDATA * get_gbmain() const
Definition: info_window.h:85
CONSTEXPR long FIELD_FILTER_STRING_WRITEABLE
Definition: item_sel_list.h:42
void create_menu(const char *name, const char *mnemonic, AW_active mask=AWM_ALL)
Definition: AW_window.cxx:469
const char * qbox_pos_fig
Definition: db_query.h:52
#define AWAR_FIELD_CREATE_TYPE_TMPL
Definition: ui_species.cxx:50
bool hits_were_truncated() const
void init_info_window(AW_root *aw_root, AW_window_simple_menu *aws, const ItemSelector &itemType, int detach_id)
Definition: info_window.cxx:36
void touch()
Definition: AW_awar.cxx:210
GBDATA *(* get_first_item_container)(GBDATA *, AW_root *, QUERY_RANGE)
Definition: items.h:69
void GBS_strcat(GBS_strstruct *strstr, const char *ptr)
Definition: arb_strbuf.cxx:108
static void error(const char *msg)
Definition: mkptypes.cxx:96
GBDATA * GB_get_root(GBDATA *gbd)
Definition: arbdb.cxx:1714
GBDATA *(* get_next_item_container)(GBDATA *, QUERY_RANGE)
Definition: items.h:70
#define AWAR_TREE_REFRESH
void set_query(DbQuery *new_query)
Definition: ui_species.cxx:928
GBDATA * GBT_find_or_create_species_rel_species_data(GBDATA *gb_species_data, const char *name, bool markCreated)
Definition: aditem.cxx:57
static void setup_next_neighbour_config(AWT_config_definition &cdef, bool for_listed)
#define AWAR_TREE
CONSTEXPR_INLINE_Cxx14 void swap(unsigned char &c1, unsigned char &c2)
Definition: ad_io_inline.h:19
static void reorder_right_behind_left(AW_window *aws, Itemfield_Selection *selleft, Itemfield_Selection *selright)
Definition: ui_species.cxx:544
static InfoWindowRegistry infowin
Definition: info_window.h:187
static void reactivate(AW_window *aww)
Definition: info_window.h:189
static long count_field_occurrence(BoundItemSel *bsel, const char *field_name)
Definition: ui_species.cxx:286
#define AWAR_SPECIES_NAME
const char * count_pos_fig
Definition: db_query.h:58
AW_selection_list * get_result_list() const
Definition: ui_species.cxx:943
void attach_selected_item() const
Definition: info_window.h:110
#define AWAR_NN_RANGE_END
Definition: ui_species.cxx:59
char * read_sequence_region(GBDATA *gb_data, const PosRange &range)
Definition: ui_species.cxx:955
bool is_maininfo() const
Definition: info_window.h:82
static DbScanner * create(GBDATA *gb_main, const char *scanner_id, AW_window *aws, const char *box_pos_fig, const char *edit_pos_fig, const char *edit_enable_pos_fig, DB_SCANNERMODE scannermode, const char *mark_pos_fig, ItemSelector &selector)
Definition: db_scanner.cxx:227
FF_complement
static void nn_searchRel_awar_changed_cb(AW_root *awr)
const char * by_pos_fig
Definition: db_query.h:50
#define AWAR_NN_SELECTED_AUTO_MARK
Definition: ui_species.cxx:67
const char * prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector &itemtype, FailIfField failIf)
void AWTC_create_common_next_neighbour_vars(AW_root *aw_root, const RootCallback &awar_changed_cb)
GBDATA * GBT_find_species_rel_species_data(GBDATA *gb_species_data, const char *name)
Definition: aditem.cxx:133
char * read_string() const
Definition: AW_awar.cxx:201
static AW_window * create_next_neighbours_listed_window(AW_root *aw_root, DbQuery *query)
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2488
void GBS_strforget(GBS_strstruct *strstr)
Definition: arb_strbuf.cxx:76
GB_TYPES GBT_get_type_of_changekey(GBDATA *gb_main, const char *field_name, const char *change_key_path)
Definition: adChangeKey.cxx:34
Definition: arbdb.h:86
void species_field_selection_list_update_cb(AW_window *, GBDATA *gb_main)
Definition: changekey.cxx:189
GBDATA *(* get_first_item)(GBDATA *, QUERY_RANGE)
Definition: items.h:72
AW_option_menu_struct * create_option_menu(const char *awar_name, bool fallback2default)
#define AWAR_NN_SELECTED_HIT_COUNT
Definition: ui_species.cxx:65
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
Definition: adali.cxx:670
AW_window * create_fields_reorder_window(AW_root *root, BoundItemSel *bound_selector)
Definition: ui_species.cxx:590
FamilyList * next
AW_awar * remove_callback(const RootCallback &cb)
Definition: AW_awar.cxx:527
void search_duplicated_field_content(AW_window *dummy, DbQuery *query, bool tokenize)
Definition: db_query.cxx:1194
#define AWAR_FIELD_DELETE_TMPL
Definition: ui_species.cxx:51
void create_autosize_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, unsigned xtraSpace=1)
Definition: AW_button.cxx:419
void awt_create_PTSERVER_selection_button(AW_window *aws, const char *varname)
Definition: db_query.h:24
float read_float() const
Definition: AW_awar.cxx:180
void insert_default_option(AW_label choice_label, const char *mnemonic, const char *var_value, const char *name_of_color=NULp)
QUERY_RANGE
Definition: items.h:40
int get_field_count() const
Definition: ui_species.cxx:406
#define AWAR_NN_MIN_SCORE
Definition: ui_species.cxx:60
GBDATA *(* get_next_item)(GBDATA *, QUERY_RANGE)
Definition: items.h:73
void GBS_chrcat(GBS_strstruct *strstr, char ch)
Definition: arb_strbuf.cxx:119
bool aw_ask_sure(const char *unique_id, const char *msg)
__ATTR__USERESULT GB_ERROR save_changes()
Definition: ui_species.cxx:469
GB_ERROR AWTC_recreate_name(GBDATA *gb_species)
Definition: AW_rename.cxx:366
void create_input_field(const char *awar_name, int columns=0)
Definition: AW_button.cxx:855
ASSERTING_CONSTEXPR_INLINE int bio2info(int biopos)
Definition: arb_defs.h:26
Definition: arbdb.h:63
#define AWAR_NN_COMPLEMENT
Definition: ui_species.cxx:57
void move_to(int to_move, int wanted_position)
Definition: ui_species.cxx:456
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
static unsigned nn_perform_delayed_autosearch_cb(AW_root *)
void auto_space(int xspace, int yspace)
Definition: AW_at.cxx:259
popup_info_window_cb popup_info_window
Definition: db_query.h:69
GB_ERROR close(GB_ERROR error)
Definition: arbdbpp.cxx:32
void GB_write_flag(GBDATA *gbd, long flag)
Definition: arbdb.cxx:2737
static void create_next_neighbours_vars(AW_root *aw_root)
char * GBS_mempntr(GBS_strstruct *strstr)
Definition: arb_strbuf.cxx:86
GB_ERROR GBT_write_string(GBDATA *gb_container, const char *fieldpath, const char *content)
Definition: adtools.cxx:451
GBDATA * GBT_get_changekey(GBDATA *gb_main, const char *key, const char *change_key_path)
Definition: adChangeKey.cxx:16
AW_window * create_field_create_window(AW_root *root, BoundItemSel *bound_selector)
Definition: ui_species.cxx:787
const char * do_mark_pos_fig
Definition: db_query.h:62
bool IS_QUERIED(GBDATA *gb_item, const query_spec *aqs)
Definition: db_query.h:84
void move_selection(int offset)
Definition: AW_select.cxx:415
Itemfield_Selection * create_itemfield_selection_list(AW_window *aws, const FieldSelDef &selDef, const char *at)
static DbQuery * GLOBAL_species_query
#define __ATTR__USERESULT
Definition: attributes.h:58
#define AWAR_NN_MAX_HITS
Definition: ui_species.cxx:61
bool ARB_in_expert_mode(AW_root *awr)
#define CHANGE_KEY_PATH
Definition: arbdbt.h:86
#define AWAR_PROBE_ADMIN_PT_SERVER
Definition: probe_gui.hxx:24
ItemSelector & SPECIES_get_selector()
Definition: species.cxx:139
GBDATA * GBT_first_species(GBDATA *gb_main)
Definition: aditem.cxx:124
static void awtc_move_hits(AW_window *aww)
GBDATA * gb_main
Definition: items.h:85
#define CHANGEKEY_TYPE
Definition: arbdbt.h:92
#define abs(x)
Definition: f2c.h:151
AW_window * create_field_delete_window(AW_root *root, BoundItemSel *bound_selector)
Definition: ui_species.cxx:720
#define ui_assert(cond)
Definition: ui_species.cxx:41
const FamilyList * getFamilyList() const
bool is_shown() const
Definition: AW_window.cxx:1622
static GBDATA * expect_species_selected(AW_root *aw_root, GBDATA *gb_main, char **give_name=NULp)
Definition: ui_species.cxx:169
const char * query_pos_fig
Definition: db_query.h:54
static AW_window * popup_new_speciesOrganismWindow(AW_root *aw_root, GBDATA *gb_main, bool organismWindow, int detach_id)
void aw_message(const char *msg)
Definition: AW_status.cxx:932
const char * do_query_pos_fig
Definition: db_query.h:60
GB_ERROR GBT_add_new_changekey_to_keypath(GBDATA *gb_main, const char *name, int type, const char *keypath)
Definition: adChangeKey.cxx:87
void add_detach_area(detached_uppopper popup_detached_cb) const
AW_root * get_root()
Definition: aw_window.hxx:348
GBDATA * GBT_next_species(GBDATA *gb_species)
Definition: aditem.cxx:128
#define AWAR_NN_SELECTED_AUTO_SEARCH
Definition: ui_species.cxx:66
#define NULp
Definition: cxxforward.h:97
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:136
static PosRange get_nn_range_from_awars(AW_root *aw_root)
Definition: ui_species.cxx:948
void bubble_sort(int p1, int p2, ReorderMode mode, BoundItemSel *selector)
Definition: ui_species.cxx:408
GB_ERROR write_string(const char *aw_string)
char * dup_corresponding_part(const char *source, size_t source_len) const
Definition: pos_range.cxx:27
ItemSelector & get_selector() const
Definition: item_sel_list.h:71
const char * GBT_get_name(GBDATA *gb_item)
Definition: aditem.cxx:446
GBDATA * GBT_find_SAI_rel_SAI_data(GBDATA *gb_sai_data, const char *name)
Definition: aditem.cxx:169
void sep______________()
Definition: AW_window.cxx:750
#define GB_USERFLAG_QUERY
Definition: arbdb.h:55
static GB_ERROR species_create_handler(const char *dest, GBDATA *gb_main)
Definition: ui_species.cxx:139
#define AWAR_NN_MISMATCHES
static void awtc_mark_hits(AW_window *)
const char * local_id(const char *id) const
Definition: AW_window.cxx:744
#define AWAR_NN_LISTED_DEST_FIELD
Definition: ui_species.cxx:71
GB_TYPES
Definition: arbdb.h:62
GBDATA * GB_nextChild(GBDATA *child)
Definition: adquery.cxx:326
#define AWAR_FIELD_REORDER_ORDER
Definition: ui_species.cxx:44
GB_transaction ta(gb_var)
GB_ERROR GBT_write_int(GBDATA *gb_container, const char *fieldpath, long content)
Definition: adtools.cxx:471
void callback(const WindowCallback &cb)
Definition: AW_window.cxx:130
GBDATA * gb_main
Definition: db_query.h:39
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:874
static AW_window * nn_of_sel_win
GBDATA * gb_main
Definition: adname.cxx:33
static void awtc_nn_search(AW_window *)
GB_ERROR GB_resort_data_base(GBDATA *gb_main, GBDATA **new_order_list, long listsize)
Definition: arbdb.cxx:2619
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 * GBT_get_SAI_data(GBDATA *gb_main)
Definition: aditem.cxx:152
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
void hide_or_notify(const char *error)
Definition: AW_window.cxx:1817
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
Definition: aditem.cxx:437
const char * do_set_pos_fig
Definition: db_query.h:65
int getRealHits() const
#define AWAR_FIELD_CONVERT_SOURCE_TMPL
Definition: ui_species.cxx:52
int get_and_fix_range_from_awar(AW_awar *awar)
Definition: ui_species.cxx:902
#define AWAR_FIELD_CREATE_NAME_TMPL
Definition: ui_species.cxx:49
static AW_window * create_field_convert_window(AW_root *root, BoundItemSel *bound_selector)
Definition: ui_species.cxx:852
AwarName tree_name
Definition: db_query.h:43
static void field_delete_cb(AW_window *aws, Itemfield_Selection *item_sel)
Definition: ui_species.cxx:679
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
GB_ERROR write_int(long aw_int)
const MutableBoundItemSel BoundItemSel
Definition: items.h:105
const InfoWindow & registerInfoWindow(AW_window *aww, DbScanner *scanner, int detach_id)
Definition: info_window.h:142
long GBS_read_hash(const GB_HASH *hs, const char *key)
Definition: adhash.cxx:395
static void field_convert_update_typesel_cb(AW_root *root, BoundItemSel *bound_selector)
Definition: ui_species.cxx:837
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
void inc_and_check_user_abort(GB_ERROR &error)
Definition: arb_progress.h:274
void set_result_list(AW_selection_list *new_resultList)
Definition: ui_species.cxx:934
void init(AW_root *root, const char *wid, const char *windowname)
Definition: AW_window.cxx:2817
AW_selection_list * get_sellist()
Definition: aw_select.hxx:196
const char * do_delete_pos_fig
Definition: db_query.h:64
CONSTEXPR long FIELD_FILTER_STRING_READABLE
Definition: item_sel_list.h:47
const char * do_unmark_pos_fig
Definition: db_query.h:63
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:195
const char * do_refresh_pos_fig
Definition: db_query.h:67
void unquery_all()
void insert_fieldtype_toggles(AW_window *aws)
Definition: ui_species.cxx:779
QUERY_ITEM_TYPE type
Definition: items.h:50
CONSTEXPR long FIELD_UNFILTERED
Definition: item_sel_list.h:49
static const char * localize_scanner_id(const char *scanner_id, int detach_id)
Definition: info_window.h:195
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)
Definition: adhash.cxx:253
#define AWAR_NN_OLIGO_LEN
void create_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, const char *color=NULp)
Definition: AW_button.cxx:446
#define AWAR_NN_REL_MATCHES
Definition: arbdb.h:66
void AWT_activate_prompt(const char *title, const char *prompt, const char *defaultResult, const char *button, const ResultHandler &handle_result, const char *helpfile, const char *srt)
Definition: AWT_prompt.cxx:62
GBDATA * GBT_get_species_data(GBDATA *gb_main)
Definition: aditem.cxx:105