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