00001
00002
00027 #include <string>
00028 #include <hugin_version.h>
00029
00030 #if (!defined __APPLE__)
00031 #include "getopt.h"
00032 #endif
00033
00034 #ifdef WIN32
00035 #include <getopt.h>
00036 #else
00037 #include <unistd.h>
00038 #endif
00039
00040 #include "PTBatcher.h"
00041
00042 using namespace std;
00043
00044
00045 void usage()
00046 {
00047 cout << "PTBatcher: panotools batch stitcher" << endl
00048 << "Version " << DISPLAY_VERSION << endl << endl
00049 << "Usage: PTBatcher [options] input.pto output" << endl
00050 << "Options:" << endl
00051 << " -a file add project to queue. Unless -o option is present, the default prefix is appointed." << endl
00052 << " -o output prefix (together with -a option)" << endl
00053 << " -l list all projects in batch queue" << endl
00054 << " -c clear all projects from batch queue" << endl
00055 << " -x id remove project with specified id" << endl
00056 << " -r reset all projects to waiting status" << endl
00057 << " -b start batch process" << endl
00058 << " -p use parallel processing (together with -b option)" << endl
00059 << " -d delete .pto files when complete (together with -b option)" << endl
00060 << " -s shutdown computer when complete (together with -b option)" << endl
00061 << " -v verbose mode" << endl
00062 << " -h print this help" << endl
00063 << "Arguments:" << endl
00064 << " input.pto Path to project file." << endl
00065 << endl;
00066 }
00067
00068 #ifdef __WXMSW__ //windows version needs int main to enable console (and an OnInit function definition)
00069 bool HostApp::OnInit()
00070 {
00071 return true;
00072 };
00073
00074 int main(int argc, char* argv[])
00075 #else
00076 bool HostApp::OnInit()
00077 #endif
00078 {
00079
00080
00081 char type = 'n';
00082
00083 bool optionError = false;
00084 bool prefix = false;
00085
00086
00087 #ifdef __WXMSW__ //windows version needs to create a wxApp object
00088 HostApp app;
00089 app.InitBatch(wxString::FromAscii(argv[0]));
00090 Batch* batch = app.batch;
00091 char** newArgv = argv;
00092 #else //linux version needs to convert argv
00093 InitBatch(argv[0]);
00094
00095 char** newArgv = (char**)malloc(sizeof(char*)*argc);
00096 for(int i=0; i<argc; i++)
00097 {
00098 newArgv[i]= (char*)malloc(sizeof(char)*wxString(argv[i]).Length());
00099 strcpy(newArgv[i],wxString(argv[i]).char_str());
00100 }
00101 #endif
00102
00103 const char* optstring = "haolxrbpdsvc";
00104 char c;
00105 while ((c = getopt (argc, newArgv, optstring)) != -1)
00106 {
00107 switch(c)
00108 {
00109 case 'a':
00110 if(type != 'n' && type != 'a')
00111 {
00112 optionError = true;
00113 }
00114 type = 'a';
00115 break;
00116 case 'l':
00117 if(type != 'n' && type != 'l')
00118 {
00119 optionError = true;
00120 }
00121 type = 'l';
00122 break;
00123 case 'c':
00124 if(type != 'n' && type != 'c')
00125 {
00126 optionError = true;
00127 }
00128 type = 'c';
00129 break;
00130 case 'x':
00131 if(type != 'n' && type != 'x')
00132 {
00133 optionError = true;
00134 }
00135 type = 'x';
00136 break;
00137 case 'r':
00138 if(type != 'n' && type != 'r')
00139 {
00140 optionError = true;
00141 }
00142 type = 'r';
00143 break;
00144 case 'b':
00145 if(type != 'n' && type != 'b')
00146 {
00147 optionError = true;
00148 }
00149 type = 'b';
00150 break;
00151 case 'o':
00152 prefix = true;
00153 break;
00154 case 'p':
00155 batch->parallel = true;
00156 break;
00157 case 'd':
00158 batch->deleteFiles = true;
00159 break;
00160 case 's':
00161 batch->shutdown = true;
00162 break;
00163 case 'v':
00164 batch->verbose = true;
00165 break;
00166 case 'h':
00167 usage();
00168 return 0;
00169 default:
00170 usage();
00171 return 0;
00172 }
00173 }
00174
00175
00176 if(optionError || type == 'n' ||
00177 (type == 'a' && (batch->parallel || batch->deleteFiles || batch->shutdown)) ||
00178 (type == 'l' && (prefix || batch->parallel || batch->deleteFiles || batch->shutdown)) ||
00179 (type == 'c' && (prefix || batch->parallel || batch->deleteFiles || batch->shutdown)) ||
00180 (type == 'x' && (prefix || batch->parallel || batch->deleteFiles || batch->shutdown)) ||
00181 (type == 'r' && (prefix || batch->parallel || batch->deleteFiles || batch->shutdown)) ||
00182 (type == 'b' && prefix))
00183 {
00184 usage();
00185
00186 return 1;
00187 }
00188 string input = "";
00189 string output = "";
00190 if(type == 'a')
00191 {
00192 if(prefix && (optind+2 == argc))
00193 {
00194 input = newArgv[optind];
00195 output = newArgv[optind+1];
00196 }
00197 else if(!prefix && (optind+1 == argc))
00198 {
00199 input = newArgv[optind];
00200 }
00201 else
00202 {
00203 usage();
00204 return 1;
00205 }
00206 batch->LoadTemp();
00207 batch->AddProjectToBatch(wxString(input.c_str(), wxConvLocal),wxString(output.c_str(), wxConvLocal));
00208 if(output != "")
00209 {
00210 cout << "Added project " << input << " with output " << output << endl;
00211 }
00212 else
00213 {
00214 cout << "Added project " << input << endl;
00215 }
00216 batch->SaveTemp();
00217 }
00218 else if(type == 'l')
00219 {
00220 if(optind!=argc)
00221 {
00222 usage();
00223 return 1;
00224 }
00225 batch->LoadTemp();
00226 batch->ListBatch();
00227
00228 return 0;
00229 }
00230 else if(type == 'c')
00231 {
00232 if(optind!=argc)
00233 {
00234 usage();
00235 return 1;
00236 }
00237 batch->LoadTemp();
00238 batch->ClearBatch();
00239 batch->SaveTemp();
00240 return 0;
00241 }
00242 else if(type == 'x')
00243 {
00244 if(optind+1==argc && atoi(newArgv[optind])!=0)
00245 {
00246 batch->LoadTemp();
00247 batch->RemoveProject(atoi(newArgv[optind]));
00248 batch->SaveTemp();
00249 return 0;
00250 }
00251 else
00252 {
00253 usage();
00254 return 1;
00255 }
00256 }
00257 else if(type == 'r')
00258 {
00259 if(optind!=argc)
00260 {
00261 usage();
00262 return 1;
00263 }
00264 batch->LoadTemp();
00265 for(int i=0; i<batch->GetProjectCount(); i++)
00266 {
00267 batch->SetStatus(i,Project::WAITING);
00268 }
00269 batch->SaveTemp();
00270 return 0;
00271 }
00272 else if(type == 'b')
00273 {
00274 batch->LoadTemp();
00275 batch->RunBatch();
00276 while(!batch->AllDone())
00277 {
00278 #if defined __WXMSW__
00279 wxSleep(1);
00280 #else
00281 sleep(1000);
00282 #endif
00283 }
00284 batch->SaveTemp();
00285 }
00286
00287 return EXIT_SUCCESS;
00288 }