MiltonApp.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class MiltonApp 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 Main entrypoint for Qt-based frontend which comes bundled with Milton 00009 (including a non-graphical 'nox' mode for remote / batch rendering). 00010 00011 @note 00012 MiltonApp constructs an underlying QApplication, which must be 00013 initialized before any other Qt user-interface objects are created. 00014 For this reason, initializing MiltonApp should generally be at the 00015 very beginning of your program's mainline. 00016 00017 @note 00018 MiltonApp is a singleton class and is only meant to be instantiated 00019 once per program (generally the first line of main) 00020 <!-------------------------------------------------------------------->**/ 00021 00022 #ifndef MILTON_APP_H_ 00023 #define MILTON_APP_H_ 00024 00025 #include "MiltonParams.h" 00026 #include "OpenGLCanvas.h" 00027 #include "ImageCanvas.h" 00028 #include "Gui.h" 00029 00030 class QApplication; 00031 class RenderOutput; 00032 00033 DECLARE_STL_TYPEDEF(std::vector<Renderer*>, RendererList); 00034 DECLARE_STL_TYPEDEF(std::vector<Canvas*>, CanvasList); 00035 00036 class MiltonApp { 00037 public: 00038 ///@name Constructors 00039 //@{----------------------------------------------------------------- 00040 00041 /** 00042 * @brief 00043 * Constructs a MiltonApp from the commandline parameters given 00044 * 00045 * @param title denotes the main titlebar of the Gui when it is enabled 00046 * @param enableGui denotes whether or not to default to having a Qt Gui 00047 * (enableGui may be overridden via the '-nox' commandline flag which 00048 * indicates a strict non-graphical mode) 00049 * 00050 * @note 00051 * Gui mode may be disabled implicitly if the current environment 00052 * or platform does not support QtGui or graphics in general (eg. no 00053 * X-server) 00054 */ 00055 MiltonApp(int argc, char **argv, 00056 const std::string &title = "Milton Renderer", 00057 bool enableGui = true); 00058 00059 virtual ~MiltonApp(); 00060 00061 00062 //@}----------------------------------------------------------------- 00063 ///@name Initialization 00064 //@{----------------------------------------------------------------- 00065 00066 /** 00067 * @brief 00068 * Loads / initializes canvases and renderer jobs specified on the 00069 * commandline (which was given to MiltonApp's constructor) 00070 * 00071 * @note 00072 * Invoking this method is completely optional and only provided 00073 * for convenience; a MiltonApp can disregard its commandline input 00074 * and construct a single OpenGLCanvas, for example, and still 00075 * utilize the underlying Milton framework without actually rendering 00076 * anything. 00077 * 00078 * @returns whether or not initialization was successful (will fail 00079 * if commandline contained invalid arguments or if a scenefile 00080 * that was specified fails to load) 00081 */ 00082 virtual bool loadCommandlineParams(); 00083 00084 /** 00085 * @brief 00086 * Adds the given canvas to this MiltonApp, optionally specifying 00087 * its subwindow's title @p name 00088 */ 00089 virtual void addCanvas (Canvas *canvas, const std::string &name = ""); 00090 00091 /** 00092 * @brief 00093 * Adds a non-graphical render job to this MiltonApp, whose render 00094 * method will be called in a new thread upon calling MiltonApp's exec 00095 */ 00096 virtual void addRenderer(Renderer *renderer); 00097 00098 00099 //@}----------------------------------------------------------------- 00100 ///@name Main usage interface 00101 //@{----------------------------------------------------------------- 00102 00103 /** 00104 * @brief 00105 * Enters Milton's main rendering loop, blocking the calling thread 00106 * until it completes. If Gui mode is enabled, this will initiate any 00107 * non-deferred renders and enter the underlying QApplication's main 00108 * loop (renders may be deferred via the -pause commandline flag, in 00109 * which case you must hit 'render' in the Gui to initiate rendering). 00110 * If Gui mode is disabled, this will begin rendering all batch jobs 00111 * which have been added to this app, either implicitly via the 00112 * commandline or explicitly via addRenderer 00113 * 00114 * @note 00115 * If Gui mode is disabled, the -pause commandline flag has no effect, 00116 * and all renders are initiated right away upon entering exec 00117 * 00118 * @note 00119 * exec blocks the calling thread until execution completes 00120 * 00121 * @returns whether or not execution was successful 00122 * @see isGuiEnabled 00123 */ 00124 virtual bool exec(); 00125 00126 00127 //@}----------------------------------------------------------------- 00128 ///@name Accessors 00129 //@{----------------------------------------------------------------- 00130 00131 /** 00132 * @returns whether or not the Qt frontend and connection to the 00133 * underlying X-server is enabled 00134 * 00135 * @note 00136 * Gui mode will be disabled if the underlying runtime environment 00137 * doesn't support Qt graphics or if the '-nox' flag was passed to 00138 * MiltonApp via the commandline 00139 */ 00140 inline bool isGuiEnabled() const { 00141 return m_params.enableGui; 00142 } 00143 00144 /** 00145 * @returns the underlying parameters used by loadCommandlineParams 00146 * to parse and load scenefiles 00147 */ 00148 virtual MiltonParams &getParams() { 00149 return m_params; 00150 } 00151 00152 /** 00153 * @returns the underlying parameters used by loadCommandlineParams 00154 * to parse and load scenefiles 00155 */ 00156 virtual const MiltonParams &getParams() const { 00157 return m_params; 00158 } 00159 00160 /** 00161 * @returns the underlying Qt Gui (for convenience only) 00162 */ 00163 virtual Gui *getGui() { 00164 return m_gui; 00165 } 00166 00167 /** 00168 * @returns the underlying Qt Gui (for convenience only) 00169 */ 00170 virtual const Gui *getGui() const { 00171 return m_gui; 00172 } 00173 00174 /** 00175 * @returns the underlying Qt QApplication (for convenience only) 00176 */ 00177 virtual QApplication *getQApplication() { 00178 return m_qApplication; 00179 } 00180 00181 /** 00182 * @returns the underlying Qt QApplication (for convenience only) 00183 */ 00184 virtual const QApplication *getQApplication() const { 00185 return m_qApplication; 00186 } 00187 00188 /** 00189 * @returns an std::vector of non-graphical renderer jobs which have 00190 * been added to this MiltonApp via addRenderer 00191 */ 00192 virtual RendererList &getRenderers() { 00193 return m_renderers; 00194 } 00195 00196 /** 00197 * @returns an std::vector of non-graphical renderer jobs which have 00198 * been added to this MiltonApp via addRenderer 00199 */ 00200 virtual const RendererList &getRenderers() const { 00201 return m_renderers; 00202 } 00203 00204 /** 00205 * @returns an std::vector of Canvases which have been added to this 00206 * MiltonApp via addCanvas 00207 */ 00208 virtual CanvasList &getCanvases() { 00209 return m_canvases; 00210 } 00211 00212 /** 00213 * @returns an std::vector of Canvases which have been added to this 00214 * MiltonApp via addCanvas 00215 */ 00216 virtual const CanvasList &getCanvases() const { 00217 return m_canvases; 00218 } 00219 00220 00221 //@}----------------------------------------------------------------- 00222 ///@name Miscellaneous 00223 //@{----------------------------------------------------------------- 00224 00225 /** 00226 * @brief 00227 * Prints an explanation of MiltonApp commandline usage to stderr 00228 * via std::cerr, including an optional error message 00229 */ 00230 virtual void printUsage(int argc = 0, char **argv = NULL, 00231 const char *errorMsg = NULL); 00232 00233 protected: 00234 /** 00235 * @brief 00236 * Fills in params by parsing commandline arguments 00237 * 00238 * @returns whether or not parsing was successful 00239 */ 00240 virtual bool _initializeParams(int argc, char **argv, 00241 MiltonParams ¶ms); 00242 00243 /** 00244 * @returns RenderOutput parsed from params.output 00245 */ 00246 virtual RenderOutput *_getOutput(MiltonParams ¶ms); 00247 00248 00249 //@}----------------------------------------------------------------- 00250 00251 protected: 00252 MiltonParams m_params; 00253 std::string m_title; 00254 00255 RendererList m_renderers; 00256 CanvasList m_canvases; 00257 00258 QApplication *m_qApplication; 00259 Gui *m_gui; 00260 00261 private: 00262 /** 00263 * @brief 00264 * Initializes the Milton stats package (see Random::init) and 00265 * instantiates a Qt Gui if Gui mode is enabled 00266 */ 00267 void _init(); 00268 00269 private: 00270 /** 00271 * @brief 00272 * boolean denoting whether or not a MiltonApp has previously been 00273 * constructed, in order to safeguard against undefined functionality 00274 * in the event of multiple MiltonApps being instantiated 00275 */ 00276 static bool s_instance; 00277 }; 00278 00279 #endif // MILTON_APP_H_ 00280
Generated on 28 Feb 2009 for Milton by
1.5.6