ExportAgent.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 EXPORT_AGENT_H
00011 #define EXPORT_AGENT_H
00012 
00013 #include "ExecutableAgent.h"
00014 #include "TypesFile.h"
00015 
00016 #include <string>
00017 
00018 class Exporter;
00019 class FileDescriptor;
00020 class PlugInArgList;
00021 class QWidget;
00022 class SessionItem;
00023 
00024 /**
00025  *  This is a helper class that makes working with Exporter
00026  *  plug-ins easier.  This class will manage the lifecycle of
00027  *  the Exporter plug-in. This class can be used
00028  *  to export a SessionItem.
00029  *
00030  *  You should not create an instance of this class using
00031  *  ObjectFactory, but you should use ExporterResource.
00032  *
00033  *  @warning If you do not call an overload of instantiate() before
00034  *  calling any other methods, a std::logic_error will be thrown.
00035  *  You cannot call instantiate() twice on the same instance
00036  *  or a std::logic_error will be thrown.
00037  *
00038  *  @see ExporterResource, Exporter
00039  */
00040 class ExportAgent : public ExecutableAgent
00041 {
00042 public:
00043    using ExecutableAgent::instantiate;
00044 
00045    /**
00046     *  Creates an invalid object for delayed initialization of an ExportAgent.
00047     *
00048     *  Creates an invalid object where no exporter is
00049     *  initially created.  The exporter can then be initialized later by calling
00050     *  setPlugIn().
00051     *
00052     *  @param   pProgress
00053     *           The progress object to pass into the exporter.  If \b NULL is
00054     *           passed in, a progress object is obtained by calling
00055     *           PlugInManagerServices::getProgress().
00056     *  @param   batch
00057     *           Set this value to \b true to execute the exporter in batch mode
00058     *           or to \b false to execute the exporter in interactive mode.
00059     *  @throw   std::logic_error
00060     *           Thrown if the instantiate() method is called more than
00061     *           once on a instance.
00062     */
00063    virtual void instantiate(Progress* pProgress, bool batch) = 0;
00064 
00065    /**
00066     *  Creates an exporter to export data.
00067     *
00068     *  Creates the exporter but does not specify the data to
00069     *  export.  This method can be used if the exporter does not need a specific
00070     *  data value, or one will be provided later through setItem().
00071     *
00072     *  @param   exporterName
00073     *           The name of the exporter to create and execute.
00074     *  @param   pProgress
00075     *           The progress object to pass into the exporter.  If \b NULL is
00076     *           passed in, a progress object is obtained by calling
00077     *           PlugInManagerServices::getProgress().
00078     *  @param   batch
00079     *           Set this value to \b true to execute the exporter in batch mode
00080     *           or to \b false to execute the exporter in interactive mode.
00081     *  @throw   std::logic_error
00082     *           Thrown if the instantiate() method is called more than
00083     *           once on a instance.
00084     */
00085    virtual void instantiate(std::string exporterName, Progress* pProgress, bool batch) = 0;
00086 
00087    /**
00088     *  Uses an existing exporter to export data.
00089     *
00090     *  @param   pPlugIn
00091     *           The exporter to execute.  The agent assumes ownership of the
00092     *           exporter and will destroy it as necessary upon agent
00093     *           destruction.
00094     *  @param   pProgress
00095     *           The progress object to pass into the exporter.  If \b NULL is
00096     *           passed in, a progress object is obtained by calling
00097     *           PlugInManagerServices::getProgress().
00098     *  @param   batch
00099     *           Set this value to \b true to execute the exporter in batch mode
00100     *           or to \b false to execute the exporter in interactive mode.
00101     *  @throw   std::logic_error
00102     *           Thrown if the instantiate() method is called more than
00103     *           once on a instance.
00104     */
00105    virtual void instantiate(PlugIn* pPlugIn, Progress* pProgress, bool batch) = 0;
00106 
00107    /**
00108     *  Creates an exporter to export a view.
00109     *
00110     *  @param   exporterName
00111     *           The name of the exporter to create and execute.
00112     *  @param   pItem
00113     *           The item to pass into the exporter.
00114     *  @param   pFileDescriptor
00115     *           The file descriptor describing how the exporter should save
00116     *           the data to disk.
00117     *  @param   pProgress
00118     *           The progress object to pass into the exporter.  If \b NULL is
00119     *           passed in, a progress object is obtained by calling
00120     *           PlugInManagerServices::getProgress().
00121     *  @param   batch
00122     *           Set this value to \b true to execute the exporter in batch mode
00123     *           or to \b false to execute the exporter in interactive mode.
00124     *  @throw   std::logic_error
00125     *           Thrown if the instantiate() method is called more than
00126     *           once on a instance.
00127     */
00128    virtual void instantiate(std::string exporterName, SessionItem *pItem, FileDescriptor* pFileDescriptor,
00129       Progress* pProgress, bool batch) = 0;
00130 
00131    /**
00132     *  Uses an existing exporter to export a session item.
00133     *
00134     *  @param   pPlugIn
00135     *           The exporter to execute.  The agent assumes ownership of the
00136     *           exporter and will destroy it as necessary upon agent
00137     *           destruction.
00138     *  @param   pItem
00139     *           The item to pass into the exporter.
00140     *  @param   pFileDescriptor
00141     *           The file descriptor describing how the exporter should save
00142     *           the data to disk.
00143     *  @param   pProgress
00144     *           The progress object to pass into the exporter.  If \b NULL is
00145     *           passed in, a progress object is obtained by calling
00146     *           PlugInManagerServices::getProgress().
00147     *  @param   batch
00148     *           Set this value to \b true to execute the exporter in batch mode
00149     *           or to \b false to execute the exporter in interactive mode.
00150     *  @throw   std::logic_error
00151     *           Thrown if the instantiate() method is called more than
00152     *           once on a instance.
00153     */
00154    virtual void instantiate(PlugIn* pPlugIn, SessionItem *pItem, FileDescriptor* pFileDescriptor,
00155       Progress* pProgress, bool batch) = 0;
00156 
00157    /**
00158     *  Gets a pointer to the underlying exporter plug-in.
00159     *
00160     *  This differs from getPlugIn() in that it performs a dynamic_cast
00161     *  to type Exporter. This is a convenience function and
00162     *  is equivalent to dynamic_cast<Exporter*>(getPlugIn())
00163     *
00164     *  @throw   std::logic_error
00165     *           Thrown if the instantiate() method has not yet
00166     *           been called on this instance.
00167     *
00168     *  @return   A pointer to the underlying exporter plug-in.
00169     */
00170    virtual Exporter *getExporter() = 0;
00171 
00172    /**
00173     *  Gets a pointer to the underlying exporter plug-in.
00174     *
00175     *  This differs from getPlugIn() in that it performs a dynamic_cast
00176     *  to type Exporter. This is a convenience function and
00177     *  is equivalent to dynamic_cast<Exporter*>(getPlugIn())
00178     *
00179     *  @throw   std::logic_error
00180     *           Thrown if the instantiate() method has not yet
00181     *           been called on this instance.
00182     *
00183     *  @return   A pointer to the underlying exporter plug-in.
00184     */
00185    virtual const Exporter *getExporter() const = 0;
00186 
00187    /**
00188     *  Gets the exporter plug-in's custom options page.
00189     *
00190     *  This gets a custom option widget using the existing
00191     *  agent's plug-in arguments.
00192     *
00193     *  @throw   std::logic_error
00194     *           Thrown if the instantiate() method has not yet
00195     *           been called on this instance.
00196     *
00197     *  @return  A custom option widget or NULL if the exporter
00198     *           does not have a custom option widget.
00199     */
00200    virtual QWidget *getExportOptionsWidget() = 0;
00201 
00202    /**
00203     *  Sets the session item to pass into the exporter.
00204     *
00205     *  @param  pItem
00206     *          The session item to pass into the exporter.
00207     *  @throw   std::logic_error
00208     *           Thrown if the instantiate() method has not yet
00209     *           been called on this instance.
00210     */
00211    virtual void setItem(SessionItem* pItem) = 0;
00212 
00213    /**
00214     *  Returns the session item that will be passed into the exporter when it
00215     *  is executed.
00216     *
00217     *  @throw   std::logic_error
00218     *           Thrown if the instantiate() method has not yet
00219     *           been called on this instance.
00220     *
00221     *  @return  The session item that is passed into the exporter.  This is
00222     *           either the session item passed in upon instantiation of the agent
00223     *           or the session item obtained by calling setItem().
00224     */
00225    virtual SessionItem* getItem() const = 0;
00226 
00227    /**
00228     *  Sets the file descriptor that the exporter uses to save the file.
00229     *
00230     *  @param   pFileDescriptor
00231     *           The file descriptor to pass into the exporter.
00232     *  @throw   std::logic_error
00233     *           Thrown if the instantiate() method has not yet
00234     *           been called on this instance.
00235     */
00236    virtual void setFileDescriptor(FileDescriptor* pFileDescriptor) = 0;
00237 
00238    /**
00239     *  Returns the file descriptor that will be passed into the exporter when
00240     *  it is executed.
00241     *
00242     *  @throw   std::logic_error
00243     *           Thrown if the instantiate() method has not yet
00244     *           been called on this instance.
00245     *
00246     *  @return  The file descriptor that is passed into the exporter.  This is
00247     *           either the file descriptor passed in upon instantiation of the
00248     *           agent or the file descriptor obtained by calling
00249     *           setFileDescriptor().
00250     */
00251    virtual FileDescriptor* getFileDescriptor() = 0;
00252 
00253    /**
00254     *  Returns the file descriptor that will be passed into the exporter when
00255     *  it is executed.
00256     *
00257     *  @throw   std::logic_error
00258     *           Thrown if the instantiate() method has not yet
00259     *           been called on this instance.
00260     *
00261     *  @return  The file descriptor that is passed into the exporter.  This is
00262     *           either the file descriptor passed in upon instantiation of the
00263     *           agent or the file descriptor obtained by calling
00264     *           setFileDescriptor().
00265     */
00266    virtual const FileDescriptor* getFileDescriptor() const = 0;
00267 
00268    /**
00269     *  Gets the default file extensions from the exporter.
00270     *
00271     *  @throw   std::logic_error
00272     *           Thrown if the instantiate() method has not yet
00273     *           been called on this instance.
00274     *
00275     *  @return  The default extensions string returned by calling
00276     *           Exporter::getDefaultExtensions().
00277     */
00278    virtual std::string getDefaultExtensions() const = 0;
00279 
00280    /**
00281     *  Validate the input argument list.
00282     *
00283     *  This validates the input argument list as it will be passed to Executable::execute().
00284     *  If the plug-in is interactive, information and choices may be presented to the user
00285     *  to decide how to proceed. If the plug-in is in batch mode, information may be logged
00286     *  to the message log but no user interaction is possible.
00287     *
00288     *  @param errorMessage
00289     *         This is the error or informational message to display to the user.
00290     *
00291     *  @throw   std::logic_error
00292     *           Thrown if the instantiate() method has not yet
00293     *           been called on this instance.
00294     *
00295     *  @return Validation result indicating if the exporter can save the data
00296     *
00297     *  @see ValidationResultType
00298     */
00299    virtual ValidationResultType validate(std::string &errorMessage) = 0;
00300 
00301    /**
00302     *  Executes the exporter to save the data.
00303     *
00304     *  This method first creates the input and output arg lists if necessary,
00305     *  populates the input arg list, and then executes the exporter.
00306     *
00307     *  @par Arg Values:
00308     *  The following input arg values are automatically populated unless the
00309     *  actual value in the arg has already been set and
00310     *  PlugInArg::isActualSet() returns \c true:
00311     *  - All args documented in ExecutableAgent::execute().
00312     *  - Exporter::ExportItemArg() is populated with the SessionItem that will
00313     *    be exported as returned by getItem().
00314     *  - Exporter::ExportDescriptorArg() is populated with the FileDescriptor
00315     *    to use for export as returned by getFileDescriptor().
00316     *
00317     *  @throw   std::logic_error
00318     *           Thrown if the instantiate() method has not yet
00319     *           been called on this instance.
00320     *
00321     *  @return  The success value returned by the exporter.
00322     */
00323    virtual bool execute() = 0;
00324 
00325 protected:
00326    /**
00327     * This should be destroyed by calling ObjectFactory::destroyObject.
00328     */
00329    virtual ~ExportAgent() {}
00330 };
00331 
00332 #endif

Software Development Kit - Opticks 4.9.0 Build 16218