mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-20 00:21:31 +00:00
Move LOCALE_IO out of common.h
This commit is contained in:
parent
472ea039dd
commit
1d559108c8
bitmap2component
common
eeschema
libedit
plotters
plot_schematic_DXF.cppplot_schematic_HPGL.cppplot_schematic_PDF.cppplot_schematic_PS.cppplot_schematic_SVG.cpp
sch_plugins
sim
gerbview
include
pcb_calculator
pcbnew
board_stackup_manager
dialogs
exporters
export_d356.cppexport_footprints_placefile.cppexport_gencad.cppexport_hyperlynx.cppexport_idf.cppgen_drill_report_files.cppgendrill_Excellon_writer.cppgendrill_gerber_writer.cppgerber_jobfile_writer.cppgerber_placefile_writer.cpp
footprint_info_impl.cppimport_gfx
kicad_clipboard.cppmicrowave
pcbplot.cppplugins
eagle
geda
kicad
legacy
pcad
specctra_import_export
@ -34,6 +34,7 @@
|
||||
#include <common.h>
|
||||
#include <layers_id_colors_and_visibility.h>
|
||||
|
||||
#include <locale_io.h>
|
||||
#include <potracelib.h>
|
||||
|
||||
#include "bitmap2component.h"
|
||||
|
@ -354,6 +354,7 @@ set( COMMON_SRCS
|
||||
lib_table_base.cpp
|
||||
lib_tree_model.cpp
|
||||
lib_tree_model_adapter.cpp
|
||||
locale_io.cpp
|
||||
lockfile.cpp
|
||||
lset.cpp
|
||||
marker_base.cpp
|
||||
|
@ -238,87 +238,6 @@ bool IsMetricUnit( EDA_UNITS aUnit )
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Global variables definitions.
|
||||
*
|
||||
* TODO: All of these variables should be moved into the class were they
|
||||
* are defined and used. Most of them probably belong in the
|
||||
* application class.
|
||||
*/
|
||||
|
||||
// When reading/writing files, we need to swtich to setlocale( LC_NUMERIC, "C" ).
|
||||
// Works fine to read/write files with floating point numbers.
|
||||
// We can call setlocale( LC_NUMERIC, "C" ) of wxLocale( "C", "C", "C", false )
|
||||
// wxWidgets discourage a direct call to setlocale
|
||||
// However, for us, calling wxLocale( "C", "C", "C", false ) has a unwanted effect:
|
||||
// The I18N translations are no longer active, because the English dixtionary is selected.
|
||||
// To read files, this is not a major issues, but the resul can differ
|
||||
// from using setlocale(xx, "C").
|
||||
// Previouly, we called setlocale( LC_NUMERIC, "C" )
|
||||
// The old code will be removed when calling wxLocale( "C", "C", "C", false )
|
||||
// is fully tested, and all issues fixed
|
||||
#define USE_WXLOCALE 1 /* 0 to call setlocale, 1 to call wxLocale */
|
||||
|
||||
// On Windows, when using setlocale, a wx alert is generated
|
||||
// in some cases (reading a bitmap for instance)
|
||||
// So we disable alerts during the time a file is read or written
|
||||
#if !USE_WXLOCALE
|
||||
#if defined( _WIN32 ) && defined( DEBUG )
|
||||
// a wxAssertHandler_t function to filter wxWidgets alert messages when reading/writing a file
|
||||
// when switching the locale to LC_NUMERIC, "C"
|
||||
// It is used in class LOCALE_IO to hide a useless (in kicad) wxWidgets alert message
|
||||
void KiAssertFilter( const wxString &file, int line,
|
||||
const wxString &func, const wxString &cond,
|
||||
const wxString &msg)
|
||||
{
|
||||
if( !msg.Contains( "Decimal separator mismatch" ) )
|
||||
wxTheApp->OnAssertFailure( file.c_str(), line, func.c_str(), cond.c_str(), msg.c_str() );
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
std::atomic<unsigned int> LOCALE_IO::m_c_count( 0 );
|
||||
LOCALE_IO::LOCALE_IO() : m_wxLocale( nullptr )
|
||||
{
|
||||
// use thread safe, atomic operation
|
||||
if( m_c_count++ == 0 )
|
||||
{
|
||||
#if USE_WXLOCALE
|
||||
m_wxLocale = new wxLocale( "C", "C", "C", false );
|
||||
#else
|
||||
// Store the user locale name, to restore this locale later, in dtor
|
||||
m_user_locale = setlocale( LC_NUMERIC, nullptr );
|
||||
#if defined( _WIN32 ) && defined( DEBUG )
|
||||
// Disable wxWidgets alerts
|
||||
wxSetAssertHandler( KiAssertFilter );
|
||||
#endif
|
||||
// Switch the locale to C locale, to read/write files with fp numbers
|
||||
setlocale( LC_NUMERIC, "C" );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LOCALE_IO::~LOCALE_IO()
|
||||
{
|
||||
// use thread safe, atomic operation
|
||||
if( --m_c_count == 0 )
|
||||
{
|
||||
// revert to the user locale
|
||||
#if USE_WXLOCALE
|
||||
delete m_wxLocale; // Deleting m_wxLocale restored previous locale
|
||||
m_wxLocale = nullptr;
|
||||
#else
|
||||
setlocale( LC_NUMERIC, m_user_locale.c_str() );
|
||||
#if defined( _WIN32 ) && defined( DEBUG )
|
||||
// Enable wxWidgets alerts
|
||||
wxSetDefaultAssertHandler();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow )
|
||||
{
|
||||
wxCoord width;
|
||||
|
@ -24,8 +24,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <common.h> // for LOCALE_IO
|
||||
#include <config_params.h> // for PARAM_CFG_INT_WITH_SCALE, PARAM_CFG_...
|
||||
#include <locale_io.h>
|
||||
#include <gal/color4d.h> // for COLOR4D
|
||||
#include <math/util.h> // for KiROUND
|
||||
#include <wx/config.h> // for wxConfigBase
|
||||
|
48
common/locale_io.cpp
Normal file
48
common/locale_io.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <locale_io.h>
|
||||
#include <wx/intl.h>
|
||||
|
||||
std::atomic<unsigned int> LOCALE_IO::m_c_count( 0 );
|
||||
|
||||
|
||||
LOCALE_IO::LOCALE_IO() : m_wxLocale( nullptr )
|
||||
{
|
||||
// use thread safe, atomic operation
|
||||
if( m_c_count++ == 0 )
|
||||
{
|
||||
m_wxLocale = new wxLocale( "C", "C", "C", false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LOCALE_IO::~LOCALE_IO()
|
||||
{
|
||||
// use thread safe, atomic operation
|
||||
if( --m_c_count == 0 )
|
||||
{
|
||||
delete m_wxLocale; // Deleting m_wxLocale restored previous locale
|
||||
m_wxLocale = nullptr;
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
#include <eda_item.h>
|
||||
#include <locale_io.h>
|
||||
#include <page_layout/ws_data_item.h>
|
||||
#include <page_layout/ws_data_model.h>
|
||||
#include <page_layout/ws_draw_item.h>
|
||||
|
@ -31,6 +31,7 @@
|
||||
*/
|
||||
|
||||
#include <eda_item.h>
|
||||
#include <locale_io.h>
|
||||
#include <page_layout/ws_painter.h>
|
||||
#include <page_layout/ws_draw_item.h>
|
||||
#include <page_layout/ws_data_item.h>
|
||||
|
@ -24,13 +24,14 @@
|
||||
#include <utility>
|
||||
#include <sstream>
|
||||
|
||||
#include <common.h>
|
||||
#include <locale_io.h>
|
||||
#include <gal/color4d.h>
|
||||
#include <settings/json_settings.h>
|
||||
#include <settings/nested_settings.h>
|
||||
#include <settings/parameters.h>
|
||||
#include <wx/config.h>
|
||||
#include <wx/debug.h>
|
||||
#include <wx/fileconf.h>
|
||||
#include <wx/filename.h>
|
||||
|
||||
const wxChar* const traceSettings = wxT( "KICAD_SETTINGS" );
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <sch_painter.h>
|
||||
#include <lib_edit_frame.h>
|
||||
#include <locale_io.h>
|
||||
#include <class_libentry.h>
|
||||
#include <class_library.h>
|
||||
#include <plotters_specific.h>
|
||||
|
@ -25,6 +25,7 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <locale_io.h>
|
||||
#include <plotters_specific.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <sch_sheet_path.h>
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <plotters_specific.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <base_units.h>
|
||||
#include <locale_io.h>
|
||||
#include <sch_sheet_path.h>
|
||||
#include <schematic.h>
|
||||
#include <project.h>
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <plotters_specific.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <base_units.h>
|
||||
#include <locale_io.h>
|
||||
#include <sch_sheet_path.h>
|
||||
#include <sch_painter.h>
|
||||
#include <schematic.h>
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <sch_edit_frame.h>
|
||||
#include <base_units.h>
|
||||
#include <sch_sheet_path.h>
|
||||
#include <locale_io.h>
|
||||
#include <pgm_base.h>
|
||||
#include <project.h>
|
||||
#include <reporter.h>
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <sch_draw_panel.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <base_units.h>
|
||||
#include <locale_io.h>
|
||||
#include <lib_edit_frame.h>
|
||||
#include <sch_sheet_path.h>
|
||||
#include <schematic.h>
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <sch_plugins/eagle/sch_eagle_plugin.h>
|
||||
|
||||
#include <kiway.h>
|
||||
#include <locale_io.h>
|
||||
#include <properties.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <advanced_config.h>
|
||||
#include <pgm_base.h>
|
||||
#include <trace_helpers.h>
|
||||
#include <locale_io.h>
|
||||
#include <sch_bitmap.h>
|
||||
#include <sch_bus_entry.h>
|
||||
#include <sch_component.h>
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <gr_text.h>
|
||||
#include <kiway.h>
|
||||
#include <kicad_string.h>
|
||||
#include <locale_io.h>
|
||||
#include <richio.h>
|
||||
#include <core/typeinfo.h>
|
||||
#include <properties.h>
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "spice_reporter.h"
|
||||
|
||||
#include <common.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/dir.h>
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <confirm.h>
|
||||
#include <common.h>
|
||||
#include <ki_exception.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
SPICE_VALUE::SPICE_VALUE( const wxString& aString )
|
||||
{
|
||||
|
@ -70,6 +70,7 @@
|
||||
#include <gerber_file_image_list.h>
|
||||
#include <excellon_image.h>
|
||||
#include <kicad_string.h>
|
||||
#include <locale_io.h>
|
||||
#include <X2_gerber_attributes.h>
|
||||
#include <view/view.h>
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <export_to_pcbnew.h>
|
||||
|
||||
#include <confirm.h>
|
||||
#include <locale_io.h>
|
||||
#include <macros.h>
|
||||
#include <trigo.h>
|
||||
#include <gerbview_frame.h>
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <gerbview.h>
|
||||
#include <richio.h>
|
||||
#include <locale_io.h>
|
||||
#include <gerber_file_image.h>
|
||||
#include <gerber_file_image_list.h>
|
||||
#include <gerbview_frame.h>
|
||||
|
@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include <kicad_string.h>
|
||||
#include <locale_io.h>
|
||||
#include <gerbview.h>
|
||||
#include <gerbview_frame.h>
|
||||
#include <gerber_file_image.h>
|
||||
|
@ -212,31 +212,6 @@ enum class EDA_UNITS
|
||||
bool IsImperialUnit( EDA_UNITS aUnit );
|
||||
bool IsMetricUnit( EDA_UNITS aUnit );
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate the current locale within a scope in which you are expecting
|
||||
* exceptions to be thrown.
|
||||
*
|
||||
* The constructor sets a "C" language locale option, to read/print files with floating
|
||||
* point numbers. The destructor insures that the default locale is restored if an
|
||||
* exception is thrown or not.
|
||||
*/
|
||||
class LOCALE_IO
|
||||
{
|
||||
public:
|
||||
LOCALE_IO();
|
||||
~LOCALE_IO();
|
||||
|
||||
private:
|
||||
// allow for nesting of LOCALE_IO instantiations
|
||||
static std::atomic<unsigned int> m_c_count;
|
||||
|
||||
// The locale in use before switching to the "C" locale
|
||||
// (the locale can be set by user, and is not always the system locale)
|
||||
std::string m_user_locale;
|
||||
wxLocale* m_wxLocale;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the size of @a aSingleLine of text when it is rendered in @a aWindow
|
||||
* using whatever font is currently set in that window.
|
||||
|
56
include/locale_io.h
Normal file
56
include/locale_io.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef LOCALE_IO_H
|
||||
#define LOCALE_IO_H
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
|
||||
class wxLocale;
|
||||
|
||||
/**
|
||||
* Instantiate the current locale within a scope in which you are expecting
|
||||
* exceptions to be thrown.
|
||||
*
|
||||
* The constructor sets a "C" language locale option, to read/print files with floating
|
||||
* point numbers. The destructor insures that the default locale is restored if an
|
||||
* exception is thrown or not.
|
||||
*/
|
||||
class LOCALE_IO
|
||||
{
|
||||
public:
|
||||
LOCALE_IO();
|
||||
~LOCALE_IO();
|
||||
|
||||
private:
|
||||
// allow for nesting of LOCALE_IO instantiations
|
||||
static std::atomic<unsigned int> m_c_count;
|
||||
|
||||
// The locale in use before switching to the "C" locale
|
||||
// (the locale can be set by user, and is not always the system locale)
|
||||
std::string m_user_locale;
|
||||
wxLocale* m_wxLocale;
|
||||
};
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user