KiCad PCB EDA Suite
trace_helpers.cpp
Go to the documentation of this file.
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 
30 #include <trace_helpers.h>
31 
32 
33 const wxChar* const traceFindReplace = wxT( "KICAD_FIND_REPLACE" );
34 const wxChar* const kicadTraceCoords = wxT( "KICAD_COORDS" );
35 const wxChar* const kicadTraceKeyEvent = wxT( "KICAD_KEY_EVENTS" );
36 const wxChar* const kicadTraceToolStack = wxT( "KICAD_TOOL_STACK" );
37 const wxChar* const kicadTraceCoroutineStack = wxT( "KICAD_COROUTINE_STACK" );
38 const wxChar* const traceSchLibMem = wxT( "KICAD_SCH_LIB_MEM" );
39 const wxChar* const traceFindItem = wxT( "KICAD_FIND_ITEM" );
40 const wxChar* const traceSchLegacyPlugin = wxT( "KICAD_SCH_LEGACY_PLUGIN" );
41 const wxChar* const traceGedaPcbPlugin = wxT( "KICAD_GEDA_PLUGIN" );
42 const wxChar* const traceKicadPcbPlugin = wxT( "KICAD_PCB_PLUGIN" );
43 const wxChar* const tracePrinting = wxT( "KICAD_PRINT" );
44 const wxChar* const traceAutoSave = wxT( "KICAD_AUTOSAVE" );
45 const wxChar* const tracePathsAndFiles = wxT( "KICAD_PATHS_AND_FILES" );
46 const wxChar* const traceLocale = wxT( "KICAD_LOCALE" );
47 const wxChar* const traceScreen = wxT( "KICAD_SCREEN" );
48 const wxChar* const traceZoomScroll = wxT( "KICAD_ZOOM_SCROLL" );
49 const wxChar* const traceSymbolResolver = wxT( "KICAD_SYM_RESOLVE" );
50 const wxChar* const traceDisplayLocation = wxT( "KICAD_DISPLAY_LOCATION" );
51 const wxChar* const traceSchSheetPaths = wxT( "KICAD_SCH_SHEET_PATHS" );
52 const wxChar* const traceEnvVars = wxT( "KICAD_ENV_VARS" );
53 const wxChar* const traceGalProfile = wxT( "KICAD_GAL_PROFILE" );
54 
55 
56 wxString dump( const wxArrayString& aArray )
57 {
58  wxString tmp;
59 
60  for( unsigned i = 0; i < aArray.GetCount(); i++ )
61  {
62  if( aArray[i].IsEmpty() )
63  tmp << wxT( "\"\" " );
64  else
65  tmp << aArray[i] << wxT( " " );
66  }
67 
68  return tmp;
69 }
70 
71 
72 // The following code was shamelessly copied from the wxWidgets keyboard sample
73 // at https://github.com/wxWidgets/wxWidgets/blob/master/samples/keyboard/keyboard.cpp.
74 
76 // Author: Vadim Zeitlin
77 // Modified by: Marcin Wojdyr
78 // Created: 07.04.02
79 // Copyright: (c) 2002 Vadim Zeitlin
80 // Licence: wxWindows licence
82 
83 // helper function that returns textual description of wx virtual keycode
84 const char* GetVirtualKeyCodeName(int keycode)
85 {
86  switch ( keycode )
87  {
88 #define WXK_(x) \
89  case WXK_##x: return #x;
90 
91  WXK_(BACK)
92  WXK_(TAB)
93  WXK_(RETURN)
94  WXK_(ESCAPE)
95  WXK_(SPACE)
96  WXK_(DELETE)
97  WXK_(START)
98  WXK_(LBUTTON)
99  WXK_(RBUTTON)
100  WXK_(CANCEL)
101  WXK_(MBUTTON)
102  WXK_(CLEAR)
103  WXK_(SHIFT)
104  WXK_(ALT)
105  WXK_(CONTROL)
106  WXK_(MENU)
107  WXK_(PAUSE)
108  WXK_(CAPITAL)
109  WXK_(END)
110  WXK_(HOME)
111  WXK_(LEFT)
112  WXK_(UP)
113  WXK_(RIGHT)
114  WXK_(DOWN)
115  WXK_(SELECT)
116  WXK_(PRINT)
117  WXK_(EXECUTE)
118  WXK_(SNAPSHOT)
119  WXK_(INSERT)
120  WXK_(HELP)
121  WXK_(NUMPAD0)
122  WXK_(NUMPAD1)
123  WXK_(NUMPAD2)
124  WXK_(NUMPAD3)
125  WXK_(NUMPAD4)
126  WXK_(NUMPAD5)
127  WXK_(NUMPAD6)
128  WXK_(NUMPAD7)
129  WXK_(NUMPAD8)
130  WXK_(NUMPAD9)
131  WXK_(MULTIPLY)
132  WXK_(ADD)
133  WXK_(SEPARATOR)
134  WXK_(SUBTRACT)
135  WXK_(DECIMAL)
136  WXK_(DIVIDE)
137  WXK_(F1)
138  WXK_(F2)
139  WXK_(F3)
140  WXK_(F4)
141  WXK_(F5)
142  WXK_(F6)
143  WXK_(F7)
144  WXK_(F8)
145  WXK_(F9)
146  WXK_(F10)
147  WXK_(F11)
148  WXK_(F12)
149  WXK_(F13)
150  WXK_(F14)
151  WXK_(F15)
152  WXK_(F16)
153  WXK_(F17)
154  WXK_(F18)
155  WXK_(F19)
156  WXK_(F20)
157  WXK_(F21)
158  WXK_(F22)
159  WXK_(F23)
160  WXK_(F24)
161  WXK_(NUMLOCK)
162  WXK_(SCROLL)
163  WXK_(PAGEUP)
164  WXK_(PAGEDOWN)
165  WXK_(NUMPAD_SPACE)
166  WXK_(NUMPAD_TAB)
167  WXK_(NUMPAD_ENTER)
168  WXK_(NUMPAD_F1)
169  WXK_(NUMPAD_F2)
170  WXK_(NUMPAD_F3)
171  WXK_(NUMPAD_F4)
172  WXK_(NUMPAD_HOME)
173  WXK_(NUMPAD_LEFT)
174  WXK_(NUMPAD_UP)
175  WXK_(NUMPAD_RIGHT)
176  WXK_(NUMPAD_DOWN)
177  WXK_(NUMPAD_PAGEUP)
178  WXK_(NUMPAD_PAGEDOWN)
179  WXK_(NUMPAD_END)
180  WXK_(NUMPAD_BEGIN)
181  WXK_(NUMPAD_INSERT)
182  WXK_(NUMPAD_DELETE)
183  WXK_(NUMPAD_EQUAL)
184  WXK_(NUMPAD_MULTIPLY)
185  WXK_(NUMPAD_ADD)
186  WXK_(NUMPAD_SEPARATOR)
187  WXK_(NUMPAD_SUBTRACT)
188  WXK_(NUMPAD_DECIMAL)
189  WXK_(NUMPAD_DIVIDE)
190 
191  WXK_(WINDOWS_LEFT)
192  WXK_(WINDOWS_RIGHT)
193 #ifdef __WXOSX__
194  WXK_(RAW_CONTROL)
195 #endif
196 #undef WXK_
197 
198  default:
199  return nullptr;
200  }
201 }
202 
203 
204 // helper function that returns textual description of key in the event
205 wxString GetKeyName( const wxKeyEvent &aEvent )
206 {
207  int keycode = aEvent.GetKeyCode();
208  const char* virt = GetVirtualKeyCodeName( keycode );
209 
210  if( virt )
211  return virt;
212 
213  if( keycode > 0 && keycode < 32 )
214  return wxString::Format( "Ctrl-%c", (unsigned char)('A' + keycode - 1) );
215 
216  if( keycode >= 32 && keycode < 128 )
217  return wxString::Format( "'%c'", (unsigned char)keycode );
218 
219 #if wxUSE_UNICODE
220  int uc = aEvent.GetUnicodeKey();
221 
222  if( uc != WXK_NONE )
223  return wxString::Format( "'%c'", uc );
224 #endif
225 
226  return "unknown";
227 }
228 
229 
230 wxString dump( const wxKeyEvent& aEvent )
231 {
232  wxString msg;
233  wxString eventType = "unknown";
234 
235  if( aEvent.GetEventType() == wxEVT_KEY_DOWN )
236  eventType = "KeyDown";
237  else if( aEvent.GetEventType() == wxEVT_KEY_UP )
238  eventType = "KeyUp";
239  else if( aEvent.GetEventType() == wxEVT_CHAR )
240  eventType = "Char";
241  else if( aEvent.GetEventType() == wxEVT_CHAR_HOOK )
242  eventType = "Hook";
243 
244  // event key_name KeyCode modifiers Unicode raw_code raw_flags pos
245  msg.Printf( "%7s %15s %5d %c%c%c%c"
246 #if wxUSE_UNICODE
247  "%5d (U+%04x)"
248 #else
249  " none "
250 #endif
251 #ifdef wxHAS_RAW_KEY_CODES
252  " %7lu 0x%08lx"
253 #else
254  " not-set not-set"
255 #endif
256  " (%5d,%5d)",
257  eventType,
258  GetKeyName( aEvent ),
259  aEvent.GetKeyCode(),
260  aEvent.ControlDown() ? 'C' : '-',
261  aEvent.AltDown() ? 'A' : '-',
262  aEvent.ShiftDown() ? 'S' : '-',
263  aEvent.MetaDown() ? 'M' : '-'
264 #if wxUSE_UNICODE
265  , aEvent.GetUnicodeKey()
266  , aEvent.GetUnicodeKey()
267 #endif
268 #ifdef wxHAS_RAW_KEY_CODES
269  , (unsigned long) aEvent.GetRawKeyCode()
270  , (unsigned long) aEvent.GetRawKeyFlags()
271 #endif
272  , aEvent.GetX()
273  , aEvent.GetY()
274  );
275 
276  return msg;
277 }
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
#define WXK_(x)
const wxChar *const traceZoomScroll
Flag to enable debug output of zoom-scrolling calculations in KIGFX::ZOOM_CONTROLLER and derivatives.
const wxChar *const traceFindReplace
Flag to enable find and replace debug tracing.
const wxChar *const traceSymbolResolver
Flag to enable debug output of symbol library resolver results.
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
const wxChar *const traceGedaPcbPlugin
Flag to enable GEDA PCB plugin debug output.
wxString GetKeyName(const wxKeyEvent &aEvent)
const wxChar *const traceScreen
Flag to enable debug output of BASE_SCREEN and it's derivatives.
const char * GetVirtualKeyCodeName(int keycode)
const wxChar *const tracePrinting
Flag to enable print controller debug output.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
const wxChar *const traceDisplayLocation
Flag to enable debug output of display positioning logic.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
wxLogTrace helper definitions.
const wxChar *const traceLocale
Flag to enable locale debug output.
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
static VECTOR2D CLEAR
const wxChar *const traceSchLibMem
Flag to enable schematic library memory deletion debug output.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const wxChar *const kicadTraceCoroutineStack
Flag to enable tracing of the coroutine call stack.
const wxChar *const traceFindItem
Flag to enable find debug tracing.
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
Definition: am_param.h:150
const wxChar *const kicadTraceCoords
Flag to enable draw panel coordinate debug tracing.