2018-04-17 16:25:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Wayne Stambaugh <stambaughw@gmail.com>
|
2021-03-22 19:34:33 +00:00
|
|
|
* Copyright (C) 2018-2021 KiCad Developers, see change_log.txt for contributors.
|
2018-04-17 16:25:19 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file trace_helpers.cpp
|
|
|
|
* @brief wxLogTrace helper implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <trace_helpers.h>
|
|
|
|
|
2021-11-28 20:50:49 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2018-04-17 16:25:19 +00:00
|
|
|
|
|
|
|
const wxChar* const traceFindReplace = wxT( "KICAD_FIND_REPLACE" );
|
|
|
|
const wxChar* const kicadTraceCoords = wxT( "KICAD_COORDS" );
|
|
|
|
const wxChar* const kicadTraceKeyEvent = wxT( "KICAD_KEY_EVENTS" );
|
2019-07-27 14:11:41 +00:00
|
|
|
const wxChar* const kicadTraceToolStack = wxT( "KICAD_TOOL_STACK" );
|
2021-04-16 16:49:20 +00:00
|
|
|
const wxChar* const kicadTraceCoroutineStack = wxT( "KICAD_COROUTINE_STACK" );
|
2018-04-17 16:25:19 +00:00
|
|
|
const wxChar* const traceSchLibMem = wxT( "KICAD_SCH_LIB_MEM" );
|
|
|
|
const wxChar* const traceFindItem = wxT( "KICAD_FIND_ITEM" );
|
|
|
|
const wxChar* const traceSchLegacyPlugin = wxT( "KICAD_SCH_LEGACY_PLUGIN" );
|
2022-12-15 14:57:53 +00:00
|
|
|
const wxChar* const traceSchPlugin = wxT( "KICAD_SCH_PLUGIN" );
|
2018-04-17 16:25:19 +00:00
|
|
|
const wxChar* const traceGedaPcbPlugin = wxT( "KICAD_GEDA_PLUGIN" );
|
|
|
|
const wxChar* const traceKicadPcbPlugin = wxT( "KICAD_PCB_PLUGIN" );
|
|
|
|
const wxChar* const tracePrinting = wxT( "KICAD_PRINT" );
|
|
|
|
const wxChar* const traceAutoSave = wxT( "KICAD_AUTOSAVE" );
|
2018-04-30 19:17:34 +00:00
|
|
|
const wxChar* const tracePathsAndFiles = wxT( "KICAD_PATHS_AND_FILES" );
|
2018-10-17 19:03:33 +00:00
|
|
|
const wxChar* const traceLocale = wxT( "KICAD_LOCALE" );
|
2022-01-18 12:43:31 +00:00
|
|
|
const wxChar* const traceFonts = wxT( "KICAD_FONTS" );
|
2018-10-17 19:03:33 +00:00
|
|
|
const wxChar* const traceScreen = wxT( "KICAD_SCREEN" );
|
2018-11-22 16:24:17 +00:00
|
|
|
const wxChar* const traceZoomScroll = wxT( "KICAD_ZOOM_SCROLL" );
|
2019-04-30 17:03:19 +00:00
|
|
|
const wxChar* const traceSymbolResolver = wxT( "KICAD_SYM_RESOLVE" );
|
2020-04-26 20:53:29 +00:00
|
|
|
const wxChar* const traceDisplayLocation = wxT( "KICAD_DISPLAY_LOCATION" );
|
|
|
|
const wxChar* const traceSchSheetPaths = wxT( "KICAD_SCH_SHEET_PATHS" );
|
2020-08-11 23:11:48 +00:00
|
|
|
const wxChar* const traceEnvVars = wxT( "KICAD_ENV_VARS" );
|
2021-03-22 19:34:33 +00:00
|
|
|
const wxChar* const traceGalProfile = wxT( "KICAD_GAL_PROFILE" );
|
2022-09-12 18:01:48 +00:00
|
|
|
const wxChar* const traceKiCad2Step = wxT( "KICAD2STEP" );
|
2018-04-17 16:25:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxString dump( const wxArrayString& aArray )
|
|
|
|
{
|
|
|
|
wxString tmp;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < aArray.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
if( aArray[i].IsEmpty() )
|
|
|
|
tmp << wxT( "\"\" " );
|
|
|
|
else
|
|
|
|
tmp << aArray[i] << wxT( " " );
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The following code was shamelessly copied from the wxWidgets keyboard sample
|
|
|
|
// at https://github.com/wxWidgets/wxWidgets/blob/master/samples/keyboard/keyboard.cpp.
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by: Marcin Wojdyr
|
|
|
|
// Created: 07.04.02
|
|
|
|
// Copyright: (c) 2002 Vadim Zeitlin
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// helper function that returns textual description of wx virtual keycode
|
|
|
|
const char* GetVirtualKeyCodeName(int keycode)
|
|
|
|
{
|
|
|
|
switch ( keycode )
|
|
|
|
{
|
|
|
|
#define WXK_(x) \
|
|
|
|
case WXK_##x: return #x;
|
|
|
|
|
|
|
|
WXK_(BACK)
|
|
|
|
WXK_(TAB)
|
|
|
|
WXK_(RETURN)
|
|
|
|
WXK_(ESCAPE)
|
|
|
|
WXK_(SPACE)
|
|
|
|
WXK_(DELETE)
|
|
|
|
WXK_(START)
|
|
|
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|
|
#endif
|
|
|
|
#undef WXK_
|
|
|
|
|
|
|
|
default:
|
2021-07-15 19:26:35 +00:00
|
|
|
return nullptr;
|
2018-04-17 16:25:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// helper function that returns textual description of key in the event
|
|
|
|
wxString GetKeyName( const wxKeyEvent &aEvent )
|
|
|
|
{
|
|
|
|
int keycode = aEvent.GetKeyCode();
|
|
|
|
const char* virt = GetVirtualKeyCodeName( keycode );
|
|
|
|
|
|
|
|
if( virt )
|
|
|
|
return virt;
|
|
|
|
|
|
|
|
if( keycode > 0 && keycode < 32 )
|
|
|
|
return wxString::Format( "Ctrl-%c", (unsigned char)('A' + keycode - 1) );
|
|
|
|
|
|
|
|
if( keycode >= 32 && keycode < 128 )
|
|
|
|
return wxString::Format( "'%c'", (unsigned char)keycode );
|
|
|
|
|
|
|
|
#if wxUSE_UNICODE
|
|
|
|
int uc = aEvent.GetUnicodeKey();
|
|
|
|
|
|
|
|
if( uc != WXK_NONE )
|
|
|
|
return wxString::Format( "'%c'", uc );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString dump( const wxKeyEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2023-01-17 04:14:38 +00:00
|
|
|
wxString eventType = wxS( "unknown" );
|
2018-04-17 16:25:19 +00:00
|
|
|
|
|
|
|
if( aEvent.GetEventType() == wxEVT_KEY_DOWN )
|
2023-01-17 04:14:38 +00:00
|
|
|
eventType = wxS( "KeyDown" );
|
2018-04-17 16:25:19 +00:00
|
|
|
else if( aEvent.GetEventType() == wxEVT_KEY_UP )
|
2023-01-17 04:14:38 +00:00
|
|
|
eventType = wxS( "KeyUp" );
|
2018-04-17 16:25:19 +00:00
|
|
|
else if( aEvent.GetEventType() == wxEVT_CHAR )
|
2023-01-17 04:14:38 +00:00
|
|
|
eventType = wxS( "Char" );
|
2018-04-17 16:25:19 +00:00
|
|
|
else if( aEvent.GetEventType() == wxEVT_CHAR_HOOK )
|
2023-01-17 04:14:38 +00:00
|
|
|
eventType = wxS( "Hook" );
|
2018-04-17 16:25:19 +00:00
|
|
|
|
|
|
|
// event key_name KeyCode modifiers Unicode raw_code raw_flags pos
|
|
|
|
msg.Printf( "%7s %15s %5d %c%c%c%c"
|
|
|
|
#if wxUSE_UNICODE
|
|
|
|
"%5d (U+%04x)"
|
|
|
|
#else
|
|
|
|
" none "
|
|
|
|
#endif
|
|
|
|
#ifdef wxHAS_RAW_KEY_CODES
|
|
|
|
" %7lu 0x%08lx"
|
|
|
|
#else
|
|
|
|
" not-set not-set"
|
|
|
|
#endif
|
2021-05-03 20:07:16 +00:00
|
|
|
" (%5d,%5d)",
|
2018-04-17 16:25:19 +00:00
|
|
|
eventType,
|
|
|
|
GetKeyName( aEvent ),
|
|
|
|
aEvent.GetKeyCode(),
|
|
|
|
aEvent.ControlDown() ? 'C' : '-',
|
|
|
|
aEvent.AltDown() ? 'A' : '-',
|
|
|
|
aEvent.ShiftDown() ? 'S' : '-',
|
|
|
|
aEvent.MetaDown() ? 'M' : '-'
|
|
|
|
#if wxUSE_UNICODE
|
|
|
|
, aEvent.GetUnicodeKey()
|
|
|
|
, aEvent.GetUnicodeKey()
|
|
|
|
#endif
|
|
|
|
#ifdef wxHAS_RAW_KEY_CODES
|
|
|
|
, (unsigned long) aEvent.GetRawKeyCode()
|
|
|
|
, (unsigned long) aEvent.GetRawKeyFlags()
|
|
|
|
#endif
|
|
|
|
, aEvent.GetX()
|
|
|
|
, aEvent.GetY()
|
|
|
|
);
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
2021-11-28 20:50:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
TRACE_MANAGER& TRACE_MANAGER::Instance()
|
|
|
|
{
|
|
|
|
static TRACE_MANAGER* self = nullptr;
|
|
|
|
|
|
|
|
if( !self )
|
|
|
|
{
|
|
|
|
self = new TRACE_MANAGER;
|
|
|
|
self->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
return *self;
|
|
|
|
}
|
|
|
|
|
2022-07-15 20:49:01 +00:00
|
|
|
|
|
|
|
bool TRACE_MANAGER::IsTraceEnabled( const wxString& aWhat )
|
2021-11-28 20:50:49 +00:00
|
|
|
{
|
|
|
|
if( !m_printAllTraces )
|
|
|
|
{
|
|
|
|
if( !m_globalTraceEnabled )
|
2022-07-15 20:49:01 +00:00
|
|
|
return false;
|
2021-11-28 20:50:49 +00:00
|
|
|
|
|
|
|
if( m_enabledTraces.find( aWhat ) == m_enabledTraces.end() )
|
2022-07-15 20:49:01 +00:00
|
|
|
return false;
|
2021-11-28 20:50:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-15 20:49:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TRACE_MANAGER::traceV( const wxString& aWhat, const wxString& aFmt, va_list vargs )
|
|
|
|
{
|
|
|
|
if( !IsTraceEnabled( aWhat ) )
|
|
|
|
return;
|
|
|
|
|
2021-11-28 20:50:49 +00:00
|
|
|
wxString str;
|
|
|
|
str.PrintfV( aFmt, vargs );
|
|
|
|
|
2024-02-10 19:05:21 +00:00
|
|
|
#if defined( __UNIX__ ) || defined( _WIN32 )
|
2021-11-28 20:50:49 +00:00
|
|
|
fprintf( stderr, " %-30s | %s", aWhat.c_str().AsChar(), str.c_str().AsChar() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-07-15 20:49:01 +00:00
|
|
|
|
2021-11-28 20:50:49 +00:00
|
|
|
void TRACE_MANAGER::init()
|
|
|
|
{
|
|
|
|
wxString traceVars;
|
|
|
|
m_globalTraceEnabled = wxGetEnv( wxT( "KICAD_TRACE" ), &traceVars );
|
|
|
|
m_printAllTraces = false;
|
|
|
|
|
|
|
|
if( !m_globalTraceEnabled )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxStringTokenizer tokenizer( traceVars, wxT( "," ) );
|
2021-12-05 19:16:18 +00:00
|
|
|
|
2021-11-28 20:50:49 +00:00
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
wxString token = tokenizer.GetNextToken();
|
|
|
|
m_enabledTraces[token] = true;
|
2021-12-05 19:16:18 +00:00
|
|
|
|
|
|
|
if( token.Lower() == wxT( "all" ) )
|
2021-11-28 20:50:49 +00:00
|
|
|
m_printAllTraces = true;
|
|
|
|
}
|
2021-12-05 19:16:18 +00:00
|
|
|
}
|