Пример #1
0
static gboolean
gv_rect_tool_motion_notify(GvTool *r_tool, GdkEventMotion *event)
{
    GvRectTool *tool = GV_RECT_TOOL(r_tool);

    if (tool->drawing)
    {
        /* Map pointer position to tail vertex */
        gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
                                 &tool->v_tail.x, &tool->v_tail.y);

        gv_tool_clamp_to_bounds( GV_TOOL(tool),
                                 &tool->v_tail.x, &tool->v_tail.y );

        gv_view_area_queue_draw(GV_TOOL(tool)->view);
    }

    if (tool->reshaping)
    {
        /* Map pointer position to tail vertex */
        gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
                                 &tool->v_tail.x, &tool->v_tail.y);
        gv_rect_tool_reshape( tool, tool->v_tail.x, tool->v_tail.y );
    }
    return FALSE;
}
Пример #2
0
static void
gv_rect_tool_key_press(GvTool *rtool, GdkEventKey *event)
{
    GvRectTool *tool = GV_RECT_TOOL(rtool);

    if (!gv_rect_tool_configure(tool)) return;

    switch (event->keyval)
    {
        case GDK_Delete:
        case GDK_BackSpace:
        case GDK_Escape:
          if( tool->drawing )
          {
              tool->drawing = FALSE;
              gv_view_area_queue_draw(GV_TOOL(tool)->view);
          }
          if( tool->reshaping )
          {
              /* Reopen undo.  Push a memento describing the ring addition */
              gv_undo_enable();
              gv_undo_open();

              tool->reshaping = FALSE;
              gv_view_area_queue_draw(GV_TOOL(tool)->view);
          }
          break;
    }
}
Пример #3
0
static gint
gv_rotate_tool_configure(GvRotateTool *tool)
{
    /* Check that we still are working on the active layer */
    if (!tool->layer ||	GTK_OBJECT(tool->layer) !=
	gv_view_area_active_layer(GV_TOOL(tool)->view))
    {
	GtkObject *layer;

	if (tool->named_layer)
	{
	    /* Look for named layer if given */
	    layer = gv_view_area_get_named_layer(GV_TOOL(tool)->view,
						 tool->named_layer);
	}
	else
	{
            layer = gv_view_area_get_layer_of_type(GV_TOOL(tool)->view,
                                                   GV_TYPE_SHAPES_LAYER,
                                                   FALSE);
	}

	if (!layer)
	{
	    g_warning("gv_rotate_tool_configure(): no shapes layer in view");
	    return FALSE;
	}

	gv_rotate_tool_set_layer(tool, GV_SHAPE_LAYER(layer));
    }
    return tool->layer != NULL;
}
Пример #4
0
static void
gv_point_tool_button_press(GvTool *tool, GdkEventButton *event)
{
    if (event->button == 1)
    {
	GvVertex vertex;
	
	if (!gv_point_tool_configure(tool)) return;

	/* Get pointer location */
	gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
				 &vertex.x, &vertex.y);

        if( !gv_tool_check_bounds( GV_TOOL(tool), vertex.x, vertex.y ) )
            return;

	/* Add a new point */
        if( GV_IS_POINT_LAYER(GV_POINT_TOOL(tool)->layer) )
        {
            gv_point_layer_select_new_point(
                GV_POINT_LAYER(GV_POINT_TOOL(tool)->layer), 
                &vertex);
        }
        else
        {
            GvShape   *new_point;

            new_point = gv_shape_new( GVSHAPE_POINT );
            gv_shape_set_xyz( new_point, 0, 0, vertex.x, vertex.y, 0.0 );
            gv_shapes_layer_select_new_shape( 
                GV_SHAPES_LAYER(GV_POINT_TOOL(tool)->layer), 
                new_point );
        }
    }
}
Пример #5
0
static gboolean
gv_rect_tool_button_release(GvTool *r_tool, GdkEventButton *event)
{
    GvRectTool *tool = GV_RECT_TOOL(r_tool);

    if (event->button == 1 && tool->drawing )
    {
        GvShape *shape;

        if (!gv_rect_tool_configure(tool)) return FALSE;

        /* Map pointer position to tail vertex */
        gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
                                 &tool->v_tail.x, &tool->v_tail.y);

        gv_tool_clamp_to_bounds( GV_TOOL(tool),
                                 &tool->v_tail.x, &tool->v_tail.y );

        if( tool->v_tail.x != tool->v_head.x 
            && tool->v_tail.y != tool->v_head.y )
        {
            /* create the new rectangle */
            shape = gv_shape_new( GVSHAPE_AREA );

            gv_shape_add_node( shape, 0, tool->v_tail.x, tool->v_tail.y, 0 );
            gv_shape_add_node( shape, 0, tool->v_tail.x, tool->v_head.y, 0 );
            gv_shape_add_node( shape, 0, tool->v_head.x, tool->v_head.y, 0 );
            gv_shape_add_node( shape, 0, tool->v_head.x, tool->v_tail.y, 0 );
            gv_shape_add_node( shape, 0, tool->v_tail.x, tool->v_tail.y, 0 ); 

            gv_shapes_layer_select_new_shape( GV_SHAPES_LAYER(tool->layer), 
                                              shape );
        }

        tool->drawing = FALSE;
        return FALSE;
    }

    if (event->button == 1 && tool->reshaping )
    {
        if (!gv_rect_tool_configure(tool)) return FALSE;

        /* Reopen undo.  Push a memento describing the ring addition */
        gv_undo_enable();
        gv_undo_open();

        /* Map pointer position to tail vertex */
        gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
                                 &tool->v_tail.x, &tool->v_tail.y);
        gv_rect_tool_reshape( tool, tool->v_tail.x, tool->v_tail.y );

        tool->reshaping = FALSE;
    }
    return FALSE;
}
Пример #6
0
void
gv_rotate_tool_set_layer(GvRotateTool *tool, GvShapeLayer *layer)
{
    if (GV_TOOL(tool)->view == NULL)
    {
	g_warning("gv_rotate_tool_set_layer(): inactive tool");
	return;
    }

    if( layer != NULL && gv_data_is_read_only( GV_DATA(layer) ) )
    {
        g_warning( "gv_rotate_tool_set_layer(): layer is read-only" );
        return;
    }

    gv_rotate_tool_terminate( tool );
    tool->shape_id = -1;

    /* Disconnect from the previous layer (for draw) */
    if (tool->layer)
    {
        tool->rrmode = RRMODE_DISPLAY;

        /** TODO: Not sure that we need to unselect ... try to remove later */

	gv_shape_layer_clear_selection(GV_SHAPE_LAYER(tool->layer));
	gtk_signal_disconnect_by_data(GTK_OBJECT(tool->layer), (gpointer)tool);
	gv_view_area_queue_draw(GV_TOOL(tool)->view);
    }
 
    if( layer == NULL )
        tool->layer = NULL;
    else
        tool->layer = GV_SHAPES_LAYER(layer);

    if (layer)
    {
	gv_view_area_set_active_layer(GV_TOOL(tool)->view, GTK_OBJECT(layer));
	
        /* Redraw when the layer draws */
	gtk_signal_connect_object_after(GTK_OBJECT(layer), "draw",
					GTK_SIGNAL_FUNC(gv_rotate_tool_draw),
					GTK_OBJECT(tool));
        /* Recover if layer destroyed */
        gtk_signal_connect(
            GTK_OBJECT(layer), "destroy", 
            GTK_SIGNAL_FUNC(gv_rotate_tool_layer_destroy),
            GTK_OBJECT(tool));
    }
}
Пример #7
0
void 
gv_rotate_tool_terminate( GvRotateTool *tool )
{
    if( tool->rrmode == RRMODE_DISPLAY )
        return;

    if( tool->original != NULL 
        && gv_shapes_get_shape( tool->layer->data, tool->shape_id) != NULL )
    {
        gv_shapes_replace_shapes( tool->layer->data, 1, &(tool->shape_id), 
                                  &(tool->original), FALSE );
        tool->original = NULL;
        gv_undo_enable();
        gv_undo_open();
    }
    else if( tool->original != NULL )
    {
        gv_shape_delete( tool->original );
        tool->original = NULL;
        gv_undo_enable();
        gv_undo_open();
    }

    tool->shape_id = -1;
    tool->rrmode = RRMODE_DISPLAY;
    gv_view_area_queue_draw(GV_TOOL(tool)->view);
}
Пример #8
0
static void
gv_point_tool_init(GvPointTool *tool)
{
    GV_TOOL(tool)->cursor = gdk_cursor_new(GDK_TCROSS);
    tool->layer = NULL;
    tool->named_layer = NULL;
}
Пример #9
0
GvTool *
gv_rect_tool_new(void)
{
    GvRectTool *tool = g_object_new(GV_TYPE_RECT_TOOL, NULL);

    return GV_TOOL(tool);
}
Пример #10
0
void
gv_rect_tool_set_layer(GvRectTool *tool, GvShapeLayer *layer)
{
    if (GV_TOOL(tool)->view == NULL)
    {
        g_warning("gv_rect_tool_set_layer(): inactive tool");
        return;
    }

    if( layer != NULL && gv_data_is_read_only( GV_DATA(layer) ) )
    {
        g_warning( "gv_rect_tool_set_layer(): layer is read-only" );
        return;
    }

    /* Disconnect from the previous layer (for draw) */
    if (tool->layer)
    {
        if (tool->drawing)
            tool->drawing = FALSE;

        gv_shape_layer_clear_selection(GV_SHAPE_LAYER(tool->layer));
        g_signal_handlers_disconnect_matched (tool->layer, G_SIGNAL_MATCH_DATA,
                                                0, 0, NULL, NULL, tool);
        gv_view_area_queue_draw(GV_TOOL(tool)->view);
    }

    if( layer == NULL )
        tool->layer = NULL;
    else
        tool->layer = GV_SHAPES_LAYER(layer);

    if (layer)
    {
        gv_view_area_set_active_layer(GV_TOOL(tool)->view, G_OBJECT(layer));

        /* Redraw when the layer draws */
        g_signal_connect_object(layer, "draw",
                                G_CALLBACK(gv_rect_tool_draw),
                                GV_TOOL(tool), G_CONNECT_SWAPPED | G_CONNECT_AFTER);

        /* recover if layer destroyed */
        g_signal_connect_swapped(layer, "teardown",
                                G_CALLBACK(gv_rect_tool_layer_destroy),
                                tool);
    }
}
Пример #11
0
static void
gv_rect_tool_init(GvRectTool *tool)
{
    GV_TOOL(tool)->cursor = gdk_cursor_new(GDK_TCROSS);
    tool->layer = NULL;
    tool->named_layer = NULL;
    tool->drawing = FALSE;
}
Пример #12
0
static void 
gv_rect_tool_reshape( GvRectTool *r_tool, gvgeocoord x, gvgeocoord y )

