source: branches/help/SECEDIT/SEC_main.cxx

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