source: branches/port5/EDIT4/ED4_root.cxx

Last change on this file was 6358, 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: 76.7 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    ED4_finish_and_show_notFoundMessage();
735
736    return ( ED4_R_OK );
737}
738
739ED4_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
740    ED4_folding_line *flv, *flh;
741    int x1, x2, y1, y2;
742    AW_rectangle area_rect;
743    get_device()->get_area_size(&area_rect);
744
745    x1 = area_rect.l;
746    for (flv=get_ed4w()->vertical_fl; ; flv = flv->next) {
747        if (flv) {
748            e4_assert(flv->length==INFINITE);
749            x2 = int(flv->window_pos[X_POS]);
750        }
751        else {
752            x2 = area_rect.r;
753            if (x1==x2) {
754                break;
755            }
756        }
757
758        y1 = area_rect.t;
759        for (flh=get_ed4w()->horizontal_fl; ; flh = flh->next) {
760            if (flh) {
761                e4_assert(flh->length==INFINITE);
762                y2 = int(flh->window_pos[Y_POS]);
763            }
764            else {
765                y2 = area_rect.b;
766                if (y1==y2) {
767                    break;
768                }
769            }
770
771            if (x1<=x && x<=x2 && y1<=y && y<=y2) {
772                rect->t = y1;
773                rect->b = y2;
774                rect->l = x1;
775                rect->r = x2;
776                return ED4_R_OK;
777            }
778            y1 = y2;
779            if (!flh) break;
780        }
781        x1 = x2;
782        if (!flv) break;
783    }
784    return ED4_R_IMPOSSIBLE; // no area contains x/y :-(
785}
786
787ED4_returncode ED4_root::world_to_win_coords(AW_window *IF_DEBUG(aww), AW_pos *xPtr, AW_pos *yPtr)  // calculates transformation from world to window
788{                                               // coordinates in a given window
789    ED4_window      *current_window;
790    ED4_folding_line    *current_fl;
791    AW_pos      temp_x, temp_y, x, y;
792
793    current_window = get_ed4w();
794    e4_assert(current_window==first_window->get_matching_ed4w(aww));
795
796    if (! current_window) {
797        e4_assert(0);
798        return ( ED4_R_WARNING ); // should never occur
799    }
800
801    temp_x = x = *xPtr;
802    temp_y = y = *yPtr;
803
804    current_fl = current_window->vertical_fl;                       // calculate x-offset due to vertical folding lines
805    while (current_fl && (x>=current_fl->world_pos[X_POS])) {
806        if ((current_fl->length == INFINITE) ||
807            ((y >= current_fl->world_pos[Y_POS]) &&
808             (y <= current_fl->world_pos[Y_POS] + current_fl->length)))
809        {
810            temp_x -= current_fl->dimension;
811
812        }
813        current_fl = current_fl->next;
814    }
815
816    current_fl = current_window->horizontal_fl;                     // calculate y-offset due to horizontal folding lines
817    while (current_fl && (y >= current_fl->world_pos[Y_POS])) {
818        if ((current_fl->length == INFINITE) ||
819            ((x >= current_fl->world_pos[X_POS]) &&
820             (x <= (current_fl->world_pos[X_POS] + current_fl->length))))
821        {
822            temp_y -= current_fl->dimension;
823        }
824        current_fl = current_fl->next;
825    }
826
827    *xPtr = temp_x;
828    *yPtr = temp_y;
829
830    return ( ED4_R_OK );
831}
832
833void ED4_root::copy_window_struct( ED4_window *source , ED4_window *destination )
834{
835    destination->slider_pos_horizontal  = source->slider_pos_horizontal;
836    destination->slider_pos_vertical    = source->slider_pos_vertical;
837    destination->coords         = source->coords;
838}
839
840
841void ED4_reload_helix_cb(AW_window *aww,AW_CL cd1, AW_CL cd2) {
842    const char *err = ED4_ROOT->helix->init(GLOBAL_gb_main);
843    if (err) aw_message(err);
844    ED4_refresh_window(aww,cd1,cd2);
845}
846
847
848void ED4_reload_ecoli_cb(AW_window *aww,AW_CL cd1, AW_CL cd2)
849{
850    const char *err = ED4_ROOT->ecoli_ref->init(GLOBAL_gb_main);
851    if (err) aw_message(err);
852    ED4_refresh_window(aww,cd1,cd2);
853}
854
855// --------------------------------------------------------------------------------
856//  recursion through all species
857// --------------------------------------------------------------------------------
858
859static GB_ERROR do_sth_with_species_error = NULL;
860
861ED4_returncode do_sth_with_species(void **arg1, void **arg2, ED4_base *base)
862{
863    if (!do_sth_with_species_error && base->is_species_manager()) {
864        GB_ERROR (*what_to_do_with_species)(GBDATA*,void**) = (GB_ERROR (*)(GBDATA*,void**))arg1;
865        ED4_species_manager *species_manager = base->to_species_manager();
866        ED4_species_name_terminal *species_name_terminal = species_manager->search_spec_child_rek(ED4_L_SPECIES_NAME)->to_species_name_terminal();
867
868        if (species_name_terminal->get_species_pointer()) {
869            char *species_name = GB_read_as_string(species_name_terminal->get_species_pointer());
870
871            e4_assert(species_name);
872            GBDATA *species = GBT_find_species(GLOBAL_gb_main, species_name);
873            if (species) do_sth_with_species_error = what_to_do_with_species(species, arg2);
874            delete species_name;
875        }
876    }
877
878    return ED4_R_OK;
879}
880
881
882GB_ERROR ED4_with_all_loaded_species(GB_ERROR (*what_to_do_with_species)(GBDATA*,void**), void **arg)
883{
884    ED4_ROOT->root_group_man->route_down_hierarchy((void**)what_to_do_with_species, arg, do_sth_with_species);
885    GB_ERROR error = do_sth_with_species_error;
886    do_sth_with_species_error = NULL;
887    return error;
888}
889
890// --------------------------------------------------------------------------------
891//  faligner
892// --------------------------------------------------------------------------------
893
894static int has_species_name(ED4_base *base, AW_CL cl_species_name)
895{
896    ED4_species_name_terminal *name_term = base->to_species_name_terminal();
897    GBDATA *gbd = name_term->get_species_pointer();
898
899    if (gbd) {
900        const char *name = GB_read_char_pntr(gbd);
901        e4_assert(name);
902        int has_name = strcmp(name,(const char*)cl_species_name)==0;
903        return has_name;
904    }
905
906    return 0;
907}
908
909ED4_species_name_terminal *ED4_find_species_name_terminal(const char *species_name)
910{
911    ED4_base *base = ED4_ROOT->root_group_man->find_first_that(ED4_L_SPECIES_NAME, has_species_name, (AW_CL)species_name);
912
913    return base ? base->to_species_name_terminal() : 0;
914}
915
916static char *get_group_consensus(const char *species_name, int start_pos, int end_pos)
917{
918    ED4_species_name_terminal *name_term = ED4_find_species_name_terminal(species_name);
919    char *consensus = 0;
920
921    if (name_term) {
922        ED4_group_manager *group_man = name_term->get_parent(ED4_L_GROUP)->to_group_manager();
923        if (group_man) {
924            consensus = group_man->table().build_consensus_string(start_pos, end_pos, 0);
925        }
926    }
927
928    return consensus;
929}
930
931static int get_selected_range(int *firstColumn, int *lastColumn)
932{
933    ED4_list_elem *listElem = ED4_ROOT->selected_objects.first();
934    if (listElem) {
935        ED4_selection_entry *selectionEntry = (ED4_selection_entry*)listElem->elem();
936        ED4_sequence_terminal *seqTerm = selectionEntry->object->get_parent(ED4_L_SPECIES)->search_spec_child_rek(ED4_L_SEQUENCE_STRING)->to_sequence_terminal();
937
938        ED4_get_selected_range(seqTerm, firstColumn, lastColumn);
939        return 1;
940    }
941    return 0;
942}
943
944static ED4_list_elem *actual_aligner_elem = 0;
945static GBDATA *get_next_selected_species(void)
946{
947    if (!actual_aligner_elem) return 0;
948
949    ED4_selection_entry *selectionEntry = (ED4_selection_entry*)actual_aligner_elem->elem();
950    ED4_species_manager *specMan = selectionEntry->object->get_parent(ED4_L_SPECIES)->to_species_manager();
951
952    actual_aligner_elem = actual_aligner_elem->next();
953    return specMan->get_species_pointer();
954}
955static GBDATA *get_first_selected_species(int *total_no_of_selected_species)
956{
957    int selected = ED4_ROOT->selected_objects.no_of_entries();
958
959    if (total_no_of_selected_species) {
960        *total_no_of_selected_species = selected;
961    }
962
963    if (selected) {
964        actual_aligner_elem = ED4_ROOT->selected_objects.first();
965    }
966    else {
967        actual_aligner_elem = 0;
968    }
969
970    return get_next_selected_species();
971}
972
973struct AWTC_faligner_cd faligner_client_data =
974{
975 1,                             // default is to do a refresh
976 ED4_timer_refresh,             // with this function
977 get_group_consensus,           // aligner fetches consensus of group of species via this function
978 get_selected_range,            // aligner fetches column range of selection via this function
979 get_first_selected_species,    // aligner fetches first and..
980 get_next_selected_species,         // .. following selected species via this functions
981 0 // AW_helix (needed for island_hopping)
982 };
983
984static GB_ERROR ED4_delete_temp_entries(GBDATA *species, void **alignment_char_ptr)
985{
986    GB_CSTR alignment = (GB_CSTR)alignment_char_ptr;
987    GB_ERROR error = AWTC_delete_temp_entries(species, alignment);
988
989    return error;
990}
991
992void ED4_remove_faligner_entries(AW_window *, AW_CL, AW_CL) {
993    GB_ERROR error = GB_begin_transaction(GLOBAL_gb_main);
994    if (!error) error = ED4_with_all_loaded_species(ED4_delete_temp_entries, (void**)ED4_ROOT->alignment_name);
995    GB_end_transaction_show_error(GLOBAL_gb_main, error, aw_message);
996}
997
998void ED4_turnSpecies(AW_window *aw, AW_CL, AW_CL) {
999    GB_ERROR error = GB_begin_transaction(GLOBAL_gb_main);
1000
1001    if (!error) {
1002        AW_root *root       = aw->get_root();
1003        char    *name       = root->awar(AWAR_SPECIES_NAME)->read_string();
1004        char    *ali        = ED4_ROOT->alignment_name;
1005        GBDATA  *gb_species = GBT_expect_species(GLOBAL_gb_main, name);
1006        GBDATA  *gbd        = gb_species ? GBT_read_sequence(gb_species, ali) : NULL;
1007        char    *data       = gbd ? GB_read_string(gbd) : NULL;
1008
1009        if (!data) error = GB_await_error();
1010        else {
1011            long length = GB_read_string_count(gbd);
1012
1013            char T_or_U;
1014            error = GBT_determine_T_or_U(ED4_ROOT->alignment_type, &T_or_U, "reverse-complement");
1015            if (!error) {
1016                GBT_reverseComplementNucSequence(data, length, T_or_U);
1017                error = GB_write_string(gbd,data);
1018            }
1019        }
1020
1021        free(data);
1022        free(name);
1023    }
1024
1025    GB_end_transaction_show_error(GLOBAL_gb_main, error, aw_message);
1026}
1027
1028
1029#if defined(DEBUG) && 0
1030
1031void ED4_testSplitNMerge(AW_window *aw, AW_CL, AW_CL)
1032{
1033    AW_root *root = aw->get_root();
1034    char *name;
1035    GBDATA *species;
1036    GBDATA *gbd;
1037    char *data;
1038    long length;
1039
1040    GB_ERROR error = GB_begin_transaction(gb_main);
1041    char *ali = ED4_ROOT->alignment_name;
1042
1043    if (!error)
1044    {
1045        name = root->awar(AWAR_SPECIES_NAME)->read_string();
1046        species = GBT_find_species(gb_main, name);
1047        gbd = species ? GBT_read_sequence(species, ali) : NULL;
1048        data = gbd ? GB_read_string(gbd) : NULL;
1049        length = gbd ? GB_read_string_count(gbd) : NULL;
1050
1051        if (data)
1052        {
1053            char *newData = AWTC_testConstructSequence(data);
1054
1055            if (newData)
1056            {
1057                error = GB_write_string(gbd,newData);
1058                delete [] newData;
1059            }
1060        }
1061        else
1062        {
1063            error = GB_get_error();
1064            if (!error) error = GB_export_error("Can't read data of '%s'", name);
1065        }
1066
1067        delete name;
1068        delete data;
1069    }
1070
1071    GB_end_transaction_show_error(gb_main, error, aw_message);
1072}
1073
1074#endif
1075
1076static void col_stat_activated(AW_window *)
1077{
1078    ED4_ROOT->column_stat_initialized = 1;
1079    ED4_ROOT->column_stat_activated = 1;
1080    ED4_ROOT->refresh_all_windows(1);
1081}
1082
1083void ED4_activate_col_stat(AW_window *aww,AW_CL, AW_CL){
1084    if (!ED4_ROOT->column_stat_initialized) {
1085        AW_window *aww_st = st_create_main_window(ED4_ROOT->aw_root,ED4_ROOT->st_ml,(AW_CB0)col_stat_activated,(AW_window *)aww);
1086        aww_st->show();
1087        return;
1088    }
1089    else { // re-activate
1090        ED4_ROOT->column_stat_activated = 1;
1091        ED4_ROOT->refresh_all_windows(1);
1092    }
1093}
1094static void disable_col_stat(AW_window *, AW_CL, AW_CL) {
1095    if (ED4_ROOT->column_stat_initialized && ED4_ROOT->column_stat_activated) {
1096        ED4_ROOT->column_stat_activated = 0;
1097        ED4_ROOT->refresh_all_windows(1);
1098    }
1099}
1100
1101static void title_mode_changed(AW_root *aw_root, AW_window *aww)
1102{
1103    int title_mode = aw_root->awar(AWAR_EDIT_TITLE_MODE)->read_int();
1104
1105    if (title_mode==0) {
1106        aww->set_info_area_height(57);
1107    }
1108    else {
1109        aww->set_info_area_height(170);
1110    }
1111}
1112
1113// static void ED4_unfold_if_folded(AW_window *aww, AW_CL, AW_CL)
1114// {
1115//     AW_root *aw_root = ED4_ROOT->aw_root;
1116//     int title_mode = aw_root->awar(AWAR_EDIT_TITLE_MODE)->read_int();
1117
1118//     if (title_mode==0) {
1119//  aw_root->awar(AWAR_EDIT_TITLE_MODE)->write_int(1);
1120//  title_mode_changed(aw_root, aww);
1121//     }
1122// }
1123
1124void ED4_undo_redo(AW_window*, AW_CL undo_type)
1125{
1126    GB_ERROR error = GB_undo(GLOBAL_gb_main,(GB_UNDO_TYPE)undo_type);
1127
1128    if (error) {
1129        aw_message(error);
1130    }
1131    else {
1132        GB_begin_transaction(GLOBAL_gb_main);
1133        GB_commit_transaction(GLOBAL_gb_main);
1134        ED4_cursor *cursor = &ED4_ROOT->get_ed4w()->cursor;
1135        if (cursor->owner_of_cursor) {
1136            ED4_terminal *terminal = cursor->owner_of_cursor->to_terminal();
1137
1138            terminal->set_refresh();
1139            terminal->parent->refresh_requested_by_child();
1140        }
1141        //  aed_expose(aw,cd1,0);
1142    }
1143}
1144
1145void aw_clear_message_cb(AW_window *aww);
1146
1147void ED4_clear_errors(AW_window*, AW_CL)
1148{
1149    //    ED4_ROOT->aw_root->awar(AWAR_ERROR_MESSAGES)->write_string("");
1150    aw_clear_message_cb(ED4_ROOT->get_aww());
1151}
1152
1153AW_window *ED4_zoom_message_window(AW_root *root, AW_CL)
1154{
1155    AW_window_simple *aws = new AW_window_simple;
1156
1157    aws->init(root, "ZOOM_ERR_MSG", "Errors and warnings");
1158    aws->load_xfig("edit4/message.fig");
1159
1160    aws->callback((AW_CB0)AW_POPDOWN);
1161    aws->at("hide");
1162    aws->create_button("HIDE", "HIDE");
1163
1164    aws->callback(ED4_clear_errors, (AW_CL)0);
1165    aws->at("clear");
1166    aws->create_button("CLEAR", "CLEAR");
1167
1168    aws->at("errortext");
1169    aws->create_text_field(AWAR_ERROR_MESSAGES);
1170
1171    return (AW_window *)aws;
1172}
1173
1174
1175char *cat(char *toBuf, const char *s1, const char *s2)
1176{
1177    char *buf = toBuf;
1178
1179    while ((*buf++=*s1++)!=0) ;
1180    buf--;
1181    while ((*buf++=*s2++)!=0) ;
1182
1183    return toBuf;
1184}
1185
1186static void insert_search_fields(AW_window_menu_modes *awmm,
1187                                 const char *label_prefix, const char *macro_prefix,
1188                                 const char *pattern_awar_name, ED4_SearchPositionType type, const char *show_awar_name,
1189                                 int short_form)
1190{
1191    char buf[200];
1192
1193    if (!short_form) {
1194        awmm->at(cat(buf, label_prefix, "search"));
1195        awmm->create_input_field(pattern_awar_name, 30);
1196    }
1197
1198    awmm->at(cat(buf, label_prefix, "n"));
1199    awmm->callback(ED4_search, ED4_encodeSearchDescriptor(+1, type));
1200    awmm->create_button(cat(buf, macro_prefix, "_SEARCH_NEXT"), "#edit/next.bitmap");
1201
1202    awmm->at(cat(buf, label_prefix, "l"));
1203    awmm->callback(ED4_search, ED4_encodeSearchDescriptor(-1, type));
1204    awmm->create_button(cat(buf, macro_prefix, "_SEARCH_LAST"), "#edit/last.bitmap");
1205
1206    awmm->at(cat(buf, label_prefix, "d"));
1207    awmm->callback(AW_POPUP, (AW_CL)ED4_create_search_window, (AW_CL)type);
1208    awmm->create_button(cat(buf, macro_prefix, "_SEARCH_DETAIL"), "#edit/detail.bitmap");
1209
1210    awmm->at(cat(buf, label_prefix, "s"));
1211    awmm->create_toggle(show_awar_name);
1212}
1213
1214void ED4_set_protection(AW_window */*aww*/, AW_CL cd1, AW_CL /*cd2*/) {
1215    ED4_cursor *cursor = &ED4_ROOT->get_ed4w()->cursor;
1216    GB_ERROR    error  = 0;
1217
1218    if (cursor->owner_of_cursor) {
1219        int                         wanted_protection = int(cd1);
1220        ED4_sequence_terminal      *seq_term          = cursor->owner_of_cursor->to_sequence_terminal();
1221        ED4_sequence_info_terminal *seq_info_term     = seq_term->parent->search_spec_child_rek(ED4_L_SEQUENCE_INFO)->to_sequence_info_terminal();
1222        GBDATA                     *gbd               = seq_info_term->data();
1223
1224        GB_push_transaction(gbd);
1225
1226        GB_push_my_security(gbd);
1227        error = GB_write_security_write(gbd, wanted_protection);
1228        GB_pop_my_security(gbd);
1229
1230        error = GB_end_transaction(gbd, error);
1231    }
1232    else {
1233        error = "No species selected";
1234    }
1235
1236    if (error) aw_message(error);
1237}
1238
1239typedef enum {
1240    ED4_MS_NONE,
1241    ED4_MS_ALL,
1242    ED4_MS_INVERT,
1243    ED4_MS_INVERT_GROUP,
1244    ED4_MS_UNMARK_ALL,
1245    ED4_MS_MARK_SELECTED,
1246    ED4_MS_UNMARK_SELECTED,
1247    ED4_MS_SELECT_MARKED,
1248    ED4_MS_DESELECT_MARKED,
1249    ED4_MS_TOGGLE_BLOCKTYPE
1250
1251} MenuSelectType;
1252
1253static void ED4_menu_select(AW_window *aww, AW_CL type,AW_CL) {
1254    GB_transaction dummy(GLOBAL_gb_main);
1255    MenuSelectType select = MenuSelectType(type);
1256    ED4_multi_species_manager *middle_multi_man = ED4_ROOT->middle_area_man->get_defined_level(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
1257
1258    e4_assert(middle_multi_man);
1259
1260    switch(select) {
1261        case ED4_MS_NONE: {
1262            if (ED4_getBlocktype()!=ED4_BT_NOBLOCK) {
1263                ED4_ROOT->deselect_all();
1264                ED4_setBlocktype(ED4_BT_NOBLOCK);
1265            }
1266            break;
1267        }
1268        case ED4_MS_ALL: {
1269            middle_multi_man->select_all_species();
1270            ED4_correctBlocktypeAfterSelection();
1271            break;
1272        }
1273        case ED4_MS_INVERT: {
1274            middle_multi_man->invert_selection_of_all_species();
1275            ED4_correctBlocktypeAfterSelection();
1276            break;
1277        }
1278        case ED4_MS_SELECT_MARKED: {
1279            middle_multi_man->select_marked_species(1);
1280            ED4_correctBlocktypeAfterSelection();
1281            break;
1282        }
1283        case ED4_MS_DESELECT_MARKED: {
1284            middle_multi_man->select_marked_species(0);
1285            ED4_correctBlocktypeAfterSelection();
1286            break;
1287        }
1288        case ED4_MS_UNMARK_ALL: {
1289            GBT_mark_all(GLOBAL_gb_main, 0);
1290            break;
1291        }
1292        case ED4_MS_MARK_SELECTED: {
1293            middle_multi_man->mark_selected_species(1);
1294            ED4_correctBlocktypeAfterSelection();
1295            break;
1296        }
1297        case ED4_MS_UNMARK_SELECTED: {
1298            middle_multi_man->mark_selected_species(0);
1299            ED4_correctBlocktypeAfterSelection();
1300            break;
1301        }
1302        case ED4_MS_INVERT_GROUP: {
1303            ED4_cursor *cursor = &ED4_ROOT->first_window->get_matching_ed4w(aww)->cursor;
1304            int done = 0;
1305
1306            if (cursor->owner_of_cursor) {
1307                ED4_multi_species_manager *multi_man = cursor->owner_of_cursor->get_parent(ED4_L_MULTI_SPECIES)->to_multi_species_manager();
1308
1309                multi_man->invert_selection_of_all_species();
1310                ED4_correctBlocktypeAfterSelection();
1311                done = 1;
1312            }
1313
1314            if (!done) {
1315                aw_message("Place cursor into group");
1316            }
1317            break;
1318        }
1319        case ED4_MS_TOGGLE_BLOCKTYPE: {
1320            ED4_toggle_block_type();
1321            break;
1322        }
1323        default: {
1324            e4_assert(0);
1325            break;
1326        }
1327    }
1328
1329    ED4_refresh_window(aww, 1, 0);
1330}
1331
1332void ED4_menu_perform_block_operation(AW_window*, AW_CL type, AW_CL) {
1333    ED4_perform_block_operation(ED4_blockoperation_type(type));
1334}
1335
1336static void modes_cb(AW_window*, AW_CL cd1, AW_CL)
1337{
1338    ED4_ROOT->species_mode = ED4_species_mode(cd1);
1339}
1340void ED4_no_dangerous_modes(void)
1341{
1342    switch (ED4_ROOT->species_mode) {
1343        case ED4_SM_KILL: {
1344            ED4_ROOT->species_mode = ED4_SM_MOVE;
1345            ED4_ROOT->get_aww()->select_mode(0);
1346            break;
1347        }
1348        default: {
1349            break;
1350        }
1351    }
1352}
1353
1354void ED4_init_faligner_data(AWTC_faligner_cd *faligner_data) {
1355    GB_ERROR  error          = GB_push_transaction(GLOBAL_gb_main);
1356    char     *alignment_name = GBT_get_default_alignment(GLOBAL_gb_main);
1357    long      alilen         = GBT_get_alignment_len(GLOBAL_gb_main, alignment_name);
1358
1359    if (alilen<=0) error = GB_await_error();
1360    else {
1361        char   *helix_string = 0;
1362        char   *helix_name   = GBT_get_default_helix(GLOBAL_gb_main);
1363        GBDATA *gb_helix_con = GBT_find_SAI(GLOBAL_gb_main, helix_name);
1364        if (gb_helix_con) {
1365            GBDATA *gb_helix = GBT_read_sequence(gb_helix_con, alignment_name);
1366            if (gb_helix) helix_string = GB_read_string(gb_helix);
1367        }
1368        free(helix_name);
1369        freeset(faligner_data->helix_string, helix_string);
1370    }
1371
1372    free(alignment_name);
1373    error = GB_end_transaction(GLOBAL_gb_main, error);
1374    if (error) aw_message(error);
1375}
1376
1377static void ED4_create_faligner_window(AW_root *awr, AW_CL cd) {
1378    ED4_init_faligner_data((AWTC_faligner_cd*)cd);
1379    AWTC_create_faligner_window(awr, cd);
1380}
1381
1382static void ED4_save_defaults(AW_window *aw, AW_CL cl_mode, AW_CL) {
1383    int mode = (int)cl_mode;
1384
1385    AW_save_specific_defaults(aw, ED4_propertyName(mode));
1386}
1387
1388static AW_window *ED4_create_gc_window(AW_root *aw_root, AW_gc_manager id) {
1389    static AW_window *gc_win = 0;
1390    if (!gc_win) {
1391        gc_win = AW_create_gc_window(aw_root, id);
1392    }
1393    return gc_win;
1394}
1395
1396ED4_returncode ED4_root::generate_window( AW_device **device,   ED4_window **new_window)
1397{
1398    AW_window_menu_modes *awmm;
1399
1400    {
1401        ED4_window *ed4w = first_window;
1402
1403        while (ed4w) { // before creating a window look for a hidden window
1404            if (ed4w->is_hidden) {
1405                ed4w->aww->show();
1406                ed4w->is_hidden = false;
1407                return ED4_R_BREAK;
1408            }
1409            ed4w = ed4w->next;
1410        }
1411    }
1412
1413    if (ED4_window::no_of_windows == MAXWINDOWS)                            // no more then 5 windows allowed
1414    {
1415        aw_message(GBS_global_string("Restricted to %i windows", MAXWINDOWS));
1416        return ED4_R_BREAK;
1417    }
1418
1419    awmm = new AW_window_menu_modes;
1420    {
1421        int   len = strlen(alignment_name)+35;
1422        char *buf = GB_give_buffer(len);
1423        snprintf(buf, len-1, "ARB_EDIT4 *%d* [%s]", ED4_window::no_of_windows+1, alignment_name);
1424        awmm->init( aw_root, "ARB_EDIT4", buf, 800,450);
1425    }
1426
1427    *device     = awmm->get_device(AW_MIDDLE_AREA); // points to Middle Area device
1428    *new_window = ED4_window::insert_window( awmm ); // append to window list
1429
1430    e4_assert(ED4_window::no_of_windows >= 1);
1431    bool clone = ED4_window::no_of_windows>1;
1432    if (!clone) {                                   // this is the first window
1433        AW_init_color_group_defaults("arb_edit4");
1434    }
1435    else { // additional edit windows
1436        copy_window_struct( first_window, *new_window );
1437    }
1438
1439    // each window has its own gc-manager
1440    aw_gc_manager = AW_manage_GC(awmm,              // window
1441                                 *device,           // device-handle of window
1442                                 ED4_G_STANDARD,    // GC_Standard configuration
1443                                 ED4_G_DRAG,
1444                                 AW_GCM_DATA_AREA,
1445                                 ED4_expose_cb,     // callback function
1446                                 1,                 // AW_CL for callback function
1447                                 0,                 // AW_CL for callback function
1448                                 true,              // use color groups
1449
1450                                 "#f8f8f8",
1451                                 "STANDARD$black",  // Standard Color showing sequences
1452                                 "#SEQUENCES (0)$#505050", // default color for sequences (color 0)
1453                                 "+-HELIX (1)$#8E0000",  "+-COLOR 2$#0000dd",    "-COLOR 3$#00AA55",
1454                                 "+-COLOR 4$#80f",       "+-COLOR 5$#c0a020",    "-COLOR 6$grey",
1455                                 "+-COLOR 7$#ff0000",    "+-COLOR 8$#44aaff",    "-COLOR 9$#ffaa00",
1456
1457                                 "+-RANGE 0$#FFFFFF",    "+-RANGE 1$#F0F0F0",    "-RANGE 2$#E0E0E0",
1458                                 "+-RANGE 3$#D8D8D8",    "+-RANGE 4$#D0D0D0",    "-RANGE 5$#C8C8C8",
1459                                 "+-RANGE 6$#C0C0C0",    "+-RANGE 7$#B8B8B8",    "-RANGE 8$#B0B0B0",
1460                                 "-RANGE 9$#A0A0A0",
1461
1462                                 // colors used to Paint search patterns
1463                                 // (do not change the names of these gcs)
1464                                 "+-User1$#B8E2F8",      "+-User2$#B8E2F8",      "-Probe$#B8E2F8", // see also SEC_graphic::init_devices
1465                                 "+-Primer(l)$#A9FE54",  "+-Primer(r)$#A9FE54",  "-Primer(g)$#A9FE54",
1466                                 "+-Sig(l)$#DBB0FF",     "+-Sig(r)$#DBB0FF",     "-Sig(g)$#DBB0FF",
1467
1468                                 "+-MISMATCHES$#FF9AFF", "-CURSOR$#FF0080",
1469                                 "+-MARKED$#f4f8e0",     "-SELECTED$#FFFF80",
1470
1471                                 NULL);
1472
1473    // since the gc-managers of all EDIT4-windows point to the same window properties,
1474    // changing fonts and colors is always done on first gc-manager
1475    static AW_gc_manager first_gc_manager = 0;
1476    if (!first_gc_manager) first_gc_manager = aw_gc_manager;
1477
1478#define SEP________________________SEP awmm->insert_separator()
1479
1480    // ------------------------------
1481    //  File
1482    // ------------------------------
1483
1484#if defined(DEBUG)
1485    AWT_create_debug_menu(awmm);
1486#endif // DEBUG
1487
1488    awmm->create_menu("File", "F", "No Help", AWM_ALL );
1489
1490    awmm->insert_menu_topic("new_win",        "New Editor Window",     "W", 0, AWM_ALL, ED4_new_editor_window,         0,                                             0)   ;
1491    awmm->insert_menu_topic("save_config",    "Save Configuration",    "S", 0, AWM_ALL, (AW_CB)ED4_save_configuration, (AW_CL) 0,                                     (int)0 );
1492    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 );
1493    SEP________________________SEP;
1494    awmm->insert_menu_topic("load_config",   "Load Configuration",   "L", 0, AWM_ALL, AW_POPUP,           (AW_CL)ED4_start_editor_on_old_configuration, 0);
1495    awmm->insert_menu_topic("reload_config", "Reload Configuration", "R", 0, AWM_ALL, ED4_restart_editor, 0,                                            0);
1496    SEP________________________SEP;
1497    GDE_load_menu(awmm,AWM_ALL,"Print");
1498    SEP________________________SEP;
1499
1500    if (clone) awmm->insert_menu_topic( "close", "CLOSE", "C", 0, AWM_ALL, ED4_quit_editor, 0, 0);
1501    else       awmm->insert_menu_topic( "quit",  "QUIT",  "Q", 0, AWM_ALL, ED4_quit_editor, 0, 0);
1502   
1503    // ------------------------------
1504    //  Create
1505    // ------------------------------
1506
1507    awmm->create_menu("Create", "C", 0, AWM_ALL);
1508    awmm->insert_menu_topic("create_species",                "Create new species",                "n", 0, AWM_ALL, AW_POPUP, (AW_CL)ED4_create_new_seq_window, (int)0);
1509    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);
1510    awmm->insert_menu_topic("copy_species",                  "Copy current species",              "C", 0, AWM_ALL, AW_POPUP, (AW_CL)ED4_create_new_seq_window, (int)2);
1511    SEP________________________SEP;
1512    awmm->insert_menu_topic("create_group",           "Create new Group",              "G", 0, AWM_ALL, group_species_cb, 0, 0);
1513    awmm->insert_menu_topic("create_groups_by_field", "Create new groups using Field", "F", 0, AWM_ALL, group_species_cb, 1, 0);
1514
1515    // ------------------------------
1516    //  Edit
1517    // ------------------------------
1518
1519    awmm->create_menu( "Edit", "E", 0, AWM_ALL);
1520    awmm->insert_menu_topic("refresh",     "Refresh [Ctrl-L]",           "f",  0, AWM_ALL, ED4_refresh_window,                   1, 0);
1521    awmm->insert_menu_topic("load_actual", "Load current species [GET]", "G", 0, AWM_ALL, ED4_get_and_jump_to_actual_from_menu, 0, 0);
1522    awmm->insert_menu_topic("load_marked", "Load marked species",        "m", 0, AWM_ALL, ED4_get_marked_from_menu,             0, 0);
1523    SEP________________________SEP;
1524    awmm->insert_menu_topic("refresh_ecoli",       "Reload Ecoli sequence",        "E", 0, AWM_ALL, ED4_reload_ecoli_cb,     0, 0);
1525    awmm->insert_menu_topic("refresh_helix",       "Reload Helix",                 "H", 0, AWM_ALL, ED4_reload_helix_cb,     0, 0);
1526    awmm->insert_menu_topic("helix_jump_opposite", "Jump helix opposite [Ctrl-J]", "J", 0, AWM_ALL, ED4_helix_jump_opposite, 0, 0);
1527    SEP________________________SEP;
1528
1529    awmm->insert_sub_menu("Set protection of current ", "p");
1530    {
1531        char macro[] = "to_0",
1532            topic[] = ".. to 0",
1533            hotkey[] = "0";
1534
1535        for (char i='0'; i<='6'; i++) {
1536            macro[3] = topic[6] = hotkey[0] = i;
1537            awmm->insert_menu_topic(macro, topic, hotkey, 0, AWM_ALL, ED4_set_protection, AW_CL(i-'0'), 0);
1538        }
1539    }
1540    awmm->close_sub_menu();
1541
1542#if !defined(NDEBUG) && 0
1543    awmm->insert_menu_topic("turn_sequence", "Turn Sequence",             "T", 0, AWM_ALL, ED4_turnSpecies,     1, 0);
1544    awmm->insert_menu_topic(0,               "Test (test split & merge)", "T", 0, AWM_ALL, ED4_testSplitNMerge, 1, 0);
1545#endif
1546    SEP________________________SEP;
1547    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);
1548    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);
1549    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);
1550    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);
1551    awmm->insert_menu_topic("del_ali_tmp",        "Remove all aligner Entries",          "v", 0,                  AWM_ALL,            ED4_remove_faligner_entries,            1,                                 0);
1552    SEP________________________SEP;
1553    awmm->insert_menu_topic("missing_bases", "Dot potentially missing bases", "D", "missbase.hlp", AWM_EXP, ED4_popup_dot_missing_bases_window, 0, 0);
1554    SEP________________________SEP;
1555    awmm->insert_menu_topic("sec_edit", "Edit secondary structure", "c", 0, AWM_ALL, ED4_SECEDIT_start, (AW_CL)GLOBAL_gb_main, 0);
1556
1557    // ------------------------------
1558    //  View
1559    // ------------------------------
1560
1561    awmm->create_menu("View", "V", 0, AWM_ALL);
1562    awmm->insert_sub_menu("Search", "S");
1563    {
1564        int         s;
1565        const char *hotkeys  = "12Poiclrg";
1566        char        hotkey[] = "_";
1567
1568        e4_assert(strlen(hotkeys) == SEARCH_PATTERNS);
1569
1570        for (s=0; s<SEARCH_PATTERNS; s++) {
1571            ED4_SearchPositionType type = ED4_SearchPositionType(s);
1572            const char *id = ED4_SearchPositionTypeId[type];
1573            int len = strlen(id);
1574            char *macro_name = GB_give_buffer(2*(len+8));
1575            char *menu_entry_name = macro_name+(len+8);
1576
1577#ifndef NDEBUG
1578            memset(macro_name, 0, 2*(len+8)); // to avoid memchk-warning
1579#endif
1580            sprintf(macro_name, "%s_SEARCH", id);
1581            char *p = macro_name;
1582            while (1) {
1583                char c = *p++;
1584                if (!c) break;
1585                p[-1] = toupper(c);
1586            }
1587            sprintf(menu_entry_name, "%s Search", id);
1588
1589            hotkey[0] = hotkeys[s];
1590            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));
1591        }
1592    }
1593    awmm->close_sub_menu();
1594    SEP________________________SEP;
1595    awmm->insert_sub_menu("Cursor position ", "p");
1596    awmm->insert_menu_topic("store_curpos",   "Store cursor position",    "S", 0, AWM_ALL, ED4_store_curpos,        0, 0);
1597    awmm->insert_menu_topic("restore_curpos", "Restore cursor position ", "R", 0, AWM_ALL, ED4_restore_curpos,      0, 0);
1598    awmm->insert_menu_topic("clear_curpos",   "Clear stored positions",   "C", 0, AWM_ALL, ED4_clear_stored_curpos, 0, 0);
1599    awmm->close_sub_menu();
1600
1601    SEP________________________SEP;
1602    awmm->insert_menu_topic("change_cursor", "Change cursor type",                "t", 0,                   AWM_ALL, ED4_change_cursor,         0, 0);
1603    awmm->insert_menu_topic("show_all",      "Show all bases ",                   "a", "set_reference.hlp", AWM_ALL, ED4_set_reference_species, 1, 0);
1604    awmm->insert_menu_topic("show_diff",     "Show only differences to selected", "d", "set_reference.hlp", AWM_ALL, ED4_set_reference_species, 0, 0);
1605    SEP________________________SEP;
1606    awmm->insert_menu_topic("enable_col_stat",  "Activate column statistics", "v", "st_ml.hlp", AWM_EXP, ED4_activate_col_stat,          0, 0);
1607    awmm->insert_menu_topic("disable_col_stat", "Disable column statistics",  "i", "st_ml.hlp", AWM_EXP, disable_col_stat,               0, 0);
1608    awmm->insert_menu_topic("detail_col_stat",  "Detailed column statistics", "c", "st_ml.hlp", AWM_EXP, ED4_show_detailed_column_stats, 0, 0);
1609    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);
1610    SEP________________________SEP;
1611    awmm->insert_menu_topic( "visualize_SAI", "Visualize SAIs", "z", "visualizeSAI.hlp", AWM_ALL,AW_POPUP,(AW_CL)ED4_createVisualizeSAI_window, 0 );
1612    // Enable ProteinViewer only for DNA sequence type
1613    if (alignment_type == GB_AT_DNA) {
1614        awmm->insert_menu_topic( "Protein_Viewer", "Protein Viewer", "w", "proteinViewer.hlp", AWM_ALL,AW_POPUP,(AW_CL)ED4_CreateProteinViewer_window, 0 );
1615    }
1616
1617    // ------------------------------
1618    //  Block
1619    // ------------------------------
1620
1621    awmm->create_menu("Block", "B", 0, AWM_ALL);
1622
1623    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);
1624    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);
1625    awmm->insert_menu_topic("select_all",      "Select all species",      "S", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_ALL)            , 0);
1626    awmm->insert_menu_topic("deselect_all",    "Deselect all species",    "D", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_NONE)           , 0);
1627    SEP________________________SEP;
1628    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);
1629    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);
1630    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);
1631    SEP________________________SEP;
1632    awmm->insert_menu_topic("invert_all",   "Invert selected species", "I", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_INVERT)      , 0);
1633    awmm->insert_menu_topic("invert_group", "Invert group",            "g", "e4_block.hlp", AWM_ALL, ED4_menu_select, AW_CL(ED4_MS_INVERT_GROUP), 0);
1634    SEP________________________SEP;
1635    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);
1636    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);
1637    SEP________________________SEP;
1638    awmm->insert_menu_topic("reverse",            "Reverse selection ",    "v", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_REVERSE)           , 0);
1639    awmm->insert_menu_topic("complement",         "Complement selection ", "o", "e4_block.hlp", AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_COMPLEMENT)        , 0);
1640    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);
1641    SEP________________________SEP;
1642    awmm->insert_menu_topic("unalignBlockLeft",  "Unalign block",       "a", "e4_block.hlp",   AWM_ALL, ED4_menu_perform_block_operation, AW_CL(ED4_BO_UNALIGN)      ,                          0);
1643    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);
1644    awmm->insert_menu_topic("replace",           "Search & Replace ",   "h", "e4_replace.hlp", AWM_ALL, AW_POPUP,                              (AW_CL)               ED4_create_replace_window, 0);
1645    SEP________________________SEP;
1646    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);
1647    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);
1648    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);
1649
1650    // ------------------------------
1651    //  Properties
1652    // ------------------------------
1653
1654    awmm->create_menu("Properties",   "P", "Select something",    AWM_ALL);
1655   
1656    awmm->insert_menu_topic("props_frame",     "Frame Settings ",       "F", 0,                  AWM_ALL, AW_POPUP, (AW_CL)AW_preset_window,                       0);
1657    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);
1658    awmm->insert_menu_topic("props_consensus", "Consensus Definition ", "u", "e4_consensus.hlp", AWM_ALL, AW_POPUP, (AW_CL)ED4_create_consensus_definition_window, 0);
1659    SEP________________________SEP;
1660
1661    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);
1662    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);
1663
1664    SEP________________________SEP;
1665
1666    static AW_cb_struct *expose_cb = 0;
1667    if (!expose_cb) expose_cb = new AW_cb_struct(awmm, (AW_CB)ED4_expose_cb, 0, 0);
1668
1669    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);
1670    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);
1671
1672    awmm->insert_menu_topic("props_key_map", "Key Mappings ",              "K", "nekey_map.hlp", AWM_ALL, AW_POPUP, (AW_CL)create_key_map_window, 0);
1673    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);
1674    SEP________________________SEP;
1675    awmm->insert_sub_menu("Save properties ...", "a");
1676    {
1677        static const char * const tag[] = { "save_alispecific_props", "save_alitype_props", "save_props" };
1678        static const char * const entry_type[] = { "alignment specific ", "ali-type specific ", "" };
1679
1680        // check what is the default mode
1681        int default_mode = -1;
1682        for (int mode = 0; mode <= 2; ++mode) {
1683            if (0 == strcmp(ED4_propertyName(mode), db_name)) {
1684                default_mode = mode;
1685                break;
1686            }
1687        }
1688
1689        const char *entry = GBS_global_string("Save loaded Properties (~/%s)", db_name);
1690        awmm->insert_menu_topic("save_loaded_props", entry, "l", "e4_defaults.hlp", AWM_ALL, ED4_save_defaults, (AW_CL)default_mode, 0);
1691        SEP________________________SEP;
1692
1693        for (int mode = 2; mode >= 0; --mode) {
1694            char hotkey[] = "x";
1695            hotkey[0]     = "Pta"[mode];
1696            entry         = GBS_global_string("Save %sProperties (~/%s)", entry_type[mode], ED4_propertyName(mode));
1697            awmm->insert_menu_topic(tag[mode], entry, hotkey, "e4_defaults.hlp", AWM_ALL, ED4_save_defaults, (AW_CL)mode, 0);
1698        }
1699    }
1700    awmm->close_sub_menu();
1701
1702    awmm->insert_help_topic("ARB_EDIT4 help",     "E", "e4.hlp", AWM_ALL, (AW_CB)AW_POPUP_HELP, (AW_CL)"e4.hlp", 0);
1703
1704    // ----------------------------------------------------------------------------------------------------
1705
1706#undef SEP________________________SEP
1707
1708    aw_root->awar_int(AWAR_EDIT_TITLE_MODE)->add_callback((AW_RCB1)title_mode_changed, (AW_CL)awmm);
1709    awmm->set_bottom_area_height( 0 ); //No bottom area
1710
1711    awmm->auto_space(5,-2);
1712    awmm->shadow_width(3);
1713
1714    int db_pathx,db_pathy;
1715    awmm->get_at_position( &db_pathx,&db_pathy );
1716
1717    awmm->shadow_width(1);
1718    awmm->load_xfig("edit4/editmenu.fig", false);
1719
1720    // -------------------------
1721    //      help /quit /fold
1722    // -------------------------
1723
1724    awmm->button_length(0);
1725
1726    awmm->at("quit");
1727    awmm->callback(ED4_quit_editor, 0, 0);
1728    awmm->help_text("quit.hlp");
1729
1730    if (clone) awmm->create_button("CLOSE","#close.xpm");
1731    else       awmm->create_button("QUIT","#quit.xpm");
1732   
1733    awmm->at("help");
1734    awmm->callback(AW_help_entry_pressed);
1735    awmm->help_text("e4.hlp");
1736    awmm->create_button("HELP","#help.xpm");
1737
1738    awmm->at("fold");
1739    awmm->help_text("e4.hlp");
1740    awmm->create_toggle(AWAR_EDIT_TITLE_MODE, "#more.bitmap", "#less.bitmap");
1741
1742    // ------------------
1743    //      positions
1744    // ------------------
1745   
1746    awmm->button_length(0);
1747   
1748    awmm->at("posTxt");     awmm->create_button(0, "Position");
1749
1750    awmm->button_length(6+1);
1751   
1752    awmm->at("ecoliTxt");   awmm->create_button(0, ED4_AWAR_NDS_ECOLI_NAME, 0, "+");
1753
1754    awmm->button_length(0);
1755   
1756    awmm->at("baseTxt");    awmm->create_button(0, "Base");
1757    awmm->at("iupacTxt");   awmm->create_button(0, "IUPAC");
1758    awmm->at("helixnrTxt"); awmm->create_button(0, "Helix#");
1759
1760    awmm->at("pos");
1761    awmm->callback((AW_CB)ED4_jump_to_cursor_position, (AW_CL) get_ed4w()->awar_path_for_cursor, AW_CL(1));
1762    awmm->create_input_field(get_ed4w()->awar_path_for_cursor,7);
1763
1764    awmm->at("ecoli");
1765    awmm->callback((AW_CB)ED4_jump_to_cursor_position,(AW_CL) get_ed4w()->awar_path_for_Ecoli, AW_CL(0));
1766    awmm->create_input_field(get_ed4w()->awar_path_for_Ecoli,6);
1767
1768    awmm->at("base");
1769    awmm->callback((AW_CB)ED4_jump_to_cursor_position,(AW_CL) get_ed4w()->awar_path_for_basePos, AW_CL(0));
1770    awmm->create_input_field(get_ed4w()->awar_path_for_basePos,6);
1771
1772    awmm->at("iupac");
1773    awmm->callback((AW_CB)ED4_set_iupac,(AW_CL) get_ed4w()->awar_path_for_IUPAC, AW_CL(0));
1774    awmm->create_input_field(get_ed4w()->awar_path_for_IUPAC,4);
1775
1776    awmm->at("helixnr");
1777    awmm->callback((AW_CB)ED4_set_helixnr,(AW_CL) get_ed4w()->awar_path_for_helixNr, AW_CL(0));
1778    awmm->create_input_field(get_ed4w()->awar_path_for_helixNr,5);
1779
1780    // ---------------------------
1781    //      jump/get/undo/redo
1782    // ---------------------------
1783
1784    awmm->button_length(4);
1785   
1786    awmm->at("jump");
1787    awmm->callback(ED4_jump_to_current_species, 0);
1788    awmm->help_text("e4.hlp");
1789    awmm->create_button("JUMP", "Jump");
1790
1791    awmm->at("get");
1792    awmm->callback(ED4_get_and_jump_to_actual, 0);
1793    awmm->help_text("e4.hlp");
1794    awmm->create_button("GET", "Get");
1795
1796    awmm->button_length(0);
1797   
1798    awmm->at("undo");
1799    awmm->callback(ED4_undo_redo, GB_UNDO_UNDO);
1800    awmm->help_text("undo.hlp");
1801    awmm->create_button("UNDO", "#undo.bitmap");
1802
1803    awmm->at("redo");
1804    awmm->callback(ED4_undo_redo, GB_UNDO_REDO);
1805    awmm->help_text("undo.hlp");
1806    awmm->create_button("REDO", "#redo.bitmap");
1807
1808    // -------------------------
1809    //      aligner / SAIviz
1810    // -------------------------
1811   
1812    awmm->button_length(7);
1813   
1814    awmm->at("aligner");
1815    awmm->callback(AW_POPUP, (AW_CL)ED4_create_faligner_window, (AW_CL)&faligner_client_data);
1816    awmm->help_text("faligner.hlp");
1817    awmm->create_button("ALIGNER", "Aligner");
1818
1819    awmm->at("saiviz");
1820    awmm->callback(AW_POPUP,(AW_CL)ED4_createVisualizeSAI_window, 0 );
1821    awmm->help_text("visualizeSAI.hlp");
1822    awmm->create_button("SAIVIZ", "SAIviz");
1823
1824    // ------------------------------------------
1825    //      align/insert/protection/direction
1826    // ------------------------------------------
1827
1828    awmm->button_length(0);
1829   
1830    awmm->at("protect");
1831    awmm->create_option_menu(AWAR_EDIT_SECURITY_LEVEL);
1832    awmm->insert_option("0",0,0);
1833    awmm->insert_option("1",0,1);
1834    awmm->insert_option("2",0,2);
1835    awmm->insert_option("3",0,3);
1836    awmm->insert_option("4",0,4);
1837    awmm->insert_option("5",0,5);
1838    awmm->insert_default_option("6",0,6);
1839    awmm->update_option_menu();
1840
1841    // draw protection icon AFTER protection!!
1842    awmm->at("pico");
1843    awmm->create_button("PROTECT","#protect.xpm");
1844
1845    // draw align/edit-button AFTER protection!!
1846    awmm->at("edit");
1847    awmm->create_toggle(AWAR_EDIT_MODE, "#edit/align.xpm", "#edit/editseq.xpm", 7);
1848
1849    awmm->at("insert");
1850    awmm->create_text_toggle(AWAR_INSERT_MODE, "Replace", "Insert", 7);
1851
1852    awmm->at("direct");
1853    awmm->create_toggle(AWAR_EDIT_DIRECTION,"#edit/3to5.bitmap","#edit/5to3.bitmap", 7);
1854
1855    // ------------------------
1856    //      secedit / rna3d
1857    // ------------------------
1858
1859    int xoffset = 0;
1860
1861    // Enable RNA3D and SECEDIT programs if the database contains valid alignment of rRNA sequences.
1862    if (alignment_type == GB_AT_RNA) {
1863        awmm->button_length(0);
1864       
1865        awmm->at("secedit");
1866        awmm->callback(ED4_SECEDIT_start, (AW_CL)GLOBAL_gb_main, 0);
1867        awmm->help_text("arb_secedit.hlp");
1868        awmm->create_button("SECEDIT", "#edit/secedit.xpm");
1869       
1870#if defined(ARB_OPENGL)
1871        awmm->at("rna3d");
1872        awmm->callback(ED4_RNA3D_Start, 0, 0);
1873        awmm->help_text("rna3d_general.hlp");
1874        awmm->create_button("RNA3D", "#edit/rna3d.xpm");
1875#endif // ARB_OPENGL
1876    }
1877    else {
1878        awmm->at("secedit");
1879        int xsecedit = awmm->get_at_xposition();
1880        awmm->at("zoom");
1881        int xzoom    = awmm->get_at_xposition();
1882        xoffset      = xsecedit-xzoom; // shift message stuff to the left by xoffset
1883    }
1884
1885    {
1886        int x, y;
1887
1888        awmm->at("zoom");
1889        if (xoffset) { awmm->get_at_position(&x, &y); awmm->at(x+xoffset, y); }
1890        awmm->callback(AW_POPUP, (AW_CL)ED4_zoom_message_window, (AW_CL)0);
1891        awmm->create_button("ZOOM", "#edit/zoom.bitmap");
1892
1893        awmm->at("clear");
1894        if (xoffset) { awmm->get_at_position(&x, &y); awmm->at(x+xoffset, y); }
1895        awmm->callback(ED4_clear_errors, (AW_CL)0);
1896        awmm->create_button("CLEAR", "#edit/clear.bitmap");
1897
1898        awmm->at("errortext");
1899        if (xoffset) { awmm->get_at_position(&x, &y); awmm->at(x+xoffset, y); }
1900        aw_root->awar_string(AWAR_ERROR_MESSAGES, "This is ARB Edit4 [Build " ARB_VERSION "]");
1901        awmm->create_text_field(AWAR_ERROR_MESSAGES);
1902        aw_set_local_message();
1903    }
1904
1905    // --------------------
1906    //      'more' area
1907    // --------------------
1908
1909    awmm->at("cons");
1910    awmm->create_toggle(ED4_AWAR_CONSENSUS_SHOW, "#edit/nocons.bitmap", "#edit/cons.bitmap");
1911
1912    awmm->at("num");
1913    awmm->create_toggle(ED4_AWAR_DIGITS_AS_REPEAT, "#edit/norepeat.bitmap", "#edit/repeat.bitmap");
1914
1915    awmm->at("key");
1916    awmm->create_toggle("key_mapping/enable", "#edit/nokeymap.bitmap", "#edit/keymap.bitmap");
1917
1918    // search
1919   
1920    awmm->button_length(0);
1921#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)
1922
1923    INSERT_SEARCH_FIELDS(0, u1, USER1);
1924    INSERT_SEARCH_FIELDS(0, u2, USER2);
1925    INSERT_SEARCH_FIELDS(0, pro, PROBE);
1926    INSERT_SEARCH_FIELDS(1, pri1, PRIMER1);
1927    INSERT_SEARCH_FIELDS(1, pri2, PRIMER2);
1928    INSERT_SEARCH_FIELDS(1, pri3, PRIMER3);
1929    INSERT_SEARCH_FIELDS(1, sig1, SIG1);
1930    INSERT_SEARCH_FIELDS(1, sig2, SIG2);
1931    INSERT_SEARCH_FIELDS(1, sig3, SIG3);
1932
1933#undef INSERT_SEARCH_FIELDS
1934
1935    awmm->at("alast");
1936    awmm->callback(ED4_search, ED4_encodeSearchDescriptor(-1, ED4_ANY_PATTERN));
1937    awmm->create_button("ALL_SEARCH_LAST", "#edit/last.bitmap");
1938
1939    awmm->at("anext");
1940    awmm->callback(ED4_search, ED4_encodeSearchDescriptor(+1, ED4_ANY_PATTERN));
1941    awmm->create_button("ALL_SEARCH_NEXT", "#edit/next.bitmap");
1942
1943    title_mode_changed(aw_root, awmm);
1944
1945    // Buttons at left window border
1946
1947    awmm->create_mode("edit/arrow.bitmap", "normal.hlp", AWM_ALL, (AW_CB)modes_cb, (AW_CL)0, (AW_CL)0);
1948    awmm->create_mode("edit/kill.bitmap",  "kill.hlp",   AWM_ALL, (AW_CB)modes_cb, (AW_CL)1, (AW_CL)0);
1949    awmm->create_mode("edit/mark.bitmap",  "mark.hlp",   AWM_ALL, (AW_CB)modes_cb, (AW_CL)2, (AW_CL)0);
1950
1951    AWTC_create_faligner_variables(awmm->get_root(), db);
1952
1953    return ( ED4_R_OK );
1954}
1955
1956AW_window *ED4_root::create_new_window( void )                      // only the first time, other cases: generate_window
1957{
1958    AW_device  *device     = NULL;
1959    ED4_window *new_window = NULL;
1960
1961    generate_window( &device, &new_window );
1962
1963    ED4_calc_terminal_extentions();
1964
1965    last_window_reached     = 1;
1966    DRAW                    = 1;
1967    move_cursor             = 0;
1968    max_seq_terminal_length = 0;
1969
1970    ED4_init_notFoundMessage();
1971
1972    return ( new_window->aww );
1973}
1974
1975ED4_index ED4_root::pixel2pos(AW_pos click_x) {
1976    // 'click_x' is the x-offset into the terminal in pixels
1977    // returns the x-offset into the terminal in base positions (clipped to max. allowed position)
1978
1979    int       length_of_char = font_group.get_width(ED4_G_SEQUENCES);
1980    ED4_index scr_pos        = int((click_x-CHARACTEROFFSET) / length_of_char);
1981    int       max_scrpos     = root_group_man->remap()->get_max_screen_pos();
1982
1983    if (scr_pos>max_scrpos) scr_pos = max_scrpos;
1984
1985    return scr_pos;
1986}
1987
1988ED4_root::ED4_root()
1989{
1990    memset((char *)this,0,sizeof(*this));
1991
1992    aw_root      = new AW_root;
1993    first_window = NULL;
1994    main_manager = NULL;
1995    database     = NULL;
1996    tmp_ed4w     = NULL;
1997    tmp_aww      = NULL;
1998    tmp_device   = NULL;
1999    temp_gc      = 0;
2000
2001    scroll_links.link_for_hor_slider = NULL;
2002    scroll_links.link_for_ver_slider = NULL;
2003
2004    folding_action = 0;
2005   
2006    species_mode            = ED4_SM_MOVE;
2007    scroll_picture.scroll   = 0;
2008    scroll_picture.old_x    = 0;
2009    scroll_picture.old_y    = 0;
2010    middle_area_man         = NULL;
2011    top_area_man            = NULL;
2012    root_group_man          = NULL;
2013    ecoli_ref               = NULL;
2014    protstruct              = NULL;
2015    protstruct_len          = 0;
2016    column_stat_activated   = 0;
2017    column_stat_initialized = 0;
2018    visualizeSAI            = 0;
2019    visualizeSAI_allSpecies = 0;
2020
2021    aw_initstatus();
2022}
2023
2024
2025ED4_root::~ED4_root()
2026{
2027    delete aw_root;
2028    delete first_window;
2029    delete main_manager;
2030    delete middle_area_man;
2031    delete top_area_man;
2032    delete database;
2033    delete ecoli_ref;
2034    if (protstruct) free(protstruct);
2035}
2036
2037//***********************************
2038//* ED4_root Methods        end *
2039//***********************************
Note: See TracBrowser for help on using the repository browser.