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