1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : ED4_terminal.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 | #include "ed4_class.hxx" |
---|
13 | #include "ed4_awars.hxx" |
---|
14 | #include "ed4_edit_string.hxx" |
---|
15 | #include "ed4_block.hxx" |
---|
16 | #include "ed4_nds.hxx" |
---|
17 | #include "ed4_ProteinViewer.hxx" |
---|
18 | #include "ed4_seq_colors.hxx" |
---|
19 | |
---|
20 | #include <arbdbt.h> |
---|
21 | |
---|
22 | #include <aw_preset.hxx> |
---|
23 | #include <aw_awar.hxx> |
---|
24 | #include <aw_awar_defs.hxx> |
---|
25 | #include <aw_msg.hxx> |
---|
26 | #include <aw_root.hxx> |
---|
27 | #include <aw_question.hxx> |
---|
28 | |
---|
29 | #include <st_window.hxx> |
---|
30 | |
---|
31 | // ----------------------------------- |
---|
32 | // static terminal properties |
---|
33 | |
---|
34 | static ED4_objspec tree_terminal_spec( |
---|
35 | ED4_P_IS_TERMINAL, // static props |
---|
36 | ED4_L_TREE, // level |
---|
37 | ED4_L_NO_LEVEL, // allowed children level |
---|
38 | ED4_L_NO_LEVEL, // handled object |
---|
39 | ED4_L_NO_LEVEL // restriction level |
---|
40 | ); |
---|
41 | |
---|
42 | static ED4_objspec bracket_terminal_spec( |
---|
43 | ED4_P_IS_TERMINAL, // static props |
---|
44 | ED4_L_BRACKET, // level |
---|
45 | ED4_L_NO_LEVEL, // allowed children level |
---|
46 | ED4_L_NO_LEVEL, // handled object |
---|
47 | ED4_L_NO_LEVEL // restriction level |
---|
48 | ); |
---|
49 | |
---|
50 | static ED4_objspec species_name_terminal_spec( |
---|
51 | ED4_P_IS_TERMINAL, // static props |
---|
52 | ED4_L_SPECIES_NAME, // level |
---|
53 | ED4_L_NO_LEVEL, // allowed children level |
---|
54 | ED4_L_SPECIES, // handled object |
---|
55 | ED4_L_NO_LEVEL // restriction level |
---|
56 | ); |
---|
57 | |
---|
58 | static ED4_objspec sequence_info_terminal_spec( |
---|
59 | ED4_P_IS_TERMINAL, // static props |
---|
60 | ED4_L_SEQUENCE_INFO, // level |
---|
61 | ED4_L_NO_LEVEL, // allowed children level |
---|
62 | ED4_L_SEQUENCE, // handled object |
---|
63 | ED4_L_NO_LEVEL // restriction level |
---|
64 | ); |
---|
65 | |
---|
66 | static ED4_objspec sequence_terminal_spec( |
---|
67 | ED4_P_IS_TERMINAL, // static props |
---|
68 | ED4_L_SEQUENCE_STRING, // level |
---|
69 | ED4_L_NO_LEVEL, // allowed children level |
---|
70 | ED4_L_NO_LEVEL, // handled object |
---|
71 | ED4_L_NO_LEVEL // restriction level |
---|
72 | ); |
---|
73 | |
---|
74 | static ED4_objspec orf_terminal_spec( |
---|
75 | ED4_P_IS_TERMINAL, // static props |
---|
76 | ED4_L_ORF, // level |
---|
77 | ED4_L_NO_LEVEL, // allowed children level |
---|
78 | ED4_L_NO_LEVEL, // handled object |
---|
79 | ED4_L_NO_LEVEL // restriction level |
---|
80 | ); |
---|
81 | |
---|
82 | static ED4_objspec pure_text_terminal_spec( |
---|
83 | ED4_P_IS_TERMINAL, // static props |
---|
84 | ED4_L_PURE_TEXT, // level |
---|
85 | ED4_L_NO_LEVEL, // allowed children level |
---|
86 | ED4_L_NO_LEVEL, // handled object |
---|
87 | ED4_L_NO_LEVEL // restriction level |
---|
88 | ); |
---|
89 | |
---|
90 | static ED4_objspec spacer_terminal_spec( |
---|
91 | ED4_P_IS_TERMINAL, // static props |
---|
92 | ED4_L_SPACER, // level |
---|
93 | ED4_L_NO_LEVEL, // allowed children level |
---|
94 | ED4_L_NO_LEVEL, // handled object |
---|
95 | ED4_L_NO_LEVEL // restriction level |
---|
96 | ); |
---|
97 | |
---|
98 | static ED4_objspec line_terminal_spec( |
---|
99 | ED4_P_IS_TERMINAL, // static props |
---|
100 | ED4_L_LINE, // level |
---|
101 | ED4_L_NO_LEVEL, // allowed children level |
---|
102 | ED4_L_NO_LEVEL, // handled object |
---|
103 | ED4_L_NO_LEVEL // restriction level |
---|
104 | ); |
---|
105 | |
---|
106 | static ED4_objspec column_stat_terminal_spec( |
---|
107 | ED4_P_IS_TERMINAL, // static props |
---|
108 | ED4_L_COL_STAT, // level |
---|
109 | ED4_L_NO_LEVEL, // allowed children level |
---|
110 | ED4_L_NO_LEVEL, // handled object |
---|
111 | ED4_L_NO_LEVEL // restriction level |
---|
112 | ); |
---|
113 | |
---|
114 | |
---|
115 | char *ED4_terminal::resolve_pointer_to_string_copy(int *str_len) const { |
---|
116 | int len; |
---|
117 | const char *s = resolve_pointer_to_char_pntr(&len); |
---|
118 | char *t = GB_strduplen(s, len); // space for zero byte is allocated by GB_strduplen |
---|
119 | |
---|
120 | if (str_len) *str_len = len; |
---|
121 | return t; |
---|
122 | } |
---|
123 | |
---|
124 | const char *ED4_terminal::resolve_pointer_to_char_pntr(int *str_len) const |
---|
125 | { |
---|
126 | GB_TYPES gb_type; |
---|
127 | const char *db_pointer = NULL; |
---|
128 | GBDATA *gbd = get_species_pointer(); |
---|
129 | |
---|
130 | if (!gbd) { |
---|
131 | if (str_len) { |
---|
132 | if (id) *str_len = strlen(id); |
---|
133 | else *str_len = 0; |
---|
134 | } |
---|
135 | return id; // if we don't have a link to the database we have to use our id |
---|
136 | } |
---|
137 | |
---|
138 | GB_push_transaction(GLOBAL_gb_main); |
---|
139 | |
---|
140 | const char *copy_of = 0; // if set, return a copy of this string |
---|
141 | |
---|
142 | gb_type = GB_read_type(gbd); |
---|
143 | #if defined(WARN_TODO) |
---|
144 | #warning temporary workaround - gb_type GB_INT and GB_FLOAT in the switch directive must not be displayed but ignored |
---|
145 | #endif |
---|
146 | switch (gb_type) |
---|
147 | { |
---|
148 | case GB_STRING: |
---|
149 | db_pointer = GB_read_char_pntr(gbd); |
---|
150 | if (str_len) { |
---|
151 | *str_len = GB_read_string_count(gbd); |
---|
152 | e4_assert(*str_len == (int)strlen(db_pointer)); |
---|
153 | } |
---|
154 | break; |
---|
155 | case GB_BITS: |
---|
156 | db_pointer = GB_read_bits_pntr(gbd, '.', '+'); |
---|
157 | if (str_len) { |
---|
158 | *str_len = GB_read_bits_count(gbd); |
---|
159 | e4_assert(*str_len == (int)strlen(db_pointer)); |
---|
160 | } |
---|
161 | break; |
---|
162 | case GB_BYTES: |
---|
163 | db_pointer = GB_read_bytes_pntr(gbd); |
---|
164 | if (str_len) { |
---|
165 | *str_len = GB_read_bytes_count(gbd); |
---|
166 | e4_assert(*str_len == (int)strlen(db_pointer)); |
---|
167 | } |
---|
168 | break; |
---|
169 | case GB_DB: |
---|
170 | copy_of = "GB_DB"; |
---|
171 | break; |
---|
172 | case GB_INT: // FIXME: temporary Workaround |
---|
173 | copy_of = "GB_INT"; |
---|
174 | break; |
---|
175 | case GB_INTS: |
---|
176 | copy_of = "GB_INTS"; |
---|
177 | break; |
---|
178 | case GB_FLOAT: // FIXME: temporary Workaround |
---|
179 | copy_of = "GB_FLOAT"; |
---|
180 | break; |
---|
181 | case GB_FLOATS: |
---|
182 | copy_of = "GB_FLOATS"; |
---|
183 | break; |
---|
184 | default: |
---|
185 | printf("Unknown data type - Please contact administrator\n"); |
---|
186 | e4_assert(0); |
---|
187 | break; |
---|
188 | } |
---|
189 | |
---|
190 | if (copy_of) { |
---|
191 | e4_assert(db_pointer == 0); |
---|
192 | |
---|
193 | int len = strlen(copy_of); |
---|
194 | db_pointer = GB_strduplen(copy_of, len); |
---|
195 | |
---|
196 | if (str_len) *str_len = len; |
---|
197 | } |
---|
198 | |
---|
199 | GB_pop_transaction(GLOBAL_gb_main); |
---|
200 | |
---|
201 | return db_pointer; |
---|
202 | } |
---|
203 | |
---|
204 | GB_ERROR ED4_terminal::write_sequence(const char *seq, int seq_len) |
---|
205 | { |
---|
206 | GB_ERROR err = 0; |
---|
207 | GBDATA *gbd = get_species_pointer(); |
---|
208 | e4_assert(gbd); // we must have a link to the database! |
---|
209 | |
---|
210 | GB_push_transaction(GLOBAL_gb_main); |
---|
211 | |
---|
212 | int old_seq_len; |
---|
213 | char *old_seq = resolve_pointer_to_string_copy(&old_seq_len); |
---|
214 | |
---|
215 | bool allow_write_data = true; |
---|
216 | if (ED4_ROOT->aw_root->awar(ED4_AWAR_ANNOUNCE_CHECKSUM_CHANGES)->read_int()) { |
---|
217 | long old_checksum = GBS_checksum(old_seq, 1, "-."); |
---|
218 | long new_checksum = GBS_checksum(seq, 1, "-."); |
---|
219 | |
---|
220 | if (old_checksum != new_checksum) { |
---|
221 | if (aw_question(NULL, "Checksum changed!", "Allow, Reject") == 1) { |
---|
222 | allow_write_data = false; |
---|
223 | } |
---|
224 | |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | if (allow_write_data) { |
---|
229 | GB_TYPES gb_type = GB_read_type(gbd); |
---|
230 | switch (gb_type) { |
---|
231 | case GB_STRING: { |
---|
232 | err = GB_write_string(gbd, seq); |
---|
233 | break; |
---|
234 | } |
---|
235 | case GB_BITS: { |
---|
236 | err = GB_write_bits(gbd, seq, seq_len, ".-"); |
---|
237 | break; |
---|
238 | } |
---|
239 | default: { |
---|
240 | e4_assert(0); |
---|
241 | break; |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | GB_pop_transaction(GLOBAL_gb_main); |
---|
247 | |
---|
248 | if (!err && dynamic_prop&ED4_P_CONSENSUS_RELEVANT) { |
---|
249 | if (old_seq) { |
---|
250 | curr_timestamp = GB_read_clock(GLOBAL_gb_main); |
---|
251 | |
---|
252 | get_parent(ED4_L_MULTI_SPECIES)->to_multi_species_manager() |
---|
253 | ->update_bases_and_rebuild_consensi(old_seq, old_seq_len, get_parent(ED4_L_SPECIES)->to_species_manager(), ED4_U_UP); // bases_check |
---|
254 | } |
---|
255 | else { |
---|
256 | aw_message("Couldn't read old sequence data"); |
---|
257 | } |
---|
258 | |
---|
259 | request_refresh(); |
---|
260 | } |
---|
261 | |
---|
262 | if (old_seq) free(old_seq); |
---|
263 | |
---|
264 | return err; |
---|
265 | } |
---|
266 | |
---|
267 | |
---|
268 | ED4_returncode ED4_terminal::remove_callbacks() // removes callbacks and gb_alignment |
---|
269 | { |
---|
270 | if (get_species_pointer()) { |
---|
271 | set_species_pointer(0); |
---|
272 | tflag.deleted = 1; // @@@ why ? |
---|
273 | clr_property(ED4_P_CURSOR_ALLOWED); |
---|
274 | request_refresh(); |
---|
275 | } |
---|
276 | return ED4_R_OK; |
---|
277 | } |
---|
278 | |
---|
279 | #if 0 |
---|
280 | static ARB_ERROR ed4_remove_species_manager_callbacks(ED4_base *base) { // @@@ unused since [8286] |
---|
281 | if (base->is_species_manager()) { |
---|
282 | base->to_species_manager()->remove_all_callbacks(); |
---|
283 | } |
---|
284 | return NULL; |
---|
285 | } |
---|
286 | #endif |
---|
287 | |
---|
288 | inline void remove_from_consensus(ED4_manager *group_or_species_man) { |
---|
289 | GB_transaction ta(GLOBAL_gb_main); |
---|
290 | ED4_manager *parent_manager = group_or_species_man->parent; |
---|
291 | parent_manager->update_consensus(parent_manager, NULL, group_or_species_man); |
---|
292 | parent_manager->rebuild_consensi(parent_manager, ED4_U_UP); |
---|
293 | } |
---|
294 | |
---|
295 | ED4_returncode ED4_terminal::kill_object() { |
---|
296 | ED4_species_manager *species_manager = get_parent(ED4_L_SPECIES)->to_species_manager(); |
---|
297 | |
---|
298 | if (species_manager->is_consensus_manager()) { // kill whole group |
---|
299 | if (ED4_new_species_multi_species_manager()==species_manager->parent) { |
---|
300 | aw_message("This group has to exist - deleting it isn't allowed"); |
---|
301 | return ED4_R_IMPOSSIBLE; |
---|
302 | } |
---|
303 | |
---|
304 | ED4_manager *group_manager = species_manager->get_parent(ED4_L_GROUP)->to_group_manager(); |
---|
305 | remove_from_consensus(group_manager); |
---|
306 | group_manager->Delete(); |
---|
307 | } |
---|
308 | else { // kill single species/SAI |
---|
309 | remove_from_consensus(species_manager); |
---|
310 | species_manager->Delete(); |
---|
311 | } |
---|
312 | |
---|
313 | return ED4_R_OK; |
---|
314 | } |
---|
315 | |
---|
316 | ED4_base *ED4_terminal::get_competent_clicked_child(AW_pos /* x */, AW_pos /* y */, ED4_properties /* relevant_prop */) |
---|
317 | { |
---|
318 | e4_assert(0); |
---|
319 | return NULL; |
---|
320 | } |
---|
321 | |
---|
322 | ED4_returncode ED4_terminal::handle_move(ED4_move_info * /* moveinfo */) |
---|
323 | { |
---|
324 | e4_assert(0); |
---|
325 | return ED4_R_IMPOSSIBLE; |
---|
326 | } |
---|
327 | |
---|
328 | ED4_returncode ED4_terminal::move_requested_by_child(ED4_move_info * /* moveinfo */) |
---|
329 | { |
---|
330 | e4_assert(0); |
---|
331 | return ED4_R_IMPOSSIBLE; |
---|
332 | } |
---|
333 | |
---|
334 | |
---|
335 | ED4_base *ED4_terminal::get_competent_child(AW_pos /* x */, AW_pos /* y */, ED4_properties /* relevant_prop */) |
---|
336 | { |
---|
337 | e4_assert(0); |
---|
338 | return NULL; |
---|
339 | } |
---|
340 | |
---|
341 | ED4_returncode ED4_terminal::draw_drag_box(AW_pos x, AW_pos y, GB_CSTR text, int cursor_y) { |
---|
342 | // draws drag box of object at location abs_x, abs_y |
---|
343 | |
---|
344 | if (cursor_y!=-1) { |
---|
345 | ED4_base *drag_target = NULL; |
---|
346 | { |
---|
347 | ED4_extension location; |
---|
348 | location.position[X_POS] = 0; |
---|
349 | location.position[Y_POS] = (AW_pos)cursor_y; // cursor_y is already in world coordinates |
---|
350 | |
---|
351 | ED4_ROOT->get_device_manager()->children->search_target_species(&location, ED4_P_HORIZONTAL, &drag_target, ED4_L_NO_LEVEL); |
---|
352 | } |
---|
353 | |
---|
354 | if (drag_target) { |
---|
355 | AW_pos target_x, target_y; |
---|
356 | |
---|
357 | drag_target->calc_world_coords (&target_x, &target_y); |
---|
358 | current_ed4w()->world_to_win_coords(&target_x, &target_y); |
---|
359 | |
---|
360 | #define ARROW_LENGTH 3 |
---|
361 | AW_pos drag_line_x0[3], drag_line_y0[3]; |
---|
362 | AW_pos drag_line_x1[3], drag_line_y1[3]; |
---|
363 | |
---|
364 | drag_line_x0[0] = target_x + 5; // horizontal |
---|
365 | drag_line_y0[0] = target_y + drag_target->extension.size[HEIGHT]; |
---|
366 | drag_line_x1[0] = drag_line_x0[0] + 50; |
---|
367 | drag_line_y1[0] = target_y + drag_target->extension.size[HEIGHT]; |
---|
368 | |
---|
369 | drag_line_x0[1] = drag_line_x0[0] -ARROW_LENGTH; // arrow |
---|
370 | drag_line_y0[1] = drag_line_y0[0] -ARROW_LENGTH; |
---|
371 | drag_line_x1[1] = drag_line_x0[0]; |
---|
372 | drag_line_y1[1] = drag_line_y0[0]; |
---|
373 | |
---|
374 | drag_line_x0[2] = drag_line_x0[0] -ARROW_LENGTH; // arrow |
---|
375 | drag_line_y0[2] = drag_line_y0[0] + ARROW_LENGTH; |
---|
376 | drag_line_x1[2] = drag_line_x0[0]; |
---|
377 | drag_line_y1[2] = drag_line_y0[0]; |
---|
378 | #undef ARROW_LENGTH |
---|
379 | |
---|
380 | for (ED4_index i = 0; i <= 2; i++) { |
---|
381 | current_device()->line(ED4_G_DRAG, drag_line_x0[i], drag_line_y0[i], drag_line_x1[i], drag_line_y1[i], AW_SCREEN); |
---|
382 | } |
---|
383 | } |
---|
384 | } |
---|
385 | |
---|
386 | if (text != NULL) { |
---|
387 | current_device()->text(ED4_G_DRAG, text, (x + 20), (y + INFO_TERM_TEXT_YOFFSET), 0, AW_SCREEN); |
---|
388 | } |
---|
389 | |
---|
390 | return ED4_R_OK; |
---|
391 | } |
---|
392 | |
---|
393 | ED4_returncode ED4_terminal::move_requested_by_parent(ED4_move_info *) { // handles a move request coming from parent |
---|
394 | e4_assert(0); |
---|
395 | return (ED4_R_IMPOSSIBLE); |
---|
396 | } |
---|
397 | |
---|
398 | void ED4_multi_species_manager::toggle_selected_species() { |
---|
399 | if (all_are_selected()) deselect_all_species_and_SAI(); |
---|
400 | else select_all(false); // species and SAI |
---|
401 | |
---|
402 | ED4_correctBlocktypeAfterSelection(); |
---|
403 | } |
---|
404 | |
---|
405 | #if defined(DEBUG) && 1 |
---|
406 | static inline void dumpEvent(const char *where, AW_event *event) { |
---|
407 | printf("%s: x=%i y=%i\n", where, event->x, event->y); |
---|
408 | } |
---|
409 | #else |
---|
410 | #define dumpEvent(w, e) |
---|
411 | #endif |
---|
412 | |
---|
413 | ED4_returncode ED4_terminal::event_sent_by_parent(AW_event *event, AW_window *aww) { |
---|
414 | // handles an input event coming from parent |
---|
415 | |
---|
416 | // static data to move terminal: |
---|
417 | static ED4_species_name_terminal *dragged_name_terminal = 0; |
---|
418 | |
---|
419 | static bool pressed_left_button = false; |
---|
420 | static int other_x, other_y; // coordinates of last event |
---|
421 | static bool dragged_was_selected = false; // the dragged terminal is temp. added to selected |
---|
422 | |
---|
423 | // ---------------------------- |
---|
424 | // drag/drop terminal |
---|
425 | if (dragged_name_terminal) { |
---|
426 | if (event->button == AW_BUTTON_LEFT) { |
---|
427 | switch (event->type) { |
---|
428 | case AW_Mouse_Drag: { |
---|
429 | ED4_selection_entry *sel_info = dragged_name_terminal->selection_info; |
---|
430 | |
---|
431 | if (pressed_left_button) { |
---|
432 | AW_pos world_x, world_y; |
---|
433 | |
---|
434 | dragged_name_terminal->calc_world_coords(&world_x, &world_y); |
---|
435 | current_ed4w()->world_to_win_coords(&world_x, &world_y); |
---|
436 | |
---|
437 | sel_info->drag_old_x = world_x; |
---|
438 | sel_info->drag_old_y = world_y; |
---|
439 | sel_info->drag_off_x = world_x-other_x; |
---|
440 | sel_info->drag_off_y = world_y-other_y; |
---|
441 | sel_info->old_event_y = -1; |
---|
442 | |
---|
443 | pressed_left_button = false; |
---|
444 | } |
---|
445 | |
---|
446 | GB_CSTR text = dragged_name_terminal->get_displayed_text(); |
---|
447 | |
---|
448 | if (dragged_name_terminal->dragged) { |
---|
449 | dragged_name_terminal->draw_drag_box(sel_info->drag_old_x, sel_info->drag_old_y, text, sel_info->old_event_y); |
---|
450 | } |
---|
451 | |
---|
452 | AW_pos new_x = sel_info->drag_off_x + event->x; |
---|
453 | AW_pos new_y = sel_info->drag_off_y + event->y; |
---|
454 | |
---|
455 | dragged_name_terminal->draw_drag_box(new_x, new_y, text, event->y); // @@@ event->y ist falsch, falls vertikal gescrollt ist! |
---|
456 | |
---|
457 | sel_info->drag_old_x = new_x; |
---|
458 | sel_info->drag_old_y = new_y; |
---|
459 | sel_info->old_event_y = event->y; |
---|
460 | |
---|
461 | dragged_name_terminal->dragged = true; |
---|
462 | break; |
---|
463 | } |
---|
464 | case AW_Mouse_Release: { |
---|
465 | if (dragged_name_terminal->dragged) { |
---|
466 | { |
---|
467 | char *db_pointer = dragged_name_terminal->resolve_pointer_to_string_copy(); |
---|
468 | ED4_selection_entry *sel_info = dragged_name_terminal->selection_info; |
---|
469 | |
---|
470 | dragged_name_terminal->draw_drag_box(sel_info->drag_old_x, sel_info->drag_old_y, db_pointer, sel_info->old_event_y); |
---|
471 | dragged_name_terminal->dragged = false; |
---|
472 | |
---|
473 | free(db_pointer); |
---|
474 | } |
---|
475 | { |
---|
476 | ED4_move_info mi; |
---|
477 | |
---|
478 | mi.object = dragged_name_terminal; |
---|
479 | mi.end_x = event->x; |
---|
480 | mi.end_y = event->y; |
---|
481 | mi.mode = ED4_M_FREE; |
---|
482 | mi.preferred_parent = ED4_L_NO_LEVEL; |
---|
483 | |
---|
484 | dragged_name_terminal->parent->move_requested_by_child(&mi); |
---|
485 | } |
---|
486 | { |
---|
487 | ED4_device_manager *device_manager = ED4_ROOT->get_device_manager(); |
---|
488 | |
---|
489 | for (int i=0; i<device_manager->children->members(); i++) { // when moving species numbers have to be recalculated |
---|
490 | ED4_base *member = device_manager->children->member(i); |
---|
491 | |
---|
492 | if (member->is_area_manager()) { |
---|
493 | member->to_area_manager()->get_multi_species_manager()->update_requested_by_child(); |
---|
494 | } |
---|
495 | } |
---|
496 | } |
---|
497 | } |
---|
498 | if (!dragged_was_selected) { |
---|
499 | ED4_ROOT->remove_from_selected(dragged_name_terminal); |
---|
500 | } |
---|
501 | |
---|
502 | pressed_left_button = false; |
---|
503 | dragged_name_terminal = 0; |
---|
504 | break; |
---|
505 | } |
---|
506 | default: |
---|
507 | break; |
---|
508 | } |
---|
509 | } |
---|
510 | } |
---|
511 | else { |
---|
512 | switch (event->button) { |
---|
513 | case AW_BUTTON_LEFT: { |
---|
514 | if (is_species_name_terminal()) { |
---|
515 | switch (ED4_ROOT->species_mode) { |
---|
516 | case ED4_SM_KILL: { |
---|
517 | if (event->type == AW_Mouse_Press) { |
---|
518 | if (containing_species_manager()->is_selected()) ED4_ROOT->remove_from_selected(this->to_species_name_terminal()); |
---|
519 | kill_object(); |
---|
520 | return ED4_R_BREAK; |
---|
521 | } |
---|
522 | break; |
---|
523 | } |
---|
524 | case ED4_SM_MOVE: { |
---|
525 | if (event->type == AW_Mouse_Press) { |
---|
526 | dragged_name_terminal = to_species_name_terminal(); |
---|
527 | pressed_left_button = true; |
---|
528 | |
---|
529 | other_x = event->x; |
---|
530 | other_y = event->y; |
---|
531 | |
---|
532 | dragged_was_selected = containing_species_manager()->is_selected(); |
---|
533 | if (!dragged_was_selected) { |
---|
534 | ED4_ROOT->add_to_selected(dragged_name_terminal); |
---|
535 | ED4_trigger_instant_refresh(); |
---|
536 | } |
---|
537 | } |
---|
538 | break; |
---|
539 | } |
---|
540 | case ED4_SM_INFO: |
---|
541 | case ED4_SM_MARK: { |
---|
542 | static ED4_species_manager *prev_clicked_species_man = NULL; |
---|
543 | ED4_species_manager *species_man = get_parent(ED4_L_SPECIES)->to_species_manager(); |
---|
544 | |
---|
545 | GBDATA *gbd = species_man->get_species_pointer(); |
---|
546 | if (gbd) { |
---|
547 | bool acceptClick = false; |
---|
548 | static int markHow = -1; // -1=invert, 0=unmark, 1=mark |
---|
549 | { |
---|
550 | switch (event->type) { |
---|
551 | case AW_Mouse_Press: |
---|
552 | acceptClick = true; |
---|
553 | markHow = -1; |
---|
554 | break; |
---|
555 | |
---|
556 | case AW_Mouse_Drag: |
---|
557 | acceptClick = prev_clicked_species_man != species_man; |
---|
558 | break; |
---|
559 | |
---|
560 | case AW_Mouse_Release: |
---|
561 | acceptClick = prev_clicked_species_man != species_man; |
---|
562 | prev_clicked_species_man = NULL; |
---|
563 | break; |
---|
564 | } |
---|
565 | } |
---|
566 | |
---|
567 | if (acceptClick) { |
---|
568 | if (ED4_ROOT->species_mode == ED4_SM_MARK) { |
---|
569 | if (markHow<0) markHow = !GB_read_flag(gbd); |
---|
570 | GB_write_flag(gbd, markHow); |
---|
571 | request_refresh(); |
---|
572 | if (ED4_ROOT->alignment_type == GB_AT_DNA) PV_RefreshWindow(aww->get_root()); // ProtView: Refreshing orf terminals (@@@ weird place to perform refresh) |
---|
573 | } |
---|
574 | else { |
---|
575 | e4_assert(ED4_ROOT->species_mode == ED4_SM_INFO); |
---|
576 | |
---|
577 | const char *name = GBT_read_name(gbd); |
---|
578 | if (name) { |
---|
579 | const char *awar_select = species_man->inside_SAI_manager() ? AWAR_SAI_NAME : AWAR_SPECIES_NAME; |
---|
580 | ED4_ROOT->aw_root->awar(awar_select)->write_string(name); |
---|
581 | } |
---|
582 | } |
---|
583 | prev_clicked_species_man = species_man; |
---|
584 | } |
---|
585 | } |
---|
586 | else { |
---|
587 | prev_clicked_species_man = NULL; |
---|
588 | } |
---|
589 | break; |
---|
590 | } |
---|
591 | } |
---|
592 | } |
---|
593 | else if (is_bracket_terminal()) { // fold/unfold group |
---|
594 | if (event->type == AW_Mouse_Press) { |
---|
595 | if (dynamic_prop & ED4_P_IS_FOLDED) to_bracket_terminal()->unfold(); |
---|
596 | else to_bracket_terminal()->fold(); |
---|
597 | } |
---|
598 | } |
---|
599 | else if (is_sequence_terminal()) { |
---|
600 | if (dynamic_prop & ED4_P_CURSOR_ALLOWED) { |
---|
601 | ED4_no_dangerous_modes(); |
---|
602 | current_cursor().show_clicked_cursor(event->x, this); |
---|
603 | } |
---|
604 | } |
---|
605 | break; |
---|
606 | } |
---|
607 | case AW_BUTTON_RIGHT: { |
---|
608 | // static data for block-selection: |
---|
609 | static bool select_started_on_seqterm = false; |
---|
610 | |
---|
611 | switch (event->type) { |
---|
612 | case AW_Mouse_Press: { |
---|
613 | select_started_on_seqterm = false; |
---|
614 | if (is_species_name_terminal()) { |
---|
615 | ED4_species_manager *species_man = get_parent(ED4_L_SPECIES)->to_species_manager(); |
---|
616 | |
---|
617 | if (species_man->is_consensus_manager()) { // click on consensus-name |
---|
618 | ED4_multi_species_manager *multi_man = species_man->get_parent(ED4_L_MULTI_SPECIES)->to_multi_species_manager(); |
---|
619 | multi_man->toggle_selected_species(); |
---|
620 | } |
---|
621 | else { // click on species or SAI name |
---|
622 | if (!species_man->is_selected()) { // select if not selected |
---|
623 | if (ED4_ROOT->add_to_selected(this->to_species_name_terminal()) == ED4_R_OK) ED4_correctBlocktypeAfterSelection(); |
---|
624 | } |
---|
625 | else { // deselect if already selected |
---|
626 | ED4_ROOT->remove_from_selected(this->to_species_name_terminal()); |
---|
627 | ED4_correctBlocktypeAfterSelection(); |
---|
628 | } |
---|
629 | } |
---|
630 | } |
---|
631 | else if (is_bracket_terminal()) { |
---|
632 | ED4_base *group = get_parent(ED4_L_GROUP); |
---|
633 | if (group) { |
---|
634 | group->to_group_manager()->get_multi_species_manager()->toggle_selected_species(); |
---|
635 | } |
---|
636 | } |
---|
637 | else if (is_sequence_terminal()) { |
---|
638 | ED4_no_dangerous_modes(); |
---|
639 | ED4_setColumnblockCorner(event, to_sequence_terminal()); // mark columnblock |
---|
640 | select_started_on_seqterm = true; |
---|
641 | } |
---|
642 | break; |
---|
643 | } |
---|
644 | |
---|
645 | case AW_Mouse_Drag: |
---|
646 | case AW_Mouse_Release: |
---|
647 | if (select_started_on_seqterm && is_sequence_terminal()) { |
---|
648 | ED4_no_dangerous_modes(); |
---|
649 | ED4_setColumnblockCorner(event, to_sequence_terminal()); // mark columnblock |
---|
650 | } |
---|
651 | break; |
---|
652 | |
---|
653 | default: |
---|
654 | break; |
---|
655 | } |
---|
656 | break; |
---|
657 | } |
---|
658 | |
---|
659 | default: break; |
---|
660 | } |
---|
661 | } |
---|
662 | |
---|
663 | return (ED4_R_OK); |
---|
664 | } |
---|
665 | |
---|
666 | void ED4_terminal::update_requested_children() {} |
---|
667 | |
---|
668 | bool ED4_terminal::calc_bounding_box() { |
---|
669 | // calculates the smallest rectangle containing the object. |
---|
670 | // requests refresh and returns true if bounding box has changed. |
---|
671 | |
---|
672 | bool bb_changed = false; |
---|
673 | |
---|
674 | if (width_link) { |
---|
675 | if (extension.size[WIDTH] != width_link->extension.size[WIDTH]) { // all bounding Boxes have the same size !!! |
---|
676 | extension.size[WIDTH] = width_link->extension.size[WIDTH]; |
---|
677 | bb_changed = true; |
---|
678 | } |
---|
679 | } |
---|
680 | |
---|
681 | if (height_link) { |
---|
682 | if (extension.size[HEIGHT] != height_link->extension.size[HEIGHT]) { |
---|
683 | extension.size[HEIGHT] = height_link->extension.size[HEIGHT]; |
---|
684 | bb_changed = true; |
---|
685 | } |
---|
686 | } |
---|
687 | |
---|
688 | |
---|
689 | if (bb_changed) { |
---|
690 | request_resize_of_linked(); |
---|
691 | request_refresh(); |
---|
692 | } |
---|
693 | return bb_changed; |
---|
694 | } |
---|
695 | |
---|
696 | void ED4_terminal::resize_requested_children() { |
---|
697 | if (update_info.resize) { // likes to resize? |
---|
698 | if (calc_bounding_box()) { |
---|
699 | request_resize(); |
---|
700 | } |
---|
701 | } |
---|
702 | } |
---|
703 | |
---|
704 | |
---|
705 | void ED4_terminal::request_refresh(int clear) { |
---|
706 | update_info.set_refresh(1); |
---|
707 | update_info.set_clear_at_refresh(clear); |
---|
708 | if (parent) parent->refresh_requested_by_child(); |
---|
709 | } |
---|
710 | |
---|
711 | |
---|
712 | ED4_base* ED4_terminal::search_ID(const char *temp_id) { |
---|
713 | if (id && strcmp(temp_id, id) == 0) return (this); |
---|
714 | return (NULL); |
---|
715 | } |
---|
716 | |
---|
717 | ED4_terminal::ED4_terminal(const ED4_objspec& spec_, GB_CSTR temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) : |
---|
718 | ED4_base(spec_, temp_id, x, y, width, height, temp_parent) |
---|
719 | { |
---|
720 | memset((char*)&tflag, 0, sizeof(tflag)); |
---|
721 | curr_timestamp = 0; |
---|
722 | } |
---|
723 | |
---|
724 | |
---|
725 | ED4_terminal::~ED4_terminal() { |
---|
726 | for (ED4_window *window = ED4_ROOT->first_window; window; window=window->next) { |
---|
727 | ED4_cursor& cursor = window->cursor; |
---|
728 | if (this == cursor.owner_of_cursor) { |
---|
729 | cursor.init(); |
---|
730 | } |
---|
731 | } |
---|
732 | } |
---|
733 | |
---|
734 | ED4_tree_terminal::ED4_tree_terminal(const char *temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
735 | : ED4_terminal(tree_terminal_spec, temp_id, x, y, width, height, temp_parent) |
---|
736 | { |
---|
737 | } |
---|
738 | |
---|
739 | ED4_returncode ED4_tree_terminal::Show(int IF_ASSERTION_USED(refresh_all), int is_cleared) |
---|
740 | { |
---|
741 | e4_assert(update_info.refresh || refresh_all); |
---|
742 | current_device()->push_clip_scale(); |
---|
743 | if (adjust_clipping_rectangle()) { |
---|
744 | if (update_info.clear_at_refresh && !is_cleared) { |
---|
745 | clear_background(); |
---|
746 | } |
---|
747 | draw(); |
---|
748 | } |
---|
749 | current_device()->pop_clip_scale(); |
---|
750 | |
---|
751 | return (ED4_R_OK); |
---|
752 | } |
---|
753 | |
---|
754 | |
---|
755 | |
---|
756 | ED4_returncode ED4_tree_terminal::draw() { |
---|
757 | AW_pos x, y; |
---|
758 | AW_pos text_x, text_y; |
---|
759 | char *db_pointer; |
---|
760 | |
---|
761 | calc_world_coords(&x, &y); |
---|
762 | current_ed4w()->world_to_win_coords(&x, &y); |
---|
763 | |
---|
764 | text_x = x + CHARACTEROFFSET; // don't change |
---|
765 | text_y = y + SEQ_TERM_TEXT_YOFFSET; |
---|
766 | |
---|
767 | db_pointer = resolve_pointer_to_string_copy(); |
---|
768 | current_device()->text(ED4_G_STANDARD, db_pointer, text_x, text_y, 0, AW_SCREEN); |
---|
769 | free(db_pointer); |
---|
770 | |
---|
771 | return (ED4_R_OK); |
---|
772 | } |
---|
773 | |
---|
774 | ED4_bracket_terminal::ED4_bracket_terminal(const char *temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
775 | : ED4_terminal(bracket_terminal_spec, temp_id, x, y, width, height, temp_parent) |
---|
776 | { |
---|
777 | } |
---|
778 | |
---|
779 | ED4_returncode ED4_bracket_terminal::Show(int IF_ASSERTION_USED(refresh_all), int is_cleared) |
---|
780 | { |
---|
781 | e4_assert(update_info.refresh || refresh_all); |
---|
782 | current_device()->push_clip_scale(); |
---|
783 | if (adjust_clipping_rectangle()) { |
---|
784 | if (update_info.clear_at_refresh && !is_cleared) { |
---|
785 | clear_background(); |
---|
786 | } |
---|
787 | draw(); |
---|
788 | } |
---|
789 | current_device()->pop_clip_scale(); |
---|
790 | |
---|
791 | return ED4_R_OK; |
---|
792 | } |
---|
793 | |
---|
794 | |
---|
795 | ED4_returncode ED4_bracket_terminal::draw() { |
---|
796 | using namespace AW; |
---|
797 | |
---|
798 | Rectangle term_area = get_win_area(current_ed4w()); |
---|
799 | AW_device *device = current_device(); |
---|
800 | |
---|
801 | ED4_multi_species_manager *multi_man = get_parent(ED4_L_GROUP)->to_group_manager()->get_multi_species_manager(); |
---|
802 | if (multi_man->get_no_of_selected_species()) { // if multi_species_manager contains selected species |
---|
803 | #if defined(DEBUG) && 0 |
---|
804 | static bool toggle = false; |
---|
805 | toggle = !toggle; |
---|
806 | device->box(toggle ? ED4_G_SELECTED : ED4_G_SELECTED+1, AW::FillStyle::SOLID, term_area); |
---|
807 | #else // !defined(DEBUG) |
---|
808 | device->box(ED4_G_SELECTED, AW::FillStyle::SOLID, term_area); |
---|
809 | #endif |
---|
810 | } |
---|
811 | |
---|
812 | if (dynamic_prop & ED4_P_IS_FOLDED) { // paint triangle for folded group |
---|
813 | Position t = term_area.upper_left_corner()+Vector(4,4); |
---|
814 | Position b = t+Vector(0,12); |
---|
815 | |
---|
816 | for (int i = 0; i<6; ++i) { |
---|
817 | device->line(ED4_G_STANDARD, t, b, AW_SCREEN); |
---|
818 | t += Vector(1, 1); |
---|
819 | b += Vector(1, -1); |
---|
820 | } |
---|
821 | e4_assert(nearlyEqual(t, b)); |
---|
822 | device->line(ED4_G_STANDARD, t, b, AW_SCREEN); // arrowhead |
---|
823 | } |
---|
824 | else { |
---|
825 | Position l = term_area.upper_left_corner()+Vector(4,5); |
---|
826 | Position r = l+Vector(6,0); |
---|
827 | |
---|
828 | for (int i = 0; i<3; ++i) { |
---|
829 | device->line(ED4_G_STANDARD, l, r, AW_SCREEN); |
---|
830 | l += Vector( 0, 1); |
---|
831 | r += Vector( 0, 1); |
---|
832 | device->line(ED4_G_STANDARD, l, r, AW_SCREEN); |
---|
833 | l += Vector( 1, 1); |
---|
834 | r += Vector(-1, 1); |
---|
835 | } |
---|
836 | e4_assert(nearlyEqual(l, r)); |
---|
837 | device->line(ED4_G_STANDARD, l, r+Vector(0,1), AW_SCREEN); // arrowhead |
---|
838 | } |
---|
839 | |
---|
840 | { |
---|
841 | Rectangle bracket(term_area.upper_left_corner()+Vector(2,2), term_area.diagonal()+Vector(-2,-4)); |
---|
842 | |
---|
843 | device->line(ED4_G_STANDARD, bracket.upper_edge(), AW_SCREEN); |
---|
844 | device->line(ED4_G_STANDARD, bracket.lower_edge(), AW_SCREEN); |
---|
845 | device->line(ED4_G_STANDARD, bracket.left_edge(), AW_SCREEN); |
---|
846 | } |
---|
847 | |
---|
848 | return (ED4_R_OK); |
---|
849 | } |
---|
850 | |
---|
851 | ED4_species_name_terminal::ED4_species_name_terminal(GB_CSTR temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) : |
---|
852 | ED4_text_terminal(species_name_terminal_spec, temp_id, x, y, width, height, temp_parent), |
---|
853 | selection_info(NULL), |
---|
854 | dragged(false) |
---|
855 | { |
---|
856 | } |
---|
857 | |
---|
858 | #define MAXNAMELEN MAXSPECIESWIDTH |
---|
859 | #define BUFFERSIZE (MAXNAMELEN<<1) |
---|
860 | GB_CSTR ED4_species_name_terminal::get_displayed_text() const |
---|
861 | { |
---|
862 | static char *real_name; |
---|
863 | static int allocatedSize; |
---|
864 | |
---|
865 | if (!real_name || allocatedSize<(BUFFERSIZE+1)) { |
---|
866 | free(real_name); |
---|
867 | allocatedSize = BUFFERSIZE+1; |
---|
868 | real_name = (char*)malloc(allocatedSize); |
---|
869 | } |
---|
870 | memset(real_name, 0, allocatedSize); |
---|
871 | |
---|
872 | ED4_species_manager *spec_man = get_parent(ED4_L_SPECIES)->to_species_manager(); |
---|
873 | |
---|
874 | if (spec_man->is_consensus_manager()) { |
---|
875 | char *db_pointer = resolve_pointer_to_string_copy(); |
---|
876 | char *bracket = strchr(db_pointer, '('); |
---|
877 | |
---|
878 | if (bracket) { |
---|
879 | int bracket_len = strlen(bracket); |
---|
880 | int name_len = bracket-db_pointer; |
---|
881 | |
---|
882 | if (bracket[-1]==' ') { |
---|
883 | name_len--; |
---|
884 | } |
---|
885 | |
---|
886 | if ((name_len+1+bracket_len)<=MAXNAMELEN) { |
---|
887 | strcpy(real_name, db_pointer); |
---|
888 | } |
---|
889 | else { |
---|
890 | int short_name_len = MAXNAMELEN-bracket_len-1; |
---|
891 | |
---|
892 | memcpy(real_name, db_pointer, short_name_len); |
---|
893 | real_name[short_name_len] = ' '; |
---|
894 | strcpy(real_name+short_name_len+1, bracket); |
---|
895 | } |
---|
896 | } |
---|
897 | else { |
---|
898 | strncpy(real_name, db_pointer, BUFFERSIZE); |
---|
899 | } |
---|
900 | |
---|
901 | free(db_pointer); |
---|
902 | } |
---|
903 | else if (spec_man->is_SAI_manager()) { |
---|
904 | char *db_pointer = resolve_pointer_to_string_copy(); |
---|
905 | |
---|
906 | strcpy(real_name, "SAI: "); |
---|
907 | if (strcmp(db_pointer, "ECOLI")==0) { |
---|
908 | const char *name_for_ecoli = ED4_ROOT->aw_root->awar(ED4_AWAR_NDS_ECOLI_NAME)->read_char_pntr(); |
---|
909 | if (name_for_ecoli[0]==0) name_for_ecoli = db_pointer; |
---|
910 | strncpy(real_name+5, name_for_ecoli, BUFFERSIZE-5); |
---|
911 | } |
---|
912 | else { |
---|
913 | strncpy(real_name+5, db_pointer, BUFFERSIZE-5); |
---|
914 | } |
---|
915 | free(db_pointer); |
---|
916 | } |
---|
917 | else { // normal species |
---|
918 | char *result = ED4_get_NDS_text(spec_man); |
---|
919 | strncpy(real_name, result, BUFFERSIZE); |
---|
920 | free(result); |
---|
921 | } |
---|
922 | |
---|
923 | return real_name; |
---|
924 | } |
---|
925 | #undef MAXNAMELEN |
---|
926 | #undef BUFFERSIZE |
---|
927 | |
---|
928 | |
---|
929 | ED4_sequence_info_terminal::ED4_sequence_info_terminal(const char *temp_id, /* GBDATA *gbd, */ AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
930 | : ED4_text_terminal(sequence_info_terminal_spec, temp_id, x, y, width, height, temp_parent) |
---|
931 | { |
---|
932 | } |
---|
933 | |
---|
934 | ED4_consensus_sequence_terminal::ED4_consensus_sequence_terminal(const char *temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
935 | : ED4_sequence_terminal(temp_id, x, y, width, height, temp_parent, false), |
---|
936 | temp_cons_seq(NULL) |
---|
937 | { |
---|
938 | species_name = NULL; |
---|
939 | } |
---|
940 | |
---|
941 | char *ED4_consensus_sequence_terminal::get_sequence_copy(int *str_len) const { |
---|
942 | return get_group_manager()->build_consensus_string(str_len); |
---|
943 | } |
---|
944 | |
---|
945 | int ED4_consensus_sequence_terminal::get_length() const { |
---|
946 | return get_char_table().size(); |
---|
947 | } |
---|
948 | |
---|
949 | |
---|
950 | ED4_abstract_sequence_terminal::ED4_abstract_sequence_terminal(const ED4_objspec& spec_, const char *temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
951 | : ED4_text_terminal(spec_, temp_id, x, y, width, height, temp_parent) |
---|
952 | { |
---|
953 | species_name = NULL; |
---|
954 | } |
---|
955 | |
---|
956 | ED4_abstract_sequence_terminal::~ED4_abstract_sequence_terminal() { |
---|
957 | free(species_name); |
---|
958 | } |
---|
959 | |
---|
960 | ED4_orf_terminal::ED4_orf_terminal(const char *temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
961 | : ED4_abstract_sequence_terminal(orf_terminal_spec, temp_id, x, y, width, height, temp_parent) |
---|
962 | { |
---|
963 | aaSequence = 0; |
---|
964 | aaSeqLen = 0; |
---|
965 | aaColor = 0; |
---|
966 | aaStartPos = 0; |
---|
967 | aaStrandType = 0; |
---|
968 | } |
---|
969 | |
---|
970 | GB_alignment_type ED4_orf_terminal::GetAliType() |
---|
971 | { |
---|
972 | return (GB_alignment_type) GB_AT_AA; |
---|
973 | } |
---|
974 | |
---|
975 | ED4_orf_terminal::~ED4_orf_terminal() |
---|
976 | { |
---|
977 | free(aaSequence); |
---|
978 | free(aaColor); |
---|
979 | } |
---|
980 | |
---|
981 | ED4_sequence_terminal::ED4_sequence_terminal(const char *temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent, bool shall_display_secstruct_info_) |
---|
982 | : ED4_abstract_sequence_terminal(sequence_terminal_spec, temp_id, x, y, width, height, temp_parent), |
---|
983 | shall_display_secstruct_info(shall_display_secstruct_info_) |
---|
984 | { |
---|
985 | st_ml_node = NULL; |
---|
986 | } |
---|
987 | |
---|
988 | GB_alignment_type ED4_sequence_terminal::GetAliType() |
---|
989 | { |
---|
990 | return ED4_ROOT->alignment_type; |
---|
991 | } |
---|
992 | |
---|
993 | ED4_pure_text_terminal::ED4_pure_text_terminal(const char *temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
994 | : ED4_text_terminal(pure_text_terminal_spec, temp_id, x, y, width, height, temp_parent) |
---|
995 | { |
---|
996 | } |
---|
997 | |
---|
998 | ED4_returncode ED4_spacer_terminal::Show(int /* refresh_all */, int is_cleared) { |
---|
999 | if (shallDraw) { |
---|
1000 | if (update_info.clear_at_refresh && !is_cleared) { |
---|
1001 | clear_background(); |
---|
1002 | } |
---|
1003 | draw(); |
---|
1004 | } |
---|
1005 | return ED4_R_OK; |
---|
1006 | } |
---|
1007 | |
---|
1008 | |
---|
1009 | ED4_returncode ED4_spacer_terminal::draw() { |
---|
1010 | #if defined(DEBUG) && 0 |
---|
1011 | clear_background(ED4_G_FIRST_COLOR_GROUP); // draw colored spacers to make them visible |
---|
1012 | #else |
---|
1013 | clear_background(0); |
---|
1014 | #endif // DEBUG |
---|
1015 | return (ED4_R_OK); |
---|
1016 | } |
---|
1017 | |
---|
1018 | ED4_spacer_terminal::ED4_spacer_terminal(const char *temp_id, bool shallDraw_, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
1019 | : ED4_terminal(spacer_terminal_spec, temp_id, x, y, width, height, temp_parent), |
---|
1020 | shallDraw(shallDraw_) |
---|
1021 | { |
---|
1022 | } |
---|
1023 | |
---|
1024 | ED4_returncode ED4_line_terminal::draw() { |
---|
1025 | AW_pos x1, y1; |
---|
1026 | calc_world_coords(&x1, &y1); |
---|
1027 | current_ed4w()->world_to_win_coords(&x1, &y1); |
---|
1028 | |
---|
1029 | AW_pos x2 = x1+extension.size[WIDTH]-1; |
---|
1030 | AW_pos y2 = y1+extension.size[HEIGHT]-1; |
---|
1031 | |
---|
1032 | AW_device *device = current_device(); |
---|
1033 | |
---|
1034 | device->line(ED4_G_STANDARD, x1, y1, x2, y1); |
---|
1035 | #if defined(DEBUG) |
---|
1036 | device->box(ED4_G_MARKED, AW::FillStyle::SOLID, x1, y1+1, x2-x1+1, y2-y1-1); |
---|
1037 | #else |
---|
1038 | device->clear_part(x1, y1+1, x2-x1+1, y2-y1-1, AW_ALL_DEVICES); |
---|
1039 | #endif // DEBUG |
---|
1040 | device->line(ED4_G_STANDARD, x1, y2, x2, y2); |
---|
1041 | |
---|
1042 | return ED4_R_OK; |
---|
1043 | } |
---|
1044 | |
---|
1045 | ED4_returncode ED4_line_terminal::Show(int /* refresh_all */, int is_cleared) |
---|
1046 | { |
---|
1047 | if (update_info.clear_at_refresh && !is_cleared) { |
---|
1048 | clear_background(); |
---|
1049 | } |
---|
1050 | draw(); |
---|
1051 | return ED4_R_OK; |
---|
1052 | } |
---|
1053 | |
---|
1054 | |
---|
1055 | ED4_line_terminal::ED4_line_terminal(const char *temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) |
---|
1056 | : ED4_terminal(line_terminal_spec, temp_id, x, y, width, height, temp_parent) |
---|
1057 | { |
---|
1058 | } |
---|
1059 | |
---|
1060 | // --------------------------------- |
---|
1061 | // ED4_columnStat_terminal |
---|
1062 | |
---|
1063 | ED4_returncode ED4_columnStat_terminal::Show(int IF_ASSERTION_USED(refresh_all), int is_cleared) |
---|
1064 | { |
---|
1065 | e4_assert(update_info.refresh || refresh_all); |
---|
1066 | current_device()->push_clip_scale(); |
---|
1067 | if (adjust_clipping_rectangle()) { |
---|
1068 | if (update_info.clear_at_refresh && !is_cleared) { |
---|
1069 | clear_background(); |
---|
1070 | } |
---|
1071 | draw(); |
---|
1072 | } |
---|
1073 | current_device()->pop_clip_scale(); |
---|
1074 | |
---|
1075 | return ED4_R_OK; |
---|
1076 | } |
---|
1077 | |
---|
1078 | inline char stat2display(int val, bool is_upper_digit) { |
---|
1079 | if (val<0) { |
---|
1080 | e4_assert(val==-1); // -1 indicates that no statistic is existing for that column |
---|
1081 | return '?'; |
---|
1082 | } |
---|
1083 | if (val==20) return ' '; // value if ACGT and - are distributed equally |
---|
1084 | if (val==100) return '^'; // we have only 2 characters to display likelihood (100 cannot be displayed) |
---|
1085 | |
---|
1086 | e4_assert(val>=0 && val<100); |
---|
1087 | |
---|
1088 | return '0' + (is_upper_digit ? (val/10) : (val%10)); |
---|
1089 | } |
---|
1090 | |
---|
1091 | inline int find_significant_positions(int sig, int like_A, int like_C, int like_G, int like_TU, int *sumPtr) { |
---|
1092 | // result == 0 -> no base-char has a significant likelihood (>=sig) |
---|
1093 | // result == 1, 2, 4, 8 -> A, C, G, T/U has a significant likelihood |
---|
1094 | // else -> the sum two of the likelihoods >= sig (bit-or-ed as in line above) |
---|
1095 | |
---|
1096 | int like[4]; |
---|
1097 | like[0] = like_A; |
---|
1098 | like[1] = like_C; |
---|
1099 | like[2] = like_G; |
---|
1100 | like[3] = like_TU; |
---|
1101 | |
---|
1102 | int bestSum = 0; |
---|
1103 | int bestResult = 0; |
---|
1104 | |
---|
1105 | int b, c; |
---|
1106 | for (b=0; b<4; b++) { |
---|
1107 | int sum = like[b]; |
---|
1108 | if (sum>=sig && sum>=bestSum) { |
---|
1109 | bestSum = sum; |
---|
1110 | bestResult = 1<<b; |
---|
1111 | } |
---|
1112 | } |
---|
1113 | |
---|
1114 | if (!bestResult) { |
---|
1115 | for (b=0; b<4; b++) { |
---|
1116 | for (c=b+1; c<4; c++) { |
---|
1117 | int sum = like[b]+like[c]; |
---|
1118 | if (sum>=sig && sum>=bestSum) { |
---|
1119 | bestSum = sum; |
---|
1120 | bestResult = (1<<b)|(1<<c); |
---|
1121 | } |
---|
1122 | } |
---|
1123 | } |
---|
1124 | } |
---|
1125 | |
---|
1126 | if (bestResult) { |
---|
1127 | if (sumPtr) *sumPtr = bestSum; |
---|
1128 | return bestResult; |
---|
1129 | } |
---|
1130 | |
---|
1131 | return 0; |
---|
1132 | } |
---|
1133 | |
---|
1134 | #define PROBE_MATCH_TARGET_STRING_LENGTH 32 |
---|
1135 | |
---|
1136 | GB_CSTR ED4_columnStat_terminal::build_probe_match_string(PosRange range) const { |
---|
1137 | static char result[PROBE_MATCH_TARGET_STRING_LENGTH+1]; // see create_probe_match_window() for length |
---|
1138 | int max_insert = PROBE_MATCH_TARGET_STRING_LENGTH; |
---|
1139 | char *r = result; |
---|
1140 | int significance = int(get_threshold()); |
---|
1141 | ED4_sequence_terminal *seq_term = corresponding_sequence_terminal(); |
---|
1142 | char *seq = seq_term->resolve_pointer_to_string_copy(); |
---|
1143 | |
---|
1144 | for (int pos=range.start(); pos<=range.end(); pos++) { |
---|
1145 | int found = find_significant_positions(significance, likelihood[0][pos], likelihood[1][pos], likelihood[2][pos], likelihood[3][pos], 0); |
---|
1146 | |
---|
1147 | if (found || strchr("-=.", seq[pos])==0) { |
---|
1148 | // '?' is inserted at every base position without significant bases (not at gaps!) |
---|
1149 | |
---|
1150 | *r++ = "NACMGRSVUWYHKDBN"[found]; // this creates a string containing the full IUPAC code |
---|
1151 | |
---|
1152 | if (max_insert--==0) { |
---|
1153 | r--; |
---|
1154 | break; |
---|
1155 | } |
---|
1156 | } |
---|
1157 | } |
---|
1158 | r[0] = 0; |
---|
1159 | free(seq); |
---|
1160 | |
---|
1161 | if (max_insert<0) { |
---|
1162 | aw_message(GBS_global_string("Max. %i bases allowed in Probe Match", PROBE_MATCH_TARGET_STRING_LENGTH)); |
---|
1163 | result[0] = 0; |
---|
1164 | } |
---|
1165 | return result; |
---|
1166 | } |
---|
1167 | #undef PROBE_MATCH_TARGET_STRING_LENGTH |
---|
1168 | |
---|
1169 | ED4_returncode ED4_columnStat_terminal::draw() { |
---|
1170 | if (!update_likelihood()) { |
---|
1171 | aw_message("Can't calculate likelihood."); |
---|
1172 | return ED4_R_IMPOSSIBLE; |
---|
1173 | } |
---|
1174 | |
---|
1175 | AW_pos x, y; |
---|
1176 | calc_world_coords(&x, &y); |
---|
1177 | current_ed4w()->world_to_win_coords(&x, &y); |
---|
1178 | |
---|
1179 | AW_pos term_height = extension.size[HEIGHT]; |
---|
1180 | AW_pos font_height = ED4_ROOT->font_group.get_height(ED4_G_SEQUENCES); |
---|
1181 | AW_pos font_width = ED4_ROOT->font_group.get_width(ED4_G_SEQUENCES); |
---|
1182 | |
---|
1183 | AW_pos text_x = x + CHARACTEROFFSET; |
---|
1184 | AW_pos text_y = y + term_height - font_height; |
---|
1185 | |
---|
1186 | AW_device *device = current_device(); |
---|
1187 | ED4_sequence_terminal *seq_term = corresponding_sequence_terminal(); |
---|
1188 | const ED4_remap *rm = ED4_ROOT->root_group_man->remap(); |
---|
1189 | |
---|
1190 | PosRange index_range = rm->clip_screen_range(seq_term->calc_update_interval()); |
---|
1191 | { |
---|
1192 | int max_seq_len = seq_term->get_length(); |
---|
1193 | int max_seq_pos = rm->sequence_to_screen(max_seq_len); |
---|
1194 | |
---|
1195 | index_range = ExplicitRange(index_range, max_seq_pos); |
---|
1196 | if (index_range.is_empty()) return ED4_R_OK; |
---|
1197 | } |
---|
1198 | |
---|
1199 | const int left = index_range.start(); |
---|
1200 | const int right = index_range.end(); |
---|
1201 | |
---|
1202 | char *sbuffer = new char[right+2]; // used to build displayed terminal content (values = '0'-'9') |
---|
1203 | memset(sbuffer, ' ', right+1); |
---|
1204 | sbuffer[right+1] = 0; // eos |
---|
1205 | |
---|
1206 | AW_pos y2; |
---|
1207 | int r; |
---|
1208 | |
---|
1209 | // Set background: |
---|
1210 | { |
---|
1211 | int significance = int(get_threshold()); |
---|
1212 | // normal columns are colored in ED4_G_STANDARD |
---|
1213 | // all columns with one (or sum of two) probability above 'significance' are back-colored in ED4_G_CBACK_0 |
---|
1214 | // the responsible probabilities (one or two) are back-colored in ED4_G_CBACK_1..ED4_G_CBACK_9 |
---|
1215 | |
---|
1216 | int old_color = ED4_G_STANDARD; |
---|
1217 | |
---|
1218 | AW_pos x2 = text_x + font_width*left + 1; |
---|
1219 | AW_pos old_x2 = x2; |
---|
1220 | |
---|
1221 | PosRange selection; |
---|
1222 | bool is_selected = ED4_get_selected_range(seq_term, selection); |
---|
1223 | |
---|
1224 | for (int i=left; i<=right; i++, x2+=font_width) { // colorize significant columns in ALL rows |
---|
1225 | int p = rm->screen_to_sequence(i); |
---|
1226 | int found = find_significant_positions(significance, likelihood[0][p], likelihood[1][p], likelihood[2][p], likelihood[3][p], 0); |
---|
1227 | |
---|
1228 | int color; |
---|
1229 | if (is_selected && selection.contains(p)) { |
---|
1230 | color = ED4_G_SELECTED; |
---|
1231 | } |
---|
1232 | else { |
---|
1233 | color = found ? ED4_G_CBACK_0 : ED4_G_STANDARD; |
---|
1234 | } |
---|
1235 | |
---|
1236 | if (color!=old_color) { |
---|
1237 | if (x2>old_x2 && old_color!=ED4_G_STANDARD) { |
---|
1238 | device->box(old_color, AW::FillStyle::SOLID, old_x2, y, x2-old_x2, term_height); |
---|
1239 | } |
---|
1240 | old_color = color; |
---|
1241 | old_x2 = x2; |
---|
1242 | } |
---|
1243 | } |
---|
1244 | if (x2>old_x2 && old_color!=ED4_G_STANDARD) { |
---|
1245 | device->box(old_color, AW::FillStyle::SOLID, old_x2, y, x2-old_x2, term_height); |
---|
1246 | } |
---|
1247 | |
---|
1248 | x2 = text_x + font_width*left + 1; |
---|
1249 | |
---|
1250 | for (int i=left; i<=right; i++, x2+=font_width) { // colorize significant columns in SINGLE rows |
---|
1251 | int p = rm->screen_to_sequence(i); |
---|
1252 | int sum; |
---|
1253 | int found = find_significant_positions(significance, likelihood[0][p], likelihood[1][p], likelihood[2][p], likelihood[3][p], &sum); |
---|
1254 | |
---|
1255 | if (found && significance<100) { |
---|
1256 | e4_assert(sum>=significance && sum<=100); |
---|
1257 | int color = ED4_G_CBACK_1+((sum-significance)*(ED4_G_CBACK_9-ED4_G_CBACK_1))/(100-significance); |
---|
1258 | e4_assert(color>=ED4_G_CBACK_1 && color<=ED4_G_CBACK_9); |
---|
1259 | |
---|
1260 | if (color!=ED4_G_STANDARD) { |
---|
1261 | int bit; |
---|
1262 | |
---|
1263 | for (r=3, y2=text_y+1, bit=1<<3; |
---|
1264 | r>=0; |
---|
1265 | r--, y2-=COLUMN_STAT_ROW_HEIGHT(font_height), bit>>=1) |
---|
1266 | { |
---|
1267 | if (found&bit) { |
---|
1268 | device->box(color, AW::FillStyle::SOLID, x2, y2-2*font_height+1, font_width, 2*font_height); |
---|
1269 | } |
---|
1270 | } |
---|
1271 | } |
---|
1272 | } |
---|
1273 | } |
---|
1274 | } |
---|
1275 | |
---|
1276 | // Draw text: |
---|
1277 | for (r=3, y2=text_y; |
---|
1278 | r>=0; |
---|
1279 | r--, y2-=COLUMN_STAT_ROW_HEIGHT(font_height)) { // 4 rows (one for T/U, G, C and A) |
---|
1280 | |
---|
1281 | int gc = ED4_ROOT->sequence_colors->char_2_gc[(unsigned char)"ACGU"[r]]; |
---|
1282 | int i; |
---|
1283 | for (i=left; i<=right; i++) { |
---|
1284 | int p = rm->screen_to_sequence(i); |
---|
1285 | int val = likelihood[r][p]; |
---|
1286 | sbuffer[i] = stat2display(val, 0); // calc lower digit |
---|
1287 | } |
---|
1288 | device->text(gc, sbuffer, text_x+font_width*0.2, y2, 0, AW_SCREEN, right); // draw lower-significant digit (shifted a bit to the right) |
---|
1289 | |
---|
1290 | for (i=left; i<=right; i++) { |
---|
1291 | int p = rm->screen_to_sequence(i); |
---|
1292 | int val = likelihood[r][p]; |
---|
1293 | sbuffer[i] = stat2display(val, 1); // calc upper digit |
---|
1294 | } |
---|
1295 | device->text(gc, sbuffer, text_x, y2-font_height, 0, AW_SCREEN, right); // draw higher-significant digit |
---|
1296 | } |
---|
1297 | |
---|
1298 | delete [] sbuffer; |
---|
1299 | return ED4_R_OK; |
---|
1300 | } |
---|
1301 | |
---|
1302 | int ED4_columnStat_terminal::update_likelihood() { |
---|
1303 | ED4_sequence_terminal *seq_term = corresponding_sequence_terminal(); |
---|
1304 | |
---|
1305 | return STAT_update_ml_likelihood(ED4_ROOT->st_ml, likelihood, latest_update, 0, seq_term->st_ml_node); |
---|
1306 | } |
---|
1307 | |
---|
1308 | ED4_columnStat_terminal::ED4_columnStat_terminal(GB_CSTR temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) : |
---|
1309 | ED4_text_terminal(column_stat_terminal_spec, temp_id, x, y, width, height, temp_parent) |
---|
1310 | { |
---|
1311 | for (int i=0; i<4; i++) likelihood[i] = 0; |
---|
1312 | latest_update = 0; |
---|
1313 | } |
---|
1314 | |
---|
1315 | ED4_columnStat_terminal::~ED4_columnStat_terminal() |
---|
1316 | { |
---|
1317 | for (int i=0; i<4; i++) free(likelihood[i]); |
---|
1318 | } |
---|
1319 | |
---|
1320 | // --------------------------------- |
---|
1321 | // ED4_reference_terminals |
---|
1322 | |
---|
1323 | void ED4_reference_terminals::clear() |
---|
1324 | { |
---|
1325 | delete ref_sequence_info; |
---|
1326 | delete ref_sequence; |
---|
1327 | delete ref_column_stat; |
---|
1328 | delete ref_column_stat_info; |
---|
1329 | null(); |
---|
1330 | } |
---|
1331 | |
---|
1332 | void ED4_reference_terminals::init(ED4_sequence_info_terminal *ref_sequence_info_, |
---|
1333 | ED4_sequence_terminal *ref_sequence_, |
---|
1334 | ED4_sequence_info_terminal *ref_column_stat_info_, |
---|
1335 | ED4_columnStat_terminal *ref_column_stat_) |
---|
1336 | { |
---|
1337 | clear(); |
---|
1338 | ref_sequence_info = ref_sequence_info_; |
---|
1339 | ref_sequence = ref_sequence_; |
---|
1340 | ref_column_stat_info = ref_column_stat_info_; |
---|
1341 | ref_column_stat = ref_column_stat_; |
---|
1342 | } |
---|