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