1 // -*- c-basic-offset: 4 -*-
2 /** @file base_wx/wxutils.h
3  *
4  *  @author Pablo d'Angelo <pablo.dangelo@web.de>
5  */
6 
7 /*  This is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU General Public
9  *  License as published by the Free Software Foundation; either
10  *  version 2 of the License, or (at your option) any later version.
11  *
12  *  This software is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public
18  *  License along with this software. If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef _BASE_WX_WXUTILS_H
24 #define _BASE_WX_WXUTILS_H
25 
26 #include <hugin_utils/utils.h>
27 
28 // use trace function under windows, because usually there is
29 // no stdout under windows
30 #ifdef __WXMSW__
31     #include <wx/string.h>
32     #include <wx/log.h>
33 
34     #ifdef DEBUG
35         #undef DEBUG_TRACE
36         #undef DEBUG_DEBUG
37         #undef DEBUG_INFO
38         #undef DEBUG_NOTICE
39 
40         // debug trace
41 //      #define DEBUG_TRACE(msg) { std::stringstream o; o << "TRACE " << DEBUG_HEADER << msg; wxLogDebug(o.str().c_str());}
42         #define DEBUG_TRACE(msg) { std::cerr << "TRACE " << DEBUG_HEADER << msg << std::endl; }
43         // low level debug info
44 //      #define DEBUG_DEBUG(msg) { std::stringstream o; o << "DEBUG " << DEBUG_HEADER << msg; wxLogDebug(o.str().c_str()); }
45         #define DEBUG_DEBUG(msg) { std::cerr << "DEBUG " << DEBUG_HEADER << msg << std::endl; }
46         // informational debug message,
47 //      #define DEBUG_INFO(msg) { std::stringstream o; o << "INFO " << DEBUG_HEADER << msg; wxLogDebug(o.str().c_str()); }
48         #define DEBUG_INFO(msg) { std::cerr << "INFO " << DEBUG_HEADER << msg << std::endl; }
49         // major change/operation should use this
50 //      #define DEBUG_NOTICE(msg) { std::stringstream o; o << "NOTICE " << DEBUG_HEADER << msg; wxLogMessage(o.str().c_str()); }
51         #define DEBUG_NOTICE(msg) { std::cerr << "NOTICE " << DEBUG_HEADER << msg << std::endl; }
52     #endif
53 
54     #undef DEBUG_WARN
55     #undef DEBUG_ERROR
56     #undef DEBUG_FATAL
57     #undef DEBUG_ASSERT
58 
59     // when an error occurred, but can be handled by the same function
60     #define DEBUG_WARN(msg) { std::stringstream o; o << "WARN: " << DEBUG_HEADER << msg; wxLogWarning(wxString(o.str().c_str(), wxConvISO8859_1));}
61     // an error occurred, might be handled by a calling function
62     #define DEBUG_ERROR(msg) { std::stringstream o; o << "ERROR: " << DEBUG_HEADER << msg; wxLogError(wxString(o.str().c_str(),wxConvISO8859_1));}
63     // a fatal error occurred. further program execution is unlikely
64     #define DEBUG_FATAL(msg) { std::stringstream o; o << "FATAL: " << DEBUG_HEADER << "(): " << msg; wxLogError(wxString(o.str().c_str(),wxConvISO8859_1)); }
65     // assertion
66     #define DEBUG_ASSERT(cond) \
67         do { \
68             if (!(cond)) { \
69                 std::stringstream o; o << "ASSERTATION: " << DEBUG_HEADER << "(): " << #cond; \
70                     wxLogFatalError(wxString(o.str().c_str(),wxConvISO8859_1)); \
71             } \
72         } while(0)
73 #endif
74 
75 
76 #endif // _BASE_WX_WXUTILS_H
77