Пример #1
0
static void
_adg_arrange(AdgEntity *entity)
{
    AdgStroke *stroke;
    AdgStrokePrivate *data;
    const CpmlExtents *trail_extents;
    CpmlExtents extents;

    /* Check for cached result */
    if (adg_entity_get_extents(entity)->is_defined)
        return;

    stroke = (AdgStroke *) entity;
    data = stroke->data;
    trail_extents = adg_trail_get_extents(data->trail);

    /* Ensure a trail is bound to this entity */
    if (trail_extents == NULL)
        return;

    cpml_extents_copy(&extents, trail_extents);
    cpml_extents_transform(&extents, adg_entity_get_local_matrix(entity));
    cpml_extents_transform(&extents, adg_entity_get_global_matrix(entity));
    adg_entity_set_extents(entity, &extents);
}
Пример #2
0
static void
_adg_arrange_class(AdgProjectionClass *projection_class,
                   AdgProjectionScheme scheme)
{
    AdgProjectionClassPrivate *data_class;
    AdgPath *symbol, *axis;

    data_class = projection_class->data_class;

    if (data_class->scheme == scheme)
        return;

    if (data_class->symbol != NULL)
        g_object_unref(data_class->symbol);

    if (data_class->axis != NULL)
        g_object_unref(data_class->axis);

    data_class->scheme = scheme;

    switch(scheme) {
    case ADG_PROJECTION_SCHEME_UNDEFINED:
        symbol = NULL;
        axis = NULL;
        break;
    case ADG_PROJECTION_SCHEME_FIRST_ANGLE:
        symbol = adg_path_new();
        adg_path_move_to_explicit(symbol, 4, 19);
        adg_path_line_to_explicit(symbol, 24, 24);
        adg_path_line_to_explicit(symbol, 24, 4);
        adg_path_line_to_explicit(symbol, 4, 9);
        adg_path_close(symbol);
        adg_path_move_to_explicit(symbol, 49, 14);
        adg_path_arc_to_explicit(symbol, 29, 14, 49, 14);
        adg_path_move_to_explicit(symbol, 44, 14);
        adg_path_arc_to_explicit(symbol, 34, 14, 44, 14);

        axis = adg_path_new();
        adg_path_move_to_explicit(axis, 0, 14);
        adg_path_line_to_explicit(axis, 53, 14);
        adg_path_move_to_explicit(axis, 39, 0);
        adg_path_line_to_explicit(axis, 39, 28);
        break;
    case ADG_PROJECTION_SCHEME_THIRD_ANGLE:
        symbol = adg_path_new();
        adg_path_move_to_explicit(symbol, 29, 19);
        adg_path_line_to_explicit(symbol, 49, 24);
        adg_path_line_to_explicit(symbol, 49, 4);
        adg_path_line_to_explicit(symbol, 29, 9);
        adg_path_close(symbol);
        adg_path_move_to_explicit(symbol, 24, 14);
        adg_path_arc_to_explicit(symbol, 4, 14, 24, 14);
        adg_path_move_to_explicit(symbol, 19, 14);
        adg_path_arc_to_explicit(symbol, 9, 14, 19, 14);

        axis = adg_path_new();
        adg_path_move_to_explicit(axis, 0, 14);
        adg_path_line_to_explicit(axis, 53, 14);
        adg_path_move_to_explicit(axis, 14, 0);
        adg_path_line_to_explicit(axis, 14, 28);
        break;
    default:
        g_return_if_reached();
        break;
    }

    data_class->symbol = symbol;
    data_class->axis = axis;
    data_class->extents.is_defined = FALSE;

    if (axis != NULL)
        cpml_extents_add(&data_class->extents,
                         adg_trail_get_extents((AdgTrail *) axis));

    if (symbol != NULL)
        cpml_extents_add(&data_class->extents,
                         adg_trail_get_extents((AdgTrail *) symbol));
}
Пример #3
0
static void
_adg_arrange(AdgEntity *entity)
{
    AdgADim *adim;
    AdgDim *dim;
    AdgADimPrivate *data;
    AdgAlignment *quote;
    const cairo_matrix_t *global, *local;
    CpmlPair ref1, ref2, base1, base12, base2;
    CpmlPair pair;
    CpmlExtents extents;
    AdgEntity *marker_entity;

    if (_ADG_OLD_ENTITY_CLASS->arrange)
        _ADG_OLD_ENTITY_CLASS->arrange(entity);

    adim = (AdgADim *) entity;

    if (! _adg_update_geometry(adim))
        return;

    dim = (AdgDim *) adim;
    data = adim->data;
    quote = adg_dim_get_quote(dim);

    _adg_update_entities(adim);

    if (data->cairo.path.status == CAIRO_STATUS_SUCCESS) {
        AdgEntity *quote_entity = (AdgEntity *) quote;
        adg_entity_set_global_map(quote_entity, &data->quote.global_map);
        return;
    }

    global = adg_entity_get_global_matrix(entity);
    local = adg_entity_get_local_matrix(entity);
    extents.is_defined = FALSE;

    cpml_pair_copy(&ref1, (CpmlPair *) adg_dim_get_ref1(dim));
    cpml_pair_copy(&ref2, (CpmlPair *) adg_dim_get_ref2(dim));
    cpml_pair_copy(&base1, &data->point.base1);
    cpml_pair_copy(&base12, &data->point.base12);
    cpml_pair_copy(&base2, &data->point.base2);

    /* Apply the local matrix to the relevant points */
    cpml_pair_transform(&ref1, local);
    cpml_pair_transform(&ref2, local);
    cpml_pair_transform(&base1, local);
    cpml_pair_transform(&base12, local);
    cpml_pair_transform(&base2, local);

    /* Combine points and global shifts to build the path */
    pair.x = ref1.x + data->shift.from1.x;
    pair.y = ref1.y + data->shift.from1.y;
    cpml_pair_to_cairo(&pair, &data->cairo.data[6]);

    pair.x = base1.x + data->shift.base1.x;
    pair.y = base1.y + data->shift.base1.y;
    cpml_pair_to_cairo(&pair, &data->cairo.data[1]);

    pair.x += data->shift.to1.x;
    pair.y += data->shift.to1.y;
    cpml_pair_to_cairo(&pair, &data->cairo.data[8]);

    pair.x = base12.x + data->shift.base12.x;
    pair.y = base12.y + data->shift.base12.y;
    cpml_pair_to_cairo(&pair, &data->cairo.data[3]);

    pair.x = ref2.x + data->shift.from2.x;
    pair.y = ref2.y + data->shift.from2.y;
    cpml_pair_to_cairo(&pair, &data->cairo.data[10]);

    pair.x = base2.x + data->shift.base2.x;
    pair.y = base2.y + data->shift.base2.y;
    cpml_pair_to_cairo(&pair, &data->cairo.data[4]);

    pair.x += data->shift.to2.x;
    pair.y += data->shift.to2.y;
    cpml_pair_to_cairo(&pair, &data->cairo.data[12]);

    /* Play with header lengths to show or hide the extension lines */
    if (data->has_extension1) {
        data->cairo.data[7].header.length = data->has_extension2 ? 2 : 6;
    } else {
        data->cairo.data[2].header.length = data->has_extension2 ? 7 : 11;
    }

    data->cairo.path.status = CAIRO_STATUS_SUCCESS;

    /* Arrange the quote */
    if (quote != NULL) {
        AdgEntity *quote_entity;
        gdouble angle;
        cairo_matrix_t map;

        quote_entity = (AdgEntity *) quote;
        angle = adg_dim_quote_angle(dim, (data->angle1 + data->angle2) / 2 + G_PI_2);
        cpml_pair_from_cairo(&pair, &data->cairo.data[3]);

        adg_alignment_set_factor_explicit(quote, 0.5, 0);

        cairo_matrix_init_translate(&map, pair.x, pair.y);
        cairo_matrix_rotate(&map, angle);
        adg_entity_set_global_map(quote_entity, &map);
        adg_entity_arrange(quote_entity);
        cpml_extents_add(&extents, adg_entity_get_extents(quote_entity));

        adg_matrix_copy(&data->quote.global_map, &map);
    }

    /* Arrange the trail */
    if (data->trail != NULL) {
        CpmlExtents trail_extents;
        cpml_extents_copy(&trail_extents, adg_trail_get_extents(data->trail));
        cpml_extents_transform(&trail_extents, global);
        cpml_extents_add(&extents, &trail_extents);
    } else {
        _adg_dispose_markers(adim);
    }

    /* Arrange the markers */
    if (data->marker1 != NULL) {
        marker_entity = (AdgEntity *) data->marker1;
        adg_marker_set_segment(data->marker1, data->trail, 1);
        adg_entity_local_changed(marker_entity);
        adg_entity_arrange(marker_entity);
        cpml_extents_add(&extents, adg_entity_get_extents(marker_entity));
    }
    if (data->marker2 != NULL) {
        marker_entity = (AdgEntity *) data->marker2;
        adg_marker_set_segment(data->marker2, data->trail, 1);
        adg_entity_local_changed(marker_entity);
        adg_entity_arrange(marker_entity);
        cpml_extents_add(&extents, adg_entity_get_extents(marker_entity));
    }

    adg_entity_set_extents(entity, &extents);
}
Пример #4
0
Файл: adg-logo.c Проект: ntd/adg
static void
_adg_arrange_class(AdgLogoClass *logo_class)
{
    AdgLogoClassPrivate *data_class;
    CpmlExtents *extents;

    data_class = logo_class->data_class;
    extents = &data_class->extents;

    if (data_class->symbol == NULL) {
        AdgPath *path = adg_path_new();

        adg_path_move_to_explicit(path, 8, 26);
        adg_path_line_to_explicit(path, 24, 10);
        adg_path_arc_to_explicit(path, 32, 18, 24, 26);
        adg_path_line_to_explicit(path, 24, 11);

        adg_path_move_to_explicit(path, 40, 10);
        adg_path_arc_to_explicit(path, 32, 18, 40, 26);
        adg_path_line_to_explicit(path, 40, 22);
        adg_path_line_to_explicit(path, 38, 22);

        adg_path_move_to_explicit(path, 23, 22);
        adg_path_line_to_explicit(path, 16, 22);

        data_class->symbol = path;
        extents->is_defined = FALSE;
    }

    if (data_class->screen == NULL) {
        AdgPath *path = adg_path_new();

        adg_path_move_to_explicit(path, 3, 3);
        adg_path_line_to_explicit(path, 47, 3);
        adg_path_fillet(path, 10);
        adg_path_line_to_explicit(path, 47, 33);
        adg_path_fillet(path, 10);
        adg_path_line_to_explicit(path, 3, 33);
        adg_path_fillet(path, 10);
        adg_path_close(path);
        adg_path_fillet(path, 10);

        data_class->screen = path;
        extents->is_defined = FALSE;
    }

    if (data_class->frame == NULL) {
        AdgPath *path = adg_path_new();

        adg_path_move_to_explicit(path, 0, 0);
        adg_path_line_to_explicit(path, 50, 0);
        adg_path_line_to_explicit(path, 50, 36);
        adg_path_line_to_explicit(path, 0, 36);
        adg_path_close(path);

        data_class->frame = path;
        extents->is_defined = FALSE;
    }

    if (!data_class->extents.is_defined) {
        cpml_extents_add(extents,
                         adg_trail_get_extents((AdgTrail *) data_class->symbol));
        cpml_extents_add(extents,
                         adg_trail_get_extents((AdgTrail *) data_class->screen));
        cpml_extents_add(extents,
                         adg_trail_get_extents((AdgTrail *) data_class->frame));
    }
}