You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
7.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Wayne Stambaugh <stambaughw@gmail.com>
  5. * Copyright (C) 2018-2021 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program 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
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file trace_helpers.h
  26. * @brief wxLogTrace helper definitions.
  27. */
  28. #ifndef _TRACE_HELPERS_H_
  29. #define _TRACE_HELPERS_H_
  30. #include <wx/arrstr.h>
  31. #include <wx/event.h>
  32. #include <wx/string.h>
  33. #include <stdarg.h>
  34. #include <map>
  35. /**
  36. * @defgroup trace_env_vars Trace Environment Variables
  37. *
  38. * wxWidgets provides trace control of debug messages using the WXTRACE environment variable.
  39. * This section defines the strings passed to WXTRACE to for debug output control of various
  40. * sections of the KiCad code. See the wxWidgets <a href="http://docs.wxwidgets.org/3.0/
  41. * group__group__funcmacro__log.html#ga947e317db477914c12b13c4534867ec9"> wxLogTrace </a>
  42. * documentation for more information.
  43. */
  44. ///@{
  45. /// \ingroup trace_env_vars
  46. /**
  47. * Flag to enable find debug tracing.
  48. *
  49. * Use "KICAD_FIND_ITEM" to enable.
  50. */
  51. extern const wxChar* const traceFindItem;
  52. /**
  53. * Flag to enable find and replace debug tracing.
  54. *
  55. * Use "KICAD_FIND_REPLACE" to enable.
  56. */
  57. extern const wxChar* const traceFindReplace;
  58. /**
  59. * Flag to enable draw panel coordinate debug tracing.
  60. *
  61. * Use "KICAD_COORDS" to enable.
  62. */
  63. extern const wxChar* const kicadTraceCoords;
  64. /**
  65. * Flag to enable wxKeyEvent debug tracing.
  66. *
  67. * Use "KICAD_KEY_EVENTS" to enable.
  68. */
  69. extern const wxChar* const kicadTraceKeyEvent;
  70. /**
  71. * Flag to enable tracing of the tool handling stack.
  72. *
  73. * Use "KICAD_TOOL_STACK" to enable.
  74. */
  75. extern const wxChar* const kicadTraceToolStack;
  76. /**
  77. * Flag to enable tracing of the coroutine call stack.
  78. *
  79. * Use "KICAD_COROUTINE_STACK" to enable.
  80. */
  81. extern const wxChar* const kicadTraceCoroutineStack;
  82. /**
  83. * Flag to enable auto save feature debug tracing.
  84. *
  85. * Use "KICAD_AUTOSAVE" to enable.
  86. */
  87. extern const wxChar* const traceAutoSave;
  88. /**
  89. * Flag to enable schematic library memory deletion debug output.
  90. *
  91. * Use "KICAD_SCH_LIB_MEM" to enable.
  92. */
  93. extern const wxChar* const traceSchLibMem;
  94. /**
  95. * Flag to enable legacy schematic plugin debug output.
  96. *
  97. * Use "KICAD_SCH_PLUGIN" to enable.
  98. */
  99. extern const wxChar* const traceSchPlugin;
  100. /**
  101. * Flag to enable legacy schematic plugin debug output.
  102. *
  103. * Use "KICAD_SCH_LEGACY_PLUGIN" to enable.
  104. */
  105. extern const wxChar* const traceSchLegacyPlugin;
  106. /**
  107. * Flag to enable GEDA PCB plugin debug output.
  108. *
  109. * Use "KICAD_PCB_PLUGIN" to enable.
  110. */
  111. extern const wxChar* const traceKicadPcbPlugin;
  112. /**
  113. * Flag to enable GEDA PCB plugin debug output.
  114. *
  115. * Use "KICAD_GEDA_PLUGIN" to enable.
  116. */
  117. extern const wxChar* const traceGedaPcbPlugin;
  118. /**
  119. * Flag to enable print controller debug output.
  120. *
  121. * Use "KICAD_PRINT" to enable.
  122. */
  123. extern const wxChar* const tracePrinting;
  124. /**
  125. * Flag to enable path and file name debug output.
  126. *
  127. * Use "KICAD_PATHS_AND_FILES" to enable.
  128. */
  129. extern const wxChar* const tracePathsAndFiles;
  130. /**
  131. * Flag to enable locale debug output.
  132. *
  133. * Use "KICAD_LOCALE" to enable.
  134. */
  135. extern const wxChar* const traceLocale;
  136. /**
  137. * Flag to enable locale debug output.
  138. *
  139. * Use "KICAD_FONTS" to enable.
  140. */
  141. extern const wxChar* const traceFonts;
  142. /**
  143. * Flag to enable debug output of #BASE_SCREEN and it's derivatives.
  144. *
  145. * Use "KICAD_SCREEN" to enable.
  146. */
  147. extern const wxChar* const traceScreen;
  148. /**
  149. * Flag to enable debug output of display positioning logic.
  150. *
  151. * Use "KICAD_DISPLAY_LOCATION" to enable.
  152. */
  153. extern const wxChar* const traceDisplayLocation;
  154. /**
  155. * Flag to enable debug output of zoom-scrolling calculations in
  156. * #KIGFX::ZOOM_CONTROLLER and derivatives.
  157. *
  158. * Use "KICAD_ZOOM_SCROLL" to enable.
  159. */
  160. extern const wxChar* const traceZoomScroll;
  161. /**
  162. * Flag to enable debug output of symbol library resolver results
  163. *
  164. * Use "KICAD_SYM_RESOLVE" to enable.
  165. */
  166. extern const wxChar* const traceSymbolResolver;
  167. /**
  168. * Flag to enable debug output of schematic symbol sheet path manipulation code.
  169. *
  170. * Use "KICAD_SCH_SHEET_PATHS" to enable.
  171. */
  172. extern const wxChar* const traceSchSheetPaths;
  173. /**
  174. * Flag to enable debug output of environment variable operations.
  175. *
  176. * Use "KICAD_ENV_VARS" to enable.
  177. */
  178. extern const wxChar* const traceEnvVars;
  179. /**
  180. * Flag to enable debug output of GAL performance profiling.
  181. *
  182. * Use "KICAD_GAL_PROFILE" to enable.
  183. */
  184. extern const wxChar* const traceGalProfile;
  185. /**
  186. * Flag to enable KiCad2Step debug tracing.
  187. *
  188. * Use "KICAD2STEP" to enable.
  189. */
  190. extern const wxChar* const traceKiCad2Step;
  191. ///@}
  192. /**
  193. * Debug helper for printing wxKeyEvent information.
  194. *
  195. * @param aEvent is the wxKeyEvent to generate the print string from.
  196. * @return the wxKeyEvent information.
  197. */
  198. extern wxString dump( const wxKeyEvent& aEvent );
  199. /**
  200. * Debug helper for printing wxArrayString contents.
  201. *
  202. * @param aArray is the string array to output.
  203. * @return the wxArrayString contents in a formatted string for debugging output.
  204. */
  205. extern wxString dump( const wxArrayString& aArray );
  206. class TRACE_MANAGER
  207. {
  208. public:
  209. TRACE_MANAGER() :
  210. m_globalTraceEnabled( false ),
  211. m_printAllTraces (false )
  212. {};
  213. ~TRACE_MANAGER(){};
  214. static TRACE_MANAGER& Instance();
  215. WX_DEFINE_VARARG_FUNC_VOID( Trace, 2, (const wxString, const wxFormatString&), DoTrace,
  216. DoTraceUtf8 )
  217. void DoTrace( const wxString aWhat, const wxChar* aFmt, ... )
  218. {
  219. va_list argptr;
  220. va_start( argptr, aFmt );
  221. traceV( aWhat, aFmt, argptr );
  222. va_end( argptr );
  223. }
  224. #if wxUSE_UNICODE_UTF8
  225. void DoTraceUtf8( const wxString aWhat, const wxChar* aFmt, ... )
  226. {
  227. va_list argptr;
  228. va_start( argptr, aFmt );
  229. traceV( aWhat, aFmt, argptr );
  230. va_end( argptr );
  231. }
  232. #endif
  233. bool IsTraceEnabled( const wxString& aWhat );
  234. private:
  235. void traceV( const wxString& aWhat, const wxString& aFmt, va_list vargs );
  236. void init();
  237. std::map<wxString, bool> m_enabledTraces;
  238. bool m_globalTraceEnabled;
  239. bool m_printAllTraces;
  240. };
  241. #define KI_TRACE( aWhat, ... ) \
  242. if( TRACE_MANAGER::Instance().IsTraceEnabled( aWhat ) ) \
  243. { \
  244. TRACE_MANAGER::Instance().Trace( aWhat, __VA_ARGS__ ); \
  245. } \
  246. else \
  247. { \
  248. }
  249. #endif // _TRACE_HELPERS_H_