diff --git a/bitmap2component/bitmap2cmp_gui.cpp b/bitmap2component/bitmap2cmp_gui.cpp index 2e5bed6253..9e3a7a7bea 100644 --- a/bitmap2component/bitmap2cmp_gui.cpp +++ b/bitmap2component/bitmap2cmp_gui.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 1992-2010 jean-pierre.charras - * Copyright (C) 1992-2021 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 @@ -439,7 +439,7 @@ bool BM2CMP_FRAME::OpenProjectFiles( const std::vector& aFileSet, int m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image ); m_NB_Image = m_Greyscale_Image; - Binarize( (double) m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() ); + Binarize( (double) m_sliderThreshold->GetValue() / m_sliderThreshold->GetMax() ); m_buttonExportFile->Enable( true ); m_buttonExportClipboard->Enable( true ); @@ -526,7 +526,7 @@ void BM2CMP_FRAME::OnSizeChangeX( wxCommandEvent& event ) if( getUnitFromSelection() == EDA_UNITS::UNSCALED ) { // for units in DPI, keeping aspect ratio cannot use m_AspectRatioLocked. - // just rescale the other dpi + // just re-scale the other dpi double ratio = new_size / m_outputSizeX.GetOutputSize(); calculatedY = m_outputSizeY.GetOutputSize() * ratio; } @@ -555,7 +555,7 @@ void BM2CMP_FRAME::OnSizeChangeY( wxCommandEvent& event ) if( getUnitFromSelection() == EDA_UNITS::UNSCALED ) { // for units in DPI, keeping aspect ratio cannot use m_AspectRatioLocked. - // just rescale the other dpi + // just re-scale the other dpi double ratio = new_size / m_outputSizeX.GetOutputSize(); calculatedX = m_outputSizeX.GetOutputSize() * ratio; } @@ -671,6 +671,7 @@ void BM2CMP_FRAME::OnThresholdChange( wxScrollEvent& event ) void BM2CMP_FRAME::OnExportToFile( wxCommandEvent& event ) { m_exportToClipboard = false; + // choices of m_rbOutputFormat are expected to be in same order as // OUTPUT_FMT_ID. See bitmap2component.h OUTPUT_FMT_ID format = (OUTPUT_FMT_ID) m_rbOutputFormat->GetSelection(); @@ -681,6 +682,7 @@ void BM2CMP_FRAME::OnExportToFile( wxCommandEvent& event ) void BM2CMP_FRAME::OnExportToClipboard( wxCommandEvent& event ) { m_exportToClipboard = true; + // choices of m_rbOutputFormat are expected to be in same order as // OUTPUT_FMT_ID. See bitmap2component.h OUTPUT_FMT_ID format = (OUTPUT_FMT_ID) m_rbOutputFormat->GetSelection(); @@ -691,7 +693,7 @@ void BM2CMP_FRAME::OnExportToClipboard( wxCommandEvent& event ) wxLogNull doNotLog; // disable logging of failed clipboard actions // Write buffer to the clipboard - if (wxTheClipboard->Open()) + if( wxTheClipboard->Open() ) { // This data objects are held by the clipboard, // so do not delete them in the app. @@ -700,7 +702,9 @@ void BM2CMP_FRAME::OnExportToClipboard( wxCommandEvent& event ) wxTheClipboard->Close(); } else + { wxMessageBox( _( "Unable to export to the Clipboard") ); + } } @@ -749,7 +753,7 @@ void BM2CMP_FRAME::OnExportLogo() FILE* outfile; outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) ); - if( outfile == NULL ) + if( outfile == nullptr ) { wxString msg; msg.Printf( _( "File '%s' could not be created." ), m_ConvertedFileName ); @@ -789,7 +793,7 @@ void BM2CMP_FRAME::exportPostScriptFormat() FILE* outfile; outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) ); - if( outfile == NULL ) + if( outfile == nullptr ) { wxString msg; msg.Printf( _( "File '%s' could not be created." ), m_ConvertedFileName ); @@ -828,7 +832,7 @@ void BM2CMP_FRAME::exportEeschemaFormat() FILE* outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) ); - if( outfile == NULL ) + if( outfile == nullptr ) { wxString msg; msg.Printf( _( "File '%s' could not be created." ), m_ConvertedFileName ); @@ -867,7 +871,7 @@ void BM2CMP_FRAME::exportPcbnewFormat() FILE* outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) ); - if( outfile == NULL ) + if( outfile == nullptr ) { wxString msg; msg.Printf( _( "File '%s' could not be created." ), m_ConvertedFileName ); @@ -917,7 +921,7 @@ void BM2CMP_FRAME::ExportToBuffer( std::string& aOutput, OUTPUT_FMT_ID aFormat ) BITMAPCONV_INFO converter( aOutput ); converter.ConvertBitmap( potrace_bitmap, aFormat, m_outputSizeX.GetOutputDPI(), - m_outputSizeY.GetOutputDPI(), modLayer ); + m_outputSizeY.GetOutputDPI(), modLayer ); if( !converter.GetErrorMessages().empty() ) wxMessageBox( converter.GetErrorMessages().c_str(), _( "Errors" ) ); diff --git a/bitmap2component/bitmap2cmp_main.cpp b/bitmap2component/bitmap2cmp_main.cpp index 2ff7f23dab..49f2b97a24 100644 --- a/bitmap2component/bitmap2cmp_main.cpp +++ b/bitmap2component/bitmap2cmp_main.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 1992-2010 jean-pierre.charras - * Copyright (C) 1992-2019 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 @@ -30,15 +30,14 @@ #include -//---------------------------------------------------------------------- - namespace BMP2CMP { static struct IFACE : public KIFACE_I { bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override; - wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override + wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, + int aCtlBits = 0 ) override { InitSettings( new BITMAP2CMP_SETTINGS ); Pgm().GetSettingsManager().RegisterSettings( KifaceSettings() ); @@ -46,19 +45,18 @@ static struct IFACE : public KIFACE_I } /** - * Function IfaceOrAddress - * return a pointer to the requested object. The safest way to use this - * is to retrieve a pointer to a static instance of an interface, similar to - * how the KIFACE interface is exported. But if you know what you are doing - * use it to retrieve anything you want. + * Return a pointer to the requested object. + * + * The safest way to use this is to retrieve a pointer to a static instance of an interface, + * similar to how the KIFACE interface is exported. But if you know what you are doing use + * it to retrieve anything you want. * * @param aDataId identifies which object you want the address of. - * - * @return void* - and must be cast into the know type. + * @return the object which must be cast into the known type. */ void* IfaceOrAddress( int aDataId ) override { - return NULL; + return nullptr; } IFACE( const char* aDSOname, KIWAY::FACE_T aType ) : @@ -73,6 +71,7 @@ using namespace BMP2CMP; static PGM_BASE* process; + KIFACE_I& Kiface() { return kiface; diff --git a/bitmap2component/bitmap2component.cpp b/bitmap2component/bitmap2component.cpp index 1c995dafa7..3d8d52d071 100644 --- a/bitmap2component/bitmap2component.cpp +++ b/bitmap2component/bitmap2component.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 1992-2019 jean-pierre.charras - * Copyright (C) 1992-2019 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,10 +43,11 @@ /* free a potrace bitmap */ static void bm_free( potrace_bitmap_t* bm ) { - if( bm != NULL ) + if( bm != nullptr ) { free( bm->map ); } + free( bm ); } @@ -66,14 +67,13 @@ BITMAPCONV_INFO::BITMAPCONV_INFO( std::string& aData ): m_PixmapHeight = 0; m_ScaleX = 1.0; m_ScaleY = 1.0; - m_Paths = NULL; + m_Paths = nullptr; m_CmpName = "LOGO"; } -int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, - OUTPUT_FMT_ID aFormat, int aDpi_X, int aDpi_Y, - BMP2CMP_MOD_LAYER aModLayer ) +int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, OUTPUT_FMT_ID aFormat, + int aDpi_X, int aDpi_Y, BMP2CMP_MOD_LAYER aModLayer ) { potrace_param_t* param; potrace_state_t* st; @@ -103,6 +103,7 @@ int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, { potrace_state_free( st ); } + potrace_param_free( param ); char msg[256]; @@ -128,6 +129,7 @@ int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, m_Format = POSTSCRIPT_FMT; m_ScaleX = 1.0; // the conversion scale m_ScaleY = m_ScaleX; + // output vector data, e.g. as a rudimentary EPS file (mainly for tests) createOutputData(); break; @@ -161,7 +163,7 @@ int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, const char* BITMAPCONV_INFO::getBoardLayerName( BMP2CMP_MOD_LAYER aChoice ) { - const char * layerName = "F.SilkS"; + const char* layerName = "F.SilkS"; switch( aChoice ) { @@ -210,10 +212,10 @@ void BITMAPCONV_INFO::outputDataHeader( const char * aBrdLayerName ) sprintf( strbuf, "(attr board_only exclude_from_pos_files exclude_from_bom)\n"); m_Data += strbuf; sprintf( strbuf, " (fp_text reference \"G***\" (at 0 0) (layer %s)\n" - " (effects (font (thickness 0.3)))\n )\n", aBrdLayerName ); + " (effects (font (thickness 0.3)))\n )\n", aBrdLayerName ); m_Data += strbuf; sprintf( strbuf, " (fp_text value \"%s\" (at 0.75 0) (layer %s) hide\n" - " (effects (font (thickness 0.3)))\n )\n", m_CmpName.c_str(), aBrdLayerName ); + " (effects (font (thickness 0.3)))\n )\n", m_CmpName.c_str(), aBrdLayerName ); m_Data += strbuf; break; @@ -226,8 +228,7 @@ void BITMAPCONV_INFO::outputDataHeader( const char * aBrdLayerName ) m_Data += strbuf; sprintf( strbuf, "#\n# %s\n", m_CmpName.c_str() ); m_Data += strbuf; - sprintf( strbuf, "# pixmap size w = %d, h = %d\n#\n", - m_PixmapWidth, m_PixmapHeight ); + sprintf( strbuf, "# pixmap size w = %d, h = %d\n#\n", m_PixmapWidth, m_PixmapHeight ); m_Data += strbuf; // print reference and value @@ -270,7 +271,7 @@ void BITMAPCONV_INFO::outputDataEnd() } -void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* aBrdLayerName ) +void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const char* aBrdLayerName ) { // write one polygon to output file. // coordinates are expected in target unit. @@ -287,15 +288,14 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* { case POSTSCRIPT_FMT: offsetY = (int)( m_PixmapHeight * m_ScaleY ); - sprintf( strbuf, "newpath\n%d %d moveto\n", - startpoint.x, offsetY - startpoint.y ); + sprintf( strbuf, "newpath\n%d %d moveto\n", startpoint.x, offsetY - startpoint.y ); m_Data += strbuf; jj = 0; + for( ii = 1; ii < aPolygon.PointCount(); ii++ ) { currpoint = aPolygon.CPoint( ii ); - sprintf( strbuf, " %d %d lineto", - currpoint.x, offsetY - currpoint.y ); + sprintf( strbuf, " %d %d lineto", currpoint.x, offsetY - currpoint.y ); m_Data += strbuf; if( jj++ > 6 ) @@ -314,12 +314,13 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* m_Data += " (fp_poly (pts"; jj = 0; + for( ii = 0; ii < aPolygon.PointCount(); ii++ ) { currpoint = aPolygon.CPoint( ii ); sprintf( strbuf, " (xy %f %f)", - ( currpoint.x - offsetX ) / PCB_IU_PER_MM, - ( currpoint.y - offsetY ) / PCB_IU_PER_MM ); + ( currpoint.x - offsetX ) / PCB_IU_PER_MM, + ( currpoint.y - offsetY ) / PCB_IU_PER_MM ); m_Data += strbuf; if( jj++ > 6 ) @@ -329,6 +330,7 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* } } // No need to close polygon + m_Data += " )"; sprintf( strbuf, "(layer %s) (width %f)\n )\n", aBrdLayerName, width ); m_Data += strbuf; @@ -337,14 +339,16 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* case KICAD_LOGO: m_Data += " (pts"; + // Internal units = micron, file unit = mm jj = 0; + for( ii = 0; ii < aPolygon.PointCount(); ii++ ) { currpoint = aPolygon.CPoint( ii ); sprintf( strbuf, " (xy %.3f %.3f)", - ( currpoint.x - offsetX ) / PL_IU_PER_MM, - ( currpoint.y - offsetY ) / PL_IU_PER_MM ); + ( currpoint.x - offsetX ) / PL_IU_PER_MM, + ( currpoint.y - offsetY ) / PL_IU_PER_MM ); m_Data += strbuf; if( jj++ > 4 ) @@ -353,6 +357,7 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* m_Data += "\n "; } } + // Close polygon sprintf( strbuf, " (xy %.3f %.3f) )\n", ( startpoint.x - offsetX ) / PL_IU_PER_MM, @@ -364,20 +369,18 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* // The polygon outline thickness is fixed here to 1 mil, the minimal // value in Eeschema (0 means use default thickness for graphics) #define EE_LINE_THICKNESS 1 - sprintf( strbuf, "P %d 0 0 %d", - (int) aPolygon.PointCount() + 1, EE_LINE_THICKNESS ); + sprintf( strbuf, "P %d 0 0 %d", (int) aPolygon.PointCount() + 1, EE_LINE_THICKNESS ); m_Data += strbuf; + for( ii = 0; ii < aPolygon.PointCount(); ii++ ) { currpoint = aPolygon.CPoint( ii ); - sprintf( strbuf, " %d %d", - currpoint.x - offsetX, currpoint.y - offsetY ); + sprintf( strbuf, " %d %d", currpoint.x - offsetX, currpoint.y - offsetY ); m_Data += strbuf; } // Close polygon - sprintf( strbuf, " %d %d", - startpoint.x - offsetX, startpoint.y - offsetY ); + sprintf( strbuf, " %d %d", startpoint.x - offsetX, startpoint.y - offsetY ); m_Data += strbuf; m_Data += " F\n"; @@ -417,12 +420,13 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer ) m_errors += "No path in black and white image: no outline created\n"; } - while( paths != NULL ) + while( paths != nullptr ) { int cnt = paths->curve.n; int* tag = paths->curve.tag; c = paths->curve.c; potrace_dpoint_t startpoint = c[cnt - 1][2]; + for( int i = 0; i < cnt; i++ ) { switch( tag[i] ) @@ -457,6 +461,7 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer ) { // Add current hole in polyset_holes polyset_holes.NewOutline(); + for( unsigned int i = 0; i < cornersBuffer.size(); i++ ) { polyset_holes.Append( int( cornersBuffer[i].x * m_ScaleX ), @@ -466,9 +471,8 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer ) cornersBuffer.clear(); - /* at the end of a group of a positive path and its negative children, fill. - */ - if( paths->next == NULL || paths->next->sign == '+' ) + // at the end of a group of a positive path and its negative children, fill. + if( paths->next == nullptr || paths->next->sign == '+' ) { polyset_areas.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); polyset_holes.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); @@ -491,6 +495,7 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer ) polyset_holes.RemoveAllContours(); main_outline = true; } + paths = paths->next; } @@ -500,15 +505,17 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer ) // a helper function to calculate a square value inline double square( double x ) { - return x*x; + return x * x; } + // a helper function to calculate a cube value inline double cube( double x ) { - return x*x*x; + return x * x * x; } + /* render a Bezier curve. */ void BezierToPolyline( std::vector & aCornersBuffer, potrace_dpoint_t p1, diff --git a/cvpcb/auto_associate.cpp b/cvpcb/auto_associate.cpp index 3893332268..39de3f98cd 100644 --- a/cvpcb/auto_associate.cpp +++ b/cvpcb/auto_associate.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * 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 @@ -45,10 +45,10 @@ #define QUOTE '\'' -/* - * read the string between quotes and put it in aTarget - * put text in aTarget - * return a pointer to the last read char (the second quote if OK) +/** + * Read the string between quotes. + * + * @return a the quoted string. */ wxString GetQuotedText( wxString& text ) { @@ -76,7 +76,6 @@ bool sortListbyCmpValue( const FOOTPRINT_EQUIVALENCE& ref, const FOOTPRINT_EQUIV } -// read the .equ files and populate the list of equivalents int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wxString* aErrorMessages ) { @@ -118,7 +117,7 @@ int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, file = wxFopen( tmp, wxT( "rt" ) ); - if( file == NULL ) + if( file == nullptr ) { error_count++; @@ -135,7 +134,7 @@ int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, continue; } - while( GetLine( file, line, NULL, sizeof( line ) ) != NULL ) + while( GetLine( file, line, nullptr, sizeof( line ) ) != nullptr ) { if( *line == 0 ) continue; diff --git a/cvpcb/cvpcb.cpp b/cvpcb/cvpcb.cpp index 840b583d8c..45a0ae8f90 100644 --- a/cvpcb/cvpcb.cpp +++ b/cvpcb/cvpcb.cpp @@ -49,26 +49,26 @@ static struct IFACE : public KIFACE_I void OnKifaceEnd() override; - wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override + wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, + int aCtlBits = 0 ) override { switch( aClassId ) { case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent ); case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent ); - default: return NULL; + default: return nullptr; } } /** - * Function IfaceOrAddress - * return a pointer to the requested object. The safest way to use this - * is to retrieve a pointer to a static instance of an interface, similar to - * how the KIFACE interface is exported. But if you know what you are doing - * use it to retrieve anything you want. + * Return a pointer to the requested object. + * + * The safest way to use this is to retrieve a pointer to a static instance of an interface, + * similar to how the KIFACE interface is exported. But if you know what you are doing use + * it to retrieve anything you want. * * @param aDataId identifies which object you want the address of. - * - * @return void* - and must be cast into the know type. + * @return the object requested and must be cast into the known type. */ void* IfaceOrAddress( int aDataId ) override { @@ -133,18 +133,18 @@ PGM_BASE* PgmOrNull() /// the fallback table for multiple projects). FP_LIB_TABLE GFootprintTable; + /// The global footprint info table. This is performance-intensive to build so we /// keep a hash-stamped global version. Any deviation from the request vs. stored /// hash will result in it being rebuilt. FOOTPRINT_LIST_IMPL GFootprintList; -//!!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it. +//!!!!!!!!!!!!!!! This code is obsolete because of the merge into Pcbnew, don't bother with it. -// A short lived implementation. cvpcb will get combine into pcbnew shortly, so +// A short lived implementation. cvpcb will get combine into Pcbnew shortly, so // we skip setting KICAD6_FOOTPRINT_DIR here for now. User should set the environment // variable. - bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) { // This is process level, not project level, initialization of the DSO. @@ -171,15 +171,15 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) if( !FP_LIB_TABLE::LoadGlobalTable( GFootprintTable ) ) { - DisplayInfoMessage( NULL, _( "You have run CvPcb for the first time using the " - "new footprint library table method for finding " - "footprints.\nCvPcb has either copied the default " - "table or created an empty table in your home " - "folder.\nYou must first configure the library " - "table to include all footprint libraries not " - "included with KiCad.\nSee the \"Footprint Library " - "Table\" section of the CvPcb documentation for " - "more information." ) ); + DisplayInfoMessage( nullptr, _( "You have run CvPcb for the first time using the " + "new footprint library table method for finding " + "footprints.\nCvPcb has either copied the default " + "table or created an empty table in your home " + "folder.\nYou must first configure the library " + "table to include all footprint libraries not " + "included with KiCad.\nSee the \"Footprint Library " + "Table\" section of the CvPcb documentation for " + "more information." ) ); } } catch( const IO_ERROR& ioe ) @@ -193,6 +193,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) return true; } + void IFACE::OnKifaceEnd() { end_common(); diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index bfb9e9dc07..e1f1961443 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -64,14 +64,14 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, _( "Assign Footprints" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, CVPCB_MAINFRAME_NAME ) { - m_symbolsListBox = NULL; - m_footprintListBox = NULL; - m_librariesListBox = NULL; - m_mainToolBar = NULL; + m_symbolsListBox = nullptr; + m_footprintListBox = nullptr; + m_librariesListBox = nullptr; + m_mainToolBar = nullptr; m_modified = false; m_skipComponentSelect = false; m_filteringOptions = FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST; - m_tcFilterString = NULL; + m_tcFilterString = nullptr; m_FootprintsList = FOOTPRINT_LIST::GetInstance( Kiway() ); m_initialized = false; m_aboutTitle = "CvPcb"; @@ -512,7 +512,7 @@ void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation, COMPONENT* symbol = m_netlist.GetComponent( aAssociation.GetComponentIndex() ); - if( symbol == NULL ) + if( symbol == nullptr ) return; LIB_ID fpid = aAssociation.GetNewFootprint(); @@ -594,7 +594,7 @@ void CVPCB_MAINFRAME::refreshAfterSymbolSearch( COMPONENT* aSymbol ) if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized m_auimgr.Update(); // (could be not the case when starting CvPcb) - if( aSymbol == NULL ) + if( aSymbol == nullptr ) { DisplayStatus(); return; @@ -825,7 +825,7 @@ void CVPCB_MAINFRAME::SendMessageToEESCHEMA( bool aClearHighligntOnly ) if ( selection < 0 ) // Nothing selected return; - if( m_netlist.GetComponent( selection ) == NULL ) + if( m_netlist.GetComponent( selection ) == nullptr ) return; // Now highlight the selected symbol: @@ -878,13 +878,13 @@ void CVPCB_MAINFRAME::BuildFootprintsListBox() { wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); - if( m_footprintListBox == NULL ) + if( m_footprintListBox == nullptr ) { m_footprintListBox = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST ); m_footprintListBox->SetFont( KIUI::GetMonospacedUIFont() ); } - m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL, wxEmptyString, + m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, nullptr, wxEmptyString, FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST ); DisplayStatus(); } @@ -896,7 +896,7 @@ void CVPCB_MAINFRAME::BuildSymbolsListBox() COMPONENT* symbol; wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); - if( m_symbolsListBox == NULL ) + if( m_symbolsListBox == nullptr ) { m_symbolsListBox = new COMPONENTS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST ); m_symbolsListBox->SetFont( KIUI::GetMonospacedUIFont() ); @@ -930,7 +930,7 @@ void CVPCB_MAINFRAME::BuildLibrariesListBox() { wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); - if( m_librariesListBox == NULL ) + if( m_librariesListBox == nullptr ) { m_librariesListBox = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST ); m_librariesListBox->SetFont( KIUI::GetMonospacedUIFont() ); @@ -959,7 +959,7 @@ COMPONENT* CVPCB_MAINFRAME::GetSelectedComponent() if( selection >= 0 && selection < (int) m_netlist.GetCount() ) return m_netlist.GetComponent( selection ); - return NULL; + return nullptr; } diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index a7765b9758..36a5365c87 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 2007-2020 KiCad Developers, see AUTHORS.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 @@ -50,8 +50,8 @@ #include #include #include -#include // Shared conditions with other pcbnew frames -#include // shared tools with other pcbnew frames +#include // Shared conditions with other Pcbnew frames +#include // shared tools with other Pcbnew frames #include #include #include @@ -182,7 +182,7 @@ DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME() GetCanvas()->SetEvtHandlerEnabled( false ); delete GetScreen(); - SetScreen( NULL ); // Be sure there is no double deletion + SetScreen( nullptr ); // Be sure there is no double deletion } @@ -197,9 +197,12 @@ void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions() #define CHECK( x ) ACTION_CONDITIONS().Check( x ) - mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); - mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); - mgr->SetConditions( ACTIONS::measureTool, CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) ); + mgr->SetConditions( ACTIONS::zoomTool, + CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); + mgr->SetConditions( ACTIONS::selectionTool, + CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); + mgr->SetConditions( ACTIONS::measureTool, + CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) ); mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) ); mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) ); @@ -216,10 +219,12 @@ void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions() }; mgr->SetConditions( PCB_ACTIONS::zoomFootprintAutomatically, CHECK( autoZoomCond ) ); - mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( cond.PadNumbersDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::showPadNumbers, + CHECK( cond.PadNumbersDisplay() ) ); mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) ); mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) ); - mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) ); + mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, + CHECK( !cond.GraphicsFillDisplay() ) ); #undef CHECK } @@ -296,7 +301,8 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar() m_mainToolBar->Add( ACTIONS::zoomInCenter ); m_mainToolBar->Add( ACTIONS::zoomOutCenter ); m_mainToolBar->Add( ACTIONS::zoomFitScreen ); - m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL ); + m_mainToolBar->Add( ACTIONS::zoomTool, + ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL ); m_mainToolBar->Add( PCB_ACTIONS::zoomFootprintAutomatically, ACTION_TOOLBAR::TOGGLE ); m_mainToolBar->AddScaledSeparator( this ); @@ -323,8 +329,7 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar() m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT ); m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT ); - // after adding the buttons to the toolbar, must call Realize() to reflect - // the changes + // after adding the buttons to the toolbar, must call Realize() to reflect the changes m_mainToolBar->Realize(); } @@ -392,7 +397,7 @@ COLOR4D DISPLAY_FOOTPRINTS_FRAME::GetGridColor() FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintName, REPORTER& aReporter ) { - FOOTPRINT* footprint = NULL; + FOOTPRINT* footprint = nullptr; LIB_ID fpid; if( fpid.Parse( aFootprintName ) >= 0 ) @@ -400,7 +405,7 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam aReporter.Report( wxString::Format( _( "Footprint ID '%s' is not valid." ), aFootprintName ), RPT_SEVERITY_ERROR ); - return NULL; + return nullptr; } wxString libNickname = FROM_UTF8( fpid.GetLibNickname().c_str() ); @@ -415,7 +420,7 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam aReporter.Report( wxString::Format( _( "Library '%s' is not in the footprint library table." ), libNickname ), RPT_SEVERITY_ERROR ); - return NULL; + return nullptr; } // See if the footprint requested is in the library @@ -423,7 +428,7 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam { aReporter.Report( wxString::Format( _( "Footprint '%s' not found." ), aFootprintName ), RPT_SEVERITY_ERROR ); - return NULL; + return nullptr; } try @@ -436,7 +441,7 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam catch( const IO_ERROR& ioe ) { DisplayError( this, ioe.What() ); - return NULL; + return nullptr; } if( footprint ) @@ -448,7 +453,7 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam aReporter.Report( wxString::Format( _( "Footprint '%s' not found." ), aFootprintName ), RPT_SEVERITY_ERROR ); - return NULL; + return nullptr; } diff --git a/cvpcb/listbox_base.cpp b/cvpcb/listbox_base.cpp index cf28338471..f03dd35e78 100644 --- a/cvpcb/listbox_base.cpp +++ b/cvpcb/listbox_base.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2012 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 @@ -31,14 +31,9 @@ #include -/****************************************************************************** -* Basic class (from wxListView) to display symbol and footprint lists -* Not directly used: the 2 list boxes actually used are derived from it -******************************************************************************/ - ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId, const wxPoint& aLocation, const wxSize& aSize, - long aStyle) : + long aStyle ) : wxListView( aParent, aId, aLocation, aSize, LISTBOX_STYLE | aStyle ), columnWidth( 0 ) { @@ -72,11 +67,6 @@ void ITEMS_LISTBOX_BASE::UpdateWidth( int aLine ) } -/* - * Calculate the width of the given line, and increase the column width - * if needed. This is effectively the wxListCtrl code for autosizing. - * NB. it relies on the caller checking the given line number is valid. - */ void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine ) { wxClientDC dc( this ); @@ -84,7 +74,7 @@ void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine ) int newWidth = 10; // Value of AUTOSIZE_COL_MARGIN from wxWidgets source. dc.SetFont( GetFont() ); - dc.GetTextExtent( GetItemText( aLine, 0 ) + " ", &w, NULL ); + dc.GetTextExtent( GetItemText( aLine, 0 ) + " ", &w, nullptr ); newWidth += w; if( newWidth > columnWidth ) @@ -95,16 +85,12 @@ void ITEMS_LISTBOX_BASE::UpdateLineWidth( unsigned aLine ) } -/* - * Return an index for the selected item - */ int ITEMS_LISTBOX_BASE::GetSelection() { return GetFirstSelected(); } -/* Removes all selection in list -*/ + void ITEMS_LISTBOX_BASE::DeselectAll() { for( int i = 0; i < GetItemCount(); i++ ) diff --git a/cvpcb/listboxes.h b/cvpcb/listboxes.h index 02f2871c15..0ba87a8b44 100644 --- a/cvpcb/listboxes.h +++ b/cvpcb/listboxes.h @@ -35,6 +35,9 @@ class FOOTPRINT_LIST; #define LISTBOX_STYLE ( wxBORDER_NONE | wxLC_NO_HEADER | wxLC_REPORT | wxLC_VIRTUAL | \ wxVSCROLL | wxHSCROLL ) +/** + * Base class to display symbol and footprint lists. + */ class ITEMS_LISTBOX_BASE : public wxListView { public: @@ -48,10 +51,10 @@ public: * @return the index of the selected item in lists allowing only one item selected * and the index of the first selected item in lists allowing many selection */ - int GetSelection(); + int GetSelection(); /** - * Removes all selection in lists which can have more than one item selected + * Remove all selection in lists which can have more than one item selected. */ void DeselectAll(); @@ -67,6 +70,11 @@ public: void UpdateWidth( int aLine = -1 ); private: + /** + * Calculate the width of the given line, and increase the column width + * if needed. This is effectively the wxListCtrl code for autosizing. + * NB. it relies on the caller checking the given line number is valid. + */ void UpdateLineWidth( unsigned aLine ); int columnWidth; @@ -154,7 +162,7 @@ public: /** * Called on a key press. * - * Call default handler for some special keys, and for "ascii" keys, select the first + * Call default handler for some special keys, and for "ASCII" keys, select the first * footprint that the name starts by the letter. * * This is the default behavior of a listbox, but because we use virtual lists, the @@ -199,7 +207,7 @@ public: /** * Called on a key press. * - * Call default handler for some special keys, and for "ascii" keys, select the first + * Call default handler for some special keys, and for "ASCII" keys, select the first * component that the name starts by the letter. * * This is the default behavior of a listbox, but because we use virtual lists, the diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp index 8de2efbecf..7e85023d76 100644 --- a/cvpcb/readwrite_dlgs.cpp +++ b/cvpcb/readwrite_dlgs.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 Jean-Pierre Charras, jean-pierre.charras - * Copyright (C) 2011-2016 Wayne Stambaugh - * Copyright (C) 1992-2020 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 @@ -34,9 +34,13 @@ #include -/// Return true if the resultant LIB_ID has a certain nickname. The guess -/// is only made if this footprint resides in only one library. -/// @return int - 0 on success, 1 on not found, 2 on ambiguous i.e. multiple matches +/** + * Return true if the resultant LIB_ID has a certain nickname. + * + * The guess is only made if this footprint resides in only one library. + * + * @return int - 0 on success, 1 on not found, 2 on ambiguous i.e. multiple matches. + */ static int guessNickname( FP_LIB_TABLE* aTbl, LIB_ID* aFootprintId ) { if( aFootprintId->GetLibNickname().size() ) @@ -83,7 +87,7 @@ bool CVPCB_MAINFRAME::ReadNetListAndFpFiles( const std::string& aNetlist ) ReadSchematicNetlist( aNetlist ); - if( m_symbolsListBox == NULL ) + if( m_symbolsListBox == nullptr ) return false; wxSafeYield(); @@ -182,7 +186,9 @@ bool CVPCB_MAINFRAME::ReadNetListAndFpFiles( const std::string& aNetlist ) dlg.ShowModal(); #else dlg.Fit(); - dlg.Show( true ); // modeless lets user watch while fixing the problems, but its not working. + + // Modeless lets user watch while fixing the problems, but its not working. + dlg.Show( true ); #endif } } @@ -195,7 +201,7 @@ bool CVPCB_MAINFRAME::ReadNetListAndFpFiles( const std::string& aNetlist ) if( component->GetFPID().IsLegacy() ) { - component->SetFPID( LIB_ID() /* empty */ ); + component->SetFPID( LIB_ID() ); m_modified = true; } } @@ -239,7 +245,6 @@ bool CVPCB_MAINFRAME::ReadNetListAndFpFiles( const std::string& aNetlist ) if( dlg.ShowModal() == wxID_OK ) { - // Update the fp selection: for( unsigned ii = 0; ii < m_indexes.size(); ii++ ) { diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 01ceb84a10..d218c17a74 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -333,7 +333,7 @@ bool SCH_EDIT_FRAME::BreakSegments( const wxPoint& aPoint, SCH_SCREEN* aScreen ) SCH_LINE* wire = static_cast( item ); if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), aPoint ) - && !wire->IsEndPoint( aPoint ) ) + && !wire->IsEndPoint( aPoint ) ) { wires.push_back( wire ); } @@ -341,7 +341,7 @@ bool SCH_EDIT_FRAME::BreakSegments( const wxPoint& aPoint, SCH_SCREEN* aScreen ) } for( SCH_LINE* wire : wires ) - brokenSegments |= BreakSegment( wire, aPoint, NULL, aScreen ); + brokenSegments |= BreakSegment( wire, aPoint, nullptr, aScreen ); return brokenSegments; } @@ -438,7 +438,6 @@ void SCH_EDIT_FRAME::DeleteJunction( SCH_ITEM* aJunction, bool aAppend ) SaveCopyInUndoList( undoList, UNDO_REDO::DELETED, aAppend ); - for( SCH_LINE* line : lines ) { if( line->GetEditFlags() & STRUCT_DELETED ) diff --git a/eeschema/bus_alias.h b/eeschema/bus_alias.h index b1e5340075..1104467b86 100644 --- a/eeschema/bus_alias.h +++ b/eeschema/bus_alias.h @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * @author Jon Evans * * This program is free software; you can redistribute it and/or @@ -32,7 +33,7 @@ class SCH_SCREEN; class BUS_ALIAS { public: - BUS_ALIAS( SCH_SCREEN* aParent = NULL ); + BUS_ALIAS( SCH_SCREEN* aParent = nullptr ); ~BUS_ALIAS(); diff --git a/eeschema/component_references_lister.cpp b/eeschema/component_references_lister.cpp index 2961ced5f9..c521a99ae7 100644 --- a/eeschema/component_references_lister.cpp +++ b/eeschema/component_references_lister.cpp @@ -310,6 +310,7 @@ wxString buildFullReference( const SCH_REFERENCE& aItem, int aUnitNumber = -1 ) return fullref; } + void SCH_REFERENCE_LIST::ReannotateDuplicates( const SCH_REFERENCE_LIST& aAdditionalReferences ) { SplitReferences(); @@ -348,7 +349,7 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, int // The algorithm tries to allocate the new reference to symbols having the same // old reference. // This algo works fine as long as the previous annotation has no duplicates. - // But when a hierarchy is reannotated with this option, the previous anotation can + // But when a hierarchy is reannotated with this option, the previous annotation can // have duplicate references, and obviously we must fix these duplicate. // therefore do not try to allocate a full reference more than once when trying // to keep this order of multi units. @@ -402,7 +403,8 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, int continue; // Check whether this symbol is in aLockedUnitMap. - SCH_REFERENCE_LIST* lockedList = NULL; + SCH_REFERENCE_LIST* lockedList = nullptr; + for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap ) { unsigned n_refs = pair.second.GetCount(); @@ -417,7 +419,9 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, int break; } } - if( lockedList != NULL ) break; + + if( lockedList != nullptr ) + break; } if( ( flatList[first].CompareRef( ref_unit ) != 0 ) @@ -469,7 +473,7 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, int // If this symbol is in aLockedUnitMap, copy the annotation to all // symbols that are not it - if( lockedList != NULL ) + if( lockedList != nullptr ) { unsigned n_refs = lockedList->GetCount(); @@ -583,7 +587,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( ANNOTATION_ERROR_HANDLER aHandler ) SortByRefAndValue(); - // Spiit reference designators into name (prefix) and number: IC1 becomes IC, and 1. + // Split reference designators into name (prefix) and number: IC1 becomes IC, and 1. SplitReferences(); // count not yet annotated items or annotation error. @@ -608,9 +612,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( ANNOTATION_ERROR_HANDLER aHandler ) } else { - msg.Printf( _( "Item not annotated: %s%s\n" ), - flatList[ii].GetRef(), - tmp ); + msg.Printf( _( "Item not annotated: %s%s\n" ), flatList[ii].GetRef(), tmp ); } aHandler( ERCE_UNANNOTATED, msg, &flatList[ii], nullptr ); @@ -672,9 +674,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( ANNOTATION_ERROR_HANDLER aHandler ) } else { - msg.Printf( _( "Duplicate items %s%s\n" ), - flatList[ii].GetRef(), - tmp ); + msg.Printf( _( "Duplicate items %s%s\n" ), flatList[ii].GetRef(), tmp ); } aHandler( ERCE_DUPLICATE_REFERENCE, msg, &flatList[ii], &flatList[ii+1] ); @@ -702,9 +702,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( ANNOTATION_ERROR_HANDLER aHandler ) } else { - msg.Printf( _( "Duplicate items %s%s\n" ), - flatList[ii].GetRef(), - tmp ); + msg.Printf( _( "Duplicate items %s%s\n" ), flatList[ii].GetRef(), tmp ); } aHandler( ERCE_DUPLICATE_REFERENCE, msg, &flatList[ii], &flatList[ii+1] ); @@ -738,7 +736,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( ANNOTATION_ERROR_HANDLER aHandler ) SCH_REFERENCE::SCH_REFERENCE( SCH_SYMBOL* aSymbol, LIB_SYMBOL* aLibSymbol, const SCH_SHEET_PATH& aSheetPath ) { - wxASSERT( aSymbol != NULL ); + wxASSERT( aSymbol != nullptr ); m_rootSymbol = aSymbol; m_libPart = aLibSymbol; // Warning: can be nullptr for orphan symbols diff --git a/eeschema/dialogs/dialog_bus_manager.cpp b/eeschema/dialogs/dialog_bus_manager.cpp index 66dde68e40..f08100fae5 100644 --- a/eeschema/dialogs/dialog_bus_manager.cpp +++ b/eeschema/dialogs/dialog_bus_manager.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * @author Jon Evans * * This program is free software: you can redistribute it and/or modify it @@ -104,8 +105,8 @@ DIALOG_BUS_MANAGER::DIALOG_BUS_MANAGER( SCH_EDIT_FRAME* aParent ) wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT ); - m_signal_edit = new wxTextCtrl( this, wxID_ANY, wxEmptyString, - wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + m_signal_edit = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, + wxDefaultSize, wxTE_PROCESS_ENTER ); auto right_button_sizer = new wxBoxSizer( wxHORIZONTAL ); @@ -146,31 +147,31 @@ DIALOG_BUS_MANAGER::DIALOG_BUS_MANAGER( SCH_EDIT_FRAME* aParent ) Bind( wxEVT_INIT_DIALOG, &DIALOG_BUS_MANAGER::OnInitDialog, this ); m_bus_list_view->Connect( wxEVT_COMMAND_LIST_ITEM_DESELECTED, - wxListEventHandler( DIALOG_BUS_MANAGER::OnSelectBus ), NULL, this ); + wxListEventHandler( DIALOG_BUS_MANAGER::OnSelectBus ), nullptr, this ); m_bus_list_view->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, - wxListEventHandler( DIALOG_BUS_MANAGER::OnSelectBus ), NULL, this ); + wxListEventHandler( DIALOG_BUS_MANAGER::OnSelectBus ), nullptr, this ); m_signal_list_view->Connect( wxEVT_COMMAND_LIST_ITEM_DESELECTED, - wxListEventHandler( DIALOG_BUS_MANAGER::OnSelectSignal ), NULL, this ); + wxListEventHandler( DIALOG_BUS_MANAGER::OnSelectSignal ), nullptr, this ); m_signal_list_view->Connect( wxEVT_COMMAND_LIST_ITEM_SELECTED, - wxListEventHandler( DIALOG_BUS_MANAGER::OnSelectSignal ), NULL, this ); + wxListEventHandler( DIALOG_BUS_MANAGER::OnSelectSignal ), nullptr, this ); m_btn_add_bus->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_BUS_MANAGER::OnAddBus ), NULL, this ); + wxCommandEventHandler( DIALOG_BUS_MANAGER::OnAddBus ), nullptr, this ); m_btn_rename_bus->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_BUS_MANAGER::OnRenameBus ), NULL, this ); + wxCommandEventHandler( DIALOG_BUS_MANAGER::OnRenameBus ), nullptr, this ); m_btn_remove_bus->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_BUS_MANAGER::OnRemoveBus ), NULL, this ); + wxCommandEventHandler( DIALOG_BUS_MANAGER::OnRemoveBus ), nullptr, this ); m_signal_edit->Connect( wxEVT_TEXT_ENTER, - wxCommandEventHandler( DIALOG_BUS_MANAGER::OnAddSignal ), NULL, this ); + wxCommandEventHandler( DIALOG_BUS_MANAGER::OnAddSignal ), nullptr, this ); m_btn_add_signal->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_BUS_MANAGER::OnAddSignal ), NULL, this ); + wxCommandEventHandler( DIALOG_BUS_MANAGER::OnAddSignal ), nullptr, this ); m_btn_rename_signal->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_BUS_MANAGER::OnRenameSignal ), NULL, this ); + wxCommandEventHandler( DIALOG_BUS_MANAGER::OnRenameSignal ), nullptr, this ); m_btn_remove_signal->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_BUS_MANAGER::OnRemoveSignal ), NULL, this ); + wxCommandEventHandler( DIALOG_BUS_MANAGER::OnRemoveSignal ), nullptr, this ); m_bus_edit->Connect( wxEVT_TEXT_ENTER, - wxCommandEventHandler( DIALOG_BUS_MANAGER::OnAddBus ), NULL, this ); + wxCommandEventHandler( DIALOG_BUS_MANAGER::OnAddBus ), nullptr, this ); // Set initial UI state @@ -204,7 +205,7 @@ bool DIALOG_BUS_MANAGER::TransferDataToWindow() std::vector< std::shared_ptr > original_aliases; // collect aliases from each open sheet - for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) + for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) { std::unordered_set> sheet_aliases = screen->GetBusAliases(); original_aliases.insert( original_aliases.end(), sheet_aliases.begin(), @@ -298,7 +299,7 @@ void DIALOG_BUS_MANAGER::OnSelectBus( wxListEvent& event ) } else { - m_active_alias = NULL; + m_active_alias = nullptr; m_bus_edit->Clear(); m_signal_edit->Clear(); m_signal_list_view->DeleteAllItems(); @@ -402,7 +403,7 @@ void DIALOG_BUS_MANAGER::OnRemoveBus( wxCommandEvent& aEvent ) m_aliases.erase( m_aliases.begin() + i ); m_bus_edit->Clear(); - m_active_alias = NULL; + m_active_alias = nullptr; auto evt = wxListEvent( wxEVT_COMMAND_LIST_ITEM_DESELECTED ); OnSelectBus( evt ); diff --git a/eeschema/dialogs/dialog_choose_symbol.cpp b/eeschema/dialogs/dialog_choose_symbol.cpp index 48b9a60215..d961df5796 100644 --- a/eeschema/dialogs/dialog_choose_symbol.cpp +++ b/eeschema/dialogs/dialog_choose_symbol.cpp @@ -96,7 +96,7 @@ DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxStr m_hsplitter = new wxSplitterWindow( m_vsplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH ); - //Avoid the splitter window being assigned as the Parent to additional windows + // Avoid the splitter window being assigned as the parent to additional windows. m_vsplitter->SetExtraStyle( wxWS_EX_TRANSIENT ); m_hsplitter->SetExtraStyle( wxWS_EX_TRANSIENT ); @@ -219,7 +219,7 @@ DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxStr if( m_details ) { m_details->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_CHOOSE_SYMBOL::OnCharHook ), - NULL, this ); + nullptr, this ); } } @@ -250,7 +250,8 @@ DIALOG_CHOOSE_SYMBOL::~DIALOG_CHOOSE_SYMBOL() if( m_details ) { m_details->Disconnect( wxEVT_CHAR_HOOK, - wxKeyEventHandler( DIALOG_CHOOSE_SYMBOL::OnCharHook ), NULL, this ); + wxKeyEventHandler( DIALOG_CHOOSE_SYMBOL::OnCharHook ), nullptr, + this ); } if( EESCHEMA_SETTINGS* cfg = dynamic_cast( Kiface().KifaceSettings() ) ) diff --git a/eeschema/dialogs/dialog_edit_symbols_libid.cpp b/eeschema/dialogs/dialog_edit_symbols_libid.cpp index ec207afb81..35462893de 100644 --- a/eeschema/dialogs/dialog_edit_symbols_libid.cpp +++ b/eeschema/dialogs/dialog_edit_symbols_libid.cpp @@ -475,7 +475,7 @@ SCH_EDIT_FRAME* DIALOG_EDIT_SYMBOLS_LIBID::GetParent() void DIALOG_EDIT_SYMBOLS_LIBID::AddRowToGrid( bool aMarkRow, const wxString& aReferences, - const wxString& aStrLibId ) + const wxString& aStrLibId ) { int row = m_grid->GetNumberRows(); @@ -634,8 +634,9 @@ void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event ) m_grid->GetCellValue( grid_row_idx, COL_CURR_LIBID ) ); wxSingleChoiceDialog dlg ( this, msg, - wxString::Format( _( "Candidates count %d " ), libIdCandidateCount ), - candidateSymbNames ); + wxString::Format( _( "Candidates count %d " ), + libIdCandidateCount ), + candidateSymbNames ); if( dlg.ShowModal() == wxID_OK ) m_grid->SetCellValue( grid_row_idx, COL_NEW_LIBID, dlg.GetStringSelection() ); @@ -649,7 +650,9 @@ void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event ) (unsigned) m_OrphansRowIndexes.size() - fixesCount ) ); } else + { wxMessageBox( wxString::Format( _( "All %u link(s) resolved" ), fixesCount ) ); + } } @@ -658,7 +661,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow ) #if 0 // Use dialog symbol selector to choose a symbol SCH_BASE_FRAME::HISTORY_LIST dummy; - SCH_BASE_FRAME::PICKED_SYMBOL sel = m_frame->SelectComponentFromLibrary( NULL, dummy, true, + SCH_BASE_FRAME::PICKED_SYMBOL sel = m_frame->SelectComponentFromLibrary( nullptr, dummy, true, 0, 0, false ); #else // Use library viewer to choose a symbol @@ -671,7 +674,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow ) if( !current.IsEmpty() ) preselected.Parse( current, true ); - PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibBrowser( this, NULL, preselected, 0, 0 ); + PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibBrowser( this, nullptr, preselected, 0, 0 ); #endif if( sel.LibId.empty() ) // command aborted @@ -764,7 +767,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow() false, /* update ref */ false, /* update other fields */ false, /* reset ref */ - true /* reset other fields */ ); + true /* reset other fields */ ); } } } @@ -829,8 +832,8 @@ bool InvokeDialogEditSymbolsLibId( SCH_EDIT_FRAME* aCaller ) // quasimodal mode for the quasimodal frame support to work. So don't use // the QUASIMODAL macros here. DIALOG_EDIT_SYMBOLS_LIBID dlg( aCaller ); - // DO NOT use ShowModal() here, otherwise the library browser will not work - // properly. + + // DO NOT use ShowModal() here, otherwise the library browser will not work properly. dlg.ShowQuasiModal(); return dlg.IsSchematicModified(); diff --git a/eeschema/dialogs/dialog_lib_symbol_properties.cpp b/eeschema/dialogs/dialog_lib_symbol_properties.cpp index e639f7a992..5859f7a75a 100644 --- a/eeschema/dialogs/dialog_lib_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_lib_symbol_properties.cpp @@ -103,7 +103,7 @@ DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES( SYMBOL_EDIT_FRAME* a // wxFormBuilder doesn't include this event... m_grid->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging ), - NULL, this ); + nullptr, this ); if( m_lastLayout != DIALOG_LIB_SYMBOL_PROPERTIES::NONE ) { @@ -137,7 +137,7 @@ DIALOG_LIB_SYMBOL_PROPERTIES::~DIALOG_LIB_SYMBOL_PROPERTIES() m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging ), - NULL, this ); + nullptr, this ); // Delete the GRID_TRICKS. m_grid->PopEventHandler( true ); @@ -171,7 +171,8 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow() m_DescCtrl->ChangeValue( m_libEntry->GetDescription() ); m_KeywordCtrl->ChangeValue( m_libEntry->GetKeyWords() ); m_SelNumberOfUnits->SetValue( m_libEntry->GetUnitCount() ); - m_OptionPartsInterchangeable->SetValue( !m_libEntry->UnitsLocked() || m_libEntry->GetUnitCount() == 1 ); + m_OptionPartsInterchangeable->SetValue( !m_libEntry->UnitsLocked() || + m_libEntry->GetUnitCount() == 1 ); m_AsConvertButt->SetValue( m_libEntry->HasConversion() ); m_OptionPower->SetValue( m_libEntry->IsPower() ); m_excludeFromBomCheckBox->SetValue( !m_libEntry->GetIncludeInBom() ); @@ -563,7 +564,9 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event ) m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); } else + { wxBell(); + } } @@ -596,7 +599,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event ) } -void DIALOG_LIB_SYMBOL_PROPERTIES::OnFilterDClick( wxMouseEvent& event) +void DIALOG_LIB_SYMBOL_PROPERTIES::OnFilterDClick( wxMouseEvent& event ) { int idx = m_FootprintFilterListBox->HitTest( event.GetPosition() ); wxCommandEvent dummy; diff --git a/eeschema/dialogs/dialog_netlist.cpp b/eeschema/dialogs/dialog_netlist.cpp index 29a7599dfb..0e3ad8704b 100644 --- a/eeschema/dialogs/dialog_netlist.cpp +++ b/eeschema/dialogs/dialog_netlist.cpp @@ -217,9 +217,9 @@ NETLIST_PAGE_DIALOG::NETLIST_PAGE_DIALOG( wxNotebook* parent, const wxString& ti { m_IdNetType = id_NetType; m_pageNetFmtName = title; - m_CommandStringCtrl = NULL; - m_TitleStringCtrl = NULL; - m_AdjustPassiveValues = NULL; + m_CommandStringCtrl = nullptr; + m_TitleStringCtrl = nullptr; + m_AdjustPassiveValues = nullptr; wxString netfmtName = static_cast( parent->GetParent() )->m_DefaultNetFmtName; @@ -254,7 +254,7 @@ NETLIST_DIALOG::NETLIST_DIALOG( SCH_EDIT_FRAME* parent ) : m_DefaultNetFmtName = settings.m_NetFormatName; for( NETLIST_PAGE_DIALOG*& page : m_PanelNetType) - page = NULL; + page = nullptr; // Add notebook pages: m_PanelNetType[PANELPCBNEW] = new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "KiCad" ), @@ -334,7 +334,7 @@ void NETLIST_DIALOG::InstallPageSpice() wxStaticText* spice_label = new wxStaticText( page, -1, _( "External simulator command:" ) ); spice_label->SetToolTip( _( "Enter the command line to run spice\n" "Usually %I\n" - "%I will be replaced by the actual spice netlist name") ); + "%I will be replaced by the actual spice netlist name" ) ); page->m_LowBoxSizer->Add( spice_label, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); page->m_CommandStringCtrl = new wxTextCtrl( page, -1, simulatorCommand, @@ -415,7 +415,7 @@ void NETLIST_DIALOG::OnNetlistTypeSelection( wxNotebookEvent& event ) { NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage(); - if( currPage == NULL ) + if( currPage == nullptr ) return; m_DefaultNetFmtName = currPage->GetPageNetFmtName(); @@ -496,7 +496,7 @@ bool NETLIST_DIALOG::TransferDataFromWindow() wxString fullname = fn.GetFullName(); wxString path = fn.GetPath(); - // fullname does not and should not include the path, per wx docs. + // full name does not and should not include the path, per wx docs. wxFileDialog dlg( this, title, path, fullname, fileWildcard, wxFD_SAVE ); if( dlg.ShowModal() == wxID_CANCEL ) @@ -578,7 +578,7 @@ void NETLIST_DIALOG::WriteCurrentNetlistSetup() { NETLIST_PAGE_DIALOG* currPage = m_PanelNetType[ii + PANELCUSTOMBASE]; - if( currPage == NULL ) + if( currPage == nullptr ) break; wxString title = currPage->m_TitleStringCtrl->GetValue(); @@ -626,7 +626,7 @@ void NETLIST_DIALOG::OnAddGenerator( wxCommandEvent& event ) netTypeId = PANELCUSTOMBASE + ii; currPage = m_PanelNetType[ii + PANELCUSTOMBASE]; - if( currPage == NULL ) + if( currPage == nullptr ) break; if( currPage->GetPageNetFmtName() == title ) diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index 7138d87315..b3f3074c21 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -37,6 +37,7 @@ #include #include + class DIALOG_PRINT_USING_PRINTER : public DIALOG_PRINT_USING_PRINTER_BASE { public: @@ -70,7 +71,7 @@ public: SCH_PRINTOUT( SCH_EDIT_FRAME* aParent, const wxString& aTitle ) : wxPrintout( aTitle ) { - wxASSERT( aParent != NULL ); + wxASSERT( aParent != nullptr ); m_parent = aParent; } @@ -336,6 +337,7 @@ bool DIALOG_PRINT_USING_PRINTER::TransferDataFromWindow() m_parent->GetPageSetupData() = printer.GetPrintDialogData().GetPrintData(); } } + Pgm().m_Printing = false; return true; @@ -349,7 +351,7 @@ bool SCH_PRINTOUT::OnPrintPage( int page ) wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false, wxT( "Cannot print invalid page number." ) ); - wxCHECK_MSG( sheetList[ page - 1].LastScreen() != NULL, false, + wxCHECK_MSG( sheetList[ page - 1].LastScreen() != nullptr, false, wxT( "Cannot print page with NULL screen." ) ); wxString msg; diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index 810dbb8840..397607fa69 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -81,7 +81,8 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : // Connect Events m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED, - wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this ); + wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), nullptr, + this ); if( Prj().IsReadOnly() ) { @@ -96,7 +97,8 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : DIALOG_SCHEMATIC_SETUP::~DIALOG_SCHEMATIC_SETUP() { m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED, - wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), NULL, this ); + wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), nullptr, + this ); } diff --git a/eeschema/dialogs/dialog_spice_model.cpp b/eeschema/dialogs/dialog_spice_model.cpp index 78ea2549c2..083e052dfb 100644 --- a/eeschema/dialogs/dialog_spice_model.cpp +++ b/eeschema/dialogs/dialog_spice_model.cpp @@ -247,21 +247,19 @@ bool DIALOG_SPICE_MODEL::TransferDataFromWindow() switch( m_pasType->GetSelection() ) { - case 0: m_fieldsTmp[SF_PRIMITIVE] = (char) SP_RESISTOR; break; - case 1: m_fieldsTmp[SF_PRIMITIVE] = (char) SP_CAPACITOR; break; - case 2: m_fieldsTmp[SF_PRIMITIVE] = (char) SP_INDUCTOR; break; + case 0: m_fieldsTmp[SF_PRIMITIVE] = (char) SP_RESISTOR; break; + case 1: m_fieldsTmp[SF_PRIMITIVE] = (char) SP_CAPACITOR; break; + case 2: m_fieldsTmp[SF_PRIMITIVE] = (char) SP_INDUCTOR; break; - default: - wxASSERT_MSG( false, "Unhandled passive type" ); - return false; - break; + default: + wxASSERT_MSG( false, "Unhandled passive type" ); + return false; + break; } m_fieldsTmp[SF_MODEL] = m_pasValue->GetValue(); } - - // Model - else if( page == m_model ) + else if( page == m_model ) // Model { if( !m_model->Validate() ) return false; @@ -656,7 +654,7 @@ bool DIALOG_SPICE_MODEL::parsePowerSource( const wxString& aModel ) } -bool DIALOG_SPICE_MODEL::generatePowerSource( wxString& aTarget ) const +bool DIALOG_SPICE_MODEL::generatePowerSource( wxString& aTarget ) { wxString acdc, trans; wxWindow* page = m_powerNotebook->GetCurrentPage(); @@ -677,7 +675,7 @@ bool DIALOG_SPICE_MODEL::generatePowerSource( wxString& aTarget ) const } catch( ... ) { - DisplayError( NULL, wxT( "Invalid DC value" ) ); + DisplayError( this, wxT( "Invalid DC value" ) ); return false; } @@ -695,7 +693,7 @@ bool DIALOG_SPICE_MODEL::generatePowerSource( wxString& aTarget ) const } catch( ... ) { - DisplayError( NULL, wxT( "Invalid AC magnitude or phase" ) ); + DisplayError( this, wxT( "Invalid AC magnitude or phase" ) ); return false; } @@ -839,6 +837,7 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath ) { //First, expand env vars, if any wxString libname = ExpandEnvVarSubstitutions( aFilePath, &Prj() ); + // Make path absolute, especially if it is relative to the project path libname = Prj().AbsolutePath( libname ); @@ -848,7 +847,7 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath ) bool in_subckt = false; // flag indicating that the parser is inside a .subckt section if( !filePath.Exists() ) - return; + return; // Display the library contents wxWindowUpdateLocker updateLock( this ); @@ -889,7 +888,6 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath ) if( type != SP_UNKNOWN ) m_models.emplace( name, MODEL( line_nr, type ) ); } - else if( token == ".subckt" ) { wxASSERT( !in_subckt ); @@ -902,7 +900,6 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath ) m_models.emplace( name, MODEL( line_nr, SP_SUBCKT ) ); } - else if( token == ".ends" ) { wxASSERT( in_subckt ); @@ -944,9 +941,10 @@ SCH_FIELD& DIALOG_SPICE_MODEL::getSchField( int aFieldType ) NETLIST_EXPORTER_PSPICE::GetSpiceFieldName( (SPICE_FIELD) aFieldType ); auto fieldIt = std::find_if( m_schfields->begin(), m_schfields->end(), - [&]( const SCH_FIELD& f ) { - return f.GetName() == spiceField; - } ); + [&]( const SCH_FIELD& f ) + { + return f.GetName() == spiceField; + } ); // Found one, so return it if( fieldIt != m_schfields->end() ) @@ -1014,6 +1012,7 @@ void DIALOG_SPICE_MODEL::onSelectLibrary( wxCommandEvent& event ) { //First, expand env vars, if any, in lib path wxString libname = ExpandEnvVarSubstitutions( m_modelLibrary->GetValue(), &Prj() ); + // Make path absolute, especially if it is relative to the project path libname = Prj().AbsolutePath( libname ); @@ -1024,7 +1023,7 @@ void DIALOG_SPICE_MODEL::onSelectLibrary( wxCommandEvent& event ) wxString wildcards = SpiceLibraryFileWildcard() + "|" + AllFilesWildcard(); wxFileDialog openDlg( this, _( "Select library" ), searchPath, "", wildcards, - wxFD_OPEN | wxFD_FILE_MUST_EXIST ); + wxFD_OPEN | wxFD_FILE_MUST_EXIST ); if( openDlg.ShowModal() == wxID_CANCEL ) return; diff --git a/eeschema/dialogs/dialog_spice_model.h b/eeschema/dialogs/dialog_spice_model.h index 298a576974..427f4fa889 100644 --- a/eeschema/dialogs/dialog_spice_model.h +++ b/eeschema/dialogs/dialog_spice_model.h @@ -62,7 +62,7 @@ private: * @param aTarget is the destination for the generated string. * @return True if the string was saved successfully. */ - bool generatePowerSource( wxString& aTarget ) const; + bool generatePowerSource( wxString& aTarget ); /** * Load a list of components (.model and .subckt) from a spice library file and add them to diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index a570412aba..c5c2668807 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -101,8 +101,10 @@ protected: if( event.GetId() == MYID_SELECT_FOOTPRINT ) { // pick a footprint using the footprint picker. - wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD ); - KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_VIEWER_MODAL, true, m_dlg ); + wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), + FOOTPRINT_FIELD ); + KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_VIEWER_MODAL, true, + m_dlg ); if( frame->ShowModal( &fpid, m_dlg ) ) m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid ); @@ -111,7 +113,8 @@ protected: } else if (event.GetId() == MYID_SHOW_DATASHEET ) { - wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), DATASHEET_FIELD ); + wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), + DATASHEET_FIELD ); GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj() ); } else @@ -816,7 +819,7 @@ DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE( SCH_EDIT_FRAME* parent ) // Connect Events m_grid->Connect( wxEVT_GRID_COL_SORT, - wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), NULL, this ); + wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), nullptr, this ); } @@ -824,7 +827,8 @@ DIALOG_SYMBOL_FIELDS_TABLE::~DIALOG_SYMBOL_FIELDS_TABLE() { // Disconnect Events m_grid->Disconnect( wxEVT_GRID_COL_SORT, - wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), NULL, this ); + wxGridEventHandler( DIALOG_SYMBOL_FIELDS_TABLE::OnColSort ), nullptr, + this ); // Delete the GRID_TRICKS. m_grid->PopEventHandler( true ); @@ -934,10 +938,6 @@ void DIALOG_SYMBOL_FIELDS_TABLE::AddField( const wxString& aDisplayName, } -/** - * Constructs the rows of m_fieldsCtrl and the columns of m_dataModel from a union of all - * field names in use. - */ void DIALOG_SYMBOL_FIELDS_TABLE::LoadFieldNames() { std::set userFieldNames; diff --git a/eeschema/dialogs/dialog_symbol_fields_table.h b/eeschema/dialogs/dialog_symbol_fields_table.h index b483f5b3b5..403c7429d7 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.h +++ b/eeschema/dialogs/dialog_symbol_fields_table.h @@ -46,6 +46,11 @@ public: private: void AddField( const wxString& displayName, const wxString& aCanonicalName, bool defaultShow, bool defaultSortBy ); + + /** + * Construct the rows of m_fieldsCtrl and the columns of m_dataModel from a union of all + * field names in use. + */ void LoadFieldNames(); void OnColSort( wxGridEvent& aEvent ); diff --git a/eeschema/dialogs/dialog_symbol_remap.cpp b/eeschema/dialogs/dialog_symbol_remap.cpp index 3b7da76f88..1f9cbb2fdc 100644 --- a/eeschema/dialogs/dialog_symbol_remap.cpp +++ b/eeschema/dialogs/dialog_symbol_remap.cpp @@ -121,7 +121,7 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent ) } createProjectSymbolLibTable( m_messagePanel->Reporter() ); - Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); + Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); Prj().SchSymbolLibTable(); remapSymbolsToLibTable( m_messagePanel->Reporter() ); @@ -133,7 +133,7 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent ) SYMBOL_LIBS::LibNamesAndPaths( &Prj(), true, &paths, &libNames ); // Reload the cache symbol library. - Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, NULL ); + Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr ); Prj().SchLibs(); Raise(); @@ -283,7 +283,7 @@ void DIALOG_SYMBOL_REMAP::remapSymbolsToLibTable( REPORTER& aReporter ) bool DIALOG_SYMBOL_REMAP::remapSymbolToLibTable( SCH_SYMBOL* aSymbol ) { - wxCHECK_MSG( aSymbol != NULL, false, "Null pointer passed to remapSymbolToLibTable." ); + wxCHECK_MSG( aSymbol != nullptr, false, "Null pointer passed to remapSymbolToLibTable." ); wxCHECK_MSG( aSymbol->GetLibId().GetLibNickname().empty(), false, "Cannot remap symbol that is already mapped." ); wxCHECK_MSG( !aSymbol->GetLibId().GetLibItemName().empty(), false, diff --git a/eeschema/ee_collectors.cpp b/eeschema/ee_collectors.cpp index 5508351172..d50e9f3857 100644 --- a/eeschema/ee_collectors.cpp +++ b/eeschema/ee_collectors.cpp @@ -215,8 +215,8 @@ bool EE_COLLECTOR::IsCorner() const if( GetCount() != 2 ) return false; - bool is_busentry0 = ( dynamic_cast( m_list[0] ) != NULL); - bool is_busentry1 = ( dynamic_cast( m_list[1] ) != NULL); + bool is_busentry0 = ( dynamic_cast( m_list[0] ) != nullptr ); + bool is_busentry1 = ( dynamic_cast( m_list[1] ) != nullptr ); if(( m_list[0]->Type() == SCH_LINE_T) && ( m_list[1]->Type() == SCH_LINE_T) ) return ( ( SCH_LINE* ) m_list[0])->GetLayer() == ( ( SCH_LINE* ) m_list[1])->GetLayer(); diff --git a/eeschema/ee_collectors.h b/eeschema/ee_collectors.h index 4abe334303..22347c554b 100644 --- a/eeschema/ee_collectors.h +++ b/eeschema/ee_collectors.h @@ -36,9 +36,6 @@ class SCH_SHEET_PATH; class SCH_SYMBOL; -/** - * EE_COLLECTOR - */ class EE_COLLECTOR : public COLLECTOR { public: @@ -68,7 +65,7 @@ public: if( (unsigned)aIndex < (unsigned)GetCount() ) return (SCH_ITEM*) m_list[ aIndex ]; - return NULL; + return nullptr; } SEARCH_RESULT Inspect( EDA_ITEM* aItem, void* aTestData ) override; diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 9cb235011a..0b085ec175 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -50,7 +50,7 @@ #include // The main sheet of the project -SCH_SHEET* g_RootSheet = NULL; +SCH_SHEET* g_RootSheet = nullptr; // a transform matrix, to display symbols in lib editor TRANSFORM DefaultTransform = TRANSFORM( 1, 0, 0, -1 ); @@ -123,7 +123,8 @@ static struct IFACE : public KIFACE_I void OnKifaceEnd() override; - wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override + wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, + int aCtlBits = 0 ) override { switch( aClassId ) { @@ -167,17 +168,19 @@ static struct IFACE : public KIFACE_I return nullptr; default: - return NULL; + return nullptr; } } /** - * Function IfaceOrAddress - * return a pointer to the requested object. The safest way to use this is to retrieve - * a pointer to a static instance of an interface, similar to how the KIFACE interface - * is exported. But if you know what you are doing use it to retrieve anything you want. + * Return a pointer to the requested object. + * + * The safest way to use this is to retrieve a pointer to a static instance of an interface, + * similar to how the KIFACE interface is exported. But if you know what you are doing use + * it to retrieve anything you want. + * * @param aDataId identifies which object you want the address of. - * @return void* - and must be cast into the know type. + * @return the object requested and must be cast into the know type. */ void* IfaceOrAddress( int aDataId ) override { @@ -186,11 +189,11 @@ static struct IFACE : public KIFACE_I case KIFACE_NETLIST_SCHEMATIC: return (void*) generateSchematicNetlist; } - return NULL; + + return nullptr; } /** - * Function SaveFileAs * Saving a file under a different name is delegated to the various KIFACEs because * the project doesn't know the internal format of the various files (which may have * paths in them that need updating). @@ -247,7 +250,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) if( !fn.FileExists() ) { - DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG fpDialog( NULL ); + DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG fpDialog( nullptr ); fpDialog.ShowModal(); } @@ -271,7 +274,7 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) "Please edit this global symbol library table in Preferences menu." ); - DisplayErrorMessage( NULL, msg, ioe.What() ); + DisplayErrorMessage( nullptr, msg, ioe.What() ); } } @@ -284,6 +287,7 @@ void IFACE::OnKifaceEnd() end_common(); } + static void traverseSEXPR( SEXPR::SEXPR* aNode, const std::function& aVisitor ) { @@ -311,8 +315,10 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProje destFile.SetPath( destPath ); - if( ext == LegacySchematicFileExtension || ext == LegacySchematicFileExtension + BackupFileSuffix || - ext == KiCadSchematicFileExtension || ext == KiCadSchematicFileExtension + BackupFileSuffix ) + if( ext == LegacySchematicFileExtension || + ext == LegacySchematicFileExtension + BackupFileSuffix || + ext == KiCadSchematicFileExtension || + ext == KiCadSchematicFileExtension + BackupFileSuffix ) { if( destFile.GetName() == aProjectName ) destFile.SetName( aNewProjectName ); @@ -416,7 +422,8 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProje wxString uri = row.GetFullURI(); uri.Replace( "/" + aProjectName + "-cache.lib", "/" + aNewProjectName + "-cache.lib" ); - uri.Replace( "/" + aProjectName + "-rescue.lib", "/" + aNewProjectName + "-rescue.lib" ); + uri.Replace( "/" + aProjectName + "-rescue.lib", "/" + aNewProjectName + + "-rescue.lib" ); uri.Replace( "/" + aProjectName + ".lib", "/" + aNewProjectName + ".lib" ); row.SetFullURI( uri ); diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 19976a5e76..c4e275ac3a 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -139,7 +139,7 @@ void SCH_EDIT_FRAME::SaveProjectSettings() void SCH_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { - // For now, axes are forced off in eeschema even if turned on in config + // For now, axes are forced off in Eeschema even if turned on in config eeconfig()->m_Window.grid.axes_enabled = false; SCH_BASE_FRAME::LoadSettings( eeconfig() ); @@ -270,7 +270,7 @@ SYMBOL_LIB_TABLE* PROJECT::SchSymbolLibTable() wxString msg; msg.Printf( _( "Error loading the symbol library table '%s'." ), fn.GetFullPath() ); - DisplayErrorMessage( NULL, msg, ioe.What() ); + DisplayErrorMessage( nullptr, msg, ioe.What() ); } } } diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index fa91f3931d..943040a748 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -287,7 +287,7 @@ int ERC_TESTER::TestConflictingBusAliases() SCH_SCREENS screens( m_schematic->Root() ); std::vector< std::shared_ptr > aliases; - for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) + for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) { std::unordered_set< std::shared_ptr > screen_aliases = screen->GetBusAliases(); @@ -682,7 +682,7 @@ int ERC_TESTER::TestLibSymbolIssues() SCH_SCREENS screens( m_schematic->Root() ); - for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) + for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) { std::vector markers; diff --git a/eeschema/lib_arc.cpp b/eeschema/lib_arc.cpp index 5833c86c1f..67118e1a86 100644 --- a/eeschema/lib_arc.cpp +++ b/eeschema/lib_arc.cpp @@ -189,6 +189,7 @@ void LIB_ARC::MirrorHorizontal( const wxPoint& aCenter ) std::swap( m_t1, m_t2 ); m_t1 = 1800 - m_t1; m_t2 = 1800 - m_t2; + if( m_t1 > 3600 || m_t2 > 3600 ) { m_t1 -= 3600; @@ -201,6 +202,7 @@ void LIB_ARC::MirrorHorizontal( const wxPoint& aCenter ) } } + void LIB_ARC::MirrorVertical( const wxPoint& aCenter ) { m_Pos.y -= aCenter.y; @@ -216,6 +218,7 @@ void LIB_ARC::MirrorVertical( const wxPoint& aCenter ) std::swap( m_t1, m_t2 ); m_t1 = - m_t1; m_t2 = - m_t2; + if( m_t1 > 3600 || m_t2 > 3600 ) { m_t1 -= 3600; @@ -228,6 +231,7 @@ void LIB_ARC::MirrorVertical( const wxPoint& aCenter ) } } + void LIB_ARC::Rotate( const wxPoint& aCenter, bool aRotateCCW ) { int rot_angle = aRotateCCW ? -900 : 900; @@ -236,6 +240,7 @@ void LIB_ARC::Rotate( const wxPoint& aCenter, bool aRotateCCW ) RotatePoint( &m_ArcEnd, aCenter, rot_angle ); m_t1 -= rot_angle; m_t2 -= rot_angle; + if( m_t1 > 3600 || m_t2 > 3600 ) { m_t1 -= 3600; @@ -249,11 +254,10 @@ void LIB_ARC::Rotate( const wxPoint& aCenter, bool aRotateCCW ) } - void LIB_ARC::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, const TRANSFORM& aTransform ) const { - wxASSERT( aPlotter != NULL ); + wxASSERT( aPlotter != nullptr ); int t1 = m_t1; int t2 = m_t2; @@ -541,7 +545,7 @@ void LIB_ARC::CalcRadiusAngles() m_Radius = KiROUND( EuclideanNorm( centerStartVector ) ); - // Angles in eeschema are still integers + // Angles in Eeschema are still integers m_t1 = KiROUND( ArcTangente( centerStartVector.y, centerStartVector.x ) ); m_t2 = KiROUND( ArcTangente( centerEndVector.y, centerEndVector.x ) ); @@ -550,18 +554,18 @@ void LIB_ARC::CalcRadiusAngles() // Restrict angle to less than 180 to avoid PBS display mirror Trace because it is // assumed that the arc is less than 180 deg to find orientation after rotate or mirror. - if( (m_t2 - m_t1) > 1800 ) + if( ( m_t2 - m_t1 ) > 1800 ) m_t2 -= 3600; - else if( (m_t2 - m_t1) <= -1800 ) + else if( ( m_t2 - m_t1 ) <= -1800 ) m_t2 += 3600; - while( (m_t2 - m_t1) >= 1800 ) + while( ( m_t2 - m_t1 ) >= 1800 ) { m_t2--; m_t1++; } - while( (m_t1 - m_t2) >= 1800 ) + while( ( m_t1 - m_t2 ) >= 1800 ) { m_t2++; m_t1--; diff --git a/eeschema/lib_bezier.cpp b/eeschema/lib_bezier.cpp index 6ab3a92a05..558b5f7645 100644 --- a/eeschema/lib_bezier.cpp +++ b/eeschema/lib_bezier.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-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 @@ -97,6 +97,7 @@ void LIB_BEZIER::MoveTo( const wxPoint& aPosition ) Offset( aPosition - m_PolyPoints[ 0 ] ); } + const wxPoint LIB_BEZIER::GetOffset() const { if ( !m_PolyPoints.size() ) @@ -105,6 +106,7 @@ const wxPoint LIB_BEZIER::GetOffset() const return m_PolyPoints[0]; } + void LIB_BEZIER::MirrorHorizontal( const wxPoint& aCenter ) { size_t i, imax = m_PolyPoints.size(); @@ -126,6 +128,7 @@ void LIB_BEZIER::MirrorHorizontal( const wxPoint& aCenter ) } } + void LIB_BEZIER::MirrorVertical( const wxPoint& aCenter ) { size_t i, imax = m_PolyPoints.size(); @@ -147,6 +150,7 @@ void LIB_BEZIER::MirrorVertical( const wxPoint& aCenter ) } } + void LIB_BEZIER::Rotate( const wxPoint& aCenter, bool aRotateCCW ) { int rot_angle = aRotateCCW ? -900 : 900; @@ -162,7 +166,7 @@ void LIB_BEZIER::Rotate( const wxPoint& aCenter, bool aRotateCCW ) void LIB_BEZIER::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, const TRANSFORM& aTransform ) const { - wxASSERT( aPlotter != NULL ); + wxASSERT( aPlotter != nullptr ); static std::vector< wxPoint > cornerList; cornerList.clear(); diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 3017bd9cfb..f41a2648c1 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -48,14 +48,14 @@ LIB_FIELD::LIB_FIELD( LIB_SYMBOL* aParent, int idfield ) : LIB_FIELD::LIB_FIELD( int idfield ) : - LIB_ITEM( LIB_FIELD_T, NULL ) + LIB_ITEM( LIB_FIELD_T, nullptr ) { Init( idfield ); } LIB_FIELD::LIB_FIELD( int aID, const wxString& aName ) : - LIB_ITEM( LIB_FIELD_T, NULL ) + LIB_ITEM( LIB_FIELD_T, nullptr ) { Init( aID ); m_name = aName; @@ -402,9 +402,7 @@ void LIB_FIELD::SetName( const wxString& aName ) wxString LIB_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( "%s '%s'", - GetName(), - ShortenedShownText() ); + return wxString::Format( "%s '%s'", GetName(), ShortenedShownText() ); } diff --git a/eeschema/lib_polyline.cpp b/eeschema/lib_polyline.cpp index 527526d4ec..f30af9c97a 100644 --- a/eeschema/lib_polyline.cpp +++ b/eeschema/lib_polyline.cpp @@ -121,7 +121,7 @@ void LIB_POLYLINE::Rotate( const wxPoint& aCenter, bool aRotateCCW ) void LIB_POLYLINE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, const TRANSFORM& aTransform ) const { - wxASSERT( aPlotter != NULL ); + wxASSERT( aPlotter != nullptr ); static std::vector< wxPoint > cornerList; cornerList.clear(); @@ -348,8 +348,7 @@ void LIB_POLYLINE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aLi wxString LIB_POLYLINE::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( _( "Polyline, %d points" ), - int( m_PolyPoints.size() ) ); + return wxString::Format( _( "Polyline, %d points" ), int( m_PolyPoints.size() ) ); } diff --git a/eeschema/lib_rectangle.cpp b/eeschema/lib_rectangle.cpp index 4bb75b931a..0d4e81413f 100644 --- a/eeschema/lib_rectangle.cpp +++ b/eeschema/lib_rectangle.cpp @@ -124,7 +124,7 @@ void LIB_RECTANGLE::Rotate( const wxPoint& aCenter, bool aRotateCCW ) void LIB_RECTANGLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, const TRANSFORM& aTransform ) const { - wxASSERT( aPlotter != NULL ); + wxASSERT( aPlotter != nullptr ); wxPoint pos = aTransform.TransformCoordinate( m_Pos ) + aOffset; wxPoint end = aTransform.TransformCoordinate( m_End ) + aOffset; diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index 3e306679e7..4adb4b9e39 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -530,7 +530,7 @@ void LIB_SYMBOL::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset } else if( drawItem.Type() == LIB_FIELD_T ) { - drawItem.Print( aSettings, aOffset, (void*) NULL, aOpts.transform ); + drawItem.Print( aSettings, aOffset, (void*) nullptr, aOpts.transform ); } else { @@ -544,7 +544,7 @@ void LIB_SYMBOL::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset void LIB_SYMBOL::Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset, const TRANSFORM& aTransform ) const { - wxASSERT( aPlotter != NULL ); + wxASSERT( aPlotter != nullptr ); aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) ); bool fill = aPlotter->GetColorMode(); @@ -590,7 +590,7 @@ void LIB_SYMBOL::Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint void LIB_SYMBOL::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset, const TRANSFORM& aTransform ) { - wxASSERT( aPlotter != NULL ); + wxASSERT( aPlotter != nullptr ); aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_FIELDS ) ); bool fill = aPlotter->GetColorMode(); @@ -626,7 +626,7 @@ void LIB_SYMBOL::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, void LIB_SYMBOL::RemoveDrawItem( LIB_ITEM* aItem ) { - wxASSERT( aItem != NULL ); + wxASSERT( aItem != nullptr ); // none of the MANDATORY_FIELDS may be removed in RAM, but they may be // omitted when saving to disk. @@ -663,7 +663,7 @@ void LIB_SYMBOL::AddDrawItem( LIB_ITEM* aItem, bool aSort ) LIB_ITEM* LIB_SYMBOL::GetNextDrawItem( const LIB_ITEM* aItem, KICAD_T aType ) { - if( aItem == NULL ) + if( aItem == nullptr ) { LIB_ITEMS_CONTAINER::ITERATOR it1 = m_drawings.begin( aType ); @@ -686,7 +686,7 @@ LIB_ITEM* LIB_SYMBOL::GetNextDrawItem( const LIB_ITEM* aItem, KICAD_T aType ) return &( *it ); } - return NULL; + return nullptr; } @@ -731,7 +731,7 @@ LIB_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aConvert ) return pinList[i]; } - return NULL; + return nullptr; } @@ -946,7 +946,7 @@ LIB_FIELD* LIB_SYMBOL::GetFieldById( int aId ) const return field; } - return NULL; + return nullptr; } @@ -958,7 +958,7 @@ LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName ) return static_cast( &item ); } - return NULL; + return nullptr; } @@ -970,14 +970,14 @@ const LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName ) const return static_cast( &item ); } - return NULL; + return nullptr; } LIB_FIELD& LIB_SYMBOL::GetValueField() { LIB_FIELD* field = GetFieldById( VALUE_FIELD ); - wxASSERT( field != NULL ); + wxASSERT( field != nullptr ); return *field; } @@ -985,7 +985,7 @@ LIB_FIELD& LIB_SYMBOL::GetValueField() LIB_FIELD& LIB_SYMBOL::GetReferenceField() { LIB_FIELD* field = GetFieldById( REFERENCE_FIELD ); - wxASSERT( field != NULL ); + wxASSERT( field != nullptr ); return *field; } @@ -993,7 +993,7 @@ LIB_FIELD& LIB_SYMBOL::GetReferenceField() LIB_FIELD& LIB_SYMBOL::GetFootprintField() { LIB_FIELD* field = GetFieldById( FOOTPRINT_FIELD ); - wxASSERT( field != NULL ); + wxASSERT( field != nullptr ); return *field; } @@ -1001,7 +1001,7 @@ LIB_FIELD& LIB_SYMBOL::GetFootprintField() LIB_FIELD& LIB_SYMBOL::GetDatasheetField() { LIB_FIELD* field = GetFieldById( DATASHEET_FIELD ); - wxASSERT( field != NULL ); + wxASSERT( field != nullptr ); return *field; } @@ -1070,7 +1070,7 @@ LIB_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aConvert, return &item; } - return NULL; + return nullptr; } diff --git a/eeschema/lib_symbol.h b/eeschema/lib_symbol.h index e40e5c9a67..68a697e62a 100644 --- a/eeschema/lib_symbol.h +++ b/eeschema/lib_symbol.h @@ -99,7 +99,7 @@ public: LIB_SYMBOL( const wxString& aName, LIB_SYMBOL* aParent = nullptr, SYMBOL_LIB* aLibrary = nullptr ); - LIB_SYMBOL( const LIB_SYMBOL& aSymbol, SYMBOL_LIB* aLibrary = NULL ); + LIB_SYMBOL( const LIB_SYMBOL& aSymbol, SYMBOL_LIB* aLibrary = nullptr ); virtual ~LIB_SYMBOL(); @@ -354,7 +354,7 @@ public: * if TYPE_NOT_INIT search for all items types * @return - The next drawing object in the list if found, otherwise NULL. */ - LIB_ITEM* GetNextDrawItem( const LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT ); + LIB_ITEM* GetNextDrawItem( const LIB_ITEM* aItem = nullptr, KICAD_T aType = TYPE_NOT_INIT ); size_t GetPinCount() const { return m_drawings.size( LIB_PIN_T ); } @@ -369,7 +369,7 @@ public: * first pin in the draw object list. * @return - The next pin object in the list if found, otherwise NULL. */ - LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL ) + LIB_PIN* GetNextPin( LIB_PIN* aItem = nullptr ) { return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T ); } diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 084737ad04..b6d648de6c 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -265,7 +265,7 @@ void LIB_TEXT::Rotate( const wxPoint& center, bool aRotateCCW ) void LIB_TEXT::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill, const TRANSFORM& aTransform ) const { - wxASSERT( plotter != NULL ); + wxASSERT( plotter != nullptr ); EDA_RECT bBox = GetBoundingBox(); // convert coordinates from draw Y axis to symbol_editor Y axis diff --git a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp index 3f3c22283e..d717c209b9 100644 --- a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp @@ -41,13 +41,13 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, { (void)aNetlistOptions; //unused int ret = 0; - FILE* f = NULL; + FILE* f = nullptr; - if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL ) + if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == nullptr ) { wxString msg; msg.Printf( _( "Failed to create file '%s'." ), aOutFileName ); - DisplayError( NULL, msg ); + DisplayError( nullptr, msg ); return false; } diff --git a/eeschema/netlist_exporters/netlist_exporter_kicad.cpp b/eeschema/netlist_exporters/netlist_exporter_kicad.cpp index 05f8dc885a..db1772f9e1 100644 --- a/eeschema/netlist_exporters/netlist_exporter_kicad.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_kicad.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 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 @@ -31,10 +31,7 @@ #include #include "netlist_exporter_kicad.h" -/** - * Generate the KiCad netlist format supported by Pcbnew. It is basically the XML netlist - * just formatted slightly different. - */ + bool NETLIST_EXPORTER_KICAD::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) { try @@ -45,7 +42,7 @@ bool NETLIST_EXPORTER_KICAD::WriteNetlist( const wxString& aOutFileName, unsigne catch( const IO_ERROR& ioe ) { - DisplayError( NULL, ioe.What() ); + DisplayError( nullptr, ioe.What() ); return false; } diff --git a/eeschema/netlist_exporters/netlist_exporter_kicad.h b/eeschema/netlist_exporters/netlist_exporter_kicad.h index f6a5b763e1..3a216a1b78 100644 --- a/eeschema/netlist_exporters/netlist_exporter_kicad.h +++ b/eeschema/netlist_exporters/netlist_exporter_kicad.h @@ -45,6 +45,9 @@ public: /** * Write netlist to \a aOutFileName. + * + * Generate the KiCad netlist format supported by Pcbnew. It is basically the XML netlist + * just formatted slightly different. */ bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) override; diff --git a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp index 3fb3eaf2d1..2c75ccf643 100644 --- a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp @@ -40,18 +40,18 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) { (void)aNetlistOptions; //unused - FILE* f = NULL; + FILE* f = nullptr; wxString field; wxString footprint; int ret = 0; // zero now, OR in the sign bit on error wxString netName; - if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL ) + if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == nullptr ) { wxString msg; msg.Printf( _( "Failed to create file '%s'." ), aOutFileName ); - DisplayError( NULL, msg ); + DisplayError( nullptr, msg ); return false; } diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index eca25b866c..c3ffc7b452 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -88,7 +88,7 @@ static void getSymbols( SCHEMATIC* aSchematic, std::vector& aSymbol */ static LIB_SYMBOL* findSymbol( const wxString& aName, SYMBOL_LIBS* aLibs, bool aCached ) { - LIB_SYMBOL *symbol = NULL; + LIB_SYMBOL *symbol = nullptr; wxString new_name = LIB_ID::FixIllegalChars( aName, false ); for( SYMBOL_LIB& each_lib : *aLibs ) @@ -233,8 +233,8 @@ RESCUE_CACHE_CANDIDATE::RESCUE_CACHE_CANDIDATE( const wxString& aRequestedName, RESCUE_CACHE_CANDIDATE::RESCUE_CACHE_CANDIDATE() { - m_cache_candidate = NULL; - m_lib_candidate = NULL; + m_cache_candidate = nullptr; + m_lib_candidate = nullptr; } @@ -359,8 +359,8 @@ RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE( RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE() { - m_cache_candidate = NULL; - m_lib_candidate = NULL; + m_cache_candidate = nullptr; + m_lib_candidate = nullptr; } @@ -729,7 +729,7 @@ bool LEGACY_RESCUER::WriteRescueLibrary( wxWindow *aParent ) boost::ptr_vector libsSave; libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs ); - m_prj->SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, NULL ); + m_prj->SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr ); libs = new SYMBOL_LIBS(); @@ -843,7 +843,7 @@ bool SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary( wxWindow *aParent ) } // Relaod the symbol library table. - m_prj->SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); + m_prj->SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); // This can only happen if the symbol library table file was corrupted on write. if( !m_prj->SchSymbolLibTable() ) diff --git a/eeschema/project_rescue.h b/eeschema/project_rescue.h index b188790703..3e723df59a 100644 --- a/eeschema/project_rescue.h +++ b/eeschema/project_rescue.h @@ -82,7 +82,7 @@ public: * Get the part that can be loaded from the project cache, if possible, or * else NULL. */ - virtual LIB_SYMBOL* GetCacheCandidate() const { return NULL; } + virtual LIB_SYMBOL* GetCacheCandidate() const { return nullptr; } /** * Get the part the would be loaded from the libraries, if possible, or else @@ -138,7 +138,7 @@ public: RESCUE_CASE_CANDIDATE( const wxString& aRequestedName, const wxString& aNewName, LIB_SYMBOL* aLibCandidate, int aUnit = 0, int aConvert = 0 ); - RESCUE_CASE_CANDIDATE() { m_lib_candidate = NULL; } + RESCUE_CASE_CANDIDATE() { m_lib_candidate = nullptr; } virtual wxString GetActionDescription() const override; diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 13cda4f2fb..2da6062e8c 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -195,7 +195,7 @@ void SCH_BASE_FRAME::UpdateStatusBar() LIB_SYMBOL* SCH_BASE_FRAME::GetLibSymbol( const LIB_ID& aLibId, bool aUseCacheLib, bool aShowErrorMsg ) { - SYMBOL_LIB* cache = ( aUseCacheLib ) ? Prj().SchLibs()->GetCacheLibrary() : NULL; + SYMBOL_LIB* cache = ( aUseCacheLib ) ? Prj().SchLibs()->GetCacheLibrary() : nullptr; return SchGetLibSymbol( aLibId, Prj().SchSymbolLibTable(), cache, this, aShowErrorMsg ); } diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index dac0f2d49c..4896d1f576 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -73,7 +73,7 @@ class SYMBOL_EDITOR_SETTINGS; * @return The symbol found in the library or NULL if the symbol was not found. */ LIB_SYMBOL* SchGetLibSymbol( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aLibTable, - SYMBOL_LIB* aCacheLib = NULL, wxWindow* aParent = NULL, + SYMBOL_LIB* aCacheLib = nullptr, wxWindow* aParent = nullptr, bool aShowErrorMsg = false ); /** diff --git a/eeschema/sch_bitmap.cpp b/eeschema/sch_bitmap.cpp index e5c28a40c0..b63cbf4633 100644 --- a/eeschema/sch_bitmap.cpp +++ b/eeschema/sch_bitmap.cpp @@ -41,7 +41,7 @@ SCH_BITMAP::SCH_BITMAP( const wxPoint& pos ) : - SCH_ITEM( NULL, SCH_BITMAP_T ) + SCH_ITEM( nullptr, SCH_BITMAP_T ) { m_pos = pos; m_layer = LAYER_NOTES; // used only to draw/plot a rectangle, @@ -95,8 +95,8 @@ EDA_ITEM* SCH_BITMAP::Clone() const void SCH_BITMAP::SwapData( SCH_ITEM* aItem ) { wxCHECK_RET( aItem->Type() == SCH_BITMAP_T, - wxString::Format( wxT( "SCH_BITMAP object cannot swap data with %s object." ), - aItem->GetClass() ) ); + wxString::Format( wxT( "SCH_BITMAP object cannot swap data with %s object." ), + aItem->GetClass() ) ); SCH_BITMAP* item = (SCH_BITMAP*) aItem; std::swap( m_pos, item->m_pos ); diff --git a/eeschema/sch_bitmap.h b/eeschema/sch_bitmap.h index 7e9e8f27f1..847b997a67 100644 --- a/eeschema/sch_bitmap.h +++ b/eeschema/sch_bitmap.h @@ -53,7 +53,7 @@ public: BITMAP_BASE* GetImage() const { - wxCHECK_MSG( m_image != NULL, NULL, "Invalid SCH_BITMAP init, m_image is NULL." ); + wxCHECK_MSG( m_image != nullptr, nullptr, "Invalid SCH_BITMAP init, m_image is NULL." ); return m_image; } diff --git a/eeschema/sch_bus_entry.cpp b/eeschema/sch_bus_entry.cpp index fa35f265ee..49e2111b62 100644 --- a/eeschema/sch_bus_entry.cpp +++ b/eeschema/sch_bus_entry.cpp @@ -39,7 +39,7 @@ SCH_BUS_ENTRY_BASE::SCH_BUS_ENTRY_BASE( KICAD_T aType, const wxPoint& pos, bool aFlipY ) : - SCH_ITEM( NULL, aType ) + SCH_ITEM( nullptr, aType ) { m_pos = pos; m_size.x = Mils2iu( DEFAULT_SCH_ENTRY_SIZE ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 979ec1f749..3da86e4d47 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -95,8 +95,6 @@ static void add_search_paths( SEARCH_STACK* aDst, const SEARCH_STACK& aSrc, int } -//------------------------------------------------ - SEARCH_STACK* PROJECT::SchSearchS() { SEARCH_STACK* ss = (SEARCH_STACK*) GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ); @@ -190,8 +188,6 @@ SYMBOL_LIBS* PROJECT::SchLibs() return libs; } -//----------------------------------------------- - BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_SOCKET( ID_EDA_SOCKET_EVENT_SERV, EDA_DRAW_FRAME::OnSockRequestServer ) @@ -326,7 +322,7 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME() delete m_item_to_repeat; // we own the cloned object, see this->SaveCopyForRepeatItem() - SetScreen( NULL ); + SetScreen( nullptr ); delete m_schematic; m_schematic = nullptr; @@ -393,7 +389,8 @@ void SCH_EDIT_FRAME::setupUIConditions() mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) ); mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) ); - mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) ); + mgr->SetConditions( ACTIONS::millimetersUnits, + CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) ); mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) ); mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) ); @@ -410,11 +407,14 @@ void SCH_EDIT_FRAME::setupUIConditions() mgr->SetConditions( EE_ACTIONS::mirrorH, ENABLE( hasElements ) ); mgr->SetConditions( EE_ACTIONS::mirrorV, ENABLE( hasElements ) ); - mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); - mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); + mgr->SetConditions( ACTIONS::zoomTool, + CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); + mgr->SetConditions( ACTIONS::selectionTool, + CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) ); if( SCRIPTING::IsWxAvailable() ) - mgr->SetConditions( EE_ACTIONS::showPythonConsole, CHECK( cond.ScriptingConsoleVisible() ) ); + mgr->SetConditions( EE_ACTIONS::showPythonConsole, + CHECK( cond.ScriptingConsoleVisible() ) ); auto showHiddenPinsCond = [this] ( const SELECTION& ) @@ -486,6 +486,7 @@ void SCH_EDIT_FRAME::SaveCopyForRepeatItem( const SCH_ITEM* aItem ) delete m_item_to_repeat; m_item_to_repeat = (SCH_ITEM*) aItem->Clone(); + // Clone() preserves the flags, we want 'em cleared. m_item_to_repeat->ClearFlags(); } @@ -518,7 +519,7 @@ void SCH_EDIT_FRAME::SetSheetNumberAndCount() sheet_number++; // Not found, increment before this current path } - for( screen = s_list.GetFirst(); screen != NULL; screen = s_list.GetNext() ) + for( screen = s_list.GetFirst(); screen != nullptr; screen = s_list.GetNext() ) screen->SetPageCount( sheet_count ); GetCurrentSheet().SetVirtualPageNumber( sheet_number ); @@ -569,7 +570,7 @@ void SCH_EDIT_FRAME::CreateScreens() m_schematic->Root().AddInstance( rootSheetPath.Path() ); m_schematic->Root().SetPageNumber( rootSheetPath, wxT( "1" ) ); - if( GetScreen() == NULL ) + if( GetScreen() == nullptr ) { SCH_SCREEN* screen = new SCH_SCREEN( m_schematic ); SetScreen( screen ); @@ -695,7 +696,7 @@ void SCH_EDIT_FRAME::doCloseWindow() SCH_SCREENS screens( Schematic().Root() ); wxFileName fn; - for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) + for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) { fn = Prj().AbsolutePath( screen->GetFileName() ); @@ -1165,7 +1166,7 @@ static void inheritNetclass( const SCH_SHEET_PATH& aSheetPath, SCH_TEXT* aItem ) void SCH_EDIT_FRAME::AddItemToScreenAndUndoList( SCH_SCREEN* aScreen, SCH_ITEM* aItem, bool aUndoAppend ) { - wxCHECK_RET( aItem != NULL, wxT( "Cannot add null item to list." ) ); + wxCHECK_RET( aItem != nullptr, wxT( "Cannot add null item to list." ) ); SCH_SHEET* parentSheet = nullptr; SCH_SYMBOL* parentSymbol = nullptr; @@ -1356,7 +1357,7 @@ void SCH_EDIT_FRAME::RecomputeIntersheetRefs() std::vector pageNumbers; /* Iterate over screens */ - for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) + for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) { pageNumbers.clear(); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index bb08f64532..fa6354daab 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -253,7 +253,7 @@ void SCH_FIELD::ImportValues( const LIB_FIELD& aSource ) void SCH_FIELD::SwapData( SCH_ITEM* aItem ) { - wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_FIELD_T), + wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_FIELD_T ), wxT( "Cannot swap field data with invalid item." ) ); SCH_FIELD* item = (SCH_FIELD*) aItem; @@ -474,9 +474,7 @@ void SCH_FIELD::Rotate( const wxPoint& aCenter ) wxString SCH_FIELD::GetSelectMenuText( EDA_UNITS aUnits ) const { - return wxString::Format( "%s '%s'", - GetName(), - ShortenedShownText() ); + return wxString::Format( "%s '%s'", GetName(), ShortenedShownText() ); } diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 0c73990990..63737874d9 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -175,7 +175,7 @@ public: bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override; - bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override; + bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = nullptr ) override; wxString GetSelectMenuText( EDA_UNITS aUnits ) const override; diff --git a/eeschema/sch_io_mgr.cpp b/eeschema/sch_io_mgr.cpp index 7b1a53206e..bb87f0981a 100644 --- a/eeschema/sch_io_mgr.cpp +++ b/eeschema/sch_io_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) 2016-2020 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2016-2021 KiCad Developers, see change_log.txt for contributors. * * @author Wayne Stambaugh * @@ -123,7 +123,7 @@ const wxString SCH_IO_MGR::GetFileExtension( SCH_FILE_T aFileType ) wxString ext = wxEmptyString; SCH_PLUGIN* plugin = FindPlugin( aFileType ); - if( plugin != NULL ) + if( plugin != nullptr ) { ext = plugin->GetFileExtension(); ReleasePlugin( plugin ); @@ -138,7 +138,7 @@ const wxString SCH_IO_MGR::GetLibraryFileExtension( SCH_FILE_T aFileType ) wxString ext = wxEmptyString; SCH_PLUGIN* plugin = FindPlugin( aFileType ); - if( plugin != NULL ) + if( plugin != nullptr ) { ext = plugin->GetLibraryFileExtension(); ReleasePlugin( plugin ); diff --git a/eeschema/sch_junction.cpp b/eeschema/sch_junction.cpp index 533b3e2621..784c702c77 100644 --- a/eeschema/sch_junction.cpp +++ b/eeschema/sch_junction.cpp @@ -40,7 +40,7 @@ #include SCH_JUNCTION::SCH_JUNCTION( const wxPoint& aPosition, int aDiameter, SCH_LAYER_ID aLayer ) : - SCH_ITEM( NULL, SCH_JUNCTION_T ) + SCH_ITEM( nullptr, SCH_JUNCTION_T ) { m_pos = aPosition; m_color = COLOR4D::UNSPECIFIED; @@ -57,7 +57,7 @@ EDA_ITEM* SCH_JUNCTION::Clone() const void SCH_JUNCTION::SwapData( SCH_ITEM* aItem ) { - wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_JUNCTION_T), + wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_JUNCTION_T ), wxT( "Cannot swap junction data with invalid item." ) ); SCH_JUNCTION* item = (SCH_JUNCTION*) aItem; @@ -119,7 +119,8 @@ void SCH_JUNCTION::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffs SHAPE_CIRCLE circle = getEffectiveShape(); - GRFilledCircle( NULL, DC, (wxPoint) circle.GetCenter() + aOffset, circle.GetRadius(), color ); + GRFilledCircle( nullptr, DC, (wxPoint) circle.GetCenter() + aOffset, circle.GetRadius(), + color ); } diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index 89c7b295cf..a29916f1cd 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -36,7 +36,7 @@ #include SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) : - SCH_ITEM( NULL, SCH_LINE_T ) + SCH_ITEM( nullptr, SCH_LINE_T ) { m_start = pos; m_end = pos; @@ -439,7 +439,7 @@ int SCH_LINE::GetReverseAngleFrom( const wxPoint& aPoint ) const bool SCH_LINE::IsParallel( const SCH_LINE* aLine ) const { - wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, false, + wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, false, wxT( "Cannot test line segment for overlap." ) ); wxPoint firstSeg = m_end - m_start; @@ -460,7 +460,7 @@ SCH_LINE* SCH_LINE::MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCh return lhs.x < rhs.x; }; - wxCHECK_MSG( aLine != NULL && aLine->Type() == SCH_LINE_T, NULL, + wxCHECK_MSG( aLine != nullptr && aLine->Type() == SCH_LINE_T, nullptr, wxT( "Cannot test line segment for overlap." ) ); if( this == aLine || GetLayer() != aLine->GetLayer() ) diff --git a/eeschema/sch_no_connect.cpp b/eeschema/sch_no_connect.cpp index e6cbdccbf9..6a8360529c 100644 --- a/eeschema/sch_no_connect.cpp +++ b/eeschema/sch_no_connect.cpp @@ -39,7 +39,7 @@ SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) : - SCH_ITEM( NULL, SCH_NO_CONNECT_T ) + SCH_ITEM( nullptr, SCH_NO_CONNECT_T ) { m_pos = pos; m_size = Mils2iu( DEFAULT_NOCONNECT_SIZE ); ///< No-connect symbol size. @@ -56,7 +56,7 @@ EDA_ITEM* SCH_NO_CONNECT::Clone() const void SCH_NO_CONNECT::SwapData( SCH_ITEM* aItem ) { - wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_NO_CONNECT_T), + wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ), wxT( "Cannot swap no connect data with invalid item." ) ); SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem; @@ -144,6 +144,7 @@ bool SCH_NO_CONNECT::doIsConnected( const wxPoint& aPosition ) const return m_pos == aPosition; } + bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosition, int aAccuracy ) const { int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy; diff --git a/eeschema/sch_plugin.cpp b/eeschema/sch_plugin.cpp index d2d83ff4f5..2aab9faf1a 100644 --- a/eeschema/sch_plugin.cpp +++ b/eeschema/sch_plugin.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) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors. * * @author Wayne Stambaugh * @@ -52,7 +52,7 @@ SCH_SHEET* SCH_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) { not_implemented( this, __FUNCTION__ ); - return NULL; + return nullptr; } @@ -87,7 +87,7 @@ LIB_SYMBOL* SCH_PLUGIN::LoadSymbol( const wxString& aLibraryPath, const wxString { // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface. not_implemented( this, __FUNCTION__ ); - return NULL; + return nullptr; } diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index eec91f0ae4..ae5d90edd2 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -161,7 +161,7 @@ wxFileName SCH_ALTIUM_PLUGIN::getLibFileName() SCH_SHEET* SCH_ALTIUM_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) { - wxASSERT( !aFileName || aSchematic != NULL ); + wxASSERT( !aFileName || aSchematic != nullptr ); wxFileName fileName( aFileName ); fileName.SetExt( KiCadSchematicFileExtension ); @@ -197,7 +197,7 @@ SCH_SHEET* SCH_ALTIUM_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchem SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable(); - wxCHECK_MSG( libTable, NULL, "Could not load symbol lib table." ); + wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." ); m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); @@ -224,7 +224,7 @@ SCH_SHEET* SCH_ALTIUM_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchem } // Reload the symbol library table. - m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); + m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); m_schematic->Prj().SchSymbolLibTable(); } @@ -579,9 +579,10 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int aIndex, SCH_SYMBOL* symbol = new SCH_SYMBOL(); symbol->SetPosition( elem.location + m_sheetOffset ); - //component->SetOrientation( elem.orientation ); // TODO: keep it simple for now, and only set position + + // TODO: keep it simple for now, and only set position. + //component->SetOrientation( elem.orientation ); symbol->SetLibId( libId ); - //component->SetLibSymbol( ksymbol ); // this has to be done after parsing the LIB_SYMBOL! symbol->SetUnit( elem.currentpartid ); @@ -651,6 +652,7 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map& aPropertie // TODO: position can be sometimes off a little bit! pin->SetPosition( GetRelativePosition( pinLocation + m_sheetOffset, symbol ) ); + // TODO: the following fix is even worse for now? // pin->SetPosition( GetRelativePosition( elem.kicadLocation, symbol ) ); @@ -920,7 +922,7 @@ void SCH_ALTIUM_PLUGIN::ParseNote( const std::map& aProperti // TODO: set border and background color once KiCad supports them. - // TODO: need some sort of propety system for storing author.... + // TODO: need some sort of property system for storing author.... size_t fontId = static_cast( elem.fontId ); @@ -969,7 +971,7 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper } else { - // simulate bezier using line segments + // simulate Bezier using line segments std::vector bezierPoints; std::vector polyPoints; @@ -1031,7 +1033,7 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper } else { - // bezier always has maximum of 4 control points + // Bezier always has maximum of 4 control points LIB_BEZIER* bezier = new LIB_BEZIER( libSymbolIt->second ); libSymbolIt->second->AddDrawItem( bezier ); @@ -1236,6 +1238,7 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map& return; SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); + // TODO: misses rounded edges LIB_RECTANGLE* rect = new LIB_RECTANGLE( libSymbolIt->second ); libSymbolIt->second->AddDrawItem( rect ); @@ -1776,7 +1779,8 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map& aPro pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN ); pin->SetVisible( false ); - wxPoint valueFieldPos = HelperGeneratePowerPortGraphics( libSymbol, elem.style, m_reporter ); + wxPoint valueFieldPos = HelperGeneratePowerPortGraphics( libSymbol, elem.style, + m_reporter ); libSymbol->GetValueField().SetPosition( valueFieldPos ); diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 1faf020950..4cb0521524 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -79,7 +79,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSh (double) maxDesignSizekicad / SCH_IU_PER_MM ) ); } - // Assume the centre at 0,0 since we are going to be translating the design afterwards anyway + // Assume the center at 0,0 since we are going to be translating the design afterwards anyway m_designCenter = { 0, 0 }; m_schematic = aSchematic; @@ -124,7 +124,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSh } - // For all sheets, centre all elements and re calculate the page size: + // For all sheets, center all elements and re calculate the page size: for( std::pair sheetPair : m_sheetMap ) { SCH_SHEET* sheet = sheetPair.second; @@ -196,7 +196,6 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSh // Set the new sheet size. sheet->GetScreen()->SetPageSettings( pageInfo ); - wxSize pageSizeIU = sheet->GetScreen()->GetPageSettings().GetSizeIU(); wxPoint sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 ); wxPoint itemsCentre = sheetBoundingBox.Centre(); @@ -428,7 +427,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances() } LIB_SYMBOL* scaledPart = getScaledLibPart( kiPart, sym.ScaleRatioNumerator, - sym.ScaleRatioDenominator ); + sym.ScaleRatioDenominator ); double symOrientDeciDeg = 0.0; SCH_SYMBOL* symbol = loadSchematicSymbol( sym, *scaledPart, symOrientDeciDeg ); @@ -854,7 +853,6 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets() m_sheetMap.at( bus.LayerID )->GetScreen()->Append( label ); } - for( std::pair danglerPair : net.Danglers ) { NET_SCH::DANGLER dangler = danglerPair.second; @@ -868,7 +866,6 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets() m_sheetMap.at( dangler.LayerID )->GetScreen()->Append( label ); } - for( NET_SCH::CONNECTION_SCH conn : net.Connections ) { if( conn.LayerID == wxT( "NO_SHEET" ) ) @@ -952,8 +949,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets() } else { - // The block terminal is either inside or on the shape edge. Lets use the - // first interection point + // The block terminal is either inside or on the shape edge. Lets use + // the first intersection point. VECTOR2I intsctPt = wireToSheetIntersects.at( 0 ).p; int intsctIndx = wireChain.FindSegment( intsctPt ); wxASSERT_MSG( intsctIndx != -1, "Can't find intersecting segment" ); @@ -1112,7 +1109,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadDocumentationSymbols() FIGURE fig = figPair.second; loadFigure( fig, docSym.LayerID, LAYER_NOTES, moveVector, rotationAngle, scalingFactor, - centreOfTransform, mirrorInvert ); + centreOfTransform, mirrorInvert ); } for( std::pair textPair : docSymDef.Texts ) @@ -1463,7 +1460,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef }; // Load all attributes in the Part Definition - for( std::pair attr : aCadstarPart->Definition.AttributeValues ) + for( std::pair attr : aCadstarPart->Definition.AttributeValues ) { ATTRIBUTE_VALUE attrVal = attr.second; loadLibraryField( attrVal ); @@ -1949,7 +1947,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector& a else arcAngleDeciDeg = NormalizeAngleNeg( arcAngleDeciDeg ); - SHAPE_ARC tempArc( VECTOR2I(centerPoint), VECTOR2I(startPoint), arcAngleDeciDeg / 10.0 ); + SHAPE_ARC tempArc( VECTOR2I(centerPoint), VECTOR2I(startPoint), + arcAngleDeciDeg / 10.0 ); SHAPE_LINE_CHAIN arcSegments = tempArc.ConvertToPolyline( Millimeter2iu( 0.1 ) ); // Load the arc as a series of piece-wise segments @@ -1959,17 +1958,17 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector& a wxPoint segStart = (wxPoint) arcSegments.Segment( jj ).A; wxPoint segEnd = (wxPoint) arcSegments.Segment( jj ).B; - loadGraphicStaightSegment( segStart, segEnd, aCadstarLineCodeID, - aCadstarSheetID, aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, - aScalingFactor, aTransformCentre, aMirrorInvert ); + loadGraphicStaightSegment( segStart, segEnd, aCadstarLineCodeID, aCadstarSheetID, + aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, + aScalingFactor, aTransformCentre, aMirrorInvert ); } } break; case VERTEX_TYPE::POINT: loadGraphicStaightSegment( startPoint, endPoint, aCadstarLineCodeID, aCadstarSheetID, - aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, aScalingFactor, - aTransformCentre, aMirrorInvert ); + aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, + aScalingFactor, aTransformCentre, aMirrorInvert ); break; default: @@ -1988,14 +1987,14 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadFigure( const FIGURE& aCadstarFigure, const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert ) { loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID, - aCadstarSheetIDOverride, aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, - aScalingFactor, aTransformCentre, aMirrorInvert ); + aCadstarSheetIDOverride, aKiCadSchLayerID, aMoveVector, + aRotationAngleDeciDeg, aScalingFactor, aTransformCentre, aMirrorInvert ); for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts ) { loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarSheetIDOverride, - aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, aScalingFactor, - aTransformCentre, aMirrorInvert ); + aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, aScalingFactor, + aTransformCentre, aMirrorInvert ); } } @@ -2039,7 +2038,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets( wxString pageNumStr = wxString::Format( "%d", getSheetNumber( aCadstarSheetID ) ); sheet->SetPageNumber( instance, pageNumStr ); - sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); + sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); m_sheetMap.insert( { aCadstarSheetID, sheet } ); @@ -2047,8 +2046,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets( } -void CADSTAR_SCH_ARCHIVE_LOADER::loadChildSheets( - LAYER_ID aCadstarSheetID, const SCH_SHEET_PATH& aSheet ) +void CADSTAR_SCH_ARCHIVE_LOADER::loadChildSheets( LAYER_ID aCadstarSheetID, + const SCH_SHEET_PATH& aSheet ) { wxCHECK_MSG( m_sheetMap.find( aCadstarSheetID ) != m_sheetMap.end(), , "FIXME! Parent sheet should be loaded before attempting to load subsheets" ); @@ -2227,6 +2226,7 @@ CADSTAR_SCH_ARCHIVE_LOADER::SYMDEF_ID CADSTAR_SCH_ARCHIVE_LOADER::getSymDefFromN return SYMDEF_ID(); } + bool CADSTAR_SCH_ARCHIVE_LOADER::isAttributeVisible( const ATTRIBUTE_ID& aCadstarAttributeID ) { // Use CADSTAR visibility settings to determine if an attribute is visible @@ -2253,7 +2253,7 @@ PLOT_DASH_TYPE CADSTAR_SCH_ARCHIVE_LOADER::getLineStyle( const LINECODE_ID& aCad { wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID ) != Assignments.Codedefs.LineCodes.end(), - PLOT_DASH_TYPE::SOLID ); + PLOT_DASH_TYPE::SOLID ); // clang-format off switch( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Style ) @@ -2276,7 +2276,7 @@ CADSTAR_SCH_ARCHIVE_LOADER::TEXTCODE CADSTAR_SCH_ARCHIVE_LOADER::getTextCode( { wxCHECK( Assignments.Codedefs.TextCodes.find( aCadstarTextCodeID ) != Assignments.Codedefs.TextCodes.end(), - TEXTCODE() ); + TEXTCODE() ); return Assignments.Codedefs.TextCodes.at( aCadstarTextCodeID ); } @@ -2286,7 +2286,7 @@ wxString CADSTAR_SCH_ARCHIVE_LOADER::getAttributeName( const ATTRIBUTE_ID& aCads { wxCHECK( Assignments.Codedefs.AttributeNames.find( aCadstarAttributeID ) != Assignments.Codedefs.AttributeNames.end(), - wxEmptyString ); + wxEmptyString ); return Assignments.Codedefs.AttributeNames.at( aCadstarAttributeID ).Name; } @@ -2306,7 +2306,7 @@ CADSTAR_SCH_ARCHIVE_LOADER::ROUTECODE CADSTAR_SCH_ARCHIVE_LOADER::getRouteCode( { wxCHECK( Assignments.Codedefs.RouteCodes.find( aCadstarRouteCodeID ) != Assignments.Codedefs.RouteCodes.end(), - ROUTECODE() ); + ROUTECODE() ); return Assignments.Codedefs.RouteCodes.at( aCadstarRouteCodeID ); } @@ -2356,8 +2356,8 @@ int CADSTAR_SCH_ARCHIVE_LOADER::getKiCadUnitNumberFromGate( const GATE_ID& aCads } -LABEL_SPIN_STYLE CADSTAR_SCH_ARCHIVE_LOADER::getSpinStyle( - const long long& aCadstarOrientation, bool aMirror ) +LABEL_SPIN_STYLE CADSTAR_SCH_ARCHIVE_LOADER::getSpinStyle( const long long& aCadstarOrientation, + bool aMirror ) { double orientationDeciDegree = getAngleTenthDegree( aCadstarOrientation ); LABEL_SPIN_STYLE spinStyle = getSpinStyleDeciDeg( orientationDeciDegree ); @@ -2402,14 +2402,17 @@ CADSTAR_SCH_ARCHIVE_LOADER::mirrorX( const ALIGNMENT& aCadstarAlignment ) case ALIGNMENT::BOTTOMLEFT: return ALIGNMENT::BOTTOMRIGHT; case ALIGNMENT::CENTERLEFT: return ALIGNMENT::CENTERRIGHT; case ALIGNMENT::TOPLEFT: return ALIGNMENT::TOPRIGHT; + //Change right to left: case ALIGNMENT::BOTTOMRIGHT: return ALIGNMENT::BOTTOMLEFT; case ALIGNMENT::CENTERRIGHT: return ALIGNMENT::CENTERLEFT; case ALIGNMENT::TOPRIGHT: return ALIGNMENT::TOPLEFT; + // Center alignment does not mirror: case ALIGNMENT::BOTTOMCENTER: case ALIGNMENT::CENTERCENTER: case ALIGNMENT::TOPCENTER: return aCadstarAlignment; + // Shouldn't be here default: wxFAIL_MSG( "Unknown Cadstar Alignment" ); return aCadstarAlignment; } @@ -2431,6 +2434,7 @@ CADSTAR_SCH_ARCHIVE_LOADER::rotate180( const ALIGNMENT& aCadstarAlignment ) case ALIGNMENT::CENTERLEFT: return ALIGNMENT::CENTERRIGHT; case ALIGNMENT::CENTERCENTER: return ALIGNMENT::CENTERCENTER; case ALIGNMENT::CENTERRIGHT: return ALIGNMENT::CENTERLEFT; + // Shouldn't be here default: wxFAIL_MSG( "Unknown Cadstar Alignment" ); return aCadstarAlignment; } @@ -2444,9 +2448,9 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT const long long aCadstarOrientAngle, bool aMirrored ) { - // Justification ignored for now as not supported in eeschema, but leaving this code in + // Justification ignored for now as not supported in Eeschema, but leaving this code in // place for future upgrades. - // TODO update this when eeschema supports justification independent of anchor position. + // TODO update this when Eeschema supports justification independent of anchor position. TEXTCODE textCode = getTextCode( aCadstarTextCodeID ); int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO ); @@ -2613,6 +2617,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT } } + SCH_TEXT* CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText( const TEXT& aCadstarTextElement ) { SCH_TEXT* kiTxt = new SCH_TEXT(); @@ -2802,8 +2807,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins( LIB_SYMBOL* aSymbolToFix, int } -std::pair -CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad( +std::pair CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad( const FIGURE& aCadstarFigure ) { wxPoint upperLeft( Assignments.Settings.DesignLimit.x, 0 ); @@ -2862,8 +2866,8 @@ wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPoint( wxPoint aCadstarPoint ) } -wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint( - wxPoint aCadstarPoint, wxPoint aCadstarCentre ) +wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint( wxPoint aCadstarPoint, + wxPoint aCadstarCentre ) { wxPoint retval; diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h index d3dc506b7d..903837a5fe 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Roberto Fernandez Bautista - * 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 as published by the @@ -38,8 +38,6 @@ class SCH_SCREEN; class CADSTAR_SCH_ARCHIVE_PLUGIN : public SCH_PLUGIN { public: - //------------------------------------------------------ - const wxString GetName() const override; void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; } @@ -51,45 +49,11 @@ public: int GetModifyHash() const override; SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic, - SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ) override; + SCH_SHEET* aAppendToMe = nullptr, + const PROPERTIES* aProperties = nullptr ) override; bool CheckHeader( const wxString& aFileName ) override; - - // unimplemented functions. Will trigger a not_implemented IO error. - //void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override; - - //void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway, - // const PROPERTIES* aProperties = NULL ) override; - - //void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath, - // const PROPERTIES* aProperties = NULL ) override; - - //LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName, - // const PROPERTIES* aProperties = NULL ) override; - - //void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol, - // const PROPERTIES* aProperties = NULL ) override; - - //void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName, - // const PROPERTIES* aProperties = NULL ) override; - - //void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName, - // const PROPERTIES* aProperties = NULL ) override; - - //void CreateSymbolLib( const wxString& aLibraryPath, - // const PROPERTIES* aProperties = NULL ) override; - - // bool DeleteSymbolLib( const wxString& aLibraryPath, - // const PROPERTIES* aProperties = NULL ) override; - - //bool IsSymbolLibWritable( const wxString& aLibraryPath ) override; - - //void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override; - - //----------------------------------------------------- - - CADSTAR_SCH_ARCHIVE_PLUGIN() { m_reporter = &WXLOG_REPORTER::GetInstance(); diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index f69facd7ad..df36a354fc 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -408,7 +408,7 @@ void SCH_EAGLE_PLUGIN::checkpoint() / std::max( 1U, m_totalCount ) ); if( !m_progressReporter->KeepRefreshing() ) - THROW_IO_ERROR( ( "Open cancelled by user." ) ); + THROW_IO_ERROR( ( "Open canceled by user." ) ); m_lastProgressCount = m_doneCount; } @@ -430,7 +430,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) ); if( !m_progressReporter->KeepRefreshing() ) - THROW_IO_ERROR( ( "Open cancelled by user." ) ); + THROW_IO_ERROR( ( "Open canceled by user." ) ); } // Load the document @@ -469,7 +469,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable(); - wxCHECK_MSG( libTable, NULL, "Could not load symbol lib table." ); + wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." ); m_pi.set( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); m_properties = std::make_unique(); @@ -498,7 +498,7 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema } // Reload the symbol library table. - m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, NULL ); + m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr ); m_schematic->Prj().SchSymbolLibTable(); } @@ -1382,7 +1382,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) if( attributeNode->GetName() == "attribute" ) { auto attr = EATTR( attributeNode ); - SCH_FIELD* field = NULL; + SCH_FIELD* field = nullptr; if( attr.name.Lower() == "name" ) { @@ -1616,7 +1616,6 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptrconnects.size() != 0 ) { for( const auto& connect : aDevice->connects ) @@ -1663,7 +1662,8 @@ bool SCH_EAGLE_PLUGIN::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr libtext( loadSymbolText( aSymbol, currentNode, aGateNumber ) ); + std::unique_ptr libtext( loadSymbolText( aSymbol, currentNode, + aGateNumber ) ); if( libtext->GetText().Upper() == ">NAME" ) { @@ -2261,7 +2261,6 @@ void SCH_EAGLE_PLUGIN::adjustNetLabels() if( segAttached && !onIntersection( labelPos ) ) continue; // label is placed correctly - // Move the label to the nearest wire if( !segAttached ) { @@ -2272,7 +2271,6 @@ void SCH_EAGLE_PLUGIN::adjustNetLabels() continue; } - // Create a vector pointing in the direction of the wire, 50 mils long VECTOR2I wireDirection( segAttached->B - segAttached->A ); wireDirection = wireDirection.Resize( Mils2iu( 50 ) ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 11fc9ee880..52341c16ff 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -423,7 +423,7 @@ double SCH_SEXPR_PARSER::parseDouble() char* tmp; // In case the file got saved with the wrong locale. - if( strchr( CurText(), ',' ) != NULL ) + if( strchr( CurText(), ',' ) != nullptr ) { THROW_PARSE_ERROR( _( "Floating point number with incorrect locale" ), CurSource(), CurLine(), CurLineNumber(), CurOffset() ); @@ -1094,7 +1094,8 @@ LIB_BEZIER* SCH_SEXPR_PARSER::parseBezier() LIB_CIRCLE* SCH_SEXPR_PARSER::parseCircle() { wxCHECK_MSG( CurTok() == T_circle, nullptr, - wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a circle token." ) ); + wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + + wxT( " as a circle token." ) ); T token; FILL_PARAMS fill; @@ -1439,7 +1440,8 @@ LIB_POLYLINE* SCH_SEXPR_PARSER::parsePolyLine() LIB_RECTANGLE* SCH_SEXPR_PARSER::parseRectangle() { wxCHECK_MSG( CurTok() == T_rectangle, nullptr, - wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a rectangle token." ) ); + wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + + wxT( " as a rectangle token." ) ); T token; FILL_PARAMS fill; @@ -1732,7 +1734,8 @@ SCH_FIELD* SCH_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) // Empty property values are valid. wxString value = FromUTF8(); - std::unique_ptr field = std::make_unique( wxDefaultPosition, -1, aParent, name ); + std::unique_ptr field = std::make_unique( wxDefaultPosition, -1, + aParent, name ); field->SetText( value ); field->SetVisible( true ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.h b/eeschema/sch_plugins/kicad/sch_sexpr_parser.h index 2971b9f52c..05f1ae2c63 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.h +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.h @@ -96,12 +96,12 @@ class SCH_SEXPR_PARSER : public SCHEMATIC_LEXER inline long parseHex() { NextTok(); - return strtol( CurText(), NULL, 16 ); + return strtol( CurText(), nullptr, 16 ); } inline int parseInt() { - return (int)strtol( CurText(), NULL, 10 ); + return (int)strtol( CurText(), nullptr, 10 ); } inline int parseInt( const char* aExpected ) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 0e85b2f60d..c17a0bbb2c 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -369,7 +369,7 @@ public: SCH_SEXPR_PLUGIN::SCH_SEXPR_PLUGIN() : m_progressReporter( nullptr ) { - init( NULL ); + init( nullptr ); } @@ -431,7 +431,7 @@ SCH_SHEET* SCH_SEXPR_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema m_currentPath.push( m_path ); init( aSchematic, aProperties ); - if( aAppendToMe == NULL ) + if( aAppendToMe == nullptr ) { // Clean up any allocated memory if an exception occurs loading the schematic. std::unique_ptr newSheet = std::make_unique( aSchematic ); @@ -469,7 +469,7 @@ SCH_SHEET* SCH_SEXPR_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema void SCH_SEXPR_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) { - SCH_SCREEN* screen = NULL; + SCH_SCREEN* screen = nullptr; if( !aSheet->GetScreen() ) { @@ -576,7 +576,7 @@ void SCH_SEXPR_PLUGIN::LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet, int void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic, const PROPERTIES* aProperties ) { - wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET object." ); + wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." ); wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." ); LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values. @@ -599,8 +599,8 @@ void SCH_SEXPR_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEM void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet ) { - wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET* object." ); - wxCHECK_RET( m_schematic != NULL, "NULL SCHEMATIC* object." ); + wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." ); + wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." ); SCH_SCREEN* screen = aSheet->GetScreen(); @@ -1051,7 +1051,7 @@ void SCH_SEXPR_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel ) const wxImage* image = aBitmap->GetImage()->GetImageData(); - wxCHECK_RET( image != NULL, "wxImage* is NULL" ); + wxCHECK_RET( image != nullptr, "wxImage* is NULL" ); m_out->Print( aNestLevel, "(image (at %s %s)", FormatInternalUnits( aBitmap->GetPosition().x ).c_str(), @@ -1306,7 +1306,7 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel ) void SCH_SEXPR_PLUGIN::saveBusAlias( std::shared_ptr aAlias, int aNestLevel ) { - wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" ); + wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" ); wxString members; @@ -1434,17 +1434,17 @@ bool SCH_SEXPR_PLUGIN_CACHE::IsFileChanged() const LIB_SYMBOL* SCH_SEXPR_PLUGIN_CACHE::removeSymbol( LIB_SYMBOL* aSymbol ) { - wxCHECK_MSG( aSymbol != NULL, NULL, "NULL pointer cannot be removed from library." ); + wxCHECK_MSG( aSymbol != nullptr, nullptr, "NULL pointer cannot be removed from library." ); - LIB_SYMBOL* firstChild = NULL; + LIB_SYMBOL* firstChild = nullptr; LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbol->GetName() ); if( it == m_symbols.end() ) - return NULL; + return nullptr; // If the entry pointer doesn't match the name it is mapped to in the library, we // have done something terribly wrong. - wxCHECK_MSG( *it->second == aSymbol, NULL, + wxCHECK_MSG( *it->second == aSymbol, nullptr, "Pointer mismatch while attempting to remove alias entry <" + aSymbol->GetName() + "> from library cache <" + m_libFileName.GetName() + ">." ); @@ -1944,8 +1944,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFor } -void SCH_SEXPR_PLUGIN_CACHE::savePin( LIB_PIN* aPin, - OUTPUTFORMATTER& aFormatter, +void SCH_SEXPR_PLUGIN_CACHE::savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter, int aNestLevel ) { wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." ); @@ -1989,8 +1988,7 @@ void SCH_SEXPR_PLUGIN_CACHE::savePin( LIB_PIN* aPin, } -void SCH_SEXPR_PLUGIN_CACHE::savePolyLine( LIB_POLYLINE* aPolyLine, - OUTPUTFORMATTER& aFormatter, +void SCH_SEXPR_PLUGIN_CACHE::savePolyLine( LIB_POLYLINE* aPolyLine, OUTPUTFORMATTER& aFormatter, int aNestLevel ) { wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." ); diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index 583027a944..b9d01bb243 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -122,7 +122,7 @@ static bool is_eol( char c ) * @param aOutput - A pointer to a string pointer to the end of the comparison if not NULL. * @return true if \a aString was found starting at \a aLine. Otherwise false. */ -static bool strCompare( const char* aString, const char* aLine, const char** aOutput = NULL ) +static bool strCompare( const char* aString, const char* aLine, const char** aOutput = nullptr ) { size_t len = strlen( aString ); bool retv = ( strncasecmp( aLine, aString, len ) == 0 ) && @@ -159,7 +159,7 @@ static bool strCompare( const char* aString, const char* aLine, const char** aOu * @throw An #IO_ERROR on an unexpected end of line. * @throw A #PARSE_ERROR if the parsed token is not a valid integer. */ -static int parseInt( LINE_READER& aReader, const char* aLine, const char** aOutput = NULL ) +static int parseInt( LINE_READER& aReader, const char* aLine, const char** aOutput = nullptr ) { if( !*aLine ) SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aLine ); @@ -201,7 +201,7 @@ static int parseInt( LINE_READER& aReader, const char* aLine, const char** aOutp * @throw IO_ERROR on an unexpected end of line. * @throw PARSE_ERROR if the parsed token is not a valid integer. */ -static uint32_t parseHex( LINE_READER& aReader, const char* aLine, const char** aOutput = NULL ) +static uint32_t parseHex( LINE_READER& aReader, const char* aLine, const char** aOutput = nullptr ) { if( !*aLine ) SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aLine ); @@ -247,7 +247,7 @@ static uint32_t parseHex( LINE_READER& aReader, const char* aLine, const char** * @throw PARSE_ERROR if the parsed token is not a valid integer. */ static double parseDouble( LINE_READER& aReader, const char* aLine, - const char** aOutput = NULL ) + const char** aOutput = nullptr ) { if( !*aLine ) SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aLine ); @@ -288,7 +288,7 @@ static double parseDouble( LINE_READER& aReader, const char* aLine, * @throw PARSE_ERROR if the parsed token is not a single character token. */ static char parseChar( LINE_READER& aReader, const char* aCurrentToken, - const char** aNextToken = NULL ) + const char** aNextToken = nullptr ) { while( *aCurrentToken && isspace( *aCurrentToken ) ) aCurrentToken++; @@ -328,7 +328,7 @@ static char parseChar( LINE_READER& aReader, const char* aCurrentToken, * @throw PARSE_ERROR if the \a aCanBeEmpty is false and no string was parsed. */ static void parseUnquotedString( wxString& aString, LINE_READER& aReader, - const char* aCurrentToken, const char** aNextToken = NULL, + const char* aCurrentToken, const char** aNextToken = nullptr, bool aCanBeEmpty = false ) { if( !*aCurrentToken ) @@ -390,7 +390,7 @@ static void parseUnquotedString( wxString& aString, LINE_READER& aReader, * @throw PARSE_ERROR if the \a aCanBeEmpty is false and no string was parsed. */ static void parseQuotedString( wxString& aString, LINE_READER& aReader, - const char* aCurrentToken, const char** aNextToken = NULL, + const char* aCurrentToken, const char** aNextToken = nullptr, bool aCanBeEmpty = false ) { if( !*aCurrentToken ) @@ -589,7 +589,7 @@ SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN() : m_lastProgressLine( 0 ), m_lineCount( 0 ) { - init( NULL ); + init( nullptr ); } @@ -634,7 +634,7 @@ void SCH_LEGACY_PLUGIN::checkpoint() SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchematic, SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) { - wxASSERT( !aFileName || aSchematic != NULL ); + wxASSERT( !aFileName || aSchematic != nullptr ); LOCALE_IO toggle; // toggles on, then off, the C locale. SCH_SHEET* sheet; @@ -672,7 +672,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchem m_currentPath.push( m_path ); init( aSchematic, aProperties ); - if( aAppendToMe == NULL ) + if( aAppendToMe == nullptr ) { // Clean up any allocated memory if an exception occurs loading the schematic. std::unique_ptr newSheet = std::make_unique( aSchematic ); @@ -702,7 +702,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchem void SCH_LEGACY_PLUGIN::loadHierarchy( SCH_SHEET* aSheet ) { - SCH_SCREEN* screen = NULL; + SCH_SCREEN* screen = nullptr; if( !aSheet->GetScreen() ) { @@ -904,7 +904,7 @@ void SCH_LEGACY_PLUGIN::loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen ) void SCH_LEGACY_PLUGIN::loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen ) { - wxASSERT( aScreen != NULL ); + wxASSERT( aScreen != nullptr ); wxString buf; const char* line = aReader.Line(); @@ -941,7 +941,7 @@ void SCH_LEGACY_PLUGIN::loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScr aScreen->SetPageSettings( pageInfo ); - while( line != NULL ) + while( line != nullptr ) { buf.clear(); @@ -1037,7 +1037,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader ) const char* line = aReader.ReadLine(); - while( line != NULL ) + while( line != nullptr ) { if( strCompare( "S", line, &line ) ) // Sheet dimensions. { @@ -1090,7 +1090,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader ) sheetPin->SetText( text ); - if( line == NULL ) + if( line == nullptr ) THROW_IO_ERROR( _( "unexpected end of line" ) ); switch( parseChar( aReader, line, &line ) ) @@ -1128,7 +1128,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader ) } else if( strCompare( "$EndSheet", line ) ) { - sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); + sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); return sheet.release(); } @@ -1137,7 +1137,7 @@ SCH_SHEET* SCH_LEGACY_PLUGIN::loadSheet( LINE_READER& aReader ) SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line ); - return NULL; // Prevents compiler warning. Should never get here. + return nullptr; // Prevents compiler warning. Should never get here. } @@ -1147,11 +1147,11 @@ SCH_BITMAP* SCH_LEGACY_PLUGIN::loadBitmap( LINE_READER& aReader ) const char* line = aReader.Line(); - wxCHECK( strCompare( "$Bitmap", line, &line ), NULL ); + wxCHECK( strCompare( "$Bitmap", line, &line ), nullptr ); line = aReader.ReadLine(); - while( line != NULL ) + while( line != nullptr ) { if( strCompare( "Pos", line, &line ) ) { @@ -1213,7 +1213,7 @@ SCH_BITMAP* SCH_LEGACY_PLUGIN::loadBitmap( LINE_READER& aReader ) } } - if( line == NULL ) + if( line == nullptr ) THROW_IO_ERROR( _( "unexpected end of file" ) ); } else if( strCompare( "$EndBitmap", line ) ) @@ -1232,7 +1232,7 @@ SCH_JUNCTION* SCH_LEGACY_PLUGIN::loadJunction( LINE_READER& aReader ) const char* line = aReader.Line(); - wxCHECK( strCompare( "Connection", line, &line ), NULL ); + wxCHECK( strCompare( "Connection", line, &line ), nullptr ); wxString name; @@ -1254,7 +1254,7 @@ SCH_NO_CONNECT* SCH_LEGACY_PLUGIN::loadNoConnect( LINE_READER& aReader ) const char* line = aReader.Line(); - wxCHECK( strCompare( "NoConn", line, &line ), NULL ); + wxCHECK( strCompare( "NoConn", line, &line ), nullptr ); wxString name; @@ -1276,7 +1276,7 @@ SCH_LINE* SCH_LEGACY_PLUGIN::loadWire( LINE_READER& aReader ) const char* line = aReader.Line(); - wxCHECK( strCompare( "Wire", line, &line ), NULL ); + wxCHECK( strCompare( "Wire", line, &line ), nullptr ); if( strCompare( "Wire", line, &line ) ) wire->SetLayer( LAYER_WIRE ); @@ -1372,7 +1372,7 @@ SCH_BUS_ENTRY_BASE* SCH_LEGACY_PLUGIN::loadBusEntry( LINE_READER& aReader ) { const char* line = aReader.Line(); - wxCHECK( strCompare( "Entry", line, &line ), NULL ); + wxCHECK( strCompare( "Entry", line, &line ), nullptr ); std::unique_ptr busEntry; @@ -1428,7 +1428,7 @@ SCH_TEXT* SCH_LEGACY_PLUGIN::loadText( LINE_READER& aReader ) { const char* line = aReader.Line(); - wxCHECK( strCompare( "Text", line, &line ), NULL ); + wxCHECK( strCompare( "Text", line, &line ), nullptr ); std::unique_ptr text; @@ -1545,13 +1545,13 @@ SCH_SYMBOL* SCH_LEGACY_PLUGIN::loadSymbol( LINE_READER& aReader ) { const char* line = aReader.Line(); - wxCHECK( strCompare( "$Comp", line, &line ), NULL ); + wxCHECK( strCompare( "$Comp", line, &line ), nullptr ); std::unique_ptr symbol = std::make_unique(); line = aReader.ReadLine(); - while( line != NULL ) + while( line != nullptr ) { if( strCompare( "L", line, &line ) ) { @@ -1853,7 +1853,7 @@ SCH_SYMBOL* SCH_LEGACY_PLUGIN::loadSymbol( LINE_READER& aReader ) SCH_PARSE_ERROR( "invalid symbol line", aReader, line ); - return NULL; // Prevents compiler warning. Should never get here. + return nullptr; // Prevents compiler warning. Should never get here. } @@ -1863,7 +1863,7 @@ std::shared_ptr SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader auto busAlias = std::make_shared( aScreen ); const char* line = aReader.Line(); - wxCHECK( strCompare( "BusAlias", line, &line ), NULL ); + wxCHECK( strCompare( "BusAlias", line, &line ), nullptr ); wxString buf; parseUnquotedString( buf, aReader, line, &line ); @@ -1886,7 +1886,7 @@ std::shared_ptr SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic, const PROPERTIES* aProperties ) { - wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET object." ); + wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." ); wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." ); LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values. @@ -1909,8 +1909,8 @@ void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHE void SCH_LEGACY_PLUGIN::Format( SCH_SHEET* aSheet ) { - wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET* object." ); - wxCHECK_RET( m_schematic != NULL, "NULL SCHEMATIC* object." ); + wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." ); + wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." ); SCH_SCREEN* screen = aSheet->GetScreen(); @@ -2195,11 +2195,11 @@ void SCH_LEGACY_PLUGIN::saveField( SCH_FIELD* aField ) void SCH_LEGACY_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap ) { - wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" ); + wxCHECK_RET( aBitmap != nullptr, "SCH_BITMAP* is NULL" ); const wxImage* image = aBitmap->GetImage()->GetImageData(); - wxCHECK_RET( image != NULL, "wxImage* is NULL" ); + wxCHECK_RET( image != nullptr, "wxImage* is NULL" ); m_out->Print( 0, "$Bitmap\n" ); m_out->Print( 0, "Pos %-4d %-4d\n", @@ -2235,7 +2235,7 @@ void SCH_LEGACY_PLUGIN::saveBitmap( SCH_BITMAP* aBitmap ) void SCH_LEGACY_PLUGIN::saveSheet( SCH_SHEET* aSheet ) { - wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" ); + wxCHECK_RET( aSheet != nullptr, "SCH_SHEET* is NULL" ); m_out->Print( 0, "$Sheet\n" ); m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n", @@ -2299,7 +2299,7 @@ void SCH_LEGACY_PLUGIN::saveSheet( SCH_SHEET* aSheet ) void SCH_LEGACY_PLUGIN::saveJunction( SCH_JUNCTION* aJunction ) { - wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" ); + wxCHECK_RET( aJunction != nullptr, "SCH_JUNCTION* is NULL" ); m_out->Print( 0, "Connection ~ %-4d %-4d\n", Iu2Mils( aJunction->GetPosition().x ), @@ -2309,7 +2309,7 @@ void SCH_LEGACY_PLUGIN::saveJunction( SCH_JUNCTION* aJunction ) void SCH_LEGACY_PLUGIN::saveNoConnect( SCH_NO_CONNECT* aNoConnect ) { - wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" ); + wxCHECK_RET( aNoConnect != nullptr, "SCH_NOCONNECT* is NULL" ); m_out->Print( 0, "NoConn ~ %-4d %-4d\n", Iu2Mils( aNoConnect->GetPosition().x ), @@ -2319,7 +2319,7 @@ void SCH_LEGACY_PLUGIN::saveNoConnect( SCH_NO_CONNECT* aNoConnect ) void SCH_LEGACY_PLUGIN::saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry ) { - wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" ); + wxCHECK_RET( aBusEntry != nullptr, "SCH_BUS_ENTRY_BASE* is NULL" ); if( aBusEntry->GetLayer() == LAYER_WIRE ) m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n", @@ -2336,7 +2336,7 @@ void SCH_LEGACY_PLUGIN::saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry ) void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine ) { - wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" ); + wxCHECK_RET( aLine != nullptr, "SCH_LINE* is NULL" ); const char* layer = "Notes"; const char* width = "Line"; @@ -2375,7 +2375,7 @@ void SCH_LEGACY_PLUGIN::saveLine( SCH_LINE* aLine ) void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText ) { - wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" ); + wxCHECK_RET( aText != nullptr, "SCH_TEXT* is NULL" ); const char* italics = "~"; const char* textType = "Notes"; @@ -2448,7 +2448,7 @@ void SCH_LEGACY_PLUGIN::saveText( SCH_TEXT* aText ) void SCH_LEGACY_PLUGIN::saveBusAlias( std::shared_ptr aAlias ) { - wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" ); + wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" ); wxString members = boost::algorithm::join( aAlias->Members(), " " ); @@ -2523,17 +2523,17 @@ bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged() const LIB_SYMBOL* SCH_LEGACY_PLUGIN_CACHE::removeSymbol( LIB_SYMBOL* aSymbol ) { - wxCHECK_MSG( aSymbol != NULL, NULL, "NULL pointer cannot be removed from library." ); + wxCHECK_MSG( aSymbol != nullptr, nullptr, "NULL pointer cannot be removed from library." ); - LIB_SYMBOL* firstChild = NULL; + LIB_SYMBOL* firstChild = nullptr; LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbol->GetName() ); if( it == m_symbols.end() ) - return NULL; + return nullptr; // If the entry pointer doesn't match the name it is mapped to in the library, we // have done something terribly wrong. - wxCHECK_MSG( *it->second == aSymbol, NULL, + wxCHECK_MSG( *it->second == aSymbol, nullptr, "Pointer mismatch while attempting to remove alias entry <" + aSymbol->GetName() + "> from library cache <" + m_libFileName.GetName() + ">." ); @@ -2697,7 +2697,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadDocs() wxString text; wxString aliasName; wxFileName fn = m_libFileName; - LIB_SYMBOL* symbol = NULL;; + LIB_SYMBOL* symbol = nullptr;; fn.SetExt( DOC_EXT ); @@ -3275,7 +3275,7 @@ LIB_ARC* SCH_LEGACY_PLUGIN_CACHE::loadArc( std::unique_ptr& aSymbol, { const char* line = aReader.Line(); - wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" ); + wxCHECK_MSG( strCompare( "A", line, &line ), nullptr, "Invalid LIB_ARC definition" ); LIB_ARC* arc = new LIB_ARC( aSymbol.get() ); @@ -3341,7 +3341,7 @@ LIB_CIRCLE* SCH_LEGACY_PLUGIN_CACHE::loadCircle( std::unique_ptr& aS { const char* line = aReader.Line(); - wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" ); + wxCHECK_MSG( strCompare( "C", line, &line ), nullptr, "Invalid LIB_CIRCLE definition" ); LIB_CIRCLE* circle = new LIB_CIRCLE( aSymbol.get() ); @@ -3370,7 +3370,7 @@ LIB_TEXT* SCH_LEGACY_PLUGIN_CACHE::loadText( std::unique_ptr& aSymbo { const char* line = aReader.Line(); - wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" ); + wxCHECK_MSG( strCompare( "T", line, &line ), nullptr, "Invalid LIB_TEXT definition" ); LIB_TEXT* text = new LIB_TEXT( aSymbol.get() ); @@ -3461,7 +3461,7 @@ LIB_RECTANGLE* SCH_LEGACY_PLUGIN_CACHE::loadRectangle( std::unique_ptr& aSymbol, { const char* line = aReader.Line(); - wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" ); + wxCHECK_MSG( strCompare( "X", line, &line ), nullptr, "Invalid LIB_PIN definition" ); wxString name; wxString number; @@ -3683,7 +3683,7 @@ LIB_POLYLINE* SCH_LEGACY_PLUGIN_CACHE::loadPolyLine( std::unique_ptr { const char* line = aReader.Line(); - wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" ); + wxCHECK_MSG( strCompare( "P", line, &line ), nullptr, "Invalid LIB_POLYLINE definition" ); LIB_POLYLINE* polyLine = new LIB_POLYLINE( aSymbol.get() ); @@ -3714,7 +3714,7 @@ LIB_BEZIER* SCH_LEGACY_PLUGIN_CACHE::loadBezier( std::unique_ptr& aS { const char* line = aReader.Line(); - wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" ); + wxCHECK_MSG( strCompare( "B", line, &line ), nullptr, "Invalid LIB_BEZIER definition" ); LIB_BEZIER* bezier = new LIB_BEZIER( aSymbol.get() ); diff --git a/eeschema/sch_reference_list.h b/eeschema/sch_reference_list.h index 98cbf17610..ef2a849a31 100644 --- a/eeschema/sch_reference_list.h +++ b/eeschema/sch_reference_list.h @@ -48,8 +48,8 @@ public: SCH_REFERENCE() : m_sheetPath() { - m_rootSymbol = NULL; - m_libPart = NULL; + m_rootSymbol = nullptr; + m_libPart = nullptr; m_unit = 0; m_isNew = false; m_numRef = 0; diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 1055ea1a57..24e15f58b2 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -371,7 +371,7 @@ std::set SCH_SCREEN::MarkConnections( SCH_LINE* aSegment ) SCH_LINE* line = static_cast( item ); if( ( test_item->IsEndPoint( line->GetStartPoint() ) - && !GetPin( line->GetStartPoint(), NULL, true ) ) + && !GetPin( line->GetStartPoint(), nullptr, true ) ) || ( test_item->IsEndPoint( line->GetEndPoint() ) && !GetPin( line->GetEndPoint(), nullptr, true ) ) ) { @@ -509,7 +509,7 @@ bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer ) const if( GetItem( aPosition, 1, SCH_JUNCTION_T ) ) return true; - if( GetPin( aPosition, NULL, true ) ) + if( GetPin( aPosition, nullptr, true ) ) return true; if( GetWire( aPosition ) ) @@ -832,8 +832,8 @@ void SCH_SCREEN::ClearDrawingState() LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_SYMBOL** aSymbol, bool aEndPointOnly ) const { - SCH_SYMBOL* candidate = NULL; - LIB_PIN* pin = NULL; + SCH_SYMBOL* candidate = nullptr; + LIB_PIN* pin = nullptr; for( SCH_ITEM* item : Items().Overlapping( SCH_SYMBOL_T, aPosition ) ) { @@ -841,7 +841,7 @@ LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_SYMBOL** aSymbol, if( aEndPointOnly ) { - pin = NULL; + pin = nullptr; if( !candidate->GetLibSymbolRef() ) continue; @@ -1021,7 +1021,7 @@ SCH_LINE* SCH_SCREEN::GetLine( const wxPoint& aPosition, int aAccuracy, int aLay } } - return NULL; + return nullptr; } @@ -1044,7 +1044,7 @@ SCH_TEXT* SCH_SCREEN::GetLabel( const wxPoint& aPosition, int aAccuracy ) const } } - return NULL; + return nullptr; } @@ -1105,7 +1105,7 @@ SCH_SCREEN* SCH_SCREENS::GetFirst() if( m_screens.size() > 0 ) return m_screens[0]; - return NULL; + return nullptr; } @@ -1123,7 +1123,7 @@ SCH_SCREEN* SCH_SCREENS::GetScreen( unsigned int aIndex ) const if( aIndex < m_screens.size() ) return m_screens[ aIndex ]; - return NULL; + return nullptr; } @@ -1132,13 +1132,13 @@ SCH_SHEET* SCH_SCREENS::GetSheet( unsigned int aIndex ) const if( aIndex < m_sheets.size() ) return m_sheets[ aIndex ]; - return NULL; + return nullptr; } void SCH_SCREENS::addScreenToList( SCH_SCREEN* aScreen, SCH_SHEET* aSheet ) { - if( aScreen == NULL ) + if( aScreen == nullptr ) return; for( const SCH_SCREEN* screen : m_screens ) diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 979bc0c376..e01c7a8190 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -77,7 +77,7 @@ SCH_SHEET::SCH_SHEET( EDA_ITEM* aParent, const wxPoint& pos ) : m_layer = LAYER_SHEET; m_pos = pos; m_size = wxSize( Mils2iu( MIN_SHEET_WIDTH ), Mils2iu( MIN_SHEET_HEIGHT ) ); - m_screen = NULL; + m_screen = nullptr; for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i ) { @@ -159,14 +159,14 @@ void SCH_SHEET::SetScreen( SCH_SCREEN* aScreen ) if( aScreen == m_screen ) return; - if( m_screen != NULL ) + if( m_screen != nullptr ) { m_screen->DecRefCount(); if( m_screen->GetRefCount() == 0 ) { delete m_screen; - m_screen = NULL; + m_screen = nullptr; } } @@ -179,7 +179,7 @@ void SCH_SHEET::SetScreen( SCH_SCREEN* aScreen ) int SCH_SHEET::GetScreenCount() const { - if( m_screen == NULL ) + if( m_screen == nullptr ) return 0; return m_screen->GetRefCount(); @@ -299,7 +299,7 @@ void SCH_SHEET::SwapData( SCH_ITEM* aItem ) void SCH_SHEET::AddPin( SCH_SHEET_PIN* aSheetPin ) { - wxASSERT( aSheetPin != NULL ); + wxASSERT( aSheetPin != nullptr ); wxASSERT( aSheetPin->Type() == SCH_SHEET_PIN_T ); aSheetPin->SetParent( this ); @@ -310,7 +310,7 @@ void SCH_SHEET::AddPin( SCH_SHEET_PIN* aSheetPin ) void SCH_SHEET::RemovePin( const SCH_SHEET_PIN* aSheetPin ) { - wxASSERT( aSheetPin != NULL ); + wxASSERT( aSheetPin != nullptr ); wxASSERT( aSheetPin->Type() == SCH_SHEET_PIN_T ); for( auto i = m_pins.begin(); i < m_pins.end(); ++i ) @@ -476,7 +476,7 @@ void SCH_SHEET::CleanupSheet() while( i != m_pins.end() ) { /* Search the schematic for a hierarchical label corresponding to this sheet label. */ - const SCH_HIERLABEL* HLabel = NULL; + const SCH_HIERLABEL* HLabel = nullptr; for( SCH_ITEM* aItem : m_screen->Items().OfType( SCH_HIER_LABEL_T ) ) { @@ -487,7 +487,7 @@ void SCH_SHEET::CleanupSheet() } } - if( HLabel == NULL ) // Hlabel not found: delete sheet label. + if( HLabel == nullptr ) // Hlabel not found: delete sheet label. i = m_pins.erase( i ); else ++i; @@ -503,7 +503,7 @@ SCH_SHEET_PIN* SCH_SHEET::GetPin( const wxPoint& aPosition ) return pin; } - return NULL; + return nullptr; } @@ -757,7 +757,7 @@ void SCH_SHEET::Rotate( const wxPoint& aCenter ) if( m_fieldsAutoplaced == FIELDS_AUTOPLACED_AUTO ) { - AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); + AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); } else { @@ -810,7 +810,7 @@ void SCH_SHEET::Resize( const wxSize& aSize ) // Move the fields if we're in autoplace mode if( m_fieldsAutoplaced == FIELDS_AUTOPLACED_AUTO ) - AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); + AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); // Move the sheet labels according to the new sheet size. for( SCH_SHEET_PIN* sheetPin : m_pins ) @@ -883,7 +883,7 @@ SEARCH_RESULT SCH_SHEET::Visit( INSPECTOR aInspector, void* testData, const KICA // If caller wants to inspect my type if( stype == SCH_LOCATE_ANY_T || stype == Type() ) { - if( SEARCH_RESULT::QUIT == aInspector( this, NULL ) ) + if( SEARCH_RESULT::QUIT == aInspector( this, nullptr ) ) return SEARCH_RESULT::QUIT; } diff --git a/eeschema/sch_sheet_pin.cpp b/eeschema/sch_sheet_pin.cpp index c5096fb0bb..8a226bc9ad 100644 --- a/eeschema/sch_sheet_pin.cpp +++ b/eeschema/sch_sheet_pin.cpp @@ -75,8 +75,8 @@ void SCH_SHEET_PIN::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOff void SCH_SHEET_PIN::SwapData( SCH_ITEM* aItem ) { wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T, - wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ), - aItem->GetClass() ) ); + wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ), + aItem->GetClass() ) ); SCH_SHEET_PIN* pin = ( SCH_SHEET_PIN* ) aItem; SCH_TEXT::SwapData( (SCH_TEXT*) pin ); @@ -157,7 +157,7 @@ void SCH_SHEET_PIN::ConstrainOnEdge( wxPoint Pos ) { SCH_SHEET* sheet = GetParent(); - if( sheet == NULL ) + if( sheet == nullptr ) return; int leftSide = sheet->m_pos.x; diff --git a/eeschema/sch_sheet_pin.h b/eeschema/sch_sheet_pin.h index fba63fd15c..335ce37a6e 100644 --- a/eeschema/sch_sheet_pin.h +++ b/eeschema/sch_sheet_pin.h @@ -159,7 +159,7 @@ public: return SCH_ITEM::Matches( GetText(), aSearchData ); } - bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override + bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = nullptr ) override { return EDA_TEXT::Replace( aSearchData ); } diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 68264c426c..5b38edf2bb 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -103,7 +103,7 @@ SCH_SYMBOL::SCH_SYMBOL( const wxPoint& aPos, SCH_ITEM* aParent ) : SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId, const SCH_SHEET_PATH* aSheet, int unit, int convert, const wxPoint& pos ) : - SCH_ITEM( NULL, SCH_SYMBOL_T ) + SCH_ITEM( nullptr, SCH_SYMBOL_T ) { Init( pos ); @@ -741,7 +741,7 @@ SCH_FIELD* SCH_SYMBOL::FindField( const wxString& aFieldName, bool aIncludeDefau return &m_fields[i]; } - return NULL; + return nullptr; } @@ -881,7 +881,7 @@ std::vector SCH_SYMBOL::GetPins( const SCH_SHEET_PATH* aSheet ) const void SCH_SYMBOL::SwapData( SCH_ITEM* aItem ) { - wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_SYMBOL_T), + wxCHECK_RET( (aItem != nullptr) && (aItem->Type() == SCH_SYMBOL_T), wxT( "Cannot swap data with invalid symbol." ) ); SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem; @@ -1570,7 +1570,7 @@ bool SCH_SYMBOL::UpdateDanglingState( std::vector& aItemList, wxPoint SCH_SYMBOL::GetPinPhysicalPosition( const LIB_PIN* Pin ) const { - wxCHECK_MSG( Pin != NULL && Pin->Type() == LIB_PIN_T, wxPoint( 0, 0 ), + wxCHECK_MSG( Pin != nullptr && Pin->Type() == LIB_PIN_T, wxPoint( 0, 0 ), wxT( "Cannot get physical position of pin." ) ); return m_transform.TransformCoordinate( Pin->GetPosition() ) + m_pos; @@ -1611,7 +1611,7 @@ LIB_ITEM* SCH_SYMBOL::GetDrawItem( const wxPoint& aPosition, KICAD_T aType ) return m_part->LocateDrawItem( m_unit, m_convert, aType, libPosition, m_transform ); } - return NULL; + return nullptr; } diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index f32cf5ef8f..a306c932e2 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -78,7 +78,7 @@ extern std::string toUTFTildaText( const wxString& txt ); class SCH_SYMBOL : public SCH_ITEM { public: - SCH_SYMBOL( const wxPoint& pos = wxPoint( 0, 0 ), SCH_ITEM* aParent = NULL ); + SCH_SYMBOL( const wxPoint& pos = wxPoint( 0, 0 ), SCH_ITEM* aParent = nullptr ); /** * Create schematic symbol from library symbol object. diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index d636a3e8f0..5739d57e52 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -87,6 +87,7 @@ bool IncrementLabelMember( wxString& name, int aIncrement ) return true; } } + return false; } @@ -200,7 +201,7 @@ LABEL_SPIN_STYLE LABEL_SPIN_STYLE::MirrorY() SCH_TEXT::SCH_TEXT( const wxPoint& pos, const wxString& text, KICAD_T aType ) : - SCH_ITEM( NULL, aType ), + SCH_ITEM( nullptr, aType ), EDA_TEXT( text ), m_shape( PINSHEETLABEL_SHAPE::PS_INPUT ), m_isDangling( false ), @@ -792,6 +793,7 @@ void SCH_TEXT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList ) } } + #if defined(DEBUG) void SCH_TEXT::Show( int nestLevel, std::ostream& os ) const @@ -969,7 +971,7 @@ SEARCH_RESULT SCH_GLOBALLABEL::Visit( INSPECTOR aInspector, void* testData, // If caller wants to inspect my type if( stype == SCH_LOCATE_ANY_T || stype == Type() ) { - if( SEARCH_RESULT::QUIT == aInspector( this, NULL ) ) + if( SEARCH_RESULT::QUIT == aInspector( this, nullptr ) ) return SEARCH_RESULT::QUIT; } diff --git a/eeschema/sch_validators.h b/eeschema/sch_validators.h index a858a3ff6d..b59d81f4e0 100644 --- a/eeschema/sch_validators.h +++ b/eeschema/sch_validators.h @@ -51,7 +51,7 @@ class SCH_FIELD_VALIDATOR : public wxTextValidator { public: - SCH_FIELD_VALIDATOR( bool aIsLibEditor, int aFieldId, wxString* aValue = NULL ); + SCH_FIELD_VALIDATOR( bool aIsLibEditor, int aFieldId, wxString* aValue = nullptr ); SCH_FIELD_VALIDATOR( const SCH_FIELD_VALIDATOR& aValidator ); diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 4383a676ba..ba75a4fb1e 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -85,7 +85,7 @@ public: void OnSimStateChange( SPICE_SIMULATOR* aObject, SIM_STATE aNewState ) override { - wxCommandEvent* event = NULL; + wxCommandEvent* event = nullptr; switch( aNewState ) { @@ -339,8 +339,7 @@ void SIM_PLOT_FRAME::initWorkbook() void SIM_PLOT_FRAME::updateTitle() { - wxFileName filename = Prj().AbsolutePath( - m_simulator->Settings()->GetWorkbookFilename() ); + wxFileName filename = Prj().AbsolutePath( m_simulator->Settings()->GetWorkbookFilename() ); bool readOnly = false; bool unsaved = false; @@ -818,7 +817,7 @@ void SIM_PLOT_FRAME::updateSignalList() wxMemoryDC bmDC; const int isize = bmDC.GetCharHeight(); - if( m_signalsIconColorList == NULL ) + if( m_signalsIconColorList == nullptr ) m_signalsIconColorList = new wxImageList( isize, isize, false ); else m_signalsIconColorList->RemoveAll(); @@ -1068,6 +1067,7 @@ bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath ) return res; } + SIM_PLOT_TYPE SIM_PLOT_FRAME::getXAxisType( SIM_TYPE aType ) const { switch( aType ) @@ -1545,14 +1545,14 @@ void SIM_PLOT_FRAME::onShowNetlist( wxCommandEvent& event ) sizer->Add( text, 1, wxEXPAND ); SetSizer( sizer ); - Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( NETLIST_VIEW_DIALOG::onClose ), NULL, - this ); + Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( NETLIST_VIEW_DIALOG::onClose ), + nullptr, this ); finishDialogSettings(); } }; - if( m_schematicFrame == NULL || m_simulator == NULL ) + if( m_schematicFrame == nullptr || m_simulator == nullptr ) return; NETLIST_VIEW_DIALOG dlg( this, m_simulator->GetNetlist() ); @@ -1793,7 +1793,7 @@ SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU( const wxString& aSigna AddMenuItem( this, SHOW_CURSOR, _( "Show Cursor" ), KiBitmap( BITMAPS::pcb_target ) ); Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( SIGNAL_CONTEXT_MENU::onMenuEvent ), - NULL, this ); + nullptr, this ); } diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index 9add435747..ba1de261d7 100644 --- a/eeschema/sim/sim_plot_panel.cpp +++ b/eeschema/sim/sim_plot_panel.cpp @@ -452,7 +452,7 @@ void SIM_PLOT_PANEL::UpdateTraceStyle( TRACE* trace ) bool SIM_PLOT_PANEL::addTrace( const wxString& aName, int aPoints, const double* aX, const double* aY, SIM_PLOT_TYPE aType, const wxString& aParam ) { - TRACE* trace = NULL; + TRACE* trace = nullptr; wxString name = aName; if( aType & SPT_AC_MAG ) @@ -601,7 +601,7 @@ void SIM_PLOT_PANEL::EnableCursor( const wxString& aName, bool aEnable ) else { CURSOR* c = t->GetCursor(); - t->SetCursor( NULL ); + t->SetCursor( nullptr ); m_plotWin->DelLayer( c, true ); } diff --git a/eeschema/sim/sim_plot_panel.h b/eeschema/sim/sim_plot_panel.h index a8d950f0a1..7406502b92 100644 --- a/eeschema/sim/sim_plot_panel.h +++ b/eeschema/sim/sim_plot_panel.h @@ -219,7 +219,7 @@ public: { auto trace = m_traces.find( aName ); - return trace == m_traces.end() ? NULL : trace->second; + return trace == m_traces.end() ? nullptr : trace->second; } void ShowGrid( bool aEnable ) @@ -270,10 +270,10 @@ public: ///< Returns true if the trace has cursor shown. bool HasCursorEnabled( const wxString& aName ) const; - ///< Toggles cursor for a particular trace. + ///< Toggle cursor for a particular trace. void EnableCursor( const wxString& aName, bool aEnable ); - ///< Resets scale ranges to fit the current traces + ///< Reset scale ranges to fit the current traces. void ResetScales(); ///< Update trace line style diff --git a/eeschema/symbol_editor/symbol_editor_import_export.cpp b/eeschema/symbol_editor/symbol_editor_import_export.cpp index e71ff0e70a..747a74da0c 100644 --- a/eeschema/symbol_editor/symbol_editor_import_export.cpp +++ b/eeschema/symbol_editor/symbol_editor_import_export.cpp @@ -129,7 +129,7 @@ void SYMBOL_EDIT_FRAME::ExportSymbol() fn = dlg.GetPath(); fn.MakeAbsolute(); - LIB_SYMBOL* old_symbol = NULL; + LIB_SYMBOL* old_symbol = nullptr; SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() ); SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( pluginType ) ); diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index dd54fd7d4f..643a17fc16 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -126,7 +126,7 @@ public: * a row is not found in this table. No ownership is * taken of aFallBackTable. */ - SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable = NULL ); + SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable = nullptr ); /** * Return an SYMBOL_LIB_TABLE_ROW if \a aNickName is found in this table or in any chained diff --git a/eeschema/symbol_library.h b/eeschema/symbol_library.h index 4f75601f8f..53abf8c1db 100644 --- a/eeschema/symbol_library.h +++ b/eeschema/symbol_library.h @@ -253,7 +253,7 @@ public: * Save or load the names of the currently configured symbol libraries (without paths). */ static void LibNamesAndPaths( PROJECT* aProject, bool doSave, - wxString* aPaths, wxArrayString* aNames=NULL ); + wxString* aPaths, wxArrayString* aNames = nullptr ); /** * Return the name of the cache library after potentially fixing it from diff --git a/eeschema/symbol_viewer_frame.cpp b/eeschema/symbol_viewer_frame.cpp index 0135f1fa3c..55bae28852 100644 --- a/eeschema/symbol_viewer_frame.cpp +++ b/eeschema/symbol_viewer_frame.cpp @@ -154,10 +154,10 @@ SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAM ReCreateMenuBar(); m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize, - 0, NULL, wxLB_HSCROLL | wxNO_BORDER ); + 0, nullptr, wxLB_HSCROLL | wxNO_BORDER ); m_symbolList = new wxListBox( this, ID_LIBVIEW_SYM_LIST, wxDefaultPosition, wxDefaultSize, - 0, NULL, wxLB_HSCROLL | wxNO_BORDER ); + 0, nullptr, wxLB_HSCROLL | wxNO_BORDER ); if( aLibraryName.empty() ) { @@ -178,13 +178,15 @@ SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAM m_auimgr.SetManagedWindow( this ); // Manage main toolbar - m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) ); - m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) ); + m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer( 6 ) ); + m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ) + .Bottom().Layer( 6 ) ); m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3) .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) ); m_auimgr.AddPane( m_symbolList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1) - .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_symbolListWidth, -1 ) ); + .CaptionVisible( false ).MinSize( 80, -1 ) + .BestSize( m_symbolListWidth, -1 ) ); m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() ); @@ -208,7 +210,7 @@ SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAM double max_size_x = Millimeter2iu( 450 ); double max_size_y = Millimeter2iu( 450 ); BOX2D bbox; - bbox.SetOrigin( -max_size_x /2, -max_size_y/2 ); + bbox.SetOrigin( -max_size_x / 2, -max_size_y / 2 ); bbox.SetSize( max_size_x, max_size_y ); GetCanvas()->GetView()->SetBoundary( bbox ); GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true ); @@ -466,7 +468,9 @@ void SYMBOL_VIEWER_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent ) m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) ); } else if( m_unitChoice->GetCount() ) + { m_unitChoice->Clear(); + } } @@ -544,7 +548,7 @@ bool SYMBOL_VIEWER_FRAME::ReCreateLibList() bool SYMBOL_VIEWER_FRAME::ReCreateSymbolList() { - if( m_symbolList == NULL ) + if( m_symbolList == nullptr ) return false; wxArrayString aliasNames; diff --git a/eeschema/tools/assign_footprints.cpp b/eeschema/tools/assign_footprints.cpp index 441373c6c1..aaa927e605 100644 --- a/eeschema/tools/assign_footprints.cpp +++ b/eeschema/tools/assign_footprints.cpp @@ -129,7 +129,7 @@ bool SCH_EDITOR_CONTROL::processCmpToFootprintLinkFile( const wxString& aFullFil FILE* cmpFile = wxFopen( aFullFilename, wxT( "rt" ) ); - if( cmpFile == NULL ) + if( cmpFile == nullptr ) return false; // cmpFileReader dtor will close cmpFile diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp index 6dbfae6473..6f6cb2cff4 100644 --- a/eeschema/tools/ee_grid_helper.cpp +++ b/eeschema/tools/ee_grid_helper.cpp @@ -74,7 +74,7 @@ VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, int aLayer, ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, aLayer ); ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, aLayer ); ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, aLayer ); - ANCHOR* best = NULL; + ANCHOR* best = nullptr; double minDist = std::numeric_limits::max(); if( nearestOrigin ) @@ -298,14 +298,16 @@ void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, b { VECTOR2I possible( line->GetStartPoint().x, pt.y ); - if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), 0 ) ) + if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), + 0 ) ) addAnchor( possible, SNAPPABLE | VERTICAL, aItem ); } else if( line->GetStartPoint().y == line->GetEndPoint().y ) { VECTOR2I possible( pt.x, line->GetStartPoint().y ); - if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), 0 ) ) + if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), + 0 ) ) addAnchor( possible, SNAPPABLE | HORIZONTAL, aItem ); } @@ -317,7 +319,7 @@ EE_GRID_HELPER::ANCHOR* EE_GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int int aMatchLayer ) { double minDist = std::numeric_limits::max(); - ANCHOR* best = NULL; + ANCHOR* best = nullptr; for( ANCHOR& a : m_anchors ) { diff --git a/eeschema/tools/ee_point_editor.cpp b/eeschema/tools/ee_point_editor.cpp index 6310ee72a8..a6421585cf 100644 --- a/eeschema/tools/ee_point_editor.cpp +++ b/eeschema/tools/ee_point_editor.cpp @@ -580,7 +580,7 @@ void EE_POINT_EDITOR::updateParentItem() const // Update the fields if we're in autoplace mode if( sheet->GetFieldsAutoplaced() == FIELDS_AUTOPLACED_AUTO ) - sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); + sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); // Keep sheet pins attached to edges: for( SCH_SHEET_PIN* pin : sheet->GetPins() ) diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 47ca2e5689..ba2b26419f 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -90,7 +90,7 @@ bool SCH_DRAWING_TOOLS::Init() EDA_RECT SCH_DRAWING_TOOLS::GetCanvasFreeAreaPixels() { - // calculate thearea of the canvas in pixels that create no autopan when + // calculate the area of the canvas in pixels that create no autopan when // is inside this area the mouse cursor wxSize canvas_size = m_frame->GetCanvas()->GetSize(); EDA_RECT canvas_area( wxPoint( 0, 0 ), canvas_size ); @@ -256,7 +256,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) controls->WarpCursor( controls->GetCursorPosition(), true ); else if( !canvas_area.Contains( wxPoint( newMousePos ) ) ) // The mouse is outside the canvas area, after closing the dialog, - // thus can creating autopan issues. Warp the mouse to the canvas centre + // thus can creating autopan issues. Warp the mouse to the canvas center controls->WarpCursor( canvas_area.Centre(), false ); LIB_SYMBOL* libSymbol = sel.LibId.IsValid() ? @@ -275,7 +275,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) else { if( m_frame->eeconfig()->m_AutoplaceFields.enable ) - symbol->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); + symbol->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); symbol->ClearEditFlags(); @@ -501,7 +501,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) controls->WarpCursor( controls->GetCursorPosition(), true ); else if( !canvas_area.Contains( wxPoint( newMousePos ) ) ) // The mouse is outside the canvas area, after closing the dialog, - // thus can creating autopan issues. Warp the mouse to the canvas centre + // thus can creating autopan issues. Warp the mouse to the canvas center controls->WarpCursor( canvas_area.Centre(), false ); cursorPos = controls->GetMousePosition( true ); @@ -1175,9 +1175,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) controls->SetCursorPosition( cursorPos, false ); } - - // ... and second click places: - else + else // ... and second click places: { item->ClearFlags( IS_MOVING ); m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), (SCH_ITEM*) item, @@ -1336,7 +1334,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) sheet = new SCH_SHEET( m_frame->GetCurrentSheet().Last(), static_cast( cursorPos ) ); sheet->SetFlags( IS_NEW | IS_RESIZING ); - sheet->SetScreen( NULL ); + sheet->SetScreen( nullptr ); sheet->SetBorderWidth( cfg->m_Drawing.default_line_thickness ); sheet->SetBorderColor( cfg->m_Drawing.default_sheet_border_color ); sheet->SetBackgroundColor( cfg->m_Drawing.default_sheet_background_color ); @@ -1376,7 +1374,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) if( m_frame->EditSheetProperties( static_cast( sheet ), &m_frame->GetCurrentSheet(), nullptr ) ) { - sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); + sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), sheet, false ); m_frame->UpdateHierarchyNavigator(); diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp index 6238c12eb2..969ab7352f 100644 --- a/eeschema/tools/symbol_editor_edit_tool.cpp +++ b/eeschema/tools/symbol_editor_edit_tool.cpp @@ -288,7 +288,7 @@ int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) wxString name = pin->GetName(); LIB_PIN* next_pin = symbol->GetNextPin(); - while( next_pin != NULL ) + while( next_pin != nullptr ) { pin = next_pin; next_pin = symbol->GetNextPin( pin ); @@ -468,7 +468,7 @@ int SYMBOL_EDITOR_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) void SYMBOL_EDITOR_EDIT_TOOL::editGraphicProperties( LIB_ITEM* aItem ) { - if( aItem == NULL ) + if( aItem == nullptr ) return; DIALOG_LIB_EDIT_DRAW_ITEM dlg( m_frame, aItem ); @@ -492,7 +492,7 @@ void SYMBOL_EDITOR_EDIT_TOOL::editGraphicProperties( LIB_ITEM* aItem ) void SYMBOL_EDITOR_EDIT_TOOL::editTextProperties( LIB_ITEM* aItem ) { - if ( ( aItem == NULL ) || ( aItem->Type() != LIB_TEXT_T ) ) + if ( ( aItem == nullptr ) || ( aItem->Type() != LIB_TEXT_T ) ) return; DIALOG_LIB_EDIT_TEXT dlg( m_frame, (LIB_TEXT*) aItem ); @@ -508,7 +508,7 @@ void SYMBOL_EDITOR_EDIT_TOOL::editTextProperties( LIB_ITEM* aItem ) void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField ) { - if( aField == NULL ) + if( aField == nullptr ) return; wxString caption; diff --git a/eeschema/transform.cpp b/eeschema/transform.cpp index a13dd5b857..f114a92ca1 100644 --- a/eeschema/transform.cpp +++ b/eeschema/transform.cpp @@ -1,8 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2010 Wayne Stambaugh - * Copyright (C) 2015-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2010 Wayne Stambaugh + * 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 @@ -53,10 +53,8 @@ EDA_RECT TRANSFORM::TransformCoordinate( const EDA_RECT& aRect ) const return rect; } -/* -* Calculate the Inverse mirror/rotation transform. -*/ -TRANSFORM TRANSFORM::InverseTransform( ) const + +TRANSFORM TRANSFORM::InverseTransform() const { int invx1; int invx2; @@ -64,9 +62,9 @@ TRANSFORM TRANSFORM::InverseTransform( ) const int invy2; /* Calculates the inverse matrix coeffs: - * for a matrix m{x1, x2, y1, y2} - * the inverse matrix is 1/(x1*y2 -x2*y1) m{y2,-x2,-y1,x1) - */ + * for a matrix m{x1, x2, y1, y2} + * the inverse matrix is 1/(x1*y2 -x2*y1) m{y2,-x2,-y1,x1) + */ int det = x1*y2 -x2*y1; // Is never null, because the inverse matrix exists invx1 = y2/det; invx2 = -x2/det; @@ -80,7 +78,7 @@ TRANSFORM TRANSFORM::InverseTransform( ) const bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const { - wxCHECK_MSG( aAngle1 != NULL && aAngle2 != NULL, false, + wxCHECK_MSG( aAngle1 != nullptr && aAngle2 != nullptr, false, wxT( "Cannot map NULL point angles." ) ); int Angle, Delta; @@ -88,6 +86,7 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const bool swap = false; Delta = *aAngle2 - *aAngle1; + if( Delta >= 1800 ) { *aAngle1 -= 1; @@ -110,6 +109,7 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const NORMALIZE_ANGLE_POS( *aAngle1 ); NORMALIZE_ANGLE_POS( *aAngle2 ); + if( *aAngle2 < *aAngle1 ) *aAngle2 += 3600; @@ -121,8 +121,10 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const NORMALIZE_ANGLE_POS( *aAngle1 ); NORMALIZE_ANGLE_POS( *aAngle2 ); + if( *aAngle2 < *aAngle1 ) *aAngle2 += 3600; + swap = true; } diff --git a/eeschema/widgets/pin_shape_combobox.h b/eeschema/widgets/pin_shape_combobox.h index 386e29a76c..5e8bcf67f1 100644 --- a/eeschema/widgets/pin_shape_combobox.h +++ b/eeschema/widgets/pin_shape_combobox.h @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Simon Richter + * 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 @@ -35,15 +36,15 @@ public: /// @todo C++11: replace with forwarder PinShapeComboBox( wxWindow* parent, - wxWindowID id = wxID_ANY, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, - const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxBitmapComboBoxNameStr ); + wxWindowID id = wxID_ANY, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, + const wxString choices[] = nullptr, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxBitmapComboBoxNameStr ); GRAPHIC_PINSHAPE GetPinShapeSelection(); void SetSelection( GRAPHIC_PINSHAPE aShape ); diff --git a/eeschema/widgets/pin_type_combobox.h b/eeschema/widgets/pin_type_combobox.h index 0e05be4fc3..b774eb4e9e 100644 --- a/eeschema/widgets/pin_type_combobox.h +++ b/eeschema/widgets/pin_type_combobox.h @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Simon Richter + * 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 @@ -36,15 +37,15 @@ public: /// @todo C++11: replace with forwarder PinTypeComboBox( wxWindow* parent, - wxWindowID id = wxID_ANY, - const wxString& value = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - int n = 0, - const wxString choices[] = NULL, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxBitmapComboBoxNameStr ); + wxWindowID id = wxID_ANY, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, + const wxString choices[] = nullptr, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxBitmapComboBoxNameStr ); ELECTRICAL_PINTYPE GetPinTypeSelection(); void SetSelection( ELECTRICAL_PINTYPE aType ); diff --git a/eeschema/widgets/symbol_preview_widget.cpp b/eeschema/widgets/symbol_preview_widget.cpp index 7de60ac242..650c107cd5 100644 --- a/eeschema/widgets/symbol_preview_widget.cpp +++ b/eeschema/widgets/symbol_preview_widget.cpp @@ -60,7 +60,7 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway, // Do not display the grid: the look is not good for a small canvas area. // But mainly, due to some strange bug I (JPC) was unable to fix, the grid creates - // strange artifacts on Windows when eeschema is run from Kicad manager (but not in + // strange artifacts on Windows when Eeschema is run from KiCad manager (but not in // stand alone...). m_preview->GetGAL()->SetGridVisibility( false ); @@ -105,7 +105,7 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway, SetSizer( m_outerSizer ); Layout(); - Connect( wxEVT_SIZE, wxSizeEventHandler( SYMBOL_PREVIEW_WIDGET::onSize ), NULL, this ); + Connect( wxEVT_SIZE, wxSizeEventHandler( SYMBOL_PREVIEW_WIDGET::onSize ), nullptr, this ); } @@ -206,7 +206,7 @@ void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit, i view->Add( m_previewItem ); - // Get the symbole size, in internal units + // Get the symbol size, in internal units m_itemBBox = m_previewItem->GetUnitBoundingBox( settings->m_ShowUnit, settings->m_ShowConvert ); @@ -241,7 +241,9 @@ void SYMBOL_PREVIEW_WIDGET::DisplayPart( LIB_SYMBOL* aSymbol, int aUnit, int aCo m_previewItem = new LIB_SYMBOL( *aSymbol ); // For symbols having a De Morgan body style, use the first style - auto settings = static_cast( view->GetPainter()->GetSettings() ); + auto settings = + static_cast( view->GetPainter()->GetSettings() ); + // If unit isn't specified for a multi-unit part, pick the first. (Otherwise we'll // draw all of them.) settings->m_ShowUnit = ( m_previewItem->IsMulti() && aUnit == 0 ) ? 1 : aUnit; @@ -251,7 +253,7 @@ void SYMBOL_PREVIEW_WIDGET::DisplayPart( LIB_SYMBOL* aSymbol, int aUnit, int aCo view->Add( m_previewItem ); - // Get the symbole size, in internal units + // Get the symbol size, in internal units m_itemBBox = aSymbol->GetUnitBoundingBox( settings->m_ShowUnit, settings->m_ShowConvert ); // Calculate the draw scale to fit the drawing area diff --git a/eeschema/widgets/tuner_slider.cpp b/eeschema/widgets/tuner_slider.cpp index cc4660e5ca..15927b5f05 100644 --- a/eeschema/widgets/tuner_slider.cpp +++ b/eeschema/widgets/tuner_slider.cpp @@ -53,7 +53,7 @@ TUNER_SLIDER::TUNER_SLIDER( SIM_PLOT_FRAME* aFrame, wxWindow* aParent, SCH_SYMBO updateSlider(); m_simTimer.SetOwner( this ); - Connect( wxEVT_TIMER, wxTimerEventHandler( TUNER_SLIDER::onSimTimer ), NULL, this ); + Connect( wxEVT_TIMER, wxTimerEventHandler( TUNER_SLIDER::onSimTimer ), nullptr, this ); } @@ -201,7 +201,7 @@ void TUNER_SLIDER::onMinTextEnter( wxCommandEvent& event ) void TUNER_SLIDER::onSimTimer( wxTimerEvent& event ) { - if(m_changed) + if( m_changed ) { wxQueueEvent( m_frame, new wxCommandEvent( EVT_SIM_UPDATE ) ); m_changed = false; diff --git a/gerbview/X2_gerber_attributes.cpp b/gerbview/X2_gerber_attributes.cpp index bcbbb80f67..a58c057eb7 100644 --- a/gerbview/X2_gerber_attributes.cpp +++ b/gerbview/X2_gerber_attributes.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010-2014 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2014 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 @@ -45,33 +45,24 @@ #include #include -/* - * X2_ATTRIBUTE - * The attribute value consists of a number of substrings separated by a comma - */ X2_ATTRIBUTE::X2_ATTRIBUTE() { } + X2_ATTRIBUTE::~X2_ATTRIBUTE() { } -/* return the attribute name (for instance .FileFunction) - * which is given by TF command. - */ + const wxString& X2_ATTRIBUTE::GetAttribute() { return m_Prms.Item( 0 ); } -/* return a parameter - * aIdx = the index of the parameter - * aIdx = 0 is the parameter read after the TF function - * (the same as GetAttribute()) - */ -const wxString& X2_ATTRIBUTE::GetPrm( int aIdx) + +const wxString& X2_ATTRIBUTE::GetPrm( int aIdx ) { static const wxString dummy; @@ -81,15 +72,16 @@ const wxString& X2_ATTRIBUTE::GetPrm( int aIdx) return dummy; } -// Debug function: print using wxLogMessage the list of parameters + void X2_ATTRIBUTE::DbgListPrms() { - wxLogMessage( wxT("prms count %d"), GetPrmCount() ); + wxLogMessage( wxT( "prms count %d" ), GetPrmCount() ); for( int ii = 0; ii < GetPrmCount(); ii++ ) wxLogMessage( m_Prms.Item( ii ) ); } + bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char* &aText, int& aLineNum ) { @@ -136,7 +128,7 @@ bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, ch // end of current line, read another one. if( aBuffer && aFile ) { - if( fgets( aBuffer, aBuffSize, aFile ) == NULL ) + if( fgets( aBuffer, aBuffSize, aFile ) == nullptr ) { // end of file ok = false; @@ -147,27 +139,15 @@ bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, ch aText = aBuffer; } else + { return ok; + } } return ok; } -/* - * X2_ATTRIBUTE_FILEFUNCTION ( from %TF.FileFunction in Gerber file) - * Example file function: - * %TF.FileFunction,Copper,L1,Top*% - * - Type. Such as copper, solder mask etc. - * - Position. Specifies where the file appears in the PCB layer structure. - * Corresponding position substring: - * Copper layer: L1, L2, L3...to indicate the layer position followed by Top, Inr or - * Bot. L1 is always the top copper layer. E.g. L2,Inr. - * Extra layer, e.g. solder mask: Top or Bot - defines the attachment of the layer. - * Drill/rout layer: E.g. 1,4 - where 1 is the start and 4 is the end copper layer. The - * pair 1,4 defines the span of the drill/rout file - * Optional index. This can be used in instances where for example there are two solder - * masks on the same side. The index counts from the PCB surface outwards. - */ + X2_ATTRIBUTE_FILEFUNCTION::X2_ATTRIBUTE_FILEFUNCTION( X2_ATTRIBUTE& aAttributeBase ) : X2_ATTRIBUTE() { @@ -181,18 +161,21 @@ X2_ATTRIBUTE_FILEFUNCTION::X2_ATTRIBUTE_FILEFUNCTION( X2_ATTRIBUTE& aAttributeBa set_Z_Order(); } + const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetFileType() { // the type of layer (Copper, Soldermask ... ) return m_Prms.Item( 1 ); } + const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetBrdLayerId() { // the brd layer identifier: Ln (for Copper type) or Top, Bot return m_Prms.Item( 2 ); } + const wxString X2_ATTRIBUTE_FILEFUNCTION::GetDrillLayerPair() { // the layer pair identifiers, for drill files, i.e. @@ -201,6 +184,7 @@ const wxString X2_ATTRIBUTE_FILEFUNCTION::GetDrillLayerPair() return lpair; } + const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetBrdLayerSide() { if( IsCopper() ) @@ -250,11 +234,6 @@ bool X2_ATTRIBUTE_FILEFUNCTION::IsDrillFile() } -// Initialize the z order priority of the current file, from its attributes -// this priority is the order of layers from top to bottom to draw/display gerber images -// Stack up is( from external copper layer to external) -// copper, then solder paste, then solder mask, then silk screen. -// and global stackup is Front (top) layers then internal copper layers then Back (bottom) layers void X2_ATTRIBUTE_FILEFUNCTION::set_Z_Order() { m_z_order = -100; // low level @@ -266,6 +245,7 @@ void X2_ATTRIBUTE_FILEFUNCTION::set_Z_Order() m_z_order = 0; wxString num = GetBrdLayerId().Mid( 1 ); long lnum; + if( num.ToLong( &lnum ) ) m_z_sub_order = -lnum; } diff --git a/gerbview/am_primitive.cpp b/gerbview/am_primitive.cpp index 50e39afca4..5c598266dc 100644 --- a/gerbview/am_primitive.cpp +++ b/gerbview/am_primitive.cpp @@ -37,16 +37,16 @@ /** - * Function scaletoIU - * converts a distance given in floating point to our internal units + * Convert a distance given in floating point to our internal units. */ -extern int scaletoIU( double aCoord, bool isMetric ); // defined it rs274d_read_XY_and_IJ_coordinates.cpp +extern int scaletoIU( double aCoord, bool isMetric ); + /** - * Function mapPt - * translates a point from the aperture macro coordinate system to our + * Translate a point from the aperture macro coordinate system to our * deci-mils coordinate system. - * @return wxPoint - The GerbView coordinate system vector. + * + * @return The GerbView coordinate system vector. */ static wxPoint mapPt( double x, double y, bool isMetric ) { @@ -89,22 +89,28 @@ bool AM_PRIMITIVE::IsAMPrimitiveExposureOn( const GERBER_DRAW_ITEM* aParent ) co } } + // TODO(snh): Remove hard coded count const int seg_per_circle = 64; // Number of segments to approximate a circle -void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, - SHAPE_POLY_SET& aShapeBuffer, + +void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_SET& aShapeBuffer, wxPoint aShapePos ) { - #define TO_POLY_SHAPE { if( polybuffer.size() > 1 )\ - { aShapeBuffer.NewOutline(); \ - for( unsigned jj = 0; jj < polybuffer.size(); jj++ )\ - aShapeBuffer.Append( polybuffer[jj].x, polybuffer[jj].y );\ - aShapeBuffer.Append( polybuffer[0].x, polybuffer[0].y );}\ - } +#define TO_POLY_SHAPE \ + { \ + if( polybuffer.size() > 1 ) \ + { \ + aShapeBuffer.NewOutline(); \ + for( unsigned jj = 0; jj < polybuffer.size(); jj++ ) \ + aShapeBuffer.Append( polybuffer[jj].x, polybuffer[jj].y ); \ + aShapeBuffer.Append( polybuffer[0].x, polybuffer[0].y ); \ + } \ + } // Draw the primitive shape for flashed items. - static std::vector polybuffer; // create a static buffer to avoid a lot of memory reallocation + // Create a static buffer to avoid a lot of memory reallocation. + static std::vector polybuffer; polybuffer.clear(); wxPoint curPos = aShapePos; @@ -144,8 +150,8 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, } TO_POLY_SHAPE; + break; } - break; case AMP_LINE2: case AMP_LINE20: // Line with rectangle ends. (Width, start and end pos + rotation) @@ -178,8 +184,8 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, } TO_POLY_SHAPE; + break; } - break; case AMP_LINE_CENTER: { @@ -210,8 +216,8 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, } TO_POLY_SHAPE; + break; } - break; case AMP_LINE_LOWER_LEFT: { @@ -238,8 +244,8 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, } TO_POLY_SHAPE; + break; } - break; case AMP_THERMAL: { @@ -248,7 +254,8 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, * type (7), center.x , center.y, outside diam, inside diam, crosshair thickness, rotation * type is not stored in parameters list, so the first parameter is center.x * - * The thermal primitive is a ring (annulus) interrupted by four gaps. Exposure is always on. + * The thermal primitive is a ring (annulus) interrupted by four gaps. Exposure is always + * on. */ std::vector subshape_poly; curPos += mapPt( params[0].GetValue( tool ), params[1].GetValue( tool ), m_GerbMetric ); @@ -290,8 +297,9 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, /* Generated by an aperture macro declaration like: * "6,0,0,0.125,.01,0.01,3,0.003,0.150,0" - * type(6), pos.x, pos.y, diam, penwidth, gap, circlecount, crosshair thickness, crosshaire len, rotation - * type is not stored in parameters list, so the first parameter is pos.x + * type(6), pos.x, pos.y, diam, penwidth, gap, circlecount, crosshair thickness, + * crosshair len, rotation. The type is not stored in parameters list, so the first + * parameter is pos.x. */ int outerDiam = scaletoIU( params[2].GetValue( tool ), m_GerbMetric ); int penThickness = scaletoIU( params[3].GetValue( tool ), m_GerbMetric ); @@ -300,8 +308,9 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, // Draw circles: wxPoint center = aParent->GetABPosition( curPos ); + // adjust outerDiam by this on each nested circle - int diamAdjust = (gap + penThickness) * 2; + int diamAdjust = ( gap + penThickness ) * 2; for( int i = 0; i < numCircles; ++i, outerDiam -= diamAdjust ) { @@ -327,37 +336,42 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, ConvertShapeToPolygon( aParent, polybuffer ); rotation = params[8].GetValue( tool ) * 10.0; + for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) { // shape rotation: RotatePoint( &polybuffer[ii], -rotation ); + // Move to current position: polybuffer[ii] += curPos; polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] ); } TO_POLY_SHAPE; - } break; + } case AMP_OUTLINE: { /* Outline, Primitive Code 4 - * An outline primitive is an area enclosed by an n-point polygon defined by its start point and n - * subsequent points. The outline must be closed, i.e. the last point must be equal to the start - * point. There must be at least one subsequent point (to close the outline). - * The outline of the primitive is actually the contour (see 2.6) that consists of linear segments - * only, so it must conform to all the requirements described for contours. + * An outline primitive is an area enclosed by an n-point polygon defined by its start + * point and n + * subsequent points. The outline must be closed, i.e. the last point must be equal to + * the start point. There must be at least one subsequent point (to close the outline). + * The outline of the primitive is actually the contour (see 2.6) that consists of linear + * segments only, so it must conform to all the requirements described for contours. * Warning: Make no mistake: n is the number of subsequent points, being the number of * vertices of the outline or one less than the number of coordinate pairs. */ /* Generated by an aperture macro declaration like: * "4,1,3,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.0,-25" - * type(4), exposure, corners count, corner1.x, corner.1y, ..., corner1.x, corner.1y, rotation + * type(4), exposure, corners count, corner1.x, corner.1y, ..., corner1.x, corner.1y, + * rotation * type is not stored in parameters list, so the first parameter is exposure */ // params[0] is the exposure and params[1] is the corners count after the first corner int numCorners = (int) params[1].GetValue( tool ); + // the shape rotation is the last param of list, after corners int last_prm = params.size() - 1; rotation = params[last_prm].GetValue( tool ) * 10.0; @@ -383,12 +397,12 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, if( prm_idx >= last_prm ) break; } - // rotate polygon and move it to the actual position - // shape rotation: + + // rotate polygon and move it to the actual position shape rotation: for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) { RotatePoint( &polybuffer[ii], -rotation ); - } + } // Move to current position: for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) @@ -397,14 +411,14 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] ); } + break; TO_POLY_SHAPE; } - break; case AMP_POLYGON: /* Polygon, Primitive Code 5 - * A polygon primitive is a regular polygon defined by the number of vertices n, the center point - * and the diameter of the circumscribed circle + * A polygon primitive is a regular polygon defined by the number of vertices n, the + * center point and the diameter of the circumscribed circle */ /* Generated by an aperture macro declaration like: * "5,1,0.6,0,0,0.5,25" @@ -412,6 +426,7 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, * type is not stored in parameters list, so the first parameter is exposure */ curPos += mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); + // Creates the shape: ConvertShapeToPolygon( aParent, polybuffer ); @@ -439,16 +454,6 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, } -/** - * Function ConvertShapeToPolygon (virtual) - * convert a shape to an equivalent polygon. - * Arcs and circles are approximated by segments - * Useful when a shape is not a graphic primitive (shape with hole, - * rotated shape ... ) and cannot be easily drawn. - * note for some schapes conbining circles and solid lines (rectangles), only rectangles are converted - * because circles are very easy to draw (no rotation problem) so convert them in polygons, - * and draw them as polygons is not a good idea. - */ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, std::vector& aBuffer ) { @@ -465,12 +470,14 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, * type is not stored in parameters list, so the first parameter is exposure */ int radius = scaletoIU( params[1].GetValue( tool ), m_GerbMetric ) / 2; + // A circle primitive can have a 0 size (for instance when used in roundrect macro), // so skip it if( radius <= 0 ) break; - wxPoint center = mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); + wxPoint center = mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), + m_GerbMetric ); wxPoint corner; const int delta = 3600 / seg_per_circle; // rot angle in 0.1 degree @@ -482,8 +489,9 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, corner += center; aBuffer.push_back( corner ); } - } + break; + } case AMP_LINE2: case AMP_LINE20: // Line with rectangle ends. (Width, start and end pos + rotation) @@ -516,13 +524,16 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, RotatePoint( &aBuffer[ii], -angle ); aBuffer[ii] += start; } - } + break; + } case AMP_LINE_CENTER: { - wxPoint size = mapPt( params[1].GetValue( tool ), params[2].GetValue( tool ), m_GerbMetric ); - wxPoint pos = mapPt( params[3].GetValue( tool ), params[4].GetValue( tool ), m_GerbMetric ); + wxPoint size = mapPt( params[1].GetValue( tool ), params[2].GetValue( tool ), + m_GerbMetric ); + wxPoint pos = mapPt( params[3].GetValue( tool ), params[4].GetValue( tool ), + m_GerbMetric ); // Build poly: pos.x -= size.x / 2; @@ -534,14 +545,15 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, aBuffer.push_back( pos ); pos.y -= size.y; // lower right aBuffer.push_back( pos ); + break; } - break; case AMP_LINE_LOWER_LEFT: { - wxPoint size = mapPt( params[1].GetValue( tool ), params[2].GetValue( tool ), m_GerbMetric ); - wxPoint lowerLeft = mapPt( params[3].GetValue( tool ), params[4].GetValue( - tool ), m_GerbMetric ); + wxPoint size = mapPt( params[1].GetValue( tool ), params[2].GetValue( tool ), + m_GerbMetric ); + wxPoint lowerLeft = mapPt( params[3].GetValue( tool ), params[4].GetValue( tool ), + m_GerbMetric ); // Build poly: aBuffer.push_back( lowerLeft ); @@ -551,14 +563,15 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, aBuffer.push_back( lowerLeft ); lowerLeft.y -= size.y; // lower right aBuffer.push_back( lowerLeft ); + break; } - break; case AMP_THERMAL: { - // Only 1/4 of the full shape is built, because the other 3 shapes will be draw from this first - // rotated by 90, 180 and 270 deg. - // params = center.x (unused here), center.y (unused here), outside diam, inside diam, crosshair thickness + // Only 1/4 of the full shape is built, because the other 3 shapes will be draw from + // this first rotated by 90, 180 and 270 deg. + // params = center.x (unused here), center.y (unused here), outside diam, inside diam, + // crosshair thickness. int outerRadius = scaletoIU( params[2].GetValue( tool ), m_GerbMetric ) / 2; int innerRadius = scaletoIU( params[3].GetValue( tool ), m_GerbMetric ) / 2; @@ -569,12 +582,13 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, int halfthickness = scaletoIU( params[4].GetValue( tool ), m_GerbMetric ) / 2; double angle_start = RAD2DECIDEG( asin( (double) halfthickness / innerRadius ) ); - // Draw shape in the first cadrant (X and Y > 0) + // Draw shape in the first quadrant (X and Y > 0) wxPoint pos, startpos; // Inner arc startpos.x = innerRadius; double angle_end = 900 - angle_start; + for( double angle = angle_start; angle < angle_end; angle += 100 ) { pos = startpos; @@ -610,14 +624,15 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, } break; - case AMP_MOIRE: // A cross hair with n concentric circles. Only the cross is built as polygon - // because circles can be drawn easily + case AMP_MOIRE: { + // A cross hair with n concentric circles. Only the cross is built as + // polygon because circles can be drawn easily int crossHairThickness = scaletoIU( params[6].GetValue( tool ), m_GerbMetric ); int crossHairLength = scaletoIU( params[7].GetValue( tool ), m_GerbMetric ); // Create cross. First create 1/4 of the shape. - // Others point are the same, totated by 90, 180 and 270 deg + // Others point are the same, rotated by 90, 180 and 270 deg wxPoint pos( crossHairThickness / 2, crossHairLength / 2 ); aBuffer.push_back( pos ); pos.y = crossHairThickness / 2; @@ -637,8 +652,9 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, aBuffer.push_back( pos ); } } + + break; } - break; case AMP_OUTLINE: // already is a polygon. Do nothing @@ -648,19 +664,23 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, { int vertexcount = KiROUND( params[1].GetValue( tool ) ); int radius = scaletoIU( params[4].GetValue( tool ), m_GerbMetric ) / 2; + // rs274x said: vertex count = 3 ... 10, and the first corner is on the X axis if( vertexcount < 3 ) vertexcount = 3; + if( vertexcount > 10 ) vertexcount = 10; + for( int ii = 0; ii <= vertexcount; ii++ ) { wxPoint pos( radius, 0); RotatePoint( &pos, ii * 3600 / vertexcount ); aBuffer.push_back( pos ); } - } + break; + } case AMP_COMMENT: case AMP_UNKNOWN: @@ -669,16 +689,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, } } -/** GetShapeDim - * Calculate a value that can be used to evaluate the size of text - * when displaying the D-Code of an item - * due to the complexity of the shape of some primitives - * one cannot calculate the "size" of a shape (only abounding box) - * but here, the "dimension" of the shape is the diameter of the primitive - * or for lines the width of the line - * @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn - * @return a dimension, or -1 if no dim to calculate - */ + int AM_PRIMITIVE::GetShapeDim( const GERBER_DRAW_ITEM* aParent ) { int dim = -1; @@ -693,42 +704,47 @@ int AM_PRIMITIVE::GetShapeDim( const GERBER_DRAW_ITEM* aParent ) case AMP_LINE2: case AMP_LINE20: // Line with rectangle ends. (Width, start and end pos + rotation) - dim = scaletoIU( params[1].GetValue( tool ), m_GerbMetric ); // linne width - break; + dim = scaletoIU( params[1].GetValue( tool ), m_GerbMetric ); // line width + break; case AMP_LINE_CENTER: { - wxPoint size = mapPt( params[1].GetValue( tool ), params[2].GetValue( tool ), m_GerbMetric ); + wxPoint size = mapPt( params[1].GetValue( tool ), params[2].GetValue( tool ), + m_GerbMetric ); dim = std::min(size.x, size.y); + break; } - break; case AMP_LINE_LOWER_LEFT: { - wxPoint size = mapPt( params[1].GetValue( tool ), params[2].GetValue( tool ), m_GerbMetric ); + wxPoint size = mapPt( params[1].GetValue( tool ), params[2].GetValue( tool ), + m_GerbMetric ); dim = std::min(size.x, size.y); + break; } - break; case AMP_THERMAL: { - // Only 1/4 of the full shape is built, because the other 3 shapes will be draw from this first - // rotated by 90, 180 and 270 deg. - // params = center.x (unused here), center.y (unused here), outside diam, inside diam, crosshair thickness + // Only 1/4 of the full shape is built, because the other 3 shapes will be draw from + // this first rotated by 90, 180 and 270 deg. + // params = center.x (unused here), center.y (unused here), outside diam, inside diam, + // crosshair thickness. dim = scaletoIU( params[2].GetValue( tool ), m_GerbMetric ) / 2; // Outer diam + break; } - break; case AMP_MOIRE: // A cross hair with n concentric circles. dim = scaletoIU( params[7].GetValue( tool ), m_GerbMetric ); // = cross hair len break; case AMP_OUTLINE: // a free polygon : - // dim = min side of the bounding box (this is a poor criteria, but what is a good criteria b?) { + // dim = min side of the bounding box (this is a poor criteria, but what is a good + // criteria b?) // exposure, corners count, corner1.x, corner.1y, ..., rotation // note: corners count is the count of corners following corner1 int numPoints = (int) params[1].GetValue( tool ); + // Read points. numPoints does not include the starting point, so add 1. // and calculate the bounding box; wxSize pos_min, pos_max, pos; @@ -741,18 +757,24 @@ int AM_PRIMITIVE::GetShapeDim( const GERBER_DRAW_ITEM* aParent ) prm_idx++; pos.y = scaletoIU( params[prm_idx].GetValue( tool ), m_GerbMetric ); prm_idx++; + if( i == 0 ) + { pos_min = pos_max = pos; + } else { // upper right corner: if( pos_min.x > pos.x ) pos_min.x = pos.x; + if( pos_min.y > pos.y ) pos_min.y = pos.y; + // lower left corner: if( pos_max.x < pos.x ) pos_max.x = pos.x; + if( pos_max.y < pos.y ) pos_max.y = pos.y; } @@ -763,13 +785,14 @@ int AM_PRIMITIVE::GetShapeDim( const GERBER_DRAW_ITEM* aParent ) if( prm_idx >= last_prm ) break; } + // calculate dim wxSize size; size.x = pos_max.x - pos_min.x; size.y = pos_max.y - pos_min.y; dim = std::min( size.x, size.y ); - } break; + } case AMP_POLYGON: // Regular polygon dim = scaletoIU( params[4].GetValue( tool ), m_GerbMetric ) / 2; // Radius @@ -780,6 +803,7 @@ int AM_PRIMITIVE::GetShapeDim( const GERBER_DRAW_ITEM* aParent ) case AMP_EOF: break; } + return dim; } @@ -799,7 +823,9 @@ SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* a continue; if( prim_macro->IsAMPrimitiveExposureOn( aParent ) ) + { prim_macro->DrawBasicShape( aParent, m_shape, aShapePos ); + } else { prim_macro->DrawBasicShape( aParent, holeBuffer, aShapePos ); @@ -831,15 +857,9 @@ SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* a } -/* - * Function DrawApertureMacroShape - * Draw the primitive shape for flashed items. - * When an item is flashed, this is the shape of the item - */ -void APERTURE_MACRO::DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, - EDA_RECT* aClipBox, wxDC* aDC, - COLOR4D aColor, - wxPoint aShapePos, bool aFilledShape ) +void APERTURE_MACRO::DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, + wxDC* aDC, COLOR4D aColor, wxPoint aShapePos, + bool aFilledShape ) { SHAPE_POLY_SET* shapeBuffer = GetApertureMacroShape( aParent, aShapePos ); @@ -851,27 +871,20 @@ void APERTURE_MACRO::DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, SHAPE_LINE_CHAIN& poly = shapeBuffer->Outline( ii ); GRClosedPoly( aClipBox, aDC, poly.PointCount(), (wxPoint*) &poly.CPoint( 0 ), aFilledShape, - aColor, aColor ); + aColor, aColor ); } } -/** GetShapeDim - * Calculate a value that can be used to evaluate the size of text - * when displaying the D-Code of an item - * due to the complexity of a shape using many primitives - * one cannot calculate the "size" of a shape (only abounding box) - * but most of aperture macro are using one or few primitives - * and the "dimension" of the shape is the diameter of the primitive - * (or the max diameter of primitives) - * @return a dimension, or -1 if no dim to calculate - */ + int APERTURE_MACRO::GetShapeDim( GERBER_DRAW_ITEM* aParent ) { int dim = -1; + for( AM_PRIMITIVES::iterator prim_macro = primitives.begin(); prim_macro != primitives.end(); ++prim_macro ) { int pdim = prim_macro->GetShapeDim( aParent ); + if( dim < pdim ) dim = pdim; } @@ -880,20 +893,10 @@ int APERTURE_MACRO::GetShapeDim( GERBER_DRAW_ITEM* aParent ) } -/** - * function GetLocalParam - * Usually, parameters are defined inside the aperture primitive - * using immediate mode or defered mode. - * in defered mode the value is defined in a DCODE that want to use the aperture macro. - * But some parameters are defined outside the aperture primitive - * and are local to the aperture macro - * @return the value of a defered parameter defined inside the aperture macro - * @param aParamId = the param id (defined by $3 or $5 ..) to evaluate - */ double APERTURE_MACRO::GetLocalParam( const D_CODE* aDcode, unsigned aParamId ) const { // find parameter descr. - const AM_PARAM * param = NULL; + const AM_PARAM * param = nullptr; for( unsigned ii = 0; ii < m_localparamStack.size(); ii ++ ) { @@ -904,7 +907,7 @@ double APERTURE_MACRO::GetLocalParam( const D_CODE* aDcode, unsigned aParamId ) } } - if ( param == NULL ) // not found + if ( param == nullptr ) // not found return 0.0; // Evaluate parameter diff --git a/gerbview/am_primitive.h b/gerbview/am_primitive.h index 57a7aab459..167217d216 100644 --- a/gerbview/am_primitive.h +++ b/gerbview/am_primitive.h @@ -150,6 +150,10 @@ private: * * Arcs and circles are approximated by segments. Useful when a shape is not a graphic * primitive (shape with hole, rotated shape ... ) and cannot be easily drawn. + * + * @note Some schapes conbining circles and solid lines (rectangles), only rectangles are + * converted because circles are very easy to draw (no rotation problem) so convert + * them in polygons and draw them as polygons is not a good idea. */ void ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, std::vector& aBuffer ); }; diff --git a/gerbview/clear_gbr_drawlayers.cpp b/gerbview/clear_gbr_drawlayers.cpp index e6c805eb89..c4456afb4b 100644 --- a/gerbview/clear_gbr_drawlayers.cpp +++ b/gerbview/clear_gbr_drawlayers.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2016 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 @@ -39,7 +39,7 @@ bool GERBVIEW_FRAME::Clear_DrawLayers( bool query ) { - if( GetGerberLayout() == NULL ) + if( GetGerberLayout() == nullptr ) return false; if( query && GetScreen()->IsContentModified() ) diff --git a/gerbview/dcode.cpp b/gerbview/dcode.cpp index 3ef96c4056..17d39dfe66 100644 --- a/gerbview/dcode.cpp +++ b/gerbview/dcode.cpp @@ -77,7 +77,7 @@ void D_CODE::Clear_D_CODE_Data() m_DrillShape = APT_DEF_NO_HOLE; m_InUse = false; m_Defined = false; - m_Macro = NULL; + m_Macro = nullptr; m_Rotation = 0.0; m_EdgesCount = 0; m_Polygon.RemoveAllContours(); @@ -159,27 +159,29 @@ void D_CODE::DrawFlashedShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, wx case APT_CIRCLE: radius = m_Size.x >> 1; - if( !aFilledShape ) - GRCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), radius, 0, aColor ); - else - if( m_DrillShape == APT_DEF_NO_HOLE ) - { - GRFilledCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), - radius, aColor ); - } - else if( m_DrillShape == APT_DEF_ROUND_HOLE ) // round hole in shape - { - int width = (m_Size.x - m_Drill.x ) / 2; - GRCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), - radius - (width / 2), width, aColor ); - } - else // rectangular hole - { - if( m_Polygon.OutlineCount() == 0 ) - ConvertShapeToPolygon(); - DrawFlashedPolygon( aParent, aClipBox, aDC, aColor, aFilledShape, aShapePos ); - } + if( !aFilledShape ) + { + GRCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), radius, 0, aColor ); + } + else if( m_DrillShape == APT_DEF_NO_HOLE ) + { + GRFilledCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), radius, aColor ); + } + else if( m_DrillShape == APT_DEF_ROUND_HOLE ) // round hole in shape + { + int width = (m_Size.x - m_Drill.x ) / 2; + GRCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), + radius - (width / 2), width, aColor ); + } + else // rectangular hole + { + if( m_Polygon.OutlineCount() == 0 ) + ConvertShapeToPolygon(); + + DrawFlashedPolygon( aParent, aClipBox, aDC, aColor, aFilledShape, aShapePos ); + } + break; case APT_RECT: @@ -248,6 +250,7 @@ void D_CODE::DrawFlashedShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, wx DrawFlashedPolygon( aParent, aClipBox, aDC, aColor, aFilledShape, aShapePos ); } } + break; case APT_POLYGON: @@ -334,7 +337,7 @@ void D_CODE::ConvertShapeToPolygon() // we create an horizontal oval shape. then rotate if needed if( m_Size.x > m_Size.y ) // horizontal oval { - delta = (m_Size.x - m_Size.y) / 2; + delta = ( m_Size.x - m_Size.y ) / 2; radius = m_Size.y / 2; } else // vertical oval @@ -374,6 +377,7 @@ void D_CODE::ConvertShapeToPolygon() addHoleToPolygon( &m_Polygon, m_DrillShape, m_Drill, initialpos ); } + break; case APT_POLYGON: diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb.cpp b/gerbview/dialogs/dialog_layers_select_to_pcb.cpp index ee32127c3a..3b244d54fb 100644 --- a/gerbview/dialogs/dialog_layers_select_to_pcb.cpp +++ b/gerbview/dialogs/dialog_layers_select_to_pcb.cpp @@ -6,7 +6,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 * modify it under the terms of the GNU General Public License @@ -40,9 +40,10 @@ #include -// Imported function + extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber ); + enum swap_layer_id { ID_LAYERS_MAP_DIALOG = ID_GERBER_END_LIST, ID_BUTTON_0, @@ -50,12 +51,6 @@ enum swap_layer_id { }; -/* - * This dialog shows the gerber files loaded, and allows user to choose: - * what gerber file and what board layer are used - * the number of copper layers - */ - int LAYERS_MAP_DIALOG::m_exportBoardCopperLayersCount = 2; @@ -108,7 +103,7 @@ void LAYERS_MAP_DIALOG::initDialog() for( unsigned ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii ) { - if( images->GetGbrImage( ii ) == NULL ) + if( images->GetGbrImage( ii ) == nullptr ) break; m_buttonTable[m_gerberActiveLayersCount] = ii; @@ -209,7 +204,7 @@ void LAYERS_MAP_DIALOG::initDialog() m_layersList[ii] = text; } - // If the user has never stored any Gerber to Kicad layer mapping, + // If the user has never stored any Gerber to KiCad layer mapping, // then disable the button to retrieve it if( config->m_GerberToPcbLayerMapping.size() == 0 ) m_buttonRetrieve->Enable( false ); @@ -256,9 +251,7 @@ void LAYERS_MAP_DIALOG::initDialog() } } -/* Ensure m_exportBoardCopperLayersCount = 2 to BOARD_COPPER_LAYERS_MAX_COUNT - * and it is an even value because Boards have always an even layer count - */ + void LAYERS_MAP_DIALOG::normalizeBrdLayersCount() { if( ( m_exportBoardCopperLayersCount & 1 ) ) @@ -272,18 +265,14 @@ void LAYERS_MAP_DIALOG::normalizeBrdLayersCount() } -/* - * Called when user change the current board copper layers count - */ + void LAYERS_MAP_DIALOG::OnBrdLayersCountSelection( wxCommandEvent& event ) { int id = event.GetSelection(); m_exportBoardCopperLayersCount = (id+1) * 2; } -/* - * reset pcb layers selection to the default value - */ + void LAYERS_MAP_DIALOG::OnResetClick( wxCommandEvent& event ) { wxString msg; @@ -299,8 +288,6 @@ void LAYERS_MAP_DIALOG::OnResetClick( wxCommandEvent& event ) } -/* Stores the current layers selection in config - */ void LAYERS_MAP_DIALOG::OnStoreSetup( wxCommandEvent& event ) { auto config = static_cast( Kiface().KifaceSettings() ); @@ -318,6 +305,7 @@ void LAYERS_MAP_DIALOG::OnStoreSetup( wxCommandEvent& event ) m_buttonRetrieve->Enable( true ); } + void LAYERS_MAP_DIALOG::OnGetSetup( wxCommandEvent& event ) { GERBVIEW_SETTINGS* config = static_cast( Kiface().KifaceSettings() ); @@ -340,6 +328,7 @@ void LAYERS_MAP_DIALOG::OnGetSetup( wxCommandEvent& event ) for( int ii = 0; ii < m_gerberActiveLayersCount; ii++ ) { LAYER_NUM layer = m_layersLookUpTable[ii]; + if( layer == UNSELECTED_LAYER ) { m_layersList[ii]->SetLabel( _( "Do not export" ) ); @@ -366,7 +355,7 @@ void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event ) if( (ii < 0) || (ii >= GERBER_DRAWLAYERS_COUNT) ) { - wxFAIL_MSG( wxT("Bad layer id") ); + wxFAIL_MSG( wxT( "Bad layer id" ) ); return; } @@ -377,6 +366,7 @@ void LAYERS_MAP_DIALOG::OnSelectLayer( wxCommandEvent& event ) // Get file name of Gerber loaded on this layer wxFileName fn( m_Parent->GetGerberLayout()->GetImagesList()->GetGbrImage( ii )->m_FileName ); + // Surround it with quotes to make it stand out on the dialog title bar wxString layerName = "\"" + fn.GetFullName() + "\""; @@ -426,6 +416,7 @@ void LAYERS_MAP_DIALOG::OnOkClick( wxCommandEvent& event ) normalizeBrdLayersCount(); int inner_layer_max = 0; + for( int ii = 0; ii < GERBER_DRAWLAYERS_COUNT; ++ii ) { if( m_layersLookUpTable[ii] < F_Cu ) @@ -440,8 +431,8 @@ void LAYERS_MAP_DIALOG::OnOkClick( wxCommandEvent& event ) // internal copper layers = m_exportBoardCopperLayersCount-2 if( inner_layer_max > m_exportBoardCopperLayersCount-2 ) { - wxMessageBox( - _("Exported board does not have enough copper layers to handle selected inner layers") ); + wxMessageBox( _("Exported board does not have enough copper layers to handle selected " + "inner layers") ); return; } @@ -803,7 +794,6 @@ int LAYERS_MAP_DIALOG::findNumX2GerbersLoaded( std::vector& aGerber2KicadMa mapThis << x2->GetBrdLayerId() << x2->GetFileType(); } - // Check if the string we've isolated matches any known X2 layer names it = kicadLayers.find( mapThis ); diff --git a/gerbview/dialogs/dialog_print_gerbview.cpp b/gerbview/dialogs/dialog_print_gerbview.cpp index 119c388748..2a9355a6ea 100644 --- a/gerbview/dialogs/dialog_print_gerbview.cpp +++ b/gerbview/dialogs/dialog_print_gerbview.cpp @@ -170,14 +170,15 @@ void DIALOG_PRINT_GERBVIEW::createExtraOptions() // Print mirrored m_checkboxMirror = new wxCheckBox( box, wxID_ANY, _( "Print mirrored" ) ); optionsSizer->Add( m_checkboxMirror, wxGBPosition( rows, 0 ), wxGBSpan( 1, cols ), - wxBOTTOM | wxRIGHT | wxLEFT, 5 ); + wxBOTTOM | wxRIGHT | wxLEFT, 5 ); } void DIALOG_PRINT_GERBVIEW::createLeftPanel() { - wxStaticBoxSizer* sbLayersSizer = new wxStaticBoxSizer( new wxStaticBox( this, - wxID_ANY, _( "Included Layers" ) ), wxVERTICAL ); + wxStaticBoxSizer* sbLayersSizer = + new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _( "Included Layers" ) ), + wxVERTICAL ); // Layer lists wxBoxSizer* bLayerListsSizer = new wxBoxSizer( wxHORIZONTAL ); @@ -195,9 +196,11 @@ void DIALOG_PRINT_GERBVIEW::createLeftPanel() _( "Deselect all" ) ); m_buttonSelectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onSelectAllClick ), NULL, this ); + wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onSelectAllClick ), + nullptr, this ); m_buttonDeselectAll->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onDeselectAllClick ), NULL, this ); + wxCommandEventHandler( DIALOG_PRINT_GERBVIEW::onDeselectAllClick ), + nullptr, this ); wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL ); buttonSizer->Add( m_buttonSelectAll, 1, wxALL, 5 ); diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp index 48505e4635..383dec5d57 100644 --- a/gerbview/export_to_pcbnew.cpp +++ b/gerbview/export_to_pcbnew.cpp @@ -46,7 +46,7 @@ GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString { m_gerbview_frame = aFrame; m_pcb_file_name = aFileName; - m_fp = NULL; + m_fp = nullptr; m_pcbCopperLayersCount = 2; } @@ -62,7 +62,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( const LAYER_NUM* aLayerLookUpTable, int aCo m_fp = wxFopen( m_pcb_file_name, wxT( "wt" ) ); - if( m_fp == NULL ) + if( m_fp == nullptr ) { wxString msg; msg.Printf( _( "Failed to create file '%s'." ), m_pcb_file_name ); @@ -83,7 +83,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( const LAYER_NUM* aLayerLookUpTable, int aCo { EXCELLON_IMAGE* excellon = dynamic_cast( images->GetGbrImage( layer ) ); - if( excellon == NULL ) // Layer not yet used or not a drill image + if( excellon == nullptr ) // Layer not yet used or not a drill image continue; for( GERBER_DRAW_ITEM* gerb_item : excellon->GetItems() ) @@ -95,7 +95,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( const LAYER_NUM* aLayerLookUpTable, int aCo { GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer ); - if( gerber == NULL ) // Graphic layer not yet used + if( gerber == nullptr ) // Graphic layer not yet used continue; LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer]; @@ -115,7 +115,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( const LAYER_NUM* aLayerLookUpTable, int aCo { GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer ); - if( gerber == NULL ) // Graphic layer not yet used + if( gerber == nullptr ) // Graphic layer not yet used continue; LAYER_NUM pcb_layer_number = aLayerLookUpTable[layer]; @@ -134,12 +134,13 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( const LAYER_NUM* aLayerLookUpTable, int aCo fprintf( m_fp, ")\n" ); fclose( m_fp ); - m_fp = NULL; + m_fp = nullptr; return true; } -void GBR_TO_PCB_EXPORTER::export_non_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer ) +void GBR_TO_PCB_EXPORTER::export_non_copper_item( const GERBER_DRAW_ITEM* aGbrItem, + LAYER_NUM aLayer ) { // used when a D_CODE is not found. default D_CODE to draw a flashed item static D_CODE dummyD_CODE( 0 ); @@ -149,7 +150,7 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( const GERBER_DRAW_ITEM* aGbrIt D_CODE* d_codeDescr = aGbrItem->GetDcodeDescr(); SHAPE_POLY_SET polygon; - if( d_codeDescr == NULL ) + if( d_codeDescr == nullptr ) d_codeDescr = &dummyD_CODE; switch( aGbrItem->m_Shape ) @@ -159,11 +160,11 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( const GERBER_DRAW_ITEM* aGbrIt break; case GBR_SPOT_CIRCLE: - { + { VECTOR2I center = aGbrItem->GetABPosition( seg_start ); int radius = d_codeDescr->m_Size.x / 2; writePcbFilledCircle( center, radius, aLayer ); - } + } break; case GBR_SPOT_RECT: @@ -249,17 +250,6 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( const GERBER_DRAW_ITEM* aGbrIt } -/* - * Many holes will be pads, but we have no way to create those without footprints, and creating - * a footprint per pad is not really viable. - * - * So we use vias to mimic holes, with the loss of any hole shape (as we only have round holes - * in vias at present). - * - * We start out with a via size minimally larger than the hole. We'll leave it this way if - * the pad gets drawn as a copper polygon, or increase it to the proper size if it has a - * circular, concentric copper flashing. - */ void GBR_TO_PCB_EXPORTER::collect_hole( const GERBER_DRAW_ITEM* aGbrItem ) { int size = std::min( aGbrItem->m_Size.x, aGbrItem->m_Size.y ); @@ -321,7 +311,8 @@ void GBR_TO_PCB_EXPORTER::export_copper_item( const GERBER_DRAW_ITEM* aGbrItem, } -void GBR_TO_PCB_EXPORTER::export_segline_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer ) +void GBR_TO_PCB_EXPORTER::export_segline_copper_item( const GERBER_DRAW_ITEM* aGbrItem, + LAYER_NUM aLayer ) { wxPoint seg_start, seg_end; @@ -350,7 +341,8 @@ void GBR_TO_PCB_EXPORTER::writeCopperLineItem( const wxPoint& aStart, } -void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer ) +void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( const GERBER_DRAW_ITEM* aGbrItem, + LAYER_NUM aLayer ) { double a = atan2( (double) ( aGbrItem->m_Start.y - aGbrItem->m_ArcCentre.y ), (double) ( aGbrItem->m_Start.x - aGbrItem->m_ArcCentre.x ) ); @@ -384,6 +376,7 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( const GERBER_DRAW_ITEM* aGb RotatePoint( &curr_end, aGbrItem->m_ArcCentre, -RAD2DECIDEG( DELTA_ANGLE * ii ) ); seg_end = curr_end; + // Reverse Y axis: seg_start.y = -seg_start.y; seg_end.y = -seg_end.y; @@ -395,6 +388,7 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( const GERBER_DRAW_ITEM* aGb { seg_start = curr_start; seg_end = end; + // Reverse Y axis: seg_start.y = -seg_start.y; seg_end.y = -seg_end.y; @@ -403,14 +397,6 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( const GERBER_DRAW_ITEM* aGb } -/* - * Flashed items are usually pads or vias. Pads are problematic because we have no way to - * represent one in Pcbnew outside of a footprint (and creating a footprint per pad isn't really - * viable). - * If we've already created a via from a hole, and the flashed copper item is a simple circle - * then we'll enlarge the via to the proper size. Otherwise we create a copper polygon to - * represent the flashed item (which is presumably a pad). - */ void GBR_TO_PCB_EXPORTER::export_flashed_copper_item( const GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer ) { @@ -419,7 +405,7 @@ void GBR_TO_PCB_EXPORTER::export_flashed_copper_item( const GERBER_DRAW_ITEM* aG D_CODE* d_codeDescr = aGbrItem->GetDcodeDescr(); SHAPE_POLY_SET polygon; - if( d_codeDescr == NULL ) + if( d_codeDescr == nullptr ) d_codeDescr = &flashed_item_D_CODE; if( aGbrItem->m_Shape == GBR_SPOT_CIRCLE ) @@ -530,8 +516,8 @@ void GBR_TO_PCB_EXPORTER::writePcbPolygon( const SHAPE_POLY_SET& aPolys, LAYER_N } fprintf( m_fp, " (xy %s %s)", - Double2Str( MapToPcbUnits( poly.CPoint( ii ).x + aOffset.x ) ).c_str(), - Double2Str( MapToPcbUnits( -poly.CPoint( ii ).y + aOffset.y ) ).c_str() ); + Double2Str( MapToPcbUnits( poly.CPoint( ii ).x + aOffset.x ) ).c_str(), + Double2Str( MapToPcbUnits( -poly.CPoint( ii ).y + aOffset.y ) ).c_str() ); } fprintf( m_fp, ")" ); @@ -539,8 +525,7 @@ void GBR_TO_PCB_EXPORTER::writePcbPolygon( const SHAPE_POLY_SET& aPolys, LAYER_N if( jj != MAX_COORD_CNT ) fprintf( m_fp, "\n" ); - fprintf( m_fp, "(layer %s) (width 0) )\n", - TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) ); + fprintf( m_fp, "(layer %s) (width 0) )\n", TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) ); } @@ -553,7 +538,7 @@ void GBR_TO_PCB_EXPORTER::writePcbZoneItem( const GERBER_DRAW_ITEM* aGbrItem, LA return; fprintf( m_fp, "(zone (net 0) (net_name \"\") (layer %s) (tstamp 0000000) (hatch edge 0.508)\n", - TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) ); + TO_UTF8( GetPCBDefaultLayerName( aLayer ) ) ); fprintf( m_fp, " (connect_pads (clearance 0.0))\n" ); diff --git a/gerbview/export_to_pcbnew.h b/gerbview/export_to_pcbnew.h index 5c6d4e3e53..8fa884c0b6 100644 --- a/gerbview/export_to_pcbnew.h +++ b/gerbview/export_to_pcbnew.h @@ -63,7 +63,12 @@ private: /** * Collect holes from a drill layer. * - * We'll use these later when writing pads & vias. + * We'll use these later when writing pads & vias. Many holes will be pads, but we have + * no way to create those without footprints, and creating a footprint per pad is not + * really viable. We use vias to mimic holes, with the loss of any hole shape (as we only + * have round holes in vias at present). We start out with a via size minimally larger + * than the hole. We'll leave it this way if the pad gets drawn as a copper polygon, or + * increase it to the proper size if it has a circular, concentric copper flashing. */ void collect_hole( const GERBER_DRAW_ITEM* aGbrItem ); diff --git a/gerbview/gbr_layout.cpp b/gerbview/gbr_layout.cpp index 32e2d2fe8d..8166070261 100644 --- a/gerbview/gbr_layout.cpp +++ b/gerbview/gbr_layout.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-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 @@ -28,7 +28,7 @@ #include GBR_LAYOUT::GBR_LAYOUT() : - EDA_ITEM( (EDA_ITEM*)nullptr, GERBER_LAYOUT_T ) + EDA_ITEM( nullptr, GERBER_LAYOUT_T ) { } @@ -37,7 +37,7 @@ GBR_LAYOUT::~GBR_LAYOUT() { } -// Accessor to the list of gerber files (and drill files) images +// Accessor to the list of Gerber files (and drill files) images GERBER_FILE_IMAGE_LIST* GBR_LAYOUT::GetImagesList() const { return &GERBER_FILE_IMAGE_LIST::GetImagesList(); @@ -53,7 +53,7 @@ EDA_RECT GBR_LAYOUT::ComputeBoundingBox() const { GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); - if( gerber == NULL ) // Graphic layer not yet used + if( gerber == nullptr ) // Graphic layer not yet used continue; for( GERBER_DRAW_ITEM* item : gerber->GetItems() ) @@ -97,7 +97,7 @@ SEARCH_RESULT GBR_LAYOUT::Visit( INSPECTOR inspector, void* testData, const KICA { GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); - if( gerber == NULL ) // Graphic layer not yet used + if( gerber == nullptr ) // Graphic layer not yet used continue; result = gerber->Visit( inspector, testData, p ); diff --git a/gerbview/gerber_collectors.cpp b/gerbview/gerber_collectors.cpp index 036cb3a505..17d973fa1d 100644 --- a/gerbview/gerber_collectors.cpp +++ b/gerbview/gerber_collectors.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * 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 as published by the @@ -28,14 +28,11 @@ const KICAD_T GERBER_COLLECTOR::AllItems[] = { /** - * Function Inspect - * is the examining function within the INSPECTOR which is passed to the - * Iterate function. + * The examining function within the INSPECTOR which is passed to the iterate function. * - * @param testItem An EDA_ITEM to examine. - * @param testData not used here. - * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, - * else SCAN_CONTINUE; + * @param testItem is an EDA_ITEM to examine. + * @param testData is not used here. + * @return SEARCH_QUIT if the iterator is to stop the scan, else SCAN_CONTINUE. */ SEARCH_RESULT GERBER_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) { @@ -60,7 +57,7 @@ void GERBER_COLLECTOR::Collect( EDA_ITEM* aItem, const KICAD_T aScanList[], // the Inspect() function. SetRefPos( aRefPos ); - aItem->Visit( m_inspector, NULL, m_scanTypes ); + aItem->Visit( m_inspector, nullptr, m_scanTypes ); // record the length of the primary list before concatenating on to it. m_PrimaryLength = m_list.size(); diff --git a/gerbview/gerber_collectors.h b/gerbview/gerber_collectors.h index c1d1763a7a..5d8ebb9637 100644 --- a/gerbview/gerber_collectors.h +++ b/gerbview/gerber_collectors.h @@ -35,7 +35,6 @@ public: GERBER_COLLECTOR() { - //m_Guide = NULL; m_PrimaryLength = 0; SetScanTypes( AllItems ); } @@ -45,18 +44,6 @@ public: m_List2nd.clear(); } - /*void Append2nd( BOARD_ITEM* item ) - { - m_List2nd.push_back( item ); - }*/ - - /** - * Record which COLLECTORS_GUIDE to use. - * - * @param aGuide is the guide to use in the collection. - */ - //void SetGuide( const COLLECTORS_GUIDE* aGuide ) { m_Guide = aGuide; } - /** * Overload the [](int) operator to return a EDA_ITEM* instead of an EDA_ITEM* type. * @@ -68,7 +55,7 @@ public: if( (unsigned)ndx < (unsigned)GetCount() ) return (EDA_ITEM*) m_list[ ndx ]; - return NULL; + return nullptr; } /** @@ -107,11 +94,6 @@ protected: */ std::vector m_List2nd; - /** - * Determines which items are to be collected by Inspect() - */ - //const COLLECTORS_GUIDE* m_Guide; - /** * The number of items that were originally in the primary list before the * m_List2nd was concatenated onto the end of it. diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index 0822c3954b..04ed18b4c7 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2017 - * Copyright (C) 1992-2019 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 @@ -38,7 +38,7 @@ #include GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberImageFile ) : - EDA_ITEM( (EDA_ITEM*)NULL, GERBER_DRAW_ITEM_T ) + EDA_ITEM( nullptr, GERBER_DRAW_ITEM_T ) { m_GerberImageFile = aGerberImageFile; m_Shape = GBR_SEGMENT; @@ -77,7 +77,7 @@ void GERBER_DRAW_ITEM::SetNetAttributes( const GBR_NETLIST_METADATA& aNetAttribu int GERBER_DRAW_ITEM::GetLayer() const { - // returns the layer this item is on, or 0 if the m_GerberImageFile is NULL. + // Return the layer this item is on, or 0 if the m_GerberImageFile is null. return m_GerberImageFile ? m_GerberImageFile->m_GraphicLayer : 0; } @@ -174,6 +174,7 @@ wxPoint GERBER_DRAW_ITEM::GetABPosition( const wxPoint& aXYPosition ) const // abPos.y must be negated when no mirror, because draw axis is top to bottom if( !m_mirrorB ) abPos.y = -abPos.y; + return abPos; } @@ -269,11 +270,11 @@ wxString GERBER_DRAW_ITEM::ShowGBRShape() const D_CODE* GERBER_DRAW_ITEM::GetDcodeDescr() const { - if( (m_DCode < FIRST_DCODE) || (m_DCode > LAST_DCODE) ) - return NULL; + if( ( m_DCode < FIRST_DCODE ) || ( m_DCode > LAST_DCODE ) ) + return nullptr; - if( m_GerberImageFile == NULL ) - return NULL; + if( m_GerberImageFile == nullptr ) + return nullptr; return m_GerberImageFile->GetDCODE( m_DCode ); } @@ -317,7 +318,7 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const if( arc_angle < 0.0 ) arc_angle += 360.0; - if( m_End == m_Start ) // Arc with the end point = start point is expected to be a circle + if( m_End == m_Start ) // Arc with the end point = start point is expected to be a circle. arc_angle = 360.0; SHAPE_ARC arc( m_ArcCentre, m_Start, arc_angle ); @@ -335,6 +336,7 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const int radius = code->m_Size.x >> 1; bbox.Inflate( radius, radius ); } + break; } @@ -342,6 +344,7 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const { if( code ) bbox.Inflate( code->m_Size.x / 2, code->m_Size.y / 2 ); + break; } @@ -349,6 +352,7 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const { if( code ) bbox.Inflate( code->m_Size.x /2, code->m_Size.y / 2 ); + break; } @@ -362,6 +366,7 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const bbox.Inflate( code->m_Polygon.BBox().GetWidth() / 2, code->m_Polygon.BBox().GetHeight() / 2 ); } + break; } case GBR_SPOT_MACRO: @@ -370,9 +375,11 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const { // Update the shape drawings and the bounding box coordinates: code->GetMacro()->GetApertureMacroShape( this, m_Start ); + // now the bounding box is valid: bbox = code->GetMacro()->GetBoundingBox(); } + break; } @@ -407,7 +414,7 @@ const EDA_RECT GERBER_DRAW_ITEM::GetBoundingBox() const break; } - // calculate the corners coordinates in current gerber axis orientations + // calculate the corners coordinates in current Gerber axis orientations wxPoint org = GetABPosition( bbox.GetOrigin() ); wxPoint end = GetABPosition( bbox.GetEnd() ); @@ -461,7 +468,7 @@ void GERBER_DRAW_ITEM::Print( wxDC* aDC, const wxPoint& aOffset, GBR_DISPLAY_OPT static bool show_err; D_CODE* d_codeDescr = GetDcodeDescr(); - if( d_codeDescr == NULL ) + if( d_codeDescr == nullptr ) d_codeDescr = &dummyD_CODE; COLOR4D color = m_GerberImageFile->GetPositiveDrawColor(); @@ -506,6 +513,7 @@ void GERBER_DRAW_ITEM::Print( wxDC* aDC, const wxPoint& aOffset, GBR_DISPLAY_OPT { GRCircle( nullptr, aDC, GetABPosition( m_Start ), radius, m_Size.x, color ); } + break; case GBR_ARC: @@ -535,7 +543,7 @@ void GERBER_DRAW_ITEM::Print( wxDC* aDC, const wxPoint& aOffset, GBR_DISPLAY_OPT case GBR_SEGMENT: /* Plot a line from m_Start to m_End. - * Usually, a round pen is used, but some gerber files use a rectangular pen + * Usually, a round pen is used, but some Gerber files use a rectangular pen * In fact, any aperture can be used to plot a line. * currently: only a square pen is handled (I believe using a polygon gives a strange plot). */ @@ -611,7 +619,7 @@ void GERBER_DRAW_ITEM::ConvertSegmentToPolygon() corner.y += m_Size.y; m_Polygon.Append( VECTOR2I( corner ) ); // upper left corner, start point (2) - if( delta.x || delta.y) + if( delta.x || delta.y ) { corner += delta; m_Polygon.Append( VECTOR2I( corner ) ); // upper left corner, end point (3) @@ -705,9 +713,8 @@ void GERBER_DRAW_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector m_Size.y ) // Horizontal oval { int len = m_Size.y - m_Size.x; @@ -830,6 +838,7 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos, int aAccuracy ) const start.y = -len/2; end.y = len/2; } + start += bbox.Centre(); end += bbox.Centre(); @@ -837,47 +846,46 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos, int aAccuracy ) const radius = MIN_HIT_TEST_RADIUS; return TestSegmentHit( aRefPos, start, end, radius ); - } + } case GBR_ARC: + { + double radius = GetLineLength( m_Start, m_ArcCentre ); + VECTOR2D test_radius = VECTOR2D( ref_pos ) - VECTOR2D( m_ArcCentre ); + + int size = ( ( m_Size.x < MIN_HIT_TEST_RADIUS ) ? MIN_HIT_TEST_RADIUS : m_Size.x ); + + // Are we close enough to the radius? + bool radius_hit = ( std::fabs( test_radius.EuclideanNorm() - radius) < size ); + + if( radius_hit ) { - double radius = GetLineLength( m_Start, m_ArcCentre ); - VECTOR2D test_radius = VECTOR2D( ref_pos ) - VECTOR2D( m_ArcCentre ); + // Now check that we are within the arc angle - int size = ( ( m_Size.x < MIN_HIT_TEST_RADIUS ) ? MIN_HIT_TEST_RADIUS - : m_Size.x ); + VECTOR2D start = VECTOR2D( m_Start ) - VECTOR2D( m_ArcCentre ); + VECTOR2D end = VECTOR2D( m_End ) - VECTOR2D( m_ArcCentre ); - // Are we close enough to the radius? - bool radius_hit = ( std::fabs( test_radius.EuclideanNorm() - radius) < size ); + double start_angle = NormalizeAngleRadiansPos( start.Angle() ); + double end_angle = NormalizeAngleRadiansPos( end.Angle() ); - if( radius_hit ) + if( m_Start == m_End ) { - // Now check that we are within the arc angle - - VECTOR2D start = VECTOR2D( m_Start ) - VECTOR2D( m_ArcCentre ); - VECTOR2D end = VECTOR2D( m_End ) - VECTOR2D( m_ArcCentre ); - - double start_angle = NormalizeAngleRadiansPos( start.Angle() ); - double end_angle = NormalizeAngleRadiansPos( end.Angle() ); - - if( m_Start == m_End ) - { - start_angle = 0; - end_angle = 2 * M_PI; - } - else if( end_angle < start_angle ) - { - end_angle += 2 * M_PI; - } - - double test_angle = NormalizeAngleRadiansPos( test_radius.Angle() ); - - return ( test_angle > start_angle && test_angle < end_angle ); + start_angle = 0; + end_angle = 2 * M_PI; + } + else if( end_angle < start_angle ) + { + end_angle += 2 * M_PI; } - return false; + double test_angle = NormalizeAngleRadiansPos( test_radius.Angle() ); + + return ( test_angle > start_angle && test_angle < end_angle ); } + return false; + } + case GBR_SPOT_MACRO: // Aperture macro polygons are already in absolute coordinates auto p = GetDcodeDescr()->GetMacro()->GetApertureMacroShape( this, m_Start ); @@ -986,7 +994,8 @@ double GERBER_DRAW_ITEM::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const } -SEARCH_RESULT GERBER_DRAW_ITEM::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) +SEARCH_RESULT GERBER_DRAW_ITEM::Visit( INSPECTOR inspector, void* testData, + const KICAD_T scanTypes[] ) { KICAD_T stype = *scanTypes; diff --git a/gerbview/gerber_file_image_list.cpp b/gerbview/gerber_file_image_list.cpp index 270c001c62..062912e569 100644 --- a/gerbview/gerber_file_image_list.cpp +++ b/gerbview/gerber_file_image_list.cpp @@ -7,7 +7,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 1992-2016 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2016 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 @@ -40,7 +40,6 @@ GERBER_FILE_IMAGE_LIST s_GERBER_List; -// GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files GERBER_FILE_IMAGE_LIST::GERBER_FILE_IMAGE_LIST() { m_GERBER_List.reserve( GERBER_DRAWLAYERS_COUNT ); @@ -67,14 +66,10 @@ GERBER_FILE_IMAGE* GERBER_FILE_IMAGE_LIST::GetGbrImage( int aIdx ) if( (unsigned)aIdx < m_GERBER_List.size() ) return m_GERBER_List[aIdx]; - return NULL; + return nullptr; } -/* creates a new, empty GERBER_FILE_IMAGE* at index aIdx - * or at the first free location if aIdx < 0 - * aIdx = the index of graphic layer to use, or -1 to uses the first free graphic layer - * return the index actually used, or -1 if no room to add image - */ + int GERBER_FILE_IMAGE_LIST::AddGbrImage( GERBER_FILE_IMAGE* aGbrImage, int aIdx ) { int idx = aIdx; @@ -83,7 +78,7 @@ int GERBER_FILE_IMAGE_LIST::AddGbrImage( GERBER_FILE_IMAGE* aGbrImage, int aIdx { for( idx = 0; idx < (int)m_GERBER_List.size(); idx++ ) { - if( m_GERBER_List[idx] == NULL ) + if( m_GERBER_List[idx] == nullptr ) break; } } @@ -117,12 +112,12 @@ void GERBER_FILE_IMAGE_LIST::DeleteImage( int aIdx ) m_GERBER_List[ aIdx ] = nullptr; } -// Build a name for image aIdx which can be used in layers manager + const wxString GERBER_FILE_IMAGE_LIST::GetDisplayName( int aIdx, bool aNameOnly, bool aFullName ) { wxString name; - GERBER_FILE_IMAGE* gerber = NULL; + GERBER_FILE_IMAGE* gerber = nullptr; if( aIdx >= 0 && aIdx < (int)m_GERBER_List.size() ) gerber = m_GERBER_List[aIdx]; @@ -173,7 +168,9 @@ const wxString GERBER_FILE_IMAGE_LIST::GetDisplayName( int aIdx, bool aNameOnly, } } else + { name = filename; + } if( aNameOnly ) return name; @@ -185,7 +182,9 @@ const wxString GERBER_FILE_IMAGE_LIST::GetDisplayName( int aIdx, bool aNameOnly, return fullname; } else + { name.Printf( _( "Graphic layer %d" ), aIdx + 1 ); + } return name; } diff --git a/gerbview/gerbview.cpp b/gerbview/gerbview.cpp index 7ef619ef87..ea00aa1128 100644 --- a/gerbview/gerbview.cpp +++ b/gerbview/gerbview.cpp @@ -6,7 +6,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2021 KiCad Developers, see change_log.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 @@ -55,7 +55,8 @@ static struct IFACE : public KIFACE_I void OnKifaceEnd() override; - wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override + wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, + int aCtlBits = 0 ) override { switch( aClassId ) { @@ -70,24 +71,25 @@ static struct IFACE : public KIFACE_I ; } - return NULL; + return nullptr; } /** - * Function IfaceOrAddress - * return a pointer to the requested object. The safest way to use this is to retrieve - * a pointer to a static instance of an interface, similar to how the KIFACE interface - * is exported. But if you know what you are doing use it to retrieve anything you want. + * Return a pointer to the requested object. + * + * The safest way to use this is to retrieve a pointer to a static instance of an interface, + * similar to how the KIFACE interface is exported. But if you know what you are doing use + * it to retrieve anything you want. + * * @param aDataId identifies which object you want the address of. - * @return void* - and must be cast into the know type. + * @return the object requested and must be cast into the know type. */ void* IfaceOrAddress( int aDataId ) override { - return NULL; + return nullptr; } /** - * Function SaveFileAs * Saving a file under a different name is delegated to the various KIFACEs because * the project doesn't know the internal format of the various files (which may have * paths in them that need updating). @@ -100,10 +102,13 @@ static struct IFACE : public KIFACE_I } // namespace + using namespace GERBV; + static PGM_BASE* process; + KIFACE_I& Kiface() { return kiface; } @@ -129,6 +134,7 @@ PGM_BASE* PgmOrNull() return process; } + bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) { InitSettings( new GERBVIEW_SETTINGS ); diff --git a/gerbview/gerbview_draw_panel_gal.cpp b/gerbview/gerbview_draw_panel_gal.cpp index 848dc21646..eef4e8e6f5 100644 --- a/gerbview/gerbview_draw_panel_gal.cpp +++ b/gerbview/gerbview_draw_panel_gal.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018 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 @@ -39,8 +39,9 @@ using namespace std::placeholders; GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, - const wxPoint& aPosition, const wxSize& aSize, - KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) : + const wxPoint& aPosition, const wxSize& aSize, + KIGFX::GAL_DISPLAY_OPTIONS& aOptions, + GAL_TYPE aGalType ) : EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ) { m_view = new KIGFX::VIEW( true ); @@ -49,6 +50,7 @@ EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalTy m_painter = std::make_unique( m_gal ); m_view->SetPainter( m_painter.get() ); + // This fixes the zoom in and zoom out limits: m_view->SetScaleLimits( ZOOM_MAX_LIMIT_GERBVIEW, ZOOM_MIN_LIMIT_GERBVIEW ); @@ -118,7 +120,7 @@ bool GERBVIEW_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) { bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType ); - // The next onPaint event will call m_view->UpdateItems() that is very time consumming + // The next onPaint event will call m_view->UpdateItems() that is very time consuming // after switching to opengl. Clearing m_view and rebuild it is much faster if( aGalType == GAL_TYPE_OPENGL ) { @@ -132,7 +134,7 @@ bool GERBVIEW_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) { GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer ); - if( gerber == NULL ) // Graphic layer not yet used + if( gerber == nullptr ) // Graphic layer not yet used continue; for( GERBER_DRAW_ITEM* item : gerber->GetItems() ) @@ -159,9 +161,6 @@ void GERBVIEW_DRAW_PANEL_GAL::setDefaultLayerDeps() for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ ) m_view->SetLayerTarget( i, target ); - // for( int i = GERBVIEW_LAYER_ID_START; i < GERBVIEW_LAYER_ID_RESERVED; i++ ) - // m_view->SetLayerDisplayOnly( i ); - m_view->SetLayerDisplayOnly( LAYER_DCODES ); m_view->SetLayerDisplayOnly( LAYER_NEGATIVE_OBJECTS ); m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_GRID ); diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index dee37696f3..19683530f5 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -67,14 +67,14 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ) : EDA_DRAW_FRAME( aKiway, aParent, FRAME_GERBER, wxT( "GerbView" ), wxDefaultPosition, - wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GERBVIEW_FRAME_NAME ), + wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GERBVIEW_FRAME_NAME ), m_TextInfo( nullptr ), m_zipFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_ZIP_FILE1, - ID_GERBVIEW_ZIP_FILE_LIST_CLEAR, _( "Clear Recent Zip Files" ) ), + ID_GERBVIEW_ZIP_FILE_LIST_CLEAR, _( "Clear Recent Zip Files" ) ), m_drillFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_DRILL_FILE1, - ID_GERBVIEW_DRILL_FILE_LIST_CLEAR, _( "Clear Recent Drill Files" ) ), + ID_GERBVIEW_DRILL_FILE_LIST_CLEAR, _( "Clear Recent Drill Files" ) ), m_jobFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_JOB_FILE1, - ID_GERBVIEW_JOB_FILE_LIST_CLEAR, _( "Clear Recent Job Files" ) ), + ID_GERBVIEW_JOB_FILE_LIST_CLEAR, _( "Clear Recent Job Files" ) ), m_activeLayer( 0 ) { m_maximizeByDefault = true; @@ -136,7 +136,8 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ) m_LayersManager = new GERBER_LAYER_WIDGET( this, GetCanvas() ); // Update the minimum string length in the layer panel with the length of the last default layer - wxString lyrName = GetImagesList()->GetDisplayName( GetImagesList()->ImagesMaxCount(), false, true ); + wxString lyrName = GetImagesList()->GetDisplayName( GetImagesList()->ImagesMaxCount(), + false, true ); m_LayersManager->SetSmallestLayerString( lyrName ); // LoadSettings() *after* creating m_LayersManager, because LoadSettings() @@ -328,7 +329,8 @@ void GERBVIEW_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) GERBVIEW_SETTINGS* cfg = dynamic_cast( aCfg ); wxCHECK( cfg, /*void*/ ); - SetElementVisibility( LAYER_GERBVIEW_DRAWINGSHEET, cfg->m_Appearance.show_border_and_titleblock ); + SetElementVisibility( LAYER_GERBVIEW_DRAWINGSHEET, + cfg->m_Appearance.show_border_and_titleblock ); PAGE_INFO pageInfo( wxT( "GERBER" ) ); pageInfo.SetType( cfg->m_Appearance.page_type ); @@ -413,11 +415,13 @@ void GERBVIEW_FRAME::SetElementVisibility( int aLayerID, bool aNewState ) // GetLayerPolarity() returns true for negative items return ( item && item->GetLayerPolarity() ); } ); + break; } case LAYER_GERBVIEW_DRAWINGSHEET: m_showBorderAndTitleBlock = aNewState; + // NOTE: LAYER_DRAWINGSHEET always used for visibility, but the layer manager passes // LAYER_GERBVIEW_DRAWINGSHEET because of independent color control GetCanvas()->GetView()->SetLayerVisible( LAYER_DRAWINGSHEET, aNewState ); @@ -468,7 +472,7 @@ int GERBVIEW_FRAME::getNextAvailableLayer( int aLayer ) const { const GERBER_FILE_IMAGE* gerber = GetGbrImage( layer ); - if( gerber == NULL ) // this graphic layer is available: use it + if( gerber == nullptr ) // this graphic layer is available: use it return layer; ++layer; // try next graphic layer @@ -504,7 +508,7 @@ void GERBVIEW_FRAME::syncLayerBox( bool aRebuildLayerBox ) { updateDCodeSelectBox(); m_DCodeSelector->SetDCodeSelection( dcodeSelected ); - m_DCodeSelector->Enable( gerber != NULL ); + m_DCodeSelector->Enable( gerber != nullptr ); } } @@ -603,7 +607,7 @@ void GERBVIEW_FRAME::UpdateTitleAndInfo() GERBER_FILE_IMAGE* gerber = GetGbrImage( GetActiveLayer() ); // Display the gerber filename - if( gerber == NULL ) + if( gerber == nullptr ) { SetTitle( _("Gerber Viewer") ); @@ -673,7 +677,8 @@ bool GERBVIEW_FRAME::IsElementVisible( int aLayerID ) const case LAYER_GERBVIEW_BACKGROUND: return true; default: - wxFAIL_MSG( wxString::Format( "GERBVIEW_FRAME::IsElementVisible(): bad arg %d", aLayerID ) ); + wxFAIL_MSG( wxString::Format( "GERBVIEW_FRAME::IsElementVisible(): bad arg %d", + aLayerID ) ); } return true; @@ -894,9 +899,6 @@ void GERBVIEW_FRAME::SetGridColor( COLOR4D aColor ) } -/* - * Display the grid status. - */ void GERBVIEW_FRAME::DisplayGridMsg() { wxString line; diff --git a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp index 8b869cf76b..738152d60f 100644 --- a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp +++ b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010-2014 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2014 KiCad Developers, see change_log.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 @@ -50,10 +50,10 @@ static double scale_list[SCALE_LIST_SIZE] = 0.00001 * IU_PER_MILS, // provided, but not used }; -/* - * Function scale - * converts a coordinate given in floating point to Gerbvies internal units - * (currently = 10 nanometers) + +/** + * Convert a coordinate given in floating point to GerbView's internal units + * (currently = 10 nanometers). */ int scaletoIU( double aCoord, bool isMetric ) { @@ -82,13 +82,14 @@ wxPoint GERBER_FILE_IMAGE::ReadXYCoord( char*& Text, bool aExcellonMode ) else pos = m_CurrentPos; - if( Text == NULL ) + if( Text == nullptr ) return pos; text = line; + while( *Text ) { - if( (*Text == 'X') || (*Text == 'Y') || (*Text == 'A') ) + if( ( *Text == 'X' ) || ( *Text == 'Y' ) || ( *Text == 'A' ) ) { type_coord = *Text; Text++; @@ -97,12 +98,13 @@ wxPoint GERBER_FILE_IMAGE::ReadXYCoord( char*& Text, bool aExcellonMode ) while( IsNumber( *Text ) ) { - if( *Text == '.' ) // Force decimat format if reading a floating point number + if( *Text == '.' ) // Force decimal format if reading a floating point number is_float = true; // count digits only (sign and decimal point are not counted) if( (*Text >= '0') && (*Text <='9') ) nbdigits++; + *(text++) = *(Text++); } @@ -156,9 +158,13 @@ wxPoint GERBER_FILE_IMAGE::ReadXYCoord( char*& Text, bool aExcellonMode ) } if( type_coord == 'X' ) + { pos.x = current_coord; + } else if( type_coord == 'Y' ) + { pos.y = current_coord; + } else if( type_coord == 'A' ) { m_ArcRadius = current_coord; @@ -168,7 +174,9 @@ wxPoint GERBER_FILE_IMAGE::ReadXYCoord( char*& Text, bool aExcellonMode ) continue; } else + { break; + } } if( m_Relative ) @@ -182,10 +190,6 @@ wxPoint GERBER_FILE_IMAGE::ReadXYCoord( char*& Text, bool aExcellonMode ) } -/* Returns the current coordinate type pointed to by InnJnn Text (InnnnJmmmm) - * These coordinates are relative, so if coordinate is absent, its value - * defaults to 0 - */ wxPoint GERBER_FILE_IMAGE::ReadIJCoord( char*& Text ) { wxPoint pos( 0, 0 ); @@ -195,31 +199,34 @@ wxPoint GERBER_FILE_IMAGE::ReadIJCoord( char*& Text ) char* text; char line[256]; - if( Text == NULL ) + if( Text == nullptr ) return pos; text = line; + while( *Text ) { - if( (*Text == 'I') || (*Text == 'J') ) + if( ( *Text == 'I' ) || ( *Text == 'J' ) ) { type_coord = *Text; Text++; text = line; nbdigits = 0; + while( IsNumber( *Text ) ) { if( *Text == '.' ) is_float = true; // count digits only (sign and decimal point are not counted) - if( (*Text >= '0') && (*Text <='9') ) + if( ( *Text >= '0' ) && ( *Text <= '9' ) ) nbdigits++; *(text++) = *(Text++); } *text = 0; + if( is_float ) { // When X or Y values are float numbers, they are given in mm or inches @@ -230,13 +237,12 @@ wxPoint GERBER_FILE_IMAGE::ReadIJCoord( char*& Text ) } else { - int fmt_scale = - (type_coord == 'I') ? m_FmtScale.x : m_FmtScale.y; + int fmt_scale = ( type_coord == 'I' ) ? m_FmtScale.x : m_FmtScale.y; if( m_NoTrailingZeros ) { - int min_digit = - (type_coord == 'I') ? m_FmtLen.x : m_FmtLen.y; + int min_digit = ( type_coord == 'I' ) ? m_FmtLen.x : m_FmtLen.y; + while( nbdigits < min_digit ) { *(text++) = '0'; @@ -255,6 +261,7 @@ wxPoint GERBER_FILE_IMAGE::ReadIJCoord( char*& Text ) current_coord = KiROUND( current_coord * real_scale ); } + if( type_coord == 'I' ) pos.x = current_coord; else if( type_coord == 'J' ) @@ -263,7 +270,9 @@ wxPoint GERBER_FILE_IMAGE::ReadIJCoord( char*& Text ) continue; } else + { break; + } } m_IJPos = pos; @@ -277,13 +286,14 @@ wxPoint GERBER_FILE_IMAGE::ReadIJCoord( char*& Text ) // Helper functions: /** - * Function ReadInt - * reads an int from an ASCII character buffer. If there is a comma after the - * int, then skip over that. - * @param text A reference to a character pointer from which bytes are read - * and the pointer is advanced for each byte read. - * @param aSkipSeparator = true (default) to skip comma - * @return int - The int read in. + * Read an integer from an ASCII character buffer. + * + * If there is a comma after the integer, then skip over that. + * + * @param text is a reference to a character pointer from which bytes are read + * and the pointer is advanced for each byte read. + * @param aSkipSeparator set to true (default) to skip comma. + * @return The integer read in. */ int ReadInt( char*& text, bool aSkipSeparator = true ) { @@ -298,7 +308,9 @@ int ReadInt( char*& text, bool aSkipSeparator = true ) ret = 0; } else + { ret = (int) strtol( text, &text, 10 ); + } if( *text == ',' || isspace( *text ) ) { @@ -311,13 +323,14 @@ int ReadInt( char*& text, bool aSkipSeparator = true ) /** - * Function ReadDouble - * reads a double from an ASCII character buffer. If there is a comma after - * the double, then skip over that. - * @param text A reference to a character pointer from which the ASCII double - * is read from and the pointer advanced for each character read. - * @param aSkipSeparator = true (default) to skip comma - * @return double + * Read a double precision floating point number from an ASCII character buffer. + * + * If there is a comma after the number, then skip over that. + * + * @param text is a reference to a character pointer from which the ASCII double + * is read from and the pointer advanced for each character read. + * @param aSkipSeparator set to true (default) to skip comma. + * @return number read. */ double ReadDouble( char*& text, bool aSkipSeparator = true ) { @@ -332,7 +345,9 @@ double ReadDouble( char*& text, bool aSkipSeparator = true ) ret = 0.0; } else + { ret = strtod( text, &text ); + } if( *text == ',' || isspace( *text ) ) { diff --git a/gerbview/rs274d.cpp b/gerbview/rs274d.cpp index 33d3bd90be..11f87d01d7 100644 --- a/gerbview/rs274d.cpp +++ b/gerbview/rs274d.cpp @@ -6,7 +6,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * 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 @@ -74,7 +74,7 @@ * D01 = activating light (pen down) when placement * D02 = light extinction (pen up) when placement * D03 = Flash - * D09 = VAPE Flash (I never see this command in gerber file) + * D09 = VAPE Flash (I never see this command in Gerber file) * D51 = G54 preceded by -> Select VAPE * * D10 ... D999 = Identification Tool: tool selection @@ -86,16 +86,15 @@ /** - * Function fillFlashedGBRITEM - * initializes a given GBRITEM so that it can draw a circle which is filled and + * Initializes a given GBRITEM so that it can draw a circle which is filled and * has no pen border. * * @param aGbrItem The GBRITEM to fill in. - * @param aAperture the associated type of aperture - * @param Dcode_index The DCODE value, like D14 - * @param aPos The center point of the flash - * @param aSize The diameter of the round flash - * @param aLayerNegative = true if the current layer is negative + * @param aAperture the associated type of aperture. + * @param Dcode_index The DCODE value, like D14. + * @param aPos The center point of the flash. + * @param aSize The diameter of the round flash. + * @param aLayerNegative set to true if the current layer is negative. */ void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem, APERTURE_T aAperture, @@ -142,22 +141,21 @@ void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem, /** - * Function fillLineGBRITEM - * initializes a given GBRITEM so that it can draw a linear D code. + * Initialize a given GBRITEM so that it can draw a linear D code. * * @param aGbrItem The GERBER_DRAW_ITEM to fill in. - * @param Dcode_index The DCODE value, like D14 - * @param aStart The starting point of the line - * @param aEnd The ending point of the line + * @param Dcode_index The DCODE value, like D14. + * @param aStart The starting point of the line. + * @param aEnd The ending point of the line. * @param aPenSize The size of the flash. Note rectangular shapes are legal. - * @param aLayerNegative = true if the current layer is negative + * @param aLayerNegative set to true if the current layer is negative. */ void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem, - int Dcode_index, - const wxPoint& aStart, - const wxPoint& aEnd, - wxSize aPenSize, - bool aLayerNegative ) + int Dcode_index, + const wxPoint& aStart, + const wxPoint& aEnd, + wxSize aPenSize, + bool aLayerNegative ) { aGbrItem->m_Flashed = false; @@ -174,38 +172,36 @@ void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem, /** - * Function fillArcGBRITEM - * initializes a given GBRITEM so that it can draw an arc G code. - *

- * if multiquadrant == true : arc can be 0 to 360 degrees + * Initialize a given GBRITEM so that it can draw an arc G code. + * + * If multiquadrant == true : arc can be 0 to 360 degrees * and \a rel_center is the center coordinate relative to start point. - *

- * if multiquadrant == false arc can be only 0 to 90 deg, + * + * If multiquadrant == false arc can be only 0 to 90 deg, * and only in the same quadrant : *

    *
  • absolute angle 0 to 90 (quadrant 1) or *
  • absolute angle 90 to 180 (quadrant 2) or *
  • absolute angle 180 to 270 (quadrant 3) or *
  • absolute angle 270 to 0 (quadrant 4) - *

+ * + * * @param aGbrItem is the GBRITEM to fill in. - * @param Dcode_index is the DCODE value, like D14 - * @param aStart is the starting point - * @param aEnd is the ending point + * @param Dcode_index is the DCODE value, like D14. + * @param aStart is the starting point. + * @param aEnd is the ending point. * @param aRelCenter is the center coordinate relative to start point, * given in ABSOLUTE VALUE and the sign of values x et y de rel_center * must be calculated from the previously given constraint: arc only in the same quadrant. * @param aClockwise true if arc must be created clockwise * @param aPenSize The size of the flash. Note rectangular shapes are legal. - * @param aMultiquadrant = true to create arcs upto 360 deg, + * @param aMultiquadrant set to true to create arcs up to 360 degrees, * false when arc is inside one quadrant - * @param aLayerNegative = true if the current layer is negative + * @param aLayerNegative set to true if the current layer is negative. */ -void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, - const wxPoint& aStart, const wxPoint& aEnd, - const wxPoint& aRelCenter, wxSize aPenSize, - bool aClockwise, bool aMultiquadrant, - bool aLayerNegative ) +void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, const wxPoint& aStart, + const wxPoint& aEnd, const wxPoint& aRelCenter, wxSize aPenSize, + bool aClockwise, bool aMultiquadrant, bool aLayerNegative ) { wxPoint center, delta; @@ -217,7 +213,9 @@ void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict ); if( aMultiquadrant ) + { center = aStart + aRelCenter; + } else { // in single quadrant mode the relative coordinate aRelCenter is always >= 0 @@ -239,39 +237,39 @@ void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, */ if( (delta.x >= 0) && (delta.y >= 0) ) { - /* Quadrant 1 (trigo or cclockwise): - * C | E - * ---S--- - * 3 | 4 - */ + /* Quadrant 1 (trigo or cclockwise): + * C | E + * ---S--- + * 3 | 4 + */ center.x = -center.x; } else if( (delta.x >= 0) && (delta.y < 0) ) { - /* Quadrant 4 (trigo or cclockwise): - * 2 | C - * ---S--- - * 3 | E - */ - // Nothing to do + /* Quadrant 4 (trigo or cclockwise): + * 2 | C + * ---S--- + * 3 | E + */ + // Nothing to do } else if( (delta.x < 0) && (delta.y >= 0) ) { - /* Quadrant 2 (trigo or cclockwise): - * E | 1 - * ---S--- - * C | 4 - */ + /* Quadrant 2 (trigo or cclockwise): + * E | 1 + * ---S--- + * C | 4 + */ center.x = -center.x; center.y = -center.y; } else { - /* Quadrant 3 (trigo or cclockwise): - * 2 | 1 - * ---S--- - * E | C - */ + /* Quadrant 3 (trigo or cclockwise): + * 2 | 1 + * ---S--- + * E | C + */ center.y = -center.y; } @@ -302,48 +300,44 @@ void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index, /** - * Function fillArcPOLY - * creates an arc G code when found in poly outlines. - *

- * if multiquadrant == true : arc can be 0 to 360 degrees - * and \a rel_center is the center coordinate relative to start point. - *

- * if multiquadrant == false arc can be only 0 to 90 deg, - * and only in the same quadrant : + * Create an arc G code when found in polygon outlines. + * + * If multiquadrant == true : arc can be 0 to 360 degrees and \a rel_center is the center + * coordinate relative to start point. If not multiquadrant, the arc can be only 0 to 90 deg, + * and only in the same quadrant: + * *

    *
  • absolute angle 0 to 90 (quadrant 1) or *
  • absolute angle 90 to 180 (quadrant 2) or *
  • absolute angle 180 to 270 (quadrant 3) or *
  • absolute angle 270 to 0 (quadrant 4) - *

+ * + * * @param aGbrItem is the GBRITEM to fill in. - * @param aStart is the starting point - * @param aEnd is the ending point + * @param aStart is the starting point. + * @param aEnd is the ending point. * @param rel_center is the center coordinate relative to start point, * given in ABSOLUTE VALUE and the sign of values x et y de rel_center * must be calculated from the previously given constraint: arc only in the * same quadrant. * @param aClockwise true if arc must be created clockwise - * @param aMultiquadrant = true to create arcs upto 360 deg, - * false when arc is inside one quadrant - * @param aLayerNegative = true if the current layer is negative + * @param aMultiquadrant set to true to create arcs up to 360 deg or + * false when arc is inside one quadrant + * @param aLayerNegative set to true if the current layer is negative */ -static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, - const wxPoint& aStart, const wxPoint& aEnd, - const wxPoint& rel_center, - bool aClockwise, bool aMultiquadrant, - bool aLayerNegative ) +static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, const wxPoint& aStart, const wxPoint& aEnd, + const wxPoint& rel_center, bool aClockwise, bool aMultiquadrant, + bool aLayerNegative ) { /* in order to calculate arc parameters, we use fillArcGBRITEM * so we muse create a dummy track and use its geometric parameters */ - static GERBER_DRAW_ITEM dummyGbrItem( NULL ); + static GERBER_DRAW_ITEM dummyGbrItem( nullptr ); aGbrItem->SetLayerPolarity( aLayerNegative ); - fillArcGBRITEM( &dummyGbrItem, 0, - aStart, aEnd, rel_center, wxSize(0, 0), - aClockwise, aMultiquadrant, aLayerNegative ); + fillArcGBRITEM( &dummyGbrItem, 0, aStart, aEnd, rel_center, wxSize( 0, 0 ), + aClockwise, aMultiquadrant, aLayerNegative ); aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict ); @@ -371,6 +365,7 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, end_angle += 3600; double arc_angle = start_angle - end_angle; + // Approximate arc by 36 segments per 360 degree const int increment_angle = 3600 / 36; int count = std::abs( arc_angle / increment_angle ); @@ -385,13 +380,14 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, { double rot; wxPoint end_arc = start; + if( aClockwise ) - rot = ii * increment_angle; // rot is in 0.1 deg + rot = ii * increment_angle; // rot is in 0.1 deg else - rot = (count - ii) * increment_angle; // rot is in 0.1 deg + rot = ( count - ii ) * increment_angle; // rot is in 0.1 deg if( ii < count ) - RotatePoint( &end_arc, -rot ); + RotatePoint( &end_arc, -rot ); else // last point end_arc = aClockwise ? end : start; @@ -400,18 +396,18 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, } -/* Read the Gnn sequence and returns the value nn. - */ int GERBER_FILE_IMAGE::GCodeNumber( char*& Text ) { int ii = 0; char* text; char line[1024]; - if( Text == NULL ) + if( Text == nullptr ) return 0; + Text++; text = line; + while( IsNumber( *Text ) ) { *(text++) = *(Text++); @@ -423,19 +419,18 @@ int GERBER_FILE_IMAGE::GCodeNumber( char*& Text ) } -/* Get the sequence Dnn and returns the value nn - */ int GERBER_FILE_IMAGE::DCodeNumber( char*& Text ) { int ii = 0; char* text; char line[1024]; - if( Text == NULL ) + if( Text == nullptr ) return 0; Text++; text = line; + while( IsNumber( *Text ) ) *(text++) = *(Text++); @@ -447,12 +442,9 @@ int GERBER_FILE_IMAGE::DCodeNumber( char*& Text ) bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command ) { -// D( printf( "%22s: G_CODE<%d>\n", __func__, G_command ); ) - switch( G_command ) { - case GC_PHOTO_MODE: // can starts a D03 flash command: redundant, can - // be safely ignored + case GC_PHOTO_MODE: // can starts a D03 flash command: redundant, can be safely ignored. break; case GC_LINEAR_INTERPOL_1X: @@ -474,6 +466,7 @@ bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command ) if( strncmp( text, " #@! ", 5 ) == 0 ) { text += 5; + // The string starting at text is the same as the X2 attribute, // but a X2 attribute ends by '%'. So we build the X2 attribute string std::string x2buf; @@ -483,17 +476,19 @@ bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command ) x2buf += *text; text++; } + // add the end of X2 attribute string x2buf += "*%"; x2buf += '\0'; char* cptr = (char*)x2buf.data(); int code_command = ReadXCommandID( cptr ); - ExecuteRS274XCommand( code_command, NULL, 0, cptr ); + ExecuteRS274XCommand( code_command, nullptr, 0, cptr ); } while( *text && (*text != '*') ) text++; + break; case GC_SELECT_TOOL: @@ -502,8 +497,10 @@ bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command ) if( D_commande < FIRST_DCODE ) return false; + if( D_commande > (TOOLS_MAX_COUNT - 1) ) D_commande = TOOLS_MAX_COUNT - 1; + m_Current_Tool = D_commande; D_CODE* pt_Dcode = GetDCODE( D_commande ); @@ -557,6 +554,7 @@ bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command ) StepAndRepeatItem( *gbritem ); } + m_Exposure = false; m_PolygonFillMode = false; m_PolygonFillModeState = 0; @@ -586,7 +584,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande ) GERBER_DRAW_ITEM* gbritem; int dcode = 0; - D_CODE* tool = NULL; + D_CODE* tool = nullptr; wxString msg; if( D_commande >= FIRST_DCODE ) // This is a "Set tool" command @@ -643,6 +641,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande ) if( !m_AsArcG74G75Cmd ) { AddMessageToList( _( "Invalid Gerber file: missing G74 or G75 arc command" ) ); + // Disable further warning messages: m_AsArcG74G75Cmd = true; } @@ -659,6 +658,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande ) gbritem = GetLastItemInList(); gbritem->m_Start = m_PreviousPos; // m_Start is used as temporary storage + if( gbritem->m_Polygon.OutlineCount() == 0 ) { gbritem->m_Polygon.NewOutline(); @@ -681,6 +681,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande ) gbritem->m_Polygon.Append( gbritem->m_Polygon.CVertex( 0 ) ); StepAndRepeatItem( *gbritem ); } + m_Exposure = false; m_PreviousPos = m_CurrentPos; m_PolygonFillModeState = 0; @@ -757,6 +758,7 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande ) case 3: // code D3: flash aperture tool = GetDCODE( m_Current_Tool ); + if( tool ) { size = tool->m_Size; diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp index f75a1f4c2f..fae48f82d5 100644 --- a/gerbview/toolbars_gerber.cpp +++ b/gerbview/toolbars_gerber.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013 Wayne Stambaugh - * Copyright (C) 1992-2019 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 as published by the @@ -34,6 +34,7 @@ #include "widgets/gbr_layer_box_selector.h" #include "widgets/dcode_selection_box.h" + void GERBVIEW_FRAME::ReCreateHToolbar() { // Note: @@ -50,7 +51,8 @@ void GERBVIEW_FRAME::ReCreateHToolbar() else { m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize, - KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL ); + KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | + wxAUI_TB_HORIZONTAL ); m_mainToolBar->SetAuiManager( &m_auimgr ); } @@ -76,7 +78,7 @@ void GERBVIEW_FRAME::ReCreateHToolbar() if( !m_SelLayerBox ) m_SelLayerBox = new GBR_LAYER_BOX_SELECTOR( m_mainToolBar, ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, - wxDefaultPosition, wxDefaultSize, 0, NULL ); + wxDefaultPosition, wxDefaultSize, 0, nullptr ); m_SelLayerBox->Resync(); m_mainToolBar->AddControl( m_SelLayerBox ); @@ -149,8 +151,8 @@ void GERBVIEW_FRAME::ReCreateAuxiliaryToolbar() if( !m_apertText ) m_apertText = new wxStaticText( m_auxiliaryToolBar, wxID_ANY, _( "Attr:" ) ); - m_SelAperAttributesBox->SetToolTip( _("Highlight items with this aperture attribute") ); - m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language + m_SelAperAttributesBox->SetToolTip( _( "Highlight items with this aperture attribute" ) ); + m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language m_auxiliaryToolBar->AddControl( m_apertText ); m_auxiliaryToolBar->AddControl( m_SelAperAttributesBox ); m_auxiliaryToolBar->AddSpacer( 5 ); @@ -219,7 +221,8 @@ void GERBVIEW_FRAME::ReCreateOptToolbar() } else { - m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize, + m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, + wxDefaultSize, KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); m_optionsToolBar->SetAuiManager( &m_auimgr ); } @@ -278,6 +281,7 @@ void GERBVIEW_FRAME::UpdateToolbarControlSizes() #define NO_SELECTION_STRING _("") + void GERBVIEW_FRAME::updateDCodeSelectBox() { m_DCodeSelector->Clear(); @@ -305,30 +309,30 @@ void GERBVIEW_FRAME::updateDCodeSelectBox() switch( GetUserUnits() ) { - case EDA_UNITS::MILLIMETRES: - scale = IU_PER_MM; - units = "mm"; - break; + case EDA_UNITS::MILLIMETRES: + scale = IU_PER_MM; + units = "mm"; + break; - case EDA_UNITS::INCHES: - scale = IU_PER_MILS * 1000; - units = "in"; - break; + case EDA_UNITS::INCHES: + scale = IU_PER_MILS * 1000; + units = "in"; + break; - case EDA_UNITS::MILS: - scale = IU_PER_MILS; - units = "mil"; - break; + case EDA_UNITS::MILS: + scale = IU_PER_MILS; + units = "mil"; + break; - default: - wxASSERT_MSG( false, "Invalid units" ); + default: + wxASSERT_MSG( false, "Invalid units" ); } for( int ii = 0; ii < TOOLS_MAX_COUNT; ii++ ) { D_CODE* dcode = gerber->GetDCODE( ii + FIRST_DCODE ); - if( dcode == NULL ) + if( dcode == nullptr ) continue; if( !dcode->m_InUse && !dcode->m_Defined ) @@ -369,7 +373,7 @@ void GERBVIEW_FRAME::updateComponentListSelectBox() { GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); - if( gerber == NULL ) // Graphic layer not yet used + if( gerber == nullptr ) // Graphic layer not yet used continue; full_list.insert( gerber->m_ComponentsList.begin(), gerber->m_ComponentsList.end() ); @@ -397,7 +401,7 @@ void GERBVIEW_FRAME::updateNetnameListSelectBox() { GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); - if( gerber == NULL ) // Graphic layer not yet used + if( gerber == nullptr ) // Graphic layer not yet used continue; full_list.insert( gerber->m_NetnamesList.begin(), gerber->m_NetnamesList.end() ); @@ -425,7 +429,7 @@ void GERBVIEW_FRAME::updateAperAttributesSelectBox() { GERBER_FILE_IMAGE* gerber = GetImagesList()->GetGbrImage( layer ); - if( gerber == NULL ) // Graphic layer not yet used + if( gerber == nullptr ) // Graphic layer not yet used continue; if( gerber->GetDcodesCount() == 0 ) @@ -435,7 +439,7 @@ void GERBVIEW_FRAME::updateAperAttributesSelectBox() { D_CODE* aperture = gerber->GetDCODE( ii + FIRST_DCODE ); - if( aperture == NULL ) + if( aperture == nullptr ) continue; if( !aperture->m_InUse && !aperture->m_Defined ) @@ -490,7 +494,7 @@ void GERBVIEW_FRAME::OnUpdateSelectDCode( wxUpdateUIEvent& aEvent ) GERBER_FILE_IMAGE* gerber = GetGbrImage( layer ); int selected = ( gerber ) ? gerber->m_Selected_Tool : 0; - aEvent.Enable( gerber != NULL ); + aEvent.Enable( gerber != nullptr ); if( m_DCodeSelector->GetSelectedDCodeId() != selected ) { diff --git a/gerbview/tools/gerbview_inspection_tool.cpp b/gerbview/tools/gerbview_inspection_tool.cpp index 0fd53da4f8..3389e7ac2b 100644 --- a/gerbview/tools/gerbview_inspection_tool.cpp +++ b/gerbview/tools/gerbview_inspection_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jon Evans - * 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 as published by the @@ -78,23 +78,23 @@ int GERBVIEW_INSPECTION_TOOL::ShowDCodes( const TOOL_EVENT& aEvent ) switch( m_frame->GetUserUnits() ) { - case EDA_UNITS::MILLIMETRES: - scale = IU_PER_MM; - units = "mm"; - break; + case EDA_UNITS::MILLIMETRES: + scale = IU_PER_MM; + units = "mm"; + break; - case EDA_UNITS::INCHES: - scale = IU_PER_MILS * 1000; - units = "in"; - break; + case EDA_UNITS::INCHES: + scale = IU_PER_MILS * 1000; + units = "in"; + break; - case EDA_UNITS::MILS: - scale = IU_PER_MILS; - units = "mil"; - break; + case EDA_UNITS::MILS: + scale = IU_PER_MILS; + units = "mil"; + break; - default: - wxASSERT_MSG( false, "Invalid units" ); + default: + wxASSERT_MSG( false, "Invalid units" ); } for( unsigned int layer = 0; layer < m_frame->ImagesMaxCount(); ++layer ) @@ -118,7 +118,7 @@ int GERBVIEW_INSPECTION_TOOL::ShowDCodes( const TOOL_EVENT& aEvent ) { D_CODE* pt_D_code = gerber->GetDCODE( ii + FIRST_DCODE ); - if( pt_D_code == NULL ) + if( pt_D_code == nullptr ) continue; if( !pt_D_code->m_InUse && !pt_D_code->m_Defined ) @@ -144,7 +144,7 @@ int GERBVIEW_INSPECTION_TOOL::ShowDCodes( const TOOL_EVENT& aEvent ) } } - wxSingleChoiceDialog dlg( m_frame, wxEmptyString, _( "D Codes" ), list, (void**) NULL, + wxSingleChoiceDialog dlg( m_frame, wxEmptyString, _( "D Codes" ), list, (void**) nullptr, wxCHOICEDLG_STYLE & ~wxCANCEL ); dlg.ShowModal(); @@ -269,9 +269,9 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) break; } } - // click or drag starts else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) { + // click or drag starts twoPtMgr.SetOrigin( cursorPos ); twoPtMgr.SetEnd( cursorPos ); @@ -280,17 +280,17 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) originSet = true; } - // second click or mouse up after drag ends else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) { + // second click or mouse up after drag ends originSet = false; controls.SetAutoPan( false ); controls.CaptureCursor( false ); } - // move or drag when origin set updates rules else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) { + // move or drag when origin set updates rules twoPtMgr.SetAngleSnap( evt->Modifier( MD_SHIFT ) ); twoPtMgr.SetEnd( cursorPos ); diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index 5d46214024..01594af9ac 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jon Evans - * Copyright (C) 2017-2019 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 as published by the @@ -114,7 +114,7 @@ private: GERBVIEW_SELECTION_TOOL::GERBVIEW_SELECTION_TOOL() : TOOL_INTERACTIVE( "gerbview.InteractiveSelection" ), - m_frame( NULL ), + m_frame( nullptr ), m_additive( false ), m_subtractive( false ), m_exclusive_or( false ) @@ -175,8 +175,10 @@ void GERBVIEW_SELECTION_TOOL::Reset( RESET_REASON aReason ) getView()->GetPainter()->GetSettings()->SetHighlight( false ); } else + { // Restore previous properties of selected items and remove them from containers clearSelection(); + } // Reinsert the VIEW_GROUP, in case it was removed from the VIEW getView()->Remove( &m_selection ); @@ -206,9 +208,9 @@ int GERBVIEW_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { selectPoint( evt->Position() ); } - // right click? if there is any object - show the context menu else if( evt->IsClick( BUT_RIGHT ) ) { + // right click? if there is any object - show the context menu if( m_selection.Empty() ) { selectPoint( evt->Position() ); @@ -217,9 +219,9 @@ int GERBVIEW_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) m_menu.ShowContextMenu( m_selection ); } - // Middle double click? Do zoom to fit else if( evt->IsDblClick( BUT_MIDDLE ) ) { + // Middle double click? Do zoom to fit m_toolMgr->RunAction( ACTIONS::zoomFitScreen, true ); } else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE ) @@ -244,7 +246,7 @@ GERBVIEW_SELECTION& GERBVIEW_SELECTION_TOOL::GetSelection() bool GERBVIEW_SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag ) { - EDA_ITEM* item = NULL; + EDA_ITEM* item = nullptr; GERBER_COLLECTOR collector; EDA_ITEM* model = getModel(); @@ -411,7 +413,7 @@ void GERBVIEW_SELECTION_TOOL::clearSelection() EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollector ) { - EDA_ITEM* current = NULL; + EDA_ITEM* current = nullptr; KIGFX::VIEW_GROUP highlightGroup; ACTION_MENU menu( true ); @@ -466,7 +468,7 @@ EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollec } else { - current = NULL; + current = nullptr; } } else if( evt->Action() == TA_CHOICE_MENU_CHOICE ) @@ -477,7 +479,7 @@ EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollec if( id && ( *id > 0 ) ) current = ( *aCollector )[*id - 1]; else - current = NULL; + current = nullptr; break; } @@ -507,6 +509,7 @@ bool GERBVIEW_SELECTION_TOOL::selectable( const EDA_ITEM* aItem ) const { // Don't allow selection of invisible negative items auto rs = static_cast( getView()->GetPainter()->GetSettings() ); + if( !rs->IsShowNegativeItems() ) return false; } diff --git a/gerbview/widgets/dcode_selection_box.cpp b/gerbview/widgets/dcode_selection_box.cpp index c72eabca17..899071ac67 100644 --- a/gerbview/widgets/dcode_selection_box.cpp +++ b/gerbview/widgets/dcode_selection_box.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2016 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2016-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 @@ -27,14 +27,11 @@ #include "dcode_selection_box.h" -/*******************************************/ -/* Helper class for displaying DCodes list */ -/*******************************************/ DCODE_SELECTION_BOX::DCODE_SELECTION_BOX( wxAuiToolBar* aParent, wxWindowID aId, const wxPoint& aLocation, const wxSize& aSize, const wxArrayString* aChoices ) : - wxComboBox( aParent, aId, wxEmptyString, aLocation, aSize, 0, NULL, wxCB_READONLY ) + wxComboBox( aParent, aId, wxEmptyString, aLocation, aSize, 0, nullptr, wxCB_READONLY ) { if( aChoices ) // Append aChoices here is by far faster than use aChoices inside @@ -59,7 +56,7 @@ int DCODE_SELECTION_BOX::GetSelectedDCodeId() wxString msg = GetString( ii ).AfterFirst( ' ' ).BeforeFirst( ' ' ); long id; - if( msg.ToLong(&id) ) + if( msg.ToLong( &id ) ) return id; } @@ -67,9 +64,6 @@ int DCODE_SELECTION_BOX::GetSelectedDCodeId() } -/* SetDCodeSelection - * aDCodeId = the DCode Id to select or <= 0 to select "no selection" - */ void DCODE_SELECTION_BOX::SetDCodeSelection( int aDCodeId ) { wxString msg; diff --git a/gerbview/widgets/dcode_selection_box.h b/gerbview/widgets/dcode_selection_box.h index 077e3ccfd6..69250ba7e1 100644 --- a/gerbview/widgets/dcode_selection_box.h +++ b/gerbview/widgets/dcode_selection_box.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 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 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 @@ -29,34 +29,33 @@ #include -/* helper class to display a DCode list and select a DCode id. - */ - // Define event type for DCODE_SELECTION_BOX #define EVT_SELECT_DCODE EVT_COMBOBOX + +/** + * Helper to display a DCode list and select a DCode id. + */ class DCODE_SELECTION_BOX : public wxComboBox { -public: DCODE_SELECTION_BOX( wxAuiToolBar* aParent, wxWindowID aId, - const wxPoint& aLocation, const wxSize& aSize, - const wxArrayString* aChoices = NULL ); - ~DCODE_SELECTION_BOX(); +public: + DCODE_SELECTION_BOX( wxAuiToolBar* aParent, wxWindowID aId, + const wxPoint& aLocation, const wxSize& aSize, + const wxArrayString* aChoices = nullptr ); + ~DCODE_SELECTION_BOX(); /** - * Function GetSelectedDCodeId * @return the current selected DCode Id or 0 if no dcode */ int GetSelectedDCodeId(); /** - * Function SetDCodeSelection - * @param aDCodeId = the DCode Id to select or <= 0 to select "no dcode" + * @param aDCodeId is the DCode Id to select or <= 0 to select "no dcode". */ void SetDCodeSelection( int aDCodeId ); /** - * Function AppendDCodeList - * @param aChoices = the DCode Id list to add to the combo box + * @param aChoices is the DCode Id list to add to the combo box. */ void AppendDCodeList( const wxArrayString& aChoices ); }; diff --git a/gerbview/widgets/gbr_layer_box_selector.h b/gerbview/widgets/gbr_layer_box_selector.h index 3d5ce3740c..44dbba6a39 100644 --- a/gerbview/widgets/gbr_layer_box_selector.h +++ b/gerbview/widgets/gbr_layer_box_selector.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2014 KiCad Developers, see change_log.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 @@ -33,26 +33,24 @@ class GBR_LAYER_BOX_SELECTOR : public LAYER_BOX_SELECTOR { public: GBR_LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, - const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - int n = 0, const wxString choices[] = NULL ) : + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, const wxString choices[] = nullptr ) : LAYER_BOX_SELECTOR( parent, id, pos, size, n, choices ) { m_layerhotkeys = false; } // Reload the Layers names and bitmaps - // Virtual function void Resync() override; - // Returns a color index from the layer id - // Virtual function + // Return a color index from the layer id COLOR4D getLayerColor( int aLayer ) const override; - // Returns true if the layer id is enabled (i.e. is it should be displayed) - // Virtual function + // Return true if the layer id is enabled (i.e. is it should be displayed) bool isLayerEnabled( int aLayer ) const override { return true; } - // Returns the name of the layer id + // Return the name of the layer id wxString getLayerName( int aLayer ) const override; }; diff --git a/gerbview/widgets/gerbview_layer_widget.cpp b/gerbview/widgets/gerbview_layer_widget.cpp index a4e19498aa..421eb738c5 100644 --- a/gerbview/widgets/gerbview_layer_widget.cpp +++ b/gerbview/widgets/gerbview_layer_widget.cpp @@ -42,13 +42,6 @@ #include "gerbview_layer_widget.h" #include "dcode_selection_box.h" -/* - * GERBER_LAYER_WIDGET - * is here to implement the abstract functions of LAYER_WIDGET so they - * may be tied into the GERBVIEW_FRAME's data and so we can add a popup - * menu which is specific to Pcbnew's needs. - */ - GERBER_LAYER_WIDGET::GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFocusOwner ) : LAYER_WIDGET( aParent, aFocusOwner ), @@ -61,34 +54,30 @@ GERBER_LAYER_WIDGET::GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFo // Update default tabs labels for GerbView SetLayersManagerTabsText( ); - //------------------------------------------------------ // handle the popup menu over the layer window. m_LayerScrolledWindow->Connect( wxEVT_RIGHT_DOWN, - wxMouseEventHandler( GERBER_LAYER_WIDGET::onRightDownLayers ), NULL, this ); + wxMouseEventHandler( GERBER_LAYER_WIDGET::onRightDownLayers ), + nullptr, this ); // since Popupmenu() calls this->ProcessEvent() we must call this->Connect() // and not m_LayerScrolledWindow->Connect() - Connect( ID_LAYER_MANAGER_START, ID_LAYER_MANAGER_END, - wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler( GERBER_LAYER_WIDGET::onPopupSelection ), NULL, this ); + Connect( ID_LAYER_MANAGER_START, ID_LAYER_MANAGER_END, wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler( GERBER_LAYER_WIDGET::onPopupSelection ), nullptr, this ); } + GERBER_FILE_IMAGE_LIST* GERBER_LAYER_WIDGET::GetImagesList() { return &GERBER_FILE_IMAGE_LIST::GetImagesList(); } -void GERBER_LAYER_WIDGET::SetLayersManagerTabsText( ) +void GERBER_LAYER_WIDGET::SetLayersManagerTabsText() { - m_notebook->SetPageText(0, _("Layers") ); - m_notebook->SetPageText(1, _("Items") ); + m_notebook->SetPageText( 0, _( "Layers" ) ); + m_notebook->SetPageText( 1, _( "Items" ) ); } -/** - * Function ReFillRender - * Rebuild Render for instance after the config is read - */ void GERBER_LAYER_WIDGET::ReFillRender() { ClearRenderRows(); @@ -101,16 +90,20 @@ void GERBER_LAYER_WIDGET::ReFillRender() #define RR LAYER_WIDGET::ROW // Render Row abbreviation to reduce source width - // text id color tooltip checked - RR( _( "DCodes" ), LAYER_DCODES, WHITE, _( "Show DCodes identification" ) ), - RR( _( "Negative Objects" ), LAYER_NEGATIVE_OBJECTS, DARKGRAY, _( "Show negative objects in this color" ) ), + RR( _( "DCodes" ), LAYER_DCODES, WHITE, + _( "Show DCodes identification" ) ), + RR( _( "Negative Objects" ), LAYER_NEGATIVE_OBJECTS, DARKGRAY, + _( "Show negative objects in this color" ) ), RR(), - RR( _( "Grid" ), LAYER_GERBVIEW_GRID, WHITE, _( "Show the (x,y) grid dots" ) ), - RR( _( "Drawing Sheet" ), LAYER_GERBVIEW_DRAWINGSHEET, DARKRED, _( "Show drawing sheet border and title block") ), - RR( _( "Background" ), LAYER_GERBVIEW_BACKGROUND, BLACK, _( "PCB Background" ), true, false ) + RR( _( "Grid" ), LAYER_GERBVIEW_GRID, WHITE, + _( "Show the (x,y) grid dots" ) ), + RR( _( "Drawing Sheet" ), LAYER_GERBVIEW_DRAWINGSHEET, DARKRED, + _( "Show drawing sheet border and title block") ), + RR( _( "Background" ), LAYER_GERBVIEW_BACKGROUND, BLACK, + _( "PCB Background" ), true, false ) }; - for( unsigned row=0; rowGetVisibleElementColor( renderRows[row].id ); @@ -156,6 +149,7 @@ void GERBER_LAYER_WIDGET::onRightDownLayers( wxMouseEvent& event ) passOnFocus(); } + void GERBER_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) { int rowCount; @@ -206,8 +200,7 @@ bool GERBER_LAYER_WIDGET::OnLayerSelected() if( !m_alwaysShowActiveLayer ) return false; - // postprocess after active layer selection - // ensure active layer visible + // postprocess after active layer selection ensure active layer visible wxCommandEvent event; event.SetId( ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE ); onPopupSelection( event ); @@ -242,7 +235,6 @@ void GERBER_LAYER_WIDGET::ReFill() Thaw(); } -//------------------------------------------------ void GERBER_LAYER_WIDGET::OnLayerRightClick( wxMenu& aMenu ) { @@ -332,20 +324,16 @@ void GERBER_LAYER_WIDGET::OnRenderEnable( int aId, bool isEnabled ) m_frame->GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); } else + { m_frame->GetCanvas()->GetView()->SetLayerVisible( aId, isEnabled ); + } } m_frame->GetCanvas()->Refresh(); } -//----------------------------------------------- -/* - * Virtual Function useAlternateBitmap - * return true if bitmaps shown in Render layer list - * must be alternate bitmap (when a gerber image is loaded), or false to use "normal" bitmap - */ -bool GERBER_LAYER_WIDGET::useAlternateBitmap(int aRow) +bool GERBER_LAYER_WIDGET::useAlternateBitmap( int aRow ) { - return GetImagesList()->GetGbrImage( aRow ) != NULL; + return GetImagesList()->GetGbrImage( aRow ) != nullptr; } diff --git a/gerbview/widgets/gerbview_layer_widget.h b/gerbview/widgets/gerbview_layer_widget.h index 3d668eb4d3..f03c301788 100644 --- a/gerbview/widgets/gerbview_layer_widget.h +++ b/gerbview/widgets/gerbview_layer_widget.h @@ -24,10 +24,6 @@ */ -/************************************************************/ -/* class_gerber_layer_widget.h : header for the layers manager */ -/************************************************************/ - #ifndef GERBER_LAYER_WIDGET_H #define GERBER_LAYER_WIDGET_H @@ -46,6 +42,9 @@ public: */ GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFocusOwner ); + /** + * Rebuild Render for instance after the config is read. + */ void ReFill(); /** diff --git a/gerbview/widgets/layer_widget.cpp b/gerbview/widgets/layer_widget.cpp index f2e5f45633..879c55f7e0 100644 --- a/gerbview/widgets/layer_widget.cpp +++ b/gerbview/widgets/layer_widget.cpp @@ -49,8 +49,7 @@ const wxEventType LAYER_WIDGET::EVT_LAYER_COLOR_CHANGE = wxNewEventType(); /** - * Function shrinkFont - * reduces the size of the wxFont associated with \a aControl + * Reduce the size of the wxFont associated with \a aControl. */ static void shrinkFont( wxWindow* aControl, int aPointSize ) { @@ -105,7 +104,6 @@ void LAYER_WIDGET::OnLeftDownLayers( wxMouseEvent& event ) layer = getDecodedId( getLayerComp( row, 0 )->GetId() ); } - else { // all nested controls on a given row will have their ID encoded with @@ -250,7 +248,8 @@ void LAYER_WIDGET::OnTabChange( wxNotebookEvent& event ) // wxFocusEvent event( wxEVT_SET_FOCUS ); // m_FocusOwner->AddPendingEvent( event ); - passOnFocus(); // does not work in this context, probably because we have receive control here too early. + // Does not work in this context, probably because we have receive control here too early. + passOnFocus(); } @@ -261,7 +260,7 @@ wxWindow* LAYER_WIDGET::getLayerComp( int aRow, int aColumn ) const if( ndx < m_LayersFlexGridSizer->GetChildren().GetCount() ) return m_LayersFlexGridSizer->GetChildren()[ndx]->GetWindow(); - return NULL; + return nullptr; } @@ -290,7 +289,7 @@ wxWindow* LAYER_WIDGET::getRenderComp( int aRow, int aColumn ) const if( (unsigned) ndx < m_RenderFlexGridSizer->GetChildren().GetCount() ) return m_RenderFlexGridSizer->GetChildren()[ndx]->GetWindow(); - return NULL; + return nullptr; } @@ -334,12 +333,14 @@ void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec ) getBackgroundLayerColor(), aSpec.defaultColor, SWATCH_SMALL ); bmb->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this ); bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this ); - bmb->SetToolTip( _("Left double click or middle click for color change, right click for menu" ) ); + bmb->SetToolTip( _("Left double click or middle click for color change, right click for " + "menu" ) ); m_LayersFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags ); // column 2 (COLUMN_COLOR_LYR_CB) col = COLUMN_COLOR_LYR_CB; - wxCheckBox* cb = new wxCheckBox( m_LayerScrolledWindow, encodeId( col, aSpec.id ), wxEmptyString ); + wxCheckBox* cb = new wxCheckBox( m_LayerScrolledWindow, encodeId( col, aSpec.id ), + wxEmptyString ); cb->SetValue( aSpec.state ); cb->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED, &LAYER_WIDGET::OnLayerCheckBox, this ); cb->SetToolTip( _( "Enable this for visibility" ) ); @@ -478,8 +479,6 @@ void LAYER_WIDGET::passOnFocus() } -//------------------------------------------------------------ - LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( aParent, id, pos, size, style ), @@ -498,7 +497,8 @@ LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL ); - m_notebook = new wxAuiNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP ); + m_notebook = new wxAuiNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, + wxAUI_NB_TOP ); wxFont font = m_notebook->GetFont(); @@ -509,12 +509,14 @@ LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID m_notebook->SetSelectedFont( font ); m_notebook->SetMeasuringFont( font ); - m_LayerPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + m_LayerPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, + wxTAB_TRAVERSAL ); wxBoxSizer* layerPanelSizer; layerPanelSizer = new wxBoxSizer( wxVERTICAL ); - m_LayerScrolledWindow = new wxScrolledWindow( m_LayerPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER ); + m_LayerScrolledWindow = new wxScrolledWindow( m_LayerPanel, wxID_ANY, wxDefaultPosition, + wxDefaultSize, wxNO_BORDER ); m_LayerScrolledWindow->SetScrollRate( 5, 5 ); m_LayersFlexGridSizer = new wxFlexGridSizer( 0, LYR_COLUMN_COUNT, 0, 1 ); m_LayersFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL ); @@ -526,18 +528,20 @@ LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID m_LayerScrolledWindow->SetSizer( m_LayersFlexGridSizer ); m_LayerScrolledWindow->Layout(); m_LayersFlexGridSizer->Fit( m_LayerScrolledWindow ); - layerPanelSizer->Add( m_LayerScrolledWindow, 1, wxBOTTOM|wxEXPAND|wxLEFT|wxTOP, 2 ); + layerPanelSizer->Add( m_LayerScrolledWindow, 1, wxBOTTOM | wxEXPAND | wxLEFT | wxTOP, 2 ); m_LayerPanel->SetSizer( layerPanelSizer ); m_LayerPanel->Layout(); layerPanelSizer->Fit( m_LayerPanel ); m_notebook->AddPage( m_LayerPanel, _( "Layers" ), true ); - m_RenderingPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + m_RenderingPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, + wxTAB_TRAVERSAL ); wxBoxSizer* renderPanelSizer; renderPanelSizer = new wxBoxSizer( wxVERTICAL ); - m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER ); + m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, + wxDefaultSize, wxNO_BORDER ); m_RenderScrolledWindow->SetScrollRate( 5, 5 ); m_RenderFlexGridSizer = new wxFlexGridSizer( 0, RND_COLUMN_COUNT, 0, 1 ); m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL ); @@ -546,7 +550,7 @@ LAYER_WIDGET::LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID m_RenderScrolledWindow->SetSizer( m_RenderFlexGridSizer ); m_RenderScrolledWindow->Layout(); m_RenderFlexGridSizer->Fit( m_RenderScrolledWindow ); - renderPanelSizer->Add( m_RenderScrolledWindow, 1, wxALL|wxEXPAND, 5 ); + renderPanelSizer->Add( m_RenderScrolledWindow, 1, wxALL | wxEXPAND, 5 ); m_RenderingPanel->SetSizer( renderPanelSizer ); m_RenderingPanel->Layout(); @@ -591,7 +595,6 @@ wxSize LAYER_WIDGET::GetBestSize() const // Account for the parent's frame: totWidth += 15; - /* The minimum height is a small size to properly force computation * of the panel's scrollbars (otherwise it will assume it *has* all * this space) */ @@ -601,7 +604,6 @@ wxSize LAYER_WIDGET::GetBestSize() const layerz += m_LayerPanel->GetWindowBorderSize(); - // size of m_RenderScrolledWindow -------------- widths = m_RenderFlexGridSizer->GetColWidths(); totWidth = 0; @@ -613,6 +615,7 @@ wxSize LAYER_WIDGET::GetBestSize() const totWidth += widths[i] + m_RenderFlexGridSizer->GetHGap(); } } + // account for the parent's frame, this one has void space of 10 PLUS a border: totWidth += 15; @@ -713,6 +716,7 @@ void LAYER_WIDGET::SelectLayer( LAYER_NUM aLayer ) LAYER_NUM LAYER_WIDGET::GetSelectedLayer() { wxWindow* w = getLayerComp( m_CurrentRow, 0 ); + if( w ) return getDecodedId( w->GetId() ); @@ -730,6 +734,7 @@ void LAYER_WIDGET::SetLayerVisible( LAYER_NUM aLayer, bool isVisible ) void LAYER_WIDGET::setLayerCheckbox( LAYER_NUM aLayer, bool isVisible ) { int row = findLayerRow( aLayer ); + if( row >= 0 ) { wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB ); @@ -742,12 +747,14 @@ void LAYER_WIDGET::setLayerCheckbox( LAYER_NUM aLayer, bool isVisible ) bool LAYER_WIDGET::IsLayerVisible( LAYER_NUM aLayer ) { int row = findLayerRow( aLayer ); + if( row >= 0 ) { wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB ); wxASSERT( cb ); return cb->GetValue(); } + return false; } @@ -755,6 +762,7 @@ bool LAYER_WIDGET::IsLayerVisible( LAYER_NUM aLayer ) void LAYER_WIDGET::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor ) { int row = findLayerRow( aLayer ); + if( row >= 0 ) { int col = 1; // bitmap button is column 1 @@ -769,6 +777,7 @@ void LAYER_WIDGET::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor ) COLOR4D LAYER_WIDGET::GetLayerColor( LAYER_NUM aLayer ) const { int row = findLayerRow( aLayer ); + if( row >= 0 ) { int col = 1; // bitmap button is column 1 @@ -853,10 +862,9 @@ void LAYER_WIDGET::UpdateLayerIcons() /** - * MYFRAME - * is a test class here to exercise the LAYER_WIDGET and explore use cases. - * @see http://www.kirix.com/labs/wxaui/screenshots.html - * for ideas. + * A test class here to exercise the LAYER_WIDGET and explore use cases. + * + * @see http://www.kirix.com/labs/wxaui/screenshots.html for ideas. */ class MYFRAME : public wxFrame { @@ -905,7 +913,7 @@ class MYFRAME : public wxFrame public: MYFRAME( wxWindow * parent ) : wxFrame( parent, -1, wxT( "wxAUI Test" ), wxDefaultPosition, - wxSize( 800, 600 ), wxDEFAULT_FRAME_STYLE ) + wxSize( 800, 600 ), wxDEFAULT_FRAME_STYLE ) { // notify wxAUI which frame to use m_mgr.SetManagedWindow( this ); @@ -914,19 +922,20 @@ public: // add some layer rows static const LAYER_WIDGET::ROW layerRows[] = { - LAYER_WIDGET::ROW( wxT("layer 1"), 0, RED, wxT("RED"), false ), - LAYER_WIDGET::ROW( wxT("layer 2"), 1, GREEN, wxT("GREEN"), true ), - LAYER_WIDGET::ROW( wxT("brown_layer"), 2, BROWN, wxT("BROWN"), true ), - LAYER_WIDGET::ROW( wxT("layer_4_you"), 3, BLUE, wxT("BLUE"), false ), + LAYER_WIDGET::ROW( wxT( "layer 1" ), 0, RED, wxT( "RED" ), false ), + LAYER_WIDGET::ROW( wxT( "layer 2" ), 1, GREEN, wxT( "GREEN" ), true ), + LAYER_WIDGET::ROW( wxT( "brown_layer" ), 2, BROWN, wxT( "BROWN" ), true ), + LAYER_WIDGET::ROW( wxT( "layer_4_you" ), 3, BLUE, wxT( "BLUE" ), false ), }; lw->AppendLayerRows( layerRows, arrayDim(layerRows) ); // add some render rows static const LAYER_WIDGET::ROW renderRows[] = { - LAYER_WIDGET::ROW( wxT("With Very Large Ears"), 0, COLOR4D::UNSPECIFIED, wxT("Spock here") ), - LAYER_WIDGET::ROW( wxT("With Legs"), 1, YELLOW ), - LAYER_WIDGET::ROW( wxT("With Oval Eyes"), 1, BROWN, wxT("My eyes are upon you") ), + LAYER_WIDGET::ROW( wxT( "With Very Large Ears" ), 0, COLOR4D::UNSPECIFIED, + wxT( "Spock here" ) ), + LAYER_WIDGET::ROW( wxT( "With Legs" ), 1, YELLOW ), + LAYER_WIDGET::ROW( wxT( "With Oval Eyes" ), 1, BROWN, wxT( "My eyes are upon you" ) ), }; lw->AppendRenderRows( renderRows, arrayDim(renderRows) ); @@ -937,8 +946,6 @@ public: li.MinSize( lw->GetBestSize() ); li.BestSize( lw->GetBestSize() ); li.Left(); -// li.MaximizeButton( true ); -// li.MinimizeButton( true ); li.CloseButton( false ); li.Caption( wxT( "Layers" ) ); m_mgr.AddPane( lw, li ); @@ -976,7 +983,7 @@ public: bool OnInit() { - wxFrame* frame = new MYFRAME( NULL ); + wxFrame* frame = new MYFRAME( nullptr ); SetTopWindow( frame ); frame->Show();