1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : SEC_paint.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include "SEC_root.hxx" |
---|
12 | #include "SEC_graphic.hxx" |
---|
13 | #include "SEC_iter.hxx" |
---|
14 | #include "SEC_drawn_pos.hxx" |
---|
15 | #include "SEC_bonddef.hxx" |
---|
16 | #include "SEC_toggle.hxx" |
---|
17 | |
---|
18 | #include <aw_msg.hxx> |
---|
19 | #include <iupac.h> |
---|
20 | |
---|
21 | #include <ed4_extern.hxx> |
---|
22 | |
---|
23 | #include <arb_defs.h> |
---|
24 | |
---|
25 | #include <iostream> |
---|
26 | #include <sstream> |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | // ------------------- |
---|
31 | // Debugging |
---|
32 | |
---|
33 | #if defined(ASSERTION_USED) |
---|
34 | |
---|
35 | inline bool valid_cb_params(AW_CL cd1, AW_CL cd2) { |
---|
36 | return cd1 == 0 || cd2 != -1; |
---|
37 | } |
---|
38 | inline bool valid_cb_params(AW_device *device) { |
---|
39 | const AW_click_cd *cd = device->get_click_cd(); |
---|
40 | return valid_cb_params(cd->get_cd1(), cd->get_cd2()); |
---|
41 | } |
---|
42 | |
---|
43 | #endif |
---|
44 | |
---|
45 | #if defined(DEBUG) |
---|
46 | // #define PAINT_REGION_INDEX // // paint region-internal index next to base |
---|
47 | |
---|
48 | static void paintDebugInfo(AW_device *device, int color, const Position& pos, const char *txt) { |
---|
49 | sec_assert(valid_cb_params(device)); |
---|
50 | device->circle(color, AW::FillStyle::SOLID, pos.xpos(), pos.ypos(), 0.06, 0.06); |
---|
51 | device->text(SEC_GC_DEFAULT, txt, pos.xpos(), pos.ypos(), 0, AW_SCREEN); |
---|
52 | } |
---|
53 | static void paintStrandDebugInfo(AW_device *device, int color, SEC_helix_strand *strand) { |
---|
54 | AW_click_cd cd(device, strand->self(), strand->rightAttachAbspos()); paintDebugInfo(device, color, strand->rightAttachPoint(), "RAP"); |
---|
55 | cd.set_cd2(strand->leftAttachAbspos()); paintDebugInfo(device, color, strand->leftAttachPoint(), "LAP"); |
---|
56 | cd.set_cd2(strand->startAttachAbspos()); paintDebugInfo(device, color, strand->get_fixpoint(), strand->isRootsideFixpoint() ? "RFP" : "FP"); |
---|
57 | } |
---|
58 | |
---|
59 | #endif // DEBUG |
---|
60 | |
---|
61 | // ------------------- |
---|
62 | // PaintData |
---|
63 | |
---|
64 | class PaintData { |
---|
65 | int gc_edit4_to_secedit[ED4_G_DRAG+1]; // GC translation table (EDIT4 -> SECEDIT) |
---|
66 | int line_property_gc[SEC_GC_LAST_DATA+1][SEC_GC_LAST_DATA+1]; // of two GCs, which is responsible for line properties |
---|
67 | |
---|
68 | public: |
---|
69 | PaintData() { |
---|
70 | int gc; |
---|
71 | |
---|
72 | // GC translation (EDIT4->SECEDIT) |
---|
73 | for (gc = 0; gc <= ED4_G_DRAG; gc++) { |
---|
74 | gc_edit4_to_secedit[gc] = -1; // invalid |
---|
75 | } |
---|
76 | for (gc = ED4_G_SBACK_0; gc <= ED4_G_SBACK_8; gc++) { // IRRELEVANT_LOOP |
---|
77 | gc_edit4_to_secedit[gc] = gc-ED4_G_SBACK_0+SEC_GC_SBACK_0; |
---|
78 | } |
---|
79 | for (gc = ED4_G_CBACK_0; gc <= ED4_G_CBACK_9; gc++) { // IRRELEVANT_LOOP |
---|
80 | gc_edit4_to_secedit[gc] = gc-ED4_G_CBACK_0+SEC_GC_CBACK_0; |
---|
81 | } |
---|
82 | |
---|
83 | // calc line property GCs |
---|
84 | for (gc = SEC_GC_FIRST_DATA; gc <= SEC_GC_LAST_DATA; gc++) { |
---|
85 | for (int gc2 = SEC_GC_FIRST_DATA; gc <= SEC_GC_LAST_DATA; gc++) { |
---|
86 | int prop_gc; |
---|
87 | if (gc == gc2) { |
---|
88 | prop_gc = gc; |
---|
89 | } |
---|
90 | else { |
---|
91 | if (gc == SEC_GC_LOOP || gc2 == SEC_GC_LOOP) { |
---|
92 | prop_gc = SEC_GC_LOOP; // use loop-properties in loop and at loop-helix-transition |
---|
93 | } |
---|
94 | else if (gc == SEC_GC_NHELIX || gc2 == SEC_GC_NHELIX) { |
---|
95 | prop_gc = SEC_GC_NHELIX; // use nhelix-properties in nhelix and at helix-nhelix-transition |
---|
96 | } |
---|
97 | else { |
---|
98 | prop_gc = SEC_GC_HELIX; // use helix-properties in helix |
---|
99 | } |
---|
100 | } |
---|
101 | line_property_gc[gc][gc2] = prop_gc; |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | int convert_BackgroundGC(int edit4_gc) const { |
---|
107 | // returns -1 if edit4_gc is invalid |
---|
108 | sec_assert(edit4_gc >= 0 && edit4_gc <= ED4_G_DRAG); |
---|
109 | return gc_edit4_to_secedit[edit4_gc]; |
---|
110 | } |
---|
111 | |
---|
112 | int get_linePropertyGC(int gc1, int gc2) { |
---|
113 | // of the GCs of two positions, it returns the GC which is |
---|
114 | // defining the properties for the background painted in-between the two positions |
---|
115 | sec_assert(gc1 >= SEC_GC_FIRST_DATA && gc1 <= SEC_GC_LAST_DATA); |
---|
116 | sec_assert(gc2 >= SEC_GC_FIRST_DATA && gc2 <= SEC_GC_LAST_DATA); |
---|
117 | return line_property_gc[gc1][gc2]; |
---|
118 | } |
---|
119 | }; |
---|
120 | |
---|
121 | static PaintData paintData; |
---|
122 | |
---|
123 | // --------------------- |
---|
124 | // Annotations |
---|
125 | |
---|
126 | void SEC_root::paintAnnotation(AW_device *device, int gc, |
---|
127 | const Position& pos, const Position& left, const Position& right, |
---|
128 | double noteDistance, const char *text, |
---|
129 | bool lineToPos, bool linesToLeftRight, bool boxText) |
---|
130 | { |
---|
131 | // draw annotation to explicit position 'pos' (annotation is drawn "above" the line left->right) |
---|
132 | // The distance between pos and note is determined by |
---|
133 | // * textsize (minimal half textsize/boxsize) and |
---|
134 | // * the given 'noteDistance' |
---|
135 | // lineToPos == true -> draw a line from text to 'pos' |
---|
136 | // linesToLeftRight == true -> draw lines from text to 'left' and 'right' |
---|
137 | // boxText == true -> draw a box around text |
---|
138 | |
---|
139 | sec_assert(valid_cb_params(device)); |
---|
140 | |
---|
141 | Vector strand(left, right); |
---|
142 | Angle pos2note(strand); |
---|
143 | pos2note.rotate270deg(); |
---|
144 | |
---|
145 | int fontgc = gc <= SEC_GC_LAST_FONT ? gc : SEC_GC_DEFAULT; |
---|
146 | double half_charSize = center_char[fontgc].length(); |
---|
147 | |
---|
148 | SizedCstr stext(text); |
---|
149 | |
---|
150 | // calculate textsize |
---|
151 | AW_pos half_width = 0.5 * device->rtransform_size(device->get_string_size(gc, stext)); |
---|
152 | AW_pos half_height = center_char[fontgc].y(); |
---|
153 | |
---|
154 | double note_distance = max(half_height, half_width) * (boxText ? 1.3 : 1.0); |
---|
155 | note_distance = max(note_distance, noteDistance); |
---|
156 | |
---|
157 | Position note_center = pos + pos2note.normal()*note_distance; |
---|
158 | |
---|
159 | if (device->get_filter() & AW_PRINTER) { |
---|
160 | boxText = false; // don't print/xfig-export boxes |
---|
161 | } |
---|
162 | |
---|
163 | if (lineToPos || linesToLeftRight) { |
---|
164 | device->set_line_attributes(gc, 1, AW_SOLID); |
---|
165 | |
---|
166 | if (lineToPos) { |
---|
167 | Vector dist = pos2note.normal()*half_charSize; |
---|
168 | device->line(gc, boxText ? note_center : note_center-dist, pos+dist); |
---|
169 | } |
---|
170 | if (linesToLeftRight) { |
---|
171 | Vector out(pos, note_center); |
---|
172 | |
---|
173 | if (out.length()*2 >= strand.length()) { // short strands -> draw simple bracket |
---|
174 | Vector toLeft(note_center, left); |
---|
175 | Vector toRight(note_center, right); |
---|
176 | |
---|
177 | device->line(gc, boxText ? note_center : note_center+toLeft*(half_width/toLeft.length()), |
---|
178 | left-toLeft*(half_charSize/toLeft.length()), AW_ALL_DEVICES_SCALED); |
---|
179 | device->line(gc, boxText ? note_center : note_center+toRight*(half_width/toRight.length()), |
---|
180 | right-toRight*(half_charSize/toRight.length()), AW_ALL_DEVICES_SCALED); |
---|
181 | } |
---|
182 | else { |
---|
183 | Vector rightIndent = out; |
---|
184 | rightIndent.rotate270deg(); |
---|
185 | |
---|
186 | Position rightOut = right+out+rightIndent; |
---|
187 | Position leftOut = left+out-rightIndent; |
---|
188 | |
---|
189 | Vector posPad = Vector(right, rightOut).set_length(half_charSize); |
---|
190 | device->line(gc, right+posPad, rightOut); |
---|
191 | posPad.rotate90deg(); |
---|
192 | device->line(gc, left+posPad, leftOut); |
---|
193 | |
---|
194 | if (boxText) { |
---|
195 | device->line(gc, leftOut, rightOut); |
---|
196 | } |
---|
197 | else { |
---|
198 | Vector rightTextPad(note_center, rightOut); |
---|
199 | rightTextPad.set_length(half_width); |
---|
200 | |
---|
201 | device->line(gc, note_center+rightTextPad, rightOut); |
---|
202 | device->line(gc, note_center-rightTextPad, leftOut); |
---|
203 | } |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | Vector center_textcorner(-half_width, half_height); // from center to lower left corner |
---|
209 | Position textcorner = note_center+center_textcorner; |
---|
210 | |
---|
211 | if (boxText) { |
---|
212 | Vector center_corner(-half_width-half_height*0.3, half_height*1.3); // box is 25% bigger than text |
---|
213 | Rectangle box(note_center+center_corner, -2*center_corner); |
---|
214 | |
---|
215 | device->clear_part(box, -1); |
---|
216 | device->box(gc, AW::FillStyle::EMPTY, box); |
---|
217 | } |
---|
218 | |
---|
219 | device->text(gc, text, textcorner); |
---|
220 | } |
---|
221 | |
---|
222 | void SEC_root::paintPosAnnotation(AW_device *device, int gc, size_t absPos, const char *text, bool lineToBase, bool boxText) { |
---|
223 | // draw a annotation next to a base (only works after paint()). |
---|
224 | // if nothing was drawn at absPos, annotate a position between previous and next drawn position. |
---|
225 | // text == NULp -> draw absPos as number |
---|
226 | // lineToBase == true -> draw a line to the base itself |
---|
227 | // boxText == true -> draw a box around text |
---|
228 | |
---|
229 | size_t abs1, abs2; |
---|
230 | const Position& pos1 = drawnPositions->drawn_before(absPos, &abs1); |
---|
231 | const Position& pos2 = drawnPositions->drawn_after (absPos, &abs2); |
---|
232 | |
---|
233 | LineVector vec12(pos1, pos2); |
---|
234 | Position mid12 = vec12.centroid(); |
---|
235 | Position pos; |
---|
236 | { |
---|
237 | const Position *posDrawn = drawnPositions->drawn_at(absPos); |
---|
238 | if (posDrawn) { // absPos was drawn |
---|
239 | pos = *posDrawn; |
---|
240 | } |
---|
241 | else { // absPos was not drawn -> use position in-between |
---|
242 | pos = mid12; |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | if (!text) text = GBS_global_string("%zu", absPos); |
---|
247 | |
---|
248 | AW_click_cd cd(device, 0, absPos); |
---|
249 | paintAnnotation(device, gc, pos, pos1, pos2, vec12.length(), text, lineToBase, false, boxText); |
---|
250 | } |
---|
251 | |
---|
252 | void SEC_root::paintEcoliPositions(AW_device *device) { |
---|
253 | long abspos = db->ecoli()->rel_2_abs(0); |
---|
254 | paintPosAnnotation(device, SEC_GC_ECOLI, size_t(abspos), "1", true, true); |
---|
255 | |
---|
256 | const BI_ecoli_ref *ecoli = db->ecoli(); |
---|
257 | for (size_t ep = bio2info(100); ep < (size_t)ecoli->base_count(); ep += 100) { |
---|
258 | abspos = ecoli->rel_2_abs(ep); |
---|
259 | paintPosAnnotation(device, SEC_GC_ECOLI, size_t(abspos), GBS_global_string("%i", info2bio(ep)), true, true); |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | void SEC_root::paintHelixNumbers(AW_device *device) { |
---|
264 | for (SEC_base_iterator elem(this); elem; ++elem) { |
---|
265 | if (elem->getType() == SEC_HELIX) { |
---|
266 | SEC_helix& helix = static_cast<SEC_helix&>(*elem); |
---|
267 | |
---|
268 | // paint helix number of right (3') helix strand |
---|
269 | SEC_helix_strand *strand = helix.strandToRoot()->is3end() ? helix.strandToRoot() : helix.strandToOutside(); |
---|
270 | |
---|
271 | int absPos = strand->startAttachAbspos(); |
---|
272 | const char *helixNr = helixNrAt(absPos); |
---|
273 | |
---|
274 | if (helixNr) { |
---|
275 | if (helix.standardSize() == 0) { // helix with zero length (just one position on each strand) |
---|
276 | paintPosAnnotation(device, SEC_GC_HELIX_NO, |
---|
277 | strand->startAttachAbspos(), helixNr, true, true); |
---|
278 | } |
---|
279 | else { |
---|
280 | const Position& start = strand->startAttachPoint(); |
---|
281 | const Position& end = strand->endAttachPoint(); |
---|
282 | Position helixCenter = centroid(start, end); |
---|
283 | |
---|
284 | AW_click_cd cd(device, strand->self(), absPos); |
---|
285 | paintAnnotation(device, SEC_GC_HELIX_NO, |
---|
286 | helixCenter, start, end, |
---|
287 | // displayParams.distance_between_strands*2, |
---|
288 | displayParams.distance_between_strands, |
---|
289 | helixNr, false, true, true); |
---|
290 | } |
---|
291 | } |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | |
---|
296 | |
---|
297 | #if defined(PAINT_ABSOLUTE_POSITION) |
---|
298 | void SEC_root::showSomeAbsolutePositions(AW_device *device) { |
---|
299 | if (device->get_filter() != AW_SIZE) { // ignore for size calculation (@@@) |
---|
300 | Rectangle screen = device->rtransform(Rectangle(device->get_area_size(), INCLUSIVE_OUTLINE)); |
---|
301 | Vector diag3 = screen.diagonal()/3; |
---|
302 | Rectangle showInside(screen.upper_left_corner()+diag3*1.85, diag3); |
---|
303 | |
---|
304 | AW_click_cd cd(device, 0, -1); |
---|
305 | device->box(SEC_GC_DEFAULT, AW::FillStyle::EMPTY, showInside); |
---|
306 | |
---|
307 | PosMap::const_iterator end = drawnPositions->end(); |
---|
308 | for (PosMap::const_iterator pos = drawnPositions->begin(); pos != end; ++pos) { |
---|
309 | if (showInside.contains(pos->second)) { |
---|
310 | paintPosAnnotation(device, SEC_GC_DEFAULT, pos->first, NULp, true, true); |
---|
311 | } |
---|
312 | } |
---|
313 | } |
---|
314 | } |
---|
315 | #endif // PAINT_ABSOLUTE_POSITION |
---|
316 | |
---|
317 | void SEC_root::announce_base_position(int base_pos, const Position& draw_pos) { |
---|
318 | drawnPositions->announce(base_pos, draw_pos); |
---|
319 | } |
---|
320 | void SEC_root::clear_announced_positions() { |
---|
321 | if (!drawnPositions) drawnPositions = new SEC_drawn_positions; |
---|
322 | drawnPositions->clear(); |
---|
323 | } |
---|
324 | |
---|
325 | void SEC_root::delete_announced_positions() { |
---|
326 | delete drawnPositions; |
---|
327 | drawnPositions = NULp; |
---|
328 | } |
---|
329 | |
---|
330 | |
---|
331 | // ---------------------------- |
---|
332 | // Paints CONSTRAINTS |
---|
333 | |
---|
334 | void SEC_helix_strand::paint_constraints(AW_device *device) { |
---|
335 | double minS = helix_info->minSize(); |
---|
336 | double maxS = helix_info->maxSize(); |
---|
337 | |
---|
338 | if (minS>0 || maxS>0) { |
---|
339 | const Position& startP = startAttachPoint(); |
---|
340 | const Position& endP = endAttachPoint(); |
---|
341 | |
---|
342 | bool drawMidLine = minS>0 && maxS>0; |
---|
343 | Position minP = startP + Vector(startP, endP) * (drawMidLine ? minS/maxS : 0.5); |
---|
344 | |
---|
345 | AW_click_cd cd(device, self(), startAttachAbspos()); |
---|
346 | get_root()->paintAnnotation(device, SEC_GC_DEFAULT, |
---|
347 | minP, startP, endP, |
---|
348 | get_root()->display_params().distance_between_strands*2, |
---|
349 | GBS_global_string("%.1f-%.1f", minS, maxS), |
---|
350 | drawMidLine, true, true); |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | void SEC_loop::paint_constraints(AW_device *device) { |
---|
355 | int abspos = get_fixpoint_strand()->startAttachAbspos(); |
---|
356 | |
---|
357 | double minS = minSize(); |
---|
358 | double maxS = maxSize(); |
---|
359 | |
---|
360 | if (minS>0 || maxS>0) { |
---|
361 | AW_click_cd cd(device, self(), abspos); |
---|
362 | |
---|
363 | if (minS>0) device->circle(SEC_GC_DEFAULT, AW::FillStyle::EMPTY, center, Vector(minS, minS)); |
---|
364 | if (maxS>0) device->circle(SEC_GC_DEFAULT, AW::FillStyle::EMPTY, center, Vector(maxS, maxS)); |
---|
365 | |
---|
366 | device->text(SEC_GC_DEFAULT, GBS_global_string("%.1f-%.1f", minS, maxS), center+Vector(0, max(minS, maxS)/2), 0.5, AW_ALL_DEVICES_UNSCALED); |
---|
367 | } |
---|
368 | } |
---|
369 | |
---|
370 | // --------------------------- |
---|
371 | // Background colors |
---|
372 | |
---|
373 | void SEC_root::cacheBackgroundColor() { // @@@ move to SEC_db_interface |
---|
374 | freenull(bg_color); |
---|
375 | |
---|
376 | int start = 0; |
---|
377 | int len = db->length(); |
---|
378 | int end = len-1; |
---|
379 | |
---|
380 | ARB_alloc(bg_color, len); |
---|
381 | |
---|
382 | const char *bg_sai = displayParams.display_sai ? host().get_SAI_background(start, end) : NULp; |
---|
383 | const char *bg_search = displayParams.display_search ? host().get_search_background(start, end) : NULp; |
---|
384 | |
---|
385 | if (bg_sai) { |
---|
386 | if (bg_search) { |
---|
387 | for (int i = start; i <= end; ++i) { |
---|
388 | bg_color[i] = bg_search[i] ? bg_search[i] : bg_sai[i]; |
---|
389 | } |
---|
390 | } |
---|
391 | else memcpy(bg_color, bg_sai, len); |
---|
392 | } |
---|
393 | else { |
---|
394 | if (bg_search) memcpy(bg_color, bg_search, len); |
---|
395 | else memset(bg_color, 0, len); |
---|
396 | } |
---|
397 | } |
---|
398 | |
---|
399 | void SEC_root::paintBackgroundColor(AW_device *device, SEC_bgpaint_mode mode, const Position& p1, int color1, int gc1, const Position& p2, int color2, int gc2, int skel_gc) { |
---|
400 | // paints background colors for p2 and connection between p1 and p2. |
---|
401 | // gc1/gc2 are foreground gc used to detect size of background regions |
---|
402 | // |
---|
403 | // Also paints skeleton |
---|
404 | |
---|
405 | sec_assert(valid_cb_params(device)); |
---|
406 | |
---|
407 | color1 = paintData.convert_BackgroundGC(color1); // convert EDIT4-GCs into SECEDIT-GCs |
---|
408 | color2 = paintData.convert_BackgroundGC(color2); |
---|
409 | |
---|
410 | if (color1 >= 0 || color2 >= 0 || displayParams.show_strSkeleton) { |
---|
411 | const double& radius1 = get_char_radius(gc1); |
---|
412 | const double& radius2 = get_char_radius(gc2); |
---|
413 | |
---|
414 | if (mode & BG_PAINT_FIRST && color1 >= 0) { // paint first circle ? |
---|
415 | device->circle(color1, AW::FillStyle::SOLID, p1, Vector(radius1, radius1)); |
---|
416 | } |
---|
417 | |
---|
418 | if (mode & BG_PAINT_SECOND && color2 >= 0) { // paint second circle ? |
---|
419 | device->circle(color2, AW::FillStyle::SOLID, p2, Vector(radius1, radius1)); |
---|
420 | } |
---|
421 | |
---|
422 | if (color1 == color2 && color1 >= 0) { // colors are equal -> paint background between points |
---|
423 | device->set_line_attributes(color1, bg_linewidth[paintData.get_linePropertyGC(gc1, gc2)], AW_SOLID); |
---|
424 | device->line(color1, p1, p2); |
---|
425 | } |
---|
426 | |
---|
427 | if (displayParams.show_strSkeleton) { // paint skeleton? |
---|
428 | Position s1 = p1; |
---|
429 | Position s2 = p2; |
---|
430 | bool space = false; |
---|
431 | |
---|
432 | if (displayParams.hide_bases) { |
---|
433 | space = true; // no base chars -> enough space to paint |
---|
434 | } |
---|
435 | else { |
---|
436 | Vector v12(p1, p2); |
---|
437 | double vlen = v12.length(); |
---|
438 | |
---|
439 | // Note: LINE_THICKNESS |
---|
440 | // Lines drawn with thickness != 1 differ between motif-version and gtk-version: |
---|
441 | // in motif thicker lines are also drawn longer than specified (half thickness on each side) |
---|
442 | const double CORR = skelThickWorld; |
---|
443 | |
---|
444 | if ((radius1+radius2+CORR) < vlen) { // test if there is enough space between characters |
---|
445 | s1 = p1 + v12*((radius1+CORR/2)/vlen); // skeleton<->base attach-points |
---|
446 | s2 = p2 - v12*((radius2+CORR/2)/vlen); |
---|
447 | space = true; |
---|
448 | } |
---|
449 | } |
---|
450 | |
---|
451 | if (space) { |
---|
452 | device->set_line_attributes(skel_gc, displayParams.skeleton_thickness, AW_SOLID); |
---|
453 | #if defined(DEBUG) |
---|
454 | if (displayParams.show_debug) { s1 = p1; s2 = p2; } // in debug mode always show full skeleton |
---|
455 | #endif // DEBUG |
---|
456 | device->line(skel_gc, s1, s2); |
---|
457 | } |
---|
458 | } |
---|
459 | } |
---|
460 | } |
---|
461 | |
---|
462 | void SEC_root::paintSearchPatternStrings(AW_device *device, int clickedPos, AW_pos xPos, AW_pos yPos) { |
---|
463 | int searchColor = getBackgroundColor(clickedPos); |
---|
464 | |
---|
465 | if (searchColor >= SEC_GC_SBACK_0 && searchColor <= SEC_GC_SBACK_8) { |
---|
466 | static const char *text[SEC_GC_SBACK_8-SEC_GC_SBACK_0+1] = { |
---|
467 | "User 1", |
---|
468 | "User 2", |
---|
469 | "Probe", |
---|
470 | "Primer (local)", |
---|
471 | "Primer (region)", |
---|
472 | "Primer (global)", |
---|
473 | "Signature (local)", |
---|
474 | "Signature (region)", |
---|
475 | "Signature (global)", |
---|
476 | }; |
---|
477 | |
---|
478 | AW_click_cd cd(device, 0, clickedPos); |
---|
479 | device->text(searchColor, text[searchColor-SEC_GC_SBACK_0], xPos, yPos, 0, AW_SCREEN); |
---|
480 | } |
---|
481 | else { |
---|
482 | aw_message("Please click on a search result"); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | // --------------- |
---|
487 | // Bonds |
---|
488 | |
---|
489 | void SEC_bond_def::paint(AW_device *device, char base1, char base2, const Position& p1, const Position& p2, const Vector& toNextBase, const double& char_radius) const { |
---|
490 | if (base1 && base2) { |
---|
491 | char Bond = get_bond(base1, base2); |
---|
492 | if (Bond == ' ') { |
---|
493 | // check IUPACs |
---|
494 | const char *iupac1 = iupac::decode(base1, ali_type, 0); |
---|
495 | const char *iupac2 = iupac::decode(base2, ali_type, 0); |
---|
496 | |
---|
497 | bool useBond[SEC_BOND_PAIR_CHARS]; |
---|
498 | for (int i = 0; i<SEC_BOND_PAIR_CHARS; i++) useBond[i] = false; |
---|
499 | |
---|
500 | int maxIdx = -1; |
---|
501 | for (int i1 = 0; iupac1[i1]; ++i1) { |
---|
502 | for (int i2 = 0; iupac2[i2]; ++i2) { |
---|
503 | char b = get_bond(iupac1[i1], iupac2[i2]); |
---|
504 | |
---|
505 | if (b != ' ') { |
---|
506 | const char *found = strchr(SEC_BOND_PAIR_CHAR, b); |
---|
507 | int idx = found-SEC_BOND_PAIR_CHAR; |
---|
508 | |
---|
509 | useBond[idx] = true; |
---|
510 | if (idx>maxIdx) maxIdx = idx; |
---|
511 | } |
---|
512 | } |
---|
513 | } |
---|
514 | |
---|
515 | if (maxIdx >= 0) { |
---|
516 | for (int i = 0; i<SEC_BOND_PAIR_CHARS; i++) { |
---|
517 | if (useBond[i]) { |
---|
518 | paint(device, i == maxIdx ? SEC_GC_BONDS : SEC_GC_ERROR, SEC_BOND_PAIR_CHAR[i], p1, p2, toNextBase, char_radius); |
---|
519 | } |
---|
520 | } |
---|
521 | } |
---|
522 | } |
---|
523 | else { |
---|
524 | paint(device, SEC_GC_BONDS, Bond, p1, p2, toNextBase, char_radius); |
---|
525 | } |
---|
526 | } |
---|
527 | } |
---|
528 | |
---|
529 | void SEC_bond_def::paint(AW_device *device, int GC, char bondChar, const Position& p1, const Position& p2, const Vector& toNextBase, const double& char_radius) const { |
---|
530 | Vector v12(p1, p2); |
---|
531 | double oppoDist = v12.length(); |
---|
532 | double bondLen = oppoDist-2*char_radius; |
---|
533 | |
---|
534 | if (bondLen <= 0.0) return; // not enough space to draw bond |
---|
535 | |
---|
536 | Vector pb = v12*(char_radius/oppoDist); |
---|
537 | |
---|
538 | Position b1 = p1+pb; // start/end pos of bond |
---|
539 | Position b2 = p2-pb; |
---|
540 | |
---|
541 | Position center = centroid(b1, b2); |
---|
542 | |
---|
543 | Vector aside = toNextBase; |
---|
544 | { |
---|
545 | // limit aside-size by strand-distance |
---|
546 | double aside_len = aside.length(); |
---|
547 | double max_aside_len = min(aside_len, Vector(b1, b2).length()); |
---|
548 | if (max_aside_len<aside_len) { |
---|
549 | aside *= max_aside_len/aside_len; |
---|
550 | } |
---|
551 | } |
---|
552 | aside *= 0.22; // max. 22% towards next base position (has to be less than 25%, because 'aside' is added twice for some bondtypes) |
---|
553 | |
---|
554 | switch (bondChar) { |
---|
555 | case '-': // single line |
---|
556 | device->line(GC, b1, b2); |
---|
557 | break; |
---|
558 | |
---|
559 | case '#': // double cross |
---|
560 | case '=': // double line |
---|
561 | device->line(GC, b1+aside, b2+aside); |
---|
562 | device->line(GC, b1-aside, b2-aside); |
---|
563 | |
---|
564 | if (bondChar == '#') { |
---|
565 | Vector outside = v12*(bondLen/oppoDist/4); |
---|
566 | Position c1 = center+outside; |
---|
567 | Position c2 = center-outside; |
---|
568 | |
---|
569 | aside *= 2; |
---|
570 | |
---|
571 | device->line(GC, c1-aside, c1+aside); |
---|
572 | device->line(GC, c2-aside, c2+aside); |
---|
573 | } |
---|
574 | break; |
---|
575 | |
---|
576 | case '~': { |
---|
577 | double radius = aside.length(); |
---|
578 | { |
---|
579 | double maxRadius = bondLen/4; |
---|
580 | if (maxRadius<radius) radius = maxRadius; |
---|
581 | } |
---|
582 | |
---|
583 | Vector outside = v12*(radius/oppoDist); |
---|
584 | |
---|
585 | Position c1 = center+outside; |
---|
586 | Position c2 = center-outside; |
---|
587 | |
---|
588 | aside *= 2; |
---|
589 | |
---|
590 | Angle angle(outside); |
---|
591 | int deg = AW_INT(angle.degrees()); |
---|
592 | |
---|
593 | const int INSIDE = 2; |
---|
594 | const int OUTSIDE = 15; |
---|
595 | |
---|
596 | Vector vRadius(radius, radius); |
---|
597 | device->arc(GC, AW::FillStyle::EMPTY, c1, vRadius, deg+180+INSIDE, -(180+INSIDE+OUTSIDE)); |
---|
598 | device->arc(GC, AW::FillStyle::EMPTY, c2, vRadius, deg+INSIDE, -(180+INSIDE+OUTSIDE)); |
---|
599 | break; |
---|
600 | } |
---|
601 | |
---|
602 | case '+': // cross |
---|
603 | aside *= 2; |
---|
604 | device->line(GC, center-aside, center+aside); |
---|
605 | if (2*aside.length() < bondLen) { |
---|
606 | aside.rotate90deg(); |
---|
607 | device->line(GC, center-aside, center+aside); |
---|
608 | } |
---|
609 | else { |
---|
610 | device->line(GC, b1, b2); |
---|
611 | } |
---|
612 | break; |
---|
613 | |
---|
614 | case 'o': |
---|
615 | case '.': { // circles |
---|
616 | double radius = aside.length(); |
---|
617 | if (bondChar == 'o') radius *= 2; |
---|
618 | device->circle(GC, AW::FillStyle::EMPTY, center, Vector(radius, radius)); |
---|
619 | break; |
---|
620 | } |
---|
621 | |
---|
622 | case '@': // error in bonddef |
---|
623 | device->text(GC, "Err", center+Vector(0, char_radius), 0.5, AW_ALL_DEVICES_UNSCALED); |
---|
624 | break; |
---|
625 | |
---|
626 | default: |
---|
627 | sec_assert(0); // // illegal bond char |
---|
628 | break; |
---|
629 | } |
---|
630 | } |
---|
631 | |
---|
632 | // ----------------------- |
---|
633 | // Paint helices |
---|
634 | |
---|
635 | struct StrandPositionData { |
---|
636 | int abs[2]; // absolute sequence position |
---|
637 | int previous[2]; // previous drawn index |
---|
638 | bool drawn[2]; // draw position ? |
---|
639 | bool isPair; // true if position is pairing |
---|
640 | Position realpos[2]; // real position |
---|
641 | }; |
---|
642 | |
---|
643 | void SEC_helix_strand::paint_strands(AW_device *device, const Vector& strand_vec, const double& strand_len) { |
---|
644 | static StrandPositionData *data = NULp; |
---|
645 | static int allocated = 0; |
---|
646 | |
---|
647 | const SEC_region* Region[2] = { get_region(), other_strand->get_region() }; |
---|
648 | int base_count = Region[0]->get_base_count(); |
---|
649 | |
---|
650 | sec_assert(Region[1]->get_base_count() == base_count); // not aligned ? |
---|
651 | |
---|
652 | if (base_count<1) { |
---|
653 | return; // completely skip painting on strands w/o any base |
---|
654 | } |
---|
655 | |
---|
656 | if (allocated<base_count) { |
---|
657 | delete [] data; |
---|
658 | data = new StrandPositionData[base_count]; |
---|
659 | allocated = base_count; |
---|
660 | } |
---|
661 | |
---|
662 | SEC_root *root = get_root(); |
---|
663 | const BI_helix *helix = root->get_helixDef(); |
---|
664 | |
---|
665 | double base_dist = base_count>1 ? strand_len / (base_count-1) : 1; |
---|
666 | Vector vnext = strand_vec * base_dist; // vector from base to next base (in strand) |
---|
667 | |
---|
668 | // first calculate positions |
---|
669 | { |
---|
670 | StrandPositionData *curr = &data[0]; |
---|
671 | |
---|
672 | int idx[2] = { 0, base_count-1 }; |
---|
673 | Position pos[2] = { leftAttach, rightAttach }; |
---|
674 | Vector toNonBind[2]; // vectors from normal to non-binding positions |
---|
675 | toNonBind[1] = (strand_vec*0.5).rotate90deg(); |
---|
676 | toNonBind[0] = -toNonBind[1]; |
---|
677 | |
---|
678 | for (int strand = 0; strand<2; ++strand) { |
---|
679 | curr->abs[strand] = Region[strand]->getBasePos(idx[strand]); |
---|
680 | curr->previous[strand] = 0; |
---|
681 | curr->drawn[strand] = (curr->abs[strand] >= 0); |
---|
682 | } |
---|
683 | |
---|
684 | for (int dIdx = 1; ; ++dIdx) { |
---|
685 | sec_assert(pos[0].valid()); |
---|
686 | sec_assert(pos[1].valid()); |
---|
687 | |
---|
688 | int oneAbs = curr->drawn[0] ? curr->abs[0] : curr->abs[1]; |
---|
689 | sec_assert(oneAbs >= 0); // otherwise current position should have been eliminated by align_helix_strands |
---|
690 | curr->isPair = (helix->pairtype(oneAbs) != HELIX_NONE); |
---|
691 | |
---|
692 | for (int strand = 0; strand<2; ++strand) { |
---|
693 | if (curr->isPair) { |
---|
694 | curr->realpos[strand] = pos[strand]; |
---|
695 | curr->drawn[strand] = true; |
---|
696 | } |
---|
697 | else { |
---|
698 | curr->realpos[strand] = pos[strand]+toNonBind[strand]; |
---|
699 | } |
---|
700 | |
---|
701 | sec_assert(curr->realpos[strand].valid()); |
---|
702 | } |
---|
703 | |
---|
704 | if (dIdx >= base_count) break; |
---|
705 | |
---|
706 | ++idx[0]; |
---|
707 | --idx[1]; |
---|
708 | |
---|
709 | StrandPositionData *prev = curr; |
---|
710 | curr = &data[dIdx]; |
---|
711 | |
---|
712 | for (int strand = 0; strand<2; ++strand) { |
---|
713 | pos[strand] += vnext; |
---|
714 | curr->abs[strand] = Region[strand]->getBasePos(idx[strand]); |
---|
715 | curr->previous[strand] = prev->drawn[strand] ? dIdx-1 : prev->previous[strand]; |
---|
716 | curr->drawn[strand] = (curr->abs[strand] >= 0); |
---|
717 | } |
---|
718 | } |
---|
719 | } |
---|
720 | |
---|
721 | const int pair2helixGC[2] = { SEC_GC_NHELIX, SEC_GC_HELIX }; |
---|
722 | const int pair2skelGC[2] = { SEC_SKELE_NHELIX, SEC_SKELE_HELIX }; |
---|
723 | |
---|
724 | const SEC_db_interface *db = root->get_db(); |
---|
725 | const SEC_displayParams& disp = root->display_params(); |
---|
726 | |
---|
727 | // draw background and skeleton |
---|
728 | for (int pos = 1; pos<base_count; ++pos) { |
---|
729 | StrandPositionData *curr = &data[pos]; |
---|
730 | for (int strand = 0; strand<2; ++strand) { |
---|
731 | if (curr->drawn[strand]) { |
---|
732 | StrandPositionData *prev = &data[curr->previous[strand]]; |
---|
733 | |
---|
734 | int backAbs = disp.edit_rightward |
---|
735 | ? max(prev->abs[strand], curr->abs[strand]) |
---|
736 | : min(prev->abs[strand], curr->abs[strand]); |
---|
737 | |
---|
738 | AW_click_cd cd(device, self(), backAbs); |
---|
739 | root->paintBackgroundColor(device, |
---|
740 | pos == base_count-1 ? BG_PAINT_NONE : BG_PAINT_SECOND, |
---|
741 | prev->realpos[strand], root->getBackgroundColor(prev->abs[strand]), pair2helixGC[prev->isPair], |
---|
742 | curr->realpos[strand], root->getBackgroundColor(curr->abs[strand]), pair2helixGC[curr->isPair], |
---|
743 | pair2skelGC[curr->isPair && prev->isPair]); |
---|
744 | } |
---|
745 | } |
---|
746 | } |
---|
747 | |
---|
748 | // draw base characters and bonds |
---|
749 | char baseBuf[20] = "x"; |
---|
750 | for (int pos = 0; pos<base_count; ++pos) { |
---|
751 | StrandPositionData *curr = &data[pos]; |
---|
752 | char base[2] = { 0, 0 }; |
---|
753 | |
---|
754 | int gc = pair2helixGC[curr->isPair]; |
---|
755 | Vector center_char = root->get_center_char_vector(gc); |
---|
756 | |
---|
757 | for (int strand = 0; strand<2; ++strand) { |
---|
758 | if (curr->drawn[strand]) { |
---|
759 | int abs = curr->abs[strand]; |
---|
760 | const Position& realPos = curr->realpos[strand]; |
---|
761 | |
---|
762 | sec_assert(abs >= 0); |
---|
763 | |
---|
764 | base[strand] = db->baseAt(abs); |
---|
765 | root->announce_base_position(abs, realPos); |
---|
766 | |
---|
767 | if (!disp.hide_bases) { |
---|
768 | baseBuf[0] = base[strand]; |
---|
769 | Position base_pos = realPos + center_char; // center base at realpos |
---|
770 | AW_click_cd cd(device, self(), abs); |
---|
771 | #if defined(DEBUG) |
---|
772 | if (disp.show_debug) device->line(gc, realPos, base_pos); |
---|
773 | #endif // DEBUG |
---|
774 | |
---|
775 | device->text(gc, baseBuf, base_pos, 0.0, AW_ALL_DEVICES_SCALED); |
---|
776 | } |
---|
777 | } |
---|
778 | } |
---|
779 | |
---|
780 | if (disp.show_bonds == SHOW_NHELIX_BONDS || (disp.show_bonds == SHOW_HELIX_BONDS && curr->isPair)) { |
---|
781 | AW_click_cd cd(device, self(), curr->abs[0]); |
---|
782 | db->bonds()->paint(device, base[0], base[1], curr->realpos[0], curr->realpos[1], vnext, |
---|
783 | root->get_char_radius(pair2helixGC[curr->isPair]) |
---|
784 | +root->get_bondThickWorld()/2 // see .@LINE_THICKNESS |
---|
785 | ); |
---|
786 | } |
---|
787 | } |
---|
788 | } |
---|
789 | |
---|
790 | void SEC_helix_strand::paint(AW_device *device) { |
---|
791 | sec_assert(isRootsideFixpoint()); |
---|
792 | |
---|
793 | Vector strand_vec(rightAttach, other_strand->leftAttach); |
---|
794 | double strand_len = strand_vec.length(); // length of strand |
---|
795 | |
---|
796 | if (strand_len>0) { |
---|
797 | strand_vec.normalize(); // normalize |
---|
798 | } |
---|
799 | else { // strand with zero length (contains only one base-pair) |
---|
800 | strand_vec = Vector(rightAttach, leftAttach).rotate90deg(); |
---|
801 | } |
---|
802 | |
---|
803 | other_strand->origin_loop->paint(device); // first paint next loop |
---|
804 | paint_strands(device, strand_vec, strand_len); // then paint strand |
---|
805 | |
---|
806 | SEC_root *root = get_root(); |
---|
807 | const SEC_displayParams& disp = root->display_params(); |
---|
808 | |
---|
809 | if (disp.show_strSkeleton && !disp.show_bonds && disp.hide_bases) { |
---|
810 | // display strand direction |
---|
811 | LineVector strandArrow; |
---|
812 | if (strand_len>0) { |
---|
813 | strandArrow = LineVector(get_fixpoint(), strand_vec); |
---|
814 | } |
---|
815 | else { |
---|
816 | Vector fix2arrowStart(get_fixpoint(), leftAttachPoint()); |
---|
817 | fix2arrowStart.rotate90deg(); |
---|
818 | strandArrow = LineVector(get_fixpoint()-fix2arrowStart, 2*fix2arrowStart); |
---|
819 | } |
---|
820 | |
---|
821 | AW_click_cd cd(device, get_helix()->self(), startAttachAbspos()); |
---|
822 | device->line(SEC_GC_HELIX, strandArrow); |
---|
823 | |
---|
824 | Vector right = strandArrow.line_vector(); // left arrowhead vector |
---|
825 | right = (right * (disp.distance_between_strands*0.35/right.length())).rotate135deg(); |
---|
826 | |
---|
827 | Vector left = Vector(right).rotate90deg(); |
---|
828 | |
---|
829 | Position head = strandArrow.head(); |
---|
830 | device->line(SEC_GC_HELIX, LineVector(head, left)); |
---|
831 | device->line(SEC_GC_HELIX, LineVector(head, right)); |
---|
832 | } |
---|
833 | |
---|
834 | #if defined(DEBUG) |
---|
835 | if (disp.show_debug) paintStrandDebugInfo(device, SEC_GC_HELIX, other_strand); |
---|
836 | #endif // DEBUG |
---|
837 | |
---|
838 | if (root->get_show_constraints() & SEC_HELIX) paint_constraints(device); |
---|
839 | } |
---|
840 | |
---|
841 | |
---|
842 | // --------------------- |
---|
843 | // Paint loops |
---|
844 | |
---|
845 | void SEC_segment::paint(AW_device *device, SEC_helix_strand *previous_strand_pointer) { |
---|
846 | int base_count = get_region()->get_base_count(); // bases in segment |
---|
847 | |
---|
848 | const Position& startP = previous_strand_pointer->rightAttachPoint(); |
---|
849 | const Position& endP = next_helix_strand->leftAttachPoint(); |
---|
850 | |
---|
851 | Angle current; // start/current angle |
---|
852 | Angle end; // end angle |
---|
853 | double radius1; // start and.. |
---|
854 | double radius2; // end radius of segment |
---|
855 | |
---|
856 | { |
---|
857 | Vector seg_start_radius(center1, startP); |
---|
858 | radius1 = seg_start_radius.length(); |
---|
859 | current = seg_start_radius; |
---|
860 | |
---|
861 | Vector seg_end_radius(center2, endP); |
---|
862 | radius2 = seg_end_radius.length(); |
---|
863 | end = seg_end_radius; |
---|
864 | } |
---|
865 | |
---|
866 | int steps = base_count+1; |
---|
867 | |
---|
868 | double step = ((end-current)/steps).radian(); |
---|
869 | |
---|
870 | // correct if we have to paint more than a full loop |
---|
871 | if ((alpha - (step*steps)) > M_PI) { |
---|
872 | step += (2*M_PI)/steps; |
---|
873 | } |
---|
874 | |
---|
875 | double radStep = (radius2-radius1)/steps; |
---|
876 | |
---|
877 | Vector cstep(center1, center2); |
---|
878 | cstep /= steps; |
---|
879 | |
---|
880 | SEC_root *root = get_root(); |
---|
881 | const SEC_db_interface *db = root->get_db(); |
---|
882 | const SEC_displayParams& disp = root->display_params(); |
---|
883 | #if defined(DEBUG) |
---|
884 | if (disp.show_debug) { |
---|
885 | paintStrandDebugInfo(device, SEC_GC_LOOP, previous_strand_pointer); |
---|
886 | |
---|
887 | int startAbsPos = previous_strand_pointer->rightAttachAbspos(); |
---|
888 | int endAbsPos = next_helix_strand->leftAttachAbspos(); |
---|
889 | |
---|
890 | AW_click_cd cd(device, self(), startAbsPos); |
---|
891 | paintDebugInfo(device, SEC_GC_LOOP, center1, GBS_global_string("SC1 (step=%5.3f)", step)); |
---|
892 | device->line(SEC_GC_LOOP, center1, startP); |
---|
893 | device->line(SEC_GC_LOOP, center1, center2); |
---|
894 | |
---|
895 | cd.set_cd2(endAbsPos); |
---|
896 | paintDebugInfo(device, SEC_GC_LOOP, center2, "SC2"); |
---|
897 | device->line(SEC_GC_LOOP, center2, endP); |
---|
898 | } |
---|
899 | #endif // DEBUG |
---|
900 | |
---|
901 | char baseBuf[5] = "?"; // contains base char during print |
---|
902 | Position pos = startP; |
---|
903 | int abs = previous_strand_pointer->rightAttachAbspos(); |
---|
904 | int back = root->getBackgroundColor(abs); |
---|
905 | int gc = root->getBondtype(abs) == HELIX_NONE ? SEC_GC_NHELIX : SEC_GC_HELIX; |
---|
906 | int nextGc = SEC_GC_LOOP; |
---|
907 | |
---|
908 | Position currCenter = center1; |
---|
909 | double currRadius = radius1; |
---|
910 | |
---|
911 | Angle step_angle(step); |
---|
912 | |
---|
913 | for (int i = -1; i<base_count; i++) { // for each segment position (plus one pre-loop) |
---|
914 | current += step_angle; // iterate over angles |
---|
915 | currCenter += cstep; |
---|
916 | currRadius += radStep; |
---|
917 | |
---|
918 | Position nextPos = currCenter + current.normal()*currRadius; |
---|
919 | int nextAbs; |
---|
920 | |
---|
921 | if (i == (base_count-1)) { // last position (belongs to strand) |
---|
922 | nextAbs = next_helix_strand->leftAttachAbspos(); |
---|
923 | if (nextAbs<0) { // helix doesn't start with pair |
---|
924 | nextAbs = next_helix_strand->getNextAbspos(); |
---|
925 | } |
---|
926 | nextGc = root->getBondtype(nextAbs) == HELIX_NONE ? SEC_GC_NHELIX : SEC_GC_HELIX; |
---|
927 | } |
---|
928 | else { |
---|
929 | nextAbs = get_region()->getBasePos(i+1); |
---|
930 | } |
---|
931 | |
---|
932 | int nextBack = root->getBackgroundColor(nextAbs); |
---|
933 | |
---|
934 | // paint background (from pos to nextPos) |
---|
935 | AW_click_cd cd(device, self(), disp.edit_rightward ? nextAbs : abs); |
---|
936 | root->paintBackgroundColor(device, i == -1 ? BG_PAINT_BOTH : BG_PAINT_SECOND, |
---|
937 | pos, back, gc, nextPos, nextBack, nextGc, SEC_SKELE_LOOP); |
---|
938 | |
---|
939 | if (i >= 0) { |
---|
940 | // paint base char at pos |
---|
941 | baseBuf[0] = abs>0 ? db->baseAt(abs) : '?'; |
---|
942 | Vector center_char = root->get_center_char_vector(gc); |
---|
943 | Position base_pos = pos + center_char; // center base character at pos |
---|
944 | |
---|
945 | cd.set_cd2(abs); |
---|
946 | if (!disp.hide_bases) { |
---|
947 | #if defined(DEBUG) |
---|
948 | // show line from base paint pos to calculated center of char |
---|
949 | // (which is currently calculated wrong!) |
---|
950 | if (disp.show_debug) device->line(SEC_GC_LOOP, pos, base_pos); |
---|
951 | #endif // DEBUG |
---|
952 | device->text(SEC_GC_LOOP, baseBuf, base_pos, 0.0, AW_ALL_DEVICES_SCALED); |
---|
953 | } |
---|
954 | root->announce_base_position(abs, pos); |
---|
955 | } |
---|
956 | |
---|
957 | // prepare next loop |
---|
958 | pos = nextPos; |
---|
959 | abs = nextAbs; |
---|
960 | back = nextBack; |
---|
961 | gc = nextGc; |
---|
962 | } |
---|
963 | } |
---|
964 | |
---|
965 | void SEC_loop::paint(AW_device *device) { |
---|
966 | for (SEC_segment_iterator seg(this); seg; ++seg) { // first paint all segments |
---|
967 | seg->paint(device, seg->get_previous_strand()); |
---|
968 | } |
---|
969 | for (SEC_strand_iterator strand(this); strand; ++strand) { // then paint all outgoing strands |
---|
970 | if (strand->isRootsideFixpoint()) strand->paint(device); |
---|
971 | } |
---|
972 | |
---|
973 | SEC_root *sroot = get_root(); |
---|
974 | #if defined(DEBUG) |
---|
975 | if (sroot->display_params().show_debug) { |
---|
976 | SEC_helix_strand *fixpoint_strand = get_fixpoint_strand(); |
---|
977 | int abspos = fixpoint_strand->startAttachAbspos(); |
---|
978 | AW_click_cd cd(device, self(), abspos); |
---|
979 | |
---|
980 | device->set_line_attributes(SEC_GC_CURSOR, 1, AW_SOLID); |
---|
981 | device->line(SEC_GC_CURSOR, get_center(), fixpoint_strand->get_fixpoint()); |
---|
982 | |
---|
983 | paintStrandDebugInfo(device, SEC_GC_CURSOR, fixpoint_strand); |
---|
984 | paintDebugInfo(device, SEC_GC_CURSOR, get_center(), "LC"); |
---|
985 | } |
---|
986 | #endif // DEBUG |
---|
987 | if (sroot->get_show_constraints() & SEC_LOOP) paint_constraints(device); |
---|
988 | } |
---|
989 | |
---|
990 | // ------------------------------------------------------------ |
---|
991 | // Paint the whole structure (starting with SEC_root) |
---|
992 | |
---|
993 | GB_ERROR SEC_root::paint(AW_device *device) { |
---|
994 | SEC_loop *rootLoop = get_root_loop(); |
---|
995 | sec_assert(rootLoop); |
---|
996 | clear_announced_positions(); // reset positions next to cursor |
---|
997 | |
---|
998 | const BI_helix *helix = get_helixDef(); |
---|
999 | sec_assert(helix); |
---|
1000 | |
---|
1001 | GB_ERROR error = helix->get_error(); |
---|
1002 | |
---|
1003 | if (!error) { |
---|
1004 | sec_assert(SEC_GC_FIRST_FONT == 0); |
---|
1005 | // @@@ font group should be built at startup and after each font change (no need to do on every paint!) |
---|
1006 | font_group.unregisterAll(); |
---|
1007 | for (int gc = SEC_GC_FIRST_FONT; gc <= SEC_GC_LAST_FONT; ++gc) { |
---|
1008 | font_group.registerFont(device, gc, "ACGTU-."); |
---|
1009 | center_char[gc] = device->rtransform(Vector(-0.5*font_group.get_width(gc), 0.5*font_group.get_ascent(gc))); |
---|
1010 | } |
---|
1011 | |
---|
1012 | // calculate size for background painting |
---|
1013 | sec_assert(SEC_GC_FIRST_DATA == 0); |
---|
1014 | for (int gc = SEC_GC_FIRST_DATA; gc <= SEC_GC_LAST_DATA; ++gc) { |
---|
1015 | int maxSize = hypotenuse(font_group.get_width(gc), font_group.get_ascent(gc)); |
---|
1016 | bg_linewidth[gc] = maxSize*0.75; |
---|
1017 | |
---|
1018 | maxSize += 2; // add 2 extra pixels |
---|
1019 | charRadius[gc] = device->rtransform_size(maxSize) * 0.5; // was 0.75 |
---|
1020 | } |
---|
1021 | |
---|
1022 | skelThickWorld = device->rtransform_size(displayParams.skeleton_thickness); |
---|
1023 | bondThickWorld = device->rtransform_size(displayParams.bond_thickness); |
---|
1024 | |
---|
1025 | cacheBackgroundColor(); |
---|
1026 | |
---|
1027 | device->set_line_attributes(SEC_SKELE_HELIX, displayParams.skeleton_thickness, AW_SOLID); |
---|
1028 | device->set_line_attributes(SEC_SKELE_NHELIX, displayParams.skeleton_thickness, AW_SOLID); |
---|
1029 | device->set_line_attributes(SEC_SKELE_LOOP, displayParams.skeleton_thickness, AW_SOLID); |
---|
1030 | device->set_line_attributes(SEC_GC_BONDS, displayParams.bond_thickness, AW_SOLID); |
---|
1031 | |
---|
1032 | // mark the rootLoop with a box and print structure number |
---|
1033 | { |
---|
1034 | const Position& loop_center = rootLoop->get_center(); |
---|
1035 | const char *structId = db->structure()->name(); |
---|
1036 | |
---|
1037 | AW_click_cd cd(device, rootLoop->self(), -1); |
---|
1038 | |
---|
1039 | Vector center2corner(-1, -1); |
---|
1040 | center2corner.set_length(rootLoop->drawnSize()*0.33); |
---|
1041 | |
---|
1042 | Position upperleft_corner = loop_center+center2corner; |
---|
1043 | Vector diagonal = -2*center2corner; |
---|
1044 | |
---|
1045 | Position textPos(loop_center.xpos(), upperleft_corner.ypos()); |
---|
1046 | |
---|
1047 | device->box(SEC_GC_DEFAULT, AW::FillStyle::EMPTY, upperleft_corner, diagonal, AW_ALL_DEVICES_UNSCALED); |
---|
1048 | device->text(SEC_GC_DEFAULT, structId, textPos, 0.5); |
---|
1049 | } |
---|
1050 | |
---|
1051 | #if defined(CHECK_INTEGRITY) |
---|
1052 | check_integrity(CHECK_ALL); |
---|
1053 | #endif // CHECK_INTEGRITY |
---|
1054 | |
---|
1055 | rootLoop->paint(device); |
---|
1056 | |
---|
1057 | // paint ecoli positions: |
---|
1058 | if (displayParams.show_ecoli_pos) paintEcoliPositions(device); |
---|
1059 | |
---|
1060 | if (displayParams.show_helixNrs) { |
---|
1061 | paintHelixNumbers(device); |
---|
1062 | } |
---|
1063 | |
---|
1064 | #if defined(PAINT_ABSOLUTE_POSITION) |
---|
1065 | if (displayParams.show_debug) showSomeAbsolutePositions(device); |
---|
1066 | #endif // PAINT_ABSOLUTE_POSITION |
---|
1067 | |
---|
1068 | // paint cursor: |
---|
1069 | if (!drawnPositions->empty() && |
---|
1070 | (device->get_filter()&(AW_PRINTER|AW_PRINTER_EXT)) == 0) // don't print/xfig-export cursor |
---|
1071 | { |
---|
1072 | size_t abs1, abs2; |
---|
1073 | Position pos1, pos2; |
---|
1074 | size_t curAbs; |
---|
1075 | |
---|
1076 | if (displayParams.edit_rightward) { |
---|
1077 | pos1 = drawnPositions->drawn_before(cursorAbsPos, &abs1); |
---|
1078 | pos2 = drawnPositions->drawn_after(cursorAbsPos-1, &abs2); |
---|
1079 | curAbs = abs2; |
---|
1080 | } |
---|
1081 | else { |
---|
1082 | pos1 = drawnPositions->drawn_before(cursorAbsPos+1, &abs1); |
---|
1083 | pos2 = drawnPositions->drawn_after(cursorAbsPos, &abs2); |
---|
1084 | curAbs = abs1; |
---|
1085 | } |
---|
1086 | |
---|
1087 | AW_click_cd cd(device, 0, curAbs); |
---|
1088 | #if defined(DEBUG) && 1 |
---|
1089 | // draw a testline to see the baseline on that the cursor is positioned |
---|
1090 | device->set_line_attributes(SEC_GC_CURSOR, 1, AW_DASHED); |
---|
1091 | device->line(SEC_GC_CURSOR, pos1, pos2); |
---|
1092 | #endif |
---|
1093 | |
---|
1094 | Position mid = centroid(pos1, pos2); |
---|
1095 | Vector v(pos1, pos2); |
---|
1096 | { |
---|
1097 | Vector v_drawn = device->transform(v); |
---|
1098 | double drawn_length = v_drawn.length(); |
---|
1099 | |
---|
1100 | sec_assert(drawn_length>0.0); |
---|
1101 | |
---|
1102 | double cursor_size = 1.3 * max(font_group.get_max_width(), font_group.get_max_ascent()); // 30% bigger than max font size |
---|
1103 | double stretch = cursor_size*0.5/drawn_length; // stretch cursor (half fontsize in each direction) |
---|
1104 | |
---|
1105 | v.rotate90deg() *= stretch; |
---|
1106 | } |
---|
1107 | |
---|
1108 | LineVector cursor(mid+v, mid-v); |
---|
1109 | device->set_line_attributes(SEC_GC_CURSOR, 3, AW_SOLID); |
---|
1110 | device->line(SEC_GC_CURSOR, cursor); |
---|
1111 | set_last_drawed_cursor_position(cursor); |
---|
1112 | |
---|
1113 | LineVector cursor_dir(cursor.head(), displayParams.edit_rightward ? v.rotate270deg() : v.rotate90deg()); |
---|
1114 | device->line(SEC_GC_CURSOR, cursor_dir); |
---|
1115 | |
---|
1116 | |
---|
1117 | int cursor_gc = -1; |
---|
1118 | int disp_pos = -1; |
---|
1119 | |
---|
1120 | switch (displayParams.show_curpos) { |
---|
1121 | case SHOW_ABS_CURPOS: |
---|
1122 | cursor_gc = SEC_GC_CURSOR; |
---|
1123 | disp_pos = info2bio(curAbs); |
---|
1124 | break; |
---|
1125 | case SHOW_BASE_CURPOS: |
---|
1126 | cursor_gc = SEC_GC_DEFAULT; |
---|
1127 | disp_pos = host().get_base_position(curAbs+1); // show bases up to cursorpos (inclusive) |
---|
1128 | break; |
---|
1129 | case SHOW_ECOLI_CURPOS: { |
---|
1130 | cursor_gc = SEC_GC_ECOLI; |
---|
1131 | disp_pos = db->ecoli()->abs_2_rel(curAbs+1); // show ecoli base position (inclusive cursorpos) |
---|
1132 | break; |
---|
1133 | } |
---|
1134 | case SHOW_NO_CURPOS: |
---|
1135 | cursor_gc = -1; |
---|
1136 | break; |
---|
1137 | } |
---|
1138 | |
---|
1139 | if (cursor_gc >= 0) { |
---|
1140 | paintPosAnnotation(device, cursor_gc, curAbs, GBS_global_string("%u", disp_pos), true, true); |
---|
1141 | } |
---|
1142 | } |
---|
1143 | } |
---|
1144 | return error; |
---|
1145 | } |
---|
1146 | |
---|
1147 | void SEC_region::align_helix_strands(SEC_root *root, SEC_region *other_region) { |
---|
1148 | if (abspos_array) { |
---|
1149 | const BI_helix *helix = root->get_helixDef(); |
---|
1150 | if (helix && !helix->get_error()) { |
---|
1151 | SEC_region *reg[2] = { this, other_region }; |
---|
1152 | int incr[2] = { 1, -1 }; // this is iterated forward, other_region backward |
---|
1153 | int *absarr[2]; |
---|
1154 | int *new_absarr[2] = { NULp, NULp }; |
---|
1155 | |
---|
1156 | |
---|
1157 | for (int r = 0; r<2; ++r) { |
---|
1158 | absarr[r] = reg[r]->abspos_array; |
---|
1159 | } |
---|
1160 | |
---|
1161 | for (int write = 0; write < 2; ++write) { |
---|
1162 | int curr[2] = { 0, reg[1]->baseCount-1 }; |
---|
1163 | int last[2] = { reg[0]->baseCount-1, 0 }; |
---|
1164 | int newp[2] = { 0, 0 }; |
---|
1165 | |
---|
1166 | while (curr[0] <= last[0] && curr[1] >= last[1]) { |
---|
1167 | int abs[2]; |
---|
1168 | bool ispair[2]; |
---|
1169 | |
---|
1170 | for (int r = 0; r<2; ++r) { |
---|
1171 | abs[r] = absarr[r][curr[r]]; |
---|
1172 | ispair[r] = abs[r] >= 0 && (helix->pairtype(abs[r]) != HELIX_NONE); |
---|
1173 | } |
---|
1174 | |
---|
1175 | if (ispair[0] && ispair[1]) { |
---|
1176 | if (helix->opposite_position(abs[0]) != size_t(abs[1]) || |
---|
1177 | helix->opposite_position(abs[1]) != size_t(abs[0])) |
---|
1178 | { |
---|
1179 | GB_ERROR error = GBS_global_string("Helix '%s/%s' folded at wrong position. Please refold.", |
---|
1180 | helix->helixNr(abs[0]), helix->helixNr(abs[1])); |
---|
1181 | aw_message(error); |
---|
1182 | } |
---|
1183 | |
---|
1184 | for (int r = 0; r<2; ++r) { // fill up to align binding positions |
---|
1185 | while (newp[r]<newp[1-r]) { |
---|
1186 | if (write) { |
---|
1187 | new_absarr[r][newp[r]] = -1; |
---|
1188 | } |
---|
1189 | newp[r]++; |
---|
1190 | } |
---|
1191 | } |
---|
1192 | |
---|
1193 | sec_assert(newp[0] == newp[1]); |
---|
1194 | |
---|
1195 | for (int r = 0; r<2; ++r) { // copy binding positions |
---|
1196 | if (write) new_absarr[r][newp[r]] = abs[r]; |
---|
1197 | newp[r]++; curr[r] += incr[r]; |
---|
1198 | } |
---|
1199 | } |
---|
1200 | else { |
---|
1201 | bool collected = false; |
---|
1202 | for (int r = 0; r<2; ++r) { |
---|
1203 | if (abs[r] >= 0 && !ispair[r]) { // collect non-pairing bases |
---|
1204 | if (write) { |
---|
1205 | new_absarr[r][newp[r]] = abs[r]; |
---|
1206 | } |
---|
1207 | newp[r]++; curr[r] += incr[r]; |
---|
1208 | collected = true; |
---|
1209 | } |
---|
1210 | } |
---|
1211 | if (!collected) { |
---|
1212 | for (int r = 0; r<2; ++r) { |
---|
1213 | if (abs[r]<0) curr[r] += incr[r]; |
---|
1214 | } |
---|
1215 | } |
---|
1216 | } |
---|
1217 | } |
---|
1218 | |
---|
1219 | sec_assert(newp[0] == newp[1]); // alignment failed |
---|
1220 | |
---|
1221 | for (int r = 0; r<2; ++r) { |
---|
1222 | if (write) { |
---|
1223 | if (r == 1) { // reverse positions |
---|
1224 | int p2 = newp[1]-1; |
---|
1225 | int *arr = new_absarr[1]; |
---|
1226 | for (int p = 0; p<p2; ++p, --p2) { // LOOP_VECTORIZED[!<810] |
---|
1227 | swap(arr[p], arr[p2]); |
---|
1228 | } |
---|
1229 | } |
---|
1230 | |
---|
1231 | delete [] reg[r]->abspos_array; |
---|
1232 | reg[r]->abspos_array = new_absarr[r]; |
---|
1233 | #if defined(ASSERTION_USED) |
---|
1234 | reg[r]->abspos_array_size = newp[r]; |
---|
1235 | #endif // ASSERTION_USED |
---|
1236 | reg[r]->set_base_count(newp[r]); |
---|
1237 | } |
---|
1238 | else { |
---|
1239 | // allocate buffers for second pass |
---|
1240 | new_absarr[r] = new int[newp[r]]; |
---|
1241 | } |
---|
1242 | } |
---|
1243 | } |
---|
1244 | } |
---|
1245 | } |
---|
1246 | } |
---|
1247 | |
---|