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 IMPORTER_H 00011 #define IMPORTER_H 00012 00013 #include "TypesFile.h" 00014 00015 #include <string> 00016 #include <vector> 00017 00018 class DataDescriptor; 00019 class ImportDescriptor; 00020 class Progress; 00021 class QWidget; 00022 00023 /** 00024 * Interface specific to importer plug-ins. 00025 * 00026 * Defines the importer specific interface to all importer plug-ins. 00027 * This interface contains all importer specific operations. 00028 */ 00029 class Importer 00030 { 00031 public: 00032 /** 00033 * The name for an import element argument. 00034 * 00035 * Input arguments with this name will be automatically populated with the 00036 * created DataElement whose data should be populated by the importer when 00037 * the plug-in is executed with an ImportAgent. Arguments with this name 00038 * should be of the type DataElement or one of its subclasses. 00039 * 00040 * @see ImportAgent::execute() 00041 */ 00042 static std::string ImportElementArg() { return "Import Element"; } 00043 00044 /** 00045 * Returns the default file extensions recognized by the importer. 00046 * 00047 * @return The file extensions recognized by the importer as a string. 00048 * The string consists of a description followed by one or more 00049 * file extensions separated by a space. Multiple file 00050 * types may be specified with a double semicolon. Examples 00051 * include "ENVI Header Files (*.hdr)", "TIFF Files (*.tif *.tiff)", 00052 * and "Source Files (*.c*);;Header Files (*.h)". 00053 */ 00054 virtual std::string getDefaultExtensions() const = 0; 00055 00056 /** 00057 * Queries whether the user can select the given processing location. 00058 * 00059 * @param location 00060 * The processing location being queried to determine if it 00061 * is supported. 00062 * 00063 * @return Returns \b true if the user can select the given processing 00064 * location, otherwise returns \b false. 00065 * 00066 * @see ProcessingLocation 00067 */ 00068 virtual bool isProcessingLocationSupported(ProcessingLocation location) const = 0; 00069 00070 /** 00071 * Returns import descriptors for each valid data element in a given file. 00072 * 00073 * This method is called for the importer to parse a given file and create 00074 * valid import descriptors for each data element in the file that can be 00075 * used to import the data. The import descriptor objects can be created 00076 * by calling ModelServices::createImportDescriptor(). 00077 * 00078 * @param filename 00079 * Full path and name of the file to parse for data elements to 00080 * import. 00081 * 00082 * @return A vector containing valid import descriptors for each data 00083 * element in the file. An empty vector should be returned if the 00084 * importer does not support the data in the given file. 00085 * 00086 * @see ImportDescriptor 00087 */ 00088 virtual std::vector<ImportDescriptor*> getImportDescriptors(const std::string& filename) = 0; 00089 00090 /** 00091 * Returns a value indicating if this importer can load this file and how well 00092 * it can load this file. The Importer should look at as little of the file 00093 * as required as quickly as possible when determining the affinity. 00094 * 00095 * @param filename 00096 * Full path and name of the file. 00097 * 00098 * @return The value returned should be one of the following: 00099 * <ul> 00100 * <li>Importer::CAN_NOT_LOAD</li> 00101 * <li>Importer::CAN_LOAD_WITH_USER_INPUT</li> 00102 * <li>Importer::CAN_LOAD_FILE_TYPE</li> 00103 * <li>Importer::CAN_LOAD</li> 00104 * </ul> 00105 * It can be any unsigned char value if a specific 00106 * Importer requires more granularity. 00107 */ 00108 virtual unsigned char getFileAffinity(const std::string& filename) = 0; 00109 00110 /** 00111 * When an importer returns this value from getFileAffinity() 00112 * it means the importer can not load any data from the given file. 00113 */ 00114 static const unsigned char CAN_NOT_LOAD = 0; 00115 00116 /** 00117 * When an importer returns this value from getFileAffinity() 00118 * it means the importer may be able to load data from the file if 00119 * provided additional user input. The given Importer should return 00120 * a non-empty vector of a single default constructed Data Descriptor from 00121 * getImportDescriptors() if given the same filename. For example, 00122 * the "Generic Importer" will load raw data from any file as long as 00123 * it formatted BIP, BSQ, or BIL, but will still require additional 00124 * information from the user. 00125 */ 00126 static const unsigned char CAN_LOAD_WITH_USER_INPUT = 64; 00127 00128 /** 00129 * When an importer returns this value from getFileAffinity() 00130 * it means the importer may be able to load data from the file if 00131 * provided additional user input. The given Importer should return 00132 * a non-empty vector of DataDescriptors that are partially completed 00133 * from getImportDescriptors() if given the same filename that 00134 * will require additional user input. For example, the "Generic Hdf5 00135 * Importer" will locate all data within a Hdf5 file it could possibly 00136 * load and return DataDescriptors for each, but will still require 00137 * additional information from the user. 00138 */ 00139 static const unsigned char CAN_LOAD_FILE_TYPE = 128; 00140 00141 /** 00142 * When an importer returns this value from getFileAffinity() 00143 * it means the importer can load data from the given file and the Importer 00144 * will return a non-empty vector from getImportDescriptors() if 00145 * given the same filename. 00146 * 00147 * An importer can return a value greater than Importer::CAN_LOAD 00148 * if it wishes to override a particular importer. For example, 00149 * a specialized NITF importer may know details of how to load 00150 * NITF files from a particular source. 00151 */ 00152 static const unsigned char CAN_LOAD = 192; 00153 00154 /** 00155 * Returns a preview of a given data set. 00156 * 00157 * This method provides the means by which the user can preview a data set 00158 * before importing. Derived importers can override this method to create 00159 * a Qt widget displaying preview contents. 00160 * 00161 * This method is called by the core when the user views a preview of a 00162 * data set before importing. The core application assumes ownership of 00163 * the Qt widget, so the importer should not delete it. A View object can 00164 * also be created for the preview, where the returned value should be 00165 * View::getWidget(). 00166 * 00167 * @param pDescriptor 00168 * The data set to preview. 00169 * @param pProgress 00170 * A progress object in which the importer can report progress 00171 * while getting the preview. 00172 * 00173 * @return A pointer to a Qt widget containing the preview contents that 00174 * will be displayed to the user. The core application assumes 00175 * ownership of the widget and will delete it when necessary. 00176 * \b NULL is returned if no preview is available for the given 00177 * data set. 00178 */ 00179 virtual QWidget* getPreview(const DataDescriptor* pDescriptor, Progress* pProgress) = 0; 00180 00181 /** 00182 * Queries whether a given data descriptor can be successfully loaded by 00183 * the importer. 00184 * 00185 * This method is called for the importer to parse the current settings in 00186 * the data descriptor to see if it supports loading the data as currently 00187 * specified in the data descriptor. This allows importers that do not 00188 * support certain combinations of values to indicate as such. This method 00189 * is called each time the user changes a value in the import options 00190 * dialog. This method is also called by ImportAgent::execute() before 00191 * executing the importer. 00192 * 00193 * @param pDescriptor 00194 * The data descriptor to query if it can be successfully 00195 * imported. 00196 * @param errorMessage 00197 * An error message that is populated with the reason why the 00198 * importer cannot load the given data descriptor. This message 00199 * will be displayed to the user via the importer's Progress 00200 * object. If this method returns \c true, this message will be 00201 * displayed to the user as a warning. If this method returns 00202 * \c false, this message will be displayed to the user as an 00203 * error. 00204 * 00205 * @return Returns \c true if the importer can successfully import the 00206 * given data descriptor; otherwise returns \c false. 00207 * 00208 * @see DataDescriptor, FileDescriptor 00209 */ 00210 virtual bool validate(const DataDescriptor* pDescriptor, std::string& errorMessage) const = 0; 00211 00212 /** 00213 * Returns a widget to display custom import option values. 00214 * 00215 * This method provides an interface for which specialized import options 00216 * for a data set can be displayed to the user. The method returns a Qt 00217 * widget that is added to the default import options dialog. The importer 00218 * should create the widget with a NULL parent, and should destroy the 00219 * widget when the importer itself is destroyed. 00220 * 00221 * Importers should call QWidget::setWindowTitle() on the widget that is 00222 * returned to set the name that appears on the tab in the import options 00223 * dialog. If the window title is not set, the importer name is displayed. 00224 * 00225 * @param pDescriptor 00226 * The data set for which to set the current values in the widget. 00227 * 00228 * @return A QWidget that will be displayed as an additional tab in the 00229 * default import options dialog. <b>NULL</b> should be returned 00230 * if the importer does not have custom options to display to the 00231 * user. 00232 */ 00233 virtual QWidget* getImportOptionsWidget(DataDescriptor* pDescriptor) = 0; 00234 00235 /** 00236 * Modifies a data descriptor before it is imported. 00237 * 00238 * This method is called after the user has made changes to the data 00239 * descriptor contained in an ImportDescriptor returned in 00240 * getImportDescriptors() and before the element is created for import. 00241 * 00242 * @warning It is generally not recommended for an importer to modify 00243 * values that the user has the capability to change in the import 00244 * options dialog since any value that the user sets would be 00245 * overridden without the user's knowledge. 00246 * 00247 * @param pDescriptor 00248 * The data set to modify before import. 00249 */ 00250 virtual void polishDataDescriptor(DataDescriptor* pDescriptor) = 0; 00251 00252 protected: 00253 /** 00254 * Since the Importer interface is usually used in conjunction with the 00255 * PlugIn and Executable interfaces, this should be destroyed by casting to 00256 * the PlugIn interface and calling PlugInManagerServices::destroyPlugIn(). 00257 */ 00258 virtual ~Importer() {} 00259 }; 00260 00261 #endif