9
9
// =============================================================== //
18
#include <aw_awars.hxx>
19
#include <aw_global.hxx>
20
#include <aw_window.hxx>
21
#include <aw_preset.hxx>
22
#include <ed4_extern.hxx>
24
11
#include "SEC_graphic.hxx"
25
12
#include "SEC_root.hxx"
26
13
#include "SEC_iter.hxx"
27
14
#include "SEC_toggle.hxx"
29
// SEC_graphic *SEC_GRAPHIC = 0;
16
#include <ed4_extern.hxx>
18
#include <aw_awars.hxx>
19
#include <aw_global.hxx>
20
#include <aw_preset.hxx>
22
#include <aw_root.hxx>
23
#include <aw_question.hxx>
31
29
using namespace std;
33
AW_gc_manager SEC_graphic::init_devices(AW_window *aww, AW_device *device, AWT_canvas* ntw, AW_CL)
31
AW_gc_manager SEC_graphic::init_devices(AW_window *aww, AW_device *device, AWT_canvas *scr)
35
AW_gc_manager preset_window =
33
AW_gc_manager gc_manager =
35
scr->get_gc_base_name(),
41
(AW_CB)AWT_expose_cb, (AW_CL)ntw, 0,
40
makeWindowCallback(AWT_expose_cb, scr),
244
244
GB_ERROR SEC_graphic::handleMouse(AW_device *device, AW_event_type event, int button, AWT_COMMAND_MODE cmd, const Position& world, SEC_base *elem, int abspos) {
245
245
GB_ERROR error = 0;
247
// -----------------------------------------
247
// ------------------------------------------
248
248
// handle element dependent actions
249
// -----------------------------------------
252
251
static Position start; // click position on mouse down
389
388
else error = "Please click on a loop to change the root";
391
390
else { // reset angles
392
sec_assert(button == AWT_M_RIGHT);
391
sec_assert(button == AW_BUTTON_RIGHT);
393
392
elem->reset_angles();
394
393
elem->orientationChanged();
395
394
exports.save = 1;
400
case AWT_MODE_MOVE: { // fold/unfold helix
399
case AWT_MODE_FOLD: { // fold/unfold helix
401
400
if (event == AW_Mouse_Press) {
402
if (button == AWT_M_LEFT) { // fold helix
401
if (button == AW_BUTTON_LEFT) { // fold helix
404
403
const char *helix_nr = sec_root->helixNrAt(abspos);
439
case AWT_MODE_PROINFO:
437
case AWT_MODE_CURSOR:
440
439
elem = 0; // handle element-independent
442
441
default: sec_assert(0); break;
446
// --------------------------------------
445
// ---------------------------------------
447
446
// action independent of element
448
// --------------------------------------
452
case AWT_MODE_LINE: // set cursor in ARB_EDIT4
450
case AWT_MODE_CURSOR: // set cursor in ARB_EDIT4
453
451
if (event == AW_Mouse_Press) {
454
452
if (abspos >= 0 && size_t(abspos) < sec_root->max_index()) {
455
453
// sequence position in AWAR_SET_CURSOR_POSITION is starting with 0!
461
case AWT_MODE_PROINFO: // display search pattern
459
case AWT_MODE_PINFO: // display search pattern
462
460
if (event == AW_Mouse_Press) {
463
if (button == AWT_M_LEFT) {
461
if (button == AW_BUTTON_LEFT) {
464
462
if (abspos >= 0 && size_t(abspos) < sec_root->max_index()) {
465
463
sec_root->paintSearchPatternStrings(device, abspos, world.xpos()+1, world.ypos());
467
// dont refresh here!
465
// don't refresh here!
470
sec_assert(button == AWT_M_RIGHT);
468
sec_assert(button == AW_BUTTON_RIGHT);
471
469
exports.refresh = 1; // simply refresh to remove drawn patterns
486
void SEC_graphic::command(AW_device *device, AWT_COMMAND_MODE cmd,
487
int button, AW_key_mod key_modifier, AW_key_code key_code, char key_char,
488
AW_event_type event, AW_pos screen_x, AW_pos screen_y,
489
AW_clicked_line *cl, AW_clicked_text *ct)
491
if (cmd != AWT_MODE_MOD && cmd != AWT_MODE_STRETCH) sec_root->set_show_constraints(SEC_NO_TYPE);
484
void SEC_graphic::handle_command(AW_device *device, AWT_graphic_event& event) {
485
if (event.cmd() != AWT_MODE_EDIT && event.cmd() != AWT_MODE_STRETCH) sec_root->set_show_constraints(SEC_NO_TYPE);
493
487
GB_ERROR error = 0;
494
if (event== AW_Keyboard_Press || event == AW_Keyboard_Release) {
495
error = handleKey(event, key_modifier, key_code, key_char);
488
if (event.type() == AW_Keyboard_Press || event.type() == AW_Keyboard_Release) {
489
error = handleKey(event.type(), event.key_modifier(), event.key_code(), event.key_char());
498
if (button != AWT_M_MIDDLE && cmd != AWT_MODE_ZOOM) { // dont handle scroll + zoom
500
Position world = device->rtransform(Position(screen_x, screen_y)); // current click position
502
if (AW_getBestClick(world, cl, ct, &cd1, &cd2)) {
503
SEC_base *elem = reinterpret_cast<SEC_base*>(cd1);
506
#if defined(DEBUG) && 0
507
if (cl->exists) device->line(SEC_GC_CURSOR, cl->x0, cl->y0, cl->x1, cl->y1, -1, 0, -1);
508
if (ct->exists) device->box(SEC_GC_CURSOR, false, ct->textArea, -1, 0, -1);
511
error = handleMouse(device, event, button, cmd, world, elem, abspos);
492
if (event.button() != AW_BUTTON_MIDDLE && event.cmd() != AWT_MODE_ZOOM) { // don't handle scroll + zoom
493
const AW_clicked_element *clicked = event.best_click();
495
SEC_base *elem = reinterpret_cast<SEC_base*>(clicked->cd1());
496
int abspos = clicked->cd2();
498
Position world = device->rtransform(event.position());
499
error = handleMouse(device, event.type(), event.button(), event.cmd(), world, elem, abspos);
516
504
if (error) aw_message(error);
520
507
SEC_graphic::SEC_graphic(AW_root *aw_rooti, GBDATA *gb_maini)
521
: update_requested(SEC_UPDATE_RELOAD)
526
, sec_root(new SEC_root)
508
: update_requested(SEC_UPDATE_RELOAD),
513
sec_root(new SEC_root),
531
// update_requested = SEC_UPDATE_RELOAD; // // need to load structure!
534
// gb_struct_ref = 0;
537
exports.dont_fit_x = 0;
538
exports.dont_fit_y = 0;
539
exports.left_offset = 20;
540
exports.right_offset = 20;
541
exports.top_offset = 20;
542
exports.bottom_offset = 20;
543
exports.dont_scroll = 0;
545
// aw_root = aw_rooti;
546
// gb_main = gb_maini;
548
rot_ct.exists = false;
549
rot_cl.exists = false;
551
// sec_root = new SEC_root;
518
exports.set_standard_default_padding();
554
SEC_graphic::~SEC_graphic(void) {
521
SEC_graphic::~SEC_graphic() {
556
523
delete load_error;
559
void SEC_structure_changed_cb(GBDATA *gb_seq, SEC_graphic *gfx, GB_CB_TYPE type) {
526
static void SEC_structure_changed_cb(GBDATA *gb_seq, SEC_graphic *gfx, GB_CB_TYPE type) {
560
527
if (type == GB_CB_DELETE) {
561
528
gfx->gb_struct = NULL;
562
529
gfx->gb_struct_ref = NULL;
571
/** read awar AWAR_HELIX_NAME to get the name */
572
538
GB_ERROR SEC_graphic::load(GBDATA *, const char *, AW_CL, AW_CL) {
539
//! (Re-)Load secondary structure from database
573
541
sec_assert(sec_root->get_db()->canDisplay()); // need a sequence loaded (to fix bugs in versions < 3)
574
542
sec_root->nail_cursor();
576
544
GB_transaction ta(gb_main);
577
545
// first check timestamp, do not load structure that we have saved !!!!
579
547
if (GB_read_clock(gb_struct) <= last_saved) return NULL;
582
/************************** Reset structure ***********************************/
584
GB_remove_callback( gb_struct, GB_CB_ALL, (GB_CB)SEC_structure_changed_cb, (int *)this);
586
GB_remove_callback( gb_struct_ref, GB_CB_ALL, (GB_CB)SEC_structure_changed_cb, (int *)this);
587
gb_struct_ref = NULL;
552
GB_remove_callback(gb_struct, GB_CB_ALL, makeDatabaseCallback(SEC_structure_changed_cb, this)); gb_struct = NULL;
553
GB_remove_callback(gb_struct_ref, GB_CB_ALL, makeDatabaseCallback(SEC_structure_changed_cb, this)); gb_struct_ref = NULL;
590
556
request_update(SEC_UPDATE_RECOUNT);
608
572
GBDATA *gb_species = GBT_find_SAI(gb_main, name);
609
573
if (!gb_species) {
610
err = GB_export_errorf("Cannot find helix template SAI '%s'",name);
574
err = GB_export_errorf("Cannot find helix template SAI '%s'", name);
613
577
char *ali_name = GBT_get_default_alignment(gb_main);
578
long ali_len = GBT_get_alignment_len(gb_main, ali_name);
615
ali_len = GBT_get_alignment_len(gb_main,ali_name);
616
580
if (ali_len < 10) {
617
err = GB_export_errorf("alignment '%s' to short to generate helix",ali_name);
581
err = GB_export_errorf("alignment '%s' to short to generate helix", ali_name);
620
584
gb_ali = GB_search(gb_species, ali_name, GB_FIND);
622
err = GB_export_errorf("Your helix structure template '%s' has no valid sequence for alignment '%s'", name,ali_name); // no sequence for name in the database !!!
586
err = GB_export_errorf("Your helix structure template '%s' has no valid sequence for alignment '%s'", name, ali_name); // no sequence for name in the database !!!
629
593
free(helix_name);
632
// -----------------------
596
// ------------------------
633
597
// read structure
634
// -----------------------
637
gb_struct = GB_search(gb_ali,NAME_OF_STRUCT_SEQ, GB_FIND);
600
gb_struct = GB_search(gb_ali, NAME_OF_STRUCT_SEQ, GB_FIND);
640
gb_struct_ref = GB_search(gb_ali , NAME_OF_REF_SEQ , GB_STRING);
603
gb_struct_ref = GB_search(gb_ali, NAME_OF_REF_SEQ, GB_STRING);
642
605
char *strct = GB_read_string(gb_struct);
643
606
char *ref = GB_read_string(gb_struct_ref);
644
err = sec_root->read_data(strct,ref);
607
err = sec_root->read_data(strct, ref);
646
609
err = GBS_global_string("Defect structure in DB (read-error: '%s')", err);
696
659
request_update(SEC_UPDATE_ZOOM_RESET);
699
/************************* Listen to the database ***************************/
700
GB_add_callback(gb_struct,GB_CB_ALL,(GB_CB)SEC_structure_changed_cb, (int *)this);
701
GB_add_callback(gb_struct_ref,GB_CB_ALL,(GB_CB)SEC_structure_changed_cb, (int *)this);
662
// set structure-change-callbacks:
663
if(gb_struct) GB_add_callback(gb_struct, GB_CB_ALL, makeDatabaseCallback(SEC_structure_changed_cb, this));
664
if(gb_struct_ref) GB_add_callback(gb_struct_ref, GB_CB_ALL, makeDatabaseCallback(SEC_structure_changed_cb, this));
706
/** Save secondary structure to database */
707
GB_ERROR SEC_graphic::save(GBDATA *, const char *,AW_CL,AW_CL)
669
GB_ERROR SEC_graphic::save(GBDATA *, const char *, AW_CL, AW_CL) {
670
//! Save secondary structure to database
709
672
if (!gb_struct) return 0; // not loaded, so don't save
710
673
if (!sec_root) return 0;
712
675
char *data = sec_root->buildStructureString();
713
676
GB_transaction ta(gb_main);
714
GB_ERROR error = GB_write_string(gb_struct,data);
677
GB_ERROR error = GB_write_string(gb_struct, data);
716
679
const XString& xstr = sec_root->get_xString();
717
680
const char *x_string = xstr.get_x_string();
719
error = GB_write_string(gb_struct_ref,x_string);
682
error = GB_write_string(gb_struct_ref, x_string);
721
684
if (!error && xstr.alignment_too_short()) {
722
685
aw_message("Your helix needs one gap at end. Please format your alignment!");
786
749
update_requested = static_cast<SEC_update_request>(update_requested^SEC_UPDATE_RECOUNT); // clear recount flag
787
750
exports.refresh = 1;
790
753
sec_root->perform_autoscroll();
794
757
if (update_requested & SEC_UPDATE_ZOOM_RESET) {
795
res = 1; // signal zoom reset
758
res = 1; // report zoom reset
796
759
update_requested = static_cast<SEC_update_request>(update_requested^SEC_UPDATE_ZOOM_RESET); // clear zoom reset flag
808
771
sec_root->clear_last_drawed_cursor_position();
810
773
if (sec_root->canDisplay()) {
811
if (sec_root->get_root_loop()) {
774
if (sec_root->get_root_loop()) {
812
775
GB_ERROR paint_error = sec_root->paint(device);
813
776
if (paint_error) textToDisplay = GBS_global_string("Error: %s", paint_error);
828
791
if (textToDisplay) { // no structure
829
792
sec_assert(strchr(textToDisplay, '\n') == 0); // linefeeds do not work here
830
device->text(SEC_GC_ECOLI, textToDisplay, 0, 0, 0, 1, 0, 0, 0);
793
device->text(SEC_GC_ECOLI, textToDisplay, 0, 0, 0, AW_SCREEN, 0);
831
794
sec_root->set_last_drawed_cursor_position(LineVector(Origin, ZeroVector));
835
void SEC_graphic::info(AW_device *device, AW_pos x, AW_pos y, AW_clicked_line *cl, AW_clicked_text *ct)
798
void SEC_graphic::info(AW_device */*device*/, AW_pos /*x*/, AW_pos /*y*/, AW_clicked_line */*cl*/, AW_clicked_text */*ct*/) {
837
799
aw_message("INFO MESSAGE");