[aacb50]: src / hugin1 / ptbatcher / PTBatcherGUI.cpp Maximize Restore History

Download this file

PTBatcherGUI.cpp    439 lines (411 with data), 13.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
// -*- c-basic-offset: 4 -*-
/** @file PTBatcherGUI.cpp
*
* @brief Batch processor for Hugin with GUI
*
* @author Marko Kuder <marko.kuder@gmail.com>
*
* $Id: PTBatcherGUI.cpp 3322 2008-08-16 5:00:07Z mkuder $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "PTBatcherGUI.h"
// make wxwindows use this class as the main application
IMPLEMENT_APP(PTBatcherGUI)
BEGIN_EVENT_TABLE(PTBatcherGUI, wxApp)
EVT_LIST_ITEM_ACTIVATED(XRCID("project_listbox"),PTBatcherGUI::OnItemActivated)
EVT_KEY_DOWN(PTBatcherGUI::OnKeyDown)
END_EVENT_TABLE()
bool PTBatcherGUI::OnInit()
{
// Required to access the preferences of hugin
SetAppName(wxT("hugin"));
#if defined __WXMSW__
int localeID = wxConfigBase::Get()->Read(wxT("language"), (long) wxLANGUAGE_DEFAULT);
m_locale.Init(localeID);
#else
m_locale.Init(wxLANGUAGE_DEFAULT);
#endif
// setup the environment for the different operating systems
#if defined __WXMSW__
wxString huginExeDir = getExePath(argv[0]);
wxString huginRoot;
wxFileName::SplitPath(huginExeDir, &huginRoot, NULL, NULL);
m_xrcPrefix = wxString(huginRoot + wxT("/share/hugin/xrc/"));
// locale setup
m_locale.AddCatalogLookupPathPrefix(huginRoot + wxT("/share/locale"));
#elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
{
wxString exec_path = MacGetPathToBundledResourceFile(CFSTR("xrc"));
if(exec_path != wxT(""))
{
m_xrcPrefix = exec_path + wxT("/");
}
else
wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
wxString thePath = MacGetPathToBundledResourceFile(CFSTR("locale"));
if(thePath != wxT(""))
m_locale.AddCatalogLookupPathPrefix(thePath);
else {
wxMessageBox(_("Translations not found in bundle"), _("Fatal Error"));
return false;
}
}
#else
// add the locale directory specified during configure
m_xrcPrefix = wxT(INSTALL_XRC_DIR);
m_locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
#endif
// set the name of locale recource to look for
m_locale.AddCatalog(wxT("hugin"));
const wxString name = wxString::Format(_T("PTBatcherGUI-%s"), wxGetUserId().c_str());
m_checker = new wxSingleInstanceChecker(name+wxT(".lock"),wxFileName::GetTempDir());
bool IsFirstInstance=(!m_checker->IsAnotherRunning());
if(IsFirstInstance)
{
if ( ! wxFile::Exists(m_xrcPrefix + wxT("/batch_frame.xrc")) ) {
wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:") + m_xrcPrefix , _("Fatal Error"));
return false;
}
// initialize image handlers
wxInitAllImageHandlers();
// Initialize all the XRC handlers.
wxXmlResource::Get()->InitAllHandlers();
wxXmlResource::Get()->AddHandler(new ProjectListBoxXmlHandler());
// load XRC files
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_frame.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_toolbar.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("batch_menu.xrc"));
};
// parse arguments
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
//On wxWidgets 2.9, wide characters don't work here.
//On previous versions, the wxT macro is required for unicode builds.
#if wxCHECK_VERSION(2,9,0)
{ wxCMD_LINE_SWITCH, "h", "help", "show this help message",
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_SWITCH, "b", "batch", "run batch immediately" },
{ wxCMD_LINE_SWITCH, "p", "parallel", "run batch projects in parallel" },
{ wxCMD_LINE_SWITCH, "d", "delete", "delete *.pto files after stitching" },
{ wxCMD_LINE_SWITCH, "o", "overwrite", "overwrite previous files without asking" },
{ wxCMD_LINE_SWITCH, "s", "shutdown", "shutdown computer after batch is complete" },
{ wxCMD_LINE_SWITCH, "v", "verbose", "show verbose output when processing projects" },
{ wxCMD_LINE_SWITCH, "a", "assistant", "run the assistant on the given projects" },
{ wxCMD_LINE_PARAM, NULL, NULL, _("stitch_project.pto [output prefix]|assistant_project.pto"),
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL + wxCMD_LINE_PARAM_MULTIPLE },
{ wxCMD_LINE_NONE }
#else
{ wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("show this help message"),
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_SWITCH, wxT("b"), wxT("batch"), wxT("run batch immediately") },
{ wxCMD_LINE_SWITCH, wxT("p"), wxT("parallel"), wxT("run batch projects in parallel") },
{ wxCMD_LINE_SWITCH, wxT("d"), wxT("delete"), wxT("delete *.pto files after stitching") },
{ wxCMD_LINE_SWITCH, wxT("o"), wxT("overwrite"), wxT("overwrite previous files without asking") },
{ wxCMD_LINE_SWITCH, wxT("s"), wxT("shutdown"), wxT("shutdown computer after batch is complete") },
{ wxCMD_LINE_SWITCH, wxT("v"), wxT("verbose"), wxT("show verbose output when processing projects") },
{ wxCMD_LINE_SWITCH, wxT("a"), wxT("assistant"), wxT("run the assistant on the given projects") },
{ wxCMD_LINE_PARAM, NULL, NULL, _("stitch_project.pto [output prefix]|assistant_project.pto"),
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL + wxCMD_LINE_PARAM_MULTIPLE },
{ wxCMD_LINE_NONE }
#endif
};
wxCmdLineParser parser(cmdLineDesc, argc, argv);
switch ( parser.Parse() ) {
case -1: // -h or --help was given, and help displayed so exit
return false;
break;
case 0: // all is well
break;
default:
wxLogError(_("Syntax error in parameters detected, aborting."));
return false;
break;
}
wxClient client;
wxConnectionBase *conn;
wxString servername;
#ifdef __WINDOWS__
servername=name;
#else
servername=wxFileName::GetTempDir()+wxFileName::GetPathSeparator()+name+wxT(".ipc");
#endif
if(IsFirstInstance)
{
m_frame = new BatchFrame(&m_locale,m_xrcPrefix);
m_frame->RestoreSize();
SetTopWindow(m_frame);
m_frame->Show(true);
m_server = new BatchIPCServer();
if (!m_server->Create(servername))
{
delete m_server;
m_server = NULL;
};
}
else
{
conn=client.MakeConnection(wxEmptyString, servername, IPC_START);
if(!conn)
return false;
};
//m_frame->SetLocaleAndXRC(&m_locale,m_xrcPrefix);
//projectsRunning=0;
unsigned int count = 0;
if(parser.Found(wxT("a")))
{
//added assistant files
while(parser.GetParamCount()>count)
{
wxString param = parser.GetParam(count);
count++;
wxFileName name(param);
name.MakeAbsolute();
if(name.FileExists())
{
//only add existing pto files
if(name.GetExt().CmpNoCase(wxT("pto"))==0)
{
if(IsFirstInstance)
{
m_frame->AddToList(name.GetFullPath(),Project::DETECTING);
}
else
{
conn->Request(wxT("D ")+name.GetFullPath());
};
};
};
};
}
else
{
bool projectSpecified = false;
//we collect all parameters - all project files <and their output prefixes>
while(parser.GetParamCount()>count)
{
wxString param = parser.GetParam(count);
count++;
if(!projectSpecified) //next parameter must be new script file
{
wxFileName name(param);
name.MakeAbsolute();
if(IsFirstInstance)
m_frame->AddToList(name.GetFullPath());
else
conn->Request(wxT("A ")+name.GetFullPath());
projectSpecified = true;
}
else //parameter could be previous project's output prefix
{
wxFileName fn(param);
fn.MakeAbsolute();
if(!fn.HasExt()) //if there is no extension we have a prefix
{
if(IsFirstInstance)
m_frame->ChangePrefix(-1,fn.GetFullPath());
else
conn->Request(wxT("P ")+fn.GetFullPath());
projectSpecified = false;
}
else
{
wxString ext = fn.GetExt();
//we may still have a prefix, but with added image extension
if (ext.CmpNoCase(wxT("jpg")) == 0 || ext.CmpNoCase(wxT("jpeg")) == 0||
ext.CmpNoCase(wxT("tif")) == 0|| ext.CmpNoCase(wxT("tiff")) == 0 ||
ext.CmpNoCase(wxT("png")) == 0 || ext.CmpNoCase(wxT("exr")) == 0 ||
ext.CmpNoCase(wxT("pnm")) == 0 || ext.CmpNoCase(wxT("hdr")) == 0)
{
//extension will be removed before stitch, so there is no need to do it now
if(IsFirstInstance)
m_frame->ChangePrefix(-1,fn.GetFullPath());
else
conn->Request(wxT("P ")+fn.GetFullPath());
projectSpecified = false;
}
else //if parameter has a different extension we presume it is a new script file
{
//we add the new project
if(IsFirstInstance)
m_frame->AddToList(fn.GetFullPath());
else
conn->Request(wxT("A ")+fn.GetFullPath());
projectSpecified = true;
}
} //else of if(!fn.HasExt())
}
}
}
#ifdef __WXMAC__
m_macFileNameToOpenOnStart = wxT("");
wxYield();
if(m_macFileNameToOpenOnStart != wxT(""))
{
wxFileName fn(m_macFileNameToOpenOnStart);
m_frame->AddToList(fn.GetFullPath());
}
#endif
if(IsFirstInstance)
{
wxConfigBase *config=wxConfigBase::Get();
if (parser.Found(wxT("d")))
config->Write(wxT("/BatchFrame/DeleteCheck"), 1l);
if (parser.Found(wxT("p")))
config->Write(wxT("/BatchFrame/ParallelCheck"), 1l);
if (parser.Found(wxT("s")))
config->Write(wxT("/BatchFrame/ShutdownCheck"), 1l);
if (parser.Found(wxT("o")))
config->Write(wxT("/BatchFrame/OverwriteCheck"), 1l);
if (parser.Found(wxT("v")))
config->Write(wxT("/BatchFrame/VerboseCheck"), 1l);
config->Flush();
}
else
{
if (parser.Found(wxT("d")))
conn->Request(wxT("SetDeleteCheck"));
if (parser.Found(wxT("p")))
conn->Request(wxT("SetParallelCheck"));
if (parser.Found(wxT("s")))
conn->Request(wxT("SetShutdownCheck"));
if (parser.Found(wxT("o")))
conn->Request(wxT("SetOverwriteCheck"));
if (parser.Found(wxT("v")))
conn->Request(wxT("SetVerboseCheck"));
conn->Request(wxT("BringWindowToTop"));
if(parser.Found(wxT("b")))
conn->Request(wxT("RunBatch"));
conn->Disconnect();
delete conn;
delete m_checker;
return false;
};
m_frame->SetCheckboxes();
m_frame->PropagateDefaults();
if (parser.Found(wxT("b")) ) {
m_frame->RunBatch();
}
return true;
}
int PTBatcherGUI::OnExit()
{
delete m_checker;
delete m_server;
return 0;
}
void PTBatcherGUI::OnItemActivated(wxListEvent &event)
{
wxCommandEvent dummy;
m_frame->OnButtonOpenWithHugin(dummy);
}
void PTBatcherGUI::OnKeyDown(wxKeyEvent &event)
{
wxCommandEvent dummy;
switch(event.GetKeyCode())
{
case WXK_DELETE:
m_frame->OnButtonRemoveFromList(dummy);
break;
case WXK_INSERT:
m_frame->OnButtonAddToList(dummy);
break;
case WXK_ESCAPE:
m_frame->OnButtonCancel(dummy);
break;
default:
event.Skip();
break;
}
}
#ifdef __WXMAC__
// wx calls this method when the app gets "Open file" AppleEvent
void PTBatcherGUI::MacOpenFile(const wxString &fileName)
{
if(!m_frame)
m_macFileNameToOpenOnStart = fileName;
else
{
wxFileName fn(fileName);
m_frame->AddToList(fn.GetFullPath());
}
}
#endif
wxChar* BatchIPCConnection::OnRequest(const wxString& topic, const wxString& item, int *size, wxIPCFormat format)
{
BatchFrame *MyBatchFrame=wxGetApp().GetFrame();
if(item.Left(1)==wxT("A"))
{
MyBatchFrame->AddToList(item.Mid(2));
return wxT("");
};
if(item.Left(1)==wxT("D"))
{
MyBatchFrame->AddToList(item.Mid(2),Project::DETECTING);
return wxT("");
};
if(item.Left(1)==wxT("P"))
{
MyBatchFrame->ChangePrefix(-1,item.Mid(2));
return wxT("");
};
wxCommandEvent event;
event.SetInt(1);
if(item==wxT("SetDeleteCheck"))
if(!MyBatchFrame->GetCheckDelete())
{
MyBatchFrame->OnCheckDelete(event);
MyBatchFrame->SetCheckboxes();
};
if(item==wxT("SetParallelCheck"))
if(!MyBatchFrame->GetCheckParallel())
{
MyBatchFrame->OnCheckParallel(event);
MyBatchFrame->SetCheckboxes();
};
if(item==wxT("SetShutdownCheck"))
if(!MyBatchFrame->GetCheckShutdown())
{
MyBatchFrame->OnCheckShutdown(event);
MyBatchFrame->SetCheckboxes();
};
if(item==wxT("SetOverwriteCheck"))
if(!MyBatchFrame->GetCheckOverwrite())
{
MyBatchFrame->OnCheckOverwrite(event);
MyBatchFrame->SetCheckboxes();
};
if(item==wxT("SetVerboseCheck"))
if(!MyBatchFrame->GetCheckVerbose())
{
MyBatchFrame->OnCheckVerbose(event);
MyBatchFrame->SetCheckboxes();
};
if(item==wxT("BringWindowToTop"))
MyBatchFrame->RequestUserAttention();
if(item==wxT("RunBatch"))
{
wxCommandEvent myEvent(wxEVT_COMMAND_TOOL_CLICKED ,XRCID("tool_start"));
MyBatchFrame->GetEventHandler()->AddPendingEvent(myEvent);
};
return wxT("");
};
wxConnectionBase* BatchIPCServer::OnAcceptConnection (const wxString& topic)
{
if(topic==IPC_START)
return new BatchIPCConnection;
return NULL;
};