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