00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "wx/wxprec.h"
00025
00026 #ifndef WX_PRECOMP
00027 # include "wx/wx.h"
00028 #endif
00029
00030 #include <boost/program_options.hpp>
00031 #include <iostream>
00032 #include <fstream>
00033 #include <sstream>
00034
00035 #include "lux.h"
00036 #include "api.h"
00037 #include "error.h"
00038
00039 #include "wxluxapp.h"
00040 #include "wxluxgui.h"
00041
00042 using namespace lux;
00043 namespace po = boost::program_options;
00044
00045 IMPLEMENT_APP(LuxGuiApp)
00046
00047
00048 bool LuxGuiApp::OnInit() {
00049
00050 setlocale(LC_NUMERIC, "C");
00051
00052 luxInit();
00053
00054 if(ProcessCommandLine()) {
00055 m_guiFrame = new LuxGui((wxFrame*)NULL, m_openglEnabled);
00056 m_guiFrame->Show(true);
00057 SetTopWindow(m_guiFrame);
00058 m_guiFrame->SetRenderThreads(m_threads);
00059 if(!m_inputFile.IsEmpty())
00060 m_guiFrame->RenderScenefile(m_inputFile);
00061 return true;
00062 } else {
00063 return false;
00064 }
00065 }
00066
00067 bool LuxGuiApp::ProcessCommandLine() {
00068 try {
00069
00070 po::options_description generic("Generic options");
00071 generic.add_options()
00072 ("version,v", "Print version string")
00073 ("help", "Produce help message")
00074 ("debug,d", "Enable debug mode")
00075 ;
00076
00077
00078
00079
00080 po::options_description config("Configuration");
00081 config.add_options()
00082 ("threads,t", po::value < int >(), "Specify the number of threads that Lux will run in parallel.")
00083 ("useserver,u", po::value< std::vector<std::string> >()->composing(), "Specify the adress of a rendering server to use.")
00084 ("serverinterval,i", po::value < int >(), "Specify the number of seconds between requests to rendering servers.")
00085 ;
00086
00087
00088
00089 po::options_description hidden("Hidden options");
00090 hidden.add_options()
00091 ("input-file", po::value < vector < string > >(), "input file")
00092 ;
00093
00094 #ifdef LUX_USE_OPENGL
00095 generic.add_options()
00096 ("noopengl", "Disable OpenGL to display the image")
00097 ;
00098 #else
00099 hidden.add_options()
00100 ("noopengl", "Disable OpenGL to display the image")
00101 ;
00102 #endif // LUX_USE_OPENGL
00103
00104 po::options_description cmdline_options;
00105 cmdline_options.add(generic).add(config).add(hidden);
00106
00107 po::options_description config_file_options;
00108 config_file_options.add(config).add(hidden);
00109
00110 po::options_description visible("Allowed options");
00111 visible.add(generic).add(config);
00112
00113 po::positional_options_description p;
00114
00115 p.add("input-file", -1);
00116
00117 po::variables_map vm;
00118 #if wxUSE_UNICODE == 1
00119 store(po::wcommand_line_parser(wxApp::argc, wxApp::argv).
00120 options(cmdline_options).positional(p).run(), vm);
00121 #else // ANSI
00122 store(po::command_line_parser(wxApp::argc, wxApp::argv).
00123 options(cmdline_options).positional(p).run(), vm);
00124 #endif // Unicode/ANSI
00125
00126 std::ifstream ifs("luxrender.cfg");
00127 store(parse_config_file(ifs, config_file_options), vm);
00128 notify(vm);
00129
00130 if(vm.count("help")) {
00131 std::cout << "Usage: luxrender [options] file..." << std::endl;
00132 std::cout << visible << std::endl;
00133 return false;
00134 }
00135
00136 if(vm.count("version")) {
00137 std::cout << "Lux version " << LUX_VERSION_STRING << " of " << __DATE__ << " at " << __TIME__ << std::endl;
00138 return false;
00139 }
00140
00141 if(vm.count("threads")) {
00142 m_threads = vm["threads"].as < int >();
00143 }
00144 else {
00145 m_threads = 1;;
00146 }
00147
00148 if(vm.count("debug")) {
00149 luxError(LUX_NOERROR, LUX_INFO, "Debug mode enabled");
00150 luxEnableDebugMode();
00151 }
00152
00153 int serverInterval;
00154 if(vm.count("serverinterval")) {
00155 serverInterval = vm["serverinterval"].as<int>();
00156 luxSetNetworkServerUpdateInterval(serverInterval);
00157 } else {
00158 serverInterval = luxGetNetworkServerUpdateInterval();
00159 }
00160
00161 if(vm.count("useserver")) {
00162 std::stringstream ss;
00163
00164 std::vector<std::string> names = vm["useserver"].as<std::vector<std::string> >();
00165
00166 for(std::vector<std::string>::iterator i = names.begin(); i < names.end(); i++) {
00167 ss.str("");
00168 ss << "Connecting to server '" <<(*i) << "'";
00169 luxError(LUX_NOERROR, LUX_INFO, ss.str().c_str());
00170
00171
00172 luxAddServer((*i).c_str());
00173 }
00174
00175 m_useServer = true;
00176
00177 ss.str("");
00178 ss << "Server requests interval: " << serverInterval << " secs";
00179 luxError(LUX_NOERROR, LUX_INFO, ss.str().c_str());
00180 } else {
00181 m_useServer = false;
00182 }
00183
00184 if(vm.count("noopengl")) {
00185 m_openglEnabled = false;
00186 } else {
00187 #ifdef LUX_USE_OPENGL
00188 #if wxUSE_GLCANVAS == 1
00189 m_openglEnabled = true;
00190 #else
00191 m_openglEnabled = false;
00192 luxError(LUX_NOERROR, LUX_INFO, "GUI: wxWidgets without suppport for OpenGL canvas - will not be used.");
00193 #endif // wxUSE_GLCANVAS
00194 #else
00195 m_openglEnabled = false;
00196 luxError(LUX_NOERROR, LUX_INFO, "GUI: OpenGL support was not compiled in - will not be used.");
00197 #endif // LUX_USE_OPENGL
00198 }
00199
00200 if(vm.count("input-file")) {
00201 const std::vector < std::string > &v = vm["input-file"].as < vector < string > >();
00202 if(v.size() > 1) {
00203 luxError(LUX_SYSTEM, LUX_SEVERE, "More than one file passed on command line : rendering the first one.");
00204 }
00205
00206 m_inputFile = wxString(v[0].c_str(), wxConvUTF8);
00207 } else {
00208 m_inputFile.Clear();
00209 }
00210
00211 return true;
00212 } catch(std::exception &e) {
00213 std::cout << e.what() << std::endl;
00214 return false;
00215 }
00216 }