/******************************************************************************
 * $Id: gvogdihitviewer.cpp,v 1.1 1999/01/11 15:27:23 warmerda Exp $
 *
 * Name:     gvogdihitviewer.cpp
 * Project:  GDAL Qt Viewer
 * Purpose:  Implements OGDI Hit Viewer.
 * Author:   Frank Warmerdam, warmerda@home.com
 *
 ******************************************************************************
 * Copyright (c) 1999, Frank Warmerdam
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *****************************************************************************
 *
 * $Log: gvogdihitviewer.cpp,v $
 * Revision 1.1  1999/01/11 15:27:23  warmerda
 * New
 *
 */

#include "gvogdihitviewer.h"

#ifdef OGDI_ENABLED
#  include "ecs.h"
#endif

/************************************************************************/
/*                            GVOGDIHitViewer()                         */
/************************************************************************/

GVOGDIHitViewer::GVOGDIHitViewer( GVCanvas * poCanvasIn,
                                  QWidget *poParent, const char * pszName )
        : QWidget( poParent, pszName )

{
    GVRaster	*poRaster;
    
    poCanvas = poCanvasIn;
    
    resize( 400, 30 );

    poRaster = poCanvas->GetGVRaster();
    if( poRaster == NULL )
        return;

    if( poRaster->GetDS() == NULL )
        return;

    nClientID = (int) (long) GDALGetInternalHandle(poRaster->GetDS(),
                                                   "ClientID");
   
    connect( poCanvas, SIGNAL(geoPosChanged(GVGeoPoint)),
             this, SLOT(DisplayHit(GVGeoPoint)) );

    setCaption( "OGDI Hit Info" );
    
    show();
}

/************************************************************************/
/*                           ~GVOGDIHitViewer()                            */
/************************************************************************/

GVOGDIHitViewer::~GVOGDIHitViewer()

{
}


/************************************************************************/
/*                             DisplayHit()                             */
/************************************************************************/

void GVOGDIHitViewer::DisplayHit( GVGeoPoint oNewHit )

{
    QString	oString;

#ifdef OGDI_ENABLED
    ecs_Result	*psResult;
    ecs_Coordinate sCoord;

    sCoord.x = oNewHit.dfGeoX;
    sCoord.y = oNewHit.dfGeoY;

    psResult = cln_GetObjectIdFromCoord( nClientID, &sCoord );
    if( ECSERROR(psResult) )
        return;

    oString.sprintf( "%s", ECSTEXT(psResult) );
#endif

    erase();
    drawText( height() - 1, 10, oString );
}

/************************************************************************/
/*                        LaunchOGDIHitViewer()                         */
/************************************************************************/

QWidget *LaunchOGDIHitViewer( GVCanvas * poCanvas )

{
    return new GVOGDIHitViewer( poCanvas, NULL, "OGDIHitViewer" );
}
