source: tags/arb_5.1/EDIT4/ED4_root.cxx

Last change on this file was 6169, checked in by westram, 15 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 77.0 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4#include <memory.h>
5#include <string.h>
6
7#include <arbdb.h>
8#include <arbdbt.h>
9
10#include <aw_root.hxx>
11#include <aw_awars.hxx>
12#include <aw_window.hxx>
13#include <aw_preset.hxx>
14
15#include <awt.hxx>
16#include <awt_seq_colors.hxx>
17#include <awt_map_key.hxx>
18
19#include <fast_aligner.hxx>
20#include <awtc_constructSequence.hxx>
21
22#include <arb_version.h>
23
24#include <AW_helix.hxx>
25#include <st_window.hxx>
26#include <gde.hxx>
27
28#include <ed4_extern.hxx>
29
30#include "ed4_class.hxx"
31#include "ed4_awars.hxx"
32#include "ed4_tools.hxx"
33#include "ed4_block.hxx"
34#include "ed4_dots.hxx"
35#include "ed4_nds.hxx"
36#include "ed4_secedit.hxx"
37#include "ed4_visualizeSAI.hxx"
38#include "edit_naligner.hxx"
39#include "ed4_ProteinViewer.hxx"
40#include "ed4_protein_2nd_structure.hxx"
41#include "graph_aligner_gui.hxx"
42
43#if defined(ARB_OPENGL)
44#include "ed4_RNA3D.hxx"
45#endif // ARB_OPENGL
46
47AW_window *AWTC_create_island_hopping_window(AW_root *root, AW_CL );
48
49//*****************************************
50//* ED4_root Methods        beginning *
51//*****************************************
52
53// ED4_returncode ED4_root::resize_all_windows( void )     // resizes all windows for updating folding actions, new groups, movements etc.
54// {
55//     ED4_window   *window, *ed4w_temp;
56//     AW_window    *aw_temp;
57//     AW_device    *dev_temp;
58
59//     ed4w_temp = ED4_ROOT->temp_ed4w;
60//     aw_temp   = ED4_ROOT->temp_aww;
61//     dev_temp  = ED4_ROOT->temp_device;
62
63//     window = ED4_ROOT->first_window;
64//     while (window)
65//     {
66//  ED4_ROOT->temp_aww  = window->aww;
67//  ED4_ROOT->temp_device   = window->aww->get_device(AW_MIDDLE_AREA);
68//  ED4_ROOT->temp_ed4w     = window;
69
70//  ED4_ROOT->resize_all();
71//  ED4_ROOT->temp_ed4w->update_scrolled_rectangle();
72// //   ED4_ROOT->main_manager->clear_whole_background();
73//  ED4_ROOT->show_all();
74
75//  window = window->next;
76//     }
77
78//     ED4_ROOT->temp_ed4w = ed4w_temp;
79//     ED4_ROOT->temp_aww = aw_temp;
80//     ED4_ROOT->temp_device = dev_temp;
81
82//     return ( ED4_R_OK );
83// }
84
85ED4_returncode ED4_root::refresh_window_simple(int redraw)
86{
87    e4_assert(!main_manager->update_info.delete_requested);
88    e4_assert(!main_manager->update_info.resize);
89
90    int refresh_all = 0;
91    if (redraw) {
92        main_manager->update_info.set_clear_at_refresh(1);
93        refresh_all = 1;
94    }
95    main_manager->Show(refresh_all, 0);
96    return ( ED4_R_OK );
97}
98
99ED4_returncode ED4_root::refresh_window(int redraw) // this function should only be used for window specific updates (i.e. cursor placement)
100{
101    if (main_manager->update_info.delete_requested) {
102        main_manager->delete_requested_childs();
103        redraw = 1;
104    }
105
106    while (main_manager->update_info.resize) {
107        main_manager->resize_requested_by_parent();
108        redraw = 1;
109    }
110
111    return refresh_window_simple(redraw);
112}
113
114ED4_returncode ED4_root::refresh_all_windows(int redraw)
115{
116    ED4_window *old_window = get_ed4w();
117
118    last_window_reached = 0;
119
120    if (main_manager->update_info.delete_requested) {
121        main_manager->delete_requested_childs();
122        redraw = 1;
123    }
124
125    while (main_manager->update_info.resize) {
126        main_manager->resize_requested_by_parent();
127        redraw = 1;
128    }
129
130    ED4_window *window = first_window;
131    GB_transaction dummy(GLOBAL_gb_main);
132    while (window) {
133        if (!window->next) last_window_reached = 1;
134        use_window(window);
135        refresh_window_simple(redraw);
136        window = window->next;
137    }
138
139    use_window(old_window);
140
141    return ( ED4_R_OK );
142}
143
144
145ED4_returncode ED4_root::win_to_world_coords( AW_window *aww, AW_pos *x, AW_pos *y )            // calculates transformation from window to
146{                                                   // world coordinates in a given window
147    ED4_window        *current_window;
148    ED4_folding_line  *current_fl;
149    AW_pos             temp_x, temp_y;
150
151    current_window = first_window->get_matching_ed4w( aww );
152
153    if ( current_window == NULL )
154        return ( ED4_R_WARNING );
155
156    temp_x = *x;
157    temp_y = *y;
158
159    current_fl = current_window->vertical_fl;                           // calculate x-offset due to vertical folding lines
160    while ( (current_fl != NULL) && (*x >= current_fl->world_pos[X_POS]) )
161    {
162        if (    (current_fl->length == INFINITE) ||
163                ((*y >= current_fl->window_pos[Y_POS]) && (*y <= (current_fl->window_pos[Y_POS] + current_fl->length))) )
164            temp_x += current_fl->dimension;
165
166        current_fl = current_fl->next;
167    }
168
169    current_fl = current_window->horizontal_fl;                         // calculate y-offset due to horizontal folding lines
170    while ( (current_fl != NULL) && (*y >= current_fl->world_pos[Y_POS]) )
171    {
172        if (      (current_fl->length == INFINITE) ||
173                  ((*x >= current_fl->window_pos[X_POS]) && (*x <= (current_fl->window_pos[X_POS] + current_fl->length))) )
174            temp_y += current_fl->dimension;
175
176        current_fl = current_fl->next;
177    }
178
179    *x = temp_x;
180    *y = temp_y;
181
182    return ( ED4_R_OK );
183}
184
185
186short ED4_root::is_primary_selection(ED4_terminal *object )
187{
188    ED4_list_elem        *tmp_elem;
189    ED4_selection_entry  *tmp_entry;
190
191    tmp_elem = ( ED4_list_elem *) selected_objects.last();
192    if (!tmp_elem) return 0;
193
194    tmp_entry = ( ED4_selection_entry *) tmp_elem->elem();
195    return (tmp_entry != NULL) && (tmp_entry->object == object);
196}
197
198ED4_returncode ED4_root::deselect_all( void )
199{
200    ED4_multi_species_manager *main_multi_man = middle_area_man->get_defined_level(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
201
202    main_multi_man->deselect_all_species();
203    main_multi_man = top_area_man->get_defined_level(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
204    main_multi_man->deselect_all_species();
205
206    return ED4_R_OK;
207
208    //     ED4_list_elem        *current_list_elem;
209    //     ED4_selection_entry  *tmp_entry;
210
211    //     current_list_elem = selected_objects.last();
212
213    //     while ( current_list_elem ) {
214    //  tmp_entry = ( ED4_selection_entry *) current_list_elem->elem();
215    //  ED4_terminal *term = tmp_entry->object;
216    //  remove_from_selected(term);
217    //  current_list_elem = selected_objects.first();
218    //     }
219
220    //     return ( ED4_R_OK );
221}
222
223ED4_returncode  ED4_root::remove_from_selected( ED4_terminal *object )
224{
225    if ( object == NULL )
226        return ( ED4_R_IMPOSSIBLE );
227
228    if ( (selected_objects.is_elem( (void *) object->selection_info )) ) {
229        selected_objects.delete_elem( (void *) object->selection_info );
230
231        delete object->selection_info;
232        object->selection_info = NULL;
233        object->flag.selected = 0;
234        object->flag.dragged = 0;
235
236        if (object->is_species_name_terminal()) {
237            ED4_species_name_terminal *name_term = object->to_species_name_terminal();
238
239#ifdef DEBUG
240            GBDATA *gbd = name_term->get_species_pointer();
241
242            if (gbd) {
243                printf("removed term '%s'\n", GB_read_char_pntr(gbd));
244            }
245            else {
246                ED4_species_manager *spec_man = name_term->get_parent(ED4_L_SPECIES)->to_species_manager();
247
248                if (spec_man->flag.is_consensus) {
249                    printf("removed consensus '%s'\n", name_term->id);
250                }
251                else {
252                    printf("removed unknown term '%s'\n", name_term->id ? name_term->id : "NULL");
253                }
254            }
255#endif
256
257            name_term->set_refresh(1);
258            name_term->parent->refresh_requested_by_child();
259
260            ED4_sequence_terminal *seq_term = object->to_species_name_terminal()->corresponding_sequence_terminal();
261            if (seq_term) {
262                seq_term->set_refresh(1);
263                seq_term->parent->refresh_requested_by_child();
264            }
265
266            //ProtView: Refresh corresponding AA_sequence terminals
267            if (alignment_type == GB_AT_DNA) {
268                PV_CallBackFunction(this->aw_root); 
269            }
270
271            ED4_multi_species_manager *multi_man = object->get_parent(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
272            multi_man->invalidate_species_counters();
273        }
274        else {
275            object->set_refresh();
276            object->parent->refresh_requested_by_child();
277        }
278    }
279
280    return ( ED4_R_OK );
281}
282
283void ED4_root::announce_deletion(ED4_base *object) {
284    // remove any links which might point to the object
285
286    ED4_cursor& cursor = get_ed4w()->cursor;
287    if (cursor.owner_of_cursor == object) { // about to delete owner_of_cursor
288        cursor.HideCursor();
289        e4_assert(cursor.owner_of_cursor != object);
290    }
291}
292
293
294ED4_returncode ED4_root::add_to_selected( ED4_terminal *object )
295{
296    ED4_base            *tmp_object;
297    ED4_level            mlevel;
298    ED4_terminal        *sel_object;
299    ED4_selection_entry *sel_info;
300
301
302    if ( (object == NULL) || !(object->dynamic_prop & ED4_P_SELECTABLE) ) { // check if object exists and may be selected
303        return ( ED4_R_IMPOSSIBLE );
304    }
305
306    if ( selected_objects.no_of_entries() > 0 ) { // check if object is of the same type as previously selected objects
307        sel_info = (ED4_selection_entry *) selected_objects.first()->elem();
308        sel_object = sel_info->object;
309        if ( object->spec->level != sel_object->spec->level ) { // object levels are different
310            return ( ED4_R_IMPOSSIBLE );
311        }
312    }
313
314
315    if ( !(selected_objects.is_elem( (void *) object->selection_info )) ) { // object is really new to our list => calculate current extension and append it
316        object->selection_info = new ED4_selection_entry;
317
318        if ( object->dynamic_prop & ED4_P_IS_HANDLE )               // object is a handle for an object up in the hierarchy => search it
319        {
320            mlevel = object->spec->handled_level;
321            tmp_object = object;
322
323            while ( (tmp_object != NULL) && !(tmp_object->spec->level & mlevel) ) {
324                tmp_object = tmp_object->parent;
325            }
326
327            if ( tmp_object == NULL ) {
328                return ( ED4_R_WARNING );               // no target level found
329            }
330
331            object->selection_info->actual_width = tmp_object->extension.size[WIDTH];
332            object->selection_info->actual_height = tmp_object->extension.size[HEIGHT];
333        }
334        else                                    // selected object is no handle => take it directly
335        {
336            object->selection_info->actual_width = object->extension.size[WIDTH];
337            object->selection_info->actual_height = object->extension.size[HEIGHT];
338        }
339
340        object->selection_info->drag_old_x = 0;
341        object->selection_info->drag_old_y = 0;
342        object->selection_info->drag_off_x = 0;
343        object->selection_info->drag_off_y = 0;
344        object->selection_info->old_event_y = 0;
345        object->selection_info->object = object;
346        selected_objects.append_elem_backwards( (void *) object->selection_info );
347        object->flag.selected = 1;
348
349        if (object->is_species_name_terminal()) {
350            ED4_species_name_terminal *name_term = object->to_species_name_terminal();
351
352#ifdef DEBUG
353            GBDATA *gbd = name_term->get_species_pointer();
354
355            if (gbd) {
356                printf("added term '%s'\n", GB_read_char_pntr(gbd));
357            }
358            else {
359                ED4_species_manager *spec_man = name_term->get_parent(ED4_L_SPECIES)->to_species_manager();
360                if (spec_man->flag.is_consensus) {
361                    printf("added consensus '%s'\n", name_term->id);
362                }
363                else {
364                    printf("added unknown term '%s'\n", name_term->id ? name_term->id : "NULL");
365                }
366            }
367#endif
368
369            name_term->set_refresh();
370            name_term->parent->refresh_requested_by_child();
371
372            ED4_sequence_terminal *seq_term = object->to_species_name_terminal()->corresponding_sequence_terminal();
373            if (seq_term) {
374                seq_term->set_refresh();
375                seq_term->parent->refresh_requested_by_child();
376            }
377
378            //ProtView: Refresh corresponding AA_sequence terminals
379            if (alignment_type == GB_AT_DNA) {
380                PV_CallBackFunction(this->aw_root); 
381            }
382
383            ED4_multi_species_manager *multi_man = object->get_parent(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
384            multi_man->invalidate_species_counters();
385        }
386        else {
387            e4_assert(0); // test ob ueberhaupt was anderes als species_name_terminals verwendet wird
388            object->set_refresh();
389            object->parent->refresh_requested_by_child();
390        }
391
392        return ( ED4_R_OK );
393    }
394
395    return ( ED4_R_IMPOSSIBLE );
396}
397
398ED4_returncode ED4_root::resize_all( void )
399{
400    while ( main_manager->update_info.resize ) {
401        main_manager->resize_requested_by_parent();
402    }
403
404    return ( ED4_R_OK );
405}
406
407static ED4_returncode change_char_table_length(void **new_length_intPtr, void **/*not_used*/, ED4_base *base)
408{
409    if (base->is_group_manager()) {
410        int new_length = *(int*)new_length_intPtr;
411        ED4_group_manager *group_man = base->to_group_manager();
412        group_man->table().change_table_length(new_length);
413    }
414
415    return ED4_R_OK;
416}
417
418void ED4_alignment_length_changed(GBDATA *gb_alignment_len, int */*cl*/, GB_CB_TYPE IF_DEBUG(gbtype)) // callback from database
419{
420    e4_assert(gbtype==GB_CB_CHANGED);
421    int new_length = GB_read_int(gb_alignment_len);
422
423#if defined(DEBUG) && 1
424    printf("alignment_length_changed from %i to %i\n", MAXSEQUENCECHARACTERLENGTH, new_length);
425#endif
426
427    if (MAXSEQUENCECHARACTERLENGTH!=new_length) { // otherwise we already did this (i.e. we were called by changed_by_database)
428        bool was_increased = new_length>MAXSEQUENCECHARACTERLENGTH;
429
430        MAXSEQUENCECHARACTERLENGTH = new_length;
431
432        const char *err = ED4_ROOT->helix->init(GLOBAL_gb_main); // reload helix
433        if (err) { aw_message(err); err = 0; }
434
435        err = ED4_ROOT->ecoli_ref->init(GLOBAL_gb_main); // reload ecoli
436        if (err) { aw_message(err); err = 0; }
437       
438        if(ED4_ROOT->alignment_type == GB_AT_AA) {
439            //TODO: is this needed here?
440            err = ED4_pfold_set_SAI(&ED4_ROOT->protstruct, GLOBAL_gb_main, ED4_ROOT->alignment_name, &ED4_ROOT->protstruct_len); // reload protstruct
441            if (err) { aw_message(err); err = 0; }
442        }
443        //ED4_ROOT->refresh_all_windows(0);
444        //ED4_expose_all_windows();
445
446        if (was_increased) {
447            int *new_length_ptr = &new_length;
448            ED4_ROOT->main_manager->route_down_hierarchy((void**)new_length_ptr, 0, change_char_table_length);
449            ED4_ROOT->root_group_man->remap()->mark_compile_needed_force();
450        }
451    }
452}
453
454ED4_returncode ED4_root::init_alignment() {
455    GB_transaction dummy(GLOBAL_gb_main);
456
457    alignment_name = GBT_get_default_alignment(GLOBAL_gb_main);
458    alignment_type = GBT_get_alignment_type(GLOBAL_gb_main,alignment_name);
459    if (alignment_type==GB_AT_UNKNOWN) {
460        aw_popup_exit("You have to select a valid alignment before you can start ARB_EDIT4");
461    }
462
463    GBDATA *gb_alignment = GBT_get_alignment(GLOBAL_gb_main, alignment_name);
464    if (!gb_alignment) aw_popup_exit("You can't edit without an existing alignment");
465
466    GBDATA *gb_alignment_len = GB_search(gb_alignment,"alignment_len",GB_FIND);
467    int alignment_length = GB_read_int(gb_alignment_len);
468    MAXSEQUENCECHARACTERLENGTH = alignment_length; // GBT_get_alignment_len(GLOBAL_gb_main, ED4_ROOT->alignment_name);
469
470    GB_add_callback(gb_alignment_len, (GB_CB_TYPE)GB_CB_CHANGED, (GB_CB)ED4_alignment_length_changed, 0);
471
472    aw_root->awar_string(AWAR_EDITOR_ALIGNMENT, alignment_name);
473
474    return ED4_R_OK;
475}
476
477void ED4_root::recalc_font_group() {
478    font_group.unregisterAll();
479    for (int f=ED4_G_FIRST_FONT; f<=ED4_G_LAST_FONT; f++) {
480        font_group.registerFont(get_device(), f);
481    }
482}
483
484ED4_returncode ED4_root::create_hierarchy(char *area_string_middle, char *area_string_top) // creates internal hierarchy of editor
485{
486    int index = 0, x = 0, change = 0;
487    ED4_index y = 0, help = 0;
488    ED4_base *x_link, *y_link, *width_link, *height_link;
489    ED4_window *new_window;
490    long total_no_of_species, total_no_of_groups, group_count, species_count;
491
492    /*****YKADI COMMENT****************/
493    // this is the sequence reference region - it counts the species and related info (e.g. helix) displayed
494    //in the REFERENCE region -- TOP REGION
495    /*****YKADI COMMENT****************/
496
497    database->calc_no_of_all(area_string_top, &group_count, &species_count);
498    total_no_of_groups = group_count;
499    total_no_of_species = species_count;
500    loading = 1;
501
502    /*****YKADI COMMENT****************/
503    //  MIDDLE  REGION -- counts no of species and sais including groups
504    /*****YKADI COMMENT****************/
505
506    database->calc_no_of_all(area_string_middle, &group_count, &species_count);
507    total_no_of_groups += group_count;
508    total_no_of_species += species_count;
509
510    status_count_total = total_no_of_species;
511    status_count_curr  = 0;
512
513    GB_push_transaction( GLOBAL_gb_main );
514
515    ecoli_ref = new BI_ecoli_ref();
516    ecoli_ref->init(GLOBAL_gb_main);
517
518    // [former position of ali-init-code]
519
520    main_manager = new ED4_main_manager  ( "Main_Manager"  , 0, 0, 0, 0, NULL );            // build a test hierarchy
521    root_group_man = new ED4_root_group_manager ( "Root_Group_Manager" ,0 ,0 ,0 ,0 , main_manager);
522    main_manager->children->append_member ( root_group_man );
523
524    ED4_device_manager *device_manager = new ED4_device_manager( "Device_Manager", 0, 0, 0, 0, root_group_man );
525    root_group_man->children->append_member( device_manager );
526
527    ED4_calc_terminal_extentions();
528
529    {
530        int col_stat_term_height = 50; // @@@ Hoehe des ColumnStatistics Terminals ausrechnen
531
532        ref_terminals.init(new ED4_sequence_info_terminal("Reference_Sequence_Info_Terminal",/*NULL,*/ 250, 0, MAXINFOWIDTH, TERMINALHEIGHT, NULL),
533                           new ED4_sequence_terminal("Reference_Sequence_Terminal", 300, 0, 300, TERMINALHEIGHT, NULL),
534                           new ED4_sequence_info_terminal("Reference_ColumnStatistics_Info_Terminal",/*NULL,*/ 250, 0, MAXINFOWIDTH, col_stat_term_height, NULL),
535                           new ED4_columnStat_terminal("Reference_ColumnStatistics_Terminal", 300, 0, 300, col_stat_term_height, NULL));
536    }
537    x = 100;
538
539    recalc_font_group();
540
541    {
542        ED4_area_manager *middle_area_manager;
543        ED4_tree_terminal *tree_terminal;
544        ED4_multi_species_manager *top_multi_species_manager;
545        ED4_multi_species_manager *mid_multi_species_manager;
546        ED4_spacer_terminal *top_spacer_terminal;
547        ED4_spacer_terminal *top_mid_spacer_terminal;
548        ED4_spacer_terminal *top_multi_spacer_terminal_beg;
549        ED4_spacer_terminal *mid_multi_spacer_terminal_beg;
550        ED4_line_terminal *top_mid_line_terminal;
551        ED4_line_terminal *mid_bot_line_terminal;
552        ED4_spacer_terminal *total_bottom_spacer;
553
554        // ********** Top Area beginning **********
555
556        {
557            ED4_area_manager *top_area_manager = new ED4_area_manager("Top_Area_Manager", 0, y, 0, 0, device_manager);
558            device_manager->children->append_member(top_area_manager);
559            top_area_man = top_area_manager;
560
561            top_spacer_terminal = new ED4_spacer_terminal( "Top_Spacer" , 0, 0, 100, 10, top_area_manager);
562            top_area_manager->children->append_member( top_spacer_terminal );
563
564            top_multi_species_manager = new ED4_multi_species_manager("Top_MultiSpecies_Manager", x, 0, 0, 0, top_area_manager);
565            top_area_manager->children->append_member( top_multi_species_manager );
566
567            top_multi_spacer_terminal_beg = new ED4_spacer_terminal("Top_Multi_Spacer_Terminal_Beg",0,0,0,3, top_multi_species_manager);
568            top_multi_species_manager->children->append_member( top_multi_spacer_terminal_beg );
569
570            y+=3;
571
572
573            if (total_no_of_species > MINSPECFORSTATWIN) {
574                aw_openstatus("Reading species from database");
575                aw_status((double)0);
576            }
577
578
579            reference = new AWT_reference(GLOBAL_gb_main);
580            database->scan_string(top_multi_species_manager, ref_terminals.get_ref_sequence_info(), ref_terminals.get_ref_sequence(),
581                                  area_string_top, &index, &y);
582            GB_pop_transaction( GLOBAL_gb_main );
583
584            const int TOP_MID_LINE_HEIGHT   = 3;
585            int       TOP_MID_SPACER_HEIGHT = font_group.get_max_height()-TOP_MID_LINE_HEIGHT;
586
587            top_mid_line_terminal = new ED4_line_terminal( "Top_Mid_Line_Terminal" ,0, y, 0, TOP_MID_LINE_HEIGHT, device_manager );   // width will be set below
588            device_manager->children->append_member( top_mid_line_terminal );
589
590            y += TOP_MID_LINE_HEIGHT;
591
592
593            top_mid_spacer_terminal = new ED4_spacer_terminal( "Top_Middle_Spacer", 0, y, 880, TOP_MID_SPACER_HEIGHT , device_manager);
594            device_manager->children->append_member( top_mid_spacer_terminal );
595
596            // needed to avoid text-clipping problems:
597            main_manager->set_top_middle_spacer_terminal(top_mid_spacer_terminal); 
598            main_manager->set_top_middle_line_terminal(top_mid_line_terminal); 
599
600            y += TOP_MID_SPACER_HEIGHT; // add top-mid_spacer_terminal height
601
602            top_multi_species_manager->generate_id_for_groups();
603
604            //  top_area_manager->check_all();
605        }
606
607        // ********** Top Area end **********
608
609
610        // ********** Middle Area beginning **********
611
612        {
613            //  printf("Middle Area y : %d\n",y);
614            middle_area_manager = new ED4_area_manager("Middle_Area_Manager", 0, y, 0, 0, device_manager);
615            device_manager->children->append_member(middle_area_manager);
616            middle_area_man = middle_area_manager;
617
618            tree_terminal = new ED4_tree_terminal( "Tree", 0, 0, 2, change, middle_area_manager);
619            middle_area_manager->children->append_member( tree_terminal );
620
621            mid_multi_species_manager = new ED4_multi_species_manager("Middle_MultiSpecies_Manager", x, 0, 0, 0, middle_area_manager);
622            middle_area_manager->children->append_member( mid_multi_species_manager );
623
624            mid_multi_spacer_terminal_beg = new ED4_spacer_terminal("Mid_Multi_Spacer_Terminal_Beg",0,0,0,3, mid_multi_species_manager);
625            mid_multi_species_manager->children->append_member( mid_multi_spacer_terminal_beg );
626
627            y+=3;               // dummy height, to create a dummy layout ( to preserve order of objects )
628
629            scroll_links.link_for_ver_slider = middle_area_manager;
630
631            help = y;
632            index = 0;
633            {
634                GB_transaction dummy(GLOBAL_gb_main);
635                database->scan_string(mid_multi_species_manager, ref_terminals.get_ref_sequence_info(), ref_terminals.get_ref_sequence(),
636                                      area_string_middle, &index, &y);
637            }
638
639            if (total_no_of_species > MINSPECFORSTATWIN) {
640                aw_closestatus();
641            }
642
643            {
644                ED4_spacer_terminal *mid_bot_spacer_terminal = new ED4_spacer_terminal( "Middle_Bot_Spacer_Terminal", 0, y, 880, 10, device_manager);
645                device_manager->children->append_member( mid_bot_spacer_terminal );
646            }
647
648            tree_terminal->extension.size[HEIGHT] = y - help;
649
650            mid_multi_species_manager->generate_id_for_groups();
651            y += 10;                                                // add top-mid_spacer_terminal height
652
653            mid_bot_line_terminal = new ED4_line_terminal( "Mid_Bot_Line_Terminal" ,0, y, 0, 3, device_manager );   // width will be set below
654            device_manager->children->append_member( mid_bot_line_terminal );
655            y += 3;
656
657            total_bottom_spacer = new ED4_spacer_terminal("Total_Bottom_Spacer_terminal", 0, y, 0, 10000, device_manager);
658            device_manager->children->append_member(total_bottom_spacer);
659            y += 10000;
660        }
661
662        // ********** Middle Area end **********
663
664        if (scroll_links.link_for_hor_slider) {
665            long ext_width = long(scroll_links.link_for_hor_slider->extension.size[WIDTH]);
666
667            top_multi_spacer_terminal_beg->extension.size[WIDTH] = ext_width + MAXSPECIESWIDTH + SEQUENCEINFOSIZE;
668            mid_multi_spacer_terminal_beg->extension.size[WIDTH] = ext_width + MAXSPECIESWIDTH + SEQUENCEINFOSIZE;
669            total_bottom_spacer->extension.size[WIDTH] = ext_width + MAXSPECIESWIDTH + SEQUENCEINFOSIZE;
670
671            top_mid_line_terminal->extension.size[WIDTH] = ext_width + TREETERMINALSIZE + MAXSPECIESWIDTH + SEQUENCEINFOSIZE;
672            mid_bot_line_terminal->extension.size[WIDTH] = ext_width + TREETERMINALSIZE + MAXSPECIESWIDTH + SEQUENCEINFOSIZE;
673
674        }
675
676        tree_terminal->set_links( NULL, mid_multi_species_manager );                        // set links
677        top_spacer_terminal->set_links( tree_terminal, top_multi_species_manager );
678        top_mid_spacer_terminal->set_links( middle_area_manager, NULL );
679        total_bottom_spacer->set_links(mid_bot_line_terminal, 0);
680    }
681
682    first_window->update_window_coords();
683    resize_all();
684
685
686    if (total_no_of_species > MINSPECFORSTATWIN)
687    {
688        aw_openstatus("Initializing consensi");
689        aw_status((double)0);
690    }
691
692    status_count_total = total_no_of_groups + 1; // 1 is root_group_man
693    status_count_curr  = 0;
694
695    root_group_man->create_consensus(root_group_man);
696    e4_assert(root_group_man->table().ok());
697
698    if (total_no_of_species > MINSPECFORSTATWIN)
699        aw_closestatus();
700
701    //  main_manager->check_all();
702
703    root_group_man->remap()->mark_compile_needed_force();
704    root_group_man->update_remap();
705
706    // calc size and display:
707
708    resize_all();
709    loading = 0;
710
711    x_link = y_link = NULL;
712    if (main_manager)
713    {
714        x_link = scroll_links.link_for_hor_slider;
715        y_link = scroll_links.link_for_ver_slider;
716    }
717
718    width_link  = x_link;
719    height_link = y_link;
720
721    new_window = first_window;
722
723    while (new_window)
724    {
725        new_window->set_scrolled_rectangle( 0, 0, 0, 0, x_link, y_link, width_link, height_link );
726        new_window->aww->show();
727        new_window->update_scrolled_rectangle();
728        ED4_refresh_window(new_window->aww, 0, 0);
729        new_window = new_window->next;
730    }
731
732    aw_root->add_timed_callback(2000,ED4_timer,(AW_CL)0,(AW_CL)0);
733
734    char *out_message = GBS_strclose(not_found_message);
735    not_found_message = 0;
736    if (all_found != 0) aw_message(out_message);
737    free(out_message);
738
739    return ( ED4_R_OK );
740}
741
742ED4_returncode ED4_root::get_area_rectangle(AW_rectangle *rect, AW_pos x, AW_pos y) { // returns win-coordinates of area (defined by folding lines) which contains position x/y
743    ED4_folding_line *flv, *flh;
744    int x1, x2, y1, y2;
745    AW_rectangle area_rect;
746    get_device()->get_area_size(&area_rect);
747
748    x1 = area_rect.l;
749    for (flv=get_ed4w()->vertical_fl; ; flv = flv->next) {
750        if (flv) {
751            e4_assert(flv->length==INFINITE);
752            x2 = int(flv->window_pos[X_POS]);
753        }
754        else {
755            x2 = area_rect.r;
756            if (x1==x2) {
757                break;
758            }
759        }
760
761        y1 = area_rect.t;
762        for (flh=get_ed4w()->horizontal_fl; ; flh = flh->next) {
763            if (flh) {
764                e4_assert(flh->length==INFINITE);
765                y2 = int(flh->window_pos[Y_POS]);
766            }
767            else {
768                y2 = area_rect.b;
769                if (y1==y2) {
770                    break;
771                }
772            }
773
774            if (x1<=x && x<=x2 && y1<=y && y<=y2) {
775                rect->t = y1;
776                rect->b = y2;
777                rect->l = x1;
778                rect->r = x2;
779                return ED4_R_OK;
780            }
781            y1 = y2;
782            if (!flh) break;
783        }
784        x1 = x2;
785        if (!flv) break;
786    }
787    return ED4_R_IMPOSSIBLE; // no area contains x/y :-(
788}
789
790ED4_returncode ED4_root::world_to_win_coords(AW_window *IF_DEBUG(aww), AW_pos *xPtr, AW_pos *yPtr)  // calculates transformation from world to window
791{                                               // coordinates in a given window
792    ED4_window      *current_window;
793    ED4_folding_line    *current_fl;
794    AW_pos      temp_x, temp_y, x, y;
795
796    current_window = get_ed4w();
797    e4_assert(current_window==first_window->get_matching_ed4w(aww));
798
799    if (! current_window) {
800        e4_assert(0);
801        return ( ED4_R_WARNING ); // should never occur
802    }
803
804    temp_x = x = *xPtr;
805    temp_y = y = *yPtr;
806
807    current_fl = current_window->vertical_fl;                       // calculate x-offset due to vertical folding lines
808    while (current_fl && (x>=current_fl->world_pos[X_POS])) {
809        if ((current_fl->length == INFINITE) ||
810            ((y >= current_fl->world_pos[Y_POS]) &&
811             (y <= current_fl->world_pos[Y_POS] + current_fl->length)))
812        {
813            temp_x -= current_fl->dimension;
814
815        }
816        current_fl = current_fl->next;
817    }
818
819    current_fl = current_window->horizontal_fl;                     // calculate y-offset due to horizontal folding lines
820    while (current_fl && (y >= current_fl->world_pos[Y_POS])) {
821        if ((current_fl->length == INFINITE) ||
822            ((x >= current_fl->world_pos[X_POS]) &&
823             (x <= (current_fl->world_pos[X_POS] + current_fl->length))))
824        {
825            temp_y -= current_fl->dimension;
826        }
827        current_fl = current_fl->next;
828    }
829
830    *xPtr = temp_x;
831    *yPtr = temp_y;
832
833    return ( ED4_R_OK );
834}
835
836void ED4_root::copy_window_struct( ED4_window *source , ED4_window *destination )
837{
838    destination->slider_pos_horizontal  = source->slider_pos_horizontal;
839    destination->slider_pos_vertical    = source->slider_pos_vertical;
840    destination->coords         = source->coords;
841}
842
843
844void ED4_reload_helix_cb(AW_window *aww,AW_CL cd1, AW_CL cd2) {
845    const char *err = ED4_ROOT->helix->init(GLOBAL_gb_main);
846    if (err) aw_message(err);
847    ED4_refresh_window(aww,cd1,cd2);
848}
849
850
851void ED4_reload_ecoli_cb(AW_window *aww,AW_CL cd1, AW_CL cd2)
852{
853    const char *err = ED4_ROOT->ecoli_ref->init(GLOBAL_gb_main);
854    if (err) aw_message(err);
855    ED4_refresh_window(aww,cd1,cd2);
856}
857
858// --------------------------------------------------------------------------------
859//  recursion through all species
860// --------------------------------------------------------------------------------
861
862static GB_ERROR do_sth_with_species_error = NULL;
863
864ED4_returncode do_sth_with_species(void **arg1, void **arg2, ED4_base *base)
865{
866    if (!do_sth_with_species_error && base->is_species_manager()) {
867        GB_ERROR (*what_to_do_with_species)(GBDATA*,void**) = (GB_ERROR (*)(GBDATA*,void**))arg1;
868        ED4_species_manager *species_manager = base->to_species_manager();
869        ED4_species_name_terminal *species_name_terminal = species_manager->search_spec_child_rek(ED4_L_SPECIES_NAME)->to_species_name_terminal();
870
871        if (species_name_terminal->get_species_pointer()) {
872            char *species_name = GB_read_as_string(species_name_terminal->get_species_pointer());
873
874            e4_assert(species_name);
875            GBDATA *species = GBT_find_species(GLOBAL_gb_main, species_name);
876            if (species) do_sth_with_species_error = what_to_do_with_species(species, arg2);
877            delete species_name;
878        }
879    }
880
881    return ED4_R_OK;
882}
883
884
885GB_ERROR ED4_with_all_loaded_species(GB_ERROR (*what_to_do_with_species)(GBDATA*,void**), void **arg)
886{
887    ED4_ROOT->root_group_man->route_down_hierarchy((void**)what_to_do_with_species, arg, do_sth_with_species);
888    GB_ERROR error = do_sth_with_species_error;
889    do_sth_with_species_error = NULL;
890    return error;
891}
892
893// --------------------------------------------------------------------------------
894//  faligner
895// --------------------------------------------------------------------------------
896
897static int has_species_name(ED4_base *base, AW_CL cl_species_name)
898{
899    ED4_species_name_terminal *name_term = base->to_species_name_terminal();
900    GBDATA *gbd = name_term->get_species_pointer();
901
902    if (gbd) {
903        const char *name = GB_read_char_pntr(gbd);
904        e4_assert(name);
905        int has_name = strcmp(name,(const char*)cl_species_name)==0;
906        return has_name;
907    }
908
909    return 0;
910}
911
912ED4_species_name_terminal *ED4_find_species_name_terminal(const char *species_name)
913{
914    ED4_base *base = ED4_ROOT->root_group_man->find_first_that(ED4_L_SPECIES_NAME, has_species_name, (AW_CL)species_name);
915
916    return base ? base->to_species_name_terminal() : 0;
917}
918
919static char *get_group_consensus(const char *species_name, int start_pos, int end_pos)
920{
921    ED4_species_name_terminal *name_term = ED4_find_species_name_terminal(species_name);
922    char *consensus = 0;
923
924    if (name_term) {
925        ED4_group_manager *group_man = name_term->get_parent(ED4_L_GROUP)->to_group_manager();
926        if (group_man) {
927            consensus = group_man->table().build_consensus_string(start_pos, end_pos, 0);
928        }
929    }
930
931    return consensus;
932}
933
934static int get_selected_range(int *firstColumn, int *lastColumn)
935{
936    ED4_list_elem *listElem = ED4_ROOT->selected_objects.first();
937    if (listElem) {
938        ED4_selection_entry *selectionEntry = (ED4_selection_entry*)listElem->elem();
939        ED4_sequence_terminal *seqTerm = selectionEntry->object->get_parent(ED4_L_SPECIES)->search_spec_child_rek(ED4_L_SEQUENCE_STRING)->to_sequence_terminal();
940
941        ED4_get_selected_range(seqTerm, firstColumn, lastColumn);
942        return 1;
943    }
944    return 0;
945}
946
947static ED4_list_elem *actual_aligner_elem = 0;
948static GBDATA *get_next_selected_species(void)
949{
950    if (!actual_aligner_elem) return 0;
951
952    ED4_selection_entry *selectionEntry = (ED4_selection_entry*)actual_aligner_elem->elem();
953    ED4_species_manager *specMan = selectionEntry->object->get_parent(ED4_L_SPECIES)->to_species_manager();
954
955    actual_aligner_elem = actual_aligner_elem->next();
956    return specMan->get_species_pointer();
957}
958static GBDATA *get_first_selected_species(int *total_no_of_selected_species)
959{
960    int selected = ED4_ROOT->selected_objects.no_of_entries();
961
962    if (total_no_of_selected_species) {
963        *total_no_of_selected_species = selected;
964    }
965
966    if (selected) {
967        actual_aligner_elem = ED4_ROOT->selected_objects.first();
968    }
969    else {
970        actual_aligner_elem = 0;
971    }
972
973    return get_next_selected_species();
974}
975
976struct AWTC_faligner_cd faligner_client_data =
977{
978 1,                             // default is to do a refresh
979 ED4_timer_refresh,             // with this function
980 get_group_consensus,           // aligner fetches consensus of group of species via this function
981 get_selected_range,            // aligner fetches column range of selection via this function
982 get_first_selected_species,    // aligner fetches first and..
983 get_next_selected_species,         // .. following selected species via this functions
984 0 // AW_helix (needed for island_hopping)
985 };
986
987static GB_ERROR ED4_delete_temp_entries(GBDATA *species, void **alignment_char_ptr)
988{
989    GB_CSTR alignment = (GB_CSTR)alignment_char_ptr;
990    GB_ERROR error = AWTC_delete_temp_entries(species, alignment);
991
992    return error;
993}
994
995void ED4_remove_faligner_entries(AW_window *, AW_CL, AW_CL) {
996    GB_ERROR error = GB_begin_transaction(GLOBAL_gb_main);
997    if (!error) error = ED4_with_all_loaded_species(ED4_delete_temp_entries, (void**)ED4_ROOT->alignment_name);
998    GB_end_transaction_show_error(GLOBAL_gb_main, error, aw_message);
999}
1000
1001void ED4_turnSpecies(AW_window *aw, AW_CL, AW_CL) {
1002    GB_ERROR error = GB_begin_transaction(GLOBAL_gb_main);
1003
1004    if (!error) {
1005        AW_root *root       = aw->get_root();
1006        char    *name       = root->awar(AWAR_SPECIES_NAME)->read_string();
1007        char    *ali        = ED4_ROOT->alignment_name;
1008        GBDATA  *gb_species = GBT_expect_species(GLOBAL_gb_main, name);
1009        GBDATA  *gbd        = gb_species ? GBT_read_sequence(gb_species, ali) : NULL;
1010        char    *data       = gbd ? GB_read_string(gbd) : NULL;
1011
1012        if (!data) error = GB_await_error();
1013        else {
1014            long length = GB_read_string_count(gbd);
1015
1016            char T_or_U;
1017            error = GBT_determine_T_or_U(ED4_ROOT->alignment_type, &T_or_U, "reverse-complement");
1018            if (!error) {
1019                GBT_reverseComplementNucSequence(data, length, T_or_U);
1020                error = GB_write_string(gbd,data);
1021            }
1022        }
1023
1024        free(data);
1025        free(name);
1026    }
1027
1028    GB_end_transaction_show_error(GLOBAL_gb_main, error, aw_message);
1029}
1030
1031
1032#if defined(DEBUG) && 0
1033
1034void ED4_testSplitNMerge(AW_window *aw, AW_CL, AW_CL)
1035{
1036    AW_root *root = aw->get_root();
1037    char *name;
1038    GBDATA *species;
1039    GBDATA *gbd;
1040    char *data;
1041    long length;
1042
1043    GB_ERROR error = GB_begin_transaction(gb_main);
1044    char *ali = ED4_ROOT->alignment_name;
1045
1046    if (!error)
1047    {
1048        name = root->awar(AWAR_SPECIES_NAME)->read_string();
1049        species = GBT_find_species(gb_main, name);
1050        gbd = species ? GBT_read_sequence(species, ali) : NULL;
1051        data = gbd ? GB_read_string(gbd) : NULL;
1052        length = gbd ? GB_read_string_count(gbd) : NULL;
1053
1054        if (data)
1055        {
1056            char *newData = AWTC_testConstructSequence(data);
1057
1058            if (newData)
1059            {
1060                error = GB_write_string(gbd,newData);
1061                delete [] newData;
1062            }
1063        }
1064        else
1065        {
1066            error = GB_get_error();
1067            if (!error) error = GB_export_error("Can't read data of '%s'", name);
1068        }
1069
1070        delete name;
1071        delete data;
1072    }
1073
1074    GB_end_transaction_show_error(gb_main, error, aw_message);
1075}
1076
1077#endif
1078
1079static void col_stat_activated(AW_window *)
1080{
1081    ED4_ROOT->column_stat_initialized = 1;
1082    ED4_ROOT->column_stat_activated = 1;
1083    ED4_ROOT->refresh_all_windows(1);
1084}
1085
1086void ED4_activate_col_stat(AW_window *aww,AW_CL, AW_CL){
1087    if (!ED4_ROOT->column_stat_initialized) {
1088        AW_window *aww_st = st_create_main_window(ED4_ROOT->aw_root,ED4_ROOT->st_ml,(AW_CB0)col_stat_activated,(AW_window *)aww);
1089        aww_st->show();
1090        return;
1091    }
1092    else { // re-activate
1093        ED4_ROOT->column_stat_activated = 1;
1094        ED4_ROOT->refresh_all_windows(1);
1095    }
1096}
1097static void disable_col_stat(AW_window *, AW_CL, AW_CL) {
1098    if (ED4_ROOT->column_stat_initialized && ED4_ROOT->column_stat_activated) {
1099        ED4_ROOT->column_stat_activated = 0;
1100        ED4_ROOT->refresh_all_windows(1);
1101    }
1102}
1103
1104static void title_mode_changed(AW_root *aw_root, AW_window *aww)
1105{
1106    int title_mode = aw_root->awar(AWAR_EDIT_TITLE_MODE)->read_int();
1107
1108    if (title_mode==0) {
1109        aww->set_info_area_height(57);
1110    }
1111    else {
1112        aww->set_info_area_height(170);
1113    }
1114}
1115
1116// static void ED4_unfold_if_folded(AW_window *aww, AW_CL, AW_CL)
1117// {
1118//     AW_root *aw_root = ED4_ROOT->aw_root;
1119//     int title_mode = aw_root->awar(AWAR_EDIT_TITLE_MODE)->read_int();
1120
1121//     if (title_mode==0) {
1122//  aw_root->awar(AWAR_EDIT_TITLE_MODE)->write_int(1);
1123//  title_mode_changed(aw_root, aww);
1124//     }
1125// }
1126
1127void ED4_undo_redo(AW_window*, AW_CL undo_type)
1128{
1129    GB_ERROR error = GB_undo(GLOBAL_gb_main,(GB_UNDO_TYPE)undo_type);
1130
1131    if (error) {
1132        aw_message(error);
1133    }
1134    else {
1135        GB_begin_transaction(GLOBAL_gb_main);
1136        GB_commit_transaction(GLOBAL_gb_main);
1137        ED4_cursor *cursor = &ED4_ROOT->get_ed4w()->cursor;
1138        if (cursor->owner_of_cursor) {
1139            ED4_terminal *terminal = cursor->owner_of_cursor->to_terminal();
1140
1141            terminal->set_refresh();
1142            terminal->parent->refresh_requested_by_child();
1143        }
1144        //  aed_expose(aw,cd1,0);
1145    }
1146}
1147
1148void aw_clear_message_cb(AW_window *aww);
1149
1150void ED4_clear_errors(AW_window*, AW_CL)
1151{
1152    //    ED4_ROOT->aw_root->awar(AWAR_ERROR_MESSAGES)->write_string("");
1153    aw_clear_message_cb(ED4_ROOT->get_aww());
1154}
1155
1156AW_window *ED4_zoom_message_window(AW_root *root, AW_CL)
1157{
1158    AW_window_simple *aws = new AW_window_simple;
1159
1160    aws->init(root, "ZOOM_ERR_MSG", "Errors and warnings");
1161    aws->load_xfig("edit4/message.fig");
1162
1163    aws->callback((AW_CB0)AW_POPDOWN);
1164    aws->at("hide");
1165    aws->create_button("HIDE", "HIDE");
1166
1167    aws->callback(ED4_clear_errors, (AW_CL)0);
1168    aws->at("clear");
1169    aws->create_button("CLEAR", "CLEAR");
1170
1171    aws->at("errortext");
1172    aws->create_text_field(AWAR_ERROR_MESSAGES);
1173
1174    return (AW_window *)aws;
1175}
1176
1177
1178char *cat(char *toBuf, const char *s1, const char *s2)
1179{
1180    char *buf = toBuf;
1181
1182    while ((*buf++=*s1++)!=0) ;
1183    buf--;
1184    while ((*buf++=*s2++)!=0) ;
1185
1186    return toBuf;
1187}
1188
1189static void insert_search_fields(AW_window_menu_modes *awmm,
1190                                 const char *label_prefix, const char *macro_prefix,
1191                                 const char *pattern_awar_name, ED4_SearchPositionType type, const char *show_awar_name,
1192                                 int short_form)
1193{
1194    char buf[200];
1195
1196    if (!short_form) {
1197        awmm->at(cat(buf, label_prefix, "search"));
1198        awmm->create_input_field(pattern_awar_name, 30);
1199    }
1200
1201    awmm->at(cat(buf, label_prefix, "n"));
1202    awmm->callback(ED4_search, ED4_encodeSearchDescriptor(+1, type));
1203    awmm->create_button(cat(buf, macro_prefix, "_SEARCH_NEXT"), "#edit/next.bitmap");
1204
1205    awmm->at(cat(buf, label_prefix, "l"));
1206    awmm->callback(ED4_search, ED4_encodeSearchDescriptor(-1, type));
1207    awmm->create_button(cat(buf, macro_prefix, "_SEARCH_LAST"), "#edit/last.bitmap");
1208
1209    awmm->at(cat(buf, label_prefix, "d"));
1210    awmm->callback(AW_POPUP, (AW_CL)ED4_create_search_window, (AW_CL)type);
1211    awmm->create_button(cat(buf, macro_prefix, "_SEARCH_DETAIL"), "#edit/detail.bitmap");
1212
1213    awmm->at(cat(buf, label_prefix, "s"));
1214    awmm->create_toggle(show_awar_name);
1215}
1216
1217void ED4_set_protection(AW_window */*aww*/, AW_CL cd1, AW_CL /*cd2*/) {
1218    ED4_cursor *cursor = &ED4_ROOT->get_ed4w()->cursor;
1219    GB_ERROR    error  = 0;
1220
1221    if (cursor->owner_of_cursor) {
1222        int                         wanted_protection = int(cd1);
1223        ED4_sequence_terminal      *seq_term          = cursor->owner_of_cursor->to_sequence_terminal();
1224        ED4_sequence_info_terminal *seq_info_term     = seq_term->parent->search_spec_child_rek(ED4_L_SEQUENCE_INFO)->to_sequence_info_terminal();
1225        GBDATA                     *gbd               = seq_info_term->data();
1226
1227        GB_push_transaction(gbd);
1228
1229        GB_push_my_security(gbd);
1230        error = GB_write_security_write(gbd, wanted_protection);
1231        GB_pop_my_security(gbd);
1232
1233        error = GB_end_transaction(gbd, error);
1234    }
1235    else {
1236        error = "No species selected";
1237    }
1238
1239    if (error) aw_message(error);
1240}
1241
1242typedef enum {
1243    ED4_MS_NONE,
1244    ED4_MS_ALL,
1245    ED4_MS_INVERT,
1246    ED4_MS_INVERT_GROUP,
1247    ED4_MS_UNMARK_ALL,
1248    ED4_MS_MARK_SELECTED,
1249    ED4_MS_UNMARK_SELECTED,
1250    ED4_MS_SELECT_MARKED,
1251    ED4_MS_DESELECT_MARKED,
1252    ED4_MS_TOGGLE_BLOCKTYPE
1253
1254} MenuSelectType;
1255
1256static void ED4_menu_select(AW_window *aww, AW_CL type,AW_CL) {
1257    GB_transaction dummy(GLOBAL_gb_main);
1258    MenuSelectType select = MenuSelectType(type);
1259    ED4_multi_species_manager *middle_multi_man = ED4_ROOT->middle_area_man->get_defined_level(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
1260
1261    e4_assert(middle_multi_man);
1262
1263    switch(select) {
1264        case ED4_MS_NONE: {
1265            if (ED4_getBlocktype()!=ED4_BT_NOBLOCK) {
1266                ED4_ROOT->deselect_all();
1267                ED4_setBlocktype(ED4_BT_NOBLOCK);
1268            }
1269            break;
1270        }
1271        case ED4_MS_ALL: {
1272            middle_multi_man->select_all_species();
1273            ED4_correctBlocktypeAfterSelection();
1274            break;
1275        }
1276        case ED4_MS_INVERT: {
1277            middle_multi_man->invert_selection_of_all_species();
1278            ED4_correctBlocktypeAfterSelection();
1279            break;
1280        }
1281        case ED4_MS_SELECT_MARKED: {
1282            middle_multi_man->select_marked_species(1);
1283            ED4_correctBlocktypeAfterSelection();
1284            break;
1285        }
1286        case ED4_MS_DESELECT_MARKED: {
1287            middle_multi_man->select_marked_species(0);
1288            ED4_correctBlocktypeAfterSelection();
1289            break;
1290        }
1291        case ED4_MS_UNMARK_ALL: {
1292            GBT_mark_all(GLOBAL_gb_main, 0);
1293            break;
1294        }
1295        case ED4_MS_MARK_SELECTED: {
1296            middle_multi_man->mark_selected_species(1);
1297            ED4_correctBlocktypeAfterSelection();
1298            break;
1299        }
1300        case ED4_MS_UNMARK_SELECTED: {
1301            middle_multi_man->mark_selected_species(0);
1302            ED4_correctBlocktypeAfterSelection();
1303            break;
1304        }
1305        case ED4_MS_INVERT_GROUP: {
1306            ED4_cursor *cursor = &ED4_ROOT->first_window->get_matching_ed4w(aww)->cursor;
1307            int done = 0;
1308
1309            if (cursor->owner_of_cursor) {
1310                ED4_multi_species_manager *multi_man = cursor->owner_of_cursor->get_parent(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
1311
1312                multi_man->invert_selection_of_all_species();
1313                ED4_correctBlocktypeAfterSelection();
1314                done = 1;
1315            }
1316
1317            if (!done) {
1318                aw_message("Place cursor into group");
1319            }
1320            break;
1321        }
1322        case ED4_MS_TOGGLE_BLOCKTYPE: {
1323            ED4_toggle_block_type();
1324            break;
1325        }
1326        default: {
1327            e4_assert(0);
1328            break;
1329        }
1330    }
1331
1332    ED4_refresh_window(aww, 1, 0);
1333}
1334
1335void ED4_menu_perform_block_operation(AW_window*, AW_CL type, AW_CL) {
1336    ED4_perform_block_operation(ED4_blockoperation_type(type));
1337}
1338
1339static void modes_cb(AW_window*, AW_CL cd1, AW_CL)
1340{
1341    ED4_ROOT->species_mode = ED4_species_mode(cd1);
1342}
1343void ED4_no_dangerous_modes(void)
1344{
1345    switch (ED4_ROOT->species_mode) {
1346        case ED4_SM_KILL: {
1347            ED4_ROOT->species_mode = ED4_SM_MOVE;
1348            ED4_ROOT->get_aww()->select_mode(0);
1349            break;
1350        }
1351        default: {
1352            break;
1353        }
1354    }
1355}
1356
1357void ED4_init_faligner_data(AWTC_faligner_cd *faligner_data) {
1358    GB_ERROR  error          = GB_push_transaction(GLOBAL_gb_main);
1359    char     *alignment_name = GBT_get_default_alignment(GLOBAL_gb_main);
1360    long      alilen         = GBT_get_alignment_len(GLOBAL_gb_main, alignment_name);
1361
1362    if (alilen<=0) error = GB_await_error();
1363    else {
1364        char   *helix_string = 0;
1365        char   *helix_name   = GBT_get_default_helix(GLOBAL_gb_main);
1366        GBDATA *gb_helix_con = GBT_find_SAI(GLOBAL_gb_main, helix_name);
1367        if (gb_helix_con) {
1368            GBDATA *gb_helix = GBT_read_sequence(gb_helix_con, alignment_name);
1369            if (gb_helix) helix_string = GB_read_string(gb_helix);
1370        }
1371        free(helix_name);
1372        freeset(faligner_data->helix_string, helix_string);
1373    }
1374
1375    free(alignment_name);
1376    error = GB_end_transaction(GLOBAL_gb_main, error);
1377    if (error) aw_message(error);
1378}
1379
1380static void ED4_create_faligner_window(AW_root *awr, AW_CL cd) {
1381    ED4_init_faligner_data((AWTC_faligner_cd*)cd);
1382    AWTC_create_faligner_window(awr, cd);
1383}
1384
1385static void ED4_save_defaults(AW_window *aw, AW_CL cl_mode, AW_CL) {
1386    int mode = (int)cl_mode;
1387
1388    AW_save_specific_defaults(aw, ED4_propertyName(mode));
1389}
1390
1391static AW_window *ED4_create_gc_window(AW_root *aw_root, AW_gc_manager id) {
1392    static AW_window *gc_win = 0;
1393    if (!gc_win) {
1394        gc_win = AW_create_gc_window(aw_root, id);
1395    }
1396    return gc_win;
1397}
1398
1399ED4_returncode ED4_root::generate_window( AW_device **device,   ED4_window **new_window)
1400{
1401    AW_window_menu_modes *awmm;
1402
1403    {
1404        ED4_window *ed4w = first_window;
1405
1406        while (ed4w) { // before creating a window look for a hidden window
1407            if (ed4w->is_hidden) {
1408                ed4w->aww->show();
1409                ed4w->is_hidden = false;
1410                return ED4_R_BREAK;
1411            }
1412            ed4w = ed4w->next;
1413        }
1414    }
1415
1416    if (ED4_window::no_of_windows == MAXWINDOWS)                            // no more then 5 windows allowed
1417    {
1418        aw_message(GBS_global_string("Restricted to %i windows", MAXWINDOWS));
1419        return ED4_R_BREAK;
1420    }
1421
1422    awmm = new AW_window_menu_modes;
1423    {
1424        int   len = strlen(alignment_name)+35;
1425        char *buf = GB_give_buffer(len);
1426        snprintf(buf, len-1, "ARB_EDIT4 *%d* [%s]", ED4_window::no_of_windows+1, alignment_name);
1427        awmm->init( aw_root, "ARB_EDIT4", buf, 800,450);
1428    }
1429
1430    *device     = awmm->get_device(AW_MIDDLE_AREA); // points to Middle Area device
1431    *new_window = ED4_window::insert_window( awmm ); // append to window list
1432
1433    e4_assert(ED4_window::no_of_windows >= 1);
1434    bool clone = ED4_window::no_of_windows>1;
1435    if (!clone) {                                   // this is the first window
1436        AW_init_color_group_defaults("arb_edit4");
1437    }
1438    else { // additional edit windows
1439        copy_window_struct( first_window, *new_window );
1440    }
1441
1442    // each window has its own gc-manager
1443    aw_gc_manager = AW_manage_GC(awmm,              // window
1444                                 *device,           // device-handle of window
1445                                 ED4_G_STANDARD,    // GC_Standard configuration
1446                                 ED4_G_DRAG,
1447                                 AW_GCM_DATA_AREA,
1448                                 ED4_expose_cb,     // callback function
1449                                 1,                 // AW_CL for callback function
1450                                 0,                 // AW_CL for callback function
1451                                 true,              // use color groups
1452
1453                                 "#f8f8f8",
1454                                 "STANDARD$black",  // Standard Color showing sequences
1455                                 "#SEQUENCES (0)$#505050", // default color for sequences (color 0)
1456                                 "+-HELIX (1)$#8E0000",  "+-COLOR 2$#0000dd",    "-COLOR 3$#00AA55",
1457                                 "+-COLOR 4$#80f",       "+-COLOR 5$#c0a020",    "-COLOR 6$grey",
1458                                 "+-COLOR 7$#ff0000",    "+-COLOR 8$#44aaff",    "-COLOR 9$#ffaa00",
1459
1460                                 "+-RANGE 0$#FFFFFF",    "+-RANGE 1$#F0F0F0",    "-RANGE 2$#E0E0E0",
1461                                 "+-RANGE 3$#D8D8D8",    "+-RANGE 4$#D0D0D0",    "-RANGE 5$#C8C8C8",
1462                                 "+-RANGE 6$#C0C0C0",    "+-RANGE 7$#B8B8B8",    "-RANGE 8$#B0B0B0",
1463                                 "-RANGE 9$#A0A0A0",
1464
1465                                 // colors used to Paint search patterns
1466                                 // (do not change the names of these gcs)
1467                                 "+-User1$#B8E2F8",      "+-User2$#B8E2F8",      "-Probe$#B8E2F8", // see also SEC_graphic::init_devices
1468                                 "+-Primer(l)$#A9FE54",  "+-Primer(r)$#A9FE54",  "-Primer(g)$#A9FE54",
1469                                 "+-Sig(l)$#DBB0FF",     "+-Sig(r)$#DBB0FF",     "-Sig(g)$#DBB0FF",
1470
1471                                 "+-MISMATCHES$#FF9AFF", "-CURSOR$#FF0080",
1472                                 "+-MARKED$#f4f8e0",     "-SELECTED$#FFFF80",
1473
1474                                 NULL);
1475
1476    // since the gc-managers of all EDIT4-windows point to the same window properties,
1477    // changing fonts and colors is always done on first gc-manager
1478    static AW_gc_manager first_gc_manager = 0;
1479    if (!first_gc_manager) first_gc_manager = aw_gc_manager;
1480
1481#define SEP________________________SEP awmm->insert_separator()
1482
1483    // ------------------------------
1484    //  File
1485    // ------------------------------
1486
1487#if defined(DEBUG)
1488    AWT_create_debug_menu(awmm);
1489#endif // DEBUG
1490
1491    awmm->create_menu("File", "F", "No Help", AWM_ALL );
1492
1493    awmm->insert_menu_topic("new_win",        "New Editor Window",     "W", 0, AWM_ALL, ED4_new_editor_window,         0,                                             0)   ;
1494    awmm->insert_menu_topic("save_config",    "Save Configuration",    "S", 0, AWM_ALL, (AW_CB)ED4_save_configuration, (AW_CL) 0,                                     (int)0 );
1495    awmm->insert_menu_topic("save_config_as", "Save Configuration As", "A", 0, AWM_ALL, AW_POPUP,                      (AW_CL) ED4_save_configuration_as_open_window, (int)0 );
1496    SEP________________________SEP;
1497    awmm->insert_menu_topic("load_config",   "Load Configuration",   "L", 0, AWM_ALL, AW_POPUP,           (AW_CL)ED4_start_editor_on_old_configuration, 0);
1498    awmm->insert_menu_topic("reload_config", "Reload Configuration", "R", 0, AWM_ALL, ED4_restart_editor, 0,                                            0);
1499    SEP________________________SEP;
1500    GDE_load_menu(awmm,AWM_ALL,"Print");
1501    SEP________________________SEP;
1502
1503    if (clone) awmm->insert_menu_topic( "close", "CLOSE", "C", 0, AWM_ALL, ED4_quit_editor, 0, 0);
1504    else       awmm->insert_menu_topic( "quit",  "QUIT",  "Q", 0, AWM_ALL, ED4_quit_editor, 0, 0);
1505   
1506    // ------------------------------
1507    //  Create
1508    // ------------------------------
1509
1510    awmm->create_menu("Create", "C", 0, AWM_ALL);
1511    awmm->insert_menu_topic("create_species",                "Create new species",                "n", 0, AWM_ALL, AW_POPUP, (AW_CL)ED4_create_new_seq_window, (int)0);
1512    awmm->insert_menu_topic("create_species_from_consensus", "Create new species from consensus", "u", 0, AWM_ALL, AW_POPUP, (AW_CL)ED4_create_new_seq_window, (int)1);
1513    awmm->insert_menu_topic("copy_species",                  "Copy current species",              "C", 0, AWM_ALL, AW_POPUP, (AW_CL)ED4_create_new_seq_window, (int)2);
1514    SEP________________________SEP;
1515    awmm->insert_menu_topic("create_group",           "Create new Group",              "G", 0, AWM_ALL, group_species_cb, 0, 0);
1516    awmm->insert_menu_topic("create_groups_by_field", "Create new groups using Field", "F", 0, AWM_ALL, group_species_cb, 1, 0);
1517
1518    // ------------------------------
1519    //  Edit
1520    // ------------------------------
1521
1522    awmm->create_menu( "Edit", "E", 0, AWM_ALL);
1523    awmm->insert_menu_topic("refresh",     "Refresh [Ctrl-L]",           "f",  0, AWM_ALL, ED4_refresh_window,                   1, 0);
1524    awmm->insert_menu_topic("load_actual", "Load current species [GET]", "G", 0, AWM_ALL, ED4_get_and_jump_to_actual_from_menu, 0, 0);
1525    awmm->insert_menu_topic("load_marked", "Load marked species",        "m", 0, AWM_ALL, ED4_get_marked_from_menu,             0, 0);
1526    SEP________________________SEP;
1527    awmm->insert_menu_topic("refresh_ecoli",       "Reload Ecoli sequence",        "E", 0, AWM_ALL, ED4_reload_ecoli_cb,     0, 0);
1528    awmm->insert_menu_topic("refresh_helix",       "Reload Helix",                 "H", 0, AWM_ALL, ED4_reload_helix_cb,     0, 0);
1529    awmm->insert_menu_topic("helix_jump_opposite", "Jump helix opposite [Ctrl-J]", "J", 0, AWM_ALL, ED4_helix_jump_opposite, 0, 0);
1530    SEP________________________SEP;
1531
1532    awmm->insert_sub_menu("Set protection of current ", "p");
1533    {
1534        char macro[] = "to_0",
1535            topic[] = ".. to 0",
1536            hotkey[] = "0";
1537
1538        for (char i='0'; i<='6'; i++) {
1539            macro[3] = topic[6] = hotkey[0] = i;
1540            awmm->insert_menu_topic(macro, topic, hotkey, 0, AWM_ALL, ED4_set_protection, AW_CL(i-'0'), 0);
1541        }
1542    }
1543    awmm->close_sub_menu();
1544
1545#if !defined(NDEBUG) && 0
1546    awmm->insert_menu_topic("turn_sequence", "Turn Sequence",             "T", 0, AWM_ALL, ED4_turnSpecies,     1, 0);
1547    awmm->insert_menu_topic(0,               "Test (test split & merge)", "T", 0, AWM_ALL, ED4_testSplitNMerge, 1, 0);
1548#endif
1549    SEP________________________SEP;
1550    awmm->insert_menu_topic("fast_aligner",       INTEGRATED_ALIGNERS_TITLE " [Ctrl-A]", "I", "faligner.hlp",     AWM_ALL,            AW_POPUP,                               (AW_CL)ED4_create_faligner_window, (AW_CL)&faligner_client_data);
1551    awmm->insert_menu_topic("fast_align_set_ref", "Set aligner reference [Ctrl-R]",      "R", "faligner.hlp",     AWM_ALL,            (AW_CB)AWTC_set_reference_species_name, (AW_CL)aw_root,                    0);
1552    awmm->insert_menu_topic("align_sequence",     "Old aligner from ARB_EDIT",           "O", "ne_align_seq.hlp", AWM_EXP,            AW_POPUP,                               (AW_CL)create_naligner_window,     0);
1553    awmm->insert_menu_topic("sina",               "SINA (SILVA Incremental Aligner)",    "S", "sina_main.hlp",    sina_mask(aw_root), show_sina_window,                       (AW_CL)&faligner_client_data,      0);
1554    awmm->insert_menu_topic("del_ali_tmp",        "Remove all aligner Entries",          "v", 0,                  AWM_ALL,            ED4_remove_faligner_entries,            1,                                 0);
1555    SEP________________________SEP;
1556    awmm->insert_menu_topic("missing_bases", "Dot potentially missing bases", "D", "missbase.hlp", AWM_EXP, ED4_popup_dot_missing_bases_window, 0, 0);
1557    SEP________________________SEP;
1558    awmm->insert_menu_topic("sec_edit", "Edit secondary structure", "c", 0, AWM_ALL, ED4_SECEDIT_start, (AW_CL)GLOBAL_gb_main, 0);
1559
1560    // ------------------------------
1561    //  View
1562    // ------------------------------
1563
1564    awmm->create_menu("View", "V", 0, AWM_ALL);
1565    awmm->insert_sub_menu("Search", "S");
1566    {
1567        int         s;
1568        const char *hotkeys  = "12Poiclrg";
1569        char        hotkey[] = "_";
1570
1571        e4_assert(strlen(hotkeys) == SEARCH_PATTERNS);
1572
1573        for (s=0; s<SEARCH_PATTERNS; s++) {
1574            ED4_SearchPositionType type = ED4_SearchPositionType(s);
1575            const char *id = ED4_SearchPositionTypeId[type];
1576            int len = strlen(id);
1577            char *macro_name = GB_give_buffer(2*(len+8));
1578            char *menu_entry_name = macro_name+(len+8);
1579
1580#ifndef NDEBUG
1581            memset(macro_name, 0, 2*(len+8)); // to avoid memchk-warning
1582#endif
1583            sprintf(macro_name, "%s_SEARCH", id);
1584            char *p = macro_name;
1585            while (1) {
1586                char c = *p++;
1587                if (!c) break;
1588                p[-1] = toupper(c);
1589            }
1590            sprintf(menu_entry_name, "%s Search", id);
1591
1592            hotkey[0] = hotkeys[s];
1593            awmm->insert_menu_topic(macro_name, menu_entry_name, hotkey, "e4_search.hlp", AWM_ALL, AW_POPUP, AW_CL(ED4_create_search_window), AW_CL(type));
1594        }
1595    }
1596    awmm->close_sub_menu();
1597    SEP________________________SEP;
1598    awmm->insert_sub_menu("Cursor position ", "p");
1599    awmm->insert_menu_topic("store_curpos",   "Store cursor position",    "S", 0, AWM_ALL, ED4_store_curpos,        0, 0);
1600    awmm->insert_menu_topic("restore_curpos", "Restore cursor position ", "R", 0, AWM_ALL, ED4_restore_curpos,      0, 0);
1601    awmm->insert_menu_topic("clear_curpos",   "Clear stored positions",   "C", 0, AWM_ALL, ED4_clear_stored_curpos, 0, 0);
1602    awmm->close_sub_menu();
1603
1604    SEP________________________SEP;
1605    awmm->insert_menu_topic("change_cursor", "Change cursor type",                "t", 0,                   AWM_ALL, ED4_change_cursor,         0, 0);
1606    awmm->insert_menu_topic("show_all",      "Show all bases ",                   "a", "set_reference.hlp", AWM_ALL, ED4_set_reference_species, 1, 0);
1607    awmm->insert_menu_topic("show_diff",     "Show only differences to selected", "d", "set_reference.hlp", AWM_ALL, ED4_set_reference_species, 0, 0);
1608    SEP________________________SEP;
1609    awmm->insert_menu_topic("enable_col_stat",  "Activate column statistics", "v", "st_ml.hlp", AWM_EXP, ED4_activate_col_stat,          0, 0);
1610    awmm->insert_menu_topic("disable_col_stat", "Disable column statistics",  "i", "st_ml.hlp", AWM_EXP, disable_col_stat,               0, 0);
1611    awmm->insert_menu_topic("detail_col_stat",  "Detailed column statistics", "c", "st_ml.hlp", AWM_EXP, ED4_show_detailed_column_stats, 0, 0);
1612    awmm->insert_menu_topic("dcs_threshold",    "Set threshold for D.c.s.",   "f", "st_ml.hlp", AWM_EXP, ED4_set_col_stat_threshold,     1, 0);
1613    SEP________________________SEP;
1614    awmm->insert_menu_topic( "visualize_SAI", "Visualize SAIs", "z", "visualizeSAI.hlp", AWM_ALL,AW_POPUP,(AW_CL)ED4_createVisualizeSAI_window, 0 );
1615    // Enable ProteinViewer only for DNA sequence type
1616    if (alignment_type == GB_AT_DNA) {
1617        awmm->insert_menu_topic( "Protein_Viewer", "Protein Viewer", "w", "proteinViewer.hlp", AWM_ALL,AW_POPUP,(AW_CL)ED4_CreateProteinViewer_window, 0 );
1618    }
1619
1620    // ------------------------------
1621    //  Block
1622    // ------------------------------
1623
1624    awmm->create_menu("Block", "B", 0, AWM_ALL);
1625
1626    awmm->insert_menu_topic("select_marked",   "Select marked species",   "e", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_SELECT_MARKED)  , 0);
1627    awmm->insert_menu_topic("deselect_marked", "Deselect marked species", "k", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_DESELECT_MARKED), 0);
1628    awmm->insert_menu_topic("select_all",      "Select all species",      "S", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_ALL)            , 0);
1629    awmm->insert_menu_topic("deselect_all",    "Deselect all species",    "D", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_NONE)           , 0);
1630    SEP________________________SEP;
1631    awmm->insert_menu_topic("mark_selected",   "Mark selected species",   "M", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_MARK_SELECTED)  , 0);
1632    awmm->insert_menu_topic("unmark_selected", "Unmark selected species", "n", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_UNMARK_SELECTED), 0);
1633    awmm->insert_menu_topic("unmark_all",      "Unmark all species",      "U", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_UNMARK_ALL)     , 0);
1634    SEP________________________SEP;
1635    awmm->insert_menu_topic("invert_all",   "Invert selected species", "I", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_INVERT)      , 0);
1636    awmm->insert_menu_topic("invert_group", "Invert group",            "g", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_INVERT_GROUP), 0);
1637    SEP________________________SEP;
1638    awmm->insert_menu_topic("lowcase", "Change to lower case ", "w", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_LOWER_CASE), 0);
1639    awmm->insert_menu_topic("upcase",  "Change to upper case",  "p", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_UPPER_CASE), 0);
1640    SEP________________________SEP;
1641    awmm->insert_menu_topic("reverse",            "Reverse selection ",    "v", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_REVERSE)           , 0);
1642    awmm->insert_menu_topic("complement",         "Complement selection ", "o", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_COMPLEMENT)        , 0);
1643    awmm->insert_menu_topic("reverse_complement", "Reverse complement",    "t", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_REVERSE_COMPLEMENT), 0);
1644    SEP________________________SEP;
1645    awmm->insert_menu_topic("unalignBlockLeft",  "Unalign block",       "a", "e4_block.hlp",   AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_UNALIGN)      ,                          0);
1646    awmm->insert_menu_topic("unalignBlockRight", "Unalign block right", "b", "e4_block.hlp",   AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_UNALIGN_RIGHT),                          0);
1647    awmm->insert_menu_topic("replace",           "Search & Replace ",   "h", "e4_replace.hlp", AWM_ALL, AW_POPUP,                              (AW_CL)               ED4_create_replace_window, 0);
1648    SEP________________________SEP;
1649    awmm->insert_menu_topic("toggle_block_type", "Line block <-> Column block", "C", "e4_block.hlp", AWM_ALL, ED4_menu_select,                  AW_CL(ED4_MS_TOGGLE_BLOCKTYPE), 0);
1650    awmm->insert_menu_topic("shift_left",        "Shift block left ",           "l", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_SHIFT_LEFT)      , 0);
1651    awmm->insert_menu_topic("shift_right",       "Shift block right",           "r", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_SHIFT_RIGHT)     , 0);
1652
1653    // ------------------------------
1654    //  Properties
1655    // ------------------------------
1656
1657    awmm->create_menu("Properties",   "P", "Select something",    AWM_ALL);
1658   
1659    awmm->insert_menu_topic("props_frame",     "Frame Settings ",       "F", 0,                  AWM_ALL, AW_POPUP, (AW_CL)AW_preset_window,                       0);
1660    awmm->insert_menu_topic("props_options",   "Editor Options ",       "O", "e4_options.hlp",   AWM_ALL, AW_POPUP, (AW_CL)ED4_create_level_1_options_window,      0);
1661    awmm->insert_menu_topic("props_consensus", "Consensus Definition ", "u", "e4_consensus.hlp", AWM_ALL, AW_POPUP, (AW_CL)ED4_create_consensus_definition_window, 0);
1662    SEP________________________SEP;
1663
1664    awmm->insert_menu_topic("props_data",       "Change Colors & Fonts ", "C", 0,         AWM_ALL, AW_POPUP, (AW_CL)ED4_create_gc_window,      (AW_CL)first_gc_manager);
1665    awmm->insert_menu_topic("props_seq_colors", "Set Sequence Colors ",   "S", "no help", AWM_ALL, AW_POPUP, (AW_CL)create_seq_colors_window, (AW_CL)sequence_colors);
1666
1667    SEP________________________SEP;
1668
1669    static AW_cb_struct *expose_cb = 0;
1670    if (!expose_cb) expose_cb = new AW_cb_struct(awmm, (AW_CB)ED4_expose_cb, 0, 0);
1671
1672    if (alignment_type == GB_AT_AA) awmm->insert_menu_topic("props_pfold",     "Protein Match Settings ", "P", "pfold_props.hlp", AWM_ALL, AW_POPUP, (AW_CL)ED4_pfold_create_props_window, (AW_CL)expose_cb);
1673    else                            awmm->insert_menu_topic("props_helix_sym", "Helix Settings ",         "H", "helixsym.hlp",    AWM_ALL, AW_POPUP, (AW_CL)create_helix_props_window,     (AW_CL)expose_cb);
1674
1675    awmm->insert_menu_topic("props_key_map", "Key Mappings ",              "K", "nekey_map.hlp", AWM_ALL, AW_POPUP, (AW_CL)create_key_map_window, 0);
1676    awmm->insert_menu_topic("props_nds",     "Select visible info (NDS) ", "D", "e4_nds.hlp",    AWM_ALL, AW_POPUP, (AW_CL)ED4_create_nds_window, 0);
1677    SEP________________________SEP;
1678    awmm->insert_sub_menu("Save properties ...", "a");
1679    {
1680        static const char * const tag[] = { "save_alispecific_props", "save_alitype_props", "save_props" };
1681        static const char * const entry_type[] = { "alignment specific ", "ali-type specific ", "" };
1682
1683        // check what is the default mode
1684        int default_mode = -1;
1685        for (int mode = 0; mode <= 2; ++mode) {
1686            if (0 == strcmp(ED4_propertyName(mode), db_name)) {
1687                default_mode = mode;
1688                break;
1689            }
1690        }
1691
1692        const char *entry = GBS_global_string("Save loaded Properties (~/%s)", db_name);
1693        awmm->insert_menu_topic("save_loaded_props", entry, "l", "e4_defaults.hlp", AWM_ALL, ED4_save_defaults, (AW_CL)default_mode, 0);
1694        SEP________________________SEP;
1695
1696        for (int mode = 2; mode >= 0; --mode) {
1697            char hotkey[] = "x";
1698            hotkey[0]     = "Pta"[mode];
1699            entry         = GBS_global_string("Save %sProperties (~/%s)", entry_type[mode], ED4_propertyName(mode));
1700            awmm->insert_menu_topic(tag[mode], entry, hotkey, "e4_defaults.hlp", AWM_ALL, ED4_save_defaults, (AW_CL)mode, 0);
1701        }
1702    }
1703    awmm->close_sub_menu();
1704
1705    awmm->insert_help_topic("ARB_EDIT4 help",     "E", "e4.hlp", AWM_ALL, (AW_CB)AW_POPUP_HELP, (AW_CL)"e4.hlp", 0);
1706
1707    // ----------------------------------------------------------------------------------------------------
1708
1709#undef SEP________________________SEP
1710
1711    aw_root->awar_int(AWAR_EDIT_TITLE_MODE)->add_callback((AW_RCB1)title_mode_changed, (AW_CL)awmm);
1712    awmm->set_bottom_area_height( 0 ); //No bottom area
1713
1714    awmm->auto_space(5,-2);
1715    awmm->shadow_width(3);
1716
1717    int db_pathx,db_pathy;
1718    awmm->get_at_position( &db_pathx,&db_pathy );
1719
1720    awmm->shadow_width(1);
1721    awmm->load_xfig("edit4/editmenu.fig", false);
1722
1723    // -------------------------
1724    //      help /quit /fold
1725    // -------------------------
1726
1727    awmm->button_length(0);
1728
1729    awmm->at("quit");
1730    awmm->callback(ED4_quit_editor, 0, 0);
1731    awmm->help_text("quit.hlp");
1732
1733    if (clone) awmm->create_button("CLOSE","#close.xpm");
1734    else       awmm->create_button("QUIT","#quit.xpm");
1735   
1736    awmm->at("help");
1737    awmm->callback(AW_help_entry_pressed);
1738    awmm->help_text("e4.hlp");
1739    awmm->create_button("HELP","#help.xpm");
1740
1741    awmm->at("fold");
1742    awmm->help_text("e4.hlp");
1743    awmm->create_toggle(AWAR_EDIT_TITLE_MODE, "#more.bitmap", "#less.bitmap");
1744
1745    // ------------------
1746    //      positions
1747    // ------------------
1748   
1749    awmm->button_length(0);
1750   
1751    awmm->at("posTxt");     awmm->create_button(0, "Position");
1752
1753    awmm->button_length(6+1);
1754   
1755    awmm->at("ecoliTxt");   awmm->create_button(0, ED4_AWAR_NDS_ECOLI_NAME, 0, "+");
1756
1757    awmm->button_length(0);
1758   
1759    awmm->at("baseTxt");    awmm->create_button(0, "Base");
1760    awmm->at("iupacTxt");   awmm->create_button(0, "IUPAC");
1761    awmm->at("helixnrTxt"); awmm->create_button(0, "Helix#");
1762
1763    awmm->at("pos");
1764    awmm->callback((AW_CB)ED4_jump_to_cursor_position, (AW_CL) get_ed4w()->awar_path_for_cursor, AW_CL(1));
1765    awmm->create_input_field(get_ed4w()->awar_path_for_cursor,7);
1766
1767    awmm->at("ecoli");
1768    awmm->callback((AW_CB)ED4_jump_to_cursor_position,(AW_CL) get_ed4w()->awar_path_for_Ecoli, AW_CL(0));
1769    awmm->create_input_field(get_ed4w()->awar_path_for_Ecoli,6);
1770
1771    awmm->at("base");
1772    awmm->callback((AW_CB)ED4_jump_to_cursor_position,(AW_CL) get_ed4w()->awar_path_for_basePos, AW_CL(0));
1773    awmm->create_input_field(get_ed4w()->awar_path_for_basePos,6);
1774
1775    awmm->at("iupac");
1776    awmm->callback((AW_CB)ED4_set_iupac,(AW_CL) get_ed4w()->awar_path_for_IUPAC, AW_CL(0));
1777    awmm->create_input_field(get_ed4w()->awar_path_for_IUPAC,4);
1778
1779    awmm->at("helixnr");
1780    awmm->callback((AW_CB)ED4_set_helixnr,(AW_CL) get_ed4w()->awar_path_for_helixNr, AW_CL(0));
1781    awmm->create_input_field(get_ed4w()->awar_path_for_helixNr,5);
1782
1783    // ---------------------------
1784    //      jump/get/undo/redo
1785    // ---------------------------
1786
1787    awmm->button_length(4);
1788   
1789    awmm->at("jump");
1790    awmm->callback(ED4_jump_to_current_species, 0);
1791    awmm->help_text("e4.hlp");
1792    awmm->create_button("JUMP", "Jump");
1793
1794    awmm->at("get");
1795    awmm->callback(ED4_get_and_jump_to_actual, 0);
1796    awmm->help_text("e4.hlp");
1797    awmm->create_button("GET", "Get");
1798
1799    awmm->button_length(0);
1800   
1801    awmm->at("undo");
1802    awmm->callback(ED4_undo_redo, GB_UNDO_UNDO);
1803    awmm->help_text("undo.hlp");
1804    awmm->create_button("UNDO", "#undo.bitmap");
1805
1806    awmm->at("redo");
1807    awmm->callback(ED4_undo_redo, GB_UNDO_REDO);
1808    awmm->help_text("undo.hlp");
1809    awmm->create_button("REDO", "#redo.bitmap");
1810
1811    // -------------------------
1812    //      aligner / SAIviz
1813    // -------------------------
1814   
1815    awmm->button_length(7);
1816   
1817    awmm->at("aligner");
1818    awmm->callback(AW_POPUP, (AW_CL)ED4_create_faligner_window, (AW_CL)&faligner_client_data);
1819    awmm->help_text("faligner.hlp");
1820    awmm->create_button("ALIGNER", "Aligner");
1821
1822    awmm->at("saiviz");
1823    awmm->callback(AW_POPUP,(AW_CL)ED4_createVisualizeSAI_window, 0 );
1824    awmm->help_text("visualizeSAI.hlp");
1825    awmm->create_button("SAIVIZ", "SAIviz");
1826
1827    // ------------------------------------------
1828    //      align/insert/protection/direction
1829    // ------------------------------------------
1830
1831    awmm->button_length(0);
1832   
1833    awmm->at("protect");
1834    awmm->create_option_menu(AWAR_EDIT_SECURITY_LEVEL);
1835    awmm->insert_option("0",0,0);
1836    awmm->insert_option("1",0,1);
1837    awmm->insert_option("2",0,2);
1838    awmm->insert_option("3",0,3);
1839    awmm->insert_option("4",0,4);
1840    awmm->insert_option("5",0,5);
1841    awmm->insert_default_option("6",0,6);
1842    awmm->update_option_menu();
1843
1844    // draw protection icon AFTER protection!!
1845    awmm->at("pico");
1846    awmm->create_button("PROTECT","#protect.xpm");
1847
1848    // draw align/edit-button AFTER protection!!
1849    awmm->at("edit");
1850    awmm->create_toggle(AWAR_EDIT_MODE, "#edit/align.xpm", "#edit/editseq.xpm", 7);
1851
1852    awmm->at("insert");
1853    awmm->create_text_toggle(AWAR_INSERT_MODE, "Replace", "Insert", 7);
1854
1855    awmm->at("direct");
1856    awmm->create_toggle(AWAR_EDIT_DIRECTION,"#edit/3to5.bitmap","#edit/5to3.bitmap", 7);
1857
1858    // ------------------------
1859    //      secedit / rna3d
1860    // ------------------------
1861
1862    int xoffset = 0;
1863
1864    // Enable RNA3D and SECEDIT programs if the database contains valid alignment of rRNA sequences.
1865    if (alignment_type == GB_AT_RNA) {
1866        awmm->button_length(0);
1867       
1868        awmm->at("secedit");
1869        awmm->callback(ED4_SECEDIT_start, (AW_CL)GLOBAL_gb_main, 0);
1870        awmm->help_text("arb_secedit.hlp");
1871        awmm->create_button("SECEDIT", "#edit/secedit.xpm");
1872       
1873#if defined(ARB_OPENGL)
1874        awmm->at("rna3d");
1875        awmm->callback(ED4_RNA3D_Start, 0, 0);
1876        awmm->help_text("rna3d_general.hlp");
1877        awmm->create_button("RNA3D", "#edit/rna3d.xpm");
1878#endif // ARB_OPENGL
1879    }
1880    else {
1881        awmm->at("secedit");
1882        int xsecedit = awmm->get_at_xposition();
1883        awmm->at("zoom");
1884        int xzoom    = awmm->get_at_xposition();
1885        xoffset      = xsecedit-xzoom; // shift message stuff to the left by xoffset
1886    }
1887
1888    {
1889        int x, y;
1890
1891        awmm->at("zoom");
1892        if (xoffset) { awmm->get_at_position(&x, &y); awmm->at(x+xoffset, y); }
1893        awmm->callback(AW_POPUP, (AW_CL)ED4_zoom_message_window, (AW_CL)0);
1894        awmm->create_button("ZOOM", "#edit/zoom.bitmap");
1895
1896        awmm->at("clear");
1897        if (xoffset) { awmm->get_at_position(&x, &y); awmm->at(x+xoffset, y); }
1898        awmm->callback(ED4_clear_errors, (AW_CL)0);
1899        awmm->create_button("CLEAR", "#edit/clear.bitmap");
1900
1901        awmm->at("errortext");
1902        if (xoffset) { awmm->get_at_position(&x, &y); awmm->at(x+xoffset, y); }
1903        aw_root->awar_string(AWAR_ERROR_MESSAGES, "This is ARB Edit4 [Build " ARB_VERSION "]");
1904        awmm->create_text_field(AWAR_ERROR_MESSAGES);
1905        aw_set_local_message();
1906    }
1907
1908    // --------------------
1909    //      'more' area
1910    // --------------------
1911
1912    awmm->at("cons");
1913    awmm->create_toggle(ED4_AWAR_CONSENSUS_SHOW, "#edit/nocons.bitmap", "#edit/cons.bitmap");
1914
1915    awmm->at("num");
1916    awmm->create_toggle(ED4_AWAR_DIGITS_AS_REPEAT, "#edit/norepeat.bitmap", "#edit/repeat.bitmap");
1917
1918    awmm->at("key");
1919    awmm->create_toggle("key_mapping/enable", "#edit/nokeymap.bitmap", "#edit/keymap.bitmap");
1920
1921    // search
1922   
1923    awmm->button_length(0);
1924#define INSERT_SEARCH_FIELDS(Short, label_prefix, prefix) insert_search_fields(awmm, #label_prefix, #prefix, ED4_AWAR_##prefix##_SEARCH_PATTERN, ED4_##prefix##_PATTERN, ED4_AWAR_##prefix##_SEARCH_SHOW, Short)
1925
1926    INSERT_SEARCH_FIELDS(0, u1, USER1);
1927    INSERT_SEARCH_FIELDS(0, u2, USER2);
1928    INSERT_SEARCH_FIELDS(0, pro, PROBE);
1929    INSERT_SEARCH_FIELDS(1, pri1, PRIMER1);
1930    INSERT_SEARCH_FIELDS(1, pri2, PRIMER2);
1931    INSERT_SEARCH_FIELDS(1, pri3, PRIMER3);
1932    INSERT_SEARCH_FIELDS(1, sig1, SIG1);
1933    INSERT_SEARCH_FIELDS(1, sig2, SIG2);
1934    INSERT_SEARCH_FIELDS(1, sig3, SIG3);
1935
1936#undef INSERT_SEARCH_FIELDS
1937
1938    awmm->at("alast");
1939    awmm->callback(ED4_search, ED4_encodeSearchDescriptor(-1, ED4_ANY_PATTERN));
1940    awmm->create_button("ALL_SEARCH_LAST", "#edit/last.bitmap");
1941
1942    awmm->at("anext");
1943    awmm->callback(ED4_search, ED4_encodeSearchDescriptor(+1, ED4_ANY_PATTERN));
1944    awmm->create_button("ALL_SEARCH_NEXT", "#edit/next.bitmap");
1945
1946    title_mode_changed(aw_root, awmm);
1947
1948    // Buttons at left window border
1949
1950    awmm->create_mode("edit/arrow.bitmap", "normal.hlp", AWM_ALL, (AW_CB)modes_cb, (AW_CL)0, (AW_CL)0);
1951    awmm->create_mode("edit/kill.bitmap",  "kill.hlp",   AWM_ALL, (AW_CB)modes_cb, (AW_CL)1, (AW_CL)0);
1952    awmm->create_mode("edit/mark.bitmap",  "mark.hlp",   AWM_ALL, (AW_CB)modes_cb, (AW_CL)2, (AW_CL)0);
1953
1954    AWTC_create_faligner_variables(awmm->get_root(), db);
1955
1956    return ( ED4_R_OK );
1957}
1958
1959AW_window *ED4_root::create_new_window( void )                      // only the first time, other cases: generate_window
1960{
1961    AW_device  *device     = NULL;
1962    ED4_window *new_window = NULL;
1963
1964    generate_window( &device, &new_window );
1965
1966    ED4_calc_terminal_extentions();
1967
1968    last_window_reached     = 1;
1969    DRAW                    = 1;
1970    move_cursor             = 0;
1971    all_found               = 0;
1972    species_read            = 0;
1973    max_seq_terminal_length = 0;
1974
1975    not_found_message = GBS_stropen(1000);
1976
1977    GBS_strcat(not_found_message,"Some species not found:\n");
1978
1979    return ( new_window->aww );
1980}
1981
1982ED4_index ED4_root::pixel2pos(AW_pos click_x) {
1983    // 'click_x' is the x-offset into the terminal in pixels
1984    // returns the x-offset into the terminal in base positions (clipped to max. allowed position)
1985
1986    int       length_of_char = font_group.get_width(ED4_G_SEQUENCES);
1987    ED4_index scr_pos        = int((click_x-CHARACTEROFFSET) / length_of_char);
1988    int       max_scrpos     = root_group_man->remap()->get_max_screen_pos();
1989
1990    if (scr_pos>max_scrpos) scr_pos = max_scrpos;
1991
1992    return scr_pos;
1993}
1994
1995ED4_root::ED4_root()
1996{
1997    memset((char *)this,0,sizeof(*this));
1998
1999    aw_root      = new AW_root;
2000    first_window = NULL;
2001    main_manager = NULL;
2002    database     = NULL;
2003    tmp_ed4w     = NULL;
2004    tmp_aww      = NULL;
2005    tmp_device   = NULL;
2006    temp_gc      = 0;
2007
2008    scroll_links.link_for_hor_slider = NULL;
2009    scroll_links.link_for_ver_slider = NULL;
2010
2011    folding_action = 0;
2012   
2013    species_mode            = ED4_SM_MOVE;
2014    scroll_picture.scroll   = 0;
2015    scroll_picture.old_x    = 0;
2016    scroll_picture.old_y    = 0;
2017    middle_area_man         = NULL;
2018    top_area_man            = NULL;
2019    root_group_man          = NULL;
2020    ecoli_ref               = NULL;
2021    protstruct              = NULL;
2022    protstruct_len          = 0;
2023    column_stat_activated   = 0;
2024    column_stat_initialized = 0;
2025    visualizeSAI            = 0;
2026    visualizeSAI_allSpecies = 0;
2027
2028    aw_initstatus();
2029}
2030
2031
2032ED4_root::~ED4_root()
2033{
2034    delete aw_root;
2035    delete first_window;
2036    delete main_manager;
2037    delete middle_area_man;
2038    delete top_area_man;
2039    delete database;
2040    delete ecoli_ref;
2041    if (protstruct) free(protstruct);
2042}
2043
2044//***********************************
2045//* ED4_root Methods        end *
2046//***********************************
Note: See TracBrowser for help on using the repository browser.