{
    GvShape *shape;
    gvgeocoord   x1, y1, x2, y2;

    gv_tool_clamp_to_bounds( GV_TOOL(r_tool), &x, &y );

    shape = gv_shapes_get_shape( r_tool->layer->data, r_tool->shape_id );
    if( shape == NULL || gv_shape_get_nodes( shape, 0 ) != 5 )
        return;

    shape = gv_shape_copy( shape );

    x1 = gv_shape_get_x(shape,0,0);
    y1 = gv_shape_get_y(shape,0,0);
    x2 = gv_shape_get_x(shape,0,2);
    y2 = gv_shape_get_y(shape,0,2);

    if( r_tool->picked == PICK_SIDE_TOP )
        y1 = y;
    else if( r_tool->picked == PICK_SIDE_RIGHT )
        x2 = x;
    else if( r_tool->picked == PICK_SIDE_BOTTOM )
        y2 = y;
    else if( r_tool->picked == PICK_SIDE_LEFT )
        x1 = x;
    else if( r_tool->picked == PICK_CORNER_TOPLEFT )
    {
        x1 = x;
        y1 = y;
    }
    else if( r_tool->picked == PICK_CORNER_TOPRIGHT )
    {
        x2 = x;
        y1 = y;
    }
    else if( r_tool->picked == PICK_CORNER_BOTTOMRIGHT )
    {
        x2 = x;
        y2 = y;
    }
    else if( r_tool->picked == PICK_CORNER_BOTTOMLEFT )
    {
        x1 = x;
        y2 = y;
    }

    gv_shape_set_xyz( shape, 0, 0, x1, y1, 0 );
    gv_shape_set_xyz( shape, 0, 1, x1, y2, 0 );
    gv_shape_set_xyz( shape, 0, 2, x2, y2, 0 );
    gv_shape_set_xyz( shape, 0, 3, x2, y1, 0 );
    gv_shape_set_xyz( shape, 0, 4, x1, y1, 0 );

    gv_shapes_replace_shapes( r_tool->layer->data, 1, &(r_tool->shape_id),
                              &shape, FALSE );
}
Пример #13
0
void
gv_point_tool_set_layer(GvPointTool *tool, GvShapeLayer *layer)
{
    if (GV_TOOL(tool)->view == NULL)
    {
	g_warning("gv_point_tool_set_layer(): inactive tool");
	return;
    }

    if( layer != NULL 
        && !GV_IS_POINT_LAYER(layer) && !GV_IS_SHAPES_LAYER(layer) )
    {
        g_warning( "gv_point_tool_set_layer(): not a point capable layer" );
        return;
    }

    if( layer != NULL && gv_data_is_read_only( GV_DATA(layer) ) )
    {
        g_warning( "gv_point_tool_set_layer(): layer is read-only" );
        return;
    }

    /* Disconnect from the previous layer */
    if (tool->layer)
    {
	gv_shape_layer_clear_selection(GV_SHAPE_LAYER(tool->layer));
	gv_view_area_queue_draw(GV_TOOL(tool)->view);
        gtk_signal_disconnect_by_data( GTK_OBJECT(tool->layer), 
                                       GTK_OBJECT(tool) );
    }
    
    tool->layer = layer;

    if (layer)
    {
	gv_view_area_set_active_layer(GV_TOOL(tool)->view, GTK_OBJECT(layer));
        gtk_signal_connect(
            GTK_OBJECT(layer), "destroy", 
            GTK_SIGNAL_FUNC(gv_point_tool_layer_destroy),
            GTK_OBJECT(tool));
    }
}
Пример #14
0
static void
gv_rotate_tool_init(GvRotateTool *tool)
{
    GV_TOOL(tool)->cursor = gdk_cursor_new(GDK_TCROSS);
    tool->layer = NULL;
    tool->named_layer = NULL;
    tool->rrmode = RRMODE_DISPLAY;
    tool->shape_id = -1;
    tool->rotation = 0.0;
    tool->scaling = 1.0;
    tool->original = NULL;
}
Пример #15
0
static gint
gv_point_tool_configure(GvTool *r_tool)
{
    GvPointTool  *tool = GV_POINT_TOOL(r_tool);

    /* Check that we still are working on the active layer */
    if (!tool->layer ||	GTK_OBJECT(tool->layer) !=
	gv_view_area_active_layer(GV_TOOL(tool)->view))
    {
	GtkObject *layer;

	if (tool->named_layer)
	{
	    /* Look for named layer if given */
	    layer = gv_view_area_get_named_layer(GV_TOOL(tool)->view,
						 tool->named_layer);
	}
	else
	{
	    /* Attempt to find a point layer to edit */
	    layer = gv_view_area_get_layer_of_type(GV_TOOL(tool)->view,
						   GV_TYPE_POINT_LAYER,
                                                   FALSE);
            if(  layer == NULL )
                layer = gv_view_area_get_layer_of_type(GV_TOOL(tool)->view,
                                                       GV_TYPE_SHAPES_LAYER,
                                                       FALSE);
	}
	if (!layer)
	{
	    g_warning("gv_point_tool_configure(): no editable point layer in view");
	    return FALSE;
	}

	gv_point_tool_set_layer(tool, GV_SHAPE_LAYER(layer));
    }
    return tool->layer != NULL;
}
Пример #16
0
static gint gv_rotate_tool_setup_arrows( GvRotateTool *tool )

