[519868]: src / hugin1 / hugin / huginApp.cpp Maximize Restore History

Download this file

huginApp.cpp    509 lines (436 with data), 17.6 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
// -*- c-basic-offset: 4 -*-
/** @file huginApp.cpp
*
* @brief implementation of huginApp Class
*
* @author Pablo d'Angelo <pablo.dangelo@web.de>
*
* $Id$
*
* 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 <config.h>
#include "panoinc_WX.h"
#ifdef __WXMAC__
#include <wx/sysopt.h>
#endif
#include "panoinc.h"
#include "hugin/config_defaults.h"
#include "hugin/huginApp.h"
#include "hugin/AssistantPanel.h"
#include "hugin/ImagesPanel.h"
#include "hugin/CropPanel.h"
#include "hugin/CPEditorPanel.h"
#include "hugin/OptimizePhotometricPanel.h"
#include "hugin/PanoPanel.h"
#include "hugin/LensPanel.h"
#include "hugin/ImagesList.h"
#include "hugin/PreviewPanel.h"
#include "hugin/GLPreviewFrame.h"
#include "hugin/CommandHistory.h"
#include "hugin/wxPanoCommand.h"
#include "base_wx/platform.h"
#include "base_wx/huginConfig.h"
#include <tiffio.h>
using namespace utils;
// utility functions
bool str2double(wxString s, double & d)
{
if (!utils::stringToDouble(std::string(s.mb_str(wxConvLocal)), d)) {
wxLogError(_("Value must be numeric."));
return false;
}
return true;
}
wxString getDefaultProjectName(const Panorama & pano)
{
if (pano.getNrOfImages() > 0) {
wxString first_img(stripExtension(stripPath(pano.getImage(0).getFilename())).c_str(), HUGIN_CONV_FILENAME);
wxString last_img(stripExtension(stripPath(pano.getImage(pano.getNrOfImages()-1).getFilename())).c_str(), HUGIN_CONV_FILENAME);
return first_img + wxT("-") + last_img;
} else {
return wxString(wxT("pano"));
}
}
// make wxwindows use this class as the main application
IMPLEMENT_APP(huginApp)
huginApp::huginApp()
{
DEBUG_TRACE("ctor");
m_this=this;
}
huginApp::~huginApp()
{
DEBUG_TRACE("dtor");
// delete temporary dir
// if (!wxRmdir(m_workDir)) {
// DEBUG_ERROR("Could not remove temporary directory");
// }
// todo: remove all listeners from the panorama object
// delete frame;
DEBUG_TRACE("dtor end");
}
bool huginApp::OnInit()
{
DEBUG_TRACE("=========================== huginApp::OnInit() begin ===================");
SetAppName(wxT("hugin"));
#ifdef __WXMAC__
// do not use the native list control on OSX (it is very slow with the control point list window)
wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), 1);
#endif
// required by wxHtmlHelpController
wxFileSystem::AddHandler(new wxZipFSHandler);
#if defined __WXMSW__
wxString huginExeDir = getExePath(argv[0]);
wxString huginRoot;
wxFileName::SplitPath( huginExeDir, &huginRoot, NULL, NULL );
m_xrcPrefix = huginRoot + wxT("/share/hugin/xrc/");
m_DataDir = huginRoot + wxT("/share/hugin/data/");
m_utilsBinDir = huginRoot + wxT("/bin/");
// locale setup
locale.AddCatalogLookupPathPrefix(huginRoot + wxT("/share/locale"));
#elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
// initialize paths
{
wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
if (thePath == wxT("")) {
wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
return false;
}
m_xrcPrefix = thePath + wxT("/");
m_DataDir = thePath + wxT("/");
}
{
wxString thePath = MacGetPathToBundledResourceFile(CFSTR("locale"));
if(thePath != wxT(""))
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_DataDir = wxT(INSTALL_DATA_DIR);
locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
#endif
if ( ! wxFile::Exists(m_xrcPrefix + wxT("/main_frame.xrc")) ) {
wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
return false;
}
// here goes and comes configuration
wxConfigBase * config = wxConfigBase::Get();
// update incompatible configuration entries.
updateHuginConfig(config);
// do not record default values in the preferences file
config->SetRecordDefaults(false);
config->Flush();
// initialize i18n
int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
DEBUG_TRACE("localeID: " << localeID);
{
bool bLInit;
bLInit = locale.Init(localeID);
if (bLInit) {
DEBUG_TRACE("locale init OK");
DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
} else {
DEBUG_TRACE("locale init failed");
}
}
// set the name of locale recource to look for
locale.AddCatalog(wxT("hugin"));
// initialize image handlers
wxInitAllImageHandlers();
// Initialize all the XRC handlers.
wxXmlResource::Get()->InitAllHandlers();
// load all XRC files.
#ifdef _INCLUDE_UI_RESOURCES
InitXmlResource();
#else
// add custom XRC handlers
wxXmlResource::Get()->AddHandler(new AssistantPanelXmlHandler());
wxXmlResource::Get()->AddHandler(new ImagesPanelXmlHandler());
wxXmlResource::Get()->AddHandler(new LensPanelXmlHandler());
wxXmlResource::Get()->AddHandler(new ImagesListImageXmlHandler());
wxXmlResource::Get()->AddHandler(new ImagesListLensXmlHandler());
wxXmlResource::Get()->AddHandler(new ImagesListCropXmlHandler());
wxXmlResource::Get()->AddHandler(new CropPanelXmlHandler());
wxXmlResource::Get()->AddHandler(new CenterCanvasXmlHandler());
wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler());
wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler());
wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler());
wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
// load XRC files
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("crop_panel.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_list_frame.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("preview_frame.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("run_optimizer_frame.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_script_dialog.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("run_stitcher_frame.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_menu.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_tool.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_text.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("about.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("help.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("keyboard_help.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pref_dialog.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cpdetector_dialog.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("reset_dialog.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("vig_corr_dlg.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_photo_panel.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_editor_panel.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("images_panel.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lens_panel.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("assistant_panel.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_frame.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_panel.xrc"));
wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pano_panel.xrc"));
#endif
#ifdef __WXMAC__
// If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
// Those need to be initialised before first call of Yield which happens in Mainframe constructor.
m_macInitDone=false;
m_macOpenFileOnStart=false;
#endif
// create main frame
frame = new MainFrame(NULL, pano);
SetTopWindow(frame);
// restore layout
frame->RestoreLayoutOnNextResize();
// setup main frame size, after it has been created.
RestoreFramePosition(frame, wxT("MainFrame"));
#ifdef __WXMSW__
frame->SendSizeEvent();
#endif
// show the frame.
frame->Show(TRUE);
wxString cwd = wxFileName::GetCwd();
m_workDir = config->Read(wxT("tempDir"),wxT(""));
// FIXME, make secure against some symlink attacks
// get a temp dir
if (m_workDir == wxT("")) {
#if (defined __WXMSW__)
DEBUG_DEBUG("figuring out windows temp dir");
/* added by Yili Zhao */
wxChar buffer[MAX_PATH];
GetTempPath(MAX_PATH, buffer);
m_workDir = buffer;
#elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
DEBUG_DEBUG("temp dir on Mac");
m_workDir = MacGetPathToUserDomainTempDir();
if(m_workDir == wxT(""))
m_workDir = wxT("/tmp");
#else //UNIX
DEBUG_DEBUG("temp dir on unix");
// try to read environment variable
if (!wxGetEnv(wxT("TMPDIR"), &m_workDir)) {
// still no tempdir, use /tmp
m_workDir = wxT("/tmp");
}
#endif
}
if (!wxFileName::DirExists(m_workDir)) {
DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
if (!wxMkdir(m_workDir)) {
DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
}
}
if (!wxSetWorkingDirectory(m_workDir)) {
DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
}
DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
// set some suitable defaults
PanoramaOptions opts = pano.getOptions();
opts.outputFormat = PanoramaOptions::TIFF;
opts.blendMode = PanoramaOptions::ENBLEND_BLEND;
opts.enblendOptions = config->Read(wxT("Enblend/Args"),wxT(HUGIN_ENBLEND_ARGS)).mb_str(wxConvLocal);
opts.enfuseOptions = config->Read(wxT("Enfuse/Args"),wxT(HUGIN_ENFUSE_ARGS)).mb_str(wxConvLocal);
opts.interpolator = (vigra_ext::Interpolator)config->Read(wxT("Nona/Interpolator"),HUGIN_NONA_INTERPOLATOR);
opts.remapUsingGPU = (bool)config->Read(wxT("Nona/useGPU"),HUGIN_NONA_USEGPU);
opts.tiff_saveROI = (bool)config->Read(wxT("Nona/CroppedImages"),HUGIN_NONA_CROPPEDIMAGES);
pano.setOptions(opts);
if (argc > 1) {
wxFileName file(argv[1]);
// if the first file is a project file, open it
if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
file.GetExt().CmpNoCase(wxT("pts")) == 0 ||
file.GetExt().CmpNoCase(wxT("ptp")) == 0 )
{
wxString filename(argv[1]);
if (! wxIsAbsolutePath(filename)) {
filename.Prepend(wxFileName::GetPathSeparator());
filename.Prepend(cwd);
}
frame->LoadProjectFile(filename);
} else {
std::vector<std::string> filesv;
for (int i=1; i< argc; i++) {
wxFileName file(argv[i]);
if (file.GetExt().CmpNoCase(wxT("jpg")) == 0 ||
file.GetExt().CmpNoCase(wxT("jpeg")) == 0 ||
file.GetExt().CmpNoCase(wxT("tif")) == 0 ||
file.GetExt().CmpNoCase(wxT("tiff")) == 0 ||
file.GetExt().CmpNoCase(wxT("png")) == 0 ||
file.GetExt().CmpNoCase(wxT("bmp")) == 0 ||
file.GetExt().CmpNoCase(wxT("gif")) == 0 ||
file.GetExt().CmpNoCase(wxT("pnm")) == 0 ||
file.GetExt().CmpNoCase(wxT("sun")) == 0 ||
file.GetExt().CmpNoCase(wxT("hdr")) == 0 ||
file.GetExt().CmpNoCase(wxT("viff")) == 0 )
{
filesv.push_back((const char *)(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
}
}
GlobalCmdHist::getInstance().addCommand(
new PT::wxAddImagesCmd(pano,filesv)
);
}
}
#ifdef __WXMAC__
m_macInitDone = true;
if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
m_macOpenFileOnStart = false;
#endif
//check for no tip switch, needed by PTBatcher
wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
if(secondParam.Cmp(_T("-notips"))!=0)
{
//load tip startup preferences (tips will be started after splash terminates)
int nValue = config->Read(wxT("/MainFrame/ShowStartTip"), 1l);
//show tips if needed now
if(nValue > 0)
{
wxCommandEvent dummy;
frame->OnTipOfDay(dummy);
}
}
// suppress tiff warnings
TIFFSetWarningHandler(0);
pano.changeFinished();
pano.clearDirty();
DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
return true;
}
int huginApp::OnExit()
{
DEBUG_TRACE("");
return wxApp::OnExit();
}
huginApp * huginApp::Get()
{
if (m_this) {
return m_this;
} else {
DEBUG_FATAL("huginApp not yet created");
DEBUG_ASSERT(m_this);
return 0;
}
}
#ifdef __WXMAC__
void huginApp::MacOpenFile(const wxString &fileName)
{
if(!m_macInitDone)
{
m_macOpenFileOnStart=true;
m_macFileNameToOpenOnStart = fileName;
return;
}
if(frame) frame->MacOnOpenFile(fileName);
}
#endif
huginApp * huginApp::m_this = 0;
// utility functions
void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
{
DEBUG_TRACE(basename.mb_str(wxConvLocal));
wxConfigBase * config = wxConfigBase::Get();
#if ( __WXGTK__ ) && wxCHECK_VERSION(2,6,0)
// restoring the splitter positions properly when maximising doesn't work.
// Disabling maximise on wxWidgets >= 2.6.0 and gtk
//size
int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
if (w >0) {
frame->SetClientSize(w,h);
} else {
frame->Fit();
}
//position
int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
if ( y >= 0 && x >= 0 && x < 4000 && y < 4000) {
frame->Move(x, y);
} else {
frame->Move(0, 44);
}
#else
bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
if (maximized) {
frame->Maximize();
} else {
//size
int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
if (w >0) {
frame->SetClientSize(w,h);
} else {
frame->Fit();
}
//position
int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
if ( y >= 0 && x >= 0) {
frame->Move(x, y);
} else {
frame->Move(0, 44);
}
}
#endif
}
void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
{
DEBUG_TRACE(basename);
wxConfigBase * config = wxConfigBase::Get();
#if ( __WXGTK__ ) && wxCHECK_VERSION(2,6,0)
// restoring the splitter positions properly when maximising doesn't work.
// Disabling maximise on wxWidgets >= 2.6.0 and gtk
wxSize sz = frame->GetClientSize();
config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
wxPoint ps = frame->GetPosition();
config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
config->Write(wxT("/") + basename + wxT("/maximized"), 0);
#else
if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
wxSize sz = frame->GetClientSize();
config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
wxPoint ps = frame->GetPosition();
config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
config->Write(wxT("/") + basename + wxT("/maximized"), 0);
} else if (frame->IsMaximized()){
config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
}
#endif
}