Esempio n. 1
0
void
gv_shapes_replace_shapes(GvShapes *shapes, gint num_shapes, gint *shape_id,
                         GvShape **shps, int make_copy)
{
    gint i;
    GvShapeChangeInfo change_info = {GV_CHANGE_REPLACE, 0, NULL};

    change_info.num_shapes = num_shapes;
    change_info.shape_id = shape_id;

    gv_data_changing(GV_DATA(shapes), &change_info);

    for (i=0; i < num_shapes; ++i)
    {
        GvShape *shape;

        if( shape_id[i] < 0 || shape_id[i] >= shapes->shapes->len )
            continue;
        else if( gv_shapes_get_shape(shapes, shape_id[i]) != NULL )
            gv_shape_unref( gv_shapes_get_shape(shapes, shape_id[i]) );
        else
            g_warning( "Missing shape in gv_shapes_replace_shapes()" );

        if( make_copy )
            shape = gv_shape_copy(shps[i]);
        else
            shape = shps[i];

        gv_shape_ref( shape );
        g_ptr_array_index(shapes->shapes, shape_id[i]) = shape;
    }

    gv_data_changed(GV_DATA(shapes), &change_info);
}
Esempio n. 2
0
/* same as gv_shape_add_shape but do not fill the holes, always append shape at the end*/
gint
gv_shapes_add_shape_last(GvShapes *shapes, GvShape *new_shape)

{
    int  shape_id;
    GvShapeChangeInfo change_info = {GV_CHANGE_ADD, 1, NULL};


    shape_id = shapes->shapes->len;

    /* Make notification of impending change */
    change_info.shape_id = &shape_id;
    gv_data_changing(GV_DATA(shapes), &change_info);

    /* apply update */
    if( shape_id == shapes->shapes->len )
        g_ptr_array_add(shapes->shapes, new_shape );
    else
        g_ptr_array_index(shapes->shapes, shape_id) = new_shape;

    gv_shape_ref( new_shape );
    shapes->actual_num_shapes++;

    /* notify of completed change */
    gv_data_changed(GV_DATA(shapes), &change_info);

    return shape_id;
}
Esempio n. 3
0
static void
gv_shapes_insert_shapes(GvShapes *shapes, gint num_shapes, gint *shape_ids,
                        GvShape **shps)
{
    gint i;
    GvShapeChangeInfo change_info = {GV_CHANGE_ADD, 0, NULL};

    change_info.num_shapes = num_shapes;
    change_info.shape_id = shape_ids;

    gv_data_changing(GV_DATA(shapes), &change_info);

    for (i=0; i < num_shapes; ++i)
    {
        int id = shape_ids[i];

        if( id >= shapes->shapes->len )
        {
            int  old_length = shapes->shapes->len;

            g_ptr_array_set_size( shapes->shapes, id+1 );
            while( old_length < id )
            {
                g_ptr_array_index(shapes->shapes, old_length) = NULL;
                old_length++;
            }

            gv_shape_ref( shps[i] );
            g_ptr_array_index( shapes->shapes, id ) = shps[i];

            shapes->actual_num_shapes++;
        }
        else if( g_ptr_array_index( shapes->shapes, id ) == NULL )
        {
            gv_shape_ref( shps[i] );
            g_ptr_array_index( shapes->shapes, id ) = shps[i];
            shapes->actual_num_shapes++;
        }
        else
        {
            g_warning( "gv_shapes_insert_shapes(): target shape_id not NULL!");
        }
    }

    gv_data_changed(GV_DATA(shapes), &change_info);
}
Esempio n. 4
0
static void
gv_shapes_get_memento(GvData *gv_data, gpointer data,
                      GvDataMemento **memento)
{
    GvShapes    *shapes = GV_SHAPES(gv_data);
    GvShapesMemento *mem;
    GvShapeChangeInfo *info = (GvShapeChangeInfo *) data;
    int i;

    mem = g_new(GvShapesMemento, 1);
    mem->base.data = GV_DATA(shapes);
    mem->base.type = info->change_type;

    mem->ids = g_array_new(FALSE, FALSE, sizeof(gint));
    g_array_append_vals(mem->ids, info->shape_id, info->num_shapes);

    /* Grab in ascending order */
    if (info->num_shapes > 1)
    {
        g_sort_type(mem->ids->data, gint, mem->ids->len);
    }

    if (info->change_type == GV_CHANGE_ADD)
    {
        mem->shapes = NULL;
    }
    else
    {
        mem->shapes = g_ptr_array_new();
        for (i=0; i < info->num_shapes; ++i)
        {
            GvShape    *shape = gv_shapes_get_shape(shapes,info->shape_id[i]);

            shape = gv_shape_copy( shape );
            gv_shape_ref( shape );
            g_ptr_array_add(mem->shapes, shape );
        }
    }

    *memento = (GvDataMemento*)mem;
}
Esempio n. 5
0
void gv_symbol_manager_inject_vector_symbol( GvSymbolManager *manager, 
                                             const char *symbol_name, 
                                             GvShape *shape )

{
    GvSymbolObj *symbol;

    /* allocate a new symbol object */
    symbol = g_new0( GvSymbolObj, 1 );

    symbol->type = GV_SYMBOL_VECTOR;
    
    /* take a reference to the shape */
    symbol->buffer = shape;
    gv_shape_ref( shape );
    
    /* insert new symbol into symbol manager */
    g_hash_table_insert( manager->symbol_cache, g_strdup(symbol_name), symbol );

    CPLDebug("OpenEV", "inject_vector_symbol(%s)", symbol_name );
}
Esempio n. 6
0
gint
gv_shapes_add_shape(GvShapes *shapes, GvShape *new_shape)

{
    int  shape_id;
    GvShapeChangeInfo change_info = {GV_CHANGE_ADD, 1, NULL};

    /* Identify where to put it, reuse old holes if available */
    if( shapes->shapes->len != shapes->actual_num_shapes )
    {
        for( shape_id=0; shape_id < shapes->shapes->len; shape_id++ )
        {
            if( g_ptr_array_index(shapes->shapes, shape_id) == NULL )
                break;
        }
    }
    else
    {
        shape_id = shapes->shapes->len;
    }

    /* Make notification of impending change */
    change_info.shape_id = &shape_id;
    gv_data_changing(GV_DATA(shapes), &change_info);

    /* apply update */
    if( shape_id == shapes->shapes->len )
        g_ptr_array_add(shapes->shapes, new_shape );
    else
        g_ptr_array_index(shapes->shapes, shape_id) = new_shape;

    gv_shape_ref( new_shape );
    shapes->actual_num_shapes++;

    /* notify of completed change */
    gv_data_changed(GV_DATA(shapes), &change_info);

    return shape_id;
}