ARB
SEC_main.cxx
Go to the documentation of this file.
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 
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 {
43  part = part->next();
44  }
45  while (part != start_part);
46  }
47 }
48 
49 // ------------------------------------------------------
50 // auto-scrolling (triggered by structure self)
51 
52 void SEC_root::nail_position(size_t absPos) {
53  if (drawnPositions) {
54  nailedAbsPos = absPos;
55  drawnAbsPos = *drawnPositions->drawn_at(absPos);
56  }
57 }
58 
59 void 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 
69 void SEC_root::add_autoscroll(const Vector& scroll) {
70  if (autoscroll) *autoscroll += scroll;
71  else autoscroll = new Vector(scroll);
72 }
73 
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 
140 void 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 
179 static 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 
186 static void SEC_center_cb(AW_window *, SEC_root *root) {
187  root->position_cursor(true, true);
188 }
189 
190 static 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 
195 static 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 
226 static 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 
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 
294 inline GB_ERROR expectedError(const char *expected) {
295  return GBS_global_string("expected '%s'", expected);
296 }
297 inline 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 
306 static 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 
329 static 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 
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 
418 static 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 
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 
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 
461 static 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  }
498  }
499 }
500 
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 
521 
523 };
524 
525 static 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 
552  AW_window_simple *aws = new AW_window_simple;
553 
554  aws->init(awr, "SEC_BONDDEF", "Bond definitions");
555  aws->load_xfig("sec_bonddef.fig");
556 
557  aws->at("close");
558  aws->callback(AW_POPDOWN);
559  aws->create_button("CLOSE", "CLOSE", "C");
560 
561  aws->callback(makeHelpCallback("sec_bonddef.hlp"));
562  aws->at("help");
563  aws->create_button("HELP", "HELP", "H");
564 
565  aws->at("label"); int x_label = aws->get_at_xposition();
566  aws->at("pairs"); int x_pairs = aws->get_at_xposition();
567  aws->at("chars"); int x_chars = aws->get_at_xposition();
568 
569  aws->auto_space(0, 0);
570 
571 #define INSERT_PAIR_FIELDS(label, pairname) \
572  aws->at_x(x_label); \
573  aws->create_button(NULp, label); \
574  aws->at_x(x_pairs); \
575  aws->create_input_field(AWAR_SECEDIT_##pairname##_PAIRS, 30); \
576  aws->at_x(x_chars); \
577  aws->create_input_field(AWAR_SECEDIT_##pairname##_PAIR_CHAR, 1); \
578  aws->at_newline();
579 
580  INSERT_PAIR_FIELDS("Strong pairs", STRONG);
581  INSERT_PAIR_FIELDS("Normal pairs", NORMAL);
582  INSERT_PAIR_FIELDS("Weak pairs", WEAK);
583  INSERT_PAIR_FIELDS("No pairs", NO);
584  INSERT_PAIR_FIELDS("User pairs", USER);
585 
586 #undef INSERT_PAIR_FIELDS
587 
588  return aws;
589 }
590 
591 #define INSERT_PAIR_MAPPING(pairname) \
592  { AWAR_SECEDIT_##pairname##_PAIRS, "pairs_" #pairname }, \
593  { AWAR_SECEDIT_##pairname##_PAIR_CHAR, "char_" #pairname }
594 
596  { AWAR_SECEDIT_HIDE_BASES, "hidebases" },
597  { AWAR_SECEDIT_DIST_BETW_STRANDS, "stranddist" },
598  { AWAR_SECEDIT_SHOW_BONDS, "showbonds" },
599 
600  INSERT_PAIR_MAPPING(STRONG),
602  INSERT_PAIR_MAPPING(WEAK),
604  INSERT_PAIR_MAPPING(USER),
605 
606  { AWAR_SECEDIT_BOND_THICKNESS, "bondthickness" },
607  { AWAR_SECEDIT_SHOW_CURPOS, "showposition" },
608  { AWAR_SECEDIT_SHOW_HELIX_NRS, "showhelixnrs" },
609  { AWAR_SECEDIT_SHOW_ECOLI_POS, "showecolipos" },
610  { AWAR_SECEDIT_DISPLAY_SEARCH, "showsearch" },
611  { AWAR_SECEDIT_DISPLAY_SAI, "showsai" },
612  { AWAR_SECEDIT_DISPPOS_BINDING, "disppos_helix" },
613  { AWAR_SECEDIT_DISPPOS_ECOLI, "disppos_ecoli" },
614  { AWAR_SECEDIT_SHOW_STR_SKELETON, "skeleton" },
615  { AWAR_SECEDIT_SKELETON_THICKNESS, "skeleton_thickness" },
616 
617  { NULp, NULp }
618 };
619 
620 #undef INSERT_PAIR_MAPPING
621 
623  AW_window_simple *aws = new AW_window_simple;
624 
625  const int SCALED_TEXT_COLUMNS = 7;
626  const int SCALER_WIDTH = 200;
627 
628  aws->auto_space(5, 5);
629 
630  aws->init(awr, "SEC_DISPLAY_OPTS", "Display options");
631  aws->load_xfig("sec_display.fig");
632 
633  aws->at("close");
634  aws->callback(AW_POPDOWN);
635  aws->create_button("CLOSE", "CLOSE", "C");
636 
637  aws->callback(makeHelpCallback("sec_display.hlp"));
638  aws->at("help");
639  aws->create_button("HELP", "HELP", "H");
640 
641  // ----------------------------------------
642 
643  aws->at("bases");
644  aws->label("Display bases :");
645  aws->create_inverse_toggle(AWAR_SECEDIT_HIDE_BASES);
646 
647  aws->at("strand_dist");
648  aws->label("Distance between strands :");
649  aws->create_input_field_with_scaler(AWAR_SECEDIT_DIST_BETW_STRANDS, SCALED_TEXT_COLUMNS, SCALER_WIDTH, AW_SCALER_EXP_LOWER);
650 
651  aws->at("bonds");
652  aws->label("Display bonds");
653  aws->create_option_menu(AWAR_SECEDIT_SHOW_BONDS);
654  aws->insert_option("None", "n", SHOW_NO_BONDS);
655  aws->insert_option("Helix", "h", SHOW_HELIX_BONDS);
656  aws->insert_option("+Non-helix", "o", SHOW_NHELIX_BONDS);
657  aws->update_option_menu();
658 
659  aws->at("bonddef");
660  aws->callback(makeCreateWindowCallback(SEC_create_bonddef_window));
661  aws->create_button("sec_bonddef", "Define");
662 
663  aws->at("bondThickness");
664  aws->label("Bond thickness :");
665  aws->create_input_field_with_scaler(AWAR_SECEDIT_BOND_THICKNESS, SCALED_TEXT_COLUMNS, SCALER_WIDTH, AW_SCALER_EXP_LOWER);
666 
667  // ----------------------------------------
668 
669  aws->at("cursor");
670  aws->label("Annotate cursor :");
671  aws->create_option_menu(AWAR_SECEDIT_SHOW_CURPOS);
672  aws->insert_option("None", "n", SHOW_NO_CURPOS);
673  aws->insert_option("Absolute", "a", SHOW_ABS_CURPOS);
674  aws->insert_option("Ecoli", "e", SHOW_ECOLI_CURPOS);
675  aws->insert_option("Base", "b", SHOW_BASE_CURPOS);
676  aws->update_option_menu();
677 
678  aws->at("helixNrs");
679  aws->label("Annotate helices :");
680  aws->create_toggle(AWAR_SECEDIT_SHOW_HELIX_NRS);
681 
682  aws->at("ecoli");
683  aws->label("Annotate ecoli positions :");
684  aws->create_toggle(AWAR_SECEDIT_SHOW_ECOLI_POS);
685 
686  aws->at("search");
687  aws->label("Visualize search results :");
688  aws->create_toggle(AWAR_SECEDIT_DISPLAY_SEARCH);
689 
690  aws->at("sai");
691  aws->label("Visualize SAI :");
692  aws->create_toggle(AWAR_SECEDIT_DISPLAY_SAI);
693 
694  // ----------------------------------------
695 
696  aws->at("binding");
697  aws->label("Binding helix positions :");
698  aws->create_toggle(AWAR_SECEDIT_DISPPOS_BINDING);
699 
700  aws->at("ecoli2");
701  aws->label("Ecoli base positions :");
702  aws->create_toggle(AWAR_SECEDIT_DISPPOS_ECOLI);
703 
704  // ----------------------------------------
705 
706  aws->at("strSkeleton");
707  aws->label("Display structure skeleton :");
708  aws->create_toggle(AWAR_SECEDIT_SHOW_STR_SKELETON);
709 
710  aws->at("skelThickness");
711  aws->label("Skeleton thickness :");
712  aws->create_input_field_with_scaler(AWAR_SECEDIT_SKELETON_THICKNESS, SCALED_TEXT_COLUMNS, SCALER_WIDTH, AW_SCALER_EXP_LOWER);
713 
714 #ifdef DEBUG
715  aws->at("show_debug");
716  aws->label("Show debug info:");
717  aws->create_toggle(AWAR_SECEDIT_SHOW_DEBUG);
718 #endif
719 
720  aws->at("config");
721  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "secedit_display", secedit_display_config_mapping);
722 
723  return aws;
724 }
725 
726 static void SEC_exit(GBDATA *, SEC_root *sec_root) {
727  // @@@ use popdown callback for SEC_exit and valgrind open/close/open secedit
728  delete sec_root;
729 }
730 
732  return AW_create_gc_window_named(awr, gcman, "SECEDIT_COLOR_DEF2", "SECEDIT colors and fonts");
733 }
734 
736  AW_root *awr = host.get_application_root();
737  GBDATA *gb_main = host.get_database();
738 
739  SEC_graphic *gfx = new SEC_graphic(awr, gb_main); // never freed
740  SEC_root *root = gfx->sec_root;
741 
743  awm->init(awr, "ARB_SECEDIT", "ARB_SECEDIT: Secondary structure editor", 200, 200);
744 
745  AWT_canvas *scr = new AWT_canvas(gb_main, awm, awm->get_window_id(), gfx);
746  {
747  AWT_auto_refresh allowed_on(scr);
748  root->init(gfx, scr, host);
749  scr->request_resize();
750  }
751  scr->set_mode(AWT_MODE_ZOOM); // Default-Mode
752 
753  const SEC_db_interface *db = root->get_db();
754 
755  GB_atclose_callback(gb_main, makeDatabaseCallback(SEC_exit, root));
756 
757  awm->create_menu("File", "F", AWM_ALL);
758 
759  awm->insert_menu_topic("secedit_new", "New structure", "N", NULp, AWM_ALL, makeWindowCallback(SEC_new_structure, db));
760  awm->insert_menu_topic("secedit_rename", "Rename structure", "R", NULp, AWM_ALL, makeWindowCallback(SEC_rename_structure, db));
761  awm->insert_menu_topic("secedit_delete", "Delete structure", "D", NULp, AWM_ALL, makeWindowCallback(SEC_delete_structure, db));
762  awm->sep______________();
763  awm->insert_menu_topic("secedit_import", "Load structure", "L", "secedit_imexport.hlp", AWM_ALL, makeCreateWindowCallback(SEC_importExport, false, db));
764  awm->insert_menu_topic("secedit_export", "Save structure", "S", "secedit_imexport.hlp", AWM_ALL, makeCreateWindowCallback(SEC_importExport, true, db));
765  awm->sep______________();
766  awm->insert_menu_topic("secStruct2xfig", "Export structure to XFIG", "X", "tree2file.hlp", AWM_ALL, makeWindowCallback(AWT_popup_sec_export_window, scr));
767  awm->insert_menu_topic("print_secedit", "Print Structure", "P", "tree2prt.hlp", AWM_ALL, makeWindowCallback(AWT_popup_print_window, scr));
768  awm->sep______________();
769 
770  awm->insert_menu_topic("close", "Close", "C", "quit.hlp", AWM_ALL, AW_POPDOWN);
771 
772  awm->create_menu("Properties", "P", AWM_ALL);
773  awm->insert_menu_topic("sec_display", "Display options", "D", "sec_display.hlp", AWM_ALL, SEC_create_display_window);
774  awm->sep______________();
775  awm->insert_menu_topic("props_secedit", "Change Colors and Fonts", "C", "color_props.hlp", AWM_ALL, makeCreateWindowCallback(SEC_create_gc_window, scr->gc_manager));
776  awm->sep______________();
777  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));
778  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));
779  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));
780  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));
781  awm->sep______________();
782  awm->insert_menu_topic("sec_save_props", "How to save properties", "p", "savedef.hlp", AWM_ALL, makeHelpCallback("sec_props.hlp"));
783 
784  awm->create_mode("mode_zoom.xpm", "sec_mode.hlp", AWM_ALL, makeWindowCallback(sec_mode_event, root, AWT_MODE_ZOOM));
785  awm->create_mode("mode_fold.xpm", "sec_mode.hlp", AWM_ALL, makeWindowCallback(sec_mode_event, root, AWT_MODE_FOLD));
786  awm->create_mode("mode_setroot.xpm", "sec_mode.hlp", AWM_ALL, makeWindowCallback(sec_mode_event, root, AWT_MODE_SETROOT));
787  awm->create_mode("mode_rotate.xpm", "sec_mode.hlp", AWM_ALL, makeWindowCallback(sec_mode_event, root, AWT_MODE_ROTATE));
788  awm->create_mode("mode_stretch.xpm", "sec_mode.hlp", AWM_ALL, makeWindowCallback(sec_mode_event, root, AWT_MODE_STRETCH));
789  awm->create_mode("mode_edit.xpm", "sec_mode.hlp", AWM_ALL, makeWindowCallback(sec_mode_event, root, AWT_MODE_EDIT));
790  awm->create_mode("mode_cursor.xpm", "sec_mode.hlp", AWM_ALL, makeWindowCallback(sec_mode_event, root, AWT_MODE_CURSOR));
791  awm->create_mode("mode_pinfo.xpm", "sec_mode.hlp", AWM_ALL, makeWindowCallback(sec_mode_event, root, AWT_MODE_PINFO));
792 
793  awm->set_info_area_height(250);
794  awm->at(5, 2);
795  awm->auto_space(0, -2);
796 
797  awm->button_length(0);
798  awm->help_text("quit.hlp");
799  awm->callback(AW_POPDOWN);
800  awm->create_button("Close", "#quit.xpm"); // use quit button, cause users regard secedit as separate program
801 
803  awm->help_text("arb_secedit.hlp");
804  awm->create_button("HELP", "#help.xpm");
805 
806  awm->callback(makeWindowCallback(SEC_undo_cb, db, GB_UNDO_UNDO));
807  awm->help_text("undo.hlp");
808  awm->create_button("Undo", "#undo.xpm");
809 
810  awm->callback(makeWindowCallback(SEC_undo_cb, db, GB_UNDO_REDO));
811  awm->help_text("undo.hlp");
812  awm->create_button("Redo", "#redo.xpm");
813 
814  awm->callback(makeWindowCallback(SEC_toggle_cb, db));
815  awm->help_text("sec_main.hlp");
816  awm->create_button("Toggle", "Toggle");
817 
818  awm->callback(makeWindowCallback(SEC_center_cb, root));
819  awm->help_text("sec_main.hlp");
820  awm->create_button("Center", "Center");
821 
822  awm->callback(makeWindowCallback(SEC_fit_window_cb, db));
823  awm->help_text("sec_main.hlp");
824  awm->create_button("fitWindow", "Fit");
825 
826  awm->at_newline();
827 
828  {
830 
833  awm->at_newline();
834  awm->restore_at_from(*maxSize);
835  }
836 
838 
839  return awm;
840 }
841 
static void sec_mode_event(AW_window *aws, SEC_root *sec_root, AWT_COMMAND_MODE mode)
Definition: SEC_main.cxx:195
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
void nail_position(size_t absPos)
Definition: SEC_main.cxx:52
#define AWAR_SECEDIT_SHOW_CURPOS
Definition: SEC_db.hxx:41
AW_window * AW_create_gc_window_named(AW_root *aw_root, AW_gc_manager *gcman, const char *wid, const char *windowname)
Definition: AW_preset.cxx:1323
AW::Vector transform(const AW::Vector &vec) const
Definition: aw_device.hxx:144
virtual void clear(AW_bitset filteri)
Definition: AW_device.cxx:313
#define INSERT_PAIR_FIELDS(label, pairname)
const char * GB_ERROR
Definition: arb_core.h:25
#define AWAR_SECEDIT_SKELETON_THICKNESS
Definition: SEC_db.hxx:33
static AW_window * SEC_importExport(AW_root *root, bool export_to_file, const SEC_db_interface *db)
Definition: SEC_main.cxx:418
static void SEC_rename_structure(AW_window *, const SEC_db_interface *db)
Definition: SEC_main.cxx:449
static void export_structure_to_file(AW_window *, const SEC_db_interface *db)
Definition: SEC_main.cxx:247
void invalidate_base_count()
Definition: SEC_layout.cxx:266
bool empty() const
bool has_xString() const
Definition: SEC_root.hxx:760
GB_ERROR GB_commit_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2551
void button_length(int length)
Definition: AW_at.cxx:283
AWT_COMMAND_MODE
Definition: awt_canvas.hxx:25
bool valid() const
void request_zoom_reset()
Definition: awt_canvas.hxx:364
AW_device * get_device(AW_area area)
Definition: AW_window.cxx:537
static void import_structure_from_file(AW_window *, const SEC_db_interface *db)
Definition: SEC_main.cxx:336
const AW_screen_area & get_area_size() const
Definition: AW_device.cxx:57
GBDATA * gbmain() const
Definition: SEC_db.hxx:162
bool getLine(string &line)
#define MODE_TEXT_2BUTTONS(modeName, leftInfo, rightInfo)
Definition: mode_text.h:28
const SEC_db_interface * get_db() const
Definition: SEC_root.hxx:747
void update_display_as_requested(AWT_canvas *scr, bool perform_refresh)
Definition: awt_canvas.hxx:444
void insert_menu_topic(const char *id, const char *name, const char *mnemonic, const char *help_text_, AW_active mask, const WindowCallback &wcb)
Definition: AW_window.cxx:595
void GB_atclose_callback(GBDATA *gbd, const DatabaseCallback &atClose)
Definition: ad_cb.cxx:458
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:720
const char * get_window_id() const
Definition: aw_window.hxx:366
static const int SCALER_WIDTH
#define AWAR_SECEDIT_DISPLAY_SEARCH
Definition: SEC_db.hxx:43
void request_refresh()
Definition: awt_canvas.hxx:362
void GB_unlink_or_warn(const char *path, GB_ERROR *error)
Definition: arb_file.cxx:206
char * buildStructureString()
Definition: SEC_io.cxx:108
void nail_cursor()
Definition: SEC_main.cxx:59
void at(int x, int y)
Definition: AW_at.cxx:93
size_t get_x_string_length() const
Definition: SEC_abspos.hxx:72
AWT_canvas * canvas() const
Definition: SEC_db.hxx:165
void AW_create_standard_fileselection(AW_window *aws, const char *awar_prefix)
Definition: aw_file.hxx:30
SyncColors
Definition: SEC_main.cxx:517
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
const BI_helix * get_helixDef() const
Definition: SEC_root.hxx:750
void create_default_bone()
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:202
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
static AW_window * SEC_create_bonddef_window(AW_root *awr)
Definition: SEC_main.cxx:551
void init(SEC_graphic *gfx, AWT_canvas *scr, ED4_plugin_host &host)
#define AWAR_FOOTER_MAX_LEN
char * SEC_xstring_to_foldedHelixList(const char *x_string, size_t xlength, const BI_helix *helix, GB_ERROR &error)
Definition: SEC_helix.cxx:51
static void SEC_center_cb(AW_window *, SEC_root *root)
Definition: SEC_main.cxx:186
static void SEC_sync_colors(AW_window *aww, SyncColors which)
Definition: SEC_main.cxx:525
#define AWAR_SECEDIT_BOND_THICKNESS
Definition: SEC_db.hxx:34
const LineVector & get_last_drawed_cursor_position() const
Definition: SEC_root.hxx:842
void AWT_popup_sec_export_window(AW_window *parent_win, AWT_canvas *scr)
Definition: AWT_canio.cxx:810
SEC_structure_toggler * structure() const
Definition: SEC_db.hxx:169
GB_UNDO_TYPE
Definition: arbdb.h:107
AW_window * start_SECEDIT_plugin(ED4_plugin_host &host)
Definition: SEC_main.cxx:735
int create_mode(const char *pixmap, const char *help_text_, AW_active mask, const WindowCallback &cb)
Definition: AW_window.cxx:2973
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
#define MODE_TEXT_STANDARD_ZOOMMODE()
Definition: mode_text.h:35
#define AWAR_FOOTER
static void SEC_undo_cb(AW_window *, const SEC_db_interface *db, GB_UNDO_TYPE undo_type)
Definition: SEC_main.cxx:226
const XString & get_xString() const
Definition: SEC_root.hxx:761
const double & ypos() const
GB_ERROR expectedError(const char *expected)
Definition: SEC_main.cxx:294
char * SEC_foldedHelixList_to_xstring(const char *foldedHelices, size_t xlength, const BI_helix *helix, GB_ERROR &error)
Definition: SEC_helix.cxx:92
Generic smart pointer.
Definition: smartptr.h:149
const char * get_x_string() const
Definition: SEC_abspos.cxx:122
void set_show_constraints(SEC_BASE_TYPE show)
Definition: SEC_root.hxx:839
#define MODE_TEXT_1BUTTON(modeName, leftInfo)
Definition: mode_text.h:27
string lineError(const string &msg) const
#define AWAR_SECEDIT_SHOW_STR_SKELETON
Definition: SEC_db.hxx:38
#define AWAR_SECEDIT_SAVEDIR
Definition: SEC_db.hxx:30
SEC_graphic * graphic() const
Definition: SEC_db.hxx:163
void create_menu(const char *name, const char *mnemonic, AW_active mask=AWM_ALL)
Definition: AW_window.cxx:472
void help_text(const char *id)
Definition: AW_window.cxx:116
SEC_loop * get_root_loop() const
Definition: SEC_root.hxx:835
const SEC_region * get_region() const
Definition: SEC_root.hxx:304
static void error(const char *msg)
Definition: mkptypes.cxx:96
#define AWAR_SECEDIT_HIDE_BASES
Definition: SEC_db.hxx:39
void init(AW_root *root, const char *wid, const char *windowname, int width, int height)
Definition: AW_window.cxx:2389
static void SEC_exit(GBDATA *, SEC_root *sec_root)
Definition: SEC_main.cxx:726
void restore_at_from(const AW_at_storage &stored)
Definition: aw_window.hxx:551
fputc('\n', stderr)
virtual GBDATA * get_database() const =0
#define AWAR_SECEDIT_SHOW_DEBUG
Definition: SEC_db.hxx:35
#define AWAR_SECEDIT_SHOW_ECOLI_POS
Definition: SEC_db.hxx:37
bool perform_autoscroll()
Definition: SEC_main.cxx:74
#define ASS_EOF
Definition: SEC_main.cxx:245
SEC_root * secroot() const
Definition: SEC_db.cxx:497
static AW_window * SEC_create_display_window(AW_root *awr)
Definition: SEC_main.cxx:622
const double & y() const
const Position & drawn_after(size_t abspos, size_t *after_abs) const
void AW_copy_GC_colors(AW_root *aw_root, const char *source_gcman, const char *dest_gcman, const char *id0,...)
Definition: AW_preset.cxx:1090
char * read_string() const
Definition: AW_awar.cxx:198
size_t getLength() const
Definition: SEC_abspos.hxx:57
#define AWAR_SECEDIT_SHOW_BONDS
Definition: SEC_db.hxx:40
#define AWAR_SECEDIT_SHOW_HELIX_NRS
Definition: SEC_db.hxx:36
#define AWAR_SECEDIT_DIST_BETW_STRANDS
Definition: SEC_db.hxx:32
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
const char * no_mode_text_defined()
Definition: mode_text.h:38
static string scanToken(LineReader &file, string &rest, GB_ERROR &error)
Definition: SEC_main.cxx:306
int getCount() const
Definition: SEC_toggle.hxx:51
static AW_window_menu_modes_opengl * awm
static AW_at_storage * make(AW_window *aww, AW_at_storage_type type)
Definition: AW_at.cxx:444
AW_root * awroot() const
Definition: SEC_db.hxx:161
GB_ERROR GB_undo(GBDATA *gb_main, GB_UNDO_TYPE type) __ATTR__USERESULT
Definition: adindex.cxx:752
bool aw_ask_sure(const char *unique_id, const char *msg)
SEC_base_part * next()
Definition: SEC_root.hxx:301
int aw_question(const char *unique_id, const char *question, const char *buttons, bool sameSizeButtons, const char *helpfile)
Definition: AW_question.cxx:26
void set_info_area_height(int height)
Definition: AW_window.cxx:796
AWT_graphic * gfx
Definition: awt_canvas.hxx:339
fputs(TRACE_PREFIX, stderr)
GB_ERROR GB_export_errorf(const char *templat,...)
Definition: arb_msg.cxx:261
void set_mode(AWT_COMMAND_MODE mo)
Definition: awt_canvas.hxx:382
void scroll(int delta_x, int delta_y, bool dont_update_scrollbars=false)
Definition: AWT_canvas.cxx:703
static void SEC_toggle_cb(AW_window *, const SEC_db_interface *db)
Definition: SEC_main.cxx:179
void auto_space(int xspace, int yspace)
Definition: AW_at.cxx:259
void AW_help_entry_pressed(AW_window *aww)
Definition: AW_root.cxx:37
static AWT_config_mapping_def secedit_display_config_mapping[]
Definition: SEC_main.cxx:595
AW_gc_manager * gc_manager
Definition: awt_canvas.hxx:341
void add_autoscroll(const Vector &scroll)
Definition: SEC_main.cxx:69
GB_ERROR expectContent(LineReader &file, const char *expected)
Definition: SEC_main.cxx:297
GB_ERROR copyTo(const char *name)
Definition: SEC_toggle.cxx:173
static void SEC_new_structure(AW_window *, const SEC_db_interface *db)
Definition: SEC_main.cxx:461
void AWT_popup_print_window(AW_window *parent_win, AWT_canvas *scr)
Definition: AWT_canio.cxx:863
#define AWAR_SECEDIT_DISPLAY_SAI
Definition: SEC_db.hxx:42
AWT_graphic_exports exports
Definition: awt_canvas.hxx:249
void init_device(AW_device *device)
Definition: AWT_canvas.cxx:106
void init_toggler() const
Definition: SEC_db.cxx:537
#define AWAR_SECEDIT_DISPPOS_ECOLI
Definition: SEC_db.hxx:45
static void SEC_delete_structure(AW_window *, const SEC_db_interface *db)
Definition: SEC_main.cxx:501
const char * GBS_static_string(const char *str)
Definition: arb_msg.cxx:211
#define abs(x)
Definition: f2c.h:151
#define ASS_EOS
Definition: SEC_main.cxx:244
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
const Position * drawn_at(size_t abs) const
AW_root * get_root()
Definition: aw_window.hxx:350
const double & xpos() const
void invalidate_base_positions()
Definition: SEC_main.cxx:36
char * old_decode_xstring_rel_helix(GB_CSTR rel_helix, size_t xlength, const BI_helix *helix, int *no_of_helices_ptr)
Definition: SEC_helix.cxx:139
static int line
Definition: arb_a2ps.c:296
#define NULp
Definition: cxxforward.h:114
int & get_modifying_flag_ref()
Definition: awt_canvas.hxx:143
const char * name()
Definition: SEC_toggle.cxx:213
GB_ERROR write_string(const char *aw_string)
void sep______________()
Definition: AW_window.cxx:753
void position_cursor(bool toCenter, bool evenIfVisible)
Definition: SEC_main.cxx:140
static void SEC_fit_window_cb(AW_window *, const SEC_db_interface *db)
Definition: SEC_main.cxx:190
void callback(const WindowCallback &cb)
Definition: AW_window.cxx:133
int get_at_yposition() const
Definition: AW_at.cxx:300
GBDATA * gb_main
Definition: adname.cxx:33
static GB_ERROR expectToken(LineReader &file, const char *token, string &content)
Definition: SEC_main.cxx:329
#define ASS_START
Definition: SEC_main.cxx:243
AW_window * aww
Definition: awt_canvas.hxx:337
char * aw_input(const char *title, const char *prompt, const char *default_input)
Definition: AW_modal.cxx:251
static AW_window * SEC_create_gc_window(AW_root *awr, AW_gc_manager *gcman)
Definition: SEC_main.cxx:731
#define sec_assert(cond)
Definition: SEC_defs.hxx:19
#define INSERT_PAIR_MAPPING(pairname)
Definition: SEC_main.cxx:591
void at_newline()
Definition: AW_at.cxx:119
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
const double & x() const
virtual AW_root * get_application_root() const =0
#define AWAR_SECEDIT_DISPPOS_BINDING
Definition: SEC_db.hxx:44
void request_resize()
Definition: awt_canvas.hxx:363
void create_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, const char *color=NULp)
Definition: AW_button.cxx:448