ImporterShell.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef IMPORTERSHELL_H
00011 #define IMPORTERSHELL_H
00012 
00013 #include "EnumWrapper.h"
00014 #include "ExecutableShell.h"
00015 #include "Importer.h"
00016 
00017 #include <string>
00018 
00019 /**
00020  *  \ingroup ShellModule
00021  *  %Importer Shell
00022  *
00023  *  This class represents the shell for an importer plug-in.  %Importer
00024  *  developers would take this class and extend it to support thier 
00025  *  importer specific code.
00026  *
00027  *  @see     ExecutableShell, Importer
00028  */
00029 class ImporterShell : public ExecutableShell, public Importer
00030 {
00031 public:
00032    /**
00033     *  Creates an importer plug-in.
00034     *
00035     *  The constructor sets the plug-in type to PlugInManagerServices::ImporterType().
00036     *
00037     *  @see     getType()
00038     */
00039    ImporterShell();
00040 
00041    /**
00042     *  Destroys the importer plug-in.
00043     */
00044    virtual ~ImporterShell();
00045 
00046    /**
00047     *  @copydoc Importer::getDefaultExtensions()
00048     *
00049     *  @default The default implementation returns the extension string that
00050     *           was passed into setExtensions().  If setExtensions() has not
00051     *           yet been called, an empty string is returned.
00052     */
00053    virtual std::string getDefaultExtensions() const;
00054 
00055    /**
00056     *  @copydoc Importer::isProcessingLocationSupported()
00057     *
00058     *  @default Only a processing location of ProcessingLocation::IN_MEMORY is
00059     *           supported.  If \em location is ProcessingLocation::IN_MEMORY,
00060     *           the default implementation returns \b true, otherwise \b false
00061     *           is returned.
00062     */
00063    virtual bool isProcessingLocationSupported(ProcessingLocation location) const;
00064 
00065    /**
00066     *  @copydoc Importer::getPreview()
00067     *
00068     *  @default The default implementation of this method does not create a
00069     *           preview and returns \b NULL.
00070     */
00071    virtual QWidget* getPreview(const DataDescriptor* pDescriptor, Progress* pProgress);
00072 
00073    /**
00074     *  @copydoc Importer::validate()
00075     *
00076     *  @default The default implementation calls getValidationTest() to get the
00077     *           tests that should be used to validate the data set and then
00078     *           performs each of the tests specified.
00079     *
00080     *  @warning This method should not be called from within execute() because
00081     *           one or more of the tests (e.g.
00082     *           \link ImporterShell::NO_EXISTING_DATA_ELEMENT
00083     *           NO_EXISTING_DATA_ELEMENT\endlink) may fail since the import
00084     *           process has already started.
00085     */
00086    virtual bool validate(const DataDescriptor* pDescriptor, std::string& errorMessage) const;
00087 
00088    /**
00089     *  @copydoc Importer::getImportOptionsWidget()
00090     *
00091     *  @default The default implementation returns \b NULL.
00092     */
00093    virtual QWidget* getImportOptionsWidget(DataDescriptor* pDescriptor);
00094 
00095    /**
00096     *  @copydoc Importer::polishDataDescriptor()
00097     *
00098     *  @default The default implementation does nothing.
00099     */
00100    virtual void polishDataDescriptor(DataDescriptor* pDescriptor);
00101 
00102 protected:
00103    /**
00104     *  Sets the default file extensions recognized by the importer.
00105     *
00106     *  @param   extensions
00107     *           The file extensions recognized by the importer.  The string
00108     *           should consist of a description followed by one or more
00109     *           extensions separated by a space.  Multiple file types may
00110     *           be specified with a double semicolon.  Examples include
00111     *           "ENVI Header Files (*.hdr)", "TIFF Files (*.tif *.tiff)",
00112     *           and "Source Files (*.c*);;Header Files (*.h)".
00113     */
00114    void setExtensions(const std::string& extensions);
00115 
00116    /**
00117     *  Identifies the test that should be performed to validate the import.
00118     *
00119     *  @see     validate(), getValidationTest(), getValidationError()
00120     */
00121    enum ValidationTestEnum
00122    {
00123       NO_VALIDATION = 0x00000000,             /**< 0x00000000 - No validation is performed. */
00124       EXISTING_FILE = 0x00000001,             /**< 0x00000001 - Checks that the filename contained in the file
00125                                                    descriptor is a valid file that exists on the disk. */
00126       NO_EXISTING_DATA_ELEMENT = 0x00000002,  /**< 0x00000002 - Checks that an existing DataElement does not already
00127                                                    exist by calling ModelServices::getElement(). */
00128       VALID_CLASSIFICATION = 0x00000004,      /**< 0x00000004 - Checks for the existence of classification markings by
00129                                                    checking the return value of DataDescriptor::getClassification() for
00130                                                    a non-\c NULL pointer.\   Also reports a warning if the
00131                                                    classification level of the data being imported is greater than the
00132                                                    overall classification level of the system. */
00133       VALID_METADATA = 0x00000008,            /**< 0x00000008 - Checks for the existence of metadata by checking the
00134                                                    return value of DataDescriptor::getMetadata() for a non-\c NULL
00135                                                    pointer. */
00136       VALID_PROCESSING_LOCATION = 0x00000010, /**< 0x00000010 - Checks that the processing location set in the data
00137                                                    descriptor is valid by calling isProcessingLocationSupported(). */
00138       RASTER_SIZE = 0x00000020,               /**< 0x00000020 - Checks for at least one data pixel by checking for a
00139                                                    non-zero number of rows, columns, bands, and bits per element. */
00140       VALID_DATA_TYPE = 0x00000040,           /**< 0x00000040 - Checks that the data type set in the raster data
00141                                                    descriptor is one of the valid data types returned by
00142                                                    RasterDataDescriptor::getValidDataTypes(). */
00143       NO_HEADER_BYTES = 0x00000080,           /**< 0x00000080 - Checks for no header bytes set on the raster file
00144                                                    descriptor. */
00145       NO_PRE_POST_LINE_BYTES = 0x00000100,    /**< 0x00000100 - Checks for no preline or postline bytes set on the
00146                                                    raster file descriptor. */
00147       NO_PRE_POST_BAND_BYTES = 0x00000200,    /**< 0x00000200 - Checks for no preband or postband bytes set on the
00148                                                    raster file descriptor. */
00149       NO_TRAILER_BYTES = 0x00000400,          /**< 0x00000400 - Checks for no trailer bytes set on the raster file
00150                                                    descriptor. */
00151       FILE_SIZE = 0x00000800 | EXISTING_FILE, /**< 0x00000800 - Checks that the size of the file set in the raster file
00152                                                    descriptor (in bytes) is greater than or equal to required file size
00153                                                    determined by calling RasterUtilities::calculateFileSize(). */
00154       NO_BAND_FILES = 0x00001000,             /**< 0x00001000 - Checks that the number of band files is zero.\   Should
00155                                                    not be combined with \em EXISTING_BAND_FILES. */
00156       EXISTING_BAND_FILES = 0x00002000,       /**< 0x00002000 - Checks that number of band files is equal to the number
00157                                                    of bands in the raster file descriptor and that each of the band
00158                                                    files exists on the disk.\   Should not be combined with
00159                                                    \em NO_BAND_FILES. */
00160       BAND_FILE_SIZES = 0x00004000 | EXISTING_BAND_FILES, /**< 0x00004000 - Checks that the size of each band file (in
00161                                                    bytes) is greater than or equal to the required file size determined
00162                                                    by calling RasterUtilities::calculateFileSize(). */
00163       VALID_BAND_NAMES = 0x00008000 | VALID_METADATA, /**< 0x00008000 | \em VALID_METADATA - Checks that the number of
00164                                                    band names set in the metadata is equal to the number of bands in
00165                                                    the raster file descriptor.\   This test will succeed if band names
00166                                                    are not present in the metadata. */
00167       VALID_WAVELENGTHS = 0x00010000 | VALID_METADATA, /**< 0x00010000 | \em VALID_METADATA - Checks that the number of
00168                                                    wavelengths set in the metadata is equal to the number of bands in
00169                                                    the raster file descriptor by calling
00170                                                    Wavelengths::getNumWavelengths().\   This test will succeed if
00171                                                    wavelengths are not present in the metadata. */
00172       NO_INTERLEAVE_CONVERSIONS = 0x00020000, /**< 0x00020000 - Checks that the interleave format in the raster data
00173                                                    descriptor matches the interleave format in the raster file
00174                                                    descriptor.\   No check is performed if
00175                                                    RasterFileDescriptor::getBandCount() returns 1. */
00176       NO_ROW_SKIP_FACTOR = 0x00040000,        /**< 0x00040000 - Checks for no skip factor in the raster data descriptor
00177                                                    rows by calling RasterDataDescriptor::getRowSkipFactor(). */
00178       NO_COLUMN_SKIP_FACTOR = 0x00080000,     /**< 0x00080000 - Checks for no skip factor in the raster data descriptor
00179                                                    columns by calling RasterDataDescriptor::getColumnSkipFactor(). */
00180       NO_SKIP_FACTORS = NO_ROW_SKIP_FACTOR | NO_COLUMN_SKIP_FACTOR, /**< \em NO_ROW_SKIP_FACTOR |
00181                                                    \em NO_COLUMN_SKIP_FACTOR - Convenience value that performs both
00182                                                    \em NO_ROW_SKIP_FACTOR and \em NO_COLUMN_SKIP_FACTOR checks. */
00183       NO_ROW_SUBSETS = 0x00100000,            /**< 0x00100000 - Checks that the number of rows to import in the raster
00184                                                    data descriptor matches the number of rows in the raster file
00185                                                    descriptor. */
00186       NO_COLUMN_SUBSETS = 0x00200000,         /**< 0x00200000 - Checks that the number of columns to import in the
00187                                                    raster data descriptor matches the number of columns in the raster
00188                                                    file descriptor. */
00189       NO_BAND_SUBSETS = 0x00400000,           /**< 0x00400000 - Checks that the number of bands to import in the raster
00190                                                    data descriptor matches the number of bands in the raster file
00191                                                    descriptor. */
00192       NO_SUBSETS = NO_ROW_SUBSETS | NO_COLUMN_SUBSETS | NO_BAND_SUBSETS, /**< \em NO_ROW_SUBSETS |
00193                                                    \em NO_COLUMN_SUBSETS | \em NO_BAND_SUBSETS - Convenience value that
00194                                                    performs all \em NO_ROW_SUBSETS, \em NO_COLUMN_SUBSETS, and
00195                                                    \em NO_BAND_SUBSETS checks. */
00196       AVAILABLE_MEMORY = 0x00800000           /**< 0x00800000 - Checks that the amount of required memory calculated
00197                                                    from the rows, columns, bands, and bytes per element set in the
00198                                                    raster data descriptor can be successfully allocated. */
00199    };
00200 
00201    /**
00202     *  @EnumWrapper  ImporterShell::ValidationTestEnum.
00203     */
00204    typedef EnumWrapper<ValidationTestEnum> ValidationTest;
00205 
00206    /**
00207     *  Returns the test that should be performed when validating the given data
00208     *  set for import.
00209     *
00210     *  This method is called by validate() to determine which tests should be
00211     *  performed to validate the import.  This method should be overridden by
00212     *  derived importers to add additional tests or remove default tests.
00213     *
00214     *  @param   pDescriptor
00215     *           The data descriptor for the data set that is being imported.
00216     *
00217     *  @return  Returns the test that should be used to validate the import.
00218     *           The value should be an OR'd combination of
00219     *           \link ImporterShell::ValidationTest ValidationTest \endlink
00220     *           values.
00221     *
00222     *  @default The default implementation of this method returns the OR'd
00223     *           combination of the following tests:
00224     *           - \link ImporterShell::EXISTING_FILE EXISTING_FILE \endlink
00225     *           - \link ImporterShell::NO_EXISTING_DATA_ELEMENT NO_EXISTING_DATA_ELEMENT \endlink
00226     *           - \link ImporterShell::VALID_PROCESSING_LOCATION VALID_PROCESSING_LOCATION \endlink
00227     */
00228    virtual int getValidationTest(const DataDescriptor* pDescriptor) const;
00229 
00230    /**
00231     *  Returns the test that failed during the last call to validate().
00232     *
00233     *  This method can be called by importers from within an override of the
00234     *  default implementation of validate() to determine which test failed the
00235     *  validation process while calling the base class ImporterShell::validate()
00236     *  method.  This allows the importer to report custom error messages or
00237     *  to continue importing by converting an error to a warning and changing
00238     *  the validate() return value to \c true.
00239     *
00240     *  This method should not be called for importers that do not call this
00241     *  base class implementation.
00242     *
00243     *  @return  Returns the validation test that failed during the last call to
00244     *           ImporterShell::validate().  If this base class method has not
00245     *           been called or returned \c true, then an invalid value is
00246     *           returned.  An invalid value is also returned if the data
00247     *           descriptor passed into validate() or its file descriptor are
00248     *           \c NULL.
00249     */
00250    ValidationTest getValidationError() const;
00251 
00252 private:
00253    std::string mExtension;
00254    mutable ValidationTest mValidationError;
00255 };
00256 
00257 #endif

Software Development Kit - Opticks 4.9.0 Build 16218