コード例 #1
0
ファイル: adg-dim.c プロジェクト: bert/adg
/**
 * adg_dim_set_ref1_explicit:
 * @dim: an #AdgDim
 * @x: x coordinate of the first reference point
 * @y: y coordinate of the first reference point
 *
 * Sets the #AdgDim:ref1 property to the (@x, @y) explicit
 * coordinates. The old point is silently discarded,
 * unreferencing its model if that point was bound to a named
 * pair (hence, possibly destroying the model if this was the
 * last reference).
 *
 * Since: 1.0
 **/
void
adg_dim_set_ref1_explicit(AdgDim *dim, gdouble x, gdouble y)
{
    AdgPoint *point = adg_point_new();

    adg_point_set_pair_explicit(point, x, y);
    adg_dim_set_ref1(dim, point);

    adg_point_destroy(point);
}
コード例 #2
0
ファイル: adg-dim.c プロジェクト: bert/adg
/**
 * adg_dim_set_ref1_from_model:
 * @dim: an #AdgDim
 * @model: the source #AdgModel
 * @ref1: a named pair in @model
 *
 * Binds #AdgDim:ref1 to the @ref1 named pair of @model. If @model
 * is <constant>NULL</constant>, the point will be unset. In any case,
 * the old point is silently discarded, unreferencing its model
 * if that point was bound to a named pair (hence, possibly destroying
 * the model if this was the last reference).
 *
 * The assignment is lazy so @ref1 could be not be present in @model.
 * Anyway, at the first access to this point an error will be raised
 * if the named pair is still missing.
 *
 * Since: 1.0
 **/
void
adg_dim_set_ref1_from_model(AdgDim *dim, AdgModel *model, const gchar *ref1)
{
    AdgPoint *point = adg_point_new();

    adg_point_set_pair_from_model(point, model, ref1);
    adg_dim_set_ref1(dim, point);

    adg_point_destroy(point);
}
コード例 #3
0
static void
_adg_property_ref1(void)
{
    AdgDim *dim;
    AdgModel *model;
    AdgPoint *origin, *explicit_point, *model_point;
    AdgPoint *ref1;

    dim = ADG_DIM(adg_rdim_new());
    model = ADG_MODEL(adg_path_new());
    origin = adg_point_new();
    explicit_point = adg_point_new();
    model_point = adg_point_new();

    adg_point_set_pair_explicit(origin, 0, 0);
    adg_point_set_pair_explicit(explicit_point, 123, 321);
    adg_model_set_named_pair(model, "named-pair", (CpmlPair *) explicit_point);
    adg_point_set_pair_from_model(model_point, model, "named-pair");

    /* Ensure ADG does not consider an explicit point equals to
     * a point bound to a named pair with the same coordinates */
    g_assert_false(adg_point_equal(explicit_point, model_point));

    ref1 = adg_dim_get_ref1(dim);
    g_assert_null(ref1);

    /* Using the public APIs */
    adg_dim_set_ref1_explicit(dim, 0, 0);
    ref1 = adg_dim_get_ref1(dim);
    g_assert_true(adg_point_equal(ref1, origin));

    adg_dim_set_ref1(dim, NULL);
    ref1 = adg_dim_get_ref1(dim);
    g_assert_null(ref1);

    adg_dim_set_ref1(dim, explicit_point);
    ref1 = adg_dim_get_ref1(dim);
    g_assert_true(adg_point_equal(ref1, explicit_point));

    adg_dim_set_ref1_from_model(dim, model, "dummy");
    ref1 = adg_dim_get_ref1(dim);
    g_assert_nonnull(ref1);

    adg_dim_set_ref1_from_model(dim, model, "named-pair");
    ref1 = adg_dim_get_ref1(dim);
    g_assert_true(adg_point_equal(ref1, model_point));

    /* Using GObject property methods */
    g_object_set(dim, "ref1", origin, NULL);
    g_object_get(dim, "ref1", &ref1, NULL);
    g_assert_true(adg_point_equal(ref1, origin));
    adg_point_destroy(ref1);

    g_object_set(dim, "ref1", NULL, NULL);
    g_object_get(dim, "ref1", &ref1, NULL);
    g_assert_null(ref1);

    g_object_set(dim, "ref1", explicit_point, NULL);
    g_object_get(dim, "ref1", &ref1, NULL);
    g_assert_true(adg_point_equal(ref1, explicit_point));
    adg_point_destroy(ref1);

    adg_dim_set_ref1_from_model(dim, model, "dummy");
    g_object_get(dim, "ref1", &ref1, NULL);
    g_assert_nonnull(ref1);
    adg_point_destroy(ref1);

    g_object_set(dim, "ref1", model_point, NULL);
    g_object_get(dim, "ref1", &ref1, NULL);
    g_assert_true(adg_point_equal(ref1, model_point));
    adg_point_destroy(ref1);

    adg_point_destroy(origin);
    adg_point_destroy(explicit_point);
    adg_point_destroy(model_point);
    adg_entity_destroy(ADG_ENTITY(dim));
    g_object_unref(model);
}