{
    GvVertex3d pivot_3d;
    GvShape *shape = gv_shapes_get_shape( tool->layer->data, 
                                          tool->shape_id );

    if( shape == NULL )
    {
        CPLDebug( "OpenEV", "gv_rotate_tool_setup_arrows(), shape==NULL!" );
        tool->shape_id = -1;
        return 0;
    }

/* -------------------------------------------------------------------- */
/*      Compute the pivot location.                                     */
/* -------------------------------------------------------------------- */
    if( !gv_shape_get_center( shape, &pivot_3d ) )
        return 0;

    tool->v_pivot.x = pivot_3d.x;
    tool->v_pivot.y = pivot_3d.y;

/* -------------------------------------------------------------------- */
/*      Compute the up vector.                                          */
/* -------------------------------------------------------------------- */
    gv_view_area_correct_for_transform( GV_TOOL(tool)->view, 0.0, 1.0, 
                                        &(tool->v_up.x),
                                        &(tool->v_up.y) );
    gv_view_area_correct_for_transform( GV_TOOL(tool)->view, 1.0, 0.0, 
                                        &(tool->v_right.x),
                                        &(tool->v_right.y) );

    tool->rotation = 0.0;
    tool->scaling = 1.0;

    return 1;
}
Пример #17
0
static void
gv_point_tool_key_press(GvTool *rtool, GdkEventKey *event)
{
    GvPointTool *tool = GV_POINT_TOOL(rtool);

    if (!gv_point_tool_configure(GV_TOOL(tool))) return;
    
    switch (event->keyval)
    {
	case GDK_Delete:
	case GDK_BackSpace:
	    /* Delete the currently selected lines (forces redraw) */
	    gv_shape_layer_delete_selected(tool->layer);
	    break;
    }
}
Пример #18
0
GvTool *
gv_point_tool_new(void)
{
    return GV_TOOL(gtk_type_new(GV_TYPE_POINT_TOOL));
}
Пример #19
0
static gboolean
gv_rect_tool_button_press(GvTool *r_tool, GdkEventButton *event)
{
    GvRectTool *tool = GV_RECT_TOOL(r_tool);

    if (event->button == 1 && !tool->drawing )
    {
        GvNodeInfo edit_node;
        int        before, shape_id, is_rectangle = FALSE;

        if (!gv_rect_tool_configure(tool)) return FALSE;

        if (gv_shape_layer_pick_shape(GV_SHAPE_LAYER(tool->layer), 
                                      GV_TOOL(tool)->view,
                                      event->x, event->y, &shape_id))
        {
            GvShape *shape;

            /* Is the shape a rectangle? */
            shape = gv_shapes_get_shape( tool->layer->data, shape_id );
            if( shape != NULL 
                && gv_shape_type(shape) == GVSHAPE_AREA
                && gv_shape_get_rings( shape ) == 1 
                && gv_shape_get_nodes( shape, 0 ) == 5 )
            {
                gvgeocoord   x1, y1, x2, y2;

                x1 = gv_shape_get_x(shape,0,0);
                y1 = gv_shape_get_y(shape,0,0);
                x2 = gv_shape_get_x(shape,0,2);
                y2 = gv_shape_get_y(shape,0,2);

                tool->winding = 1;
                is_rectangle = gv_shape_get_x(shape,0,1) == x1
                    && gv_shape_get_y(shape,0,1) == y2
                    && gv_shape_get_x(shape,0,3) == x2
                    && gv_shape_get_y(shape,0,3) == y1
                    && gv_shape_get_x(shape,0,4) == x1
                    && gv_shape_get_y(shape,0,4) == y1;

                if( !is_rectangle )
                {
                    tool->winding = 0;
                    is_rectangle = gv_shape_get_x(shape,0,1) == x2
                        && gv_shape_get_y(shape,0,1) == y1
                        && gv_shape_get_x(shape,0,3) == x1
                        && gv_shape_get_y(shape,0,3) == y2
                        && gv_shape_get_x(shape,0,4) == x1
                        && gv_shape_get_y(shape,0,4) == y1;
                }

                if( is_rectangle )
                {
                    gv_shape_layer_clear_selection(
                        GV_SHAPE_LAYER(tool->layer));
                    gv_shape_layer_select_shape(
                        GV_SHAPE_LAYER(tool->layer), shape_id);
                }
            }
        }

        /* Is the user selecting an existing rectangles edge/corner? */
        if (is_rectangle 
            && gv_shape_layer_pick_node(GV_SHAPE_LAYER(tool->layer), 
                                        GV_TOOL(tool)->view,
                                        event->x, event->y, &before,
                                        &edit_node) )
        {
            if( tool->winding == 0 )
            {
                if( before )
                    edit_node.node_id = 5 - edit_node.node_id;
                else
                    edit_node.node_id = 4 - edit_node.node_id;
            }

            if( before && edit_node.node_id == 1 )
                tool->picked = PICK_SIDE_LEFT;
            else if( before && edit_node.node_id == 2 )
                tool->picked = PICK_SIDE_BOTTOM;
            else if( before && edit_node.node_id == 3 )
                tool->picked = PICK_SIDE_RIGHT;
            else if( before && edit_node.node_id == 4 )
                tool->picked = PICK_SIDE_TOP;
            else if( edit_node.node_id == 0 )
                tool->picked = PICK_CORNER_TOPLEFT;
            else if( edit_node.node_id == 1 )
                tool->picked = PICK_CORNER_BOTTOMLEFT;
            else if( edit_node.node_id == 2 )
                tool->picked = PICK_CORNER_BOTTOMRIGHT;
            else if( edit_node.node_id == 3 )
                tool->picked = PICK_CORNER_TOPRIGHT;
            else if( edit_node.node_id == 4 )
                tool->picked = PICK_CORNER_TOPLEFT;
            else
            {
                g_warning( "Yikes!  What node is this?" );
                return FALSE;
            }

            tool->reshaping = TRUE;
            tool->shape_id = edit_node.shape_id;

            /* Close down undo.  A single operation describing the new
               ring will be pushed to undo when drawing stops. */
            gv_undo_close();
            gv_undo_disable();

            return FALSE;
        }

        /* Map pointer position to tail vertex */
        gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
                                 &tool->v_tail.x, &tool->v_tail.y);

        if( gv_tool_check_bounds( GV_TOOL(tool),
                                  tool->v_tail.x, tool->v_tail.y ) )
        {
            /* Start a new rect */
            tool->drawing = TRUE;
            tool->v_head = tool->v_tail;
        }
    }
    return FALSE;
}
Пример #20
0
static void
gv_rotate_tool_motion_notify(GvTool *r_tool, GdkEventMotion *event)
{
    GvRotateTool *tool = GV_ROTATE_TOOL(r_tool);
    GvShape  *wrk_shape;

    if (tool->rrmode == RRMODE_DISPLAY )
        return;


    wrk_shape = gv_shape_copy(tool->original);

    /* Map pointer position to tail vertex */
    gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
                             &tool->v_tail.x, &tool->v_tail.y);

    /* Compute rotation from base. */
    if( tool->rrmode == RRMODE_ROTATE 
        || tool->rrmode == RRMODE_ROTATESCALE )
    {
        double dx = tool->v_tail.x - tool->v_pivot.x;
        double dy = tool->v_tail.y - tool->v_pivot.y;

        if( fabs(dy) < fabs(dx)/1000000.0 )
            tool->rotation = M_PI/2;
        else
            tool->rotation = atan(fabs(dx/dy));


        if( dy < 0.0 && dx >= 0.0 )
            tool->rotation = M_PI - tool->rotation;
        else if( dy >= 0.0 && dx < 0.0 )
            tool->rotation = -tool->rotation;
        else if( dy < 0.0 && dx < 0.0 )
            tool->rotation -= M_PI;


        tool->rotation = (tool->rotation / M_PI) * 180;

        gv_shape_rotate( wrk_shape, tool->rotation );
    }

    /* Compute Scaling from base. */
    if( tool->rrmode == RRMODE_SCALE 
        || tool->rrmode == RRMODE_ROTATESCALE )
    {
        double dx, dy, old_length, new_length;

        dx = tool->v_tail.x - tool->v_pivot.x;
        dy = tool->v_tail.y - tool->v_pivot.y;
        new_length = sqrt(dx*dx + dy*dy);
        
        dx = tool->v_head.x - tool->v_pivot.x;
        dy = tool->v_head.y - tool->v_pivot.y;
        old_length = sqrt(dx*dx + dy*dy);

        tool->scaling = new_length / old_length;

        gv_shape_scale( wrk_shape, tool->scaling );
    }
    
    /* Apply to the shapes object ... this will create an undo step */
    gv_shapes_replace_shapes( tool->layer->data, 1, &(tool->shape_id), 
                              &wrk_shape, FALSE );

    gv_view_area_queue_draw(GV_TOOL(tool)->view);
}
Пример #21
0
static void
gv_rotate_tool_button_press(GvTool *r_tool, GdkEventButton *event)
{
    GvRotateTool *tool = GV_ROTATE_TOOL(r_tool);

    if( event->state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK) )
        return;

