Hugin trunk 0.1
Loading...
Searching...
No Matches
platform.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
27#include "platform.h"
28
29#include <hugin_utils/utils.h>
30#include "wxutils.h"
31#include <vigra/imageinfo.hxx>
32
35{
37 extensionString.Append(ext);
38 if (wxFileName::IsCaseSensitive())
39 {
40 extensionString.Append(";*.").Append(ext.Upper());
41 };
42 return extensionString;
43};
44
46{
48 const std::string extensions = vigra::impexListExtensions();
49 std::vector<std::string> exts = hugin_utils::SplitString(extensions, " ");
50 if (exts.empty())
51 {
52 // if something goes wrong, add some defaults
53 exts.push_back("tif");
54 exts.push_back("tiff");
55 exts.push_back("jpg");
56 exts.push_back("jpeg");
57 exts.push_back("png");
58 }
59 filterString.Append(_("All Image files")).Append("|");
60 for (auto& ext : exts)
61 {
63 };
64 // remove last character == ";"
65 filterString.RemoveLast();
66 filterString.Append("|");
67 return filterString;
68};
69
71{
73 // append JPG/TIFF/PNG
75 filterString.Append("|").Append(_("HDR files (*.hdr)")).Append("|").Append(GetFilterExtensions("hdr"));
76 filterString.Append("|").Append(_("EXR files (*.exr)")).Append("|").Append(GetFilterExtensions("exr"));
77 filterString.Append("|").Append(_("All files (*)")).Append("|*");
78 return filterString;
79}
80
82{
84 filterString.Append(_("JPEG files (*.jpg,*.jpeg)")).Append("|").Append(GetFilterExtensions("jpg")).Append(";").Append(GetFilterExtensions("jpeg"));
85 filterString.Append("|").Append(_("TIFF files (*.tif,*.tiff)")).Append("|").Append(GetFilterExtensions("tif")).Append(";").Append(GetFilterExtensions("tiff"));
86 filterString.Append("|").Append(_("PNG files (*.png)")).Append("|").Append(GetFilterExtensions("png"));
87 return filterString;
88}
89
91{
93 // now the raw formats
94 const std::vector<std::string> exts = hugin_utils::GetRawExtensions();
95 filterString.Append(_("Raw files")).Append("|");
96 for (auto& ext : exts)
97 {
99 };
100 // remove last character == ";"
101 filterString.RemoveLast();
102 filterString.Append("|");
103 // now add some image format at its own
104 filterString.Append(_("JPEG files (*.jpg,*.jpeg)")).Append("|").Append(GetFilterExtensions("jpg")).Append(";").Append(GetFilterExtensions("jpeg"));
105 filterString.Append("|").Append(_("TIFF files (*.tif,*.tiff)")).Append("|").Append(GetFilterExtensions("tif")).Append(";").Append(GetFilterExtensions("tiff"));
106 filterString.Append("|").Append(_("PNG files (*.png)")).Append("|").Append(GetFilterExtensions("png"));
107 filterString.Append("|").Append(_("HDR files (*.hdr)")).Append("|").Append(GetFilterExtensions("hdr"));
108 filterString.Append("|").Append(_("EXR files (*.exr)")).Append("|").Append(GetFilterExtensions("exr"));
109 return filterString;
110};
111
113{
114 const std::vector<std::string> rawExts = hugin_utils::GetRawExtensions();
115 for (auto& ext : rawExts)
116 {
117 if (testExt.CmpNoCase(wxString(ext.c_str(), wxConvLocal)) == 0)
118 {
119 return true;
120 };
121 };
122 return false;
123};
124
125#if defined __WXMAC__ || defined __WXOSX_COCOA__
126
127#include <CoreFoundation/CFBundle.h>
128 #include "wx/osx/core/cfstring.h"
129#include <iostream>
130#include <stdio.h>
131#include "wx/utils.h"
132
133using namespace std;
134
135// note this is a "create" function for ownership
137{
139 (const char*)string.mb_str(wxConvUTF8),
141
142}
143
145{
147
149
150 if(bundleURL == NULL)
151 {
152 DEBUG_INFO("Mac: CFURL from string (" << bundlePath << ") failed." );
153 return theResult;
154 }
155
158
159 if(bundle == NULL)
160 {
161 DEBUG_INFO("Mac: CFBundleCreate (" << bundlePath << " ) failed" );
162 }
163 else
164 {
166 CFRelease( bundle );
167 if(PTOurl == NULL)
168 {
169 DEBUG_INFO("Mac: Cannot locate the executable in the bundle.");
170 }
171 else
172 {
174 CFRelease( PTOurl );
175 if(PTOAbsURL == NULL)
176 {
177 DEBUG_INFO("Mac: Cannot convert the file path to absolute");
178 }
179 else
180 {
183 if(pathInCFString == NULL)
184 {
185 DEBUG_INFO("Mac: Failed to get URL in CFString");
186 }
187 else
188 {
191 DEBUG_INFO("Mac: the executable's full path in the application bundle: " << theResult.mb_str(wxConvLocal));
192 }
193 }
194 }
195 }
196 return theResult;
197}
198
200{
202
207 FSRef documentArray[1]; // Don't really need an array if we only have 1 item
209 //Boolean isDir;
210
212 CFSTR("net.sourceforge.hugin.PTBatcherGUI"),
213 NULL,
214 &appRef,
215 &bundleURL);
216 if (err != noErr) {
217 // error, can't find PTBatcherGUI
218 cout << "PTBatcherGui check failed \n" << endl;
219 hugin_utils::HuginMessageBox(wxString::Format(_("External program %s not found in the bundle, reverting to system path"), "open"), _("Hugin"), wxOK, wxGetActiveWindow());
220 }
221 if(bundleURL == NULL)
222 {
223 DEBUG_INFO("Mac: CFURL from string (" << bundleURL << ") failed." );
224 return theResult;
225 }
226
229
230 if(bundle == NULL)
231 {
232 DEBUG_INFO("Mac: CFBundleCreate (" << bundleURL << " ) failed" );
233 }
234 else
235 {
237 CFRelease( bundle );
238 if(PTOurl == NULL)
239 {
240 DEBUG_INFO("Mac: Cannot locate the executable in the bundle.");
241 }
242 else
243 {
245 CFRelease( PTOurl );
246 if(PTOAbsURL == NULL)
247 {
248 DEBUG_INFO("Mac: Cannot convert the file path to absolute");
249 }
250 else
251 {
254 if(pathInCFString == NULL)
255 {
256 DEBUG_INFO("Mac: Failed to get URL in CFString");
257 }
258 else
259 {
262 DEBUG_INFO("Mac: the executable's full path in the application bundle: " << theResult.mb_str(wxConvLocal));
263 }
264 }
265 }
266 }
267 cout << "PTBatcherGui check returned value " << theResult << "\n" << endl;
268 return theResult;
269}
270
271#if defined MAC_SELF_CONTAINED_BUNDLE
272
274{
276
278 if(mainbundle == NULL)
279 {
280 DEBUG_INFO("Mac: Not bundled");
281 }
282 else
283 {
285 if(XRCurl == NULL)
286 {
287 DEBUG_INFO("Mac: Cannot locate the bundle in bundle.");
288 }
289 else
290 {
292 CFRelease( XRCurl );
293
294 if(bundledBundle == NULL)
295 {
296 DEBUG_INFO("Mac: Not bundled");
297 }
298 else
299 {
302
303 if(PTOurl == NULL)
304 {
305 DEBUG_INFO("Mac: Cannot locate the executable in the bundle.");
306 }
307 else
308 {
310 CFRelease( PTOurl );
311 if(PTOAbsURL == NULL)
312 {
313 DEBUG_INFO("Mac: Cannot convert the file path to absolute");
314 }
315 else
316 {
319 if(pathInCFString == NULL)
320 {
321 DEBUG_INFO("Mac: Failed to get URL in CFString");
322 }
323 else
324 {
327 DEBUG_INFO("Mac: the executable's full path in the application bundle: " << theResult.mb_str(wxConvLocal));
328 }
329 }
330 }
331 }
332 }
333 }
334 return theResult;
335}
336
338{
340
342 if(mainbundle == NULL)
343 {
344 DEBUG_INFO("Mac: Not bundled");
345 }
346 else
347 {
349 if(XRCurl == NULL)
350 {
351 DEBUG_INFO("Mac: Cannot locate the file in bundle.");
352 }
353 else
354 {
356 CFRelease( XRCurl );
357 if(pathInCFString == NULL)
358 {
359 DEBUG_INFO("Mac: Failed to get URL in CFString");
360 }
361 else
362 {
365 DEBUG_INFO("Mac: the resource file's path in the application bundle: " << theResult.mb_str(wxConvLocal));
366 }
367 }
368 }
369 return theResult;
370}
371
373{
375
377 if(mainbundle == NULL)
378 {
379 DEBUG_INFO("Mac: Not bundled");
380 }
381 else
382 {
384 if(XRCurl == NULL)
385 {
386 DEBUG_INFO("Mac: Cannot locate the file in bundle.");
387 }
388 else
389 {
391 CFRelease( XRCurl );
392 if(pathInCFString == NULL)
393 {
394 DEBUG_INFO("Mac: Failed to get URL in CFString");
395 }
396 else
397 {
400 DEBUG_INFO("Mac: the Frameworks file's path in the application bundle: " << theResult.mb_str(wxConvLocal));
401 }
402 }
403 }
404 return theResult + "/Contents/Frameworks";
405}
406
408{
410
412 if(mainbundle == NULL)
413 {
414 DEBUG_INFO("Mac: Not bundled");
415 }
416 else
417 {
419 if(PTOurl == NULL)
420 {
421 DEBUG_INFO("Mac: Cannot locate the file in the bundle.");
422 }
423 else
424 {
426 if(PTOAbsURL == NULL)
427 {
428 DEBUG_INFO("Mac: Cannot convert the file path to absolute");
429 }
430 else
431 {
434 if(pathInCFString == NULL)
435 {
436 DEBUG_INFO("Mac: Failed to get URL in CFString");
437 }
438 else
439 {
442 DEBUG_INFO("Mac: executable's full path in the application bundle: " << theResult.mb_str(wxConvLocal));
443 }
444 }
445 CFRelease( PTOurl );
446 }
447 }
448 return theResult;
449}
450
452{
454
457 if (err == noErr)
458 {
460 if (tempDirURL != NULL)
461 {
464 tmpDirPath = wxCFStringRef(tmpPath).AsString();
466 }
467 }
468
469 return tmpDirPath;
470}
471
473{
475
478 if( err == noErr)
479 {
487 }
489}
490
491
492#endif // MAC_SELF_CONTAINED_BUNDLE
493
494#endif // __WXMAC__
495
497{
498#if defined __WXMSW__
499 // the characters :"*?<>| are not allowed in filenames, these are handled well by the file dialog
500 // all other characters should work
501 return wxEmptyString;
502#else
503 // the characters =;:% does not work with the makefile
504 // we are also rejecting the characters <>*?| which are principally allowed in filenames but will probably make problems when used
505 // the double quote does not work with the panotools file format, so also reject
506 //@BUG tilde ~ and backslash \ are not working with vigraimpex, if this works again these characters can be removed from the list
507 return "*?<>|\"\\~";
508#endif
509};
510
512{
513 if(stringToTest.IsEmpty())
514 return false;
516 for(unsigned int j=0;j<forbiddenChars.size();j++)
517 {
519 return true;
520 };
521 return false;
522};
523
525{
526 wxDialog dlg;
527 wxXmlResource::Get()->LoadDialog(&dlg, parent, "dlg_warning_filename");
528 XRCCTRL(dlg, "dlg_warning_text", wxStaticText)->SetLabel(wxString::Format(_("The filename(s) contains one of the following invalid characters: %s\nHugin can not work with these filenames. Please rename your file(s) and try again."), getInvalidCharacters().c_str()));
529 XRCCTRL(dlg, "dlg_warning_list", wxListBox)->Append(filelist);
530 dlg.Fit();
531 dlg.CenterOnScreen();
532 dlg.ShowModal();
533};
534
535#if wxUSE_ON_FATAL_EXCEPTION
536void GenerateReport(wxDebugReport::Context ctx)
537{
538 //from the debugrpt sample inspired
540 report.AddAll(ctx);
542 {
543 if (report.Process())
544 {
545 wxLogMessage(_("Debug report generated in \"%s\"."), report.GetCompressedFileName().c_str());
546 report.Reset();
547 };
548 };
549};
550#endif
platform/compiler specific stuff.
#define DEBUG_INFO(msg)
Definition utils.h:69
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition wxutils.cpp:176
std::vector< std::string > SplitString(const std::string &s, const std::string &sep)
split string s at given sep, returns vector of strings
Definition utils.cpp:294
std::vector< std::string > GetRawExtensions()
return vector of known extensions of raw files, all lower case
Definition utils.cpp:964
wxString GetFileDialogImageFilters()
return filter for image files, needed by file open dialog it contains all image format vigra can read...
Definition platform.cpp:70
wxString GetFilterExtensions(const wxString &ext)
build filter string "*.ext", adds also upper case version for UNIX paths when needed
Definition platform.cpp:34
bool IsRawExtension(const wxString &testExt)
return true, if given extension is in list of known raw extension (comparision is case insensitive
Definition platform.cpp:112
bool containsInvalidCharacters(const wxString stringToTest)
returns true, if the given strings contains invalid characters
Definition platform.cpp:511
void ShowFilenameWarning(wxWindow *parent, const wxArrayString filelist)
shows a dialog about filename with invalid characters, all names in filelist will be show in list
Definition platform.cpp:524
wxString GetFileDialogImageAndRawFilters()
return filter for image and raw files, needed by file open dialog
Definition platform.cpp:90
wxString GetVigraImageFilter()
Definition platform.cpp:45
const wxString getInvalidCharacters()
returns all invalid characters for the filename (mainly characters, which does not work with gnu make...
Definition platform.cpp:496
wxString GetMainImageFilters()
return a filter for the main image files (JPG/TIFF/PNG) only
Definition platform.cpp:81
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