void gt_block_print(const GtBlock* block) { GtUword i; gt_assert(block); for (i=0;i<gt_array_size(block->elements);i++) { GtElement *elem; elem = gt_element_ref(*(GtElement**) gt_array_get(block->elements, i)); gt_assert(elem); GtRange r = gt_element_get_range(elem); printf("%s\t"GT_WU"-"GT_WU"\n", gt_element_get_type(elem), r.start, r.end); } }
bool gt_block_has_only_one_fullsize_element(const GtBlock *block) { bool ret = false; GtUword bsize; gt_assert(block); bsize = gt_array_size(block->elements); if (bsize == 1) { GtRange elem_range, block_range; gt_assert(*(GtElement**) gt_array_get(block->elements, 0) == *(GtElement**) gt_array_get(block->elements, bsize-1)); elem_range = gt_element_get_range(*(GtElement**) gt_array_get(block->elements, 0)); block_range = gt_block_get_range(block); ret = (gt_range_compare(&block_range, &elem_range) == 0); } return ret; }
int gt_canvas_cairo_visit_element(GtCanvas *canvas, GtElement *elem, GtError *err) { int had_err = 0, arrow_status = ARROW_NONE; GtRange elem_range = gt_element_get_range(elem); GtDrawingRange draw_range; double elem_start = GT_UNDEF_DOUBLE, elem_width = GT_UNDEF_DOUBLE, stroke_width = STROKE_WIDTH_DEFAULT, bar_height = BAR_HEIGHT_DEFAULT, arrow_width = ARROW_WIDTH_DEFAULT; GtColor elem_color, grey, fill_color; const char *type; GtStyleQueryStatus rval; GtStr *style; GtStrand strand = gt_element_get_strand(elem); gt_assert(canvas && elem); /* This shouldn't happen. */ if (!gt_range_overlap(&elem_range, &canvas->pvt->viewrange)) return -1; type = gt_element_get_type(elem); grey.red = grey.green = grey.blue = .85; grey.alpha = 0.5; /* get default or image-wide bar height */ if (gt_style_get_num(canvas->pvt->sty, "format", "bar_height", &bar_height, NULL, err) == GT_STYLE_QUERY_ERROR) { return -1; } /* try to get type-specific bar height */ if (gt_style_get_num_with_track(canvas->pvt->sty, type, "bar_height", &bar_height, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err) == GT_STYLE_QUERY_ERROR) { return -1; } /* get default or image-wide arrow width */ if (gt_style_get_num(canvas->pvt->sty, "format", "arrow_width", &arrow_width, NULL, err)== GT_STYLE_QUERY_ERROR) { return -1; } /* try to get type-specific arrow width */ if (gt_style_get_num_with_track(canvas->pvt->sty, type, "arrow_width", &arrow_width, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err) == GT_STYLE_QUERY_ERROR) { return -1; } if ((strand == GT_STRAND_REVERSE || strand == GT_STRAND_BOTH) /*&& delem == gt_dlist_first(elems)*/) arrow_status = ARROW_LEFT; if ((strand == GT_STRAND_FORWARD || strand == GT_STRAND_BOTH) /*&& gt_dlistelem_next(delem) == NULL*/) arrow_status = (arrow_status == ARROW_LEFT ? ARROW_BOTH : ARROW_RIGHT); gt_log_log("processing element from %lu to %lu, strand %d\n", elem_range.start, elem_range.end, (int) strand); draw_range = gt_coords_calc_generic_range(elem_range, canvas->pvt->viewrange); draw_range.start *= (canvas->pvt->width-2*canvas->pvt->margins); draw_range.end *= (canvas->pvt->width-2*canvas->pvt->margins); elem_start = draw_range.start + canvas->pvt->margins; elem_width = draw_range.end - draw_range.start; gt_assert(elem_start != GT_UNDEF_DOUBLE && elem_width != GT_UNDEF_DOUBLE); if (gt_element_is_marked(elem)) { if (gt_style_get_color_with_track(canvas->pvt->sty, type, "stroke_marked", &elem_color, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err) == GT_STYLE_QUERY_ERROR) { return -1; } if (gt_style_get_num_with_track(canvas->pvt->sty, "format", "stroke_marked_width", &stroke_width, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err) == GT_STYLE_QUERY_ERROR) { return -1; } } else { if (gt_style_get_color_with_track(canvas->pvt->sty, type, "stroke", &elem_color, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err) == GT_STYLE_QUERY_ERROR) { return -1; } if (gt_style_get_num_with_track(canvas->pvt->sty, "format", "stroke_width", &stroke_width, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err) == GT_STYLE_QUERY_ERROR) { return -1; } if (gt_style_get_num_with_track(canvas->pvt->sty, type, "stroke_width", &stroke_width, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err) == GT_STYLE_QUERY_ERROR) { return -1; } } if (gt_style_get_color_with_track(canvas->pvt->sty, type, "fill", &fill_color, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err) == GT_STYLE_QUERY_ERROR) { return -1; } if (canvas->pvt->bt && gt_double_smaller_double(draw_range.end-draw_range.start, 1.1)) { if ((unsigned long) draw_range.start > gt_bittab_size(canvas->pvt->bt)) return had_err; if (gt_bittab_bit_is_set(canvas->pvt->bt, (unsigned long) draw_range.start)) return had_err; gt_graphics_draw_vertical_line(canvas->pvt->g, elem_start, canvas->pvt->y - bar_height/2, elem_color, bar_height, stroke_width); gt_bittab_set_bit(canvas->pvt->bt, (unsigned long) draw_range.start); } /* register coordinates in GtImageInfo object if available */ if (canvas->pvt->ii) { GtRecMap *rm = gt_rec_map_new(elem_start, canvas->pvt->y - bar_height/2, elem_start+elem_width, canvas->pvt->y+bar_height/2, (GtFeatureNode*) gt_element_get_node_ref(elem)); gt_image_info_add_rec_map(canvas->pvt->ii, rm); } if (canvas->pvt->bt && draw_range.end-draw_range.start <= 1.1) { return had_err; } gt_log_log("drawing element from %f to %f, arrow status: %d", draw_range.start, draw_range.end, arrow_status); /* draw each element according to style set in the style */ style = gt_str_new(); rval = gt_style_get_str_with_track(canvas->pvt->sty, type, "style", style, gt_element_get_node_ref(elem), gt_track_get_title(canvas->pvt->current_track), err); switch (rval) { case GT_STYLE_QUERY_NOT_SET: gt_str_set(style, "box"); /* default style */ break; case GT_STYLE_QUERY_ERROR: gt_str_delete(style); gt_assert(gt_error_is_set(err)); return -1; default: break; } if (strcmp(gt_str_get(style), "box") == 0) { gt_graphics_draw_box(canvas->pvt->g, elem_start, canvas->pvt->y - bar_height/2, elem_width, bar_height, fill_color, arrow_status, arrow_width, stroke_width, elem_color, false); } else if (strcmp(gt_str_get(style), "rectangle") == 0) { gt_graphics_draw_box(canvas->pvt->g, elem_start, canvas->pvt->y - bar_height/2, elem_width, bar_height, fill_color, ARROW_NONE, arrow_width, stroke_width, elem_color, false); } else if (strcmp(gt_str_get(style), "caret") == 0) { gt_graphics_draw_caret(canvas->pvt->g, elem_start, canvas->pvt->y - bar_height/2, elem_width, bar_height, ARROW_NONE, arrow_width, stroke_width, elem_color); } else if (strcmp(gt_str_get(style), "dashes") == 0) { gt_graphics_draw_dashes(canvas->pvt->g, elem_start, canvas->pvt->y - bar_height/2, elem_width, bar_height, arrow_status, arrow_width, stroke_width, elem_color); } else if (strcmp(gt_str_get(style), "line") == 0) { gt_graphics_draw_horizontal_line(canvas->pvt->g, elem_start, canvas->pvt->y - bar_height/2, elem_color, elem_width, 1.0); } else { gt_graphics_draw_box(canvas->pvt->g, elem_start, canvas->pvt->y - bar_height/2, elem_width, bar_height, fill_color, arrow_status, arrow_width, stroke_width, elem_color, false); } gt_str_delete(style); /* draw arrowheads at clipped margins */ if (draw_range.clip == CLIPPED_LEFT || draw_range.clip == CLIPPED_BOTH) gt_graphics_draw_arrowhead(canvas->pvt->g, canvas->pvt->margins - 10, canvas->pvt->y - 4, grey, ARROW_LEFT); if (draw_range.clip == CLIPPED_RIGHT || draw_range.clip == CLIPPED_BOTH) gt_graphics_draw_arrowhead(canvas->pvt->g, canvas->pvt->width-canvas->pvt->margins + 10, canvas->pvt->y - 4, grey, ARROW_RIGHT); return had_err; }