/* -------------------------------------------------------------------- */
/*      Have we selected an active control point on the scale/rotate    */
/*      dohickey?                                                       */
/* -------------------------------------------------------------------- */
    if( tool->rrmode == RRMODE_DISPLAY && tool->shape_id != -1 )
    {
	gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y,
				 &tool->v_head.x, &tool->v_head.y);

        /*
        ** Is this location a hit on an arrow head?
        */
        tool->rrmode = 
            gv_rotate_tool_classify_hit( tool, tool->v_head.x, tool->v_head.y );

        /*
        ** Copy the original state of this shape, and disable undo till we are
        ** done.
        */
        if( tool->rrmode != RRMODE_DISPLAY )
        {
            if( event->button != 1 )
                tool->rrmode = RRMODE_ROTATESCALE;

            tool->original = gv_shape_copy(
                gv_shapes_get_shape( tool->layer->data, tool->shape_id ));

            gv_undo_close();
            gv_undo_disable();
        }
    }

/* -------------------------------------------------------------------- */
/*      Are we selecting a shape?  Note, currently we cannot clear      */
/*      our selection in resize/rotate mode - should we be able to?     */
/* -------------------------------------------------------------------- */
    if (event->button == 1 && tool->rrmode == RRMODE_DISPLAY )
    {
        int        shape_id;

	if (!gv_rotate_tool_configure(tool)) return;

	if (gv_shape_layer_pick_shape(GV_SHAPE_LAYER(tool->layer), 
                                      GV_TOOL(tool)->view,
				      event->x, event->y, &shape_id))
        {
            GvShape *shape;

            /* Is the shape rotatable? */
            shape = gv_shapes_get_shape( tool->layer->data, shape_id );

            if( TRUE )
            {
                gv_shape_layer_clear_selection(
                    GV_SHAPE_LAYER(tool->layer));
                gv_shape_layer_select_shape(
                    GV_SHAPE_LAYER(tool->layer), shape_id);
                tool->shape_id = shape_id;
                gv_view_area_queue_draw(GV_TOOL(tool)->view);
            }
        }
        return;
    }

}
Пример #22
0
GvTool *
gv_rotate_tool_new(void)
{
    return GV_TOOL(gtk_type_new(GV_TYPE_ROTATE_TOOL));
}
Пример #23
0
int main(int argc, char **argv)
{
    GtkWidget *win;
    GtkWidget *twin;   // toolbar window
    GtkWidget *swin;

    const char *filename = NULL;

    //g_thread_init(NULL);
    //gdk_threads_init();
    gdk_threads_enter();

    gtk_init(&argc, &argv);


    printf("%s\n", S52_version());


    //printf("float: %.02f \n", 3.1416);  // 3.14
    //printf("float: %.2f \n", 3.1416);   // 3.14
    //printf("float: %.02f \n", 3.1);     // 3.10
    //printf("float: %.2f \n", 3.1);      // 3.10
    //printf("float: %.2f \n", 3.665);      // 3.67
    //printf("float: %.2f \n", 3.664);      // 3.66
    //return 1;


    filename = _option(argc, argv);
    _dumpSetUp();

    VecView = gv_view_area_new();
    if (NULL == VecView){
        printf("main.c:ERROR: VecView == NULL!!  no OpenGL .. exit!\n");
        exit(0);
    }

    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect(GTK_OBJECT(win), "destroy", GTK_SIGNAL_FUNC(_destroy), NULL);

    toolbox = GV_TOOLBOX(gv_toolbox_new());
    gv_toolbox_add_tool(toolbox, "select",  gv_selection_tool_new());
    gv_toolbox_add_tool(toolbox, "zoompan", gv_zoompan_tool_new());
    gv_toolbox_add_tool(toolbox, "point",   gv_point_tool_new());
    gv_toolbox_add_tool(toolbox, "line",    gv_line_tool_new());
    gv_toolbox_add_tool(toolbox, "area",    gv_area_tool_new());
    gv_toolbox_add_tool(toolbox, "node",    gv_node_tool_new());
    gv_toolbox_add_tool(toolbox, "roi",     gv_roi_tool_new());

    link = GV_VIEW_LINK(gv_view_link_new());


    gtk_window_set_default_size( GTK_WINDOW(win), 800, 600 );

    // 2D
    gv_view_area_set_mode(GV_VIEW_AREA(VecView), 0);
    gtk_drawing_area_size(GTK_DRAWING_AREA(VecView), 800, 600);

    swin = gtk_scrolled_window_new(NULL, NULL);

    gtk_container_add(GTK_CONTAINER(win), swin);
    gtk_container_add(GTK_CONTAINER(swin), VecView);


    //gv_view_area_add_layer(GV_VIEW_AREA(view), gv_shapes_layer_new(shapes));

    gtk_signal_connect_object(GTK_OBJECT(VecView), "key-press-event",
                              GTK_SIGNAL_FUNC(_key_press_cb),
                              GTK_OBJECT(VecView));

    gtk_widget_show(VecView);
    gtk_widget_show(swin);
    gtk_widget_show(win);
    gtk_widget_grab_focus(VecView);

    gtk_signal_connect(GTK_OBJECT(win), "delete-event", GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

    gtk_quit_add_destroy(1, GTK_OBJECT(win));

    gv_tool_activate(GV_TOOL(toolbox), GV_VIEW_AREA(VecView));
    gv_toolbox_activate_tool(toolbox, "zoompan" );


    twin = _create_toolbar();

    _loadCell(filename);

    gtk_main();

    gdk_threads_leave();

    // FIXME: do we ever get here!
    // put back env. var. as it was
    /*
    if (NULL != genv){
        setenv("OGR_S57_OPTIONS", genv->str, 1);
        g_string_free(genv, TRUE);
    }
    */
    printf("exit main()\n");


    return 0;
}