From bcd6bddfd42ba9ddaaf3ed0556c035a474d02dbf Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Thu, 15 Jul 2021 15:26:35 -0400 Subject: [PATCH] Start expunging NULL. Given that KiCad is a C++ project, we should really be using nullptr instead of NULL. --- common/base_units.cpp | 5 +- common/basic_gal.cpp | 19 +- common/bitmap_base.cpp | 18 +- common/commit.cpp | 49 +++-- common/common.cpp | 31 +-- common/dialogs/dialog_color_picker.cpp | 44 ++-- common/dialogs/dialog_configure_paths.cpp | 45 ++-- .../dialog_global_lib_table_config.cpp | 6 +- common/dialogs/dialog_page_settings.cpp | 10 +- common/dialogs/panel_common_settings.cpp | 10 +- common/dialogs/panel_setup_netclasses.cpp | 9 +- common/dialogs/panel_text_variables.cpp | 13 +- common/dialogs/wx_html_report_panel.cpp | 8 +- common/draw_panel_gal.cpp | 23 +- common/dsnlexer.cpp | 54 +++-- common/eda_dde.cpp | 53 ++--- common/eda_doc.cpp | 11 +- common/eda_item.cpp | 15 +- common/eda_text.cpp | 15 +- common/filter_reader.cpp | 10 +- common/footprint_info.cpp | 10 +- common/fp_lib_table.cpp | 2 +- common/gal/cairo/cairo_gal.cpp | 19 +- common/gal/opengl/gpu_manager.cpp | 16 +- common/gal/opengl/noncached_container.cpp | 2 +- common/gal/opengl/opengl_compositor.cpp | 2 +- common/gal/opengl/opengl_gal.cpp | 19 +- common/gal/opengl/shader.cpp | 3 +- common/gbr_metadata.cpp | 103 ++++++--- common/gestfich.cpp | 14 +- common/gl_context_mgr.cpp | 12 +- common/gr_basic.cpp | 132 ++++++------ common/gr_text.cpp | 2 +- common/grid_tricks.cpp | 40 ++-- common/kicad_curl/kicad_curl_easy.cpp | 7 +- common/kiid.cpp | 8 +- common/kiway.cpp | 36 ++-- common/pgm_base.cpp | 14 +- common/plotters/DXF_plotter.cpp | 7 +- common/plotters/PDF_plotter.cpp | 6 +- common/plotters/common_plot_functions.cpp | 4 +- common/plotters/plotter.cpp | 201 ++++++++++-------- .../cadstar/cadstar_archive_parser.cpp | 49 +++-- common/plugins/eagle/eagle_parser.cpp | 2 +- common/project.cpp | 15 +- common/rc_item.cpp | 15 +- common/reporter.cpp | 26 ++- common/richio.cpp | 29 ++- common/status_popup.cpp | 3 +- common/streamwrapper.cpp | 15 +- common/string.cpp | 10 +- common/tool/action_manager.cpp | 12 +- common/tool/action_menu.cpp | 45 ++-- common/tool/common_control.cpp | 9 +- common/tool/edit_constraints.cpp | 4 +- common/tool/edit_points.cpp | 12 +- common/tool/tool_manager.cpp | 43 ++-- common/tool/zoom_tool.cpp | 4 +- common/trace_helpers.cpp | 2 +- common/undo_redo_container.cpp | 35 +-- common/utf8.cpp | 11 +- common/view/view.cpp | 6 +- common/view/wx_view_controls.cpp | 88 ++++---- common/widgets/grid_icon_text_helpers.cpp | 35 ++- common/widgets/layer_box_selector.cpp | 23 +- common/widgets/paged_dialog.cpp | 7 +- common/widgets/text_ctrl_eval.cpp | 11 +- common/widgets/unit_binder.cpp | 25 ++- common/widgets/wx_aui_art_providers.cpp | 11 +- common/widgets/wx_grid.cpp | 14 +- include/class_draw_panel_gal.h | 2 +- include/drawing_sheet/ds_data_model.h | 2 +- include/drawing_sheet/ds_draw_item.h | 4 +- include/dsnlexer.h | 4 +- include/footprint_info.h | 4 +- include/gal/hidpi_gl_canvas.h | 4 +- include/tool/edit_points.h | 4 +- include/tool/grid_helper.h | 2 +- include/tool/tool_base.h | 4 +- include/utf8.h | 6 +- include/view/view_group.h | 4 +- include/widgets/app_progress_dialog.h | 13 +- include/widgets/layer_box_selector.h | 2 +- include/widgets/ui_common.h | 9 +- include/widgets/wx_aui_art_providers.h | 7 + include/widgets/wx_grid.h | 4 + 86 files changed, 951 insertions(+), 792 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index 88c0ca8b96..55b88f1709 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -99,6 +99,7 @@ double To_User_Unit( EDA_UNITS aUnit, double aValue ) * could truncate the actual value */ + // A lower-precision (for readability) version of StringFromValue() wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType ) @@ -494,7 +495,7 @@ std::string FormatInternalUnits( int aValue ) len = snprintf( buf, sizeof(buf), "%.10f", engUnits ); // Make sure snprintf() didn't fail and the locale numeric separator is correct. - wxCHECK( len >= 0 && len < 50 && strchr( buf, ',' ) == NULL, std::string( "" ) ); + wxCHECK( len >= 0 && len < 50 && strchr( buf, ',' ) == nullptr, std::string( "" ) ); while( --len > 0 && buf[len] == '0' ) buf[len] = '\0'; @@ -509,7 +510,7 @@ std::string FormatInternalUnits( int aValue ) len = snprintf( buf, sizeof(buf), "%.10g", engUnits ); // Make sure snprintf() didn't fail and the locale numeric separator is correct. - wxCHECK( len >= 0 && len < 50 && strchr( buf, ',' ) == NULL , std::string( "" ) ); + wxCHECK( len >= 0 && len < 50 && strchr( buf, ',' ) == nullptr , std::string( "" ) ); } return std::string( buf, len ); diff --git a/common/basic_gal.cpp b/common/basic_gal.cpp index ec4ff5e983..018396c6a0 100644 --- a/common/basic_gal.cpp +++ b/common/basic_gal.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 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 @@ -23,7 +23,7 @@ */ /** - * @brief Implement a very basic GAL used to draw, plot and convert texts in segments + * Implement a very basic GAL used to draw, plot and convert texts in segments * for DRC functions, using the common GAL functions. * Draw functions use wxDC. * Plot functions use a PLOTTER @@ -53,22 +53,20 @@ const VECTOR2D BASIC_GAL::transform( const VECTOR2D& aPoint ) const } -// Draws a polyline given a list of points already transformed into the local coordinate -// system. void BASIC_GAL::doDrawPolyline( const std::vector& aLocalPointList ) { if( m_DC ) { if( m_isFillEnabled ) { - GRPoly( m_isClipped ? &m_clipBox : NULL, m_DC, aLocalPointList.size(), + GRPoly( m_isClipped ? &m_clipBox : nullptr, m_DC, aLocalPointList.size(), &aLocalPointList[0], 0, GetLineWidth(), m_Color, m_Color ); } else { for( unsigned ii = 1; ii < aLocalPointList.size(); ++ii ) { - GRCSegm( m_isClipped ? &m_clipBox : NULL, m_DC, aLocalPointList[ ii - 1], + GRCSegm( m_isClipped ? &m_clipBox : nullptr, m_DC, aLocalPointList[ ii - 1], aLocalPointList[ii], GetLineWidth(), m_Color ); } } @@ -132,13 +130,13 @@ void BASIC_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint { if( m_isFillEnabled ) { - GRLine( m_isClipped ? &m_clipBox : NULL, m_DC, startVector.x, startVector.y, + GRLine( m_isClipped ? &m_clipBox : nullptr, m_DC, startVector.x, startVector.y, endVector.x, endVector.y, GetLineWidth(), m_Color ); } else { - GRCSegm( m_isClipped ? &m_clipBox : NULL, m_DC, startVector.x, startVector.y, - endVector.x, endVector.y, GetLineWidth(), 0, m_Color ); + GRCSegm( m_isClipped ? &m_clipBox : nullptr, m_DC, startVector.x, startVector.y, + endVector.x, endVector.y, GetLineWidth(), 0, m_Color ); } } else if( m_plotter ) @@ -149,7 +147,6 @@ void BASIC_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint } else if( m_callback ) { - m_callback( startVector.x, startVector.y, - endVector.x, endVector.y, m_callbackData ); + m_callback( startVector.x, startVector.y, endVector.x, endVector.y, m_callbackData ); } } diff --git a/common/bitmap_base.cpp b/common/bitmap_base.cpp index 717fd51017..3d4d61b000 100644 --- a/common/bitmap_base.cpp +++ b/common/bitmap_base.cpp @@ -6,7 +6,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 jean-pierre.charras - * Copyright (C) 2011-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2011-2021 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 @@ -38,15 +38,11 @@ #include -/**********************/ -/* class BITMAP_BASE */ -/**********************/ - BITMAP_BASE::BITMAP_BASE( const wxPoint& pos ) { m_scale = 1.0; // 1.0 = original bitmap size - m_bitmap = NULL; - m_image = NULL; + m_bitmap = nullptr; + m_image = nullptr; m_ppi = 300; // the bitmap definition. the default is 300PPI m_pixelSizeIu = 254000.0 / m_ppi; // a pixel size value OK for bitmaps using 300 PPI // for Eeschema which uses currently 254000PPI @@ -70,10 +66,6 @@ BITMAP_BASE::BITMAP_BASE( const BITMAP_BASE& aSchBitmap ) } -/** - * Function ImportData - * Copy aItem image to me and update m_bitmap - */ void BITMAP_BASE::ImportData( BITMAP_BASE* aItem ) { *m_image = *aItem->m_image; @@ -240,7 +232,7 @@ const EDA_RECT BITMAP_BASE::GetBoundingBox() const void BITMAP_BASE::DrawBitmap( wxDC* aDC, const wxPoint& aPos ) { - if( m_bitmap == NULL ) + if( m_bitmap == nullptr ) return; wxPoint pos = aPos; @@ -342,7 +334,7 @@ void BITMAP_BASE::PlotImage( PLOTTER* aPlotter, COLOR4D aDefaultColor, int aDefaultPensize ) const { - if( m_image == NULL ) + if( m_image == nullptr ) return; // These 2 lines are useful only for plotters that cannot plot a bitmap diff --git a/common/commit.cpp b/common/commit.cpp index e2bbcdd726..ebfd3d7488 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -2,6 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright 2016-2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * * @author Tomasz Wlostowski * @author Maciej Suminski * @@ -53,35 +55,35 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ) switch( aChangeType & CHT_TYPE ) { - case CHT_ADD: - assert( m_changedItems.find( aItem ) == m_changedItems.end() ); - makeEntry( aItem, CHT_ADD | flag ); - return *this; + case CHT_ADD: + assert( m_changedItems.find( aItem ) == m_changedItems.end() ); + makeEntry( aItem, CHT_ADD | flag ); + return *this; - case CHT_REMOVE: - makeEntry( aItem, CHT_REMOVE | flag ); - return *this; + case CHT_REMOVE: + makeEntry( aItem, CHT_REMOVE | flag ); + return *this; - case CHT_MODIFY: - { - EDA_ITEM* parent = parentObject( aItem ); - EDA_ITEM* clone = nullptr; + case CHT_MODIFY: + { + EDA_ITEM* parent = parentObject( aItem ); + EDA_ITEM* clone = nullptr; - assert( parent ); + assert( parent ); - if( parent ) - clone = parent->Clone(); + if( parent ) + clone = parent->Clone(); - assert( clone ); + assert( clone ); - if( clone ) - return createModified( parent, clone, flag ); + if( clone ) + return createModified( parent, clone, flag ); - break; - } + break; + } - default: - assert( false ); + default: + assert( false ); } return *this; @@ -105,7 +107,7 @@ COMMIT& COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO aModFlag ) { UNDO_REDO change_type = aItems.GetPickedItemStatus( i ); EDA_ITEM* item = aItems.GetPickedItem( i ); - EDA_ITEM* copy = NULL; + EDA_ITEM* copy = nullptr; if( change_type == UNDO_REDO::UNSPECIFIED ) change_type = aModFlag; @@ -169,7 +171,8 @@ void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy ) if( m_changedItems.find( aItem ) != m_changedItems.end() ) { - eraseIf( m_changes, [aItem] ( const COMMIT_LINE& aEnt ) { + eraseIf( m_changes, [aItem] ( const COMMIT_LINE& aEnt ) + { return aEnt.m_item == aItem; } ); } diff --git a/common/common.cpp b/common/common.cpp index 77e0144078..900050e75a 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2014-2020 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 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 @@ -381,8 +381,8 @@ bool matchWild( const char* pat, const char* text, bool dot_special ) const char *m = pat, *n = text, - *ma = NULL, - *na = NULL; + *ma = nullptr, + *na = nullptr; int just = 0, acount = 0, count = 0; @@ -420,6 +420,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special ) if( !*m ) return false; } + if( !*m ) { /* @@ -492,7 +493,7 @@ bool matchWild( const char* pat, const char* text, bool dot_special ) static wxInt64 EPOCH_OFFSET_IN_MSEC = wxLL(11644473600000); -static void ConvertFileTimeToWx( wxDateTime *dt, const FILETIME &ft ) +static void ConvertFileTimeToWx( wxDateTime* dt, const FILETIME& ft ) { wxLongLong t( ft.dwHighDateTime, ft.dwLowDateTime ); t /= 10000; // Convert hundreds of nanoseconds to milliseconds. @@ -505,13 +506,12 @@ static void ConvertFileTimeToWx( wxDateTime *dt, const FILETIME &ft ) /** - * TimestampDir - * * This routine offers SIGNIFICANT performance benefits over using wxWidgets to gather * timestamps from matching files in a directory. - * @param aDirPath the directory to search - * @param aFilespec a (wildcarded) file spec to match against - * @return a hash of the last-mod-dates of all matching files in the directory + * + * @param aDirPath is the directory to search. + * @param aFilespec is a (wildcarded) file spec to match against. + * @return a hash of the last-mod-dates of all matching files in the directory. */ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec ) { @@ -537,7 +537,9 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec ) { ConvertFileTimeToWx( &lastModDate, findData.ftLastWriteTime ); timestamp += lastModDate.GetValue().GetValue(); - timestamp += findData.nFileSizeLow; // Get the file size (partial) as well to check for sneaky changes + + // Get the file size (partial) as well to check for sneaky changes. + timestamp += findData.nFileSizeLow; } while ( FindNextFile( fileHandle, &findData ) != 0 ); } @@ -590,7 +592,9 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec ) if( S_ISREG( entry_stat.st_mode ) ) // wxFileExists() { timestamp += entry_stat.st_mtime * 1000; - timestamp += entry_stat.st_size; // Get the file size as well to check for sneaky changes + + // Get the file size as well to check for sneaky changes. + timestamp += entry_stat.st_size; } } else @@ -607,13 +611,14 @@ long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec ) return timestamp; } + bool WarnUserIfOperatingSystemUnsupported() { if( !KIPLATFORM::APP::IsOperatingSystemUnsupported() ) return false; - wxMessageDialog dialog( NULL, _( "This operating system is not supported " - "by KiCad and its dependencies." ), + wxMessageDialog dialog( nullptr, _( "This operating system is not supported " + "by KiCad and its dependencies." ), _( "Unsupported Operating System" ), wxOK | wxICON_EXCLAMATION ); diff --git a/common/dialogs/dialog_color_picker.cpp b/common/dialogs/dialog_color_picker.cpp index 4cad19925c..a9239f84ca 100644 --- a/common/dialogs/dialog_color_picker.cpp +++ b/common/dialogs/dialog_color_picker.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2021 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 @@ -111,7 +111,7 @@ DIALOG_COLOR_PICKER::~DIALOG_COLOR_PICKER() { swatch->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxMouseEventHandler( DIALOG_COLOR_PICKER::buttColorClick ), - NULL, this ); + nullptr, this ); } } @@ -183,10 +183,10 @@ void DIALOG_COLOR_PICKER::initDefinedColors( CUSTOM_COLORS_LIST* aPredefinedColo swatch->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_COLOR_PICKER::buttColorClick ), - NULL, this ); + nullptr, this ); swatch->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_COLOR_PICKER::colorDClick ), - NULL, this ); + nullptr, this ); }; // If no predefined list is given, build the default predefined colors: @@ -230,9 +230,12 @@ void DIALOG_COLOR_PICKER::createRGBBitmap() int half_size = std::min( bmsize.x, bmsize.y )/2; // We use here a Y axis from bottom to top and origin to center, So we need to map - // coordinated to write pixel in a wxImage - #define MAPX(xx) bmsize.x/2 + (xx) - #define MAPY(yy) bmsize.y/2 - (yy) + // coordinated to write pixel in a wxImage. MAPX and MAPY are defined above so they + // must be undefined here to prevent compiler warnings. +#undef MAPX +#undef MAPY +#define MAPX( xx ) bmsize.x / 2 + ( xx ) +#define MAPY( yy ) bmsize.y / 2 - ( yy ) // Reserve room to draw cursors inside the bitmap half_size -= m_cursorsSize/2; @@ -270,6 +273,7 @@ void DIALOG_COLOR_PICKER::createRGBBitmap() // Red green area in y Z 3d axis color.b = 0.0; + for( int xx = 0; xx < half_size; xx++ ) // green axis { color.g = inc * xx; @@ -283,6 +287,7 @@ void DIALOG_COLOR_PICKER::createRGBBitmap() // Blue green area in x y 3d axis color.r = 0.0; + for( int xx = 0; xx < half_size; xx++ ) // green axis { color.g = inc * xx; @@ -315,8 +320,8 @@ void DIALOG_COLOR_PICKER::createHSVBitmap() // We use here a Y axis from bottom to top and origin to center, So we need to map // coordinated to write pixel in a wxImage - #define MAPX(xx) bmsize.x/2 + (xx) - #define MAPY(yy) bmsize.y/2 - (yy) + #define MAPX( xx ) bmsize.x / 2 + ( xx ) + #define MAPY( yy ) bmsize.y / 2 - ( yy ) wxImage img( bmsize ); // a temporary buffer to build the color map @@ -390,10 +395,10 @@ void DIALOG_COLOR_PICKER::drawRGBPalette() wxBrush brush( wxColor( 0, 0, 0 ), wxBRUSHSTYLE_TRANSPARENT ); bitmapDC.SetPen( pen ); bitmapDC.SetBrush( brush ); - int half_csize = m_cursorsSize/2; + int half_csize = m_cursorsSize / 2; #define SLOPE_AXIS 50.0 - double slope = SLOPE_AXIS/half_size; + double slope = SLOPE_AXIS / half_size; // Red axis cursor (Z 3Daxis): m_cursorBitmapRed.x = 0; @@ -425,6 +430,7 @@ void DIALOG_COLOR_PICKER::drawRGBPalette() bitmapDC.DrawLine( 0, 0, -half_size, - half_size*slope ); // green axis (Y 3D axis) m_RgbBitmap->SetBitmap( newBm ); + /* Deselect the Tool Bitmap from DC, * in order to delete the MemoryDC safely without deleting the bitmap */ bitmapDC.SelectObject( wxNullBitmap ); @@ -438,7 +444,7 @@ void DIALOG_COLOR_PICKER::drawHSVPalette() wxMemoryDC bitmapDC; wxSize bmsize = m_bitmapHSV->GetSize(); - int half_size = std::min( bmsize.x, bmsize.y )/2; + int half_size = std::min( bmsize.x, bmsize.y ) / 2; wxBitmap newBm( *m_bitmapHSV ); bitmapDC.SelectObject( newBm ); @@ -447,7 +453,7 @@ void DIALOG_COLOR_PICKER::drawHSVPalette() bitmapDC.SetDeviceOrigin( half_size, half_size ); // Reserve room to draw cursors inside the bitmap - half_size -= m_cursorsSize/2; + half_size -= m_cursorsSize / 2; // Draw the HSB cursor: m_cursorBitmapHSV.x = cos( m_hue * M_PI / 180.0 ) * half_size * m_sat; @@ -464,6 +470,7 @@ void DIALOG_COLOR_PICKER::drawHSVPalette() m_cursorsSize, m_cursorsSize ); m_HsvBitmap->SetBitmap( newBm ); + /* Deselect the Tool Bitmap from DC, * in order to delete the MemoryDC safely without deleting the bitmap */ @@ -558,7 +565,7 @@ void DIALOG_COLOR_PICKER::onRGBMouseClick( wxMouseEvent& event ) // The cursor position is relative to the m_bitmapHSV wxBitmap center wxSize bmsize = m_bitmapRGB->GetSize(); - int half_size = std::min( bmsize.x, bmsize.y )/2; + int half_size = std::min( bmsize.x, bmsize.y ) / 2; mousePos.x -= half_size; mousePos.y -= half_size; mousePos.y = -mousePos.y; // Use the bottom to top vertical axis @@ -608,12 +615,12 @@ void DIALOG_COLOR_PICKER::onRGBMouseDrag( wxMouseEvent& event ) // The cursor position is relative to the m_bitmapHSV wxBitmap center wxPoint mousePos = event.GetPosition(); wxSize bmsize = m_bitmapRGB->GetSize(); - int half_size = std::min( bmsize.x, bmsize.y )/2; + int half_size = std::min( bmsize.x, bmsize.y ) / 2; mousePos.x -= half_size; mousePos.y -= half_size; - mousePos.y = -mousePos.y; // Use the bottom to top vertical axis + mousePos.y = -mousePos.y; // Use the bottom to top vertical axis - half_size -= m_cursorsSize/2; // the actual half_size of the palette area + half_size -= m_cursorsSize / 2; // the actual half_size of the palette area // Change colors according to the selected cursor: if( m_selectedCursor == &m_cursorBitmapRed ) @@ -683,6 +690,7 @@ bool DIALOG_COLOR_PICKER::setHSvaluesFromCursor( wxPoint aMouseCursor ) wxPoint mousePos = aMouseCursor; wxSize bmsize = m_bitmapHSV->GetSize(); int half_size = std::min( bmsize.x, bmsize.y )/2; + // Make the cursor position relative to the m_bitmapHSV wxBitmap center mousePos.x -= half_size; mousePos.y -= half_size; @@ -698,7 +706,7 @@ bool DIALOG_COLOR_PICKER::setHSvaluesFromCursor( wxPoint aMouseCursor ) m_cursorBitmapHSV = mousePos; // Set saturation and hue from new cursor position: - half_size -= m_cursorsSize/2; // the actual half_size of the palette area + half_size -= m_cursorsSize / 2; // the actual half_size of the palette area m_sat = dist_from_centre / half_size; if( m_sat > 1.0 ) diff --git a/common/dialogs/dialog_configure_paths.cpp b/common/dialogs/dialog_configure_paths.cpp index 78e3efe76a..43c5b130bb 100644 --- a/common/dialogs/dialog_configure_paths.cpp +++ b/common/dialogs/dialog_configure_paths.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015-2021 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 @@ -110,8 +110,12 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO m_sdbSizerOK->SetDefault(); // wxFormBuilder doesn't include this event... - m_EnvVars->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), NULL, this ); - m_SearchPaths->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), NULL, this ); + m_EnvVars->Connect( wxEVT_GRID_CELL_CHANGING, + wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), + nullptr, this ); + m_SearchPaths->Connect( wxEVT_GRID_CELL_CHANGING, + wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), + nullptr, this ); GetSizer()->SetSizeHints( this ); Centre(); @@ -127,8 +131,12 @@ DIALOG_CONFIGURE_PATHS::~DIALOG_CONFIGURE_PATHS() if( m_helpDialog ) m_helpDialog->Destroy(); - m_EnvVars->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), NULL, this ); - m_SearchPaths->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), NULL, this ); + m_EnvVars->Disconnect( wxEVT_GRID_CELL_CHANGING, + wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), + nullptr, this ); + m_SearchPaths->Disconnect( wxEVT_GRID_CELL_CHANGING, + wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), + nullptr, this ); } @@ -200,7 +208,7 @@ void DIALOG_CONFIGURE_PATHS::AppendEnvVar( const wxString& aName, const wxString void DIALOG_CONFIGURE_PATHS::AppendSearchPath( const wxString& aName, const wxString& aPath, - const wxString& aDescription ) + const wxString& aDescription ) { int i = m_SearchPaths->GetNumberRows(); @@ -330,6 +338,7 @@ void DIALOG_CONFIGURE_PATHS::OnGridCellChanging( wxGridEvent& event ) else m_errorMsg = _( "3D search path cannot be empty." ); } + m_errorGrid = dynamic_cast( event.GetEventObject() ); m_errorRow = row; m_errorCol = col; @@ -355,7 +364,8 @@ void DIALOG_CONFIGURE_PATHS::OnGridCellChanging( wxGridEvent& event ) } else if( col == TV_NAME_COL && m_EnvVars->GetCellValue( row, TV_NAME_COL ) != text ) { - if( text == PROJECT_VAR_NAME ) // This env var name is reserved and cannot be added here: + // This env var name is reserved and cannot be added here. + if( text == PROJECT_VAR_NAME ) { wxMessageBox( wxString::Format( _( "The name %s is reserved, and cannot be used here" ), @@ -363,7 +373,9 @@ void DIALOG_CONFIGURE_PATHS::OnGridCellChanging( wxGridEvent& event ) event.Veto(); } else // Changing name; clear external flag + { m_EnvVars->SetCellValue( row, TV_FLAG_COL, wxEmptyString ); + } } } } @@ -432,7 +444,8 @@ void DIALOG_CONFIGURE_PATHS::OnDeleteSearchPath( wxCommandEvent& event ) // if there are still rows in grid, make previous row visible if( m_SearchPaths->GetNumberRows() ) { - m_SearchPaths->MakeCellVisible( std::max( 0, curRow-1 ), m_SearchPaths->GetGridCursorCol() ); + m_SearchPaths->MakeCellVisible( std::max( 0, curRow-1 ), + m_SearchPaths->GetGridCursorCol() ); m_SearchPaths->SetGridCursor( std::max( 0, curRow-1 ), m_SearchPaths->GetGridCursorCol() ); } } @@ -458,7 +471,9 @@ void DIALOG_CONFIGURE_PATHS::OnSearchPathMoveUp( wxCommandEvent& event ) m_SearchPaths->SetGridCursor( prevRow, m_SearchPaths->GetGridCursorCol() ); } else + { wxBell(); + } } @@ -482,7 +497,9 @@ void DIALOG_CONFIGURE_PATHS::OnSearchPathMoveDown( wxCommandEvent& event ) m_SearchPaths->SetGridCursor( nextRow, m_SearchPaths->GetGridCursorCol() ); } else + { wxBell(); + } } @@ -495,6 +512,7 @@ void DIALOG_CONFIGURE_PATHS::OnGridCellRightClick( wxGridEvent& aEvent ) wxMenu menu; AddMenuItem( &menu, 1, _( "File Browser..." ), KiBitmap( BITMAPS::small_folder ) ); + if( GetPopupMenuSelectionFromUser( menu ) == 1 ) { wxDirDialog dlg( nullptr, _( "Select Path" ), m_curdir, @@ -525,13 +543,16 @@ void DIALOG_CONFIGURE_PATHS::OnUpdateUI( wxUpdateUIEvent& event ) width = m_SearchPaths->GetClientRect().GetWidth(); m_SearchPaths->AutoSizeColumn( SP_ALIAS_COL ); - m_SearchPaths->SetColSize( SP_ALIAS_COL, std::max( m_SearchPaths->GetColSize( SP_ALIAS_COL ), 120 ) ); + m_SearchPaths->SetColSize( SP_ALIAS_COL, + std::max( m_SearchPaths->GetColSize( SP_ALIAS_COL ), 120 ) ); m_SearchPaths->AutoSizeColumn( SP_PATH_COL ); - m_SearchPaths->SetColSize( SP_PATH_COL, std::max( m_SearchPaths->GetColSize( SP_PATH_COL ), 300 ) ); + m_SearchPaths->SetColSize( SP_PATH_COL, + std::max( m_SearchPaths->GetColSize( SP_PATH_COL ), 300 ) ); - m_SearchPaths->SetColSize( SP_DESC_COL, width - ( m_SearchPaths->GetColSize( SP_ALIAS_COL ) - + m_SearchPaths->GetColSize( SP_PATH_COL ) ) ); + m_SearchPaths->SetColSize( SP_DESC_COL, width - + ( m_SearchPaths->GetColSize( SP_ALIAS_COL ) + + m_SearchPaths->GetColSize( SP_PATH_COL ) ) ); m_gridWidth = m_EnvVars->GetSize().GetX(); m_gridWidthsDirty = false; } diff --git a/common/dialogs/dialog_global_lib_table_config.cpp b/common/dialogs/dialog_global_lib_table_config.cpp index 4848d11a83..a91829a494 100644 --- a/common/dialogs/dialog_global_lib_table_config.cpp +++ b/common/dialogs/dialog_global_lib_table_config.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 Wayne Stambaugh - * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 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 @@ -69,7 +69,7 @@ DIALOG_GLOBAL_LIB_TABLE_CONFIG::DIALOG_GLOBAL_LIB_TABLE_CONFIG( wxWindow* aParen m_filePicker1->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_LIB_TABLE_CONFIG::onUpdateFilePicker ), - NULL, this ); + nullptr, this ); wxButton* okButton = (wxButton *) FindWindowById( wxID_OK ); @@ -84,7 +84,7 @@ DIALOG_GLOBAL_LIB_TABLE_CONFIG::~DIALOG_GLOBAL_LIB_TABLE_CONFIG() { m_filePicker1->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GLOBAL_LIB_TABLE_CONFIG::onUpdateFilePicker ), - NULL, this ); + nullptr, this ); } diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp index 67aa58b966..1a5bb070aa 100644 --- a/common/dialogs/dialog_page_settings.cpp +++ b/common/dialogs/dialog_page_settings.cpp @@ -535,7 +535,8 @@ bool DIALOG_PAGES_SETTINGS::SavePageSettings() if( !success ) { - wxASSERT_MSG( false, _( "the translation for paper size must preserve original spellings" ) ); + wxASSERT_MSG( false, + _( "the translation for paper size must preserve original spellings" ) ); m_pageInfo.SetType( PAGE_INFO::A4 ); } @@ -637,6 +638,7 @@ void DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample() wxString pageFmtName = m_pageFmt[idx].BeforeFirst( ' ' ); bool portrait = clamped_layout_size.x < clamped_layout_size.y; pageDUMMY.SetType( pageFmtName, portrait ); + if( m_customFmt ) { pageDUMMY.SetWidthMils( clamped_layout_size.x ); @@ -665,7 +667,8 @@ void DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample() renderSettings.SetLayerColor( LAYER_DRAWINGSHEET, color ); } - GRFilledRect( NULL, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, bgColor, bgColor ); + GRFilledRect( nullptr, &memDC, 0, 0, m_layout_size.x, m_layout_size.y, bgColor, + bgColor ); PrintDrawingSheet( &renderSettings, pageDUMMY, emptyString, emptyString, m_tb, m_screen->GetPageCount(), m_screen->GetPageNumber(), 1, &Prj(), @@ -674,7 +677,8 @@ void DIALOG_PAGES_SETTINGS::UpdateDrawingSheetExample() memDC.SelectObject( wxNullBitmap ); m_PageLayoutExampleBitmap->SetBitmap( *m_pageBitmap ); } - DS_DATA_MODEL::SetAltInstance( NULL ); + + DS_DATA_MODEL::SetAltInstance( nullptr ); // Refresh the dialog. Layout(); diff --git a/common/dialogs/panel_common_settings.cpp b/common/dialogs/panel_common_settings.cpp index edaae78fc1..231efaae52 100644 --- a/common/dialogs/panel_common_settings.cpp +++ b/common/dialogs/panel_common_settings.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2021 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 @@ -44,8 +44,8 @@ PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS( DIALOG_SHIM* aDialog, wxWindow* aP m_dialog( aDialog ), m_last_scale( -1 ) { - m_canvasScaleCtrl->SetRange( - DPI_SCALING::GetMinScaleFactor(), DPI_SCALING::GetMaxScaleFactor() ); + m_canvasScaleCtrl->SetRange( DPI_SCALING::GetMinScaleFactor(), + DPI_SCALING::GetMaxScaleFactor() ); m_canvasScaleCtrl->SetDigits( dpi_scaling_precision ); m_canvasScaleCtrl->SetIncrement( dpi_scaling_increment ); m_canvasScaleCtrl->SetValue( DPI_SCALING::GetDefaultScaleFactor() ); @@ -79,7 +79,7 @@ PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS( DIALOG_SHIM* aDialog, wxWindow* aP m_canvasScaleCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_COMMON_SETTINGS::OnCanvasScaleChange ), - NULL, this ); + nullptr, this ); } @@ -87,7 +87,7 @@ PANEL_COMMON_SETTINGS::~PANEL_COMMON_SETTINGS() { m_canvasScaleCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_COMMON_SETTINGS::OnCanvasScaleChange ), - NULL, this ); + nullptr, this ); } diff --git a/common/dialogs/panel_setup_netclasses.cpp b/common/dialogs/panel_setup_netclasses.cpp index 8f41414e5d..139c3c07be 100644 --- a/common/dialogs/panel_setup_netclasses.cpp +++ b/common/dialogs/panel_setup_netclasses.cpp @@ -178,7 +178,7 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, NETCLASSE // wxFormBuilder doesn't include this event... m_netclassGrid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ), - NULL, this ); + nullptr, this ); // Handle tooltips for grid m_netclassGrid->GetGridColLabelWindow()->Bind( wxEVT_MOTION, @@ -204,7 +204,7 @@ PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES() m_netclassGrid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging ), - NULL, this ); + nullptr, this ); } @@ -373,7 +373,8 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow() // Copy other NetClasses: for( int row = 1; row < m_netclassGrid->GetNumberRows(); ++row ) { - NETCLASSPTR nc = std::make_shared( m_netclassGrid->GetCellValue( row, GRID_NAME ) ); + NETCLASSPTR nc = std::make_shared( m_netclassGrid->GetCellValue( row, + GRID_NAME ) ); if( m_netclasses->Add( nc ) ) gridRowToNetclass( m_Parent->GetUserUnits(), m_netclassGrid, row, nc ); @@ -605,7 +606,7 @@ void PANEL_SETUP_NETCLASSES::onmembershipPanelSize( wxSizeEvent& event ) int c_row = m_membershipGrid->GetGridCursorRow(); int c_col = m_membershipGrid->GetGridCursorCol(); - if( c_row >= 0 && c_col == 1 ) // this means the class name choice widget is selected (opened) + if( c_row >= 0 && c_col == 1 ) // this means the class name choice widget is selected (opened) m_membershipGrid->SetGridCursor( c_row, 0 ); // Close it event.Skip(); diff --git a/common/dialogs/panel_text_variables.cpp b/common/dialogs/panel_text_variables.cpp index 47d53fe2db..7a3db5ce50 100644 --- a/common/dialogs/panel_text_variables.cpp +++ b/common/dialogs/panel_text_variables.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KICAD, a free EDA CAD application. * - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2021 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 @@ -58,7 +58,9 @@ PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES( wxWindow* aParent, PROJECT* aProject m_TextVars->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows ); // wxFormBuilder doesn't include this event... - m_TextVars->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_TEXT_VARIABLES::OnGridCellChanging ), NULL, this ); + m_TextVars->Connect( wxEVT_GRID_CELL_CHANGING, + wxGridEventHandler( PANEL_TEXT_VARIABLES::OnGridCellChanging ), + nullptr, this ); } @@ -67,7 +69,9 @@ PANEL_TEXT_VARIABLES::~PANEL_TEXT_VARIABLES() // Delete the GRID_TRICKS. m_TextVars->PopEventHandler( true ); - m_TextVars->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( PANEL_TEXT_VARIABLES::OnGridCellChanging ), NULL, this ); + m_TextVars->Disconnect( wxEVT_GRID_CELL_CHANGING, + wxGridEventHandler( PANEL_TEXT_VARIABLES::OnGridCellChanging ), + nullptr, this ); } @@ -193,7 +197,8 @@ void PANEL_TEXT_VARIABLES::OnUpdateUI( wxUpdateUIEvent& event ) int width = m_TextVars->GetClientRect().GetWidth(); m_TextVars->AutoSizeColumn( TV_NAME_COL ); - m_TextVars->SetColSize( TV_NAME_COL, std::max( m_TextVars->GetColSize( TV_NAME_COL ), 120 ) ); + m_TextVars->SetColSize( TV_NAME_COL, std::max( m_TextVars->GetColSize( TV_NAME_COL ), + 120 ) ); m_TextVars->SetColSize( TV_VALUE_COL, width - m_TextVars->GetColSize( TV_NAME_COL ) ); m_gridWidthsDirty = false; diff --git a/common/dialogs/wx_html_report_panel.cpp b/common/dialogs/wx_html_report_panel.cpp index 66f83d685c..a106553a00 100644 --- a/common/dialogs/wx_html_report_panel.cpp +++ b/common/dialogs/wx_html_report_panel.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 CERN - * Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors. * Author: Tomasz Wlostowski * * This program is free software: you can redistribute it and/or modify it @@ -33,6 +33,7 @@ #include #include + WX_HTML_REPORT_PANEL::WX_HTML_REPORT_PANEL( wxWindow* parent, wxWindowID id, const wxPoint& pos, @@ -47,7 +48,7 @@ WX_HTML_REPORT_PANEL::WX_HTML_REPORT_PANEL( wxWindow* parent, m_htmlView->SetPage( addHeader( "" ) ); Connect( wxEVT_COMMAND_MENU_SELECTED, - wxMenuEventHandler( WX_HTML_REPORT_PANEL::onMenuEvent ), NULL, this ); + wxMenuEventHandler( WX_HTML_REPORT_PANEL::onMenuEvent ), nullptr, this ); } @@ -249,7 +250,8 @@ void WX_HTML_REPORT_PANEL::onMenuEvent( wxMenuEvent& event ) // Don't globally define this; different facilities use different definitions of "ALL" -static int RPT_SEVERITY_ALL = RPT_SEVERITY_WARNING | RPT_SEVERITY_ERROR | RPT_SEVERITY_INFO | RPT_SEVERITY_ACTION; +static int RPT_SEVERITY_ALL = RPT_SEVERITY_WARNING | RPT_SEVERITY_ERROR | RPT_SEVERITY_INFO | + RPT_SEVERITY_ACTION; void WX_HTML_REPORT_PANEL::onCheckBoxShowAll( wxCommandEvent& event ) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index ceda4525a5..83a3c83777 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -95,9 +95,11 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS ); EnableScrolling( false, false ); // otherwise Zoom Auto disables GAL canvas - Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); - Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); - Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), NULL, this ); + Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), nullptr, this ); + Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), nullptr, + this ); + Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( EDA_DRAW_PANEL_GAL::onLostFocus ), nullptr, + this ); const wxEventType events[] = { // Binding both EVT_CHAR and EVT_CHAR_HOOK ensures that all key events, @@ -124,7 +126,7 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin }; for( wxEventType eventType : events ) - Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::OnEvent ), NULL, + Connect( eventType, wxEventHandler( EDA_DRAW_PANEL_GAL::OnEvent ), nullptr, m_eventDispatcher ); m_pendingRefresh = false; @@ -134,12 +136,12 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin // Set up timer that prevents too frequent redraw commands m_refreshTimer.SetOwner( this ); Connect( m_refreshTimer.GetId(), wxEVT_TIMER, - wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); + wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), nullptr, this ); // Set up timer to execute OnShow() method when the window appears on the screen m_onShowTimer.SetOwner( this ); Connect( m_onShowTimer.GetId(), wxEVT_TIMER, - wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), NULL, this ); + wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onShowTimer ), nullptr, this ); m_onShowTimer.Start( 10 ); } @@ -346,7 +348,7 @@ void EDA_DRAW_PANEL_GAL::StartDrawing() void EDA_DRAW_PANEL_GAL::StopDrawing() { m_drawingEnabled = false; - Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); + Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr, this ); m_pendingRefresh = false; m_refreshTimer.Stop(); } @@ -377,7 +379,7 @@ void EDA_DRAW_PANEL_GAL::SetTopLayer( int aLayer ) bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) { // Do not do anything if the currently used GAL is correct - if( aGalType == m_backend && m_gal != NULL ) + if( aGalType == m_backend && m_gal != nullptr ) return true; VECTOR2D grid_size = m_gal ? m_gal->GetGridSize() : VECTOR2D(); @@ -387,7 +389,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) // Prevent refreshing canvas during backend switch StopDrawing(); - KIGFX::GAL* new_gal = NULL; + KIGFX::GAL* new_gal = nullptr; try { @@ -531,7 +533,8 @@ void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent ) { m_drawing = false; m_pendingRefresh = true; - Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); + Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), nullptr, + this ); m_drawingEnabled = true; } else diff --git a/common/dsnlexer.cpp b/common/dsnlexer.cpp index ff3f38fb13..a70130a6c7 100644 --- a/common/dsnlexer.cpp +++ b/common/dsnlexer.cpp @@ -370,6 +370,7 @@ void DSNLEXER::NeedLEFT() void DSNLEXER::NeedRIGHT() { int tok = NextTok(); + if( tok != DSN_RIGHT ) Expecting( DSN_RIGHT ); } @@ -378,8 +379,10 @@ void DSNLEXER::NeedRIGHT() int DSNLEXER::NeedSYMBOL() { int tok = NextTok(); + if( !IsSymbol( tok ) ) Expecting( DSN_SYMBOL ); + return tok; } @@ -387,8 +390,10 @@ int DSNLEXER::NeedSYMBOL() int DSNLEXER::NeedSYMBOLorNUMBER() { int tok = NextTok(); + if( !IsSymbol( tok ) && tok!=DSN_NUMBER ) Expecting( "a symbol or number" ); + return tok; } @@ -396,21 +401,23 @@ int DSNLEXER::NeedSYMBOLorNUMBER() int DSNLEXER::NeedNUMBER( const char* aExpectation ) { int tok = NextTok(); + if( tok != DSN_NUMBER ) { - wxString errText = wxString::Format( - _( "need a number for '%s'" ), wxString::FromUTF8( aExpectation ).GetData() ); + wxString errText = wxString::Format( _( "need a number for '%s'" ), + wxString::FromUTF8( aExpectation ).GetData() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } + return tok; } /** - * Function isSpace - * tests for whitespace. Our whitespace, by our definition, is a subset of ASCII, - * i.e. no bytes with MSB on can be considered whitespace, since they are likely part - * of a multibyte UTF8 character. + * Test for whitespace. + * + * Our whitespace, by our definition, is a subset of ASCII, i.e. no bytes with MSB on can be + * considered whitespace, since they are likely part of a multibyte UTF8 character. */ static bool isSpace( char cc ) { @@ -428,6 +435,7 @@ static bool isSpace( char cc ) return true; } } + return false; } @@ -438,7 +446,7 @@ inline bool isDigit( char cc ) } -/// return true if @a cc is an s-expression separator character +///< @return true if @a cc is an s-expression separator character. inline bool isSep( char cc ) { return isSpace( cc ) || cc=='(' || cc==')'; @@ -446,15 +454,13 @@ inline bool isSep( char cc ) /** - * Function isNumber - * returns true if the next sequence of text is a number: + * Return true if the next sequence of text is a number: * either an integer, fixed point, or float with exponent. Stops scanning * at the first non-number character, even if it is not whitespace. * * @param cp is the start of the current token. * @param limit is the end of the current token. - * - * @return bool - true if input token is a number, else false. + * @return true if input token is a number, else false. */ static bool isNumber( const char* cp, const char* limit ) { @@ -522,6 +528,7 @@ L_read: // blank lines are returned as "\n" and will have a len of 1. // EOF will have a len of 0 and so is detectable. int len = readLine(); + if( len == 0 ) { cur = start; // after readLine(), since start can change, set cur offset to start @@ -532,7 +539,7 @@ L_read: cur = start; // after readLine() since start can change. // skip leading whitespace - while( cur 0 ) - c = (char) strtoul( tbuf, NULL, 16 ); + c = (char) strtoul( tbuf, nullptr, 16 ); else c = 'x'; // a goofed hex escape sequence, interpret as 'x' + head += i; break; default: // 1-3 byte octal escape sequence --head; + for( i=0; i<3; ++i ) { if( head[i] < '0' || head[i] > '7' ) break; + tbuf[i] = head[i]; } + tbuf[i] = '\0'; + if( i > 0 ) - c = (char) strtoul( tbuf, NULL, 8 ); + c = (char) strtoul( tbuf, nullptr, 8 ); else c = '\\'; // a goofed octal escape sequence, interpret as '\' + head += i; break; } @@ -676,7 +694,6 @@ L_read: cur - start + curText.length() ); } } - else // is specctraMode, tests in this block should not occur in KiCad mode. { /* get the dash out of a which is embedded for example @@ -694,7 +711,8 @@ L_read: // switching the string_quote character if( prevTok == DSN_STRING_QUOTE ) { - static const wxString errtxt( _("String delimiter must be a single character of ', \", or $")); + static const wxString errtxt( _("String delimiter must be a single character of " + "', \", or $") ); char cc = *cur; switch( cc ) diff --git a/common/eda_dde.cpp b/common/eda_dde.cpp index 790d436d8a..d578f23861 100644 --- a/common/eda_dde.cpp +++ b/common/eda_dde.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2014-2021 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 @@ -40,12 +40,6 @@ static const wxString HOSTNAME( wxT( "localhost" ) ); static char client_ipc_buffer[IPC_BUF_SIZE]; -/**********************************/ -/* Routines related to the server */ -/**********************************/ - -/* Function to initialize a server socket - */ void KIWAY_PLAYER::CreateServer( int service, bool local ) { wxIPV4address addr; @@ -66,8 +60,6 @@ void KIWAY_PLAYER::CreateServer( int service, bool local ) } -/* Function called on every client request. - */ void KIWAY_PLAYER::OnSockRequest( wxSocketEvent& evt ) { size_t len; @@ -98,8 +90,6 @@ void KIWAY_PLAYER::OnSockRequest( wxSocketEvent& evt ) } -/* Function called when a connection is requested by a client. - */ void KIWAY_PLAYER::OnSockRequestServer( wxSocketEvent& evt ) { wxSocketBase* socket; @@ -107,7 +97,7 @@ void KIWAY_PLAYER::OnSockRequestServer( wxSocketEvent& evt ) socket = server->Accept(); - if( socket == NULL ) + if( socket == nullptr ) return; m_sockets.push_back( socket ); @@ -118,17 +108,14 @@ void KIWAY_PLAYER::OnSockRequestServer( wxSocketEvent& evt ) } -/**********************************/ -/* Routines related to the CLIENT */ -/**********************************/ - /** - * Spins up a thread to send messages via a socket. No message queuing, if a message is in flight - * when another is posted with Send(), the second is just dropped. - * This is a workaround for "non-blocking" sockets not always being non-blocking, especially on - * Windows. It is kept fairly simple and not exposed to the outside world because it should be - * replaced in a future KiCad version with a real message queue of some sort, and unified with the - * Kiway messaging system. + * Spin up a thread to send messages via a socket. + * + * No message queuing, if a message is in flight when another is posted with Send(), the + * second is just dropped. This is a workaround for "non-blocking" sockets not always being + * non-blocking, especially on Windows. It is kept fairly simple and not exposed to the + * outside world because it should be replaced in a future KiCad version with a real message + * queue of some sort, and unified with the Kiway messaging system. */ class ASYNC_SOCKET_HOLDER { @@ -173,10 +160,11 @@ public: } /** - * Attempts to send a message if the thread is available - * @param aService is the port number (i.e. service) to send to - * @param aMessage is the message to send - * @return true if the message was queued + * Attempt to send a message if the thread is available. + * + * @param aService is the port number (i.e. service) to send to. + * @param aMessage is the message to send. + * @return true if the message was queued. */ bool Send( int aService, const std::string& aMessage ) { @@ -303,12 +291,15 @@ private: std::unique_ptr socketHolder = nullptr; -/* Used by a client to sent (by a socket connection) a data to a server. - * - Open a Socket Client connection - * - Send the buffer cmdline - * - Close the socket connection + +/** + * Used by a client to sent (by a socket connection) a data to a server. + * - Open a Socket Client connection. + * - Send the buffer cmdline. + * - Close the socket connection. * - * service is the service number for the TC/IP connection + * @param aService is the service number for the TC/IP connection. + * @param aMessage is the message to send. */ bool SendCommand( int aService, const std::string& aMessage ) { diff --git a/common/eda_doc.cpp b/common/eda_doc.cpp index 198810b012..52fd70b100 100644 --- a/common/eda_doc.cpp +++ b/common/eda_doc.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2014-2021 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 @@ -85,7 +85,7 @@ bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT wxString command; bool success = false; -#if defined(EESCHEMA) +#if defined( EESCHEMA ) SEARCH_STACK* aPaths = aProject ? aProject->SchSearchS() : nullptr; #endif @@ -118,9 +118,8 @@ bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT docname.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP ); #endif - /* Compute the full file name */ - if( wxIsAbsolutePath( docname ) || aPaths == NULL ) + if( wxIsAbsolutePath( docname ) || aPaths == nullptr ) fullfilename = docname; /* If the file exists, this is a trivial case: return the filename * "as this". the name can be an absolute path, or a relative path @@ -182,7 +181,7 @@ bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT mimeDatabase->AddFallbacks( EDAfallbacks ); filetype = mimeDatabase->GetFileTypeFromExtension( file_ext ); delete mimeDatabase; - mimeDatabase = NULL; + mimeDatabase = nullptr; } if( filetype ) @@ -203,4 +202,4 @@ bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT } return success; -} \ No newline at end of file +} diff --git a/common/eda_item.cpp b/common/eda_item.cpp index 555c929e25..2c592fae05 100644 --- a/common/eda_item.cpp +++ b/common/eda_item.cpp @@ -82,7 +82,7 @@ const EDA_RECT EDA_ITEM::GetBoundingBox() const EDA_ITEM* EDA_ITEM::Clone() const { - wxCHECK_MSG( false, NULL, wxT( "Clone not implemented in derived class " ) + GetClass() + + wxCHECK_MSG( false, nullptr, wxT( "Clone not implemented in derived class " ) + GetClass() + wxT( ". Bad programmer!" ) ); } @@ -146,7 +146,7 @@ bool EDA_ITEM::Replace( const wxFindReplaceData& aSearchData, wxString& aText ) { wxString searchString = (aSearchData.GetFlags() & wxFR_MATCHCASE) ? aText : aText.Upper(); - int result = searchString.Find( (aSearchData.GetFlags() & wxFR_MATCHCASE) ? + int result = searchString.Find( ( aSearchData.GetFlags() & wxFR_MATCHCASE ) ? aSearchData.GetFindString() : aSearchData.GetFindString().Upper() ); @@ -171,11 +171,12 @@ bool EDA_ITEM::Replace( const wxFindReplaceData& aSearchData, wxString& aText ) bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const { wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ), - GetClass() ) ); + GetClass() ) ); return false; } + EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem ) { // do not call initVars() @@ -189,6 +190,7 @@ EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem ) return *this; } + const BOX2I EDA_ITEM::ViewBBox() const { // Basic fallback @@ -205,12 +207,14 @@ void EDA_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const aLayers[0] = 0; } + BITMAPS EDA_ITEM::GetMenuImage() const { return BITMAPS::dummy_item; } -#if defined(DEBUG) + +#if defined( DEBUG ) void EDA_ITEM::ShowDummy( std::ostream& os ) const { @@ -236,9 +240,6 @@ std::ostream& EDA_ITEM::NestedSpace( int nestLevel, std::ostream& os ) #endif - - - static struct EDA_ITEM_DESC { EDA_ITEM_DESC() diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 60e3d28589..b6f07f6bc5 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -614,14 +614,14 @@ std::vector EDA_TEXT::TransformToSegmentList() const for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) { wxString txt = strings_list.Item( ii ); - GRText( NULL, positions[ii], color, txt, GetDrawRotation(), size, GetHorizJustify(), + GRText( nullptr, positions[ii], color, txt, GetDrawRotation(), size, GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer, &cornerBuffer ); } } else { - GRText( NULL, GetTextPos(), color, GetShownText(), GetDrawRotation(), size, + GRText( nullptr, GetTextPos(), color, GetShownText(), GetDrawRotation(), size, GetHorizJustify(), GetVertJustify(), penWidth, IsItalic(), forceBold, addTextSegmToBuffer, &cornerBuffer ); } @@ -671,13 +671,16 @@ static struct EDA_TEXT_DESC &EDA_TEXT::GetTextThickness, PROPERTY_DISPLAY::DISTANCE ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Italic" ), - &EDA_TEXT::SetItalic, &EDA_TEXT::IsItalic ) ); + &EDA_TEXT::SetItalic, + &EDA_TEXT::IsItalic ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Bold" ), - &EDA_TEXT::SetBold, &EDA_TEXT::IsBold ) ); + &EDA_TEXT::SetBold, &EDA_TEXT::IsBold ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Mirrored" ), - &EDA_TEXT::SetMirrored, &EDA_TEXT::IsMirrored ) ); + &EDA_TEXT::SetMirrored, + &EDA_TEXT::IsMirrored ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Visible" ), - &EDA_TEXT::SetVisible, &EDA_TEXT::IsVisible ) ); + &EDA_TEXT::SetVisible, + &EDA_TEXT::IsVisible ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Width" ), &EDA_TEXT::SetTextWidth, &EDA_TEXT::GetTextWidth, diff --git a/common/filter_reader.cpp b/common/filter_reader.cpp index 215558445b..d212cee725 100644 --- a/common/filter_reader.cpp +++ b/common/filter_reader.cpp @@ -3,7 +3,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2007-2021 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 @@ -53,7 +53,7 @@ char* FILTER_READER::ReadLine() { char* s; - while( ( s = reader.ReadLine() ) != NULL ) + while( ( s = reader.ReadLine() ) != nullptr ) { if( !strchr( "#\n\r", s[0] ) ) break; @@ -91,12 +91,12 @@ char* WHITESPACE_FILTER_READER::ReadLine() { char* s; - while( ( s = reader.ReadLine() ) != NULL ) + while( ( s = reader.ReadLine() ) != nullptr ) { - while( s != NULL && strchr( " \t", *s ) ) + while( s != nullptr && strchr( " \t", *s ) ) s++; - if( s != NULL && !strchr( "#\n\r", *s ) ) + if( s != nullptr && !strchr( "#\n\r", *s ) ) break; } diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index 702be0b310..4c84dbb200 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2011 Jean-Pierre Charras, * Copyright (C) 2013-2016 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 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 @@ -43,7 +43,7 @@ FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aLibNickname, const wxString& aFootprintName ) { if( aFootprintName.IsEmpty() ) - return NULL; + return nullptr; for( std::unique_ptr& fp : m_list ) { @@ -51,18 +51,18 @@ FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aLibNickname, return fp.get(); } - return NULL; + return nullptr; } FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aFootprintName ) { if( aFootprintName.IsEmpty() ) - return NULL; + return nullptr; LIB_ID fpid; - wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, NULL, + wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, nullptr, wxString::Format( wxT( "'%s' is not a valid LIB_ID." ), aFootprintName ) ); return GetFootprintInfo( fpid.GetLibNickname(), fpid.GetLibItemName() ); diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index a953ab5327..92e70f6c67 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -467,7 +467,7 @@ FOOTPRINT* FP_LIB_TABLE::FootprintLoadWithOptionalNickname( const LIB_ID& aFootp return ret; } - return NULL; + return nullptr; } } diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index cb152cb5a9..95bc7dd110 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -277,7 +277,8 @@ void CAIRO_GAL_BASE::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& a cairo_move_to( m_currentContext, pa1.x, pa1.y ); cairo_line_to( m_currentContext, pb1.x, pb1.y ); - cairo_arc( m_currentContext, pb.x, pb.y, rb, lineAngle - M_PI / 2.0, lineAngle + M_PI / 2.0 ); + cairo_arc( m_currentContext, pb.x, pb.y, rb, lineAngle - M_PI / 2.0, + lineAngle + M_PI / 2.0 ); cairo_arc( m_currentContext, pa.x, pa.y, rb, lineAngle + M_PI / 2.0, lineAngle + 3.0 * M_PI / 2.0 ); @@ -811,7 +812,8 @@ void CAIRO_GAL_BASE::DrawGroup( int aGroupNumber ) double x = 1.0, y = 1.0; cairo_device_to_user_distance( m_currentContext, &x, &y ); double minWidth = std::min( fabs( x ), fabs( y ) ); - cairo_set_line_width( m_currentContext, std::max( it->m_Argument.DblArg[0], minWidth ) ); + cairo_set_line_width( m_currentContext, + std::max( it->m_Argument.DblArg[0], minWidth ) ); break; } @@ -1067,8 +1069,8 @@ void CAIRO_GAL_BASE::storePath() { if( m_isFillEnabled ) { - cairo_set_source_rgba( m_currentContext, m_fillColor.r, m_fillColor.g, m_fillColor.b, - m_fillColor.a ); + cairo_set_source_rgba( m_currentContext, m_fillColor.r, m_fillColor.g, + m_fillColor.b, m_fillColor.a ); cairo_fill_preserve( m_currentContext ); } @@ -1231,7 +1233,7 @@ CAIRO_GAL::CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, m_paintListener = aPaintListener; // Connect the native cursor handler - Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( CAIRO_GAL::onSetNativeCursor ), NULL, + Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( CAIRO_GAL::onSetNativeCursor ), nullptr, this ); // Connecting the event handlers @@ -1302,8 +1304,8 @@ void CAIRO_GAL::endDrawing() pixman_image_create_bits( PIXMAN_a8r8g8b8, m_screenSize.x, m_screenSize.y, (uint32_t*) m_bitmapBuffer, m_wxBufferWidth * 4 ); - pixman_image_composite( PIXMAN_OP_SRC, srcImg, NULL, dstImg, 0, 0, 0, 0, 0, 0, m_screenSize.x, - m_screenSize.y ); + pixman_image_composite( PIXMAN_OP_SRC, srcImg, nullptr, dstImg, 0, 0, 0, 0, 0, 0, + m_screenSize.x, m_screenSize.y ); // Free allocated memory pixman_image_unref( srcImg ); @@ -1519,7 +1521,8 @@ bool CAIRO_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) { bool refresh = false; - if( m_validCompositor && aOptions.cairo_antialiasing_mode != m_compositor->GetAntialiasingMode() ) + if( m_validCompositor && + aOptions.cairo_antialiasing_mode != m_compositor->GetAntialiasingMode() ) { m_compositor->SetAntialiasingMode( m_options.cairo_antialiasing_mode ); m_validCompositor = false; diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index c7fae553a1..138bf4f0fb 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -54,7 +54,7 @@ GPU_MANAGER* GPU_MANAGER::MakeManager( VERTEX_CONTAINER* aContainer ) GPU_MANAGER::GPU_MANAGER( VERTEX_CONTAINER* aContainer ) : m_isDrawing( false ), m_container( aContainer ), - m_shader( NULL ), + m_shader( nullptr ), m_shaderAttrib( 0 ), m_enableDepthTest( true ) { @@ -73,7 +73,7 @@ void GPU_MANAGER::SetShader( SHADER& aShader ) if( m_shaderAttrib == -1 ) { - DisplayError( NULL, wxT( "Could not get the shader attribute location" ) ); + DisplayError( nullptr, wxT( "Could not get the shader attribute location" ) ); } } @@ -82,7 +82,7 @@ void GPU_MANAGER::SetShader( SHADER& aShader ) GPU_CACHED_MANAGER::GPU_CACHED_MANAGER( VERTEX_CONTAINER* aContainer ) : GPU_MANAGER( aContainer ), m_buffersInitialized( false ), - m_indicesPtr( NULL ), + m_indicesPtr( nullptr ), m_indicesBuffer( 0 ), m_indicesSize( 0 ), m_indicesCapacity( 0 ) @@ -184,7 +184,7 @@ void GPU_CACHED_MANAGER::EndDrawing() glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, (GLvoid*) COORD_OFFSET ); glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, (GLvoid*) COLOR_OFFSET ); - if( m_shader != NULL ) // Use shader if applicable + if( m_shader != nullptr ) // Use shader if applicable { m_shader->Use(); glEnableVertexAttribArray( m_shaderAttrib ); @@ -196,7 +196,7 @@ void GPU_CACHED_MANAGER::EndDrawing() glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_indicesSize * sizeof( int ), (GLvoid*) m_indices.get(), GL_DYNAMIC_DRAW ); - glDrawElements( GL_TRIANGLES, m_indicesSize, GL_UNSIGNED_INT, NULL ); + glDrawElements( GL_TRIANGLES, m_indicesSize, GL_UNSIGNED_INT, nullptr ); #ifdef KICAD_GAL_PROFILE wxLogTrace( traceGalProfile, wxT( "Cached manager size: %d" ), m_indicesSize ); @@ -210,7 +210,7 @@ void GPU_CACHED_MANAGER::EndDrawing() glDisableClientState( GL_COLOR_ARRAY ); glDisableClientState( GL_VERTEX_ARRAY ); - if( m_shader != NULL ) + if( m_shader != nullptr ) { glDisableVertexAttribArray( m_shaderAttrib ); m_shader->Deactivate(); @@ -287,7 +287,7 @@ void GPU_NONCACHED_MANAGER::EndDrawing() glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, coordinates ); glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, colors ); - if( m_shader != NULL ) // Use shader if applicable + if( m_shader != nullptr ) // Use shader if applicable { GLfloat* shaders = (GLfloat*) ( vertices ) + SHADER_OFFSET / sizeof( GLfloat ); @@ -307,7 +307,7 @@ void GPU_NONCACHED_MANAGER::EndDrawing() glDisableClientState( GL_COLOR_ARRAY ); glDisableClientState( GL_VERTEX_ARRAY ); - if( m_shader != NULL ) + if( m_shader != nullptr ) { glDisableVertexAttribArray( m_shaderAttrib ); m_shader->Deactivate(); diff --git a/common/gal/opengl/noncached_container.cpp b/common/gal/opengl/noncached_container.cpp index 0edb92b4d4..08790b8f08 100644 --- a/common/gal/opengl/noncached_container.cpp +++ b/common/gal/opengl/noncached_container.cpp @@ -73,7 +73,7 @@ VERTEX* NONCACHED_CONTAINER::Allocate( unsigned int aSize ) VERTEX* newVertices = static_cast( realloc( m_vertices, m_currentSize * 2 * sizeof( VERTEX ) ) ); - if( newVertices != NULL ) + if( newVertices != nullptr ) { m_vertices = newVertices; m_freeSpace += m_currentSize; diff --git a/common/gal/opengl/opengl_compositor.cpp b/common/gal/opengl/opengl_compositor.cpp index 5c26662aa4..9ed87f29c1 100644 --- a/common/gal/opengl/opengl_compositor.cpp +++ b/common/gal/opengl/opengl_compositor.cpp @@ -199,7 +199,7 @@ unsigned int OPENGL_COMPOSITOR::CreateBuffer( VECTOR2U aDimensions ) // Set texture parameters glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, aDimensions.x, aDimensions.y, 0, GL_RGBA, - GL_UNSIGNED_BYTE, NULL ); + GL_UNSIGNED_BYTE, nullptr ); checkGlError( "creating framebuffer texture", __FILE__, __LINE__ ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 6acc5e44ce..0309a9e9b2 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -79,7 +79,7 @@ using namespace KIGFX::BUILTIN_FONT; static void InitTesselatorCallbacks( GLUtesselator* aTesselator ); static const int glAttributes[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 8, 0 }; -wxGLContext* OPENGL_GAL::m_glMainContext = NULL; +wxGLContext* OPENGL_GAL::m_glMainContext = nullptr; int OPENGL_GAL::m_instanceCounter = 0; GLuint OPENGL_GAL::g_fontTexture = 0; bool OPENGL_GAL::m_isBitmapFontLoaded = false; @@ -210,7 +210,7 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, m_isContextLocked( false ), m_lockClientCookie( 0 ) { - if( m_glMainContext == NULL ) + if( m_glMainContext == nullptr ) { m_glMainContext = GL_CONTEXT_MANAGER::Get().CreateCtx( this ); @@ -237,7 +237,7 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, m_groupCounter = 0; // Connect the native cursor handler - Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( OPENGL_GAL::onSetNativeCursor ), NULL, + Connect( wxEVT_SET_CURSOR, wxSetCursorEventHandler( OPENGL_GAL::onSetNativeCursor ), nullptr, this ); // Connecting the event handlers @@ -325,7 +325,7 @@ OPENGL_GAL::~OPENGL_GAL() GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glMainContext ); GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glMainContext ); - m_glMainContext = NULL; + m_glMainContext = nullptr; } } @@ -334,8 +334,8 @@ wxString OPENGL_GAL::CheckFeatures( GAL_DISPLAY_OPTIONS& aOptions ) { wxString retVal = wxEmptyString; - wxFrame* testFrame = new wxFrame( NULL, wxID_ANY, wxT( "" ), wxDefaultPosition, wxSize( 1, 1 ), - wxFRAME_TOOL_WINDOW | wxNO_BORDER ); + wxFrame* testFrame = new wxFrame( nullptr, wxID_ANY, wxT( "" ), wxDefaultPosition, + wxSize( 1, 1 ), wxFRAME_TOOL_WINDOW | wxNO_BORDER ); KIGFX::OPENGL_GAL* opengl_gal = nullptr; @@ -407,7 +407,8 @@ double OPENGL_GAL::getWorldPixelSize() const VECTOR2D OPENGL_GAL::getScreenPixelSize() const { double sf = GetScaleFactor(); - return VECTOR2D( 2.0 / (double) ( m_screenSize.x * sf ), 2.0 / (double) ( m_screenSize.y * sf ) ); + return VECTOR2D( 2.0 / (double) ( m_screenSize.x * sf ), 2.0 / + (double) ( m_screenSize.y * sf ) ); } @@ -449,6 +450,7 @@ void OPENGL_GAL::beginDrawing() wxLogVerbose( "Could not create a framebuffer for overlays.\n" ); m_overlayBuffer = 0; } + m_isFramebufferInitialized = true; } @@ -2199,7 +2201,7 @@ void OPENGL_GAL::init() if( !m_glPrivContext ) throw std::runtime_error( "Could not create a private OpenGL context" ); - if( m_tesselator == NULL ) + if( m_tesselator == nullptr ) throw std::runtime_error( "Could not create the m_tesselator" ); // End initialization checks @@ -2332,6 +2334,7 @@ inline double round_to_half_pixel( double f, double r ) return ( ceil( f / r ) - 0.5 ) * r; } + void OPENGL_GAL::ComputeWorldScreenMatrix() { computeWorldScale(); diff --git a/common/gal/opengl/shader.cpp b/common/gal/opengl/shader.cpp index f471ffc26e..6df3717541 100644 --- a/common/gal/opengl/shader.cpp +++ b/common/gal/opengl/shader.cpp @@ -79,6 +79,7 @@ SHADER::~SHADER() } } + bool SHADER::LoadShaderFromFile( SHADER_TYPE aShaderType, const std::string& aShaderSourceName ) { // Load shader sources @@ -253,7 +254,7 @@ bool SHADER::loadShaderFromStringArray( SHADER_TYPE aShaderType, const char** aA programInfo( programNumber ); // Attach the sources - glShaderSource( shaderNumber, aSize, (const GLchar**) aArray, NULL ); + glShaderSource( shaderNumber, aSize, (const GLchar**) aArray, nullptr ); programInfo( programNumber ); // Compile and attach shader to the program diff --git a/common/gbr_metadata.cpp b/common/gbr_metadata.cpp index a18664fe12..9ca2d971f6 100644 --- a/common/gbr_metadata.cpp +++ b/common/gbr_metadata.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 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 @@ -33,6 +33,7 @@ #include #include + wxString GbrMakeCreationDateAttributeString( GBR_NC_STRING_FORMAT aFormat ) { // creates the CreationDate attribute: @@ -41,9 +42,11 @@ wxString GbrMakeCreationDateAttributeString( GBR_NC_STRING_FORMAT aFormat ) // the date the Gerber file was effectively created, // not the time the project of PCB was started wxDateTime date( wxDateTime::GetTimeNow() ); + // Date format: see http://www.cplusplus.com/reference/ctime/strftime wxString timezone_offset; // ISO 8601 offset from UTC in timezone timezone_offset = date.Format( "%z" ); // Extract the time zone offset + // The time zone offset format is +mm or +hhmm (or -mm or -hhmm) // (mm = number of minutes, hh = number of hours. 1h00mn is returned as +0100) // we want +(or -) hh:mm @@ -87,7 +90,8 @@ wxString GbrMakeProjectGUIDfromString( const wxString& aText ) * M = '1' or '4' (UUID version: 1 (basic) or 4 (random)) (we use 4: UUID random) * and * N = '8' or '9' or 'A|a' or 'B|b' : UUID variant 1: 2 MSB bits have meaning) (we use N = 9) - * N = 1000 or 1001 or 1010 or 1011 : 10xx means Variant 1 (Variant2: 110x and 111x are reserved) + * N = 1000 or 1001 or 1010 or 1011 : 10xx means Variant 1 (Variant2: 110x and 111x are + * reserved) */ wxString guid; @@ -158,7 +162,8 @@ std::string GBR_APERTURE_METADATA::FormatAttribute( GBR_APERTURE_ATTRIB aAttribu // generate a string to print a Gerber Aperture attribute switch( aAttribute ) { - case GBR_APERTURE_ATTRIB_END: // Dummy value (aAttribute must be < GBR_APERTURE_ATTRIB_END) + // Dummy value (aAttribute must be < GBR_APERTURE_ATTRIB_END). + case GBR_APERTURE_ATTRIB_END: case GBR_APERTURE_ATTRIB_NONE: // idle command: do nothing break; @@ -211,11 +216,13 @@ std::string GBR_APERTURE_METADATA::FormatAttribute( GBR_APERTURE_ATTRIB aAttribu attribute_string = "TA.AperFunction,BGAPad,CuDef"; break; - case GBR_APERTURE_ATTRIB_CONNECTORPAD: // print info associated to a flashed edge connector pad (outer layers) + case GBR_APERTURE_ATTRIB_CONNECTORPAD: + // print info associated to a flashed edge connector pad (outer layers) attribute_string = "TA.AperFunction,ConnectorPad"; break; - case GBR_APERTURE_ATTRIB_WASHERPAD: // print info associated to flashed mechanical pads (NPTH) + case GBR_APERTURE_ATTRIB_WASHERPAD: + // print info associated to flashed mechanical pads (NPTH) attribute_string = "TA.AperFunction,WasherPad"; break; @@ -239,13 +246,13 @@ std::string GBR_APERTURE_METADATA::FormatAttribute( GBR_APERTURE_ATTRIB aAttribu attribute_string = "TA.AperFunction,FiducialPad,Local"; break; - case GBR_APERTURE_ATTRIB_CASTELLATEDPAD: // print info associated to a flashed castellated pad - // (typically for SMDs) + case GBR_APERTURE_ATTRIB_CASTELLATEDPAD: + // print info associated to a flashed castellated pad (typically for SMDs) attribute_string = "TA.AperFunction,CastellatedPad"; break; - case GBR_APERTURE_ATTRIB_CASTELLATEDDRILL: // print info associated to a flashed castellated pad - // in drill files + case GBR_APERTURE_ATTRIB_CASTELLATEDDRILL: + // print info associated to a flashed castellated pad in drill files attribute_string = "TA.AperFunction,CastellatedDrill"; break; @@ -363,9 +370,9 @@ wxString FormatStringFromGerber( const wxString& aString ) { // make the inverse conversion of FormatStringToGerber() // It converts a "normalized" gerber string containing escape sequences - // and convert it to a 16 bits unicode char - // and return a wxString (unicode 16) from the gerber string - // Note the initial gerber string can already contain unicode chars. + // and convert it to a 16 bits Unicode char + // and return a wxString (Unicode 16) from the gerber string + // Note the initial gerber string can already contain Unicode chars. wxString txt; // The string converted from Gerber string unsigned count = aString.Length(); @@ -377,9 +384,9 @@ wxString FormatStringFromGerber( const wxString& aString ) if( code == '\\' && ii < count-5 && aString[ii+1] == 'u' ) { // Note the latest Gerber X2 spec (2019 06) uses \uXXXX to encode - // the unicode XXXX hexadecimal value + // the Unicode XXXX hexadecimal value // If 4 chars next to 'u' are hexadecimal chars, - // Convert these 4 hexadecimal digits to a 16 bit unicode + // Convert these 4 hexadecimal digits to a 16 bit Unicode // (Gerber allows only 4 hexadecimal digits) // If an error occurs, the escape sequence is not translated, // and used "as this" @@ -416,20 +423,23 @@ wxString FormatStringFromGerber( const wxString& aString ) } } else + { txt.Append( aString[ii] ); + } } return txt; } -wxString ConvertNotAllowedCharsInGerber( const wxString& aString, bool aAllowUtf8Chars, bool aQuoteString ) +wxString ConvertNotAllowedCharsInGerber( const wxString& aString, bool aAllowUtf8Chars, + bool aQuoteString ) { - /* format string means convert any code > 0x7E and unautorized codes to a hexadecimal - * 16 bits sequence unicode - * However if aAllowUtf8Chars is true only unautorized codes will be escaped, because some + /* format string means convert any code > 0x7E and unauthorized codes to a hexadecimal + * 16 bits sequence Unicode + * However if aAllowUtf8Chars is true only unauthorized codes will be escaped, because some * Gerber files accept UTF8 chars. - * unautorized codes are ',' '*' '%' '\' '"' and are used as separators in Gerber files + * unauthorized codes are ',' '*' '%' '\' '"' and are used as separators in Gerber files */ wxString txt; @@ -466,13 +476,15 @@ wxString ConvertNotAllowedCharsInGerber( const wxString& aString, bool aAllowUtf { // Convert code to 4 hexadecimal digit // (Gerber allows only 4 hexadecimal digit) in escape seq: - // "\uXXXX", XXXX is the unicode 16 bits hexa value + // "\uXXXX", XXXX is the Unicode 16 bits hexa value char hexa[32]; sprintf( hexa,"\\u%4.4X", code & 0xFFFF); txt += hexa; } else + { txt += code; + } } if( aQuoteString ) @@ -500,9 +512,10 @@ std::string GBR_DATA_FIELD::GetGerberString() const std::string FormatStringToGerber( const wxString& aString ) { wxString converted; - /* format string means convert any code > 0x7E and unautorized codes to a hexadecimal - * 16 bits sequence unicode - * unautorized codes are ',' '*' '%' '\' + + /* format string means convert any code > 0x7E and unauthorized codes to a hexadecimal + * 16 bits sequence Unicode + * unauthorized codes are ',' '*' '%' '\' * This conversion is not made for quoted strings, because if the string is * quoted, the conversion is expected to be already made, and the returned string must use * UTF8 encoding @@ -512,18 +525,20 @@ std::string FormatStringToGerber( const wxString& aString ) else converted = aString; - // Convert the char string to std::string. Be careful when converting awxString to + // Convert the char string to std::string. Be careful when converting a wxString to // a std::string: using static_cast is mandatory std::string txt = static_cast( converted.utf8_str() ); return txt; } + // Netname and Pan num fields cannot be empty in Gerber files // Normalized names must be used, if any #define NO_NET_NAME wxT( "N/C" ) // net name of not connected pads (one pad net) (normalized) #define NO_PAD_NAME wxT( "" ) // pad name of pads without pad name/number (not normalized) + bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttributes, const GBR_NETLIST_METADATA* aData, bool& aClearPreviousAttributes, bool aUseX1StructuredComment ) @@ -546,7 +561,7 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu // print a Gerber net attribute record. // it is added to the object attributes dictionary // On file, only modified or new attributes are printed. - if( aData == NULL ) + if( aData == nullptr ) return false; std::string pad_attribute_string; @@ -565,8 +580,10 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu pad_attribute_string += FormatStringToGerber( aData->m_Cmpref ) + ","; if( aData->m_Padname.IsEmpty() ) + { // Happens for "mechanical" or never connected pads pad_attribute_string += FormatStringToGerber( NO_PAD_NAME ); + } else { pad_attribute_string += aData->m_Padname.GetGerberString(); @@ -605,7 +622,9 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu } } else + { net_attribute_string += FormatStringToGerber( aData->m_Netname ); + } net_attribute_string += eol_string; } @@ -633,7 +652,7 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu if( aLastNetAttributes != full_attribute_string ) { // first, remove no longer existing attributes. - // Because in Kicad the full attribute list is evaluated for each object, + // Because in KiCad the full attribute list is evaluated for each object, // the entire dictionary is cleared // If m_TryKeepPreviousAttributes is true, only the no longer existing attribute // is cleared. @@ -650,12 +669,16 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu else clearDict = true; } - else if( aLastNetAttributes.find( pad_attribute_string ) - == std::string::npos ) // This attribute has changed + else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos ) + { + // This attribute has changed short_attribute_string += pad_attribute_string; + } } else // New attribute + { short_attribute_string += pad_attribute_string; + } if( aLastNetAttributes.find( "TO.N," ) != std::string::npos ) { @@ -666,12 +689,16 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu else clearDict = true; } - else if( aLastNetAttributes.find( net_attribute_string ) - == std::string::npos ) // This attribute has changed + else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos ) + { + // This attribute has changed. short_attribute_string += net_attribute_string; + } } else // New attribute + { short_attribute_string += net_attribute_string; + } if( aLastNetAttributes.find( "TO.C," ) != std::string::npos ) { @@ -687,14 +714,20 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu short_attribute_string.insert( 0, prepend_string + "TO.C" + eol_string ); } else + { clearDict = true; + } } - else if( aLastNetAttributes.find( cmp_attribute_string ) - == std::string::npos ) // This attribute has changed + else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos ) + { + // This attribute has changed. short_attribute_string += cmp_attribute_string; + } } else // New attribute + { short_attribute_string += cmp_attribute_string; + } aClearPreviousAttributes = clearDict; @@ -710,8 +743,6 @@ bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttribu } -/************ class GBR_CMP_PNP_METADATA *************/ - void GBR_CMP_PNP_METADATA::ClearData() { // Clear all strings @@ -722,6 +753,8 @@ void GBR_CMP_PNP_METADATA::ClearData() m_Value.Clear(); m_MountType = MOUNT_TYPE_UNSPECIFIED; } + + /** * @return a string containing the formatted metadata in X2 syntax. * one line by non empty data @@ -730,7 +763,7 @@ void GBR_CMP_PNP_METADATA::ClearData() wxString GBR_CMP_PNP_METADATA::FormatCmpPnPMetadata() { wxString text; - wxString start_of_line( "%TO."); + wxString start_of_line( "%TO." ); wxString end_of_line( "*%\n" ); wxString mounType[] = diff --git a/common/gestfich.cpp b/common/gestfich.cpp index b20efb294c..d61ab4abe6 100644 --- a/common/gestfich.cpp +++ b/common/gestfich.cpp @@ -73,7 +73,7 @@ wxString EDA_FILE_SELECTOR( const wxString& aTitle, if( defaultpath.IsEmpty() ) { - if( aMruPath == NULL ) + if( aMruPath == nullptr ) defaultpath = wxGetCwd(); else defaultpath = *aMruPath; @@ -246,14 +246,14 @@ bool OpenPDF( const wxString& file ) { wxString msg; msg.Printf( _( "Problem while running the PDF viewer.\nCommand is '%s'." ), command ); - DisplayError( NULL, msg ); + DisplayError( nullptr, msg ); } } else { wxString msg; msg.Printf( _( "Unable to find a PDF viewer for '%s'." ), file ); - DisplayError( NULL, msg ); + DisplayError( nullptr, msg ); } return false; @@ -316,10 +316,10 @@ bool doPrintFile( const wxString& file, bool aDryRun ) if( !application.IsEmpty() ) { printCommand.Printf( "osascript -e 'tell application \"%s\"' " - "-e ' set srcFileRef to (open POSIX file \"%s\")' " - "-e ' activate' " - "-e ' print srcFileRef print dialog true' " - "-e 'end tell' ", + "-e ' set srcFileRef to (open POSIX file \"%s\")' " + "-e ' activate' " + "-e ' print srcFileRef print dialog true' " + "-e 'end tell' ", application, file ); diff --git a/common/gl_context_mgr.cpp b/common/gl_context_mgr.cpp index 5b76b2d2db..fe52cf4ed5 100644 --- a/common/gl_context_mgr.cpp +++ b/common/gl_context_mgr.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 CERN - * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -26,6 +26,7 @@ #include #include + GL_CONTEXT_MANAGER& GL_CONTEXT_MANAGER::Get() { static GL_CONTEXT_MANAGER instance; @@ -33,6 +34,7 @@ GL_CONTEXT_MANAGER& GL_CONTEXT_MANAGER::Get() return instance; } + wxGLContext* GL_CONTEXT_MANAGER::CreateCtx( wxGLCanvas* aCanvas, const wxGLContext* aOther ) { wxGLContext* context = new wxGLContext( aCanvas, aOther ); @@ -66,7 +68,7 @@ void GL_CONTEXT_MANAGER::DestroyCtx( wxGLContext* aContext ) } if( m_glCtx == aContext ) - m_glCtx = NULL; + m_glCtx = nullptr; } @@ -78,7 +80,7 @@ void GL_CONTEXT_MANAGER::DeleteAll() delete ctx.first; m_glContexts.clear(); - m_glCtx = NULL; + m_glCtx = nullptr; m_glCtxMutex.unlock(); } @@ -109,7 +111,7 @@ void GL_CONTEXT_MANAGER::UnlockCtx( wxGLContext* aContext ) if( m_glCtx == aContext ) { m_glCtxMutex.unlock(); - m_glCtx = NULL; + m_glCtx = nullptr; } else { @@ -120,7 +122,7 @@ void GL_CONTEXT_MANAGER::UnlockCtx( wxGLContext* aContext ) GL_CONTEXT_MANAGER::GL_CONTEXT_MANAGER() - : m_glCtx( NULL ) + : m_glCtx( nullptr ) { } diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index 30ce90e3f8..b4c4d984f6 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 1992-2021 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 @@ -93,9 +93,10 @@ static int xcliplo = 0, static COLOR4D s_DC_lastcolor( 0, 0, 0, 0 ); static COLOR4D s_DC_lastbrushcolor( 0, 0, 0, 0 ); static bool s_DC_lastbrushfill = false; -static wxDC* s_DC_lastDC = NULL; +static wxDC* s_DC_lastDC = nullptr; -static void WinClipAndDrawLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width ) +static void WinClipAndDrawLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, + int width ) { GRLastMoveToX = x2; GRLastMoveToY = y2; @@ -120,17 +121,17 @@ void GRResetPenAndBrush( wxDC* DC ) GRSetBrush( DC, BLACK ); // Force no fill s_DC_lastbrushcolor = COLOR4D::UNSPECIFIED; s_DC_lastcolor = COLOR4D::UNSPECIFIED; - s_DC_lastDC = NULL; + s_DC_lastDC = nullptr; } /** - * Function GRSetColorPen - * sets a pen style, width, color, and alpha into the given device context. + * Set a pen style, width, color, and alpha into the given device context. */ void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style ) { wxDash dots[2] = { 1, 3 }; + // Under OSX and while printing when wxPen is set to 0, renderer follows the request drawing // nothing & in the bitmap world the minimum is enough to light a pixel, in vectorial one not if( width <= 1 ) @@ -147,21 +148,25 @@ void GRSetColorPen( wxDC* DC, COLOR4D Color, int width, wxPenStyle style ) { wxPen pen; pen.SetColour( Color.ToColour() ); + if( style == wxPENSTYLE_DOT ) { style = wxPENSTYLE_USER_DASH; pen.SetDashes( 2, dots ); } + pen.SetWidth( width ); pen.SetStyle( style ); DC->SetPen( pen ); } else + { // Should be not needed, but on Linux, in printing process // the curr pen settings needs to be sometimes re-initialized // Clearly, this is due to a bug, related to SetBrush(), // but we have to live with it, at least on wxWidgets 3.0 DC->SetPen( curr_pen ); + } } @@ -193,8 +198,7 @@ void GRSetBrush( wxDC* DC, COLOR4D Color, bool fill ) /** - * Function GRForceBlackPen - * @param flagforce True to force a black pen whenever the asked color + * @param flagforce True to force a black pen whenever the asked color. */ void GRForceBlackPen( bool flagforce ) { @@ -203,8 +207,7 @@ void GRForceBlackPen( bool flagforce ) /** - * Function GetGRForceBlackPenState - * @return s_ForceBlackPen (True if a black pen was forced) + * @return true if a black pen was forced. */ bool GetGRForceBlackPenState( void ) { @@ -242,7 +245,8 @@ void GRLine( EDA_RECT* ClipBox, } -void GRLine( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor, wxPenStyle aStyle ) +void GRLine( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd, int aWidth, + COLOR4D aColor, wxPenStyle aStyle ) { GRLine( aClipBox, aDC, aStart.x, aStart.y, aEnd.x, aEnd.y, aWidth, aColor, aStyle ); } @@ -267,16 +271,14 @@ void GRLineTo( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int width, COLOR4D Col } - - /** - * Function GRLineArray - * draws an array of lines (not a polygon). - * @param aClipBox = the clip box - * @param aDC = the device context into which drawing should occur. - * @param aLines = a list of pair of coordinate in user space: a pair for each line. - * @param aWidth = the width of each line. - * @param aColor = color to draw the lines + * Draw an array of lines (not a polygon). + * + * @param aClipBox is the clip box. + * @param aDC is the device context into which drawing should occur. + * @param aLines is a list of pair of coordinate in user space: a pair for each line. + * @param aWidth is the width of each line. + * @param aColor is the color to draw the lines. * @see COLOR4D */ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aLines, @@ -296,7 +298,7 @@ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aLines, int y1 = aLines[i].y; int x2 = aLines[i + 1].x; int y2 = aLines[i + 1].y; - if( ( aClipBox == NULL ) || !ClipLine( aClipBox, x1, y1, x2, y2 ) ) + if( ( aClipBox == nullptr ) || !ClipLine( aClipBox, x1, y1, x2, y2 ) ) aDC->DrawLine( x1, y1, x2, y2 ); } @@ -306,6 +308,7 @@ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aLines, aClipBox->Inflate(-aWidth/2); } + // Draw the outline of a thick segment with rounded ends void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, int aPenSize, COLOR4D Color ) @@ -322,7 +325,6 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, return; } - if( width <= 2 ) /* single line or 2 pixels */ { GRSetColorPen( DC, Color, width ); @@ -371,7 +373,6 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, else DC->DrawArc( start, end, org ); - // second edge start.x = len; start.y = -radius; @@ -469,7 +470,7 @@ static bool IsGRSPolyDrawable( EDA_RECT* ClipBox, int n, const wxPoint* Points ) * Draw a new polyline and fill it if Fill, in screen space. */ static void GRSPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, - int width, COLOR4D Color, COLOR4D BgColor ) + int width, COLOR4D Color, COLOR4D BgColor ) { if( !IsGRSPolyDrawable( ClipBox, n, Points ) ) return; @@ -489,6 +490,7 @@ static void GRSPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, { GRMoveTo( Points[0].x, Points[0].y ); + for( int i = 1; i < n; ++i ) { GRLineTo( ClipBox, DC, Points[i].x, Points[i].y, width, Color ); @@ -501,7 +503,7 @@ static void GRSPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, * Draw a new closed polyline and fill it if Fill, in screen space. */ static void GRSClosedPoly( EDA_RECT* aClipBox, wxDC* aDC, int aPointCount, const wxPoint* aPoints, - bool aFill, int aWidth, COLOR4D aColor, COLOR4D aBgColor ) + bool aFill, int aWidth, COLOR4D aColor, COLOR4D aBgColor ) { if( !IsGRSPolyDrawable( aClipBox, aPointCount, aPoints ) ) return; @@ -518,6 +520,7 @@ static void GRSClosedPoly( EDA_RECT* aClipBox, wxDC* aDC, int aPointCount, const { GRMoveTo( aPoints[0].x, aPoints[0].y ); + for( int i = 1; i < aPointCount; ++i ) { GRLineTo( aClipBox, aDC, aPoints[i].x, aPoints[i].y, aWidth, aColor ); @@ -538,7 +541,7 @@ static void GRSClosedPoly( EDA_RECT* aClipBox, wxDC* aDC, int aPointCount, const * Draw a new polyline and fill it if Fill, in drawing space. */ void GRPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, int width, - COLOR4D Color, COLOR4D BgColor ) + COLOR4D Color, COLOR4D BgColor ) { GRSPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor ); } @@ -548,14 +551,14 @@ void GRPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fil * Draw a closed polyline and fill it if Fill, in object space. */ void GRClosedPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, - COLOR4D Color, COLOR4D BgColor ) + COLOR4D Color, COLOR4D BgColor ) { GRClosedPoly( ClipBox, DC, n, Points, Fill, 0, Color, BgColor ); } void GRClosedPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, int width, - COLOR4D Color, COLOR4D BgColor ) + COLOR4D Color, COLOR4D BgColor ) { GRSClosedPoly( ClipBox, DC, n, Points, Fill, width, Color, BgColor ); } @@ -608,7 +611,8 @@ void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, COLOR4D Color ) } -void GRCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, int aWidth, COLOR4D aColor ) +void GRCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, int aWidth, + COLOR4D aColor ) { GRCircle( aClipBox, aDC, aPos.x, aPos.y, aRadius, aWidth, aColor ); } @@ -763,10 +767,13 @@ void GRArc( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, double StAngle, if( x < ( x0 - radius ) ) return; + if( y < ( y0 - radius ) ) return; + if( x > ( xm + radius ) ) return; + if( y > ( ym + radius ) ) return; } @@ -845,7 +852,8 @@ void GRRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, COLO } -void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC, const EDA_RECT& aRect, COLOR4D aColor, wxPenStyle aStyle ) +void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC, const EDA_RECT& aRect, COLOR4D aColor, + wxPenStyle aStyle ) { int x1 = aRect.GetX(); int y1 = aRect.GetY(); @@ -899,18 +907,16 @@ void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, /* * Draw a rectangle in screen space. */ - void GRSRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y2, int aWidth, COLOR4D aColor, wxPenStyle aStyle ) { wxPoint points[5]; - points[0] = wxPoint(x1, y1); - points[1] = wxPoint(x1, y2); - points[2] = wxPoint(x2, y2); - points[3] = wxPoint(x2, y1); + points[0] = wxPoint( x1, y1 ); + points[1] = wxPoint( x1, y2 ); + points[2] = wxPoint( x2, y2 ); + points[3] = wxPoint( x2, y1 ); points[4] = points[0]; - GRSClosedPoly( aClipBox, aDC, 5, points, NOT_FILLED, aWidth, - aColor, aColor ); + GRSClosedPoly( aClipBox, aDC, 5, points, NOT_FILLED, aWidth, aColor, aColor ); } @@ -918,43 +924,41 @@ void GRSFilledRect( EDA_RECT* aClipBox, wxDC* aDC, int x1, int y1, int x2, int y int aWidth, COLOR4D aColor, COLOR4D aBgColor ) { wxPoint points[5]; - points[0] = wxPoint(x1, y1); - points[1] = wxPoint(x1, y2); - points[2] = wxPoint(x2, y2); - points[3] = wxPoint(x2, y1); + points[0] = wxPoint( x1, y1 ); + points[1] = wxPoint( x1, y2 ); + points[2] = wxPoint( x2, y2 ); + points[3] = wxPoint( x2, y1 ); points[4] = points[0]; GRSetBrush( aDC, aBgColor, FILLED ); GRSetColorPen( aDC, aBgColor, aWidth ); - if( aClipBox && (aWidth > 0) ) + if( aClipBox && ( aWidth > 0 ) ) { - EDA_RECT clipbox(*aClipBox); - clipbox.Inflate(aWidth); - ClipAndDrawPoly(&clipbox, aDC, points, 5); // polygon approach is more accurate + EDA_RECT clipbox( *aClipBox ); + clipbox.Inflate( aWidth ); + ClipAndDrawPoly( &clipbox, aDC, points, 5 ); // polygon approach is more accurate } else + { ClipAndDrawPoly(aClipBox, aDC, points, 5 ); + } } /** - * Function ClipAndDrawPoly - * Used to clip a polygon and draw it as Filled Polygon - * uses the Sutherland and Hodgman algo to clip the given poly against a - * rectangle. This rectangle is the drawing area this is useful under - * Linux (2009) because filled polygons are incorrectly drawn if they have - * too large coordinates (seems due to integer overflows in calculations) - * Could be removed in some years, if become unnecessary. + * Used to clip a polygon and draw it as Filled Polygon. + * + * Uses the Sutherland and Hodgman algo to clip the given poly against a rectangle. This + * rectangle is the drawing area this is useful under Linux (2009) because filled polygons + * are incorrectly drawn if they have too large coordinates (seems due to integer overflows + * in calculations). Could be removed in some years, if become unnecessary. */ -/* Note: aClipBox == NULL is legal, so if aClipBox == NULL, - * the polygon is drawn, but not clipped - */ #include void ClipAndDrawPoly( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint* Points, int n ) { - if( aClipBox == NULL ) + if( aClipBox == nullptr ) { aDC->DrawPolygon( n, Points ); return; @@ -987,8 +991,7 @@ void ClipAndDrawPoly( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint* Points, int } -void GRBezier( EDA_RECT* aClipBox, wxDC* aDC, - std::vector& aPoint, +void GRBezier( EDA_RECT* aClipBox, wxDC* aDC, std::vector& aPoint, int aWidth, COLOR4D aColor ) { std::vector output; @@ -1000,17 +1003,12 @@ void GRBezier( EDA_RECT* aClipBox, wxDC* aDC, } -void GRDrawAnchor( EDA_RECT *aClipBox, wxDC *aDC, int x, int y, - int aSize, COLOR4D aColor ) +void GRDrawAnchor( EDA_RECT *aClipBox, wxDC *aDC, int x, int y, int aSize, COLOR4D aColor ) { int anchor_size = aDC->DeviceToLogicalXRel( aSize ); - GRLine( aClipBox, aDC, - x - anchor_size, y, - x + anchor_size, y, 0, aColor ); - GRLine( aClipBox, aDC, - x, y - anchor_size, - x, y + anchor_size, 0, aColor ); + GRLine( aClipBox, aDC, x - anchor_size, y, x + anchor_size, y, 0, aColor ); + GRLine( aClipBox, aDC, x, y - anchor_size, x, y + anchor_size, 0, aColor ); } diff --git a/common/gr_text.cpp b/common/gr_text.cpp index 0ccea23c7d..86cd793de2 100644 --- a/common/gr_text.cpp +++ b/common/gr_text.cpp @@ -230,6 +230,6 @@ void PLOTTER::Text( const wxPoint& aPos, SetColor( aColor ); SetCurrentLineWidth( aPenWidth, aData ); - GRText( NULL, aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aPenWidth, + GRText( nullptr, aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aPenWidth, aItalic, aBold, nullptr, nullptr, this ); } diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index d8c4ac0e10..10235bbfbc 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2012-18 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2012-2021 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 @@ -43,14 +43,21 @@ GRID_TRICKS::GRID_TRICKS( WX_GRID* aGrid ): m_sel_row_count = 0; m_sel_col_count = 0; - aGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), NULL, this ); - aGrid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftDClick ), NULL, this ); - aGrid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridCellRightClick ), NULL, this ); - aGrid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridLabelRightClick ), NULL, this ); - aGrid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridLabelLeftClick ), NULL, this ); - aGrid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), NULL, this ); - aGrid->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( GRID_TRICKS::onKeyDown ), NULL, this ); - aGrid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ), NULL, this ); + aGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, + wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), nullptr, this ); + aGrid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, + wxGridEventHandler( GRID_TRICKS::onGridCellLeftDClick ), nullptr, this ); + aGrid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, + wxGridEventHandler( GRID_TRICKS::onGridCellRightClick ), nullptr, this ); + aGrid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK, + wxGridEventHandler( GRID_TRICKS::onGridLabelRightClick ), nullptr, this ); + aGrid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK, + wxGridEventHandler( GRID_TRICKS::onGridLabelLeftClick ), nullptr, this ); + aGrid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), nullptr, this ); + aGrid->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( GRID_TRICKS::onKeyDown ), nullptr, this ); + aGrid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ), + nullptr, this ); } @@ -238,10 +245,13 @@ void GRID_TRICKS::onGridLabelRightClick( wxGridEvent& ) void GRID_TRICKS::showPopupMenu( wxMenu& menu ) { - menu.Append( GRIDTRICKS_ID_CUT, _( "Cut" ) + "\tCtrl+X", _( "Clear selected cells placing original contents on clipboard" ) ); - menu.Append( GRIDTRICKS_ID_COPY, _( "Copy" ) + "\tCtrl+C", _( "Copy selected cells to clipboard" ) ); - menu.Append( GRIDTRICKS_ID_PASTE, _( "Paste" ) + "\tCtrl+V", _( "Paste clipboard cells to matrix at current cell" ) ); - menu.Append( GRIDTRICKS_ID_DELETE, _( "Delete" ) + "\tDel", _( "Delete selected cells" ) ); + menu.Append( GRIDTRICKS_ID_CUT, _( "Cut" ) + "\tCtrl+X", + _( "Clear selected cells placing original contents on clipboard" ) ); + menu.Append( GRIDTRICKS_ID_COPY, _( "Copy" ) + "\tCtrl+C", + _( "Copy selected cells to clipboard" ) ); + menu.Append( GRIDTRICKS_ID_PASTE, _( "Paste" ) + "\tCtrl+V", + _( "Paste clipboard cells to matrix at current cell" ) ); + menu.Append( GRIDTRICKS_ID_DELETE, _( "Delete" ) + "\tDel", _( "Delete selected cells" ) ); menu.Append( GRIDTRICKS_ID_SELECT, _( "Select All" ) + "\tCtrl+A", _( "Select all cells" ) ); getSelectedArea(); @@ -457,9 +467,13 @@ void GRID_TRICKS::onKeyDown( wxKeyEvent& ev ) break; if( !test->GetChildren().empty() ) + { test = test->GetChildren().front(); + } else if( test->GetNextSibling() ) + { test = test->GetNextSibling(); + } else { while( test ) diff --git a/common/kicad_curl/kicad_curl_easy.cpp b/common/kicad_curl/kicad_curl_easy.cpp index ffeda6b807..d48063d2de 100644 --- a/common/kicad_curl/kicad_curl_easy.cpp +++ b/common/kicad_curl/kicad_curl_easy.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Mark Roszko - * Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2015-2021 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 @@ -45,7 +45,7 @@ static size_t write_callback( void* contents, size_t size, size_t nmemb, void* u KICAD_CURL_EASY::KICAD_CURL_EASY() : - m_headers( NULL ) + m_headers( nullptr ) { // Call KICAD_CURL::Init() from in here everytime, but only the first time // will incur any overhead. This strategy ensures that libcurl is never loaded @@ -120,6 +120,7 @@ bool KICAD_CURL_EASY::SetUserAgent( const std::string& aAgent ) { return true; } + return false; } @@ -130,6 +131,7 @@ bool KICAD_CURL_EASY::SetURL( const std::string& aURL ) { return true; } + return false; } @@ -140,6 +142,7 @@ bool KICAD_CURL_EASY::SetFollowRedirects( bool aFollow ) { return true; } + return false; } diff --git a/common/kiid.cpp b/common/kiid.cpp index 1f5ff86fb3..3e9ff02315 100644 --- a/common/kiid.cpp +++ b/common/kiid.cpp @@ -99,10 +99,10 @@ KIID::KIID( const wxString& aString ) : m_uuid(), m_cached_timestamp( 0 ) for( int i = 0; i < 4; ++i ) { wxString octet = aString.substr( i * 2, 2 ); - m_uuid.data[i + 12] = strtol( octet.data(), NULL, 16 ); + m_uuid.data[i + 12] = strtol( octet.data(), nullptr, 16 ); } - m_cached_timestamp = strtol( aString.c_str(), NULL, 16 ); + m_cached_timestamp = strtol( aString.c_str(), nullptr, 16 ); } else { @@ -111,7 +111,7 @@ KIID::KIID( const wxString& aString ) : m_uuid(), m_cached_timestamp( 0 ) m_uuid = stringGenerator( aString.wc_str() ); if( IsLegacyTimestamp() ) - m_cached_timestamp = strtol( aString.substr( 28 ).c_str(), NULL, 16 ); + m_cached_timestamp = strtol( aString.substr( 28 ).c_str(), nullptr, 16 ); } catch( ... ) { @@ -177,7 +177,7 @@ KIID::KIID( timestamp_t aTimestamp ) for( int i = 0; i < 4; ++i ) { wxString octet = str.substr( i * 2, 2 ); - m_uuid.data[i + 12] = strtol( octet.data(), NULL, 16 ); + m_uuid.data[i + 12] = strtol( octet.data(), nullptr, 16 ); } } diff --git a/common/kiway.cpp b/common/kiway.cpp index bad8ef31c5..d6bf2bb4ff 100644 --- a/common/kiway.cpp +++ b/common/kiway.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2014-2020 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2014-2021 KiCad Developers, see CHANGELOG.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 @@ -83,12 +83,16 @@ void KIWAY::SetTop( wxFrame* aTop ) #if 0 if( m_top ) { - m_top->Disconnect( wxEVT_DESTROY, wxWindowDestroyEventHandler( KIWAY::player_destroy_handler ), NULL, this ); + m_top->Disconnect( wxEVT_DESTROY, + wxWindowDestroyEventHandler( KIWAY::player_destroy_handler ), + nullptr, this ); } if( aTop ) { - aTop->Connect( wxEVT_DESTROY, wxWindowDestroyEventHandler( KIWAY::player_destroy_handler ), NULL, this ); + aTop->Connect( wxEVT_DESTROY, + wxWindowDestroyEventHandler( KIWAY::player_destroy_handler ), + nullptr, this ); } #endif @@ -188,7 +192,7 @@ PROJECT& KIWAY::Prj() const } -KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) +KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) { // Since this will be called from python, cannot assume that code will // not pass a bad aFaceId. @@ -198,7 +202,7 @@ KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) // way it gets some explanatory text. wxASSERT_MSG( 0, wxT( "caller has a bug, passed a bad aFaceId" ) ); - return NULL; + return nullptr; } // return the previously loaded KIFACE, if it was. @@ -208,7 +212,7 @@ KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) wxString msg; // DSO with KIFACE has not been loaded yet, does caller want to load it? - if( doLoad ) + if( doLoad ) { wxString dname = dso_search_path( aFaceId ); @@ -227,7 +231,7 @@ KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) wxDynamicLibrary dso; - void* addr = NULL; + void* addr = nullptr; // For some reason wxDynamicLibrary::Load() crashes in some languages // (chinese for instance) when loading the dynamic library. @@ -252,7 +256,7 @@ KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) msg.Printf( _( "Failed to load kiface library '%s'." ), dname ); THROW_IO_ERROR( msg ); } - else if( ( addr = dso.GetSymbol( wxT( KIFACE_INSTANCE_NAME_AND_VERSION ) ) ) == NULL ) + else if( ( addr = dso.GetSymbol( wxT( KIFACE_INSTANCE_NAME_AND_VERSION ) ) ) == nullptr ) { // Failure: error reporting UI was done via wxLogSysError(). // No further reporting required here. Assume the same thing applies here as @@ -290,9 +294,8 @@ KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) // to exist, and we did not find one. If we do not find one, this is an // installation bug. - msg = wxString::Format( _( - "Fatal Installation Bug. File:\n" - "\"%s\"\ncould not be loaded\n" ), dname ); + msg = wxString::Format( _( "Fatal Installation Bug. File:\n" + "\"%s\"\ncould not be loaded\n" ), dname ); if( ! wxFileExists( dname ) ) msg << _( "It is missing.\n" ); @@ -310,7 +313,7 @@ KIFACE* KIWAY::KiFACE( FACE_T aFaceId, bool doLoad ) THROW_IO_ERROR( msg ); } - return NULL; + return nullptr; } @@ -363,11 +366,11 @@ KIWAY_PLAYER* KIWAY::GetPlayerFrame( FRAME_T aFrameType ) wxWindowID storedId = m_playerFrameId[aFrameType]; if( storedId == wxID_NONE ) - return NULL; + return nullptr; wxWindow* frame = wxWindow::FindWindowById( storedId ); - // Since wxWindow::FindWindow*() is not cheap (especially if the window does not exist), + // Since wxWindow::FindWindow*() is not cheap (especially if the window does not exist), // clear invalid entries to save CPU on repeated calls that do not lead to frame creation if( !frame ) m_playerFrameId[aFrameType].compare_exchange_strong( storedId, wxID_NONE ); @@ -447,7 +450,7 @@ bool KIWAY::PlayerClose( FRAME_T aFrameType, bool doForce ) KIWAY_PLAYER* frame = GetPlayerFrame( aFrameType ); - if( frame == NULL ) // Already closed + if( frame == nullptr ) // Already closed return true; if( frame->NonUserClose( doForce ) ) @@ -470,7 +473,8 @@ bool KIWAY::PlayersClose( bool doForce ) } -void KIWAY::ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload, wxWindow* aSource ) +void KIWAY::ExpressMail( FRAME_T aDestination, MAIL_T aCommand, std::string& aPayload, + wxWindow* aSource ) { KIWAY_EXPRESS mail( aDestination, aCommand, aPayload, aSource ); diff --git a/common/pgm_base.cpp b/common/pgm_base.cpp index 5772def733..5b2aa4a27e 100644 --- a/common/pgm_base.cpp +++ b/common/pgm_base.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 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 @@ -163,7 +163,7 @@ const wxString& PGM_BASE::GetEditorName( bool aCanShowFileChooser ) // If we still don't have an editor name show a dialog asking the user to select one if( !editorname && aCanShowFileChooser ) { - DisplayInfoMessage( NULL, _( "No default editor found, you must choose it" ) ); + DisplayInfoMessage( nullptr, _( "No default editor found, you must choose it" ) ); editorname = AskUserForPreferredEditor(); } @@ -195,7 +195,7 @@ const wxString PGM_BASE::AskUserForPreferredEditor( const wxString& aDefaultEdit // Show the modal editor and return the file chosen (may be empty if the user cancels // the dialog). - return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path, name, ext, mask, NULL, + return EDA_FILE_SELECTOR( _( "Select Preferred Editor" ), path, name, ext, mask, nullptr, wxFD_OPEN | wxFD_FILE_MUST_EXIST, true ); } @@ -233,13 +233,13 @@ bool PGM_BASE::InitPgm( bool aHeadless ) App().SetAppName( pgm_name ); // Install some image handlers, mainly for help - if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL ) + if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == nullptr ) wxImage::AddHandler( new wxPNGHandler ); - if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == NULL ) + if( wxImage::FindHandler( wxBITMAP_TYPE_GIF ) == nullptr ) wxImage::AddHandler( new wxGIFHandler ); - if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == NULL ) + if( wxImage::FindHandler( wxBITMAP_TYPE_JPEG ) == nullptr ) wxImage::AddHandler( new wxJPEGHandler ); wxFileSystem::AddHandler( new wxZipFSHandler ); @@ -563,7 +563,7 @@ void PGM_BASE::SetLanguagePath() wxLocale::AddCatalogLookupPathPrefix( fn.GetPath() ); } - // Append path for macOS install + // Append path for macOS install fn.RemoveLastDir(); fn.RemoveLastDir(); fn.RemoveLastDir(); diff --git a/common/plotters/DXF_plotter.cpp b/common/plotters/DXF_plotter.cpp index 7fe8ff1ba1..5fe08c6d3b 100644 --- a/common/plotters/DXF_plotter.cpp +++ b/common/plotters/DXF_plotter.cpp @@ -391,7 +391,7 @@ bool DXF_PLOTTER::EndPlot() " 0\n" "EOF\n", m_outputFile ); fclose( m_outputFile ); - m_outputFile = NULL; + m_outputFile = nullptr; return true; } @@ -493,7 +493,7 @@ void DXF_PLOTTER::PlotPoly( const std::vector& aCornerList, MoveTo( aCornerList[0] ); for( unsigned ii = 1; ii < aCornerList.size(); ii++ ) - ThickSegment( aCornerList[ii-1], aCornerList[ii], aWidth, FILLED, NULL ); + ThickSegment( aCornerList[ii-1], aCornerList[ii], aWidth, FILLED, nullptr ); return; } @@ -623,9 +623,6 @@ void DXF_PLOTTER::ThickSegment( const wxPoint& aStart, const wxPoint& aEnd, int } -/* Plot an arc in DXF format - * Filling is not supported - */ void DXF_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius, FILL_TYPE fill, int width ) { diff --git a/common/plotters/PDF_plotter.cpp b/common/plotters/PDF_plotter.cpp index 9252db4252..a83ee59a8d 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -553,7 +553,7 @@ void PDF_PLOTTER::closePdfStream() else { // NULL means memos owns the memory, but provide a hint on optimum size needed. - wxMemoryOutputStream memos( NULL, std::max( 2000l, stream_len ) ) ; + wxMemoryOutputStream memos( nullptr, std::max( 2000l, stream_len ) ) ; { /* Somewhat standard parameters to compress in DEFLATE. The PDF spec is @@ -752,7 +752,7 @@ bool PDF_PLOTTER::EndPlot() // The info dictionary int infoDictHandle = startPdfObject(); char date_buf[250]; - time_t ltime = time( NULL ); + time_t ltime = time( nullptr ); strftime( date_buf, 250, "D:%Y%m%d%H%M%S", localtime( <ime ) ); if( m_title.IsEmpty() ) @@ -811,7 +811,7 @@ bool PDF_PLOTTER::EndPlot() (unsigned long) xrefTable.size(), catalogHandle, infoDictHandle, xref_start ); fclose( m_outputFile ); - m_outputFile = NULL; + m_outputFile = nullptr; return true; } diff --git a/common/plotters/common_plot_functions.cpp b/common/plotters/common_plot_functions.cpp index b65ae634bf..880d848e15 100644 --- a/common/plotters/common_plot_functions.cpp +++ b/common/plotters/common_plot_functions.cpp @@ -1,7 +1,7 @@ /* * 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. + * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. * * * This program is free software; you can redistribute it and/or @@ -145,7 +145,7 @@ void PlotDrawingSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BL DS_DRAW_ITEM_BITMAP* drawItem = (DS_DRAW_ITEM_BITMAP*) item; DS_DATA_ITEM_BITMAP* bitmap = (DS_DATA_ITEM_BITMAP*) drawItem->GetPeer(); - if( bitmap->m_ImageBitmap == NULL ) + if( bitmap->m_ImageBitmap == nullptr ) break; bitmap->m_ImageBitmap->PlotImage( plotter, drawItem->GetPosition(), plotColor, diff --git a/common/plotters/plotter.cpp b/common/plotters/plotter.cpp index 277c1ea5bc..5c96fb9048 100644 --- a/common/plotters/plotter.cpp +++ b/common/plotters/plotter.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2021 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 @@ -83,7 +83,7 @@ bool PLOTTER::OpenFile( const wxString& aFullFilename ) // but only for most of them m_outputFile = wxFopen( m_filename, wxT( "wt" ) ); - if( m_outputFile == NULL ) + if( m_outputFile == nullptr ) return false ; return true; @@ -136,6 +136,7 @@ double PLOTTER::userToDeviceSize( double size ) const #define IU_PER_MILS ( m_IUsPerDecimil * 10 ) + double PLOTTER::GetDotMarkLenIU() const { return userToDeviceSize( DOT_MARK_LEN( GetCurrentLineWidth() ) ); @@ -157,7 +158,7 @@ double PLOTTER::GetDashGapLenIU() const void PLOTTER::Arc( const SHAPE_ARC& aArc ) { Arc( wxPoint( aArc.GetCenter() ), aArc.GetStartAngle(), aArc.GetEndAngle(), aArc.GetRadius(), - FILL_TYPE::NO_FILL, aArc.GetWidth() ); + FILL_TYPE::NO_FILL, aArc.GetWidth() ); } @@ -237,8 +238,7 @@ void PLOTTER::BezierCurve( const wxPoint& aStart, const wxPoint& aControl1, void PLOTTER::PlotImage(const wxImage & aImage, const wxPoint& aPos, double aScaleFactor ) { - wxSize size( aImage.GetWidth() * aScaleFactor, - aImage.GetHeight() * aScaleFactor ); + wxSize size( aImage.GetWidth() * aScaleFactor, aImage.GetHeight() * aScaleFactor ); wxPoint start = aPos; start.x -= size.x / 2; @@ -338,6 +338,7 @@ void PLOTTER::markerVBar( const wxPoint& pos, int radius ) void PLOTTER::Marker( const wxPoint& position, int diametre, unsigned aShapeId ) { int radius = diametre / 2; + /* Marker are composed by a series of 'parts' superimposed; not every combination make sense, obviously. Since they are used in order I tried to keep the uglier/more complex constructions at the end. @@ -347,72 +348,73 @@ void PLOTTER::Marker( const wxPoint& position, int diametre, unsigned aShapeId ) If Visual C++ supported the 0b literals they would be optimally and easily encoded as an integer array. We have to do with octal */ static const unsigned char marker_patterns[MARKER_COUNT] = { - // Bit order: O Square Lozenge - | \ / - // First choice: simple shapes - 0003, // X - 0100, // O - 0014, // + - 0040, // Sq - 0020, // Lz - // Two simple shapes - 0103, // X O - 0017, // X + - 0043, // X Sq - 0023, // X Lz - 0114, // O + - 0140, // O Sq - 0120, // O Lz - 0054, // + Sq - 0034, // + Lz - 0060, // Sq Lz - // Three simple shapes - 0117, // X O + - 0143, // X O Sq - 0123, // X O Lz - 0057, // X + Sq - 0037, // X + Lz - 0063, // X Sq Lz - 0154, // O + Sq - 0134, // O + Lz - 0074, // + Sq Lz - // Four simple shapes - 0174, // O Sq Lz + - 0163, // X O Sq Lz - 0157, // X O Sq + - 0137, // X O Lz + - 0077, // X Sq Lz + - // This draws *everything * - 0177, // X O Sq Lz + - // Here we use the single bars... so the cross is forbidden - 0110, // O - - 0104, // O | - 0101, // O / - 0050, // Sq - - 0044, // Sq | - 0041, // Sq / - 0030, // Lz - - 0024, // Lz | - 0021, // Lz / - 0150, // O Sq - - 0144, // O Sq | - 0141, // O Sq / - 0130, // O Lz - - 0124, // O Lz | - 0121, // O Lz / - 0070, // Sq Lz - - 0064, // Sq Lz | - 0061, // Sq Lz / - 0170, // O Sq Lz - - 0164, // O Sq Lz | - 0161, // O Sq Lz / - // Last resort: the backlash component (easy to confound) - 0102, // \ O - 0042, // \ Sq - 0022, // \ Lz - 0142, // \ O Sq - 0122, // \ O Lz - 0062, // \ Sq Lz - 0162 // \ O Sq Lz + + // Bit order: O Square Lozenge - | \ / + // First choice: simple shapes + 0003, // X + 0100, // O + 0014, // + + 0040, // Sq + 0020, // Lz + // Two simple shapes + 0103, // X O + 0017, // X + + 0043, // X Sq + 0023, // X Lz + 0114, // O + + 0140, // O Sq + 0120, // O Lz + 0054, // + Sq + 0034, // + Lz + 0060, // Sq Lz + // Three simple shapes + 0117, // X O + + 0143, // X O Sq + 0123, // X O Lz + 0057, // X + Sq + 0037, // X + Lz + 0063, // X Sq Lz + 0154, // O + Sq + 0134, // O + Lz + 0074, // + Sq Lz + // Four simple shapes + 0174, // O Sq Lz + + 0163, // X O Sq Lz + 0157, // X O Sq + + 0137, // X O Lz + + 0077, // X Sq Lz + + // This draws *everything * + 0177, // X O Sq Lz + + // Here we use the single bars... so the cross is forbidden + 0110, // O - + 0104, // O | + 0101, // O / + 0050, // Sq - + 0044, // Sq | + 0041, // Sq / + 0030, // Lz - + 0024, // Lz | + 0021, // Lz / + 0150, // O Sq - + 0144, // O Sq | + 0141, // O Sq / + 0130, // O Lz - + 0124, // O Lz | + 0121, // O Lz / + 0070, // Sq Lz - + 0064, // Sq Lz | + 0061, // Sq Lz / + 0170, // O Sq Lz - + 0164, // O Sq Lz | + 0161, // O Sq Lz / + // Last resort: the backlash component (easy to confound) + 0102, // \ O + 0042, // \ Sq + 0022, // \ Lz + 0142, // \ O Sq + 0122, // \ O Lz + 0062, // \ Sq Lz + 0162 // \ O Sq Lz }; if( aShapeId >= MARKER_COUNT ) { @@ -421,22 +423,29 @@ void PLOTTER::Marker( const wxPoint& position, int diametre, unsigned aShapeId ) } else { - // Decode the pattern and draw the corresponding parts - unsigned char pat = marker_patterns[aShapeId]; - if( pat & 0001 ) - markerSlash( position, radius ); - if( pat & 0002 ) - markerBackSlash( position, radius ); - if( pat & 0004 ) - markerVBar( position, radius ); - if( pat & 0010 ) - markerHBar( position, radius ); - if( pat & 0020 ) - markerLozenge( position, radius ); - if( pat & 0040 ) - markerSquare( position, radius ); - if( pat & 0100 ) - markerCircle( position, radius ); + // Decode the pattern and draw the corresponding parts + unsigned char pat = marker_patterns[aShapeId]; + + if( pat & 0001 ) + markerSlash( position, radius ); + + if( pat & 0002 ) + markerBackSlash( position, radius ); + + if( pat & 0004 ) + markerVBar( position, radius ); + + if( pat & 0010 ) + markerHBar( position, radius ); + + if( pat & 0020 ) + markerLozenge( position, radius ); + + if( pat & 0040 ) + markerSquare( position, radius ); + + if( pat & 0100 ) + markerCircle( position, radius ); } } @@ -458,7 +467,7 @@ void PLOTTER::segmentAsOval( const wxPoint& start, const wxPoint& end, int width size.x = KiROUND( EuclideanNorm( size ) ) + width; size.y = width; - FlashPadOval( center, size, orient, tracemode, NULL ); + FlashPadOval( center, size, orient, tracemode, nullptr ); } @@ -538,7 +547,9 @@ void PLOTTER::ThickArc( const wxPoint& centre, double StAngle, double EndAngle, int radius, int width, OUTLINE_MODE tracemode, void* aData ) { if( tracemode == FILLED ) + { Arc( centre, StAngle, EndAngle, radius, FILL_TYPE::NO_FILL, width ); + } else { SetCurrentLineWidth( -1 ); @@ -554,19 +565,21 @@ void PLOTTER::ThickRect( const wxPoint& p1, const wxPoint& p2, int width, OUTLINE_MODE tracemode, void* aData ) { if( tracemode == FILLED ) + { Rect( p1, p2, FILL_TYPE::NO_FILL, width ); + } else { SetCurrentLineWidth( -1 ); wxPoint offsetp1( p1.x - (width - m_currentPenWidth) / 2, p1.y - (width - m_currentPenWidth) / 2 ); wxPoint offsetp2( p2.x + (width - m_currentPenWidth) / 2, - p2.y + (width - m_currentPenWidth) / 2 ); + p2.y + (width - m_currentPenWidth) / 2 ); Rect( offsetp1, offsetp2, FILL_TYPE::NO_FILL, -1 ); - offsetp1.x += (width - m_currentPenWidth); - offsetp1.y += (width - m_currentPenWidth); - offsetp2.x -= (width - m_currentPenWidth); - offsetp2.y -= (width - m_currentPenWidth); + offsetp1.x += ( width - m_currentPenWidth ); + offsetp1.y += ( width - m_currentPenWidth ); + offsetp2.x -= ( width - m_currentPenWidth ); + offsetp2.y -= ( width - m_currentPenWidth ); Rect( offsetp1, offsetp2, FILL_TYPE::NO_FILL, -1 ); } } @@ -603,7 +616,7 @@ void PLOTTER::FilledCircle( const wxPoint& pos, int diametre, OUTLINE_MODE trace void PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_TYPE aFill, - int aWidth, void * aData ) + int aWidth, void* aData ) { std::vector cornerList; cornerList.reserve( aCornerList.PointCount() ); diff --git a/common/plugins/cadstar/cadstar_archive_parser.cpp b/common/plugins/cadstar/cadstar_archive_parser.cpp index 7b08490750..12dae974cf 100644 --- a/common/plugins/cadstar/cadstar_archive_parser.cpp +++ b/common/plugins/cadstar/cadstar_archive_parser.cpp @@ -1000,14 +1000,16 @@ CADSTAR_ARCHIVE_PARSER::READABILITY CADSTAR_ARCHIVE_PARSER::ParseReadability( XN } -void CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext ) +void CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::ParseIdentifiers( XNODE* aNode, + PARSER_CONTEXT* aContext ) { TextCodeID = GetXmlAttributeIDString( aNode, 0 ); LayerID = GetXmlAttributeIDString( aNode, 1 ); } -bool CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext ) +bool CADSTAR_ARCHIVE_PARSER::ATTRIBUTE_LOCATION::ParseSubNode( XNODE* aChildNode, + PARSER_CONTEXT* aContext ) { wxString cNodeName = aChildNode->GetName(); @@ -1758,7 +1760,8 @@ void CADSTAR_ARCHIVE_PARSER::PART::PART_PIN::Parse( XNODE* aNode, PARSER_CONTEXT } -void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::PIN_EQUIVALENCE::Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) +void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::PIN_EQUIVALENCE::Parse( XNODE* aNode, + PARSER_CONTEXT* aContext ) { wxASSERT( aNode->GetName() == wxT( "PINEQUIVALENCE" ) ); @@ -1781,7 +1784,8 @@ void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::PIN_EQUIVALENCE::Parse( XNODE* aN } -void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::SWAP_GATE::Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) +void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::SWAP_GATE::Parse( XNODE* aNode, + PARSER_CONTEXT* aContext ) { wxASSERT( aNode->GetName() == wxT( "SWAPGATE" ) ); @@ -1804,7 +1808,8 @@ void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::SWAP_GATE::Parse( XNODE* aNode, P } -void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::SWAP_GROUP::Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) +void CADSTAR_ARCHIVE_PARSER::PART::DEFINITION::SWAP_GROUP::Parse( XNODE* aNode, + PARSER_CONTEXT* aContext ) { wxASSERT( aNode->GetName() == wxT( "SWAPGROUP" ) ); @@ -1961,7 +1966,8 @@ void CADSTAR_ARCHIVE_PARSER::PARTS::Parse( XNODE* aNode, PARSER_CONTEXT* aContex } -void CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext ) +void CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseIdentifiers( XNODE* aNode, + PARSER_CONTEXT* aContext ) { wxASSERT( aNode->GetName() == wxT( "JPT" ) ); @@ -1970,7 +1976,8 @@ void CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseIdentifiers( XNODE* aNode, PARS } -bool CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext ) +bool CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::ParseSubNode( XNODE* aChildNode, + PARSER_CONTEXT* aContext ) { wxString cNodeName = aChildNode->GetName(); @@ -2004,7 +2011,8 @@ void CADSTAR_ARCHIVE_PARSER::NET::JUNCTION::Parse( XNODE* aNode, PARSER_CONTEXT* } -void CADSTAR_ARCHIVE_PARSER::NET::CONNECTION::ParseIdentifiers( XNODE* aNode, PARSER_CONTEXT* aContext ) +void CADSTAR_ARCHIVE_PARSER::NET::CONNECTION::ParseIdentifiers( XNODE* aNode, + PARSER_CONTEXT* aContext ) { wxASSERT( aNode->GetName() == wxT( "CONN" ) ); @@ -2014,7 +2022,8 @@ void CADSTAR_ARCHIVE_PARSER::NET::CONNECTION::ParseIdentifiers( XNODE* aNode, PA } -bool CADSTAR_ARCHIVE_PARSER::NET::CONNECTION::ParseSubNode( XNODE* aChildNode, PARSER_CONTEXT* aContext ) +bool CADSTAR_ARCHIVE_PARSER::NET::CONNECTION::ParseSubNode( XNODE* aChildNode, + PARSER_CONTEXT* aContext ) { wxString cNodeName = aChildNode->GetName(); @@ -2302,11 +2311,11 @@ void CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd( XNODE* aNode, wxString aValue } -XNODE* CADSTAR_ARCHIVE_PARSER::LoadArchiveFile( - const wxString& aFileName, const wxString& aFileTypeIdentifier ) +XNODE* CADSTAR_ARCHIVE_PARSER::LoadArchiveFile( const wxString& aFileName, + const wxString& aFileTypeIdentifier ) { KEYWORD emptyKeywords[1] = {}; - XNODE * iNode = NULL, *cNode = NULL; + XNODE * iNode = nullptr, *cNode = nullptr; int tok; bool cadstarFileCheckDone = false; wxString str; @@ -2371,7 +2380,7 @@ XNODE* CADSTAR_ARCHIVE_PARSER::LoadArchiveFile( } // Not enough closing brackets - if( iNode != NULL ) + if( iNode != nullptr ) THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) ); // Throw if no data was parsed @@ -2380,7 +2389,7 @@ XNODE* CADSTAR_ARCHIVE_PARSER::LoadArchiveFile( else THROW_IO_ERROR( _( "The selected file is not valid or might be corrupt!" ) ); - return NULL; + return nullptr; } @@ -2390,8 +2399,8 @@ bool CADSTAR_ARCHIVE_PARSER::IsValidAttribute( wxXmlAttribute* aAttribute ) } -wxString CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString( - XNODE* aNode, unsigned int aID, bool aIsRequired ) +wxString CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString( XNODE* aNode, unsigned int aID, + bool aIsRequired ) { wxString attrName, retVal; attrName = "attr"; @@ -2409,8 +2418,8 @@ wxString CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString( } -long CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDLong( - XNODE* aNode, unsigned int aID, bool aIsRequired ) +long CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, + bool aIsRequired ) { long retVal; bool success = GetXmlAttributeIDString( aNode, aID, aIsRequired ).ToLong( &retVal ); @@ -2441,8 +2450,8 @@ void CADSTAR_ARCHIVE_PARSER::CheckNoNextNodes( XNODE* aNode ) } -void CADSTAR_ARCHIVE_PARSER::ParseChildEValue( - XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse ) +void CADSTAR_ARCHIVE_PARSER::ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, + EVALUE& aValueToParse ) { if( aNode->GetChildren()->GetName() == wxT( "E" ) ) aValueToParse.Parse( aNode->GetChildren(), aContext ); diff --git a/common/plugins/eagle/eagle_parser.cpp b/common/plugins/eagle/eagle_parser.cpp index aa158cf151..141b412e71 100644 --- a/common/plugins/eagle/eagle_parser.cpp +++ b/common/plugins/eagle/eagle_parser.cpp @@ -195,7 +195,7 @@ EROT Convert( const wxString& aRot ) + 1 // skip leading 'R' + int( value.spin ) // skip optional leading 'S' + int( value.mirror ), // skip optional leading 'M' - NULL ); + nullptr ); return value; } diff --git a/common/project.cpp b/common/project.cpp index 5989436381..8176fdd064 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2014-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2014-2021 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 @@ -42,7 +42,7 @@ PROJECT::PROJECT() : m_projectFile( nullptr ), m_localSettings( nullptr ) { - memset( m_elems, 0, sizeof(m_elems) ); + memset( m_elems, 0, sizeof( m_elems ) ); } @@ -52,7 +52,7 @@ void PROJECT::ElemsClear() // be in the same link image as PROJECT. for( unsigned i = 0; i < arrayDim( m_elems ); ++i ) { - SetElem( ELEM_T( i ), NULL ); + SetElem( ELEM_T( i ), nullptr ); } } @@ -246,19 +246,18 @@ const wxString& PROJECT::GetRString( RSTRING_T aIndex ) PROJECT::_ELEM* PROJECT::GetElem( ELEM_T aIndex ) { // This is virtual, so implement it out of line - if( unsigned( aIndex ) < arrayDim( m_elems ) ) { return m_elems[aIndex]; } - return NULL; + + return nullptr; } void PROJECT::SetElem( ELEM_T aIndex, _ELEM* aElem ) { // This is virtual, so implement it out of line - if( unsigned( aIndex ) < arrayDim( m_elems ) ) { delete m_elems[aIndex]; @@ -308,12 +307,12 @@ FP_LIB_TABLE* PROJECT::PcbFootprintLibs( KIWAY& aKiway ) } catch( const IO_ERROR& ioe ) { - DisplayErrorMessage( NULL, _( "Error loading project footprint library table." ), + DisplayErrorMessage( nullptr, _( "Error loading project footprint library table." ), ioe.What() ); } catch( ... ) { - DisplayErrorMessage( NULL, _( "Error loading project footprint library table." ) ); + DisplayErrorMessage( nullptr, _( "Error loading project footprint library table." ) ); } } diff --git a/common/rc_item.cpp b/common/rc_item.cpp index f2fc88ac2a..e0e6b837d5 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2021 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 @@ -178,7 +178,7 @@ RC_TREE_MODEL::RC_TREE_MODEL( EDA_DRAW_FRAME* aParentFrame, wxDataViewCtrl* aVie { m_view->GetMainWindow()->Connect( wxEVT_SIZE, wxSizeEventHandler( RC_TREE_MODEL::onSizeView ), - NULL, this ); + nullptr, this ); } @@ -258,7 +258,7 @@ void RC_TREE_MODEL::rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities // The fastest method to update wxDataViewCtrl is to rebuild from // scratch by calling Cleared(). Linux requires to reassociate model to // display data, but Windows will create multiple associations. - // On MacOS, this crashes kicad. See https://gitlab.com/kicad/code/kicad/issues/3666 + // On MacOS, this crashes KiCad. See https://gitlab.com/kicad/code/kicad/issues/3666 // and https://gitlab.com/kicad/code/kicad/issues/3653 m_view->AssociateModel( this ); #endif @@ -321,7 +321,7 @@ wxDataViewItem RC_TREE_MODEL::GetParent( wxDataViewItem const& aItem ) const unsigned int RC_TREE_MODEL::GetChildren( wxDataViewItem const& aItem, - wxDataViewItemArray& aChildren ) const + wxDataViewItemArray& aChildren ) const { const RC_TREE_NODE* node = ToNode( aItem ); const std::vector& children = node ? node->m_Children : m_tree; @@ -333,9 +333,6 @@ unsigned int RC_TREE_MODEL::GetChildren( wxDataViewItem const& aItem, } -/** - * Called by the wxDataView to fetch an item's value. - */ void RC_TREE_MODEL::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem, unsigned int aCol ) const @@ -400,10 +397,6 @@ void RC_TREE_MODEL::GetValue( wxVariant& aVariant, } -/** - * Called by the wxDataView to fetch an item's formatting. Return true iff the - * item has non-default attributes. - */ bool RC_TREE_MODEL::GetAttr( wxDataViewItem const& aItem, unsigned int aCol, wxDataViewItemAttr& aAttr ) const diff --git a/common/reporter.cpp b/common/reporter.cpp index 224b4c5d3c..020dc24783 100644 --- a/common/reporter.cpp +++ b/common/reporter.cpp @@ -4,8 +4,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2013 Wayne Stambaugh + * Copyright (C) 2013-2021 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 @@ -42,72 +42,81 @@ REPORTER& REPORTER::Report( const char* aText, SEVERITY aSeverity ) REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) { - wxCHECK_MSG( m_textCtrl != NULL, *this, + wxCHECK_MSG( m_textCtrl != nullptr, *this, wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) ); m_textCtrl->AppendText( aText + wxS( "\n" ) ); return *this; } + bool WX_TEXT_CTRL_REPORTER::HasMessage() const { return !m_textCtrl->IsEmpty(); } + REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) { - wxCHECK_MSG( m_string != NULL, *this, + wxCHECK_MSG( m_string != nullptr, *this, wxT( "No wxString object defined in WX_STRING_REPORTER." ) ); *m_string << aText << wxS( "\n" ); return *this; } + bool WX_STRING_REPORTER::HasMessage() const { return !m_string->IsEmpty(); } + REPORTER& WX_HTML_PANEL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) { - wxCHECK_MSG( m_panel != NULL, *this, + wxCHECK_MSG( m_panel != nullptr, *this, wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) ); m_panel->Report( aText, aSeverity ); return *this; } + REPORTER& WX_HTML_PANEL_REPORTER::ReportTail( const wxString& aText, SEVERITY aSeverity ) { - wxCHECK_MSG( m_panel != NULL, *this, + wxCHECK_MSG( m_panel != nullptr, *this, wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) ); m_panel->Report( aText, aSeverity, LOC_TAIL ); return *this; } + REPORTER& WX_HTML_PANEL_REPORTER::ReportHead( const wxString& aText, SEVERITY aSeverity ) { - wxCHECK_MSG( m_panel != NULL, *this, + wxCHECK_MSG( m_panel != nullptr, *this, wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) ); m_panel->Report( aText, aSeverity, LOC_HEAD ); return *this; } + bool WX_HTML_PANEL_REPORTER::HasMessage() const { return m_panel->Count( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING ) > 0; } + REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) { return *this; } + REPORTER& NULL_REPORTER::GetInstance() { - static REPORTER* s_nullReporter = NULL; + static REPORTER* s_nullReporter = nullptr; if( !s_nullReporter ) s_nullReporter = new NULL_REPORTER(); @@ -182,6 +191,7 @@ REPORTER& STATUSBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity return *this; } + bool STATUSBAR_REPORTER::HasMessage() const { if( m_statusBar ) diff --git a/common/richio.cpp b/common/richio.cpp index 4780e2c040..2420d332ab 100644 --- a/common/richio.cpp +++ b/common/richio.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2011 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2021 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 @@ -104,7 +104,7 @@ std::string StrPrintf( const char* format, ... ) //----------------------------------------------------------- LINE_READER::LINE_READER( unsigned aMaxLineLength ) : - m_length( 0 ), m_lineNum( 0 ), m_line( NULL ), + m_length( 0 ), m_lineNum( 0 ), m_line( nullptr ), m_capacity( 0 ), m_maxLineLength( aMaxLineLength ) { if( aMaxLineLength != 0 ) @@ -159,8 +159,8 @@ void LINE_READER::expandCapacity( unsigned aNewsize ) } -FILE_LINE_READER::FILE_LINE_READER( const wxString& aFileName, - unsigned aStartingLineNumber, unsigned aMaxLineLength ): +FILE_LINE_READER::FILE_LINE_READER( const wxString& aFileName, unsigned aStartingLineNumber, + unsigned aMaxLineLength ): LINE_READER( aMaxLineLength ), m_iOwn( true ) { m_fp = wxFopen( aFileName, wxT( "rt" ) ); @@ -215,7 +215,7 @@ char* FILE_LINE_READER::ReadLine() { m_length = 0; - for(;;) + for( ;; ) { if( m_length >= m_maxLineLength ) THROW_IO_ERROR( _( "Maximum line length exceeded" ) ); @@ -241,7 +241,7 @@ char* FILE_LINE_READER::ReadLine() // leads to better error reporting when we hit an end of file. ++m_lineNum; - return m_length ? m_line : NULL; + return m_length ? m_line : nullptr; } @@ -294,11 +294,12 @@ char* STRING_LINE_READER::ReadLine() ++m_lineNum; // this gets incremented even if no bytes were read m_line[m_length] = 0; - return m_length ? m_line : NULL; + return m_length ? m_line : nullptr; } -INPUTSTREAM_LINE_READER::INPUTSTREAM_LINE_READER( wxInputStream* aStream, const wxString& aSource ) : +INPUTSTREAM_LINE_READER::INPUTSTREAM_LINE_READER( wxInputStream* aStream, + const wxString& aSource ) : LINE_READER( LINE_READER_LINE_DEFAULT_MAX ), m_stream( aStream ) { @@ -310,7 +311,7 @@ char* INPUTSTREAM_LINE_READER::ReadLine() { m_length = 0; - for(;;) + for( ;; ) { if( m_length >= m_maxLineLength ) THROW_IO_ERROR( _( "Maximum line length exceeded" ) ); @@ -336,7 +337,7 @@ char* INPUTSTREAM_LINE_READER::ReadLine() // leads to better error reporting when we hit an end of file. ++m_lineNum; - return m_length ? m_line : NULL; + return m_length ? m_line : nullptr; } @@ -361,8 +362,8 @@ const char* OUTPUTFORMATTER::GetQuoteChar( const char* wrapee, const char* quote for( ; *wrapee; ++wrapee, isFirst = false ) { static const char quoteThese[] = "\t ()" - "%" // per Alfons of freerouting.net, he does not like this unquoted as of 1-Feb-2008 - "{}" // guessing that these are problems too + "%" // per Alfons of freerouting.net, he does not like this unquoted as of 1-Feb-2008 + "{}" // guessing that these are problems too ; // if the string to be wrapped (wrapee) has a delimiter in it, @@ -383,6 +384,7 @@ const char* OUTPUTFORMATTER::GetQuoteChar( const char* wrapee ) const return GetQuoteChar( wrapee, quoteChar ); } + int OUTPUTFORMATTER::vprint( const char* fmt, va_list ap ) { // This function can call vsnprintf twice. @@ -522,7 +524,6 @@ void STRING_FORMATTER::StripUseless() } } -//--------------------------------------------- FILE_OUTPUTFORMATTER::FILE_OUTPUTFORMATTER( const wxString& aFileName, const wxChar* aMode, char aQuoteChar ): @@ -550,8 +551,6 @@ void FILE_OUTPUTFORMATTER::write( const char* aOutBuf, int aCount ) } -//------------------------------------------- - void STREAM_OUTPUTFORMATTER::write( const char* aOutBuf, int aCount ) { int lastWrite; diff --git a/common/status_popup.cpp b/common/status_popup.cpp index 57d5a78265..4951c76c67 100644 --- a/common/status_popup.cpp +++ b/common/status_popup.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2015 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * Author: Tomasz Wlostowski * * This program is free software; you can redistribute it and/or @@ -39,7 +40,7 @@ STATUS_POPUP::STATUS_POPUP( wxWindow* aParent ) : m_panel->SetSizer( m_topSizer ); m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); - Connect( wxEVT_TIMER, wxTimerEventHandler( STATUS_POPUP::onExpire ), NULL, this ); + Connect( wxEVT_TIMER, wxTimerEventHandler( STATUS_POPUP::onExpire ), nullptr, this ); #ifdef __WXOSX_MAC__ // Key events from popups don't get put through the wxWidgets event system on OSX, diff --git a/common/streamwrapper.cpp b/common/streamwrapper.cpp index 9e0d1366e5..29cbed7201 100644 --- a/common/streamwrapper.cpp +++ b/common/streamwrapper.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Cirilo Bernardo + * Copyright (C) 2021 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 @@ -36,17 +37,17 @@ kicad::stream::stream() { - m_buf = NULL; - m_stream = NULL; + m_buf = nullptr; + m_stream = nullptr; } kicad::stream::~stream() { - if( NULL != m_stream ) + if( nullptr != m_stream ) delete m_stream; - if( NULL != m_buf ) + if( nullptr != m_buf ) { m_buf->close(); // ensure file is closed regardless of m_buf's destructor delete m_buf; @@ -56,13 +57,13 @@ kicad::stream::~stream() std::iostream* kicad::stream::Open( const char* aFileName, std::ios_base::openmode aMode ) { - if( NULL != m_stream ) + if( nullptr != m_stream ) { delete m_stream; - m_stream = NULL; + m_stream = nullptr; } - if( NULL != m_buf ) + if( nullptr != m_buf ) { m_buf->close(); delete m_buf; diff --git a/common/string.cpp b/common/string.cpp index 3262aa9042..8d87844476 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -493,8 +493,8 @@ char* StrPurge( char* text ) char* GetLine( FILE* File, char* Line, int* LineNum, int SizeLine ) { do { - if( fgets( Line, SizeLine, File ) == NULL ) - return NULL; + if( fgets( Line, SizeLine, File ) == nullptr ) + return nullptr; if( LineNum ) *LineNum += 1; @@ -597,7 +597,7 @@ int StrNumCmp( const wxString& aString1, const wxString& aString2, bool aIgnoreC bool WildCompareString( const wxString& pattern, const wxString& string_to_tst, bool case_sensitive ) { - const wxChar* cp = NULL, * mp = NULL; + const wxChar* cp = nullptr, * mp = nullptr; const wxChar* wild, * str; wxString _pattern, _string_to_tst; @@ -721,9 +721,13 @@ int ValueStringCompare( wxString strFWord, wxString strSWord ) int isEqual = strFWordBeg.CmpNoCase( strSWordBeg ); if( isEqual > 0 ) + { return 1; + } else if( isEqual < 0 ) + { return -1; + } else { // If the first sections are equal compare their digits diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index 4e2915e9fb..dcc4237977 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013 CERN - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -67,9 +67,11 @@ void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction ) } -void ACTION_MANAGER::SetConditions( const TOOL_ACTION& aAction, const ACTION_CONDITIONS& aConditions ) +void ACTION_MANAGER::SetConditions( const TOOL_ACTION& aAction, + const ACTION_CONDITIONS& aConditions ) { - // Remove any existing handlers with the old conditions to ensure the UI layer doesn't have stale data + // Remove any existing handlers with the old conditions to ensure the UI layer doesn't have + // stale data. if( m_toolMgr ) m_toolMgr->GetToolHolder()->UnregisterUIUpdateHandler( aAction ); @@ -112,7 +114,7 @@ TOOL_ACTION* ACTION_MANAGER::FindAction( const std::string& aActionName ) const if( it != m_actionNameIndex.end() ) return it->second; - return NULL; + return nullptr; } @@ -150,7 +152,7 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const // Choose the action that has the highest priority on the active tools stack // If there is none, run the global action associated with the hot key int highestPriority = -1, priority = -1; - const TOOL_ACTION* context = NULL; // pointer to context action of the highest priority tool + const TOOL_ACTION* context = nullptr; // pointer to context action of the highest priority tool std::vector global; // pointers to global actions // if there is no context action diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index 33e8c07b03..b6493d4240 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2019 CERN - * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors. * @author Tomasz Wlostowski * @author Maciej Suminski * @@ -59,7 +59,7 @@ ACTION_MENU::ACTION_MENU( bool isContextMenu, TOOL_INTERACTIVE* aTool ) : ACTION_MENU::~ACTION_MENU() { - // Set parent to NULL to prevent submenus from unregistering from a notexisting object + // Set parent to NULL to prevent submenus from unregistering from a nonexistent object for( auto menu : m_submenus ) menu->SetParent( nullptr ); @@ -78,13 +78,9 @@ void ACTION_MENU::SetIcon( BITMAPS aIcon ) void ACTION_MENU::setupEvents() { -// See wxWidgets hack in TOOL_DISPATCHER::DispatchWxEvent(). -// Connect( wxEVT_MENU_OPEN, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this ); -// Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this ); -// Connect( wxEVT_MENU_CLOSE, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this ); - - Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this ); - Connect( wxEVT_IDLE, wxIdleEventHandler( ACTION_MENU::OnIdle ), NULL, this ); + Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), nullptr, + this ); + Connect( wxEVT_IDLE, wxIdleEventHandler( ACTION_MENU::OnIdle ), nullptr, this ); } @@ -325,7 +321,8 @@ ACTION_MENU* ACTION_MENU::create() const ACTION_MENU* menu = new ACTION_MENU( false ); wxASSERT_MSG( typeid( *this ) == typeid( *menu ), - wxString::Format( "You need to override create() method for class %s", typeid(*this).name() ) ); + wxString::Format( "You need to override create() method for class %s", + typeid( *this ).name() ) ); return menu; } @@ -381,6 +378,7 @@ void ACTION_MENU::updateHotKeys() static int g_last_menu_highlighted_id = 0; + // We need to store the position of the mouse when the menu was opened so it can be passed // to the command event generated when the menu item is selected. static VECTOR2D g_menu_open_position; @@ -488,17 +486,17 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent ) wxMenu* menu = nullptr; FindItem( m_selected, &menu ); - // This conditional compilation is probably not needed. - // It will be removed later, for the Kicad V 6.x version. - // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid hang - // This hang is no longer encountered in wxWidgets 3.0.4 version, and this condition is no longer needed. - // And in 3.1.2, we have to remove it, as "menu != this" never happens - // ("menu != this" always happens in 3.1.1 and older!). - #if wxCHECK_VERSION(3, 1, 2) + // This conditional compilation is probably not needed. + // It will be removed later, for the Kicad V 6.x version. + // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid + // hang. This hang is no longer encountered in wxWidgets 3.0.4 version, and this + // condition is no longer needed. And in 3.1.2, we have to remove it, as + // "menu != this" never happens ("menu != this" always happens in 3.1.1 and older!). +#if wxCHECK_VERSION( 3, 1, 2 ) if( menu ) - #else +#else if( menu && menu != this ) - #endif +#endif { ACTION_MENU* cxmenu = static_cast( menu ); evt = cxmenu->eventHandler( aEvent ); @@ -645,11 +643,12 @@ wxMenuItem* ACTION_MENU::appendCopy( const wxMenuItem* aSource ) // On Windows, for Checkable Menu items, adding a bitmap adds also // our predefined checked alternate bitmap // On other OS, wxITEM_CHECK and wxITEM_RADIO Menu items do not use custom bitmaps. -#if defined(_WIN32) - // On Windows, AddBitmapToMenuItem() uses the unchecked bitmap for wxITEM_CHECK and wxITEM_RADIO menuitems - // and autoamtically adds a checked bitmap. +#if defined( _WIN32 ) + // On Windows, AddBitmapToMenuItem() uses the unchecked bitmap for wxITEM_CHECK and + // wxITEM_RADIO menuitems and autoamtically adds a checked bitmap. // For other menuitrms, use the "checked" bitmap. - bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK || aSource->GetKind() == wxITEM_RADIO ) ? false : true; + bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK || + aSource->GetKind() == wxITEM_RADIO ) ? false : true; const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm ); #else const wxBitmap& src_bitmap = aSource->GetBitmap(); diff --git a/common/tool/common_control.cpp b/common/tool/common_control.cpp index d7bfdef280..84b48120d4 100644 --- a/common/tool/common_control.cpp +++ b/common/tool/common_control.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2016 CERN - * @author Maciej Suminski * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * @author Maciej Suminski * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -50,6 +50,7 @@ wxString COMMON_CONTROL::m_bugReportUrl = "https://gitlab.com/kicad/code/kicad/issues/new?issue[description]=%s"; + /// Issue template to use for reporting bugs (this should not be translated) wxString COMMON_CONTROL::m_bugReportTemplate = "