source: tags/arb-6.0/SECEDIT/SEC_main.cxx

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