source: tags/arb_5.0/SECEDIT/SEC_main.cxx

Last change on this file was 6123, checked in by westram, 15 years ago
  • changed color of close.xpm to blue (before it was identical to quit.xpm (=red))
  • use close.xpm in NTREE-clone
  • use quit.xpm in secedit
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.6 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : SEC_main.cxx                                      //
4//   Purpose   : main part of SECEDIT                              //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11
12#include <cstdio>
13
14#include <arbdb.h>
15#include <arbdbt.h>
16#include <aw_window.hxx>
17#include <aw_awars.hxx>
18#include <aw_preset.hxx>
19#include <awt.hxx>
20#include <ed4_extern.hxx>
21#include <FileBuffer.h>
22
23#include "SEC_root.hxx"
24#include "SEC_graphic.hxx"
25#include "SEC_helix.hxx"
26#include "SEC_drawn_pos.hxx"
27#include "SEC_toggle.hxx"
28
29#ifndef sec_assert // happens in NDEBUG mode
30#define sec_assert(cond) arb_assert(cond)
31#endif
32
33void SEC_root::invalidate_base_positions() {
34    if (root_loop) {
35        SEC_base_part *start_part = root_loop->get_fixpoint_strand();
36        SEC_base_part *part       = start_part;
37
38        do {
39            part->get_region()->invalidate_base_count();
40            part = part->next();
41        }
42        while (part != start_part);
43    }
44}
45
46// -----------------------------------------------------
47//      auto-scrolling (triggered by structure self)
48// -----------------------------------------------------
49
50void SEC_root::nail_position(size_t absPos) {
51    if (drawnPositions) {
52        nailedAbsPos = absPos;
53        drawnAbsPos  = *drawnPositions->drawn_at(absPos);
54    }
55}
56
57void SEC_root::nail_cursor() { // re-position on cursor
58    if (cursorAbsPos >= 0) {
59        if (drawnPositions && !drawnPositions->empty()) {
60            size_t abs;
61            drawnAbsPos  = drawnPositions->drawn_after(cursorAbsPos-1, &abs);
62            nailedAbsPos = abs;
63        }
64    }
65}
66
67void SEC_root::add_autoscroll(const Vector& scroll) {
68    if (autoscroll) *autoscroll += scroll;
69    else autoscroll              = new Vector(scroll);
70}
71
72bool SEC_root::perform_autoscroll() {
73    bool        scrolled = false;
74    AWT_canvas *canvas   = db->canvas();
75   
76    if (canvas && (nailedAbsPos != -1 || autoscroll)) {
77        AW_device *device = canvas->aww->get_device(AW_MIDDLE_AREA);
78
79        if (nailedAbsPos != -1) {
80            {
81                int     absPos = nailedAbsPos;
82                Vector *scroll = autoscroll;
83
84                // avoid endless recursion:
85                nailedAbsPos = -1;
86                autoscroll   = 0;
87
88#warning make the refresh invisible
89                canvas->refresh();
90
91                nailedAbsPos = absPos;
92                autoscroll   = scroll;
93            }
94            const Position *newPos = drawnPositions->drawn_at(nailedAbsPos);
95            if (newPos) {
96                Vector old2new(drawnAbsPos, *newPos);
97#if defined(DEBUG) && 0
98                printf("drawnAbsPos=%.2f/%.2f newPos=%.2f/%.2f old2new=%.2f/%.2f\n",
99                       drawnAbsPos.xpos(), drawnAbsPos.ypos(),
100                       newPos->xpos(), newPos->ypos(),
101                       old2new.x(), old2new.y());
102#endif // DEBUG
103                add_autoscroll(old2new);
104            }
105            nailedAbsPos = -1;
106        }
107        if (autoscroll) {
108            canvas->init_device(device); // loads correct zoom
109            Vector screen_scroll = device->transform(*autoscroll);
110
111#if defined(DEBUG) && 0
112            printf("autoscroll=%.2f/%.2f screen_scroll=%.2f/%.2f\n",
113                   autoscroll->x(), autoscroll->y(),
114                   screen_scroll.x(), screen_scroll.y());
115#endif // DEBUG
116
117            delete autoscroll;
118            autoscroll = 0;
119
120            device->clear(-1);
121            canvas->scroll(NULL, screen_scroll, false);
122            scrolled = true;
123        }
124    }
125    return scrolled;
126}
127// --------------------------------------------------------------------------------
128
129void SEC_root::position_cursor(bool toCenter, bool evenIfVisible) {
130    // centers the cursor in display (or scrolls it into view)
131    // if 'evenIfVisible' is true, always do it, otherwise only if not fully visible
132
133    const LineVector& cursorLine = get_last_drawed_cursor_position();
134    sec_assert(cursorLine.valid());
135
136    AWT_canvas *ntw    = db->canvas();
137    AW_device  *device = ntw->aww->get_device(AW_MIDDLE_AREA);
138   
139    Rectangle cursor(device->transform(cursorLine));
140    Rectangle screen = device->get_area_size();
141
142    if (evenIfVisible || !screen.contains(cursor)) {
143        if (!toCenter) {
144            if (perform_autoscroll()) {
145                cursor = Rectangle(device->transform(cursorLine));
146                if (!screen.contains(cursor)) {
147                    toCenter = true;
148                }
149            }
150            else { // if autoscroll didn't work
151                toCenter = true; // center cursor
152            }
153        }
154
155        if (toCenter) {
156            Vector scroll(cursor.centroid(), screen.centroid());
157
158#if defined(DEBUG) && 1
159            printf("Auto-scroll: scroll = (%f, %f) [Center cursor]\n", scroll.x(), scroll.y());
160#endif
161            ntw->scroll(NULL, -scroll, false);
162            ntw->refresh();
163        }
164    }
165}
166
167void SEC_toggle_cb(AW_window *, AW_CL cl_secroot, AW_CL) {
168    SEC_root               *root = (SEC_root*)cl_secroot;
169    const SEC_db_interface *db   = root->get_db();
170
171    GB_ERROR error = db->structure()->next();
172    if (error) aw_message(error);
173    db->canvas()->refresh();
174}
175
176void SEC_center_cb(AW_window *, AW_CL cl_secroot, AW_CL) {
177    SEC_root *root = (SEC_root*)cl_secroot;
178    root->position_cursor(true, true);
179}
180
181static void SEC_fit_window_cb(AW_window */*aw*/, AW_CL cl_secroot, AW_CL) {
182    SEC_root               *root = (SEC_root*)cl_secroot;
183    const SEC_db_interface *db   = root->get_db();
184
185    db->graphic()->request_update(SEC_UPDATE_ZOOM_RESET);
186    db->canvas()->refresh();
187}
188
189static void sec_mode_event(AW_window *aws, AW_CL cl_secroot, AW_CL cl_mode)
190{
191    SEC_root         *sec_root = (SEC_root*)cl_secroot;
192    AWT_COMMAND_MODE  mode = (AWT_COMMAND_MODE)cl_mode;
193
194    // SEC_root   *sec_root = SEC_GRAPHIC->sec_root;
195    const char *text     = 0;
196
197    sec_root->set_show_constraints(SEC_NO_TYPE);
198
199    switch(mode){
200        case AWT_MODE_ZOOM: {
201            text="ZOOM MODE : CLICK or SELECT an area to ZOOM IN (LEFT) or ZOOM OUT (RIGHT) ";
202            break;
203        }
204        case AWT_MODE_MOVE: {
205            text="HELIX MODE    LEFT: build helix   RIGHT: remove helix";
206            break;
207        }
208        case AWT_MODE_SETROOT: {
209            text="SET ROOT MODE    LEFT: Set logical center of structure   RIGHT: Reset angles on sub-structure";
210            break;
211        }
212        case AWT_MODE_ROT: {
213            text="ROTATE MODE    LEFT: Rotate helix/loop RIGHT: w/o substructure";
214            break;
215        }
216        case AWT_MODE_STRETCH: {
217            text="STRETCH MODE  : LEFT-CLICK & DRAG: stretch HELICES and LOOPS   RIGHT: Reset";
218            sec_root->set_show_constraints(SEC_ANY_TYPE);
219            break;
220        }
221        case AWT_MODE_MOD: {
222            text="CONSTRAINT MODE    LEFT: modify constraint";
223            sec_root->set_show_constraints(SEC_ANY_TYPE);
224            break;
225        }
226        case AWT_MODE_LINE: {
227            text="SET CURSOR MODE    LEFT: Set Cursor in ARB_EDIT4";
228            break;
229        }
230        case AWT_MODE_PROINFO: {
231            text="PROBE INFO MODE    LEFT: Displays PROBE information   RIGHT: Clears the Display";
232            break;
233        }
234        default: {
235#if defined(DEBUG)
236            sec_assert(0);
237#endif // DEBUG
238            break;
239        }
240    }
241
242    sec_assert(strlen(text) < AWAR_FOOTER_MAX_LEN); // text too long!
243
244    aws->get_root()->awar(AWAR_FOOTER)->write_string(text);
245
246    AWT_canvas *ntw = sec_root->get_db()->canvas();
247    ntw->set_mode(mode);
248    ntw->refresh();
249}
250
251void SEC_undo_cb(AW_window *, AW_CL cl_db, AW_CL cl_undo_type) {
252    SEC_db_interface *db        = (SEC_db_interface*)cl_db;
253    GB_UNDO_TYPE      undo_type = (GB_UNDO_TYPE)cl_undo_type;
254   
255    GBDATA   *gb_main = db->gbmain();
256    GB_ERROR  error   = GB_undo(gb_main, undo_type);
257    if (error) {
258        aw_message(error);
259    }
260    else{
261        GB_begin_transaction(gb_main);
262        GB_commit_transaction(gb_main);
263        db->canvas()->refresh();
264    }
265}
266
267// --------------------------------------------------------------------------------
268
269#define ASS       "ARB secondary structure v1" // dont change version here!
270#define ASS_START "["ASS"]"
271#define ASS_EOS   "[end of structure]"
272#define ASS_EOF   "[end of "ASS"]"
273
274static void export_structure_to_file(AW_window *, AW_CL cl_db)
275{
276    SEC_db_interface *db       = (SEC_db_interface*)cl_db;
277    AW_root          *aw_root  = db->awroot();
278    char             *filename = aw_root->awar(AWAR_SECEDIT_SAVEDIR"/file_name")->read_string();
279    FILE             *out      = fopen(filename, "wt");
280    GB_ERROR          error    = 0;
281
282    if (out) {
283        SEC_root *sec_root = db->secroot();
284
285        fputs(ASS_START, out); fputc('\n', out);
286
287        char *strct = sec_root->buildStructureString();
288        fputs(strct, out);
289        delete [] strct;
290
291        fputs(ASS_EOS, out); fputc('\n', out);
292
293        const XString& xstr     = sec_root->get_xString();
294        const char    *x_string = xstr.get_x_string();
295
296        sec_assert(xstr.get_x_string_length() == strlen(x_string));
297
298        char *foldInfo = SEC_xstring_to_foldedHelixList(x_string, xstr.get_x_string_length(), sec_root->get_helixDef());
299        fprintf(out, "foldedHelices=%s\n", foldInfo);
300        free(foldInfo);
301
302        fputs(ASS_EOF, out); fputc('\n', out);
303        fclose(out);
304    }
305    else {
306        error = GB_export_errorf("Can't write secondary structure to '%s'", filename);
307    }
308
309    if (error) aw_popup_ok(error);
310}
311
312inline GB_ERROR expectedError(const char *expected) {
313    return GBS_global_string("expected '%s'", expected);
314}
315inline GB_ERROR expectContent(FileBuffer& file, const char *expected) {
316    GB_ERROR error = 0;
317    string   line;
318    if (!file.getLine(line) || line != expected) {
319        error = expectedError(expected);
320    }
321    return error;
322}
323
324static string scanToken(FileBuffer& file, string& rest, GB_ERROR& error) {
325    string line;
326    string token;
327
328    sec_assert(error == 0);
329
330    if (file.getLine(line)) {
331        size_t equal = line.find('=');
332
333        if (equal == string::npos) {
334            error = "Expected '='";
335        }
336        else {
337            token = line.substr(0, equal);
338            rest  = line.substr(equal+1);
339        }
340    }
341    else {
342        error = "Unexpected EOF";
343    }
344    return token;
345}
346
347static GB_ERROR expectToken(FileBuffer& file, const char *token, string& content) {
348    GB_ERROR error      = 0;
349    string   foundToken = scanToken(file, content, error);
350    if (foundToken != token) error = expectedError(token);
351    return error;
352}
353
354static void import_structure_from_file(AW_window *, AW_CL cl_db) {
355    GB_ERROR          error = 0;
356    SEC_db_interface *db    = (SEC_db_interface*)cl_db;
357    SEC_root         *root  = db->secroot();
358
359    if (!root->has_xString()) {
360        error = "Please select a species in EDIT4";
361    }
362    else {
363        char        *filename = db->awroot()->awar(AWAR_SECEDIT_SAVEDIR"/file_name")->read_string();
364        FILE        *in       = fopen(filename, "rt"); // closed by FileBuffer
365
366        if (!in) {
367            error = GB_export_errorf("Can't open file '%s'", filename);
368        }
369        else {
370            FileBuffer file(filename, in);
371            error = expectContent(file, ASS_START);
372       
373            string structure;
374            while (!error) {
375                string line;
376                if (!file.getLine(line)) error = expectedError(ASS_EOS);
377                else {
378                    if (line == ASS_EOS) break;
379                    structure += line + "\n"; 
380                }
381            }
382
383            char *x_string = 0;
384            if (!error) {
385                string content;
386                string token = scanToken(file, content, error);
387
388                if (!error) {
389                    // we already have an existing xstring, use it's length for new xstring
390                    size_t xlength = root->get_xString().getLength();
391
392                    if (token == "foldedHelices") { // new version
393                        x_string = SEC_foldedHelixList_to_xstring(content.c_str(), xlength, root->get_helixDef(), error); // sets error
394                    }
395                    else if (token == "no of helices") { // old version
396                        int saved_helices = atoi(content.c_str());
397
398                        error             = expectToken(file, "length of xstring", content); // ignore, using curr value
399                        if (!error) error = expectToken(file, "xstring_rel_helix", content);
400                        if (!error) {
401                            int helices_in_db;
402                            x_string = old_decode_xstring_rel_helix(content.c_str(), xlength, root->get_helixDef(), &helices_in_db);
403                            if (helices_in_db != saved_helices) {
404                                error = GBS_global_string("Number of helices does not match (file=%i, db=%i).\n"
405                                                          "Saving the structure again from another DB with correct number of helices will work around this restriction.",
406                                                          saved_helices, helices_in_db);
407                            }
408                        }
409                    }
410                    else {
411                        error = "Expected 'foldedHelices' or 'no of helices'";
412                    }
413                }
414                if (!error) error = expectContent(file, ASS_EOF);
415            }
416
417            if (error) {
418                error = GBS_global_string("%s", file.lineError(error).c_str());
419            }
420            else {
421                db->graphic()->write_data_to_db(structure.c_str(), x_string);
422                db->canvas()->refresh();
423            }
424            free(x_string);
425        }
426        free(filename);
427    }
428    if (error) aw_popup_ok(error);
429}
430
431#undef ASS
432#undef ASS_START
433#undef ASS_EOS
434#undef ASS_EOF
435
436static AW_window *SEC_importExport(AW_root *root, int export_to_file, SEC_db_interface *db)
437{
438    AW_window_simple *aws = new AW_window_simple;
439
440    if (export_to_file) aws->init(root, "export_secondary_structure", "Export secondary structure to ...");
441    else                aws->init(root, "import_secondary_structure", "Import secondary structure from ...");
442
443    aws->load_xfig("sec_imexport.fig");
444
445    aws->at("close");
446    aws->callback((AW_CB0)AW_POPDOWN);
447    aws->create_button("CLOSE","CLOSE","C");
448
449    aws->at("help");
450    aws->callback( AW_POPUP_HELP, (AW_CL)"sec_imexport.hlp");
451    aws->create_button("HELP","HELP","H");
452
453    awt_create_selection_box((AW_window *)aws, AWAR_SECEDIT_SAVEDIR);
454
455    aws->at("save");
456    if (export_to_file) {
457        aws->callback(export_structure_to_file, (AW_CL)db);
458        aws->create_button("EXPORT","EXPORT","E");
459    }
460    else {
461        aws->callback(import_structure_from_file, (AW_CL)db);
462        aws->create_button("IMPORT","IMPORT","I");
463    }
464
465    return aws;
466}
467
468static AW_window *SEC_import(AW_root *root, AW_CL cl_db) { return SEC_importExport(root, 0, (SEC_db_interface*)cl_db); }
469static AW_window *SEC_export(AW_root *root, AW_CL cl_db) { return SEC_importExport(root, 1, (SEC_db_interface*)cl_db); }
470
471static void SEC_rename_structure(AW_window *, AW_CL cl_db, AW_CL) {
472    SEC_db_interface      *db        = (SEC_db_interface*)cl_db;
473    SEC_structure_toggler *structure = db->structure();
474
475    char *new_name = aw_input("Rename structure", "New name", structure->name());
476    if (new_name) {
477        structure->setName(new_name);
478        free(new_name);
479        db->canvas()->refresh();
480    }
481}
482
483static void SEC_new_structure(AW_window *, AW_CL cl_db, AW_CL) {
484    SEC_db_interface      *db        = (SEC_db_interface*)cl_db;
485    SEC_structure_toggler *structure = db->structure();
486
487    if (!structure) {
488        db->init_toggler();
489        structure = db->structure();
490        sec_assert(structure);
491    }
492
493    GB_ERROR error = 0;
494    bool     done  = false;
495
496    switch (aw_question("Create new structure?", "Default bone,Copy current,Abort")) {
497        case 0:                 // default bone
498            error = structure->copyTo("Default");
499            if (!error) {
500                db->secroot()->create_default_bone();
501                db->graphic()->save(0, 0, 0, 0);
502                done = true;
503            }
504            break;
505
506        case 1:                 // copy current
507            error = structure->copyTo(GBS_global_string("%s(copy)", structure->name()));
508            done  = !error;
509            break;
510
511        case 2:                 // abort
512            break;
513    }
514
515    if (done) {
516        db->graphic()->request_update(SEC_UPDATE_ZOOM_RESET);
517        db->canvas()->refresh();
518        SEC_rename_structure(0, cl_db, 0);
519    }
520}
521
522static void SEC_delete_structure(AW_window *, AW_CL cl_db, AW_CL) {
523    SEC_db_interface      *db        = (SEC_db_interface*)cl_db;
524    SEC_structure_toggler *structure = db->structure();
525
526    if (structure->getCount()>1) {
527        if (aw_ask_sure(GBS_global_string("Are you sure to delete structure '%s'?", structure->name()))) {
528            GB_ERROR error = structure->remove();
529            if (error) aw_message(error);
530            db->canvas()->refresh();
531        }
532    }
533    else {
534        aw_message("You cannot delete the last structure");
535    }
536}
537
538static void SEC_sync_colors(AW_window *aww, AW_CL cl_mode, AW_CL) {
539    // overwrites color settings with those from EDIT4
540
541    int mode = (int)cl_mode;
542
543    if (mode & 1) { // search string colors
544        AW_copy_GCs(aww->get_root(), "ARB_EDIT4", "ARB_SECEDIT", false,
545                    "User1",   "User2",   "Probe",
546                    "Primerl", "Primerr", "Primerg",
547                    "Sigl",    "Sigr",    "Sigg",
548                    "MISMATCHES",
549                    NULL);
550    }
551    if (mode & 2) { // range colors
552        AW_copy_GCs(aww->get_root(), "ARB_EDIT4", "ARB_SECEDIT", false,
553                    "RANGE_0", "RANGE_1", "RANGE_2",
554                    "RANGE_3", "RANGE_4", "RANGE_5",
555                    "RANGE_6", "RANGE_7", "RANGE_8",
556                    "RANGE_9",
557                    NULL);
558    }
559    if (mode & 4) { // other colors
560        AW_copy_GCs(aww->get_root(), "ARB_EDIT4", "ARB_SECEDIT", false,
561                    "CURSOR",
562                    NULL);
563    }
564}
565
566static AW_window *SEC_create_bonddef_window(AW_root *awr) {
567    AW_window_simple *aws = new AW_window_simple;
568
569    aws->init(awr, "SEC_BONDDEF", "Bond definitions");
570    aws->load_xfig("sec_bonddef.fig");
571
572    aws->callback((AW_CB0)AW_POPDOWN);
573    aws->at("close");
574    aws->create_button("CLOSE", "CLOSE", "C");
575
576    aws->callback( AW_POPUP_HELP,(AW_CL)"sec_bonddef.hlp");
577    aws->at("help");
578    aws->create_button("HELP","HELP","H");
579
580    aws->at("label"); int x_label = aws->get_at_xposition();
581    aws->at("pairs"); int x_pairs = aws->get_at_xposition();
582    aws->at("chars"); int x_chars = aws->get_at_xposition();
583
584    aws->auto_space(0, 0);
585
586#define INSERT_PAIR_FIELDS(label, pairname)                             \
587    aws->at_x(x_label);                                                 \
588    aws->create_button("", label);                                      \
589    aws->at_x(x_pairs);                                                 \
590    aws->create_input_field(AWAR_SECEDIT_##pairname##_PAIRS, 30);       \
591    aws->at_x(x_chars);                                                 \
592    aws->create_input_field(AWAR_SECEDIT_##pairname##_PAIR_CHAR, 1);    \
593    aws->at_newline();
594
595    INSERT_PAIR_FIELDS("Strong pairs", STRONG);
596    INSERT_PAIR_FIELDS("Normal pairs", NORMAL);
597    INSERT_PAIR_FIELDS("Weak pairs", WEAK);
598    INSERT_PAIR_FIELDS("No pairs", NO);
599    INSERT_PAIR_FIELDS("User pairs", USER);
600
601#undef INSERT_PAIR_FIELDS
602   
603    return aws;
604}
605
606static AW_window *SEC_create_display_window(AW_root *awr) {
607    AW_window_simple *aws = new AW_window_simple;
608
609    aws->init(awr, "SEC_DISPLAY_OPTS", "Display options");
610    aws->load_xfig("sec_display.fig");
611
612    aws->callback((AW_CB0)AW_POPDOWN);
613    aws->at("close");
614    aws->create_button("CLOSE", "CLOSE", "C");
615
616    aws->callback( AW_POPUP_HELP,(AW_CL)"sec_display.hlp");
617    aws->at("help");
618    aws->create_button("HELP","HELP","H");
619   
620    // ----------------------------------------
621
622    aws->at("bases");
623    aws->label("Display bases              :");
624    aws->create_inverse_toggle(AWAR_SECEDIT_HIDE_BASES);
625
626    aws->at("strand_dist");
627    aws->label("Distance between strands   :");
628    aws->create_input_field(AWAR_SECEDIT_DIST_BETW_STRANDS);
629
630    aws->at("bonds");
631    aws->label("Display bonds");
632    aws->create_option_menu(AWAR_SECEDIT_SHOW_BONDS);
633    aws->insert_option("None",       "n", SHOW_NO_BONDS);
634    aws->insert_option("Helix",      "h", SHOW_HELIX_BONDS);
635    aws->insert_option("+Non-helix", "o", SHOW_NHELIX_BONDS);
636    aws->update_option_menu();
637
638    aws->at("bonddef");
639    aws->callback(AW_POPUP, (AW_CL)SEC_create_bonddef_window, 0);
640    aws->create_button("sec_bonddef", "Define", 0);
641
642    aws->at("bondThickness");
643    aws->label("Bond thickness             :");
644    aws->create_input_field(AWAR_SECEDIT_BOND_THICKNESS);
645
646    // ----------------------------------------
647   
648    aws->at("cursor");
649    aws->label("Annotate cursor            :");
650    aws->create_option_menu(AWAR_SECEDIT_SHOW_CURPOS);
651    aws->insert_option("None",     "n", SHOW_NO_CURPOS);
652    aws->insert_option("Absolute", "a", SHOW_ABS_CURPOS);
653    aws->insert_option("Ecoli",    "e", SHOW_ECOLI_CURPOS);
654    aws->insert_option("Base",     "b", SHOW_BASE_CURPOS);
655    aws->update_option_menu();
656   
657    aws->at("helixNrs");
658    aws->label("Annotate helices           :");
659    aws->create_toggle(AWAR_SECEDIT_SHOW_HELIX_NRS);
660
661    aws->at("ecoli");
662    aws->label("Annotate ecoli positions   :");
663    aws->create_toggle(AWAR_SECEDIT_SHOW_ECOLI_POS);
664
665    aws->at("search");
666    aws->label("Visualize search results   :");
667    aws->create_toggle(AWAR_SECEDIT_DISPLAY_SEARCH);
668
669    aws->at("sai");
670    aws->label("Visualize SAI              :");
671    aws->create_toggle(AWAR_SECEDIT_DISPLAY_SAI);
672   
673    // ----------------------------------------
674
675    aws->at("binding");
676    aws->label("Binding helix positions    :");
677    aws->create_toggle(AWAR_SECEDIT_DISPPOS_BINDING);
678   
679    aws->at("ecoli2");
680    aws->label("Ecoli base positions       :");
681    aws->create_toggle(AWAR_SECEDIT_DISPPOS_ECOLI);
682   
683    // ----------------------------------------
684
685    aws->at("strSkeleton");
686    aws->label("Display structure skeleton :");
687    aws->create_toggle(AWAR_SECEDIT_SHOW_STR_SKELETON);
688
689    aws->at("skelThickness");
690    aws->label("Skeleton thickness         :");
691    aws->create_input_field(AWAR_SECEDIT_SKELETON_THICKNESS);
692
693#ifdef DEBUG
694    aws->at("show_debug");
695    aws->label("Show debug info:");
696    aws->create_toggle(AWAR_SECEDIT_SHOW_DEBUG);
697#endif
698
699    return aws;
700}
701
702static void SEC_exit(GBDATA *gb_main, void *cl_sec_root) {
703    SEC_root *sec_root = static_cast<SEC_root*>(cl_sec_root);
704
705    delete sec_root;
706}
707
708AW_window *SEC_create_main_window(AW_root *awr, GBDATA *gb_main) {
709    SEC_graphic *gfx  = new SEC_graphic(awr, gb_main); // never freed
710    SEC_root    *root = gfx->sec_root;
711
712    AW_window_menu_modes *awm = new AW_window_menu_modes();
713    awm->init(awr,"ARB_SECEDIT", "ARB_SECEDIT: Secondary structure editor", 200,200);
714
715    AW_gc_manager aw_gc_manager;
716    AWT_canvas *ntw = new AWT_canvas(gb_main, awm, gfx, aw_gc_manager, AWAR_SPECIES_NAME);
717    root->init(gfx, ntw);
718
719    ntw->recalc_size();
720    ntw->set_mode(AWT_MODE_ZOOM); // Default-Mode
721
722    const SEC_db_interface *db = root->get_db();
723
724    GB_atclose(gb_main, SEC_exit, root);
725   
726    awm->create_menu("File", "F", "secedit_file.hlp",  AWM_ALL );
727
728    awm->insert_menu_topic("secedit_new", "New structure", "N", 0, AWM_ALL, SEC_new_structure, (AW_CL)db, 0);
729    awm->insert_menu_topic("secedit_rename", "Rename structure", "R", 0, AWM_ALL, SEC_rename_structure, (AW_CL)db, 0);
730    awm->insert_menu_topic("secedit_delete", "Delete structure", "D", 0, AWM_ALL, SEC_delete_structure, (AW_CL)db, 0);
731    awm->insert_separator();
732    awm->insert_menu_topic("secedit_import", "Load structure", "L", "secedit_imexport.hlp", AWM_ALL, AW_POPUP, (AW_CL)SEC_import, (AW_CL)db);
733    awm->insert_menu_topic("secedit_export", "Save structure", "S", "secedit_imexport.hlp", AWM_ALL, AW_POPUP, (AW_CL)SEC_export, (AW_CL)db);
734    awm->insert_separator();
735    awm->insert_menu_topic("secStruct2xfig", "Export Structure to XFIG", "X", "sec_layout.hlp",  AWM_ALL, AWT_popup_sec_export_window, (AW_CL)ntw, 0);
736    awm->insert_menu_topic("print_secedit",  "Print Structure",          "P", "secedit2prt.hlp", AWM_ALL, AWT_popup_print_window,      (AW_CL)ntw, 0);
737    awm->insert_separator();
738
739    awm->insert_menu_topic( "close", "Close", "C","quit.hlp", AWM_ALL, (AW_CB)AW_POPDOWN, 0, 0);
740
741    awm->create_menu("Properties","P","properties.hlp", AWM_ALL);
742    awm->insert_menu_topic("sec_display", "Display options", "D", "sec_display.hlp", AWM_ALL, AW_POPUP, (AW_CL)SEC_create_display_window, 0);
743    awm->insert_separator();
744    awm->insert_menu_topic("props_secedit", "Change Colors and Fonts","C","secedit_props_data.hlp",AWM_ALL, AW_POPUP, (AW_CL)AW_create_gc_window, (AW_CL)aw_gc_manager );
745    awm->insert_separator();
746    awm->insert_menu_topic("sync_search_colors", "Sync search colors with EDIT4", "s", "sync_colors.hlp", AWM_ALL, SEC_sync_colors, (AW_CL)1, 0);
747    awm->insert_menu_topic("sync_range_colors",  "Sync range colors with EDIT4",  "r", "sync_colors.hlp", AWM_ALL, SEC_sync_colors, (AW_CL)2, 0);
748    awm->insert_menu_topic("sync_other_colors",  "Sync other colors with EDIT4",  "o", "sync_colors.hlp", AWM_ALL, SEC_sync_colors, (AW_CL)4, 0);
749    awm->insert_menu_topic("sync_all_colors",    "Sync all colors with EDIT4",    "a", "sync_colors.hlp", AWM_ALL, SEC_sync_colors, (AW_CL)(1|2|4), 0);
750    awm->insert_separator();
751    awm->insert_menu_topic("sec_save_props",    "How to save properties",   "p","savedef.hlp",  AWM_ALL, (AW_CB) AW_POPUP_HELP, (AW_CL)"sec_props.hlp", 0 );
752
753    awm->create_mode("pzoom.bitmap",       "sec_mode.hlp", AWM_ALL, sec_mode_event, (AW_CL)root, (AW_CL)AWT_MODE_ZOOM);
754    awm->create_mode("sec_modify.bitmap",  "sec_mode.hlp", AWM_ALL, sec_mode_event, (AW_CL)root, (AW_CL)AWT_MODE_MOVE);
755    awm->create_mode("setroot.bitmap",     "sec_mode.hlp", AWM_ALL, sec_mode_event, (AW_CL)root, (AW_CL)AWT_MODE_SETROOT);
756    awm->create_mode("rot.bitmap",         "sec_mode.hlp", AWM_ALL, sec_mode_event, (AW_CL)root, (AW_CL)AWT_MODE_ROT);
757    awm->create_mode("stretch.bitmap",     "sec_mode.hlp", AWM_ALL, sec_mode_event, (AW_CL)root, (AW_CL)AWT_MODE_STRETCH);
758    awm->create_mode("info.bitmap",        "sec_mode.hlp", AWM_ALL, sec_mode_event, (AW_CL)root, (AW_CL)AWT_MODE_MOD);
759    awm->create_mode("sec_setcurs.bitmap", "sec_mode.hlp", AWM_ALL, sec_mode_event, (AW_CL)root, (AW_CL)AWT_MODE_LINE);
760    awm->create_mode("probeInfo.bitmap",   "sec_mode.hlp", AWM_ALL, sec_mode_event, (AW_CL)root, (AW_CL)AWT_MODE_PROINFO);
761
762    awm->set_info_area_height( 250 );
763    awm->at(5,2);
764    // awm->auto_space(5,-2);
765    awm->auto_space(0,-2);
766
767    awm->button_length(0);
768    awm->help_text("quit.hlp");
769    awm->callback((AW_CB0)AW_POPDOWN);
770    awm->create_button("Close", "#quit.xpm"); // use quit button, cause users regard secedit as separate program
771
772    // awm->callback(AW_POPUP_HELP,(AW_CL)"arb_secedit.hlp");
773    // awm->button_length(0);
774    // awm->help_text("help.hlp");
775    // awm->create_button("HELP", "HELP","H");
776
777    awm->callback(AW_help_entry_pressed);
778    awm->help_text("arb_secedit.hlp");
779    // awm->create_button(0,"?");
780    awm->create_button("HELP","#help.xpm");
781
782    awm->callback(SEC_undo_cb,(AW_CL)db,(AW_CL)GB_UNDO_UNDO);
783    awm->help_text("undo.hlp");
784    awm->create_button("Undo", "#undo.bitmap");
785
786    awm->callback(SEC_undo_cb,(AW_CL)db,(AW_CL)GB_UNDO_REDO);
787    awm->help_text("undo.hlp");
788    awm->create_button("Redo", "#redo.bitmap");
789
790    awm->callback(SEC_toggle_cb, (AW_CL)root, 0);
791    awm->help_text("sec_main.hlp");
792    awm->create_button("Toggle", "Toggle");
793
794    awm->callback(SEC_center_cb, (AW_CL)root, 0);
795    awm->help_text("sec_main.hlp");
796    awm->create_button("Center", "Center");
797
798    awm->callback((AW_CB)SEC_fit_window_cb,(AW_CL)root, 0);
799    awm->help_text("sec_main.hlp");
800    awm->create_button("fitWindow", "Fit");
801
802    awm->at_newline();
803
804    {
805        AW_at_maxsize maxSize; // store size (so AWAR_FOOTER does not affect min. window size)
806        maxSize.store(awm->_at);
807        awm->button_length(AWAR_FOOTER_MAX_LEN);
808        awm->create_button(0,AWAR_FOOTER);
809        awm->at_newline();
810        maxSize.restore(awm->_at);
811    }
812
813    // awm->set_info_area_height(awm->get_at_yposition()+6);
814    awm->set_info_area_height(awm->get_at_yposition());
815
816    return awm;
817}
818
Note: See TracBrowser for help on using the repository browser.