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 PLUGINSHELL_H 00011 #define PLUGINSHELL_H 00012 00013 #include "ObjectResource.h" 00014 #include "PlugIn.h" 00015 00016 #include <list> 00017 #include <string> 00018 #include <vector> 00019 00020 class Progress; 00021 class QAction; 00022 class QIcon; 00023 class SessionItemId; 00024 class SettableSessionItem; 00025 00026 /** 00027 * Report failure if a condition is not met. 00028 * 00029 * There must be variables named pProgress and pStep in order to 00030 * use this macro, of types Progress* and StepResource, respectively. 00031 00032 * @param cond 00033 * The condition to check again. 00034 * @param errorMessage 00035 * The message, implicitly convertable to a std::string, to report. 00036 * @param action 00037 * The action to take in case of failure. For example, "return", "continue", "break" 00038 */ 00039 #define FAIL_IF(cond, errorMessage, action) \ 00040 if (cond) \ 00041 { \ 00042 if (pProgress != NULL) \ 00043 { \ 00044 pProgress->updateProgress(errorMessage, 0, ERRORS); \ 00045 } \ 00046 pStep.get()->finalize(Message::Failure, errorMessage); \ 00047 action; \ 00048 } 00049 00050 /** 00051 * \ingroup ShellModule 00052 * A base class for plug-in shells or plug-in instances. 00053 * 00054 * This class provides a default implementation of the PlugIn 00055 * interfaces and serves as an optional base class for specialized 00056 * plug-in shell classes and/or custom plug-ins. 00057 * 00058 * @see PlugIn 00059 */ 00060 class PlugInShell : public PlugIn 00061 { 00062 public: 00063 /** 00064 * Creates the plug-in. 00065 * 00066 * The constructor initializes the plug-in as follows: 00067 * - getVersion() returns the same version as the main application with 00068 * which the plug-in was compiled. 00069 * - isProduction() returns \b false. 00070 * - areMultipleInstancesAllowed() returns \b false. 00071 * 00072 * @see ConfigurationSettings::getVersion() 00073 */ 00074 PlugInShell(); 00075 00076 /** 00077 * Destroys the plug-in. 00078 */ 00079 virtual ~PlugInShell(); 00080 00081 // SessionItem 00082 const std::string& getId() const; 00083 bool isValidSessionSaveItem() const; 00084 00085 /** 00086 * @copydoc SessionItem::getIcon() 00087 * 00088 * @default This implementation will always return an 00089 * empty QIcon. If you would like 00090 * to return a custom QIcon, you must 00091 * override this method in your subclass. 00092 * In order to properly support batch 00093 * mode, you should only construct 00094 * the QIcon when this method is 00095 * called and do not construct 00096 * the QIcon in your subclasses 00097 * constructor. 00098 */ 00099 const QIcon& getIcon() const; 00100 const std::string& getName() const; 00101 const std::string& getDisplayName(bool fullName = false) const; 00102 const std::string& getDisplayText() const; 00103 std::list<ContextMenuAction> getContextMenuActions() const; 00104 bool hasFilenameDisplay() const; 00105 std::vector<std::string> getPropertiesPages() const; 00106 bool serialize(SessionItemSerializer& serializer) const; 00107 bool deserialize(SessionItemDeserializer& deserializer); 00108 /** 00109 * @copydoc SettableSessionItem::setId() 00110 */ 00111 virtual bool setId(const SessionItemId& id); 00112 00113 // PlugIn 00114 std::string getVersion() const; 00115 bool isProduction() const; 00116 std::string getCreator() const; 00117 std::string getCopyright() const; 00118 std::map<std::string, std::string> getDependencyCopyright() const; 00119 std::string getDescription() const; 00120 std::string getShortDescription() const; 00121 std::string getDescriptorId() const; 00122 std::string getType() const; 00123 std::string getSubtype() const; 00124 bool areMultipleInstancesAllowed() const; 00125 00126 protected: 00127 /** 00128 * @copydoc SettableSessionItem::setName() 00129 */ 00130 void setName(const std::string& name); 00131 00132 /** 00133 * @copydoc SettableSessionItem::setValidSessionSaveItem() 00134 */ 00135 void setValidSessionSaveItem(bool isValid); 00136 00137 /** 00138 * @copydoc SettableSessionItem::setDisplayName() 00139 */ 00140 void setDisplayName(const std::string& displayName); 00141 00142 /** 00143 * @copydoc SettableSessionItem::setDisplayText() 00144 */ 00145 void setDisplayText(const std::string& displayText); 00146 00147 /** 00148 * @copydoc SettableSessionItem::addContextMenuAction() 00149 */ 00150 void addContextMenuAction(const ContextMenuAction& menuAction); 00151 00152 /** 00153 * @copydoc SettableSessionItem::setContextMenuActions() 00154 */ 00155 void setContextMenuActions(const std::list<ContextMenuAction>& actions); 00156 00157 /** 00158 * @copydoc SettableSessionItem::setFilenameDisplay() 00159 */ 00160 void setFilenameDisplay(bool bFilenameDisplay); 00161 00162 /** 00163 * @copydoc SettableSessionItem::addPropertiesPage() 00164 */ 00165 void addPropertiesPage(const std::string& plugInName); 00166 00167 /** 00168 * @copydoc SettableSessionItem::removePropertiesPage() 00169 */ 00170 void removePropertiesPage(const std::string& plugInName); 00171 00172 /** 00173 * @copydoc SettableSessionItem::setPropertiesPages() 00174 */ 00175 void setPropertiesPages(const std::vector<std::string>& plugInNames); 00176 00177 /** 00178 * Sets the plug-in version. 00179 * 00180 * This method sets the plug-in version as a string. 00181 * For example, "1.1.1" is a valid version string. 00182 * 00183 * @param version 00184 * The plug-in version. 00185 */ 00186 void setVersion(const std::string& version); 00187 00188 /** 00189 * Sets the plug-in production status. 00190 * 00191 * This method sets the plug-in production status as a bool. 00192 * 00193 * @param productionStatus 00194 * Is the plug-in a production plug-in? 00195 */ 00196 void setProductionStatus(bool productionStatus); 00197 00198 /** 00199 * Sets the name of the organization that created the plug-in. 00200 * 00201 * This method sets the string name of the organization 00202 * responsible for creating the plug-in. For example, 00203 * "Ball Aerospace & Technologies Corp." is a valid creator string. 00204 * 00205 * @param creator 00206 * The organization that created the plug-in. 00207 */ 00208 void setCreator(const std::string& creator); 00209 00210 /** 00211 * Sets the full copyright information for the plug-in. 00212 * 00213 * @param copyright 00214 * The copyright information for the plug-in. 00215 */ 00216 void setCopyright(const std::string& copyright); 00217 00218 /** 00219 * Adds a dependency copyright message. 00220 * 00221 * @param dependencyName 00222 * The name identifying the dependency. For example: 'libtiff' or 'qt'. 00223 * @param copyright 00224 * The verbatim copyright message for the dependency. 00225 * The copyright message may be formatted with HTML markup. 00226 */ 00227 void addDependencyCopyright(const std::string& dependencyName, const std::string& copyright); 00228 00229 /** 00230 * Sets a text description for the plug-in. 00231 * 00232 * This method sets the full textual description for a 00233 * plug-in. The description string can be of arbitrary 00234 * length. 00235 * 00236 * @param description 00237 * The full plug-in description. 00238 * 00239 * @see setShortDescription() 00240 */ 00241 void setDescription(const std::string& description); 00242 00243 /** 00244 * Sets a short description for the plug-in. 00245 * 00246 * This method sets a short 50-charater or less 00247 * description about the plug-in. This short description 00248 * is used for brief descriptive table entries in the GUI. 00249 * 00250 * @param shortDescription 00251 * The short plug-in description. 00252 * 00253 * @see setDescription() 00254 */ 00255 void setShortDescription(const std::string& shortDescription); 00256 00257 /** 00258 * Sets unique for the plug-in descriptor. 00259 * 00260 * This method sets a unique id for the plug-in class. This string 00261 * should be formatted as a UUID. This value must be the same between 00262 * instances of the application. 00263 * 00264 * @param id 00265 * The unique id for the descriptor. 00266 */ 00267 void setDescriptorId(const std::string& id); 00268 00269 /** 00270 * Sets the plug-in type. 00271 * 00272 * Default plug-in types include the following: 00273 * <ul> 00274 * <li>Algorithm</li> 00275 * <li>Custom Options</li> 00276 * <li>Exporter</li> 00277 * <li>Georeference</li> 00278 * <li>Importer</li> 00279 * <li>Interpreter</li> 00280 * <li>RasterPager</li> 00281 * <li>Viewer</li> 00282 * <li>Wizard</li> 00283 * </ul> 00284 * 00285 * @param type 00286 * The plug-in type. 00287 */ 00288 void setType(const std::string& type); 00289 00290 /** 00291 * Sets the plug-in subtype. 00292 * 00293 * Plug-ins can optionally define a subtype to further distinguish between 00294 * multiple kinds of plug-ins with the same type, typically importers and 00295 * exporters. The subtype is used internally to populate file selection 00296 * dialogs so that they contain only a subset of plug-ins of a given type. 00297 * Default plug-in subtypes include the following: 00298 * <ul> 00299 * <li>Product</li> 00300 * <li>%RasterElement</li> 00301 * <li>%Signature</li> 00302 * <li>%SignatureSet</li> 00303 * </ul> 00304 * 00305 * @param subtype 00306 * The plug-in subtype. 00307 */ 00308 void setSubtype(const std::string& subtype); 00309 00310 /** 00311 * Sets whether multiple instances of the plug-in can be instantiated 00312 * simultaneously. 00313 * 00314 * @param bMultipleInstances 00315 * Set this value to true if the multiple instances of the 00316 * plug-in can be created and executed simultaneously, 00317 * otherwise false. 00318 */ 00319 void allowMultipleInstances(bool bMultipleInstances); 00320 00321 private: 00322 FactoryResource<SettableSessionItem> mpSessionItem; 00323 std::string mVersion; 00324 bool mProductionStatus; 00325 std::string mCreator; 00326 std::string mCopyright; 00327 std::map<std::string, std::string> mDependencyCopyright; 00328 std::string mDescription; 00329 std::string mShortDescription; 00330 std::string mDescriptorId; 00331 std::string mType; 00332 std::string mSubtype; 00333 bool mAllowMultipleInstances; 00334 }; 00335 00336 #endif