package org.mbari.seepsearch.tools;

import java.io.*;

import org.mbari.seepsearch.grid.*;
import java.awt.*;
import java.io.*;

import javax.swing.*;

import org.mbari.swing.*;

/**
 * <p>Adds a reference to a <code>RasterGrid</code> to processes that act on
 * all the ROV navigation files.</p>
 *
 * <p>The Seep Search project is a sub-project of the Continental
 * Margin Fluids and Gases project (200010). It involves the analysis of
 * archived ROV data to obtain understanding of seep distritution in Monterey
 * Bay.</p>
 *
 * <p>The Purpose of this Java package is to intercompare ROV Navigation files,
 * VIMS data on seep community observations and the EM-300 bathymetry. We are
 * looking for locations where the ROV navigation files and the EM-300 data
 * have similar depths between the 2 data sets, which implies that the ROV is
 * observing the sea floor.</p><hr><br>
 *
 * <p>MBARI provides this documentation and code &quot;as is&quot;, with no
 * warranty, express or implied, of its quality or consistency. It is provided
 * without support and without obligation on the part of the Monterey Bay
 * Aquarium Research Institute to assist in its use, correction, modification,
 * or enhancement. This information should not be published or distributed to
 * third parties without specific written permission from MBARI.</p><br>
 *
 * Copyright 2002 MBARI.<br>
 * MBARI Proprietary Information. All rights reserved.<br><hr><br>
 *
 * $Log: RovBathymetryProcess.java,v $
 * Revision 1.1  2002/02/25 16:40:09  brian
 * Modified tools to ignore eastings and northings columns.
 *
 * Revision 1.2  2002/02/09 00:07:19  brian
 * Working tools to calculate ROV altitude. There's a glitch that occurs for a few files. Need to look into this
 *<br><hr><br>
 *
 * @author  : $Author: brian $
 * @version : $Revision: 1.1 $
 */
public abstract class RovBathymetryProcess extends RovNavFileProcess {

    /**
     * Constructor that specifies the root of the ROV data path
     * @param rovDataPath
     */
    public RovBathymetryProcess(String rovDataPath, String gridFilename) throws
        IOException, GridException {
        super(rovDataPath);
        setAsciiBathymetryGrid(gridFilename);
    }

    /**
     * Sets the grid to be used for processing the internal data.
     * @param asciiBathymetryGrid Name of the Ascii Raster Grid file.
     * @throws GridException
     * @throws IOException
     */
    public void setAsciiBathymetryGrid(String asciiBathymetryGrid) throws
            GridException, IOException {

        // Give the user some feedback
        progressBar.setStringPainted(true);
        progressBar.setMinimum(0);
        progressBar.setMaximum(1);
        progressBar.setValue(0);
        progressFrame.pack();
        progressBar.setString("Reading grid " + asciiBathymetryGrid);
        progressFrame.setVisible(true);
        Dimension d = progressBar.getSize();
        Rectangle rect = new Rectangle(0, 0, d.width, d.height);
        progressBar.paintImmediately(rect);

        // Read the grid file
        //reader = new AsciiNullGridReader(asciiBathymetryGrid);
        reader = new AsciiRasterGridReader(asciiBathymetryGrid);
        reader.read();

        // Close down the progressbar
        progressBar.setString("Completed");
        progressBar.setValue(1);
        progressBar.paintImmediately(rect);
        progressFrame.setVisible(false);

    }

    /**
     *
     * @return The grid used for processing. <b>null</b> if none is specified.
     */
    public String getAsciiBathymetryGrid() {
        return (reader != null) ? reader.getFile().getAbsolutePath() : null;
    }

    /**
     * Access to the UTM zone.
     * @return The UTM zone of the grid
     */
    public int getUtmZone() {
        return utmZone;
    }

    /**
     * Access tot he UTM zone. The grid is treated if UTM only if
     * <code>setUtm(<b>true</b>)</code> is called.
     * @param utmZone The utm zone of the bathymetry grid. The defualt is zone 10.
     */
    public void setUtmZone(int utmZone) {
        this.utmZone = utmZone;
    }

    /**
     * Specify if the bathymetry grid is in utm. If this is set to true, also set
     * the UTM zone with <i>setUtmZone</i>. The default UTM zone is 10
     * @param utm
     */
    public void setUtm(boolean utm) {
        this.utm = utm;
    }

    /**
     * Is the bathymetry grid in UTM a utm projection.
     * @return True if the batymetry grid is utm
     */
    public boolean isUtm() {
        return utm;
    }

    /**
     * The reader used to inject the RasterGrid file.
     */
    protected AsciiRasterGridReader reader;

    /**
     * The UTM zone of the cooridnate frame of the <code>RasterGrid</code>
     */
    private int utmZone = 10;

    /**
     * Is the grid in UTM coordinates? true = utm, false = geographic
     */
    private boolean utm = false;
}