コード例 #1
0
ファイル: gvpointtool.c プロジェクト: Onjrew/OpenEV
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 );
        }
    }
}
コード例 #2
0
ファイル: gvrecttool.c プロジェクト: midendian/openev2
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;
}
コード例 #3
0
ファイル: gvsymbolmanager.c プロジェクト: Onjrew/OpenEV
GvSymbolObj *
gv_symbol_manager_get_symbol(GvSymbolManager *manager, const char *symbol_name)
{
    gchar   *pszOpenEVHome = NULL;
    gchar   *pszSymbolsDir = NULL;
    gchar   *pszAbsolutePath = NULL;
    gchar   *pszPathSeparator = NULL;
    GDALDatasetH hDataset;
    GvSymbolObj *poSymbol;
    CPLXMLNode  *xml_shape = NULL;
    GByte *rgba_buffer;

/* -------------------------------------------------------------------- */
/*      Lookup the symbol in the hash table, and return it if found.    */
/* -------------------------------------------------------------------- */
    poSymbol = g_hash_table_lookup( manager->symbol_cache, symbol_name );
    if( poSymbol != NULL )
        return poSymbol;

/* -------------------------------------------------------------------- */
/*      We didn't already have it, so try to find a file to load it     */
/*      from.                                                           */
/* -------------------------------------------------------------------- */
#ifndef WIN32
    pszPathSeparator = "/";
#else
    pszPathSeparator = "\\";
#endif /* WIN32 */

    /* validate inputs */
    g_return_val_if_fail( manager != NULL, 0 );
    g_return_val_if_fail( symbol_name != NULL, 0 );

    /* get an absolute path */
    if ( !g_path_is_absolute( symbol_name ) )
    {
        /* check configuration option first */
        pszSymbolsDir = g_strdup( gv_manager_get_preference( gv_get_manager(),
                                                             "symbols_dir" ) );

        /* if not configured check $OPENEV_HOME */
        if ( !pszSymbolsDir )
        {
            pszOpenEVHome = g_getenv( "OPENEV_HOME" );
            if( pszOpenEVHome == NULL )
                pszOpenEVHome = g_getenv( "OPENEVHOME" );
            if ( pszOpenEVHome )
                pszSymbolsDir = g_strjoin( pszPathSeparator, pszOpenEVHome,
                                           "symbols", NULL );
        }
        
        /* get current directory as last resort */
        if ( !pszSymbolsDir )
            pszSymbolsDir = g_get_current_dir();

        pszAbsolutePath = g_strjoin( pszPathSeparator, pszSymbolsDir, 
                                     symbol_name, NULL );
        g_free( pszSymbolsDir );
    }
    else
        pszAbsolutePath = g_strdup( symbol_name );

/* -------------------------------------------------------------------- */
/*      pszAbsolutePath contains a newly allocated string that is       */
/*      suitable for using as a key in the hash table.  If a texture    */
/*      is found in the hash table then this string needs to be         */
/*      freed.  If one isn't found then the string is used in the       */
/*      hash table and should be freed when the associated hash         */
/*      table entry is released                                         */
/* -------------------------------------------------------------------- */
    CPLDebug( "OpenEV", 
              "gv_symbol_manager_get_symbol(%s) ... need to load.", 
                  pszAbsolutePath );
    
    /* 
     * validate path by opening with GDAL and looking for an error 
     * Disable CPL error handler to supress error reporting
     */
    
    CPLErrorReset();
    CPLPushErrorHandler( CPLQuietErrorHandler );
    hDataset = GDALOpen( pszAbsolutePath, GA_ReadOnly );
    CPLPopErrorHandler();
    
    if ( hDataset )
    {
        rgba_buffer = gdal_to_rgba( hDataset );
        
        if ( rgba_buffer )
        {
            gv_symbol_manager_inject_raster_symbol( 
                manager, symbol_name,
                GDALGetRasterXSize( hDataset ),
                GDALGetRasterYSize( hDataset ),
                rgba_buffer );
            CPLFree( rgba_buffer );
        }
        
        GDALClose( hDataset );
    }
    /* probably we have vector symbol? */
    else if ( ( xml_shape = CPLParseXMLFile( pszAbsolutePath ) ) )
    {
        GvShape     *shape;
        shape = gv_shape_from_xml_tree( xml_shape );
        
        CPLDestroyXMLNode( xml_shape );
        
        if( shape != NULL )
            gv_symbol_manager_inject_vector_symbol( manager, symbol_name,
                                                    shape );
        else
        {
            CPLDebug( "OpenEV", 
                      "Failed to instantiate GvSahpe from file %s, using simple point.", 
                      pszAbsolutePath );
        
            shape = gv_shape_new( GVSHAPE_POINT );
            gv_symbol_manager_inject_vector_symbol( manager, symbol_name,
                                                    shape );
        }
    }
    else
    {
        GvShape *shape;

        CPLDebug( "OpenEV", "Failed to open file %s, using simple point.", 
                  pszAbsolutePath );
        
        shape = gv_shape_new( GVSHAPE_POINT );
        gv_symbol_manager_inject_vector_symbol( manager, symbol_name,
                                                shape );
    }
    
    /* look up in the hash table again */
    poSymbol = g_hash_table_lookup(manager->symbol_cache, symbol_name );

    g_free( pszAbsolutePath );

    return poSymbol;
}