| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : ED4_no_class.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #include <ed4_extern.hxx> |
|---|
| 12 | |
|---|
| 13 | #include "ed4_awars.hxx" |
|---|
| 14 | #include "ed4_class.hxx" |
|---|
| 15 | #include "ed4_edit_string.hxx" |
|---|
| 16 | #include "ed4_nds.hxx" |
|---|
| 17 | #include "ed4_list.hxx" |
|---|
| 18 | #include "ed4_seq_colors.hxx" |
|---|
| 19 | #include "ed4_flags.hxx" |
|---|
| 20 | |
|---|
| 21 | #include <iupac.h> |
|---|
| 22 | #include <consensus_config.h> |
|---|
| 23 | #include <item_sel_list.h> |
|---|
| 24 | #include <macros.hxx> |
|---|
| 25 | |
|---|
| 26 | #include <awt.hxx> |
|---|
| 27 | #include <awt_config_manager.hxx> |
|---|
| 28 | #include <awt_misc.hxx> |
|---|
| 29 | #include <awt_sel_boxes.hxx> |
|---|
| 30 | |
|---|
| 31 | #include <aw_awars.hxx> |
|---|
| 32 | #include <AW_helix.hxx> |
|---|
| 33 | #include <aw_msg.hxx> |
|---|
| 34 | #include <AW_rename.hxx> |
|---|
| 35 | #include <aw_root.hxx> |
|---|
| 36 | |
|---|
| 37 | #include <ad_config.h> |
|---|
| 38 | |
|---|
| 39 | #include <arb_defs.h> |
|---|
| 40 | #include <arb_global_defs.h> |
|---|
| 41 | #include <arb_progress.h> |
|---|
| 42 | |
|---|
| 43 | #include <cctype> |
|---|
| 44 | #include <limits.h> |
|---|
| 45 | |
|---|
| 46 | #include <vector> |
|---|
| 47 | |
|---|
| 48 | using namespace std; |
|---|
| 49 | |
|---|
| 50 | struct group_folding { |
|---|
| 51 | int max_depth; // maximum group level (root-group has level 0) |
|---|
| 52 | int max_visible; // max visible group level (even if folded) |
|---|
| 53 | int max_unfolded; // max visible unfolded group level |
|---|
| 54 | |
|---|
| 55 | group_folding() : |
|---|
| 56 | max_depth(0), |
|---|
| 57 | max_visible(0), |
|---|
| 58 | max_unfolded(0) |
|---|
| 59 | {} |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | static ARB_ERROR update_group_folding(ED4_base *base, group_folding *folding) { |
|---|
| 63 | if (base->is_group_manager()) { |
|---|
| 64 | int group_level = base->calc_group_depth()+1; |
|---|
| 65 | folding->max_depth = std::max(folding->max_depth, group_level); |
|---|
| 66 | |
|---|
| 67 | bool is_folded = base->has_property(PROP_IS_FOLDED); |
|---|
| 68 | if (group_level>folding->max_visible || (group_level>folding->max_unfolded && !is_folded)) { // may change other maxima? |
|---|
| 69 | bool is_visible = !base->is_hidden(); |
|---|
| 70 | if (is_visible) { |
|---|
| 71 | folding->max_visible = std::max(folding->max_visible, group_level); |
|---|
| 72 | if (!is_folded) { |
|---|
| 73 | folding->max_unfolded = std::max(folding->max_unfolded, group_level); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | return NULp; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | static void calculate_group_folding(group_folding& folding) { |
|---|
| 82 | if (ED4_ROOT->main_manager) { |
|---|
| 83 | ED4_ROOT->main_manager->route_down_hierarchy(makeED4_route_cb(update_group_folding, &folding)).expect_no_error(); |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | void ED4_calc_terminal_extentions() { |
|---|
| 88 | ED4_ROOT->recalc_font_group(); |
|---|
| 89 | |
|---|
| 90 | AW_device *device = ED4_ROOT->first_window->get_device(); // any device |
|---|
| 91 | |
|---|
| 92 | const AW_font_group& font_group = ED4_ROOT->font_group; |
|---|
| 93 | const AW_font_limits& seq_font_limits = font_group.get_limits(ED4_G_SEQUENCES); |
|---|
| 94 | const AW_font_limits& seq_equal_limits = device->get_font_limits(ED4_G_SEQUENCES, '='); |
|---|
| 95 | const AW_font_limits& info_font_limits = font_group.get_limits(ED4_G_STANDARD); |
|---|
| 96 | |
|---|
| 97 | int info_char_width = info_font_limits.width; |
|---|
| 98 | int seq_term_descent; |
|---|
| 99 | |
|---|
| 100 | if (ED4_ROOT->helix->is_enabled() || ED4_ROOT->protstruct) { // display helix ? |
|---|
| 101 | ED4_ROOT->helix_spacing = |
|---|
| 102 | seq_equal_limits.ascent // the ascent of '=' |
|---|
| 103 | + ED4_ROOT->helix_add_spacing; // xtra user-defined spacing |
|---|
| 104 | |
|---|
| 105 | seq_term_descent = ED4_ROOT->helix_spacing; |
|---|
| 106 | } |
|---|
| 107 | else { |
|---|
| 108 | ED4_ROOT->helix_spacing = 0; |
|---|
| 109 | seq_term_descent = seq_font_limits.descent; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | // for wanted_seq_term_height ignore descent, because it additionally allocates 'ED4_ROOT->helix_spacing' space: |
|---|
| 113 | int wanted_seq_term_height = seq_font_limits.ascent + seq_term_descent + ED4_ROOT->terminal_add_spacing; |
|---|
| 114 | int wanted_seq_info_height = info_font_limits.get_height() + ED4_ROOT->terminal_add_spacing; |
|---|
| 115 | |
|---|
| 116 | TERMINAL_HEIGHT = (wanted_seq_term_height>wanted_seq_info_height) ? wanted_seq_term_height : wanted_seq_info_height; |
|---|
| 117 | |
|---|
| 118 | { |
|---|
| 119 | group_folding folding; |
|---|
| 120 | calculate_group_folding(folding); |
|---|
| 121 | |
|---|
| 122 | int maxbrackets = folding.max_unfolded; |
|---|
| 123 | int maxchars = ED4_get_NDS_width(); |
|---|
| 124 | |
|---|
| 125 | #if defined(DEBUG) |
|---|
| 126 | fprintf(stderr, "maxbrackets=%i\n", maxbrackets); |
|---|
| 127 | #endif |
|---|
| 128 | |
|---|
| 129 | MAXNAME_WIDTH = |
|---|
| 130 | (maxchars+1+1)*info_char_width + // width defined in NDS window (+ 1 char for marked-box; + 1 extra char to avoid truncation) |
|---|
| 131 | maxbrackets*BRACKET_WIDTH; // brackets defined in NDS window |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | { |
|---|
| 135 | SpeciesFlags& flags = SpeciesFlags::mutable_instance(); |
|---|
| 136 | int headerlen = flags.get_header_length(); |
|---|
| 137 | |
|---|
| 138 | if (headerlen) { |
|---|
| 139 | flags.calculate_header_dimensions(device, ED4_G_FLAG_INFO); |
|---|
| 140 | FLAG_WIDTH = flags.get_pixel_width(); |
|---|
| 141 | } |
|---|
| 142 | else { |
|---|
| 143 | FLAG_WIDTH = 0; |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | MAXINFO_WIDTH = |
|---|
| 148 | CHARACTEROFFSET + |
|---|
| 149 | info_char_width*ED4_ROOT->aw_root->awar(ED4_AWAR_NDS_INFO_WIDTH)->read_int() + |
|---|
| 150 | 1; // + 1 extra char to avoid truncation |
|---|
| 151 | |
|---|
| 152 | INFO_TERM_TEXT_YOFFSET = info_font_limits.ascent - 1; |
|---|
| 153 | SEQ_TERM_TEXT_YOFFSET = seq_font_limits.ascent - 1; |
|---|
| 154 | |
|---|
| 155 | if (INFO_TERM_TEXT_YOFFSET<SEQ_TERM_TEXT_YOFFSET) INFO_TERM_TEXT_YOFFSET = SEQ_TERM_TEXT_YOFFSET; |
|---|
| 156 | |
|---|
| 157 | #if defined(DEBUG) && 0 |
|---|
| 158 | printf("seq_term_descent = %i\n", seq_term_descent); |
|---|
| 159 | printf("TERMINAL_HEIGHT = %i\n", TERMINAL_HEIGHT); |
|---|
| 160 | printf("MAXNAME_WIDTH = %i\n", MAXNAME_WIDTH); |
|---|
| 161 | printf("FLAG_WIDTH = %i\n", FLAG_WIDTH); |
|---|
| 162 | printf("MAXINFO_WIDTH = %i\n", MAXINFO_WIDTH); |
|---|
| 163 | printf("INFO_TERM_TEXT_YOFFSET= %i\n", INFO_TERM_TEXT_YOFFSET); |
|---|
| 164 | printf(" SEQ_TERM_TEXT_YOFFSET= %i\n", SEQ_TERM_TEXT_YOFFSET); |
|---|
| 165 | #endif // DEBUG |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | bool ED4_flag_header_terminal::set_dynamic_size() { |
|---|
| 169 | return extension.set_size_does_change(WIDTH, FLAG_WIDTH); |
|---|
| 170 | } |
|---|
| 171 | bool ED4_flag_terminal::set_dynamic_size() { |
|---|
| 172 | return extension.set_size_does_change(WIDTH, FLAG_WIDTH); |
|---|
| 173 | } |
|---|
| 174 | bool ED4_species_name_terminal::set_dynamic_size() { |
|---|
| 175 | return extension.set_size_does_change(WIDTH, MAXNAME_WIDTH - BRACKET_WIDTH * calc_group_depth()); |
|---|
| 176 | } |
|---|
| 177 | bool ED4_sequence_info_terminal::set_dynamic_size() { |
|---|
| 178 | return extension.set_size_does_change(WIDTH, MAXINFO_WIDTH); |
|---|
| 179 | } |
|---|
| 180 | bool ED4_line_terminal::set_dynamic_size() { |
|---|
| 181 | // dynamically adapt to ref_terminals |
|---|
| 182 | |
|---|
| 183 | AW_pos overall_width = |
|---|
| 184 | TREE_TERMINAL_WIDTH + |
|---|
| 185 | MAXNAME_WIDTH + |
|---|
| 186 | ED4_ROOT->ref_terminals.sequence_info()->extension.size[WIDTH] + |
|---|
| 187 | ED4_ROOT->ref_terminals.sequence()->extension.size[WIDTH]; |
|---|
| 188 | |
|---|
| 189 | return extension.set_size_does_change(WIDTH, overall_width); |
|---|
| 190 | } |
|---|
| 191 | bool ED4_spacer_terminal::set_dynamic_size() { |
|---|
| 192 | if (!has_property(PROP_DYNA_RESIZE)) return false; // some spacer terminals never change their size (eg. bottom-spacer) |
|---|
| 193 | |
|---|
| 194 | AW_pos new_height = SPACER_HEIGHT; |
|---|
| 195 | |
|---|
| 196 | if (parent->is_device_manager()) { |
|---|
| 197 | if (this == ED4_ROOT->main_manager->get_top_middle_spacer_terminal()) { |
|---|
| 198 | ED4_terminal *top_middle_line_terminal = ED4_ROOT->main_manager->get_top_middle_line_terminal(); |
|---|
| 199 | |
|---|
| 200 | // top-middle spacer + top-middle line >= font-size (otherwise scrolling relicts!) |
|---|
| 201 | new_height = TERMINAL_HEIGHT - top_middle_line_terminal->extension.size[HEIGHT]; |
|---|
| 202 | } |
|---|
| 203 | else { |
|---|
| 204 | new_height = 1; // use minimal height for other top-group spacers |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | else { |
|---|
| 208 | ED4_manager *grandpa = parent->parent; |
|---|
| 209 | e4_assert(grandpa); |
|---|
| 210 | |
|---|
| 211 | if (grandpa->is_group_manager()) { |
|---|
| 212 | ED4_group_manager *group_man = grandpa->to_group_manager(); |
|---|
| 213 | if (group_man->has_property(PROP_IS_FOLDED)) { |
|---|
| 214 | if (!AW_root::SINGLETON->awar(ED4_AWAR_CONSENSUS_SHOW)->read_int()) { |
|---|
| 215 | new_height = SPACER_NOCONS_HEIGHT; |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | return extension.set_size_does_change(HEIGHT, new_height); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | static ARB_ERROR update_extension_size(ED4_base *base) { |
|---|
| 225 | base->resize_dynamic(); |
|---|
| 226 | return NULp; // doesn't fail |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | void ED4_resize_all_extensions() { // @@@ pass flag to force resize-request? (eg. for initial-call?) |
|---|
| 230 | ED4_calc_terminal_extentions(); |
|---|
| 231 | |
|---|
| 232 | // @@@ below calculations have to be done at startup as well (are they done somewhere else or not done?) |
|---|
| 233 | |
|---|
| 234 | ED4_ROOT->ref_terminals.sequence()->extension.size[HEIGHT] = TERMINAL_HEIGHT; |
|---|
| 235 | ED4_ROOT->ref_terminals.sequence_info()->extension.size[HEIGHT] = TERMINAL_HEIGHT; |
|---|
| 236 | ED4_ROOT->ref_terminals.sequence_info()->extension.size[WIDTH] = MAXINFO_WIDTH; |
|---|
| 237 | |
|---|
| 238 | int screenwidth = ED4_ROOT->root_group_man->remap()->shown_sequence_to_screen(MAXSEQUENCECHARACTERLENGTH); |
|---|
| 239 | while (1) { |
|---|
| 240 | ED4_ROOT->ref_terminals.sequence()->extension.size[WIDTH] = ED4_ROOT->font_group.get_width(ED4_G_SEQUENCES) * (screenwidth+3); |
|---|
| 241 | |
|---|
| 242 | ED4_ROOT->main_manager->route_down_hierarchy(makeED4_route_cb(update_extension_size)).expect_no_error(); |
|---|
| 243 | |
|---|
| 244 | ED4_ROOT->resize_all_requesting_childs(); // Note: may change mapping |
|---|
| 245 | |
|---|
| 246 | int new_screenwidth = ED4_ROOT->root_group_man->remap()->shown_sequence_to_screen(MAXSEQUENCECHARACTERLENGTH); |
|---|
| 247 | if (new_screenwidth == screenwidth) { // mapping did not change |
|---|
| 248 | break; |
|---|
| 249 | } |
|---|
| 250 | screenwidth = new_screenwidth; |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | static ARB_ERROR call_edit(ED4_base *object, const ED4_work_info *work_info) { |
|---|
| 255 | // called after editing consensus to edit single sequences |
|---|
| 256 | GB_ERROR error = NULp; |
|---|
| 257 | |
|---|
| 258 | if (object->is_species_seq_terminal()) { |
|---|
| 259 | int expected_prop = PROP_CURSOR_ALLOWED|PROP_ALIGNMENT_DATA; |
|---|
| 260 | |
|---|
| 261 | if ((object->dynamic_prop & expected_prop) == expected_prop) { |
|---|
| 262 | ED4_work_info new_work_info; |
|---|
| 263 | |
|---|
| 264 | new_work_info.event = work_info->event; |
|---|
| 265 | new_work_info.char_position = work_info->char_position; |
|---|
| 266 | new_work_info.out_seq_position = work_info->out_seq_position; |
|---|
| 267 | new_work_info.refresh_needed = false; |
|---|
| 268 | new_work_info.cursor_jump = ED4_JUMP_KEEP_VISIBLE; |
|---|
| 269 | new_work_info.out_string = NULp; |
|---|
| 270 | new_work_info.mode = work_info->mode; |
|---|
| 271 | new_work_info.rightward = work_info->rightward; |
|---|
| 272 | new_work_info.cannot_handle = false; |
|---|
| 273 | new_work_info.is_sequence = work_info->is_sequence; |
|---|
| 274 | new_work_info.working_terminal = object->to_terminal(); |
|---|
| 275 | |
|---|
| 276 | if (object->get_species_pointer()) { |
|---|
| 277 | new_work_info.gb_data = object->get_species_pointer(); |
|---|
| 278 | new_work_info.string = NULp; |
|---|
| 279 | } |
|---|
| 280 | else { |
|---|
| 281 | new_work_info.gb_data = NULp; |
|---|
| 282 | new_work_info.string = object->id; // @@@ looks obsolete (see [8402] for previous code) |
|---|
| 283 | e4_assert(0); // assume we never come here |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | new_work_info.repeat_count = 1; |
|---|
| 287 | |
|---|
| 288 | { |
|---|
| 289 | ED4_Edit_String editString; |
|---|
| 290 | error = editString.edit(&new_work_info); |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | e4_assert(error || !new_work_info.out_string); |
|---|
| 294 | |
|---|
| 295 | if (new_work_info.refresh_needed) { |
|---|
| 296 | object->request_refresh(); |
|---|
| 297 | if (object->is_sequence_terminal()) { |
|---|
| 298 | ED4_sequence_terminal *seq_term = object->to_sequence_terminal(); |
|---|
| 299 | seq_term->results().searchAgain(); |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | if (move_cursor) { |
|---|
| 304 | current_cursor().jump_sequence_pos(new_work_info.out_seq_position, ED4_JUMP_KEEP_VISIBLE); |
|---|
| 305 | move_cursor = 0; |
|---|
| 306 | } |
|---|
| 307 | } |
|---|
| 308 | } |
|---|
| 309 | return error; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | static int get_max_slider_xpos() { |
|---|
| 313 | const AW_screen_area& rect = current_device()->get_area_size(); |
|---|
| 314 | |
|---|
| 315 | AW_pos x, y; |
|---|
| 316 | ED4_base *horizontal_link = ED4_ROOT->scroll_links.link_for_hor_slider; |
|---|
| 317 | horizontal_link->calc_world_coords(&x, &y); |
|---|
| 318 | |
|---|
| 319 | AW_pos max_xpos = horizontal_link->extension.size[WIDTH] // overall width of virtual scrolling area |
|---|
| 320 | - (rect.r - x); // minus width of visible scroll-area (== relative width of horizontal scrollbar) |
|---|
| 321 | |
|---|
| 322 | if (max_xpos<0) max_xpos = 0; // happens when window-content is smaller than window (e.g. if (folded) alignment is narrow) |
|---|
| 323 | return int(max_xpos+0.5); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | static int get_max_slider_ypos() { |
|---|
| 327 | const AW_screen_area& rect = current_device()->get_area_size(); |
|---|
| 328 | |
|---|
| 329 | AW_pos x, y; |
|---|
| 330 | ED4_base *vertical_link = ED4_ROOT->scroll_links.link_for_ver_slider; |
|---|
| 331 | vertical_link->calc_world_coords(&x, &y); |
|---|
| 332 | |
|---|
| 333 | AW_pos max_ypos = vertical_link->extension.size[HEIGHT] // overall height of virtual scrolling area |
|---|
| 334 | - (rect.b - y); // minus height of visible scroll-area (== relative height of vertical scrollbar) |
|---|
| 335 | |
|---|
| 336 | if (max_ypos<0) max_ypos = 0; // happens when window-content is smaller than window (e.g. if ARB_EDIT4 is not filled) |
|---|
| 337 | return int(max_ypos+0.5); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | static void ed4_scroll(AW_window *aww, int xdiff, int ydiff, bool use_scroll_speed) { |
|---|
| 341 | if (use_scroll_speed) { |
|---|
| 342 | xdiff = xdiff * ED4_ROOT->aw_root->awar(ED4_AWAR_SCROLL_SPEED_X)->read_int() / 10; |
|---|
| 343 | ydiff = ydiff * ED4_ROOT->aw_root->awar(ED4_AWAR_SCROLL_SPEED_Y)->read_int() / 10; |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | int new_xpos = aww->slider_pos_horizontal + xdiff; |
|---|
| 347 | int new_ypos = aww->slider_pos_vertical + ydiff; |
|---|
| 348 | |
|---|
| 349 | if (xdiff<0) { // scroll left |
|---|
| 350 | if (new_xpos<0) new_xpos = 0; |
|---|
| 351 | } |
|---|
| 352 | else if (xdiff>0) { // scroll right |
|---|
| 353 | int max_xpos = get_max_slider_xpos(); |
|---|
| 354 | if (max_xpos<0) max_xpos = 0; |
|---|
| 355 | if (new_xpos>max_xpos) new_xpos = max_xpos; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | if (ydiff<0) { // scroll up |
|---|
| 359 | if (new_ypos<0) new_ypos = 0; |
|---|
| 360 | } |
|---|
| 361 | else if (ydiff>0) { // scroll down |
|---|
| 362 | int max_ypos = get_max_slider_ypos(); |
|---|
| 363 | if (max_ypos<0) max_ypos = 0; |
|---|
| 364 | if (new_ypos>max_ypos) new_ypos = max_ypos; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | if (new_xpos!=aww->slider_pos_horizontal) { |
|---|
| 368 | aww->set_horizontal_scrollbar_position(new_xpos); |
|---|
| 369 | ED4_horizontal_change_cb(aww); |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | if (new_ypos!=aww->slider_pos_vertical) { |
|---|
| 373 | aww->set_vertical_scrollbar_position(new_ypos); |
|---|
| 374 | ED4_vertical_change_cb(aww); |
|---|
| 375 | } |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | static void scrollHalfPage(bool backwards, bool horizontal) { |
|---|
| 379 | ED4_window *e4w = current_ed4w(); |
|---|
| 380 | AW::Rectangle scrolledArea = e4w->scrolled_rect.get_window_rect(); |
|---|
| 381 | |
|---|
| 382 | double fdist = horizontal ? scrolledArea.width() : scrolledArea.height(); |
|---|
| 383 | int dist = int(fdist/2 + 0.5); |
|---|
| 384 | |
|---|
| 385 | if (backwards) dist = -dist; |
|---|
| 386 | |
|---|
| 387 | ed4_scroll(e4w->aww, horizontal ? dist : 0, horizontal ? 0 : dist, false); |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | static void executeKeystroke(AW_event *event, int repeatCount) { |
|---|
| 391 | e4_assert(repeatCount>0); |
|---|
| 392 | |
|---|
| 393 | if (event->keycode == AW_KEY_PGUP || event->keycode == AW_KEY_PGDN) { |
|---|
| 394 | scrollHalfPage(event->keycode == AW_KEY_PGUP, event->keymodifier & AW_KEYMODE_ALT); |
|---|
| 395 | } |
|---|
| 396 | else if (event->keycode!=AW_KEY_NONE) { |
|---|
| 397 | ED4_cursor *cursor = ¤t_cursor(); |
|---|
| 398 | if (cursor->owner_of_cursor && !cursor->owner_of_cursor->flag.hidden) { |
|---|
| 399 | GBDATA *gb_main = ED4_ROOT->get_gb_main(); |
|---|
| 400 | if (event->keycode == AW_KEY_UP || event->keycode == AW_KEY_DOWN || |
|---|
| 401 | ((event->keymodifier & AW_KEYMODE_CONTROL) && |
|---|
| 402 | (event->keycode == AW_KEY_HOME || event->keycode == AW_KEY_END))) |
|---|
| 403 | { |
|---|
| 404 | GB_transaction ta(gb_main); |
|---|
| 405 | while (repeatCount--) { |
|---|
| 406 | cursor->move_cursor(event); |
|---|
| 407 | } |
|---|
| 408 | } |
|---|
| 409 | else { |
|---|
| 410 | // @@@ move into separate function? |
|---|
| 411 | |
|---|
| 412 | ED4_work_info work_info; |
|---|
| 413 | |
|---|
| 414 | work_info.cannot_handle = false; |
|---|
| 415 | work_info.event = *event; |
|---|
| 416 | work_info.char_position = cursor->get_screen_pos(); |
|---|
| 417 | work_info.out_seq_position = cursor->get_sequence_pos(); |
|---|
| 418 | work_info.refresh_needed = false; |
|---|
| 419 | work_info.cursor_jump = ED4_JUMP_KEEP_VISIBLE; |
|---|
| 420 | work_info.out_string = NULp; // nur falls new malloc |
|---|
| 421 | work_info.repeat_count = repeatCount; |
|---|
| 422 | |
|---|
| 423 | ED4_terminal *terminal = cursor->owner_of_cursor; |
|---|
| 424 | e4_assert(terminal->is_text_terminal()); |
|---|
| 425 | |
|---|
| 426 | work_info.working_terminal = terminal; |
|---|
| 427 | |
|---|
| 428 | if (terminal->is_sequence_terminal()) { |
|---|
| 429 | work_info.mode = awar_edit_mode; |
|---|
| 430 | work_info.rightward = awar_edit_rightward; |
|---|
| 431 | work_info.is_sequence = 1; |
|---|
| 432 | } |
|---|
| 433 | else { |
|---|
| 434 | work_info.rightward = true; |
|---|
| 435 | work_info.is_sequence = 0; |
|---|
| 436 | |
|---|
| 437 | if (terminal->is_pure_text_terminal()) { |
|---|
| 438 | work_info.mode = awar_edit_mode; |
|---|
| 439 | } |
|---|
| 440 | else if (terminal->is_columnStat_terminal()) { |
|---|
| 441 | work_info.mode = AD_NOWRITE; |
|---|
| 442 | } |
|---|
| 443 | else { |
|---|
| 444 | e4_assert(0); |
|---|
| 445 | } |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | work_info.string = NULp; |
|---|
| 449 | work_info.gb_data = NULp; |
|---|
| 450 | |
|---|
| 451 | if (terminal->get_species_pointer()) { |
|---|
| 452 | work_info.gb_data = terminal->get_species_pointer(); |
|---|
| 453 | } |
|---|
| 454 | else if (terminal->is_columnStat_terminal()) { |
|---|
| 455 | work_info.gb_data = terminal->to_columnStat_terminal()->corresponding_sequence_terminal()->get_species_pointer(); |
|---|
| 456 | } |
|---|
| 457 | else { |
|---|
| 458 | e4_assert(terminal->is_consensus_terminal()); |
|---|
| 459 | ED4_consensus_sequence_terminal *cterm = terminal->to_consensus_sequence_terminal(); |
|---|
| 460 | work_info.string = cterm->temp_cons_seq; |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | ED4_Edit_String editString; |
|---|
| 464 | ARB_ERROR error = NULp; |
|---|
| 465 | |
|---|
| 466 | GB_push_transaction(gb_main); |
|---|
| 467 | |
|---|
| 468 | if (terminal->is_consensus_terminal()) { |
|---|
| 469 | ED4_consensus_sequence_terminal *cterm = terminal->to_consensus_sequence_terminal(); |
|---|
| 470 | ED4_group_manager *group_manager = terminal->get_parent(LEV_GROUP)->to_group_manager(); |
|---|
| 471 | |
|---|
| 472 | e4_assert(!cterm->temp_cons_seq); |
|---|
| 473 | work_info.string = cterm->temp_cons_seq = group_manager->build_consensus_string(); |
|---|
| 474 | |
|---|
| 475 | error = editString.edit(&work_info); |
|---|
| 476 | |
|---|
| 477 | cursor->jump_sequence_pos(work_info.out_seq_position, ED4_JUMP_KEEP_VISIBLE); |
|---|
| 478 | |
|---|
| 479 | work_info.string = NULp; |
|---|
| 480 | |
|---|
| 481 | if (work_info.cannot_handle) { |
|---|
| 482 | e4_assert(!error); // see ED4_Edit_String::edit() |
|---|
| 483 | move_cursor = 1; |
|---|
| 484 | error = group_manager->route_down_hierarchy(makeED4_route_cb(call_edit, &work_info)); |
|---|
| 485 | group_manager->rebuild_consensi(group_manager, ED4_U_UP_DOWN); |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | freenull(cterm->temp_cons_seq); |
|---|
| 489 | } |
|---|
| 490 | else { |
|---|
| 491 | error = editString.edit(&work_info); |
|---|
| 492 | cursor->jump_sequence_pos(work_info.out_seq_position, work_info.cursor_jump); |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | editString.finish_edit(); |
|---|
| 496 | |
|---|
| 497 | if (error) work_info.refresh_needed = true; |
|---|
| 498 | |
|---|
| 499 | GB_end_transaction_show_error(gb_main, error, aw_message); |
|---|
| 500 | |
|---|
| 501 | if (work_info.refresh_needed) { |
|---|
| 502 | GB_transaction ta(gb_main); |
|---|
| 503 | |
|---|
| 504 | terminal->request_refresh(); |
|---|
| 505 | if (terminal->is_sequence_terminal()) { |
|---|
| 506 | ED4_sequence_terminal *seq_term = terminal->to_sequence_terminal(); |
|---|
| 507 | seq_term->results().searchAgain(); |
|---|
| 508 | } |
|---|
| 509 | } |
|---|
| 510 | } |
|---|
| 511 | } |
|---|
| 512 | } |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | void ED4_remote_event(AW_event *faked_event) { // keystrokes forwarded from SECEDIT |
|---|
| 516 | ED4_MostRecentWinContext context; |
|---|
| 517 | executeKeystroke(faked_event, 1); |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | void ED4_input_cb(AW_window *aww) { |
|---|
| 521 | AW_event event; |
|---|
| 522 | static AW_event lastEvent; |
|---|
| 523 | static int repeatCount; |
|---|
| 524 | |
|---|
| 525 | ED4_LocalWinContext uses(aww); |
|---|
| 526 | |
|---|
| 527 | aww->get_event(&event); |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | #if defined(DEBUG) && 0 |
|---|
| 531 | printf("event.type=%i event.keycode=%i event.character='%c' event.keymodifier=%i\n", event.type, event.keycode, event.character, event.keymodifier); |
|---|
| 532 | #endif |
|---|
| 533 | |
|---|
| 534 | switch (event.type) { |
|---|
| 535 | case AW_Keyboard_Press: { |
|---|
| 536 | if (repeatCount==0) { // first key event? |
|---|
| 537 | lastEvent = event; |
|---|
| 538 | repeatCount = 1; |
|---|
| 539 | } |
|---|
| 540 | else { |
|---|
| 541 | if (lastEvent.keycode==event.keycode && |
|---|
| 542 | lastEvent.character==event.character && |
|---|
| 543 | lastEvent.keymodifier==event.keymodifier) { // same key as last? |
|---|
| 544 | repeatCount++; |
|---|
| 545 | } |
|---|
| 546 | else { // other key => execute now |
|---|
| 547 | executeKeystroke(&lastEvent, repeatCount); |
|---|
| 548 | lastEvent = event; |
|---|
| 549 | repeatCount = 1; |
|---|
| 550 | } |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | if (repeatCount) { |
|---|
| 554 | #if defined(DARWIN) || 1 |
|---|
| 555 | // sth goes wrong with OSX -> always execute keystroke |
|---|
| 556 | // Xfree 4.3 has problems as well, so repeat counting is disabled completely |
|---|
| 557 | executeKeystroke(&lastEvent, repeatCount); |
|---|
| 558 | repeatCount = 0; |
|---|
| 559 | #else |
|---|
| 560 | AW_ProcessEventType nextEventType = ED4_ROOT->aw_root->peek_key_event(aww); |
|---|
| 561 | |
|---|
| 562 | if (nextEventType!=KEY_RELEASED) { // no key waiting => execute now |
|---|
| 563 | executeKeystroke(&lastEvent, repeatCount); |
|---|
| 564 | repeatCount = 0; |
|---|
| 565 | } |
|---|
| 566 | #endif |
|---|
| 567 | } |
|---|
| 568 | break; |
|---|
| 569 | } |
|---|
| 570 | case AW_Keyboard_Release: { |
|---|
| 571 | AW_ProcessEventType nextEventType = ED4_ROOT->aw_root->peek_key_event(aww); |
|---|
| 572 | |
|---|
| 573 | if (nextEventType!=KEY_PRESSED && repeatCount) { // no key follows => execute keystrokes (if any) |
|---|
| 574 | executeKeystroke(&lastEvent, repeatCount); |
|---|
| 575 | repeatCount = 0; |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | break; |
|---|
| 579 | } |
|---|
| 580 | default: { |
|---|
| 581 | if (event.button == AW_WHEEL_UP || event.button == AW_WHEEL_DOWN) { |
|---|
| 582 | if (event.type == AW_Mouse_Press) { |
|---|
| 583 | bool horizontal = event.keymodifier & AW_KEYMODE_ALT; |
|---|
| 584 | int direction = event.button == AW_WHEEL_UP ? -1 : 1; |
|---|
| 585 | |
|---|
| 586 | int dx = horizontal ? direction*ED4_ROOT->font_group.get_max_width() : 0; |
|---|
| 587 | int dy = horizontal ? 0 : direction*ED4_ROOT->font_group.get_max_height(); |
|---|
| 588 | |
|---|
| 589 | ed4_scroll(aww, dx, dy, true); |
|---|
| 590 | } |
|---|
| 591 | return; |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | if (event.button == AW_BUTTON_MIDDLE) { |
|---|
| 595 | if (event.type == AW_Mouse_Press) { |
|---|
| 596 | ED4_ROOT->scroll_picture.scroll = 1; |
|---|
| 597 | ED4_ROOT->scroll_picture.old_y = event.y; |
|---|
| 598 | ED4_ROOT->scroll_picture.old_x = event.x; |
|---|
| 599 | return; |
|---|
| 600 | } |
|---|
| 601 | if (event.type == AW_Mouse_Release) { |
|---|
| 602 | ED4_ROOT->scroll_picture.scroll = 0; |
|---|
| 603 | return; |
|---|
| 604 | } |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | #if defined(DEBUG) && 0 |
|---|
| 608 | if (event.button==AW_BUTTON_LEFT) { |
|---|
| 609 | printf("[ED4_input_cb] type=%i x=%i y=%i ", (int)event.type, (int)event.x, (int)event.y); |
|---|
| 610 | } |
|---|
| 611 | #endif |
|---|
| 612 | |
|---|
| 613 | AW_pos win_x = event.x; |
|---|
| 614 | AW_pos win_y = event.y; |
|---|
| 615 | current_ed4w()->win_to_world_coords(&(win_x), &(win_y)); |
|---|
| 616 | event.x = (int) win_x; |
|---|
| 617 | event.y = (int) win_y; |
|---|
| 618 | |
|---|
| 619 | #if defined(DEBUG) && 0 |
|---|
| 620 | if (event.button==AW_BUTTON_LEFT) { |
|---|
| 621 | printf("-> x=%i y=%i\n", (int)event.type, (int)event.x, (int)event.y); |
|---|
| 622 | } |
|---|
| 623 | #endif |
|---|
| 624 | |
|---|
| 625 | GB_transaction ta(ED4_ROOT->get_gb_main()); |
|---|
| 626 | ED4_ROOT->main_manager->event_sent_by_parent(&event, aww); |
|---|
| 627 | break; |
|---|
| 628 | } |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | ED4_trigger_instant_refresh(); |
|---|
| 632 | } |
|---|
| 633 | |
|---|
| 634 | void ED4_vertical_change_cb(AW_window *aww) { |
|---|
| 635 | ED4_LocalWinContext uses(aww); |
|---|
| 636 | |
|---|
| 637 | ED4_window *win = current_ed4w(); |
|---|
| 638 | { |
|---|
| 639 | GB_transaction ta(ED4_ROOT->get_gb_main()); |
|---|
| 640 | |
|---|
| 641 | int old_slider_pos = win->slider_pos_vertical; |
|---|
| 642 | |
|---|
| 643 | { // correct slider_pos if necessary |
|---|
| 644 | int max_slider_ypos = get_max_slider_ypos(); |
|---|
| 645 | |
|---|
| 646 | if (aww->slider_pos_vertical>max_slider_ypos) aww->set_vertical_scrollbar_position(max_slider_ypos); |
|---|
| 647 | if (aww->slider_pos_vertical<0) aww->set_vertical_scrollbar_position(0); |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | int slider_diff = aww->slider_pos_vertical - old_slider_pos; |
|---|
| 651 | |
|---|
| 652 | win->coords.window_upper_clip_point += slider_diff; |
|---|
| 653 | win->coords.window_lower_clip_point += slider_diff; |
|---|
| 654 | |
|---|
| 655 | win->scroll_rectangle(0, -slider_diff); |
|---|
| 656 | win->slider_pos_vertical = aww->slider_pos_vertical; |
|---|
| 657 | } |
|---|
| 658 | win->update_window_coords(); |
|---|
| 659 | } |
|---|
| 660 | |
|---|
| 661 | void ED4_horizontal_change_cb(AW_window *aww) { |
|---|
| 662 | ED4_LocalWinContext uses(aww); |
|---|
| 663 | |
|---|
| 664 | ED4_window *win = current_ed4w(); |
|---|
| 665 | { |
|---|
| 666 | GB_transaction ta(ED4_ROOT->get_gb_main()); |
|---|
| 667 | |
|---|
| 668 | int old_slider_pos = win->slider_pos_horizontal; |
|---|
| 669 | |
|---|
| 670 | { // correct slider_pos if necessary |
|---|
| 671 | int max_slider_xpos = get_max_slider_xpos(); |
|---|
| 672 | |
|---|
| 673 | if (aww->slider_pos_horizontal>max_slider_xpos) aww->set_horizontal_scrollbar_position(max_slider_xpos); |
|---|
| 674 | if (aww->slider_pos_horizontal<0) aww->set_horizontal_scrollbar_position(0); |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | int slider_diff = aww->slider_pos_horizontal - old_slider_pos; |
|---|
| 678 | |
|---|
| 679 | win->coords.window_left_clip_point += slider_diff; |
|---|
| 680 | win->coords.window_right_clip_point += slider_diff; |
|---|
| 681 | |
|---|
| 682 | win->scroll_rectangle(-slider_diff, 0); |
|---|
| 683 | win->slider_pos_horizontal = aww->slider_pos_horizontal; |
|---|
| 684 | } |
|---|
| 685 | win->update_window_coords(); |
|---|
| 686 | } |
|---|
| 687 | |
|---|
| 688 | void ED4_scrollbar_change_cb(AW_window *aww) { |
|---|
| 689 | ED4_LocalWinContext uses(aww); |
|---|
| 690 | |
|---|
| 691 | ED4_window *win = current_ed4w(); |
|---|
| 692 | { |
|---|
| 693 | GB_transaction ta(ED4_ROOT->get_gb_main()); |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | int old_hslider_pos = win->slider_pos_horizontal; |
|---|
| 697 | int old_vslider_pos = win->slider_pos_vertical; |
|---|
| 698 | |
|---|
| 699 | { |
|---|
| 700 | // correct slider_pos if necessary |
|---|
| 701 | int max_slider_xpos = get_max_slider_xpos(); |
|---|
| 702 | int max_slider_ypos = get_max_slider_ypos(); |
|---|
| 703 | |
|---|
| 704 | if (aww->slider_pos_horizontal>max_slider_xpos) aww->set_horizontal_scrollbar_position(max_slider_xpos); |
|---|
| 705 | if (aww->slider_pos_horizontal<0) aww->set_horizontal_scrollbar_position(0); |
|---|
| 706 | |
|---|
| 707 | if (aww->slider_pos_vertical>max_slider_ypos) aww->set_vertical_scrollbar_position(max_slider_ypos); |
|---|
| 708 | if (aww->slider_pos_vertical<0) aww->set_vertical_scrollbar_position(0); |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | int slider_hdiff = aww->slider_pos_horizontal - old_hslider_pos; |
|---|
| 712 | int slider_vdiff = aww->slider_pos_vertical - old_vslider_pos; |
|---|
| 713 | |
|---|
| 714 | ED4_coords *coords = &win->coords; |
|---|
| 715 | coords->window_left_clip_point += slider_hdiff; |
|---|
| 716 | coords->window_right_clip_point += slider_hdiff; |
|---|
| 717 | coords->window_upper_clip_point += slider_vdiff; |
|---|
| 718 | coords->window_lower_clip_point += slider_vdiff; |
|---|
| 719 | |
|---|
| 720 | win->scroll_rectangle(-slider_hdiff, -slider_vdiff); |
|---|
| 721 | |
|---|
| 722 | win->slider_pos_vertical = aww->slider_pos_vertical; |
|---|
| 723 | win->slider_pos_horizontal = aww->slider_pos_horizontal; |
|---|
| 724 | } |
|---|
| 725 | win->update_window_coords(); |
|---|
| 726 | } |
|---|
| 727 | |
|---|
| 728 | void ED4_motion_cb(AW_window *aww) { |
|---|
| 729 | AW_event event; |
|---|
| 730 | |
|---|
| 731 | ED4_LocalWinContext uses(aww); |
|---|
| 732 | |
|---|
| 733 | aww->get_event(&event); |
|---|
| 734 | |
|---|
| 735 | if (event.type == AW_Mouse_Drag && event.button == AW_BUTTON_MIDDLE) { |
|---|
| 736 | if (ED4_ROOT->scroll_picture.scroll) { |
|---|
| 737 | int xdiff = ED4_ROOT->scroll_picture.old_x - event.x; |
|---|
| 738 | int ydiff = ED4_ROOT->scroll_picture.old_y - event.y; |
|---|
| 739 | |
|---|
| 740 | ed4_scroll(aww, xdiff, ydiff, true); |
|---|
| 741 | |
|---|
| 742 | ED4_ROOT->scroll_picture.old_x = event.x; |
|---|
| 743 | ED4_ROOT->scroll_picture.old_y = event.y; |
|---|
| 744 | } |
|---|
| 745 | } |
|---|
| 746 | else { |
|---|
| 747 | |
|---|
| 748 | #if defined(DEBUG) && 0 |
|---|
| 749 | if (event.button==AW_BUTTON_LEFT) { |
|---|
| 750 | printf("[ED4_motion_cb] type=%i x=%i y=%i ", (int)event.type, (int)event.x, (int)event.y); |
|---|
| 751 | } |
|---|
| 752 | #endif |
|---|
| 753 | |
|---|
| 754 | AW_pos win_x = event.x; |
|---|
| 755 | AW_pos win_y = event.y; |
|---|
| 756 | current_ed4w()->win_to_world_coords(&win_x, &win_y); |
|---|
| 757 | event.x = (int) win_x; |
|---|
| 758 | event.y = (int) win_y; |
|---|
| 759 | |
|---|
| 760 | #if defined(DEBUG) && 0 |
|---|
| 761 | if (event.button==AW_BUTTON_LEFT) { |
|---|
| 762 | printf("-> x=%i y=%i\n", (int)event.type, (int)event.x, (int)event.y); |
|---|
| 763 | } |
|---|
| 764 | #endif |
|---|
| 765 | |
|---|
| 766 | GB_transaction ta(ED4_ROOT->get_gb_main()); |
|---|
| 767 | ED4_ROOT->main_manager->event_sent_by_parent(&event, aww); |
|---|
| 768 | } |
|---|
| 769 | } |
|---|
| 770 | |
|---|
| 771 | void ED4_remote_set_cursor_cb(AW_root *awr) { |
|---|
| 772 | AW_awar *awar = awr->awar(AWAR_SET_CURSOR_POSITION); |
|---|
| 773 | long pos = awar->read_int(); |
|---|
| 774 | |
|---|
| 775 | if (pos != -1) { |
|---|
| 776 | ED4_MostRecentWinContext context; |
|---|
| 777 | ED4_cursor *cursor = ¤t_cursor(); |
|---|
| 778 | cursor->jump_sequence_pos(pos, ED4_JUMP_CENTERED); |
|---|
| 779 | awar->write_int(-1); |
|---|
| 780 | } |
|---|
| 781 | } |
|---|
| 782 | |
|---|
| 783 | void ED4_jump_to_cursor_position(AW_window *aww, const char *awar_name, PositionType posType) { |
|---|
| 784 | ED4_LocalWinContext uses(aww); |
|---|
| 785 | ED4_cursor *cursor = ¤t_cursor(); |
|---|
| 786 | GB_ERROR error = NULp; |
|---|
| 787 | |
|---|
| 788 | long pos = aww->get_root()->awar(awar_name)->read_int(); |
|---|
| 789 | |
|---|
| 790 | if (pos>0) pos = bio2info(pos); |
|---|
| 791 | else if (pos<0) { // jump negative (count from back) |
|---|
| 792 | int last_pos = -1; // [1..] |
|---|
| 793 | |
|---|
| 794 | switch (posType) { |
|---|
| 795 | case ED4_POS_SEQUENCE: { |
|---|
| 796 | last_pos = MAXSEQUENCECHARACTERLENGTH; |
|---|
| 797 | break; |
|---|
| 798 | } |
|---|
| 799 | case ED4_POS_ECOLI: { |
|---|
| 800 | BI_ecoli_ref *ecoli = ED4_ROOT->ecoli_ref; |
|---|
| 801 | if (ecoli->gotData()) { |
|---|
| 802 | last_pos = ecoli->abs_2_rel(INT_MAX); |
|---|
| 803 | } |
|---|
| 804 | else { |
|---|
| 805 | last_pos = 0; // doesnt matter (error below) |
|---|
| 806 | } |
|---|
| 807 | break; |
|---|
| 808 | } |
|---|
| 809 | case ED4_POS_BASE: { |
|---|
| 810 | last_pos = cursor->sequence2base_position(INT_MAX); |
|---|
| 811 | break; |
|---|
| 812 | } |
|---|
| 813 | } |
|---|
| 814 | |
|---|
| 815 | e4_assert(last_pos != -1); |
|---|
| 816 | pos = bio2info(last_pos+1+pos); |
|---|
| 817 | } |
|---|
| 818 | |
|---|
| 819 | switch (posType) { |
|---|
| 820 | case ED4_POS_SEQUENCE: { |
|---|
| 821 | e4_assert(strcmp(awar_name, current_ed4w()->awar_path_for_cursor)==0); |
|---|
| 822 | break; |
|---|
| 823 | } |
|---|
| 824 | case ED4_POS_ECOLI: { |
|---|
| 825 | e4_assert(strcmp(awar_name, current_ed4w()->awar_path_for_Ecoli)==0); |
|---|
| 826 | |
|---|
| 827 | BI_ecoli_ref *ecoli = ED4_ROOT->ecoli_ref; |
|---|
| 828 | if (ecoli->gotData()) pos = ecoli->rel_2_abs(pos); |
|---|
| 829 | else error = "No ecoli reference"; |
|---|
| 830 | break; |
|---|
| 831 | } |
|---|
| 832 | case ED4_POS_BASE: { |
|---|
| 833 | e4_assert(strcmp(awar_name, current_ed4w()->awar_path_for_basePos)==0); |
|---|
| 834 | pos = cursor->base2sequence_position(pos); |
|---|
| 835 | break; |
|---|
| 836 | } |
|---|
| 837 | } |
|---|
| 838 | |
|---|
| 839 | // now position is absolute [0..N-1] |
|---|
| 840 | |
|---|
| 841 | // limit to screen |
|---|
| 842 | { |
|---|
| 843 | ED4_remap *remap = ED4_ROOT->root_group_man->remap(); |
|---|
| 844 | long max = remap->screen_to_sequence(remap->get_max_screen_pos()); |
|---|
| 845 | |
|---|
| 846 | if (pos > max) pos = max; |
|---|
| 847 | else if (pos<0) pos = 0; |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | if (error) { |
|---|
| 851 | aw_message(error); |
|---|
| 852 | } |
|---|
| 853 | else { |
|---|
| 854 | cursor->jump_sequence_pos(pos, ED4_JUMP_CENTERED); |
|---|
| 855 | } |
|---|
| 856 | } |
|---|
| 857 | |
|---|
| 858 | void ED4_set_helixnr(AW_window *aww, const char *awar_name) { |
|---|
| 859 | ED4_LocalWinContext uses(aww); |
|---|
| 860 | ED4_cursor *cursor = ¤t_cursor(); |
|---|
| 861 | |
|---|
| 862 | if (cursor->owner_of_cursor) { |
|---|
| 863 | AW_root *root = aww->get_root(); |
|---|
| 864 | char *helix_nr = root->awar(awar_name)->read_string(); |
|---|
| 865 | BI_helix *helix = ED4_ROOT->helix; |
|---|
| 866 | |
|---|
| 867 | if (helix->has_entries()) { |
|---|
| 868 | long pos = helix->first_position(helix_nr); |
|---|
| 869 | |
|---|
| 870 | if (pos == -1) { |
|---|
| 871 | aw_message(GBS_global_string("No helix '%s' found", helix_nr)); |
|---|
| 872 | } |
|---|
| 873 | else { |
|---|
| 874 | cursor->jump_sequence_pos(pos, ED4_JUMP_CENTERED); |
|---|
| 875 | } |
|---|
| 876 | } |
|---|
| 877 | else { |
|---|
| 878 | aw_message("Got no helix information"); |
|---|
| 879 | } |
|---|
| 880 | free(helix_nr); |
|---|
| 881 | } |
|---|
| 882 | } |
|---|
| 883 | |
|---|
| 884 | void ED4_set_iupac(AW_window *aww, const char *awar_name) { |
|---|
| 885 | ED4_LocalWinContext uses(aww); |
|---|
| 886 | ED4_cursor *cursor = ¤t_cursor(); |
|---|
| 887 | |
|---|
| 888 | if (cursor->owner_of_cursor) { |
|---|
| 889 | if (cursor->in_consensus_terminal()) { |
|---|
| 890 | aw_message("You cannot change the consensus"); |
|---|
| 891 | } |
|---|
| 892 | else { |
|---|
| 893 | int len; |
|---|
| 894 | char *seq = cursor->owner_of_cursor->resolve_pointer_to_string_copy(&len); |
|---|
| 895 | int seq_pos = cursor->get_sequence_pos(); |
|---|
| 896 | |
|---|
| 897 | e4_assert(seq); |
|---|
| 898 | |
|---|
| 899 | if (seq_pos<len) { |
|---|
| 900 | char *iupac = ED4_ROOT->aw_root->awar(awar_name)->read_string(); |
|---|
| 901 | char new_char = iupac::encode(iupac, ED4_ROOT->alignment_type); |
|---|
| 902 | |
|---|
| 903 | seq[seq_pos] = new_char; |
|---|
| 904 | cursor->owner_of_cursor->write_sequence(seq, len); |
|---|
| 905 | |
|---|
| 906 | free(iupac); |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | free(seq); |
|---|
| 910 | } |
|---|
| 911 | } |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | void ED4_exit() { |
|---|
| 915 | // @@@ most of the code here could be placed in ED4_ROOT-dtor |
|---|
| 916 | |
|---|
| 917 | GBDATA *gb_main = ED4_ROOT->get_gb_main(); |
|---|
| 918 | ED4_ROOT->aw_root->unlink_awars_from_DB(gb_main); |
|---|
| 919 | |
|---|
| 920 | ED4_window *ed4w = ED4_ROOT->first_window; |
|---|
| 921 | |
|---|
| 922 | while (ed4w) { |
|---|
| 923 | ed4w->aww->hide(); |
|---|
| 924 | ed4w->cursor.prepare_shutdown(); // removes any callbacks |
|---|
| 925 | ed4w = ed4w->next; |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | while (ED4_ROOT->first_window) { |
|---|
| 929 | ED4_ROOT->first_window->delete_window(ED4_ROOT->first_window); |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | shutdown_macro_recording(ED4_ROOT->aw_root); |
|---|
| 933 | delete ED4_ROOT; |
|---|
| 934 | |
|---|
| 935 | #if defined(DEBUG) |
|---|
| 936 | AWT_browser_forget_db(gb_main); |
|---|
| 937 | #endif // DEBUG |
|---|
| 938 | GB_close(gb_main); |
|---|
| 939 | |
|---|
| 940 | ::exit(EXIT_SUCCESS); |
|---|
| 941 | } |
|---|
| 942 | |
|---|
| 943 | void ED4_quit_editor(AW_window *aww) { |
|---|
| 944 | ED4_LocalWinContext uses(aww); // @@@ dont use context here |
|---|
| 945 | |
|---|
| 946 | if (ED4_ROOT->first_window == current_ed4w()) { // quit button has been pressed in first window |
|---|
| 947 | ED4_exit(); |
|---|
| 948 | } |
|---|
| 949 | // case : in another window close has been pressed |
|---|
| 950 | current_aww()->hide(); |
|---|
| 951 | current_ed4w()->is_hidden = true; |
|---|
| 952 | } |
|---|
| 953 | |
|---|
| 954 | static int timer_calls = 0; |
|---|
| 955 | static int timer_calls_triggered = 0; |
|---|
| 956 | |
|---|
| 957 | static unsigned ED4_timer(AW_root *) { |
|---|
| 958 | timer_calls++; |
|---|
| 959 | |
|---|
| 960 | #if defined(TRACE_REFRESH) |
|---|
| 961 | fprintf(stderr, "ED4_timer\n"); fflush(stderr); |
|---|
| 962 | #endif |
|---|
| 963 | GBDATA *gb_main = ED4_ROOT->get_gb_main(); |
|---|
| 964 | |
|---|
| 965 | // get all changes from server |
|---|
| 966 | GB_begin_transaction(gb_main); |
|---|
| 967 | GB_tell_server_dont_wait(gb_main); |
|---|
| 968 | GB_commit_transaction(gb_main); |
|---|
| 969 | |
|---|
| 970 | ED4_ROOT->refresh_all_windows(0); |
|---|
| 971 | |
|---|
| 972 | if (timer_calls == timer_calls_triggered) { |
|---|
| 973 | timer_calls_triggered++; |
|---|
| 974 | return 2000; // trigger callback after 2s |
|---|
| 975 | } |
|---|
| 976 | return 0; // do not trigger callback |
|---|
| 977 | } |
|---|
| 978 | |
|---|
| 979 | void ED4_trigger_instant_refresh() { |
|---|
| 980 | #if defined(TRACE_REFRESH) |
|---|
| 981 | fprintf(stderr, "ED4_trigger_instant_refresh\n"); fflush(stderr); |
|---|
| 982 | #endif |
|---|
| 983 | timer_calls_triggered++; |
|---|
| 984 | ED4_ROOT->aw_root->add_timed_callback(1, makeTimedCallback(ED4_timer)); // trigger instant callback |
|---|
| 985 | } |
|---|
| 986 | void ED4_request_full_refresh() { |
|---|
| 987 | ED4_ROOT->main_manager->request_refresh(); |
|---|
| 988 | } |
|---|
| 989 | void ED4_request_full_instant_refresh() { |
|---|
| 990 | ED4_request_full_refresh(); |
|---|
| 991 | ED4_trigger_instant_refresh(); |
|---|
| 992 | } |
|---|
| 993 | |
|---|
| 994 | void ED4_request_relayout() { |
|---|
| 995 | ED4_resize_all_extensions(); |
|---|
| 996 | ED4_ROOT->main_manager->request_resize(); |
|---|
| 997 | ED4_trigger_instant_refresh(); |
|---|
| 998 | } |
|---|
| 999 | |
|---|
| 1000 | #define SIGNIFICANT_FIELD_CHARS 30 // length used to compare field contents (in createGroupFromSelected) |
|---|
| 1001 | |
|---|
| 1002 | static void createGroupFromSelected(GB_CSTR group_name, GB_CSTR field_name, GB_CSTR field_content) { |
|---|
| 1003 | // creates a new group named group_name |
|---|
| 1004 | // if field_name==0 -> all selected species & subgroups are moved to this new group |
|---|
| 1005 | // if field_name!=0 -> all selected species containing field_content in field field_name are moved to this new group |
|---|
| 1006 | |
|---|
| 1007 | ED4_multi_species_manager *top_multi_species_manager = ED4_ROOT->top_area_man->get_multi_species_manager(); |
|---|
| 1008 | ED4_multi_species_manager *group_content_manager; |
|---|
| 1009 | ED4_group_manager *new_group_manager = ED4_build_group_manager_start(top_multi_species_manager, group_name, 1, false, ED4_ROOT->ref_terminals, group_content_manager); |
|---|
| 1010 | ED4_build_group_manager_end(group_content_manager); |
|---|
| 1011 | |
|---|
| 1012 | group_content_manager->update_requested_by_child(); |
|---|
| 1013 | |
|---|
| 1014 | ED4_counter++; |
|---|
| 1015 | ED4_base::touch_world_cache(); |
|---|
| 1016 | |
|---|
| 1017 | bool lookingForNoContent = !field_content || field_content[0]==0; |
|---|
| 1018 | |
|---|
| 1019 | ED4_selected_elem *list_elem = ED4_ROOT->selected_objects->head(); |
|---|
| 1020 | while (list_elem) { |
|---|
| 1021 | ED4_base *object = list_elem->elem()->object; |
|---|
| 1022 | object = object->get_parent(LEV_SPECIES); |
|---|
| 1023 | |
|---|
| 1024 | bool move_object = true; |
|---|
| 1025 | if (object->is_consensus_manager()) { |
|---|
| 1026 | object = object->get_parent(LEV_GROUP); |
|---|
| 1027 | if (field_name) move_object = false; // don't move groups if moving by field_name |
|---|
| 1028 | } |
|---|
| 1029 | else { |
|---|
| 1030 | e4_assert(object->is_species_manager()); |
|---|
| 1031 | if (field_name) { |
|---|
| 1032 | GBDATA *gb_species = object->get_species_pointer(); |
|---|
| 1033 | GBDATA *gb_field = GB_search(gb_species, field_name, GB_FIND); |
|---|
| 1034 | |
|---|
| 1035 | move_object = lookingForNoContent; |
|---|
| 1036 | if (gb_field) { // field was found |
|---|
| 1037 | char *found_content = GB_read_as_string(gb_field); |
|---|
| 1038 | if (found_content) { |
|---|
| 1039 | move_object = strncmp(found_content, field_content, SIGNIFICANT_FIELD_CHARS)==0; |
|---|
| 1040 | free(found_content); |
|---|
| 1041 | } |
|---|
| 1042 | } |
|---|
| 1043 | } |
|---|
| 1044 | } |
|---|
| 1045 | |
|---|
| 1046 | if (move_object) { |
|---|
| 1047 | ED4_base *base = object->get_parent(LEV_MULTI_SPECIES); |
|---|
| 1048 | if (base && base->is_multi_species_manager()) { |
|---|
| 1049 | ED4_multi_species_manager *old_multi = base->to_multi_species_manager(); |
|---|
| 1050 | old_multi->invalidate_species_counters(); |
|---|
| 1051 | } |
|---|
| 1052 | |
|---|
| 1053 | object->parent->remove_member(object); |
|---|
| 1054 | group_content_manager->append_member(object); |
|---|
| 1055 | |
|---|
| 1056 | object->parent = group_content_manager; |
|---|
| 1057 | object->set_width(); |
|---|
| 1058 | } |
|---|
| 1059 | |
|---|
| 1060 | list_elem = list_elem->next(); |
|---|
| 1061 | } |
|---|
| 1062 | |
|---|
| 1063 | new_group_manager->create_consensus(new_group_manager, NULp); |
|---|
| 1064 | group_content_manager->invalidate_species_counters(); |
|---|
| 1065 | |
|---|
| 1066 | new_group_manager->fold(); |
|---|
| 1067 | |
|---|
| 1068 | group_content_manager->resize_requested_by_child(); |
|---|
| 1069 | } |
|---|
| 1070 | |
|---|
| 1071 | static void group_species(bool use_field, AW_window *use_as_main_window) { |
|---|
| 1072 | GB_ERROR error = NULp; |
|---|
| 1073 | GBDATA *gb_main = ED4_ROOT->get_gb_main(); |
|---|
| 1074 | GB_push_transaction(gb_main); |
|---|
| 1075 | |
|---|
| 1076 | ED4_LocalWinContext uses(use_as_main_window); |
|---|
| 1077 | |
|---|
| 1078 | if (!use_field) { |
|---|
| 1079 | char *group_name = aw_input("Enter name for new group:"); |
|---|
| 1080 | |
|---|
| 1081 | if (group_name) { |
|---|
| 1082 | if (strlen(group_name)>GB_GROUP_NAME_MAX) { |
|---|
| 1083 | group_name[GB_GROUP_NAME_MAX] = 0; |
|---|
| 1084 | aw_message("Truncated overlong group name"); |
|---|
| 1085 | } |
|---|
| 1086 | createGroupFromSelected(group_name, NULp, NULp); |
|---|
| 1087 | free(group_name); |
|---|
| 1088 | } |
|---|
| 1089 | } |
|---|
| 1090 | else { |
|---|
| 1091 | char *field_name = ED4_ROOT->aw_root->awar(AWAR_FIELD_CHOSEN)->read_string(); |
|---|
| 1092 | char *doneContents = ARB_strdup(";"); |
|---|
| 1093 | size_t doneLen = 1; |
|---|
| 1094 | |
|---|
| 1095 | bool tryAgain = true; |
|---|
| 1096 | bool foundField = false; |
|---|
| 1097 | bool foundSpecies = false; |
|---|
| 1098 | |
|---|
| 1099 | if (strcmp(field_name, NO_FIELD_SELECTED) == 0) { |
|---|
| 1100 | error = "Please select a field to use for grouping."; |
|---|
| 1101 | } |
|---|
| 1102 | |
|---|
| 1103 | while (tryAgain && !error) { |
|---|
| 1104 | tryAgain = false; |
|---|
| 1105 | ED4_selected_elem *list_elem = ED4_ROOT->selected_objects->head(); |
|---|
| 1106 | while (list_elem && !error) { |
|---|
| 1107 | ED4_base *object = list_elem->elem()->object; |
|---|
| 1108 | object = object->get_parent(LEV_SPECIES); |
|---|
| 1109 | if (!object->is_consensus_manager()) { |
|---|
| 1110 | GBDATA *gb_species = object->get_species_pointer(); |
|---|
| 1111 | GBDATA *gb_field = NULp; |
|---|
| 1112 | |
|---|
| 1113 | if (gb_species) { |
|---|
| 1114 | foundSpecies = true; |
|---|
| 1115 | gb_field = GB_search(gb_species, field_name, GB_FIND); |
|---|
| 1116 | } |
|---|
| 1117 | |
|---|
| 1118 | error = GB_incur_error_if(!gb_field); |
|---|
| 1119 | if (!error) { |
|---|
| 1120 | e4_assert(gb_field); |
|---|
| 1121 | char *field_content = GB_read_as_string(gb_field); |
|---|
| 1122 | if (field_content) { |
|---|
| 1123 | size_t field_content_len = strlen(field_content); |
|---|
| 1124 | |
|---|
| 1125 | foundField = true; |
|---|
| 1126 | if (field_content_len>SIGNIFICANT_FIELD_CHARS) { |
|---|
| 1127 | field_content[SIGNIFICANT_FIELD_CHARS] = 0; |
|---|
| 1128 | field_content_len = SIGNIFICANT_FIELD_CHARS; |
|---|
| 1129 | } |
|---|
| 1130 | |
|---|
| 1131 | char with_semi[SIGNIFICANT_FIELD_CHARS+2+1]; |
|---|
| 1132 | sprintf(with_semi, ";%s;", field_content); |
|---|
| 1133 | |
|---|
| 1134 | if (!strstr(doneContents, with_semi)) { // field_content was not used yet |
|---|
| 1135 | createGroupFromSelected(field_content, field_name, field_content); |
|---|
| 1136 | tryAgain = true; |
|---|
| 1137 | |
|---|
| 1138 | int newlen = doneLen + field_content_len + 1; |
|---|
| 1139 | char *newDone = ARB_alloc<char>(newlen+1); |
|---|
| 1140 | |
|---|
| 1141 | GBS_global_string_to_buffer(newDone, newlen+1, "%s%s;", doneContents, field_content); |
|---|
| 1142 | freeset(doneContents, newDone); |
|---|
| 1143 | doneLen = newlen; |
|---|
| 1144 | } |
|---|
| 1145 | free(field_content); |
|---|
| 1146 | } |
|---|
| 1147 | else { |
|---|
| 1148 | error = "Incompatible field type"; |
|---|
| 1149 | } |
|---|
| 1150 | } |
|---|
| 1151 | } |
|---|
| 1152 | list_elem = list_elem->next(); |
|---|
| 1153 | } |
|---|
| 1154 | } |
|---|
| 1155 | |
|---|
| 1156 | if (!error) { |
|---|
| 1157 | if (!foundSpecies) error = "Please select some species in order to insert them into new groups"; |
|---|
| 1158 | else if (!foundField) error = GBS_global_string("Field not found: '%s'%s", field_name, error ? GBS_global_string(" (Reason: %s)", error) : ""); |
|---|
| 1159 | } |
|---|
| 1160 | |
|---|
| 1161 | free(doneContents); |
|---|
| 1162 | free(field_name); |
|---|
| 1163 | } |
|---|
| 1164 | |
|---|
| 1165 | GB_end_transaction_show_error(gb_main, error, aw_message); |
|---|
| 1166 | } |
|---|
| 1167 | |
|---|
| 1168 | static void group_species_by_field_content(AW_window*, AW_window *use_as_main_window, AW_window *window_to_hide) { |
|---|
| 1169 | group_species(true, use_as_main_window); |
|---|
| 1170 | window_to_hide->hide(); |
|---|
| 1171 | } |
|---|
| 1172 | |
|---|
| 1173 | static AW_window *create_group_species_by_field_window(AW_root *aw_root, AW_window *use_as_main_window) { |
|---|
| 1174 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 1175 | |
|---|
| 1176 | aws->init(aw_root, "CREATE_GROUP_USING_FIELD_CONTENT", "Create groups using field"); |
|---|
| 1177 | aws->auto_space(10, 10); |
|---|
| 1178 | |
|---|
| 1179 | aws->button_length(10); |
|---|
| 1180 | aws->at_newline(); |
|---|
| 1181 | |
|---|
| 1182 | aws->callback(AW_POPDOWN); |
|---|
| 1183 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 1184 | |
|---|
| 1185 | aws->callback(makeHelpCallback("group_by_field.hlp")); |
|---|
| 1186 | aws->create_button("HELP", "HELP", "H"); |
|---|
| 1187 | |
|---|
| 1188 | aws->at_newline(); |
|---|
| 1189 | aws->label("Use content of field"); |
|---|
| 1190 | create_itemfield_selection_button(aws, FieldSelDef(AWAR_FIELD_CHOSEN, ED4_ROOT->get_gb_main(), SPECIES_get_selector(), FIELD_FILTER_STRING_READABLE, "group-field"), NULp); |
|---|
| 1191 | |
|---|
| 1192 | aws->at_newline(); |
|---|
| 1193 | aws->callback(makeWindowCallback(group_species_by_field_content, use_as_main_window, static_cast<AW_window*>(aws))); |
|---|
| 1194 | aws->create_autosize_button("USE_FIELD", "Group selected species by content", ""); |
|---|
| 1195 | |
|---|
| 1196 | return aws; |
|---|
| 1197 | } |
|---|
| 1198 | |
|---|
| 1199 | void group_species_cb(AW_window *aww, bool use_fields) { |
|---|
| 1200 | if (!use_fields) { |
|---|
| 1201 | group_species(false, aww); |
|---|
| 1202 | } |
|---|
| 1203 | else { |
|---|
| 1204 | static AW_window *ask_field_window; |
|---|
| 1205 | |
|---|
| 1206 | if (!ask_field_window) ask_field_window = create_group_species_by_field_window(ED4_ROOT->aw_root, aww); |
|---|
| 1207 | ask_field_window->activate(); |
|---|
| 1208 | } |
|---|
| 1209 | } |
|---|
| 1210 | |
|---|
| 1211 | static GB_ERROR ED4_load_new_config(char *name) { |
|---|
| 1212 | GB_ERROR error; |
|---|
| 1213 | GBT_config cfg(ED4_ROOT->get_gb_main(), name, error); |
|---|
| 1214 | if (cfg.exists()) { |
|---|
| 1215 | ED4_ROOT->main_manager->clear_whole_background(); |
|---|
| 1216 | |
|---|
| 1217 | max_seq_terminal_length = 0; |
|---|
| 1218 | |
|---|
| 1219 | ED4_init_notFoundMessage(); |
|---|
| 1220 | |
|---|
| 1221 | if (ED4_ROOT->selected_objects->size() > 0) { |
|---|
| 1222 | ED4_ROOT->deselect_all(); |
|---|
| 1223 | } |
|---|
| 1224 | |
|---|
| 1225 | ED4_ROOT->remove_all_callbacks(); |
|---|
| 1226 | |
|---|
| 1227 | ED4_ROOT->scroll_picture.scroll = 0; |
|---|
| 1228 | ED4_ROOT->scroll_picture.old_x = 0; |
|---|
| 1229 | ED4_ROOT->scroll_picture.old_y = 0; |
|---|
| 1230 | |
|---|
| 1231 | ED4_ROOT->ref_terminals.clear(); |
|---|
| 1232 | |
|---|
| 1233 | for (ED4_window *window = ED4_ROOT->first_window; window; window=window->next) { |
|---|
| 1234 | window->cursor.init(); |
|---|
| 1235 | window->aww->set_horizontal_scrollbar_position (0); |
|---|
| 1236 | window->aww->set_vertical_scrollbar_position (0); |
|---|
| 1237 | } |
|---|
| 1238 | |
|---|
| 1239 | ED4_ROOT->scroll_links.link_for_hor_slider = NULp; |
|---|
| 1240 | ED4_ROOT->scroll_links.link_for_ver_slider = NULp; |
|---|
| 1241 | ED4_ROOT->middle_area_man = NULp; |
|---|
| 1242 | ED4_ROOT->top_area_man = NULp; |
|---|
| 1243 | |
|---|
| 1244 | delete ED4_ROOT->main_manager; |
|---|
| 1245 | ED4_ROOT->main_manager = NULp; |
|---|
| 1246 | delete ED4_ROOT->ecoli_ref; |
|---|
| 1247 | |
|---|
| 1248 | ED4_ROOT->first_window->reset_all_for_new_config(); |
|---|
| 1249 | ED4_ROOT->create_hierarchy(cfg.get_definition(GBT_config::MIDDLE_AREA), cfg.get_definition(GBT_config::TOP_AREA)); |
|---|
| 1250 | } |
|---|
| 1251 | |
|---|
| 1252 | return error; |
|---|
| 1253 | } |
|---|
| 1254 | |
|---|
| 1255 | static ED4_EDITMODE ED4_get_edit_mode(AW_root *root) { |
|---|
| 1256 | if (!root->awar(AWAR_EDIT_MODE)->read_int()) return AD_ALIGN; |
|---|
| 1257 | return root->awar(AWAR_INSERT_MODE)->read_int() ? AD_INSERT : AD_REPLACE; |
|---|
| 1258 | } |
|---|
| 1259 | |
|---|
| 1260 | void ed4_changesecurity(AW_root *root) { |
|---|
| 1261 | ED4_EDITMODE mode = ED4_get_edit_mode(root); |
|---|
| 1262 | const char *awar_name = NULp; |
|---|
| 1263 | |
|---|
| 1264 | switch (mode) { |
|---|
| 1265 | case AD_ALIGN: |
|---|
| 1266 | awar_name = AWAR_EDIT_SECURITY_LEVEL_ALIGN; |
|---|
| 1267 | break; |
|---|
| 1268 | default: |
|---|
| 1269 | awar_name = AWAR_EDIT_SECURITY_LEVEL_CHANGE; |
|---|
| 1270 | } |
|---|
| 1271 | |
|---|
| 1272 | ED4_ROOT->aw_root->awar(AWAR_EDIT_SECURITY_LEVEL)->map(awar_name); |
|---|
| 1273 | |
|---|
| 1274 | long level = ED4_ROOT->aw_root->awar(awar_name)->read_int(); |
|---|
| 1275 | GB_change_my_security(ED4_ROOT->get_gb_main(), level); // change user security in EDIT4 |
|---|
| 1276 | } |
|---|
| 1277 | |
|---|
| 1278 | void ed4_change_edit_mode(AW_root *root) { |
|---|
| 1279 | awar_edit_mode = ED4_get_edit_mode(root); |
|---|
| 1280 | ed4_changesecurity(root); |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | ARB_ERROR rebuild_consensus(ED4_base *object) { |
|---|
| 1284 | if (object->is_consensus_manager()) { |
|---|
| 1285 | ED4_species_manager *spec_man = object->to_species_manager(); |
|---|
| 1286 | spec_man->do_callbacks(); |
|---|
| 1287 | |
|---|
| 1288 | ED4_base *sequence_data_terminal = spec_man->search_spec_child_rek(LEV_SEQUENCE_STRING); |
|---|
| 1289 | sequence_data_terminal->request_refresh(); |
|---|
| 1290 | } |
|---|
| 1291 | return NULp; // needed by route_down_hierarchy |
|---|
| 1292 | } |
|---|
| 1293 | |
|---|
| 1294 | void ED4_new_editor_window(AW_window *aww) { |
|---|
| 1295 | ED4_LocalWinContext uses(aww); |
|---|
| 1296 | |
|---|
| 1297 | AW_device *device; |
|---|
| 1298 | ED4_window *new_window = NULp; |
|---|
| 1299 | |
|---|
| 1300 | if (ED4_ROOT->generate_window(&device, &new_window) != ED4_R_BREAK) { |
|---|
| 1301 | ED4_LocalWinContext now_uses(new_window); |
|---|
| 1302 | |
|---|
| 1303 | new_window->set_scrolled_rectangle(ED4_ROOT->scroll_links.link_for_hor_slider, |
|---|
| 1304 | ED4_ROOT->scroll_links.link_for_ver_slider, |
|---|
| 1305 | ED4_ROOT->scroll_links.link_for_hor_slider, |
|---|
| 1306 | ED4_ROOT->scroll_links.link_for_ver_slider); |
|---|
| 1307 | |
|---|
| 1308 | new_window->aww->show(); |
|---|
| 1309 | new_window->update_scrolled_rectangle(); |
|---|
| 1310 | } |
|---|
| 1311 | } |
|---|
| 1312 | |
|---|
| 1313 | |
|---|
| 1314 | |
|---|
| 1315 | static void ED4_start_editor_on_configuration(AW_window *aww) { |
|---|
| 1316 | aww->hide(); |
|---|
| 1317 | |
|---|
| 1318 | GB_ERROR error; |
|---|
| 1319 | { |
|---|
| 1320 | char *name = aww->get_root()->awar(AWAR_EDIT_CONFIGURATION)->read_string(); |
|---|
| 1321 | error = ED4_load_new_config(name); |
|---|
| 1322 | free(name); |
|---|
| 1323 | } |
|---|
| 1324 | |
|---|
| 1325 | if (error) { |
|---|
| 1326 | aw_message(error); |
|---|
| 1327 | aww->show(); // show old window |
|---|
| 1328 | } |
|---|
| 1329 | } |
|---|
| 1330 | |
|---|
| 1331 | struct cursorpos { |
|---|
| 1332 | RefPtr<ED4_cursor> cursor; |
|---|
| 1333 | int screen_rel; |
|---|
| 1334 | int seq; |
|---|
| 1335 | |
|---|
| 1336 | cursorpos(ED4_window *win) |
|---|
| 1337 | : cursor(&win->cursor), |
|---|
| 1338 | screen_rel(cursor->get_screen_relative_pos()), |
|---|
| 1339 | seq(cursor->get_sequence_pos()) |
|---|
| 1340 | {} |
|---|
| 1341 | }; |
|---|
| 1342 | |
|---|
| 1343 | |
|---|
| 1344 | void ED4_compression_changed_cb(AW_root *awr) { |
|---|
| 1345 | ED4_remap_mode mode = (ED4_remap_mode)awr->awar(ED4_AWAR_COMPRESS_SEQUENCE_TYPE)->read_int(); |
|---|
| 1346 | int percent = awr->awar(ED4_AWAR_COMPRESS_SEQUENCE_PERCENT)->read_int(); |
|---|
| 1347 | GB_transaction ta(ED4_ROOT->get_gb_main()); |
|---|
| 1348 | |
|---|
| 1349 | if (ED4_ROOT->root_group_man) { |
|---|
| 1350 | vector<cursorpos> pos; |
|---|
| 1351 | |
|---|
| 1352 | for (ED4_window *win = ED4_ROOT->first_window; win; win = win->next) { |
|---|
| 1353 | pos.push_back(cursorpos(win)); |
|---|
| 1354 | } |
|---|
| 1355 | |
|---|
| 1356 | ED4_ROOT->root_group_man->remap()->set_mode(mode, percent); |
|---|
| 1357 | ED4_resize_all_extensions(); |
|---|
| 1358 | |
|---|
| 1359 | for (vector<cursorpos>::iterator i = pos.begin(); i != pos.end(); ++i) { |
|---|
| 1360 | ED4_cursor *cursor = i->cursor; |
|---|
| 1361 | ED4_window *win = cursor->window(); |
|---|
| 1362 | |
|---|
| 1363 | win->update_scrolled_rectangle(); // @@@ needed ? |
|---|
| 1364 | |
|---|
| 1365 | cursor->jump_sequence_pos(i->seq, ED4_JUMP_KEEP_POSITION); |
|---|
| 1366 | cursor->set_screen_relative_pos(i->screen_rel); |
|---|
| 1367 | } |
|---|
| 1368 | |
|---|
| 1369 | ED4_request_full_instant_refresh(); |
|---|
| 1370 | } |
|---|
| 1371 | } |
|---|
| 1372 | |
|---|
| 1373 | void ED4_compression_toggle_changed_cb(AW_root *root, bool hideChanged) { |
|---|
| 1374 | int gaps = root->awar(ED4_AWAR_COMPRESS_SEQUENCE_GAPS)->read_int(); |
|---|
| 1375 | int hide = root->awar(ED4_AWAR_COMPRESS_SEQUENCE_HIDE)->read_int(); |
|---|
| 1376 | |
|---|
| 1377 | ED4_remap_mode mode = ED4_remap_mode(root->awar(ED4_AWAR_COMPRESS_SEQUENCE_TYPE)->read_int()); // @@@ mode is overwritten below |
|---|
| 1378 | |
|---|
| 1379 | if (hideChanged) { |
|---|
| 1380 | // ED4_AWAR_COMPRESS_SEQUENCE_HIDE changed |
|---|
| 1381 | if (hide!=0 && gaps!=2) { |
|---|
| 1382 | root->awar(ED4_AWAR_COMPRESS_SEQUENCE_GAPS)->write_int(2); |
|---|
| 1383 | return; |
|---|
| 1384 | } |
|---|
| 1385 | } |
|---|
| 1386 | else { |
|---|
| 1387 | // ED4_AWAR_COMPRESS_SEQUENCE_GAPS changed |
|---|
| 1388 | if (gaps!=2 && hide!=0) { |
|---|
| 1389 | root->awar(ED4_AWAR_COMPRESS_SEQUENCE_HIDE)->write_int(0); |
|---|
| 1390 | return; |
|---|
| 1391 | } |
|---|
| 1392 | } |
|---|
| 1393 | |
|---|
| 1394 | mode = ED4_RM_NONE; |
|---|
| 1395 | switch (gaps) { |
|---|
| 1396 | case 0: mode = ED4_RM_NONE; break; |
|---|
| 1397 | case 1: mode = ED4_RM_DYNAMIC_GAPS; break; |
|---|
| 1398 | case 2: { |
|---|
| 1399 | switch (hide) { |
|---|
| 1400 | case 0: mode = ED4_RM_MAX_ALIGN; break; |
|---|
| 1401 | case 1: mode = ED4_RM_SHOW_ABOVE; break; |
|---|
| 1402 | default: e4_assert(0); break; |
|---|
| 1403 | } |
|---|
| 1404 | break; |
|---|
| 1405 | } |
|---|
| 1406 | default: e4_assert(0); break; |
|---|
| 1407 | } |
|---|
| 1408 | |
|---|
| 1409 | root->awar(ED4_AWAR_COMPRESS_SEQUENCE_TYPE)->write_int(int(mode)); |
|---|
| 1410 | } |
|---|
| 1411 | |
|---|
| 1412 | static AWT_config_mapping_def editor_options_config_mapping[] = { |
|---|
| 1413 | { ED4_AWAR_COMPRESS_SEQUENCE_GAPS, "compressgaps" }, |
|---|
| 1414 | { ED4_AWAR_COMPRESS_SEQUENCE_HIDE, "hidenucs" }, |
|---|
| 1415 | { ED4_AWAR_COMPRESS_SEQUENCE_PERCENT, "hidepercent" }, |
|---|
| 1416 | { AWAR_EDIT_HELIX_SPACING, "helixspacing" }, |
|---|
| 1417 | { AWAR_EDIT_TERMINAL_SPACING, "terminalspacing" }, |
|---|
| 1418 | { ED4_AWAR_SCROLL_SPEED_X, "scrollspeedx" }, |
|---|
| 1419 | { ED4_AWAR_SCROLL_SPEED_Y, "scrollspeedy" }, |
|---|
| 1420 | { ED4_AWAR_SCROLL_MARGIN, "scrollmargin" }, |
|---|
| 1421 | { ED4_AWAR_GAP_CHARS, "gapchars" }, |
|---|
| 1422 | { ED4_AWAR_DIGITS_AS_REPEAT, "digitsasrepeat" }, |
|---|
| 1423 | { ED4_AWAR_FAST_CURSOR_JUMP, "fastcursorjump" }, |
|---|
| 1424 | { ED4_AWAR_ANNOUNCE_CHECKSUM_CHANGES, "announcechecksumchanges" }, |
|---|
| 1425 | |
|---|
| 1426 | { NULp, NULp } |
|---|
| 1427 | }; |
|---|
| 1428 | |
|---|
| 1429 | AW_window *ED4_create_editor_options_window(AW_root *root) { |
|---|
| 1430 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 1431 | |
|---|
| 1432 | aws->init(root, "EDIT4_PROPS", "EDIT4 Options"); |
|---|
| 1433 | aws->load_xfig("edit4/options.fig"); |
|---|
| 1434 | |
|---|
| 1435 | aws->auto_space(5, 5); |
|---|
| 1436 | |
|---|
| 1437 | const int SCALEDCOLUMNS = 4; |
|---|
| 1438 | const int SCALERLEN = 200; |
|---|
| 1439 | |
|---|
| 1440 | aws->callback(AW_POPDOWN); |
|---|
| 1441 | aws->at("close"); |
|---|
| 1442 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 1443 | |
|---|
| 1444 | aws->callback(makeHelpCallback("e4_options.hlp")); |
|---|
| 1445 | aws->at("help"); |
|---|
| 1446 | aws->create_button("HELP", "HELP", "H"); |
|---|
| 1447 | |
|---|
| 1448 | // ----------------------------------- |
|---|
| 1449 | // Online Sequence Compression |
|---|
| 1450 | |
|---|
| 1451 | aws->at("gaps"); |
|---|
| 1452 | aws->create_toggle_field(ED4_AWAR_COMPRESS_SEQUENCE_GAPS); |
|---|
| 1453 | aws->insert_default_toggle("Show all gaps", "A", 0); |
|---|
| 1454 | aws->insert_toggle("Show some gaps", "S", 1); |
|---|
| 1455 | aws->insert_toggle("Hide all gaps", "H", 2); |
|---|
| 1456 | aws->update_toggle_field(); |
|---|
| 1457 | |
|---|
| 1458 | aws->at("hide"); |
|---|
| 1459 | aws->create_toggle_field(ED4_AWAR_COMPRESS_SEQUENCE_HIDE); |
|---|
| 1460 | aws->insert_default_toggle("Hide no Nucleotides", "0", 0); |
|---|
| 1461 | aws->insert_toggle("Hide columns with less than...", "1", 1); |
|---|
| 1462 | aws->update_toggle_field(); |
|---|
| 1463 | |
|---|
| 1464 | aws->at("percent"); |
|---|
| 1465 | aws->create_input_field_with_scaler(ED4_AWAR_COMPRESS_SEQUENCE_PERCENT, SCALEDCOLUMNS, SCALERLEN, AW_SCALER_LINEAR); |
|---|
| 1466 | |
|---|
| 1467 | // -------------- |
|---|
| 1468 | // Layout |
|---|
| 1469 | |
|---|
| 1470 | aws->at("seq_helix"); aws->create_input_field_with_scaler(AWAR_EDIT_HELIX_SPACING, SCALEDCOLUMNS, SCALERLEN, AW_SCALER_EXP_CENTER); |
|---|
| 1471 | aws->at("seq_seq"); aws->create_input_field_with_scaler(AWAR_EDIT_TERMINAL_SPACING, SCALEDCOLUMNS, SCALERLEN, AW_SCALER_EXP_CENTER); |
|---|
| 1472 | |
|---|
| 1473 | // -------------------- |
|---|
| 1474 | // Scroll-Speed |
|---|
| 1475 | |
|---|
| 1476 | aws->at("scroll_x"); |
|---|
| 1477 | aws->create_input_field(ED4_AWAR_SCROLL_SPEED_X); |
|---|
| 1478 | |
|---|
| 1479 | aws->at("scroll_y"); |
|---|
| 1480 | aws->create_input_field(ED4_AWAR_SCROLL_SPEED_Y); |
|---|
| 1481 | |
|---|
| 1482 | aws->at("margin"); |
|---|
| 1483 | aws->create_input_field(ED4_AWAR_SCROLL_MARGIN); |
|---|
| 1484 | |
|---|
| 1485 | // --------------- |
|---|
| 1486 | // Editing |
|---|
| 1487 | |
|---|
| 1488 | aws->at("gapchars"); |
|---|
| 1489 | aws->create_input_field(ED4_AWAR_GAP_CHARS); |
|---|
| 1490 | |
|---|
| 1491 | aws->at("repeat"); |
|---|
| 1492 | aws->create_toggle(ED4_AWAR_DIGITS_AS_REPEAT); |
|---|
| 1493 | |
|---|
| 1494 | aws->at("fast"); |
|---|
| 1495 | aws->create_toggle(ED4_AWAR_FAST_CURSOR_JUMP); |
|---|
| 1496 | |
|---|
| 1497 | aws->at("checksum"); |
|---|
| 1498 | aws->create_toggle(ED4_AWAR_ANNOUNCE_CHECKSUM_CHANGES); |
|---|
| 1499 | |
|---|
| 1500 | aws->at("config"); |
|---|
| 1501 | AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "options", editor_options_config_mapping); |
|---|
| 1502 | |
|---|
| 1503 | return aws; |
|---|
| 1504 | } |
|---|
| 1505 | |
|---|
| 1506 | static AWT_config_mapping_def consensus_config_mapping[] = { |
|---|
| 1507 | { ED4_AWAR_CONSENSUS_COUNTGAPS, CONSENSUS_CONFIG_COUNTGAPS }, |
|---|
| 1508 | { ED4_AWAR_CONSENSUS_GAPBOUND, CONSENSUS_CONFIG_GAPBOUND }, |
|---|
| 1509 | { ED4_AWAR_CONSENSUS_GROUP, CONSENSUS_CONFIG_GROUP }, |
|---|
| 1510 | { ED4_AWAR_CONSENSUS_CONSIDBOUND, CONSENSUS_CONFIG_CONSIDBOUND }, |
|---|
| 1511 | { ED4_AWAR_CONSENSUS_UPPER, CONSENSUS_CONFIG_UPPER }, |
|---|
| 1512 | { ED4_AWAR_CONSENSUS_LOWER, CONSENSUS_CONFIG_LOWER }, |
|---|
| 1513 | |
|---|
| 1514 | { NULp, NULp } |
|---|
| 1515 | }; |
|---|
| 1516 | |
|---|
| 1517 | AW_window *ED4_create_consensus_definition_window(AW_root *root) { |
|---|
| 1518 | // keep in sync with ../NTREE/AP_consensus.cxx@AP_create_con_expert_window |
|---|
| 1519 | |
|---|
| 1520 | static AW_window_simple *aws = NULp; |
|---|
| 1521 | |
|---|
| 1522 | if (!aws) { |
|---|
| 1523 | aws = new AW_window_simple; |
|---|
| 1524 | |
|---|
| 1525 | aws->init(root, "EDIT4_CONSENSUS_DEFm", "EDIT4 Consensus Definition"); |
|---|
| 1526 | aws->load_xfig("edit4/consensus.fig"); |
|---|
| 1527 | |
|---|
| 1528 | aws->auto_space(5, 5); |
|---|
| 1529 | |
|---|
| 1530 | const int SCALEDCOLUMNS = 3; |
|---|
| 1531 | const int SCALERSIZE = 150; |
|---|
| 1532 | |
|---|
| 1533 | // top part of window: |
|---|
| 1534 | aws->button_length(9); |
|---|
| 1535 | |
|---|
| 1536 | aws->callback(AW_POPDOWN); |
|---|
| 1537 | aws->at("close"); |
|---|
| 1538 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 1539 | |
|---|
| 1540 | aws->callback(makeHelpCallback("e4_consensus.hlp")); |
|---|
| 1541 | aws->at("help"); |
|---|
| 1542 | aws->create_button("HELP", "HELP", "H"); |
|---|
| 1543 | |
|---|
| 1544 | // center part of window (same as in NTREE): |
|---|
| 1545 | aws->at("countgaps"); |
|---|
| 1546 | aws->create_toggle_field(ED4_AWAR_CONSENSUS_COUNTGAPS); |
|---|
| 1547 | aws->insert_toggle("on", "1", 1); |
|---|
| 1548 | aws->insert_default_toggle("off", "0", 0); |
|---|
| 1549 | aws->update_toggle_field(); |
|---|
| 1550 | |
|---|
| 1551 | aws->at("gapbound"); |
|---|
| 1552 | aws->create_input_field_with_scaler(ED4_AWAR_CONSENSUS_GAPBOUND, SCALEDCOLUMNS, SCALERSIZE, AW_SCALER_LINEAR); |
|---|
| 1553 | |
|---|
| 1554 | aws->at("group"); |
|---|
| 1555 | aws->create_toggle_field(ED4_AWAR_CONSENSUS_GROUP); |
|---|
| 1556 | aws->insert_toggle("on", "1", 1); |
|---|
| 1557 | aws->insert_default_toggle("off", "0", 0); |
|---|
| 1558 | aws->update_toggle_field(); |
|---|
| 1559 | |
|---|
| 1560 | aws->at("considbound"); |
|---|
| 1561 | aws->create_input_field_with_scaler(ED4_AWAR_CONSENSUS_CONSIDBOUND, SCALEDCOLUMNS, SCALERSIZE, AW_SCALER_LINEAR); |
|---|
| 1562 | |
|---|
| 1563 | aws->at("showgroups"); |
|---|
| 1564 | aws->callback(AWT_create_IUPAC_info_window); |
|---|
| 1565 | aws->create_autosize_button("SHOW_IUPAC", "Show IUPAC groups", "S"); |
|---|
| 1566 | |
|---|
| 1567 | aws->at("upper"); |
|---|
| 1568 | aws->create_input_field_with_scaler(ED4_AWAR_CONSENSUS_UPPER, SCALEDCOLUMNS, SCALERSIZE, AW_SCALER_LINEAR); |
|---|
| 1569 | |
|---|
| 1570 | aws->at("lower"); |
|---|
| 1571 | aws->create_input_field_with_scaler(ED4_AWAR_CONSENSUS_LOWER, SCALEDCOLUMNS, SCALERSIZE, AW_SCALER_LINEAR); |
|---|
| 1572 | |
|---|
| 1573 | // bottom part of window: |
|---|
| 1574 | aws->at("show"); |
|---|
| 1575 | aws->label("Display consensus?"); |
|---|
| 1576 | aws->create_toggle(ED4_AWAR_CONSENSUS_SHOW); |
|---|
| 1577 | |
|---|
| 1578 | aws->at("config"); |
|---|
| 1579 | AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, CONSENSUS_CONFIG_ID, consensus_config_mapping); |
|---|
| 1580 | } |
|---|
| 1581 | |
|---|
| 1582 | return aws; |
|---|
| 1583 | } |
|---|
| 1584 | |
|---|
| 1585 | static void consensus_upper_lower_changed_cb(AW_root *awr, bool upper_changed) { |
|---|
| 1586 | AW_awar *awar_lower = awr->awar(ED4_AWAR_CONSENSUS_LOWER); |
|---|
| 1587 | AW_awar *awar_upper = awr->awar(ED4_AWAR_CONSENSUS_UPPER); |
|---|
| 1588 | |
|---|
| 1589 | int lower = awar_lower->read_int(); |
|---|
| 1590 | int upper = awar_upper->read_int(); |
|---|
| 1591 | |
|---|
| 1592 | if (upper<lower) { |
|---|
| 1593 | if (upper_changed) awar_lower->write_int(upper); |
|---|
| 1594 | else awar_upper->write_int(lower); |
|---|
| 1595 | } |
|---|
| 1596 | ED4_consensus_definition_changed(awr); |
|---|
| 1597 | } |
|---|
| 1598 | |
|---|
| 1599 | void ED4_create_consensus_awars(AW_root *aw_root) { |
|---|
| 1600 | GB_transaction ta(ED4_ROOT->get_gb_main()); |
|---|
| 1601 | |
|---|
| 1602 | aw_root->awar_int(ED4_AWAR_CONSENSUS_COUNTGAPS, 1) ->add_callback(ED4_consensus_definition_changed); |
|---|
| 1603 | aw_root->awar_int(ED4_AWAR_CONSENSUS_GROUP, 1) ->add_callback(ED4_consensus_definition_changed); |
|---|
| 1604 | aw_root->awar_int(ED4_AWAR_CONSENSUS_GAPBOUND, 60)->set_minmax(0, 100)->add_callback(ED4_consensus_definition_changed); |
|---|
| 1605 | aw_root->awar_int(ED4_AWAR_CONSENSUS_CONSIDBOUND, 30)->set_minmax(0, 100)->add_callback(ED4_consensus_definition_changed); |
|---|
| 1606 | aw_root->awar_int(ED4_AWAR_CONSENSUS_UPPER, 95)->set_minmax(0, 100)->add_callback(makeRootCallback(consensus_upper_lower_changed_cb, true)); |
|---|
| 1607 | aw_root->awar_int(ED4_AWAR_CONSENSUS_LOWER, 70)->set_minmax(0, 100)->add_callback(makeRootCallback(consensus_upper_lower_changed_cb, false)); |
|---|
| 1608 | |
|---|
| 1609 | AW_awar *cons_show = aw_root->awar_int(ED4_AWAR_CONSENSUS_SHOW, 1); |
|---|
| 1610 | |
|---|
| 1611 | cons_show->write_int(1); |
|---|
| 1612 | cons_show->add_callback(ED4_consensus_display_changed); |
|---|
| 1613 | } |
|---|
| 1614 | |
|---|
| 1615 | void ED4_reloadConfiguration(AW_window *aww) { |
|---|
| 1616 | ED4_start_editor_on_configuration(aww); |
|---|
| 1617 | } |
|---|
| 1618 | |
|---|
| 1619 | AW_window *ED4_create_loadConfiguration_window(AW_root *awr) { |
|---|
| 1620 | static AW_window_simple *aws = NULp; |
|---|
| 1621 | if (!aws) { |
|---|
| 1622 | aws = new AW_window_simple; |
|---|
| 1623 | aws->init(awr, "LOAD_CONFIGURATION", "Load existing configuration"); |
|---|
| 1624 | aws->load_xfig("edit4/load_config.fig"); |
|---|
| 1625 | |
|---|
| 1626 | aws->at("close"); |
|---|
| 1627 | aws->callback(AW_POPDOWN); |
|---|
| 1628 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 1629 | |
|---|
| 1630 | aws->at("help"); |
|---|
| 1631 | aws->callback(makeHelpCallback("species_configs_saveload.hlp")); |
|---|
| 1632 | aws->create_button("HELP", "HELP"); |
|---|
| 1633 | |
|---|
| 1634 | aws->at("confs"); |
|---|
| 1635 | awt_create_CONFIG_selection_list(ED4_ROOT->get_gb_main(), aws, AWAR_EDIT_CONFIGURATION, false); |
|---|
| 1636 | |
|---|
| 1637 | aws->at("go"); |
|---|
| 1638 | aws->callback(ED4_start_editor_on_configuration); |
|---|
| 1639 | aws->create_button("LOAD", "LOAD"); |
|---|
| 1640 | |
|---|
| 1641 | aws->window_fit(); |
|---|
| 1642 | } |
|---|
| 1643 | return aws; |
|---|
| 1644 | } |
|---|
| 1645 | |
|---|
| 1646 | void ED4_saveConfiguration(AW_window *aww, bool hide_aww) { |
|---|
| 1647 | if (hide_aww) aww->hide(); |
|---|
| 1648 | |
|---|
| 1649 | char *name = aww->get_root()->awar(AWAR_EDIT_CONFIGURATION)->read_string(); |
|---|
| 1650 | EDB_root_bact::save_current_config(name); |
|---|
| 1651 | free(name); |
|---|
| 1652 | } |
|---|
| 1653 | |
|---|
| 1654 | AW_window *ED4_create_saveConfigurationAs_window(AW_root *awr) { |
|---|
| 1655 | static AW_window_simple *aws = NULp; |
|---|
| 1656 | if (!aws) { |
|---|
| 1657 | aws = new AW_window_simple; |
|---|
| 1658 | aws->init(awr, "SAVE_CONFIGURATION", "Save current configuration as"); |
|---|
| 1659 | aws->load_xfig("edit4/save_config.fig"); |
|---|
| 1660 | |
|---|
| 1661 | aws->at("close"); |
|---|
| 1662 | aws->callback(AW_POPDOWN); |
|---|
| 1663 | aws->create_button("CLOSE", "CLOSE"); |
|---|
| 1664 | |
|---|
| 1665 | aws->at("help"); |
|---|
| 1666 | aws->callback(makeHelpCallback("species_configs_saveload.hlp")); |
|---|
| 1667 | aws->create_button("HELP", "HELP"); |
|---|
| 1668 | |
|---|
| 1669 | aws->at("save"); |
|---|
| 1670 | aws->create_input_field(AWAR_EDIT_CONFIGURATION); |
|---|
| 1671 | |
|---|
| 1672 | aws->at("confs"); |
|---|
| 1673 | awt_create_CONFIG_selection_list(ED4_ROOT->get_gb_main(), aws, AWAR_EDIT_CONFIGURATION, false); |
|---|
| 1674 | |
|---|
| 1675 | aws->at("go"); |
|---|
| 1676 | aws->callback(makeWindowCallback(ED4_saveConfiguration, true)); |
|---|
| 1677 | aws->create_button("SAVE", "SAVE"); |
|---|
| 1678 | } |
|---|
| 1679 | return aws; |
|---|
| 1680 | } |
|---|
| 1681 | |
|---|
| 1682 | static char *filter_loadable_SAIs(GBDATA *gb_sai) { |
|---|
| 1683 | GBDATA *gb_ali = GB_search(gb_sai, ED4_ROOT->alignment_name, GB_FIND); |
|---|
| 1684 | if (gb_ali) { |
|---|
| 1685 | GBDATA *gb_data = GB_search(gb_ali, "data", GB_FIND); |
|---|
| 1686 | if (gb_data) { |
|---|
| 1687 | const char *sai_name = GBT_get_name(gb_sai); |
|---|
| 1688 | if (sai_name && !ED4_find_SAI_name_terminal(sai_name)) { // if not loaded yet |
|---|
| 1689 | return ARB_strdup(sai_name); |
|---|
| 1690 | } |
|---|
| 1691 | } |
|---|
| 1692 | } |
|---|
| 1693 | return NULp; |
|---|
| 1694 | } |
|---|
| 1695 | |
|---|
| 1696 | AW_window *ED4_create_loadSAI_window(AW_root *awr) { |
|---|
| 1697 | static AW_window_simple *aws = NULp; |
|---|
| 1698 | if (!aws) { |
|---|
| 1699 | aws = new AW_window_simple; |
|---|
| 1700 | aws->init(awr, "LOAD_SAI", "Load additional SAI"); |
|---|
| 1701 | aws->load_xfig("edit4/load_sai.fig"); |
|---|
| 1702 | |
|---|
| 1703 | aws->at("close"); |
|---|
| 1704 | aws->callback(AW_POPDOWN); |
|---|
| 1705 | aws->create_button("CLOSE", "CLOSE"); |
|---|
| 1706 | |
|---|
| 1707 | aws->at("help"); |
|---|
| 1708 | aws->callback(makeHelpCallback("e4_get_species.hlp")); |
|---|
| 1709 | aws->create_button("HELP", "HELP"); |
|---|
| 1710 | |
|---|
| 1711 | aws->at("sai"); |
|---|
| 1712 | awt_create_SAI_selection_list(ED4_ROOT->get_gb_main(), aws, AWAR_SAI_NAME, false, makeSaiSelectionlistFilterCallback(filter_loadable_SAIs)); |
|---|
| 1713 | ED4_ROOT->loadable_SAIs = LSAI_UPTODATE; |
|---|
| 1714 | |
|---|
| 1715 | aws->at("go"); |
|---|
| 1716 | aws->callback(ED4_get_and_jump_to_selected_SAI); |
|---|
| 1717 | aws->create_button("LOAD", "LOAD"); |
|---|
| 1718 | } |
|---|
| 1719 | return aws; |
|---|
| 1720 | } |
|---|
| 1721 | |
|---|
| 1722 | static GB_ERROR createDataFromConsensus(GBDATA *gb_species, ED4_group_manager *group_man) { |
|---|
| 1723 | GB_ERROR error = NULp; |
|---|
| 1724 | |
|---|
| 1725 | int len; |
|---|
| 1726 | char *consensus = group_man->build_consensus_string(&len); |
|---|
| 1727 | |
|---|
| 1728 | char *equal_to = ED4_ROOT->aw_root->awar(ED4_AWAR_CREATE_FROM_CONS_REPL_EQUAL)->read_string(); |
|---|
| 1729 | char *point_to = ED4_ROOT->aw_root->awar(ED4_AWAR_CREATE_FROM_CONS_REPL_POINT)->read_string(); |
|---|
| 1730 | int allUpper = ED4_ROOT->aw_root->awar(ED4_AWAR_CREATE_FROM_CONS_ALL_UPPER)->read_int(); |
|---|
| 1731 | |
|---|
| 1732 | for (int p=0; p<len; p++) { |
|---|
| 1733 | switch (consensus[p]) { |
|---|
| 1734 | case '=': consensus[p] = equal_to[0]; break; |
|---|
| 1735 | case '.': consensus[p] = point_to[0]; break; |
|---|
| 1736 | default: { |
|---|
| 1737 | if (allUpper) { |
|---|
| 1738 | consensus[p] = toupper(consensus[p]); |
|---|
| 1739 | } |
|---|
| 1740 | break; |
|---|
| 1741 | } |
|---|
| 1742 | } |
|---|
| 1743 | } |
|---|
| 1744 | |
|---|
| 1745 | if (ED4_ROOT->aw_root->awar(ED4_AWAR_CREATE_FROM_CONS_CREATE_POINTS)) { // points at start & end of sequence? |
|---|
| 1746 | for (int p=0; p<len; p++) { |
|---|
| 1747 | if (!ED4_is_gap_character(consensus[p])) break; |
|---|
| 1748 | consensus[p] = '.'; |
|---|
| 1749 | } |
|---|
| 1750 | for (int p=len-1; p>=0; p--) { |
|---|
| 1751 | if (!ED4_is_gap_character(consensus[p])) break; |
|---|
| 1752 | consensus[p] = '.'; |
|---|
| 1753 | } |
|---|
| 1754 | } |
|---|
| 1755 | |
|---|
| 1756 | GB_CSTR ali = GBT_get_default_alignment(ED4_ROOT->get_gb_main()); |
|---|
| 1757 | GBDATA *gb_ali = GB_search(gb_species, ali, GB_DB); |
|---|
| 1758 | if (gb_ali) { |
|---|
| 1759 | GBDATA *gb_data = GB_search(gb_ali, "data", GB_STRING); |
|---|
| 1760 | error = GB_write_pntr(gb_data, consensus, len+1, len); |
|---|
| 1761 | } |
|---|
| 1762 | else { |
|---|
| 1763 | error = GB_export_errorf("Can't find alignment '%s'", ali); |
|---|
| 1764 | } |
|---|
| 1765 | free(consensus); |
|---|
| 1766 | return error; |
|---|
| 1767 | } |
|---|
| 1768 | |
|---|
| 1769 | // -------------------------------------------------------------------------------- |
|---|
| 1770 | |
|---|
| 1771 | struct SpeciesMergeList { |
|---|
| 1772 | GBDATA *species; |
|---|
| 1773 | char *species_name; |
|---|
| 1774 | |
|---|
| 1775 | SpeciesMergeList *next; |
|---|
| 1776 | }; |
|---|
| 1777 | |
|---|
| 1778 | static ARB_ERROR add_species_to_merge_list(ED4_base *base, SpeciesMergeList **smlp, GBDATA *gb_species_data) { |
|---|
| 1779 | GB_ERROR error = NULp; |
|---|
| 1780 | |
|---|
| 1781 | if (base->is_species_name_terminal()) { |
|---|
| 1782 | ED4_species_name_terminal *name_term = base->to_species_name_terminal(); |
|---|
| 1783 | |
|---|
| 1784 | if (!name_term->inside_consensus_manager()) { |
|---|
| 1785 | char *species_name = name_term->resolve_pointer_to_string_copy(); |
|---|
| 1786 | GBDATA *gb_species = GBT_find_species_rel_species_data(gb_species_data, species_name); |
|---|
| 1787 | |
|---|
| 1788 | if (gb_species) { |
|---|
| 1789 | SpeciesMergeList *sml = new SpeciesMergeList; |
|---|
| 1790 | |
|---|
| 1791 | sml->species = gb_species; |
|---|
| 1792 | sml->species_name = ARB_strdup(species_name); |
|---|
| 1793 | sml->next = *smlp; |
|---|
| 1794 | *smlp = sml; |
|---|
| 1795 | } |
|---|
| 1796 | else { |
|---|
| 1797 | error = GB_append_exportedError(GBS_global_string("can't find species '%s'", species_name)); |
|---|
| 1798 | } |
|---|
| 1799 | |
|---|
| 1800 | free(species_name); |
|---|
| 1801 | } |
|---|
| 1802 | } |
|---|
| 1803 | return error; |
|---|
| 1804 | } |
|---|
| 1805 | static int SpeciesMergeListLength(SpeciesMergeList *sml) { |
|---|
| 1806 | int length = 0; |
|---|
| 1807 | |
|---|
| 1808 | while (sml) { |
|---|
| 1809 | length++; |
|---|
| 1810 | sml = sml->next; |
|---|
| 1811 | } |
|---|
| 1812 | |
|---|
| 1813 | return length; |
|---|
| 1814 | } |
|---|
| 1815 | static void freeSpeciesMergeList(SpeciesMergeList *sml) { |
|---|
| 1816 | while (sml) { |
|---|
| 1817 | free(sml->species_name); |
|---|
| 1818 | freeset(sml, sml->next); |
|---|
| 1819 | } |
|---|
| 1820 | } |
|---|
| 1821 | |
|---|
| 1822 | // -------------------------------------------------------------------------------- |
|---|
| 1823 | |
|---|
| 1824 | inline bool nameIsUnique(const char *short_name, GBDATA *gb_species_data) { |
|---|
| 1825 | return !GBT_find_species_rel_species_data(gb_species_data, short_name); |
|---|
| 1826 | } |
|---|
| 1827 | |
|---|
| 1828 | |
|---|
| 1829 | static void create_new_species(AW_window *, SpeciesCreationMode creation_mode) { |
|---|
| 1830 | char *new_species_full_name = ED4_ROOT->aw_root->awar(ED4_AWAR_SPECIES_TO_CREATE)->read_string(); // this contains the full_name now! |
|---|
| 1831 | ARB_ERROR error = NULp; |
|---|
| 1832 | |
|---|
| 1833 | e4_assert(creation_mode>=0 && creation_mode<=2); |
|---|
| 1834 | |
|---|
| 1835 | if (!new_species_full_name || new_species_full_name[0]==0) { |
|---|
| 1836 | error = "Please enter a full_name for the new species"; |
|---|
| 1837 | } |
|---|
| 1838 | else { |
|---|
| 1839 | ED4_MostRecentWinContext context; |
|---|
| 1840 | |
|---|
| 1841 | GBDATA *gb_main = ED4_ROOT->get_gb_main(); |
|---|
| 1842 | error = GB_begin_transaction(gb_main); |
|---|
| 1843 | |
|---|
| 1844 | GBDATA *gb_species_data = GBT_get_species_data(gb_main); |
|---|
| 1845 | char *new_species_name = NULp; |
|---|
| 1846 | char *acc = NULp; |
|---|
| 1847 | char *addid = NULp; |
|---|
| 1848 | |
|---|
| 1849 | enum e_dataSource { MERGE_FIELDS, COPY_FIELDS } dataSource = (enum e_dataSource)ED4_ROOT->aw_root ->awar(ED4_AWAR_CREATE_FROM_CONS_DATA_SOURCE)->read_int(); |
|---|
| 1850 | enum { NOWHERE, ON_SPECIES, ON_CONSENSUS } where_we_are = NOWHERE; |
|---|
| 1851 | ED4_terminal *cursor_terminal = NULp; |
|---|
| 1852 | |
|---|
| 1853 | if (!error) { |
|---|
| 1854 | if (creation_mode==CREATE_FROM_CONSENSUS || creation_mode==COPY_SPECIES) { |
|---|
| 1855 | ED4_cursor *cursor = ¤t_cursor(); |
|---|
| 1856 | |
|---|
| 1857 | if (cursor->owner_of_cursor) { |
|---|
| 1858 | cursor_terminal = cursor->owner_of_cursor; |
|---|
| 1859 | where_we_are = cursor_terminal->is_consensus_terminal() ? ON_CONSENSUS : ON_SPECIES; |
|---|
| 1860 | } |
|---|
| 1861 | } |
|---|
| 1862 | |
|---|
| 1863 | if (creation_mode==COPY_SPECIES || (creation_mode==CREATE_FROM_CONSENSUS && dataSource==COPY_FIELDS)) { |
|---|
| 1864 | if (where_we_are==ON_SPECIES) { |
|---|
| 1865 | ED4_species_name_terminal *spec_name = cursor_terminal->to_sequence_terminal()->corresponding_species_name_terminal(); |
|---|
| 1866 | const char *source_name = spec_name->resolve_pointer_to_char_pntr(); |
|---|
| 1867 | GBDATA *gb_source = GBT_find_species_rel_species_data(gb_species_data, source_name); |
|---|
| 1868 | |
|---|
| 1869 | if (!gb_source) error = GBS_global_string("No such species: '%s'", source_name); |
|---|
| 1870 | else { |
|---|
| 1871 | GBDATA *gb_acc = GB_search(gb_source, "acc", GB_FIND); |
|---|
| 1872 | if (gb_acc) acc = GB_read_string(gb_acc); // if has accession |
|---|
| 1873 | |
|---|
| 1874 | const char *add_field = AW_get_nameserver_addid(gb_main); |
|---|
| 1875 | GBDATA *gb_addid = add_field[0] ? GB_search(gb_source, add_field, GB_FIND) : NULp; |
|---|
| 1876 | if (gb_addid) addid = GB_read_as_string(gb_addid); |
|---|
| 1877 | } |
|---|
| 1878 | } |
|---|
| 1879 | else { |
|---|
| 1880 | error = "Please place cursor on a species"; |
|---|
| 1881 | } |
|---|
| 1882 | } |
|---|
| 1883 | } |
|---|
| 1884 | |
|---|
| 1885 | if (!error) { |
|---|
| 1886 | UniqueNameDetector *existingNames = NULp; |
|---|
| 1887 | |
|---|
| 1888 | if (creation_mode==0) { |
|---|
| 1889 | error = "It's no good idea to create the short-name for a new species using the nameserver! (has no acc yet)"; |
|---|
| 1890 | } |
|---|
| 1891 | else { |
|---|
| 1892 | error = AWTC_generate_one_name(gb_main, new_species_full_name, acc, addid, new_species_name); |
|---|
| 1893 | if (!error) { // name was created |
|---|
| 1894 | if (!nameIsUnique(new_species_name, gb_species_data)) { |
|---|
| 1895 | if (!existingNames) existingNames = new UniqueNameDetector(gb_species_data); |
|---|
| 1896 | freeset(new_species_name, AWTC_makeUniqueShortName(new_species_name, *existingNames)); |
|---|
| 1897 | if (!new_species_name) error = GB_await_error(); |
|---|
| 1898 | } |
|---|
| 1899 | } |
|---|
| 1900 | } |
|---|
| 1901 | |
|---|
| 1902 | if (error) { // try to make a random name |
|---|
| 1903 | const char *msg = GBS_global_string("%s\nGenerating a random name instead.", error.deliver()); |
|---|
| 1904 | aw_message(msg); |
|---|
| 1905 | error = NULp; |
|---|
| 1906 | |
|---|
| 1907 | if (!existingNames) existingNames = new UniqueNameDetector(gb_species_data); |
|---|
| 1908 | new_species_name = AWTC_generate_random_name(*existingNames); |
|---|
| 1909 | |
|---|
| 1910 | if (!new_species_name) { |
|---|
| 1911 | error = GBS_global_string("Failed to create a new name for '%s'", new_species_full_name); |
|---|
| 1912 | } |
|---|
| 1913 | } |
|---|
| 1914 | |
|---|
| 1915 | if (existingNames) delete existingNames; |
|---|
| 1916 | } |
|---|
| 1917 | |
|---|
| 1918 | if (!error) { |
|---|
| 1919 | if (!error) { |
|---|
| 1920 | if (creation_mode==CREATE_NEW_SPECIES) { |
|---|
| 1921 | GBDATA *gb_created_species = GBT_find_or_create_species(gb_main, new_species_name, true); |
|---|
| 1922 | if (!gb_created_species) { |
|---|
| 1923 | error = GBS_global_string("Failed to create new species '%s'", new_species_name); |
|---|
| 1924 | } |
|---|
| 1925 | else { |
|---|
| 1926 | GB_CSTR ali = GBT_get_default_alignment(gb_main); |
|---|
| 1927 | GBDATA *gb_ali = GB_search(gb_created_species, ali, GB_DB); |
|---|
| 1928 | |
|---|
| 1929 | if (gb_ali) error = GBT_write_string(gb_ali, "data", "......."); |
|---|
| 1930 | else error = GBS_global_string("Can't create alignment '%s' (Reason: %s)", ali, GB_await_error()); |
|---|
| 1931 | } |
|---|
| 1932 | if (!error) error = GBT_write_string(gb_created_species, "full_name", new_species_full_name); |
|---|
| 1933 | } |
|---|
| 1934 | else if (creation_mode==CREATE_FROM_CONSENSUS && dataSource==MERGE_FIELDS) { |
|---|
| 1935 | // create from consensus (merge fields from all species in container) |
|---|
| 1936 | if (where_we_are==NOWHERE) { |
|---|
| 1937 | error = "Please place cursor on any sequence/consensus of group"; |
|---|
| 1938 | } |
|---|
| 1939 | else { |
|---|
| 1940 | ED4_group_manager *group_man = cursor_terminal->get_parent(LEV_GROUP)->to_group_manager(); |
|---|
| 1941 | SpeciesMergeList *sml = NULp; // list of species in group |
|---|
| 1942 | |
|---|
| 1943 | error = group_man->route_down_hierarchy(makeED4_route_cb(add_species_to_merge_list, &sml, gb_species_data)); |
|---|
| 1944 | if (!error && !sml) { |
|---|
| 1945 | error = "Please choose a none empty group!"; |
|---|
| 1946 | } |
|---|
| 1947 | |
|---|
| 1948 | GBDATA *gb_new_species = NULp; |
|---|
| 1949 | if (!error) { |
|---|
| 1950 | GBDATA *gb_source = sml->species; |
|---|
| 1951 | gb_new_species = GB_create_container(gb_species_data, "species"); |
|---|
| 1952 | error = GB_copy_dropProtectMarksAndTempstate(gb_new_species, gb_source); // copy first found species to create a new species |
|---|
| 1953 | } |
|---|
| 1954 | if (!error) error = GBT_write_string(gb_new_species, "name", new_species_name); // insert new 'name' |
|---|
| 1955 | if (!error) error = GBT_write_string(gb_new_species, "full_name", new_species_full_name); // insert new 'full_name' |
|---|
| 1956 | if (!error) error = createDataFromConsensus(gb_new_species, group_man); // insert consensus as 'data' |
|---|
| 1957 | |
|---|
| 1958 | if (!error) { |
|---|
| 1959 | char *doneFields = ARB_strdup(";name;full_name;"); // all fields which are already merged |
|---|
| 1960 | int doneLen = strlen(doneFields); |
|---|
| 1961 | SpeciesMergeList *sl = sml; |
|---|
| 1962 | int sl_length = SpeciesMergeListLength(sml); |
|---|
| 1963 | int *fieldStat = new int[sl_length]; // 0 = not used yet ; -1 = don't has field ; 1..n = field content, same number means same content |
|---|
| 1964 | |
|---|
| 1965 | arb_progress progress("Merging fields", long(sl_length)); |
|---|
| 1966 | |
|---|
| 1967 | while (sl && !error) { // with all species do.. |
|---|
| 1968 | char *newFields = GB_get_subfields(sl->species); |
|---|
| 1969 | char *fieldStart = newFields; // points to ; before next field |
|---|
| 1970 | |
|---|
| 1971 | while (fieldStart[1] && !error) { // with all subfields of the species do.. |
|---|
| 1972 | char *fieldEnd = strchr(fieldStart+1, ';'); |
|---|
| 1973 | |
|---|
| 1974 | e4_assert(fieldEnd); |
|---|
| 1975 | char behind = fieldEnd[1]; |
|---|
| 1976 | fieldEnd[1] = 0; |
|---|
| 1977 | |
|---|
| 1978 | if (!strstr(doneFields, fieldStart)) { // field is not merged yet |
|---|
| 1979 | char *fieldName = fieldStart+1; |
|---|
| 1980 | int fieldLen = int(fieldEnd-fieldName); |
|---|
| 1981 | |
|---|
| 1982 | e4_assert(fieldEnd[0]==';'); |
|---|
| 1983 | fieldEnd[0] = 0; |
|---|
| 1984 | |
|---|
| 1985 | GBDATA *gb_field = GB_search(sl->species, fieldName, GB_FIND); |
|---|
| 1986 | e4_assert(gb_field); // field has to exist, cause it was found before |
|---|
| 1987 | |
|---|
| 1988 | GB_TYPES type = GB_read_type(gb_field); |
|---|
| 1989 | if (type==GB_STRING) { // we only merge string fields |
|---|
| 1990 | int i; |
|---|
| 1991 | int doneSpecies = 0; |
|---|
| 1992 | int nextStat = 1; |
|---|
| 1993 | |
|---|
| 1994 | for (i=0; i<sl_length; i++) { // clear field status |
|---|
| 1995 | fieldStat[i] = 0; |
|---|
| 1996 | } |
|---|
| 1997 | |
|---|
| 1998 | while (doneSpecies<sl_length) { // since all species in list were handled |
|---|
| 1999 | SpeciesMergeList *sl2 = sml; |
|---|
| 2000 | i = 0; |
|---|
| 2001 | |
|---|
| 2002 | while (sl2) { |
|---|
| 2003 | if (fieldStat[i]==0) { |
|---|
| 2004 | gb_field = GB_search(sl2->species, fieldName, GB_FIND); |
|---|
| 2005 | if (gb_field) { |
|---|
| 2006 | char *content = GB_read_as_string(gb_field); |
|---|
| 2007 | SpeciesMergeList *sl3 = sl2->next; |
|---|
| 2008 | |
|---|
| 2009 | fieldStat[i] = nextStat; |
|---|
| 2010 | doneSpecies++; |
|---|
| 2011 | int j = i+1; |
|---|
| 2012 | while (sl3) { |
|---|
| 2013 | if (fieldStat[j]==0) { |
|---|
| 2014 | gb_field = GB_search(sl3->species, fieldName, GB_FIND); |
|---|
| 2015 | if (gb_field) { |
|---|
| 2016 | char *content2 = GB_read_as_string(gb_field); |
|---|
| 2017 | |
|---|
| 2018 | if (strcmp(content, content2)==0) { // if contents are the same, they get the same status |
|---|
| 2019 | fieldStat[j] = nextStat; |
|---|
| 2020 | doneSpecies++; |
|---|
| 2021 | } |
|---|
| 2022 | free(content2); |
|---|
| 2023 | } |
|---|
| 2024 | else { |
|---|
| 2025 | fieldStat[j] = -1; |
|---|
| 2026 | doneSpecies++; |
|---|
| 2027 | } |
|---|
| 2028 | } |
|---|
| 2029 | sl3 = sl3->next; |
|---|
| 2030 | j++; |
|---|
| 2031 | } |
|---|
| 2032 | |
|---|
| 2033 | free(content); |
|---|
| 2034 | nextStat++; |
|---|
| 2035 | } |
|---|
| 2036 | else { |
|---|
| 2037 | fieldStat[i] = -1; // field does not exist here |
|---|
| 2038 | doneSpecies++; |
|---|
| 2039 | } |
|---|
| 2040 | } |
|---|
| 2041 | sl2 = sl2->next; |
|---|
| 2042 | i++; |
|---|
| 2043 | } |
|---|
| 2044 | } |
|---|
| 2045 | |
|---|
| 2046 | e4_assert(nextStat!=1); // this would mean that none of the species contained the field |
|---|
| 2047 | |
|---|
| 2048 | { |
|---|
| 2049 | char *new_content = NULp; |
|---|
| 2050 | int new_content_len = 0; |
|---|
| 2051 | |
|---|
| 2052 | if (nextStat==2) { // all species contain same field content or do not have the field |
|---|
| 2053 | SpeciesMergeList *sl2 = sml; |
|---|
| 2054 | |
|---|
| 2055 | while (sl2) { |
|---|
| 2056 | gb_field = GB_search(sl2->species, fieldName, GB_FIND); |
|---|
| 2057 | if (gb_field) { |
|---|
| 2058 | new_content = GB_read_as_string(gb_field); |
|---|
| 2059 | new_content_len = strlen(new_content); // @@@ new_content_len never used |
|---|
| 2060 | break; |
|---|
| 2061 | } |
|---|
| 2062 | sl2 = sl2->next; |
|---|
| 2063 | } |
|---|
| 2064 | } |
|---|
| 2065 | else { // different field contents |
|---|
| 2066 | int currStat; |
|---|
| 2067 | for (currStat=1; currStat<nextStat; currStat++) { |
|---|
| 2068 | int names_len = 1; // open bracket |
|---|
| 2069 | SpeciesMergeList *sl2 = sml; |
|---|
| 2070 | i = 0; |
|---|
| 2071 | char *content = NULp; |
|---|
| 2072 | |
|---|
| 2073 | while (sl2) { |
|---|
| 2074 | if (fieldStat[i]==currStat) { |
|---|
| 2075 | names_len += strlen(sl2->species_name)+1; |
|---|
| 2076 | if (!content) { |
|---|
| 2077 | gb_field = GB_search(sl2->species, fieldName, GB_FIND); |
|---|
| 2078 | e4_assert(gb_field); |
|---|
| 2079 | content = GB_read_as_string(gb_field); |
|---|
| 2080 | } |
|---|
| 2081 | } |
|---|
| 2082 | sl2 = sl2->next; |
|---|
| 2083 | i++; |
|---|
| 2084 | } |
|---|
| 2085 | |
|---|
| 2086 | e4_assert(content); |
|---|
| 2087 | int add_len = names_len+1+strlen(content); |
|---|
| 2088 | char *whole = ARB_alloc<char>(new_content_len+1+add_len+1); |
|---|
| 2089 | e4_assert(whole); |
|---|
| 2090 | char *add = new_content ? whole+sprintf(whole, "%s ", new_content) : whole; |
|---|
| 2091 | sl2 = sml; |
|---|
| 2092 | i = 0; |
|---|
| 2093 | int first = 1; |
|---|
| 2094 | while (sl2) { |
|---|
| 2095 | if (fieldStat[i]==currStat) { |
|---|
| 2096 | add += sprintf(add, "%c%s", first ? '{' : ';', sl2->species_name); |
|---|
| 2097 | first = 0; |
|---|
| 2098 | } |
|---|
| 2099 | sl2 = sl2->next; |
|---|
| 2100 | i++; |
|---|
| 2101 | } |
|---|
| 2102 | add += sprintf(add, "} %s", content); |
|---|
| 2103 | |
|---|
| 2104 | free(content); |
|---|
| 2105 | |
|---|
| 2106 | freeset(new_content, whole); |
|---|
| 2107 | new_content_len = strlen(new_content); |
|---|
| 2108 | } |
|---|
| 2109 | } |
|---|
| 2110 | |
|---|
| 2111 | if (new_content) { |
|---|
| 2112 | error = GBT_write_string(gb_new_species, fieldName, new_content); |
|---|
| 2113 | free(new_content); |
|---|
| 2114 | } |
|---|
| 2115 | } |
|---|
| 2116 | } |
|---|
| 2117 | |
|---|
| 2118 | // mark field as done: |
|---|
| 2119 | char *new_doneFields = ARB_alloc<char>(doneLen+fieldLen+1+1); |
|---|
| 2120 | sprintf(new_doneFields, "%s%s;", doneFields, fieldName); |
|---|
| 2121 | doneLen += fieldLen+1; |
|---|
| 2122 | freeset(doneFields, new_doneFields); |
|---|
| 2123 | |
|---|
| 2124 | fieldEnd[0] = ';'; |
|---|
| 2125 | } |
|---|
| 2126 | |
|---|
| 2127 | fieldEnd[1] = behind; |
|---|
| 2128 | fieldStart = fieldEnd; |
|---|
| 2129 | } |
|---|
| 2130 | free(newFields); |
|---|
| 2131 | sl = sl->next; |
|---|
| 2132 | progress.inc_and_check_user_abort(error); |
|---|
| 2133 | } |
|---|
| 2134 | free(doneFields); |
|---|
| 2135 | delete [] fieldStat; |
|---|
| 2136 | } |
|---|
| 2137 | freeSpeciesMergeList(sml); sml = NULp; |
|---|
| 2138 | } |
|---|
| 2139 | } |
|---|
| 2140 | else { // copy species or create from consensus (copy fields from one species) |
|---|
| 2141 | e4_assert(where_we_are==ON_SPECIES); |
|---|
| 2142 | |
|---|
| 2143 | ED4_species_name_terminal *spec_name = cursor_terminal->to_sequence_terminal()->corresponding_species_name_terminal(); |
|---|
| 2144 | const char *source_name = spec_name->resolve_pointer_to_char_pntr(); |
|---|
| 2145 | GBDATA *gb_source = GBT_find_species_rel_species_data(gb_species_data, source_name); |
|---|
| 2146 | |
|---|
| 2147 | if (gb_source) { |
|---|
| 2148 | GBDATA *gb_new_species = GB_create_container(gb_species_data, "species"); |
|---|
| 2149 | error = GB_copy_dropProtectMarksAndTempstate(gb_new_species, gb_source); |
|---|
| 2150 | if (!error) error = GBT_write_string(gb_new_species, "name", new_species_name); |
|---|
| 2151 | if (!error) error = GBT_write_string(gb_new_species, "full_name", new_species_full_name); // insert new 'full_name' |
|---|
| 2152 | if (!error && creation_mode==CREATE_FROM_CONSENSUS) { |
|---|
| 2153 | ED4_group_manager *group_man = cursor_terminal->get_parent(LEV_GROUP)->to_group_manager(); |
|---|
| 2154 | error = createDataFromConsensus(gb_new_species, group_man); |
|---|
| 2155 | } |
|---|
| 2156 | } |
|---|
| 2157 | else { |
|---|
| 2158 | error = GBS_global_string("Can't find species '%s'", source_name); |
|---|
| 2159 | } |
|---|
| 2160 | } |
|---|
| 2161 | } |
|---|
| 2162 | |
|---|
| 2163 | error = GB_end_transaction(gb_main, error); |
|---|
| 2164 | if (!error) ED4_get_and_jump_to_species(new_species_name); |
|---|
| 2165 | } |
|---|
| 2166 | else { |
|---|
| 2167 | GB_abort_transaction(gb_main); |
|---|
| 2168 | } |
|---|
| 2169 | |
|---|
| 2170 | free(addid); |
|---|
| 2171 | free(acc); |
|---|
| 2172 | free(new_species_name); |
|---|
| 2173 | } |
|---|
| 2174 | |
|---|
| 2175 | aw_message_if(error); |
|---|
| 2176 | free(new_species_full_name); |
|---|
| 2177 | } |
|---|
| 2178 | |
|---|
| 2179 | AW_window *ED4_create_new_seq_window(AW_root *root, SpeciesCreationMode creation_mode) { |
|---|
| 2180 | e4_assert(valid(creation_mode)); |
|---|
| 2181 | |
|---|
| 2182 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 2183 | switch (creation_mode) { |
|---|
| 2184 | case CREATE_NEW_SPECIES: aws->init(root, "create_species", "Create species"); break; |
|---|
| 2185 | case CREATE_FROM_CONSENSUS: aws->init(root, "create_species_from_consensus", "Create species from consensus"); break; |
|---|
| 2186 | case COPY_SPECIES: aws->init(root, "copy_species", "Copy current species"); break; |
|---|
| 2187 | } |
|---|
| 2188 | |
|---|
| 2189 | if (creation_mode==CREATE_FROM_CONSENSUS) { |
|---|
| 2190 | aws->load_xfig("edit4/create_seq_fc.fig"); |
|---|
| 2191 | } |
|---|
| 2192 | else { |
|---|
| 2193 | aws->load_xfig("edit4/create_seq.fig"); |
|---|
| 2194 | } |
|---|
| 2195 | |
|---|
| 2196 | aws->callback(AW_POPDOWN); |
|---|
| 2197 | aws->at("close"); |
|---|
| 2198 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 2199 | |
|---|
| 2200 | aws->at("label"); |
|---|
| 2201 | aws->create_autosize_button(NULp, "Please enter the FULL_NAME\nof the new species"); |
|---|
| 2202 | |
|---|
| 2203 | aws->at("input"); |
|---|
| 2204 | aws->create_input_field(ED4_AWAR_SPECIES_TO_CREATE, 30); |
|---|
| 2205 | |
|---|
| 2206 | aws->at("ok"); |
|---|
| 2207 | aws->callback(makeWindowCallback(create_new_species, creation_mode)); |
|---|
| 2208 | aws->create_button("GO", "GO", "g"); |
|---|
| 2209 | |
|---|
| 2210 | if (creation_mode==CREATE_FROM_CONSENSUS) { |
|---|
| 2211 | aws->at("replace_equal"); |
|---|
| 2212 | aws->label("Replace '=' by "); |
|---|
| 2213 | aws->create_input_field(ED4_AWAR_CREATE_FROM_CONS_REPL_EQUAL, 1); |
|---|
| 2214 | |
|---|
| 2215 | aws->at("replace_point"); |
|---|
| 2216 | aws->label("Replace '.' by "); |
|---|
| 2217 | aws->create_input_field(ED4_AWAR_CREATE_FROM_CONS_REPL_POINT, 1); |
|---|
| 2218 | |
|---|
| 2219 | aws->at("replace_start_end"); |
|---|
| 2220 | aws->label("Create ... at ends of sequence?"); |
|---|
| 2221 | aws->create_toggle(ED4_AWAR_CREATE_FROM_CONS_CREATE_POINTS); |
|---|
| 2222 | |
|---|
| 2223 | aws->at("upper"); |
|---|
| 2224 | aws->label("Convert all chars to upper?"); |
|---|
| 2225 | aws->create_toggle(ED4_AWAR_CREATE_FROM_CONS_ALL_UPPER); |
|---|
| 2226 | |
|---|
| 2227 | aws->at("data"); |
|---|
| 2228 | aws->label("Other fields"); |
|---|
| 2229 | aws->create_option_menu(ED4_AWAR_CREATE_FROM_CONS_DATA_SOURCE, true); |
|---|
| 2230 | aws->insert_default_option("Merge from all in group", "", 0); |
|---|
| 2231 | aws->insert_option("Copy from current species", "", 1); |
|---|
| 2232 | aws->update_option_menu(); |
|---|
| 2233 | } |
|---|
| 2234 | |
|---|
| 2235 | return aws; |
|---|
| 2236 | } |
|---|
| 2237 | |
|---|