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