Hugin trunk 0.1
Loading...
Searching...
No Matches
hugin_stitch_project.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
27#include <hugin_config.h>
28#include "panoinc_WX.h"
29#include "panoinc.h"
30
31#include <wx/wfstream.h>
32#if defined __WXMSW__ || defined UNIX_SELF_CONTAINED_BUNDLE
33#include <wx/stdpaths.h>
34#endif
35
36#include <fstream>
37#include <sstream>
39#include "base_wx/huginConfig.h"
41#include "base_wx/platform.h"
42#include "base_wx/wxPlatform.h"
43#include "base_wx/wxutils.h"
44
45#include <tiffio.h>
46
47// somewhere SetDesc gets defined.. this breaks wx/cmdline.h on OSX
48#ifdef SetDesc
49#undef SetDesc
50#endif
51
52#include <wx/cmdline.h>
53
54class RunStitchFrame: public wxFrame
55{
56public:
57 RunStitchFrame(wxWindow * parent, const wxString& title, const wxPoint& pos, const wxSize& size);
58
60
61 void OnQuit(wxCommandEvent& event);
62 void OnAbout(wxCommandEvent& event);
63 void OnProgress(wxCommandEvent& event);
65 void SetOverwrite(bool doOverwrite);
66
67private:
68
69 bool m_isStitching;
73
75 void OnCancel(wxCommandEvent & event);
76
78};
79
80// event ID's for RunStitchPanel
81enum
82{
85};
86
87RunStitchFrame::RunStitchFrame(wxWindow * parent, const wxString& title, const wxPoint& pos, const wxSize& size)
88 : wxFrame(parent, -1, title, pos, size), m_isStitching(false)
89{
91 m_stitchPanel = new RunStitchPanel(this);
92
93 topsizer->Add(m_stitchPanel, 1, wxEXPAND | wxALL, 2);
94
97 bottomsizer->Add(m_progress, 1, wxEXPAND | wxALL, 10);
98 bottomsizer->Add( new wxButton(this, wxID_CANCEL, _("Cancel")),
99 0, wxALL, 10);
100 topsizer->Add(bottomsizer, 0, wxEXPAND);
101
102#ifdef __WXMSW__
103 // wxFrame does have a strange background color on Windows..
104 this->SetBackgroundColour(m_stitchPanel->GetBackgroundColour());
105#endif
106
107 // setup the environment for the different operating systems
109#if defined __WXMSW__
110 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
111 exePath.RemoveLastDir();
112 wxIconBundle myIcons(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + "share\\hugin\\xrc\\data\\hugin.ico", wxBITMAP_TYPE_ICO);
114#else
116#if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
117 {
119 if (!exec_path.IsEmpty())
120 {
121 xrcPrefix = exec_path + "/";
122 }
123 else
124 {
125 hugin_utils::HuginMessageBox(_("xrc directory not found in bundle"), _("Hugin_stitch_project"), wxOK | wxICON_ERROR, wxGetActiveWindow());
126 }
127 }
128#elif defined UNIX_SELF_CONTAINED_BUNDLE
129 // initialize paths
130 {
131 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
132 exePath.RemoveLastDir();
134 xrcPrefix = huginRoot + "share/hugin/xrc/";
135 }
136#else
137 // add the locale directory specified during configure
139#endif
140 if (!xrcPrefix.IsEmpty())
141 {
142 wxIcon myIcon(xrcPrefix + "data/hugin.png", wxBITMAP_TYPE_PNG);
144 }
145#endif
146
148// topsizer->SetSizeHints( this ); // set size hints to honour minimum size
149 m_deleteOnExit=false;
150 // bind event handler
156
157}
158
160{
161 hugin_utils::HuginMessageBox(wxString::Format(_("HuginStitchProject. Application to stitch hugin project files.\n Version: %s"), hugin_utils::GetHuginVersion()),
162 _("Hugin_stitch_project"), wxOK | wxICON_INFORMATION, this);
163}
165{
166 DEBUG_TRACE("");
167 if (m_isStitching) {
169 m_isStitching = false;
170 }
171 Close();
172}
173
174void RunStitchFrame::OnCancel(wxCommandEvent& WXUNUSED(event))
175{
176 DEBUG_TRACE("");
177 if (m_isStitching) {
179 m_isStitching = false;
180 } else {
181 Close();
182 }
183}
184
186{
187 if (! m_isStitching) {
188 // canceled stitch
189 // TODO: Cleanup files?
190 Close();
191 } else {
192 m_isStitching = false;
193 if (event.GetExitCode() != 0)
194 {
195 if (hugin_utils::HuginMessageBox(_("Error during stitching\nPlease report the complete text to the bug tracker on https://bugs.launchpad.net/hugin.\n\nDo you want to save the log file?"),
196 _("Hugin_stitch_project"), wxICON_ERROR | wxYES_NO, this) == wxYES)
197 {
198 wxString defaultdir = wxConfigBase::Get()->Read("/actualPath",wxEmptyString);
199 wxFileDialog dlg(this,
200 _("Specify log file"),
202 _("Log files (*.log)|*.log|All files (*)|*"),
204 dlg.SetDirectory(wxConfigBase::Get()->Read("/actualPath",wxEmptyString));
205 if (dlg.ShowModal() == wxID_OK)
206 {
207 wxConfig::Get()->Write("/actualPath", dlg.GetDirectory()); // remember for later
208 m_stitchPanel->SaveLog(dlg.GetPath());
209 };
210 }
211 } else {
213 {
215 };
216 Close();
217 }
218 }
219}
220
222{
223 if (event.GetInt() >= 0)
224 {
225 m_progress->SetValue(event.GetInt());
226 };
227};
228
239
244
245// **********************************************************************
246
247
252class stitchApp : public wxApp
253{
254public:
255
258 stitchApp();
259
262 virtual ~stitchApp();
263
266 virtual bool OnInit();
267
269 virtual int OnExit();
270
271#ifdef __WXMAC__
273 void MacOpenFile(const wxString &fileName);
274#endif
275
276private:
278#ifdef __WXMAC__
280#endif
281};
282
284{
285 // suppress tiff warnings
287
288 DEBUG_TRACE("ctor");
289}
290
292{
293 DEBUG_TRACE("dtor");
294 DEBUG_TRACE("dtor end");
295}
296
298{
299 // Required to access the preferences of hugin
300 SetAppName("hugin");
301#if defined __WXMSW__ && wxCHECK_VERSION(3,3,0)
302 // automatically switch between light and dark mode
303 SetAppearance(Appearance::System);
304#endif
305#if defined __WXGTK__
307#endif
308
309 // need to explicitly initialize locale for C++ library/runtime
310 setlocale(LC_ALL, "");
311 // initialize i18n
312#if defined __WXMSW__
313 int localeID = wxConfigBase::Get()->Read("language", (long) wxLANGUAGE_DEFAULT);
314 m_locale.Init(localeID);
315#else
317#endif
318
319 // setup the environment for the different operating systems
320#if defined __WXMSW__
321 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
322 exePath.RemoveLastDir();
323 // locale setup
324 m_locale.AddCatalogLookupPathPrefix(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + "share\\locale");
325
326#elif defined UNIX_SELF_CONTAINED_BUNDLE
327 // initialize paths
328 {
329 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
330 exePath.RemoveLastDir();
332 // add the locale directory specified during configure
333 m_locale.AddCatalogLookupPathPrefix(huginRoot + "share/locale");
334 }
335#else
336 // add the locale directory specified during configure
337 m_locale.AddCatalogLookupPathPrefix(INSTALL_LOCALE_DIR);
338#endif
339
340 // set the name of locale recource to look for
341 m_locale.AddCatalog("hugin");
342
343 // parse arguments
344 static const wxCmdLineEntryDesc cmdLineDesc[] =
345 {
346 //On wxWidgets 2.9, wide characters don't work here.
347 //On previous versions, the wxT macro is required for unicode builds.
348 { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
350 { wxCMD_LINE_OPTION, "o", "output", "output prefix" },
351 { wxCMD_LINE_SWITCH, "d", "delete", "delete pto file after stitching" },
352 { wxCMD_LINE_SWITCH, "w", "overwrite", "overwrite existing files" },
353 { wxCMD_LINE_OPTION, "u", "user-defined-output", "use user defined output" },
354 { wxCMD_LINE_PARAM, NULL, NULL, "<project>",
357 };
358
360
361 switch ( parser.Parse() ) {
362 case -1: // -h or --help was given, and help displayed so exit
363 return false;
364 break;
365 case 0: // all is well
366 break;
367 default:
368 wxLogError(_("Syntax error in parameters detected, aborting."));
369 return false;
370 break;
371 }
372
374#ifdef __WXMAC__
376 wxYield();
378
379 // bring myself front (for being called from command line)
380 {
383 if (err == noErr)
384 {
386 }
387 }
388#endif
389
391 parser.Found("u", &userDefinedOutput);
392 if (!userDefinedOutput.IsEmpty())
393 {
394 if (!wxFileName::FileExists(userDefinedOutput))
395 {
396 hugin_utils::HuginMessageBox(wxString::Format(_("Could not find the specified user output file \"%s\"."), userDefinedOutput),
397 _("Hugin_stitch_project"), wxOK | wxICON_EXCLAMATION, wxGetActiveWindow());
398 return false;
399 };
400 };
401 if( parser.GetParamCount() == 0 && wxIsEmpty(scriptFile))
402 {
403 wxString defaultdir = wxConfigBase::Get()->Read("/actualPath",wxEmptyString);
405 _("Specify project source project file"),
407 _("Project files (*.pto)|*.pto|All files (*)|*"),
409
410 dlg.SetDirectory(wxConfigBase::Get()->Read("/actualPath",wxEmptyString));
411 if (dlg.ShowModal() == wxID_OK) {
412 wxConfig::Get()->Write("/actualPath", dlg.GetDirectory()); // remember for later
413 scriptFile = dlg.GetPath();
414 } else { // bail
415 return false;
416 }
417 } else if(wxIsEmpty(scriptFile)) {
418 scriptFile = parser.GetParam(0);
419 std::cout << "********************* script file: " << (const char *)scriptFile.mb_str(wxConvLocal) << std::endl;
421 scriptFile = wxGetCwd() + wxFileName::GetPathSeparator() + scriptFile;
422 }
423 }
424
425 std::cout << "input file is " << (const char *)scriptFile.mb_str(wxConvLocal) << std::endl;
426
428
429 if ( !parser.Found("o", &outname) ) {
430 // ask for output.
431 wxFileDialog dlg(0,_("Specify output prefix"),
432 wxConfigBase::Get()->Read("/actualPath",wxEmptyString),
435 dlg.SetDirectory(wxConfigBase::Get()->Read("/actualPath",wxEmptyString));
436 if (dlg.ShowModal() == wxID_OK) {
437 while(containsInvalidCharacters(dlg.GetPath()))
438 {
439 hugin_utils::HuginMessageBox(wxString::Format(_("The given filename contains one of the following invalid characters: %s\nHugin can not work with this filename. Please enter a valid filename."), getInvalidCharacters()),
440 _("Hugin_stitch_project"), wxOK | wxICON_EXCLAMATION, wxGetActiveWindow());
441 if(dlg.ShowModal()!=wxID_OK)
442 return false;
443 };
444 wxFileName prefix(dlg.GetPath());
445 while (!prefix.IsDirWritable())
446 {
447 hugin_utils::HuginMessageBox(wxString::Format(_("You have no permissions to write in folder \"%s\".\nPlease select another folder for the final output."), prefix.GetPath().c_str()),
448 _("Hugin_stitch_project"), wxOK | wxICON_INFORMATION, wxGetActiveWindow());
449 if (dlg.ShowModal() != wxID_OK)
450 {
451 return false;
452 };
453 prefix = dlg.GetPath();
454 };
455
456 wxConfig::Get()->Write("/actualPath", dlg.GetDirectory()); // remember for later
457 outname = dlg.GetPath();
458 } else { // bail
459// wxLogError( _("No project files specified"));
460 return false;
461 }
462 }
463
464 // check output filename
466 wxString ext = outfn.GetExt();
467 // remove extension if it indicates an image file
468 if (ext.CmpNoCase("jpg") == 0 || ext.CmpNoCase("jpeg") == 0||
469 ext.CmpNoCase("tif") == 0|| ext.CmpNoCase("tiff") == 0 ||
470 ext.CmpNoCase("png") == 0 || ext.CmpNoCase("exr") == 0 ||
471 ext.CmpNoCase("pnm") == 0 || ext.CmpNoCase("hdr"))
472 {
473 outfn.ClearExt();
474 outname = outfn.GetFullPath();
475 }
476
477 RunStitchFrame *frame = new RunStitchFrame(NULL, "Hugin Stitcher", wxDefaultPosition, wxSize(640,600) );
478 frame->Show( true );
479 SetTopWindow( frame );
480
481 wxFileName basename(scriptFile);
482 frame->SetTitle(wxString::Format(_("%s - Stitching"), basename.GetName().c_str()));
483 frame->SetOverwrite(parser.Found("w"));
484 bool n = frame->StitchProject(scriptFile, outname, userDefinedOutput, parser.Found("d"));
485 return n;
486}
487
488
490{
491 DEBUG_TRACE("");
492 return 0;
493}
494
495
496#ifdef __WXMAC__
497// wx calls this method when the app gets "Open file" AppleEvent
498void stitchApp::MacOpenFile(const wxString &fileName)
499{
501}
502#endif
503
504// make wxwindows use this class as the main application
void OnQuit(wxCommandEvent &event)
void SetOverwrite(bool doOverwrite)
sets, if existing output file should be automatic overwritten
void OnCancel(wxCommandEvent &event)
RunStitchFrame(wxWindow *parent, const wxString &title, const wxPoint &pos, const wxSize &size)
void OnProcessTerminate(wxProcessEvent &event)
RunStitchPanel * m_stitchPanel
void OnAbout(wxCommandEvent &event)
void OnProgress(wxCommandEvent &event)
bool StitchProject(wxString scriptFile, wxString outname, wxString userDefinedOutput=wxEmptyString)
Starts stitching of project file.
void SetOverwrite(bool over=true)
bool SaveLog(const wxString &filename)
save the content of the window into a given log file
bool StitchProject(const wxString &scriptFile, const wxString &outname, const wxString &userDefinedOutput=wxEmptyString)
The application class for hugin_stitch_project.
virtual bool OnInit()
pseudo constructor.
virtual int OnExit()
just for testing purposes
virtual ~stitchApp()
dtor.
implementation of huginApp Class
functions for interaction with the hugin configuration file
#define DEBUG_TRACE(msg)
Definition utils.h:67
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition wxutils.cpp:176
std::string GetHuginVersion()
return a string with version numbers
Definition utils.cpp:907
include file for the hugin project
include file for the hugin project
bool containsInvalidCharacters(const wxString stringToTest)
returns true, if the given strings contains invalid characters
Definition platform.cpp:511
const wxString getInvalidCharacters()
returns all invalid characters for the filename (mainly characters, which does not work with gnu make...
Definition platform.cpp:496
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41
platform/compiler specific stuff.