source: tags/initial/NTREE/ad_spec.cxx

Last change on this file was 2, checked in by oldcode, 24 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.7 KB
Line 
1#include <stdio.h>
2#include <string.h>
3#include <arbdb.h>
4#include <arbdbt.h>
5#include <aw_root.hxx>
6#include <aw_device.hxx>
7#include <aw_window.hxx>
8#include <aw_awars.hxx>
9#include "ad_spec.hxx"
10#include <awt.hxx>
11#include <awt_www.hxx>
12#include <awt_tree.hxx>
13#include <awt_canvas.hxx>
14#include <awt_dtree.hxx>
15#include <awtlocal.hxx>
16#include <awtc_next_neighbours.hxx>
17#include <ntree.hxx>
18
19extern GBDATA *gb_main;
20#define AD_F_ALL (AW_active)-1
21
22void create_species_var(AW_root *aw_root, AW_default aw_def)
23{
24    //  aw_root->awar_string( AWAR_SPECIES_NAME, "" ,   gb_main);
25    aw_root->awar_string( AWAR_SPECIES_DEST, "" ,       aw_def);
26    aw_root->awar_string( AWAR_SPECIES_INFO, "" ,       aw_def);
27    aw_root->awar_string( AWAR_SPECIES_KEY, "" ,        aw_def);
28    aw_root->awar_string( AWAR_FIELD_REORDER_SOURCE, "" ,       aw_def);
29    aw_root->awar_string( AWAR_FIELD_REORDER_DEST, "" , aw_def);
30    aw_root->awar_string( AWAR_FIELD_CREATE_NAME, "" ,  aw_def);
31    aw_root->awar_int( AWAR_FIELD_CREATE_TYPE, GB_STRING,       aw_def );
32    aw_root->awar_string( AWAR_FIELD_DELETE, "" ,       aw_def);
33
34}
35
36void species_rename_cb(AW_window *aww){
37    GB_ERROR error = 0;
38    char *source = aww->get_root()->awar(AWAR_SPECIES_NAME)->read_string();
39    char *dest = aww->get_root()->awar(AWAR_SPECIES_DEST)->read_string();
40    GBT_begin_rename_session(gb_main,0);
41    error = GBT_rename_species(source,dest);
42    if (!error) {
43        aww->get_root()->awar(AWAR_SPECIES_NAME)->write_string(dest);
44    }
45    if (!error) GBT_commit_rename_session(0);
46    else        GBT_abort_rename_session();
47    if (error) aw_message(error);
48    delete source;
49    delete dest;
50}
51
52void species_copy_cb(AW_window *aww){
53    GB_ERROR error = 0;
54    char *source = aww->get_root()->awar(AWAR_SPECIES_NAME)->read_string();
55    char *dest = aww->get_root()->awar(AWAR_SPECIES_DEST)->read_string();
56    GB_begin_transaction(gb_main);
57    GBDATA *gb_species_data =   GB_search(gb_main,"species_data",GB_CREATE_CONTAINER);
58    GBDATA *gb_species =                GBT_find_species_rel_species_data(gb_species_data,source);
59    GBDATA *gb_dest =           GBT_find_species_rel_species_data(gb_species_data,dest);
60    if (gb_dest) {
61        error = "Sorry: species already exists";
62    }else       if (gb_species) {
63        gb_dest = GB_create_container(gb_species_data,"species");
64        error = GB_copy(gb_dest,gb_species);
65        if (!error) {
66            GBDATA *gb_name =
67                GB_search(gb_dest,"name",GB_STRING);
68            error = GB_write_string(gb_name,dest);
69        }
70        if (!error) {
71            aww->get_root()->awar(AWAR_SPECIES_NAME)->write_string(dest);
72        }
73    }else{
74        error = "Please select a species first";
75    }
76    if (!error){
77        aww->hide();
78        GB_commit_transaction(gb_main);
79    }else{
80        GB_abort_transaction(gb_main);
81    }
82    if (error) aw_message(error);
83    delete source;
84    delete dest;
85}
86
87void move_species_to_extended(AW_window *aww){
88    GB_ERROR error = 0;
89    char *source = aww->get_root()->awar(AWAR_SPECIES_NAME)->read_string();
90    GB_begin_transaction(gb_main);
91
92    GBDATA *gb_extended_data = GB_search(gb_main,"extended_data",GB_CREATE_CONTAINER);
93    GBDATA *gb_species = GBT_find_species(gb_main,source);
94    GBDATA *gb_dest = GBT_find_SAI_rel_exdata(gb_extended_data,source);
95    if (gb_dest) {
96        error = "Sorry: SAI already exists";
97    }else       if (gb_species) {
98        gb_dest = GB_create_container(gb_extended_data,"extended");
99        error = GB_copy(gb_dest,gb_species);
100        if (!error) {
101            error = GB_delete(gb_species);
102            if (!error) {
103                aww->get_root()->awar(AWAR_SPECIES_NAME)->write_string("");
104            }
105        }
106    }else{
107        error = "Please select a species first";
108    }
109
110    if (!error) GB_commit_transaction(gb_main);
111    else        GB_abort_transaction(gb_main);
112    if (error) aw_message(error);
113    delete source;
114}
115
116
117void species_create_cb(AW_window *aww){
118    GB_ERROR error = 0;
119    char *dest = aww->get_root()->awar(AWAR_SPECIES_DEST)->read_string();
120    GB_begin_transaction(gb_main);
121    GBDATA *gb_species_data = GB_search(gb_main,"species_data",GB_CREATE_CONTAINER);
122    GBDATA *gb_dest = GBT_find_species_rel_species_data(gb_species_data,dest);
123    if (gb_dest) {
124        error = "Sorry: species already exists";
125    }else{
126        gb_dest = GBT_create_species_rel_species_data(gb_species_data,dest);
127        if (!gb_dest) error = GB_get_error();
128        if (!error) {
129            aww->get_root()->awar(AWAR_SPECIES_NAME)->write_string(dest);
130        }
131    }
132    if (!error) GB_commit_transaction(gb_main);
133    else        GB_abort_transaction(gb_main);
134    if (error) aw_message(error);
135    delete dest;
136}
137
138AW_window *create_species_rename_window(AW_root *root)
139{
140    AW_window_simple *aws = new AW_window_simple;
141    aws->init( root, "RENAME_SPECIES", "SPECIES RENAME", 100, 100 );
142    aws->load_xfig("ad_al_si.fig");
143
144    aws->callback( (AW_CB0)AW_POPDOWN);
145    aws->at("close");
146    aws->create_button("CLOSE","CLOSE","C");                       
147
148    aws->at("label");
149    aws->create_button(0,"Please enter the new name\nof the species");
150
151    aws->at("input");
152    aws->create_input_field(AWAR_SPECIES_DEST,15);
153
154    aws->at("ok");
155    aws->callback(species_rename_cb);
156    aws->create_button("GO","GO","G");                     
157
158    return (AW_window *)aws;
159}
160
161AW_window *create_species_copy_window(AW_root *root)
162{
163    AW_window_simple *aws = new AW_window_simple;
164    aws->init( root, "COPY_SPECIES", "SPECIES COPY", 100, 100 );
165    aws->load_xfig("ad_al_si.fig");
166
167    aws->callback( (AW_CB0)AW_POPDOWN);
168    aws->at("close");
169    aws->create_button("CLOSE","CLOSE","C");                       
170
171    aws->at("label");
172    aws->create_button(0,"Please enter the name\nof the new species");
173
174    aws->at("input");
175    aws->create_input_field(AWAR_SPECIES_DEST,15);
176
177    aws->at("ok");
178    aws->callback(species_copy_cb);
179    aws->create_button("GO","GO","G");                     
180
181    return (AW_window *)aws;
182}
183
184AW_window *create_species_create_window(AW_root *root)
185{
186    AW_window_simple *aws = new AW_window_simple;
187    aws->init( root, "CREATE_SPECIES","SPECIES CREATE", 100, 100 );
188    aws->load_xfig("ad_al_si.fig");
189
190    aws->callback( (AW_CB0)AW_POPDOWN);
191    aws->at("close");
192    aws->create_button("CLOSE","CLOSE","C");                       
193
194    aws->at("label");
195    aws->create_button(0,"Please enter the name\nof the new species");
196
197    aws->at("input");
198    aws->create_input_field(AWAR_SPECIES_DEST,15);
199
200    aws->at("ok");
201    aws->callback(species_create_cb);
202    aws->create_button("GO","GO","G");                     
203
204    return (AW_window *)aws;
205}
206
207void ad_species_delete_cb(AW_window *aww){
208    if (aw_message("Are you sure to delete the species","OK,CANCEL"))return;
209    GB_ERROR error = 0;
210    char *source = aww->get_root()->awar(AWAR_SPECIES_NAME)->read_string();
211    GB_begin_transaction(gb_main);
212    GBDATA *gb_species = GBT_find_species(gb_main,source);
213       
214    if (gb_species) error = GB_delete(gb_species);
215    else                error = "Please select a species first";
216
217    if (!error) GB_commit_transaction(gb_main);
218    else        GB_abort_transaction(gb_main);
219
220    if (error) aw_message(error);
221    delete source;
222}
223static AW_CL ad_global_scannerid = 0;
224static AW_root *ad_global_scannerroot = 0;
225
226void AD_map_species(AW_root *aw_root, AW_CL scannerid)
227{
228    GB_push_transaction(gb_main);
229    char *source = aw_root->awar(AWAR_SPECIES_NAME)->read_string();
230    GBDATA *gb_species = GBT_find_species(gb_main,source);
231    if (gb_species) 
232        awt_map_arbdb_scanner(scannerid,gb_species,0);
233    GB_pop_transaction(gb_main);
234    delete source;
235}
236
237void AD_map_viewer(GBDATA *gbd,AD_MAP_VIEWER_TYPE type)
238{
239    GB_push_transaction(gb_main);
240    if (ad_global_scannerid){
241        GBDATA *gb_species_data =       GB_search(gb_main,"species_data",GB_CREATE_CONTAINER);
242        if (gbd && GB_get_father(gbd)==gb_species_data) {
243            // I got a species !!!!!!
244            GBDATA *gb_name = GB_find(gbd,"name",0,down_level);
245            if (gb_name) {
246                char *name = GB_read_string(gb_name);
247                ad_global_scannerroot->awar(AWAR_SPECIES_NAME)->write_string(name);
248                                // that will map the species
249            }else{
250                ad_global_scannerroot->awar(AWAR_SPECIES_NAME)->write_string("");
251                awt_map_arbdb_scanner(ad_global_scannerid,gbd,0);
252                                // do it by hand
253            }
254        }else{
255            ad_global_scannerroot->awar(AWAR_SPECIES_NAME)->write_string("");
256            awt_map_arbdb_scanner(ad_global_scannerid,gbd,0);
257            // do it by hand
258        }
259    }
260    while (gbd && type == ADMVT_WWW){
261        char *name = strdup("noname");
262        GBDATA *gb_name = GB_find(gbd,"name",0,down_level);
263        if (!gb_name) gb_name = GB_find(gbd,"group_name",0,down_level); // bad hack, should work
264        if (gb_name){
265            delete name;
266            name = GB_read_string(gb_name);
267        }
268        GB_ERROR error = awt_openURL_by_gbd(nt.awr,gb_main,gbd, name);
269        if (error) aw_message(error);
270        break;
271    }
272    GB_pop_transaction(gb_main);
273}
274
275void ad_list_reorder_cb(AW_window *aws) {
276    GB_begin_transaction(gb_main);
277    char *source = aws->get_root()->awar(AWAR_FIELD_REORDER_SOURCE)->read_string();
278    char *dest = aws->get_root()->awar(AWAR_FIELD_REORDER_DEST)->read_string();
279    GB_ERROR warning = 0;
280
281    GBDATA *gb_source = awt_get_key(gb_main,source);
282    GBDATA *gb_dest = awt_get_key(gb_main,dest);
283    GBDATA *gb_key_data =
284        GB_search(gb_main,CHANGE_KEY_PATH,GB_CREATE_CONTAINER);
285    if (!gb_source) {
286        aw_message("Please select an item you want to move (left box)");
287    }
288    if (gb_source &&!gb_dest) {
289        aw_message("Please select a destination where to place your item (right box)");
290    }
291    if (gb_source && gb_dest && (gb_dest !=gb_source) ) {
292        GBDATA **new_order;
293        int nitems = 0;
294        GBDATA *gb_cnt;
295        for (   gb_cnt  = GB_find(gb_key_data,0,0,down_level);
296                gb_cnt;
297                gb_cnt = GB_find(gb_cnt,0,0,this_level|search_next)){
298            nitems++;
299        }
300        new_order = new GBDATA *[nitems];
301        nitems = 0;
302        for (   gb_cnt  = GB_find(gb_key_data,0,0,down_level);
303                gb_cnt;
304                gb_cnt = GB_find(gb_cnt,0,0,this_level|search_next)){
305            if (gb_cnt == gb_source) continue;
306            new_order[nitems++] = gb_cnt;
307            if (gb_cnt == gb_dest) {
308                new_order[nitems++] = gb_source;
309            }
310        }
311        warning = GB_resort_data_base(gb_main,new_order,nitems);
312        delete new_order;
313    }
314
315    delete source;
316    delete dest;
317    GB_commit_transaction(gb_main);
318    if (warning) aw_message(warning);
319}
320
321AW_window *create_ad_list_reorder(AW_root *root)
322{
323    static AW_window_simple *aws = 0;
324    if (aws) return (AW_window *)aws;
325    aws = new AW_window_simple;
326    aws->init( root, "REORDER_FIELDS", "REORDER FIELDS",600, 200 );
327    aws->load_xfig("ad_kreo.fig");
328
329    aws->callback( (AW_CB0)AW_POPDOWN);
330    aws->at("close");
331    aws->create_button("CLOSE","CLOSE","C");                       
332
333    aws->at("doit");
334    aws->button_length(0);
335    aws->callback(ad_list_reorder_cb);
336    aws->help_text("spaf_reorder.hlp");
337    aws->create_button("MOVE_TO_NEW_POSITION",
338                       "MOVE  SELECTED LEFT  ITEM\nAFTER SELECTED RIGHT ITEM","P");
339
340    awt_create_selection_list_on_scandb(gb_main,
341                                        (AW_window*)aws,AWAR_FIELD_REORDER_SOURCE,
342                                        AWT_NDS_FILTER,
343                                        "source",0);
344    awt_create_selection_list_on_scandb(gb_main,
345                                        (AW_window*)aws,AWAR_FIELD_REORDER_DEST,
346                                        AWT_NDS_FILTER,
347                                        "dest",0);
348
349    return (AW_window *)aws;
350}
351
352void ad_field_only_delete(AW_window *aws)
353{
354    AWUSE(aws);
355
356    GB_begin_transaction(gb_main);
357    char *source = aws->get_root()->awar(AWAR_FIELD_DELETE)->read_string();
358    GB_ERROR error = 0;
359
360    GBDATA *gb_source = awt_get_key(gb_main,source);
361    if (!gb_source) {
362        aw_message("Please select an item you want to delete");
363    }else{
364        error = GB_delete(gb_source);
365    }
366    delete source;
367    if (error) {
368        GB_abort_transaction(gb_main);
369        if (error) aw_message(error);
370    }else{
371        GB_commit_transaction(gb_main);
372    }
373}
374
375void ad_field_delete(AW_window *aws)
376{
377    AWUSE(aws);
378
379    GB_begin_transaction(gb_main);
380    char *source = aws->get_root()->awar(AWAR_FIELD_DELETE)->read_string();
381    GB_ERROR error = 0;
382
383    GBDATA *gb_source = awt_get_key(gb_main,source);
384    if (!gb_source) {
385        aw_message("Please select an item you want to delete");
386    }else{
387        error = GB_delete(gb_source);
388    }
389    GBDATA *gb_species;
390
391    for (gb_species = GBT_first_species(gb_main);
392         !error && gb_species;
393         gb_species = GBT_next_species(gb_species)){
394        GBDATA *gbd = GB_search(gb_species,source,GB_FIND);
395        if (gbd){
396            error = GB_delete(gbd);
397        }
398    }
399
400    delete source;
401    if (error) {
402        GB_abort_transaction(gb_main);
403        if (error) aw_message(error);
404    }else{
405        GB_commit_transaction(gb_main);
406    }
407}
408
409AW_window *create_ad_field_delete(AW_root *root)
410{
411    static AW_window_simple *aws = 0;
412    if (aws) return (AW_window *)aws;
413    aws = new AW_window_simple;
414    aws->init( root, "DELETE_FIELD", "DELETE FIELD", 600, 200 );
415    aws->load_xfig("ad_delof.fig");
416    aws->button_length(6);
417       
418    aws->at("close");aws->callback( AW_POPDOWN);
419    aws->create_button("CLOSE","CLOSE","C");                       
420
421    aws->at("help");aws->callback( AW_POPUP_HELP,(AW_CL)"spaf_delete.hlp");
422    aws->create_button("HELP","HELP","H");                         
423
424    aws->at("doit");
425    aws->callback(ad_field_only_delete);
426    aws->help_text("rm_field_only.hlp");
427    aws->create_button("HIDE_FIELD","HIDE FIELD\n(NOTHING DELETED)","F");
428
429    aws->at("delf");
430    aws->callback(ad_field_delete);
431    aws->help_text("rm_field_cmpt.hlp");
432    aws->create_button("DELETE_FIELD", "DELETE FIELD\n(DATA DELETED)","C");
433
434    awt_create_selection_list_on_scandb(gb_main,
435                                        (AW_window*)aws,AWAR_FIELD_DELETE,
436                                        -1,
437                                        "source",0);
438
439    return (AW_window *)aws;
440}
441
442void ad_field_create_cb(AW_window *aws)
443{
444    GB_push_transaction(gb_main);
445    char *name = aws->get_root()->awar(AWAR_FIELD_CREATE_NAME)->read_string();
446    GB_ERROR error = GB_check_key(name);
447    GB_ERROR error2 = GB_check_hkey(name);
448    if (error && !error2) {
449        aw_message("Warning: Your key contain a '/' character,\n"
450                   "    that means it is a hierarchical key");
451        error = 0;
452    }
453
454    int type = (int)aws->get_root()->awar(AWAR_FIELD_CREATE_TYPE)->read_int();
455
456    if(!error) error = awt_add_new_changekey(gb_main, name, type);
457    if (error) {
458        aw_message(error);
459    }else{
460        aws->hide();
461    }
462    delete name;
463    GB_pop_transaction(gb_main); 
464}
465
466AW_window *create_ad_field_create(AW_root *root)
467{
468    static AW_window_simple *aws = 0;
469    if (aws) return (AW_window *)aws;
470    aws = new AW_window_simple;
471    aws->init( root, "CREATE_FIELD","CREATE A NEW FIELD", 400, 100 );
472    aws->load_xfig("ad_fcrea.fig");
473
474    aws->callback( (AW_CB0)AW_POPDOWN);
475    aws->at("close");
476    aws->create_button("CLOSE","CLOSE","C");                       
477
478
479    aws->at("input");
480    aws->label("FIELD NAME");
481    aws->create_input_field(AWAR_FIELD_CREATE_NAME,15);
482
483    aws->at("type");
484    aws->create_toggle_field(AWAR_FIELD_CREATE_TYPE,"FIELD TYPE","F");
485    aws->insert_toggle("Ascii Text","S",                (int)GB_STRING);
486    aws->insert_toggle("Link","L",                      (int)GB_LINK);
487    aws->insert_toggle("Rounded Numerical","N", (int)GB_INT);
488    aws->insert_toggle("Numerical","R",         (int)GB_FLOAT);
489    aws->insert_toggle("MASK = 01 Text","0",    (int)GB_BITS);
490    aws->update_toggle_field();
491
492
493    aws->at("ok");
494    aws->callback(ad_field_create_cb);
495    aws->create_button("CREATE","CREATE","C");                     
496
497    return (AW_window *)aws;
498}
499
500void ad_spec_create_field_items(AW_window *aws) {
501    aws->insert_menu_topic("reorder_fields",    "Reorder    Fields ...",        "r","spaf_reorder.hlp", AD_F_ALL,       AW_POPUP, (AW_CL)create_ad_list_reorder, 0 );
502    aws->insert_menu_topic("delete_field",              "Delete/Hide Field ...","D","spaf_delete.hlp",  AD_F_ALL,       AW_POPUP, (AW_CL)create_ad_field_delete, 0 );
503    aws->insert_menu_topic("create_field",              "Create Field ...",     "C","spaf_create.hlp",  AD_F_ALL,       AW_POPUP, (AW_CL)create_ad_field_create, 0 );
504    aws->insert_menu_topic("unhide_fields",             "Scan Database for all Hidden Fields","S","scandb.hlp",AD_F_ALL,(AW_CB)awt_selection_list_rescan_cb, (AW_CL)gb_main, AWT_NDS_FILTER );
505}
506
507#include <probe_design.hxx>
508
509void awtc_nn_search_all_listed(AW_window *aww,AW_CL _cbs  ){
510    struct adaqbsstruct *cbs = (struct adaqbsstruct *)_cbs;
511    GB_begin_transaction(gb_main);
512    int pts = aww->get_root()->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int();
513    char *dest_field = aww->get_root()->awar("next_neighbours/dest_field")->read_string();
514    char *ali_name = aww->get_root()->awar(AWAR_DEFAULT_ALIGNMENT)->read_string();
515    GB_ERROR error = 0;
516    GB_TYPES dest_type = awt_get_type_of_changekey(gb_main,dest_field);
517    if (!dest_type){
518        error = GB_export_error("Please select a valid field");
519    }
520    long max = awt_count_queried_species(cbs);
521   
522    if (strcmp(dest_field, "name")==0) {
523        int answer = aw_message("CAUTION! This will destroy all name-fields of the listed species.\n",
524                                "Continue and destroy all name-fields,Abort");
525       
526        if (answer==1) {
527            error = GB_export_error("Aborted by user");
528        }
529    } 
530   
531    aw_openstatus("Finding next neighbours");
532    long count = 0;
533    GBDATA *gb_species;
534    for (gb_species = GBT_first_species(gb_main);
535         !error && gb_species;
536         gb_species = GBT_next_species(gb_species)){
537        if (!IS_QUERIED(gb_species,cbs)) continue;
538        count ++;
539        GBDATA *gb_data = GBT_read_sequence(gb_species,ali_name);
540        if (!gb_data)   continue;
541        if (count %10 == 0){
542            GBDATA *gb_name = GB_search(gb_species,"name",GB_STRING);
543            aw_status(GBS_global_string("Species '%s' (%i:%i)",
544                                        GB_read_char_pntr(gb_name),
545                                        count, max));
546        }
547        if (aw_status(count/(double)max)){
548            error = "operation aborted";
549            break;
550        }
551        {
552            char *sequence = GB_read_string(gb_data);
553            AWTC_FIND_FAMILY ff(gb_main);
554            error = ff.go(pts,sequence,GB_TRUE,1);     
555            if (error) break;
556            {
557                AWTC_FIND_FAMILY_MEMBER *fm = ff.family_list;
558                const char *value;
559                if (fm){
560                    value = GBS_global_string("%i '%s'",fm->matches,fm->name);
561                }else{
562                    value = "0";
563                }
564                GBDATA *gb_dest = GB_search(gb_species,dest_field,dest_type);
565                error = GB_write_as_string(gb_dest,value);
566            }   
567            delete sequence;
568        }
569    }
570    aw_closestatus();
571    if (error){
572        GB_abort_transaction(gb_main);
573        aw_message(error);
574    }else{
575        GB_commit_transaction(gb_main);
576    }
577    delete dest_field;
578    delete ali_name;
579}
580void awtc_nn_search(AW_window *aww,AW_CL id ){
581    GB_transaction dummy(gb_main);
582    int pts = aww->get_root()->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int();
583    int max_hits = aww->get_root()->awar("next_neighbours/max_hits")->read_int();
584    char *sequence = 0;
585    {
586        char *sel_species =     aww->get_root()->awar(AWAR_SPECIES_NAME)->read_string();
587        GBDATA *gb_species =    GBT_find_species(gb_main,sel_species);
588
589        if (!gb_species){
590            delete sel_species;
591            aw_message("Select a species first");
592            return;
593        }
594        char *ali_name = aww->get_root()->awar(AWAR_DEFAULT_ALIGNMENT)->read_string();
595        GBDATA *gb_data = GBT_read_sequence(gb_species,ali_name);
596        if (!gb_data){
597            aw_message(GBS_global_string("Species '%s' has no sequence '%s'",sel_species,ali_name));
598        }
599        delete sel_species;
600        delete ali_name;
601        if (!gb_data) return;
602        sequence = GB_read_string(gb_data);
603    }
604   
605    AWTC_FIND_FAMILY ff(gb_main);
606    GB_ERROR error = ff.go(pts,sequence,GB_TRUE,max_hits);
607    delete sequence;
608    AW_selection_list* sel = (AW_selection_list *)id;
609    aww->clear_selection_list(sel);
610    if (error) {
611        aw_message(error);
612        aww->insert_default_selection(sel,"No hits found","");
613    }else{
614        AWTC_FIND_FAMILY_MEMBER *fm;
615        for (fm = ff.family_list; fm; fm = fm->next){
616            const char *dis = GBS_global_string("%-20s Score:%4i",fm->name,fm->matches);
617            aww->insert_selection(sel,(char *)dis,fm->name);
618        }
619       
620        aww->insert_default_selection(sel,"No more hits","");
621    }
622    aww->update_selection_list(sel);
623}
624void awtc_move_hits(AW_window *,AW_CL id, AW_CL cbs){
625    awt_copy_selection_list_2_queried_species((struct adaqbsstruct *)cbs,(AW_selection_list *)id);
626}
627
628AW_window *ad_spec_next_neighbours_listed_create(AW_root *aw_root,AW_CL cbs){
629    static AW_window_simple *aws = 0;
630    if (aws){
631        return (AW_window *)aws;
632    }
633    aw_root->awar_int(AWAR_PROBE_ADMIN_PT_SERVER);
634    aw_root->awar_string("next_neighbours/dest_field","tmp");
635       
636    aws = new AW_window_simple;
637    aws->init( aw_root, "SEARCH_NEXT_RELATIVES_OF_LISTED", "Search Next Neighbours of Listed", 600, 0 );
638    aws->load_xfig("ad_spec_nnm.fig");
639       
640    aws->at("close");
641    aws->callback( (AW_CB0)AW_POPDOWN);
642    aws->create_button("CLOSE","CLOSE","C");                       
643
644    aws->at("help");
645    aws->callback(AW_POPUP_HELP, (AW_CL)"next_neighbours_marked.hlp");
646    aws->create_button("HELP","HELP","H");                         
647
648    aws->at("pt_server");
649    probe_design_build_pt_server_choices(aws,AWAR_PROBE_ADMIN_PT_SERVER,AW_FALSE);
650
651
652       
653    aws->at("field");
654    awt_create_selection_list_on_scandb(gb_main,aws,"next_neighbours/dest_field",
655                                        (1<<GB_INT) | (1<<GB_STRING), "field",0);
656
657
658    aws->at("go");
659    aws->callback(awtc_nn_search_all_listed,cbs);
660    aws->create_button("SEARCH","SEARCH");                         
661       
662    return (AW_window *)aws;
663}
664
665AW_window *ad_spec_next_neighbours_create(AW_root *aw_root,AW_CL cbs){
666    static AW_window_simple *aws = 0;
667    if (aws){
668        return (AW_window *)aws;
669    }
670    aw_root->awar_int(AWAR_PROBE_ADMIN_PT_SERVER);
671    aw_root->awar_int("next_neighbours/max_hits",20);
672       
673    aws = new AW_window_simple;
674    aws->init( aw_root, "SEARCH_NEXT_RELATIVE_OF_SELECTED", "Search Next Neighbours", 600, 0 );
675    aws->load_xfig("ad_spec_nn.fig");
676       
677    aws->at("close");
678    aws->callback( (AW_CB0)AW_POPDOWN);
679    aws->create_button("CLOSE","CLOSE","C");                       
680
681    aws->at("help");
682    aws->callback(AW_POPUP_HELP, (AW_CL)"next_neighbours.hlp");
683    aws->create_button("HELP","HELP","H");                         
684
685    aws->at("pt_server");
686    probe_design_build_pt_server_choices(aws,AWAR_PROBE_ADMIN_PT_SERVER,AW_FALSE);
687
688    aws->at("max_hit");
689    aws->create_input_field("next_neighbours/max_hits",5);
690       
691    aws->at("hits");
692    AW_selection_list *id = aws->create_selection_list(AWAR_SPECIES_NAME);
693    aws->insert_default_selection(id,"No hits found","");
694    aws->update_selection_list(id);
695
696    aws->at("go");
697    aws->callback(awtc_nn_search,(AW_CL)id);
698    aws->create_button("SEARCH","SEARCH");                         
699
700    aws->at("move");
701    aws->callback(awtc_move_hits,(AW_CL)id,cbs);
702    aws->create_button("MOVE_TO_HITLIST","MOVE TO HITLIST");                       
703       
704    return (AW_window *)aws;
705}
706AW_window *create_species_window(AW_root *aw_root)
707{
708    static AW_window_simple_menu *aws = 0;
709    if (aws){
710        return (AW_window *)aws;
711    }
712    aws = new AW_window_simple_menu;
713    aws->init( aw_root, "SPECIES_INFORMATION", "SPECIES INFORMATION", 0,0,800, 0 );
714    aws->load_xfig("ad_spec.fig");
715
716    aws->button_length(8);
717
718    aws->at("close");
719    aws->callback( (AW_CB0)AW_POPDOWN);
720    aws->create_button("CLOSE","CLOSE","C");                       
721
722    aws->at("search");
723    aws->callback(AW_POPUP, (AW_CL)ad_create_query_window, 0);
724    aws->create_button("SEARCH","SEARCH","S");                     
725
726    aws->at("help");
727    aws->callback(AW_POPUP_HELP, (AW_CL)"species_info.hlp");
728    aws->create_button("HELP","HELP","H");                         
729
730
731    AW_CL scannerid = awt_create_arbdb_scanner(gb_main, aws, "box",0,"field","enable",AWT_VIEWER,0,"mark",AWT_NDS_FILTER);
732    ad_global_scannerid = scannerid;
733    ad_global_scannerroot = aws->get_root();
734
735    aws->create_menu(       0,   "SPECIES",     "E", "spa_species.hlp",  AD_F_ALL );
736    aws->insert_menu_topic("species_delete",    "Delete",       "D","spa_delete.hlp",   AD_F_ALL,       (AW_CB)ad_species_delete_cb, 0, 0);
737    aws->insert_menu_topic("species_rename",    "Rename ...",   "R","spa_rename.hlp",   AD_F_ALL,       AW_POPUP, (AW_CL)create_species_rename_window, 0);
738    aws->insert_menu_topic("species_copy",              "Copy ...",     "C","spa_copy.hlp",     AD_F_ALL,       AW_POPUP, (AW_CL)create_species_copy_window, 0);
739    aws->insert_menu_topic("species_create",    "Create ...",   "R","spa_create.hlp",   AD_F_ALL,       AW_POPUP, (AW_CL)create_species_create_window, 0);
740    aws->insert_menu_topic("species_convert_2_sai",     "Convert to SAI","E","sp_sp_2_ext.hlp",AD_F_ALL,        (AW_CB)move_species_to_extended, 0, 0);
741    aws->insert_separator();
742
743    aws->create_menu(       0,   "FIELDS",     "I", "spa_fields.hlp",  AD_F_ALL );
744    ad_spec_create_field_items(aws);
745
746    aws->get_root()->awar(AWAR_SPECIES_NAME)->add_callback(     AD_map_species,scannerid);
747       
748    aws->show();
749    AD_map_species(aws->get_root(),scannerid);
750    return (AW_window *)aws;
751}
752
753AW_CL ad_query_global_cbs = 0;
754
755void ad_unquery_all(){
756    awt_unquery_all(0,(struct adaqbsstruct *)ad_query_global_cbs);
757}
758
759void ad_query_update_list(){
760    awt_query_update_list(NULL,(struct adaqbsstruct *)ad_query_global_cbs);
761}
762
763AW_window *ad_create_query_window(AW_root *aw_root)
764{
765    static AW_window_simple_menu *aws = 0;
766    if (aws){
767        return (AW_window *)aws;
768    }
769    aws = new AW_window_simple_menu;
770    aws->init( aw_root, "SPECIES_QUERY", "SEARCH and QUERY", 0,0,500, 0 );
771    aws->create_menu(0,"MORE_FUNCTIONS","F");
772    aws->load_xfig("ad_query.fig");
773
774
775    awt_query_struct awtqs;
776
777    awtqs.gb_main               = gb_main;
778    awtqs.species_name  = AWAR_SPECIES_NAME;
779    awtqs.select_bit    = 1;
780    awtqs.use_menu              = 1;
781    awtqs.ere_pos_fig   = "ere";
782    awtqs.by_pos_fig    = "by";
783    awtqs.qbox_pos_fig  = "qbox";
784    awtqs.rescan_pos_fig        = 0;
785    awtqs.key_pos_fig   = 0;
786    awtqs.query_pos_fig = "content";
787    awtqs.result_pos_fig        = "result";
788    awtqs.count_pos_fig = "count";
789    awtqs.do_query_pos_fig      = "doquery";
790    awtqs.do_mark_pos_fig       = "domark";
791    awtqs.do_unmark_pos_fig     = "dounmark";
792    awtqs.do_delete_pos_fig     = "dodelete";
793    awtqs.do_set_pos_fig        = "doset";
794    awtqs.do_refresh_pos_fig= "dorefresh";
795    awtqs.open_parser_pos_fig= "openparser";
796    awtqs.create_view_window= (AW_CL)create_species_window;
797    AW_CL cbs = (AW_CL)awt_create_query_box((AW_window*)aws,&awtqs);
798    ad_query_global_cbs = cbs;
799    aws->create_menu(       0,   "MORE_SEARCH",     "S" );
800    aws->insert_menu_topic( "search_equal_fields_within_db","Search For Equal Fields and Mark Duplikates",                      "E",0,  -1, (AW_CB)awt_search_equal_entries, cbs, 0 );
801    aws->insert_menu_topic( "search_equal_words_within_db", "Search For Equal Words Between Fields and Mark Duplikates",        "W",0,  -1, (AW_CB)awt_search_equal_entries, cbs, 1 );
802    aws->insert_menu_topic( "search_next_relativ_of_sel",       "Search Next Relatives of SELECTED Species in PT_Server ...",   "R",0,  -1, (AW_CB)AW_POPUP,    (AW_CL)ad_spec_next_neighbours_create, cbs );
803    aws->insert_menu_topic( "search_next_relativ_of_listed","Search Next Relatives of LISTED Species in PT_Server ...",         "M",0,  -1, (AW_CB)AW_POPUP,    (AW_CL)ad_spec_next_neighbours_listed_create, cbs );
804
805    aws->button_length(7);
806
807    aws->at("close");
808    aws->callback( (AW_CB0)AW_POPDOWN);
809    aws->create_button("CLOSE","CLOSE","C");                       
810
811    aws->at("help");
812    aws->callback( AW_POPUP_HELP,(AW_CL)"sp_search.hlp");
813    aws->create_button("HELP","HELP","H");                         
814
815    return (AW_window *)aws;
816}
Note: See TracBrowser for help on using the repository browser.