From 369d813a32d09c5c3d4c27ea3977ff0d79be53ee Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Tue, 27 Jul 2021 13:29:35 -0400 Subject: [PATCH] Pass std::string by reference instead of on the stack where applicable. --- libs/sexpr/include/sexpr/sexpr.h | 33 +- libs/sexpr/include/sexpr/sexpr_exception.h | 8 +- libs/sexpr/include/sexpr/sexpr_parser.h | 3 +- pcbnew/plugins/fabmaster/import_fabmaster.cpp | 6 +- pcbnew/plugins/fabmaster/import_fabmaster.h | 6 +- utils/idftools/idf_outlines.cpp | 643 +++++++------- utils/idftools/idf_outlines.h | 681 +++++++------- utils/idftools/idf_parser.cpp | 414 +++++---- utils/idftools/idf_parser.h | 837 +++++++++--------- 9 files changed, 1306 insertions(+), 1325 deletions(-) diff --git a/libs/sexpr/include/sexpr/sexpr.h b/libs/sexpr/include/sexpr/sexpr.h index 9e010e7baa..375caf049e 100644 --- a/libs/sexpr/include/sexpr/sexpr.h +++ b/libs/sexpr/include/sexpr/sexpr.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Mark Roszko + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,12 +44,6 @@ namespace SEXPR class SEXPR { - protected: - SEXPR_TYPE m_type; - SEXPR( SEXPR_TYPE aType, size_t aLineNumber ); - SEXPR( SEXPR_TYPE aType ); - size_t m_lineNumber; - public: virtual ~SEXPR() {}; bool IsList() const { return m_type == SEXPR_TYPE::SEXPR_TYPE_LIST; } @@ -69,6 +64,12 @@ namespace SEXPR SEXPR_LIST* GetList(); std::string AsString( size_t aLevel = 0) const; size_t GetLineNumber() const { return m_lineNumber; } + + protected: + SEXPR_TYPE m_type; + SEXPR( SEXPR_TYPE aType, size_t aLineNumber ); + SEXPR( SEXPR_TYPE aType ); + size_t m_lineNumber; }; struct SEXPR_INTEGER : public SEXPR @@ -97,10 +98,10 @@ namespace SEXPR { std::string m_value; - SEXPR_STRING( std::string aValue ) : - SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_STRING ), m_value(aValue) {}; + SEXPR_STRING( const std::string& aValue ) : + SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_STRING ), m_value( aValue ) {}; - SEXPR_STRING( std::string aValue, int aLineNumber ) : + SEXPR_STRING( const std::string& aValue, int aLineNumber ) : SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_STRING, aLineNumber ), m_value( aValue ) {}; }; @@ -108,10 +109,10 @@ namespace SEXPR { std::string m_value; - SEXPR_SYMBOL( std::string aValue ) : + SEXPR_SYMBOL( const std::string& aValue ) : SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_SYMBOL ), m_value( aValue ) {}; - SEXPR_SYMBOL( std::string aValue, int aLineNumber ) : + SEXPR_SYMBOL( const std::string& aValue, int aLineNumber ) : SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_SYMBOL, aLineNumber ), m_value( aValue ) {}; }; @@ -153,8 +154,6 @@ namespace SEXPR class SEXPR_SCAN_ARG { - friend class SEXPR_LIST; - public: SEXPR_SCAN_ARG( int32_t* aValue ) : type( Type::INT ) { u.int_value = aValue; } @@ -181,6 +180,8 @@ namespace SEXPR type( Type::STRING_COMP ) { str_value = aValue; } private: + friend class SEXPR_LIST; + enum class Type : char { INT, DOUBLE, STRING, LONGINT, STRING_COMP, SEXPR_STRING }; Type type; @@ -198,8 +199,6 @@ namespace SEXPR class SEXPR_CHILDREN_ARG { - friend class SEXPR_LIST; - public: SEXPR_CHILDREN_ARG( int32_t aValue ) : type( Type::INT ) { u.int_value = aValue; } @@ -210,7 +209,7 @@ namespace SEXPR SEXPR_CHILDREN_ARG( double aValue ) : type( Type::DOUBLE ) { u.dbl_value = aValue; } - SEXPR_CHILDREN_ARG( std::string aValue ) : + SEXPR_CHILDREN_ARG( const std::string& aValue ) : type( Type::STRING ) { str_value = aValue; } SEXPR_CHILDREN_ARG( const char* aValue ) : @@ -223,6 +222,8 @@ namespace SEXPR type( Type::SEXPR_ATOM ) { u.sexpr_ptr = aPointer; } private: + friend class SEXPR_LIST; + enum class Type : char { INT, DOUBLE, STRING, LONGINT, SEXPR_STRING, SEXPR_ATOM }; Type type; diff --git a/libs/sexpr/include/sexpr/sexpr_exception.h b/libs/sexpr/include/sexpr/sexpr_exception.h index 5f50227597..9bdee01546 100644 --- a/libs/sexpr/include/sexpr/sexpr_exception.h +++ b/libs/sexpr/include/sexpr/sexpr_exception.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2016 Mark Roszko - * 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 @@ -27,9 +27,10 @@ namespace SEXPR class PARSE_EXCEPTION : public std::exception { public: - PARSE_EXCEPTION( const std::string aMessage ) : msg( aMessage ) {} + PARSE_EXCEPTION( const std::string& aMessage ) : msg( aMessage ) {} const char* what() const noexcept override { return msg.c_str(); } virtual ~PARSE_EXCEPTION() noexcept {} + private: std::string msg; }; @@ -37,9 +38,10 @@ namespace SEXPR class INVALID_TYPE_EXCEPTION : public std::exception { public: - INVALID_TYPE_EXCEPTION( const std::string aMessage ) : msg( aMessage ) {} + INVALID_TYPE_EXCEPTION( const std::string& aMessage ) : msg( aMessage ) {} const char* what() const noexcept override { return msg.c_str(); } virtual ~INVALID_TYPE_EXCEPTION() noexcept {} + private: std::string msg; }; diff --git a/libs/sexpr/include/sexpr/sexpr_parser.h b/libs/sexpr/include/sexpr/sexpr_parser.h index f918619960..552e7bceb7 100644 --- a/libs/sexpr/include/sexpr/sexpr_parser.h +++ b/libs/sexpr/include/sexpr/sexpr_parser.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Mark Roszko + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,7 +35,7 @@ namespace SEXPR ~PARSER(); std::unique_ptr Parse( const std::string& aString ); std::unique_ptr ParseFromFile( const std::string& aFilename ); - static std::string GetFileContents( const std::string &aFilename ); + static std::string GetFileContents( const std::string& aFilename ); private: std::unique_ptr parseString( diff --git a/pcbnew/plugins/fabmaster/import_fabmaster.cpp b/pcbnew/plugins/fabmaster/import_fabmaster.cpp index e7ff2a8f61..28ab27fd12 100644 --- a/pcbnew/plugins/fabmaster/import_fabmaster.cpp +++ b/pcbnew/plugins/fabmaster/import_fabmaster.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 BeagleBoard Foundation - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. * Author: Seth Hillbrand * * This program is free software; you can redistribute it and/or @@ -78,7 +78,7 @@ void FABMASTER::checkpoint() } -double FABMASTER::readDouble( const std::string aStr ) const +double FABMASTER::readDouble( const std::string& aStr ) const { std::istringstream istr( aStr ); istr.imbue( std::locale::classic() ); @@ -89,7 +89,7 @@ double FABMASTER::readDouble( const std::string aStr ) const } -int FABMASTER::readInt( const std::string aStr ) const +int FABMASTER::readInt( const std::string& aStr ) const { std::istringstream istr( aStr ); istr.imbue( std::locale::classic() ); diff --git a/pcbnew/plugins/fabmaster/import_fabmaster.h b/pcbnew/plugins/fabmaster/import_fabmaster.h index 07a26bf4ae..2a46e33524 100644 --- a/pcbnew/plugins/fabmaster/import_fabmaster.h +++ b/pcbnew/plugins/fabmaster/import_fabmaster.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. * Author: Seth Hillbrand * * This program is free software; you can redistribute it and/or @@ -554,8 +554,8 @@ private: * @param aStr string to generate value from * @return 0 if value cannot be created */ - double readDouble( const std::string aStr ) const; - int readInt( const std::string aStr ) const; + double readDouble( const std::string& aStr ) const; + int readInt( const std::string& aStr ) const; /** * Sets zone priorities based on zone BB size. Larger bounding boxes get smaller priorities diff --git a/utils/idftools/idf_outlines.cpp b/utils/idftools/idf_outlines.cpp index 7ffdcba0bc..ffa3485c4a 100644 --- a/utils/idftools/idf_outlines.cpp +++ b/utils/idftools/idf_outlines.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2017 Cirilo Bernardo + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -39,35 +40,35 @@ static std::string GetOutlineTypeString( IDF3::OUTLINE_TYPE aOutlineType ) { switch( aOutlineType ) { - case OTLN_BOARD: - return ".BOARD_OUTLINE"; + case OTLN_BOARD: + return ".BOARD_OUTLINE"; - case OTLN_OTHER: - return ".OTHER_OUTLINE"; + case OTLN_OTHER: + return ".OTHER_OUTLINE"; - case OTLN_PLACE: - return ".PLACEMENT_OUTLINE"; + case OTLN_PLACE: + return ".PLACEMENT_OUTLINE"; - case OTLN_ROUTE: - return ".ROUTE_OUTLINE"; + case OTLN_ROUTE: + return ".ROUTE_OUTLINE"; - case OTLN_PLACE_KEEPOUT: - return ".PLACE_KEEPOUT"; + case OTLN_PLACE_KEEPOUT: + return ".PLACE_KEEPOUT"; - case OTLN_ROUTE_KEEPOUT: - return ".ROUTE_KEEPOUT"; + case OTLN_ROUTE_KEEPOUT: + return ".ROUTE_KEEPOUT"; - case OTLN_VIA_KEEPOUT: - return ".VIA_KEEPOUT"; + case OTLN_VIA_KEEPOUT: + return ".VIA_KEEPOUT"; - case OTLN_GROUP_PLACE: - return ".PLACE_REGION"; + case OTLN_GROUP_PLACE: + return ".PLACE_REGION"; - case OTLN_COMPONENT: - return "COMPONENT OUTLINE"; + case OTLN_COMPONENT: + return "COMPONENT OUTLINE"; - default: - break; + default: + break; } std::ostringstream ostr; @@ -76,12 +77,13 @@ static std::string GetOutlineTypeString( IDF3::OUTLINE_TYPE aOutlineType ) return ostr.str(); } + #ifndef DISABLE_IDF_OWNERSHIP static bool CheckOwnership( int aSourceLine, const char* aSourceFunc, IDF3_BOARD* aParent, IDF3::KEY_OWNER aOwnerCAD, IDF3::OUTLINE_TYPE aOutlineType, std::string& aErrorString ) { - if( aParent == NULL ) + if( aParent == nullptr ) { ostringstream ostr; ostr << "* " << __FILE__ << ":" << aSourceLine << ":" << aSourceFunc << "():\n"; @@ -127,31 +129,29 @@ static bool CheckOwnership( int aSourceLine, const char* aSourceFunc, #endif -/* - * BOARD OUTLINE - */ BOARD_OUTLINE::BOARD_OUTLINE() { outlineType = OTLN_BOARD; single = false; owner = UNOWNED; - parent = NULL; + parent = nullptr; thickness = 0.0; unit = UNIT_MM; - return; } + BOARD_OUTLINE::~BOARD_OUTLINE() { clear(); - return; } + IDF3::OUTLINE_TYPE BOARD_OUTLINE::GetOutlineType( void ) { return outlineType; } + void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aIdfVersion ) { // reads the outline data from a file @@ -167,8 +167,8 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI std::string iline; std::string entry; std::stringstream tstr; - IDF_OUTLINE* op = NULL; - IDF_SEGMENT* sp = NULL; + IDF_OUTLINE* op = nullptr; + IDF_SEGMENT* sp = nullptr; IDF_POINT prePt; IDF_POINT curPt; std::streampos pos; @@ -188,7 +188,8 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI { ostringstream ostr; - ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << GetOutlineTypeString( outlineType ); + ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << + GetOutlineTypeString( outlineType ); ostr << " is quoted\n"; ostr << "* line: '" << iline << "'"; @@ -201,7 +202,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI // rewind to the start of the last line; the routine invoking // this is responsible for checking that the current '.END_ ...' // matches the section header. - if(aBoardFile.eof()) + if( aBoardFile.eof() ) aBoardFile.clear(); aBoardFile.seekg( pos ); @@ -227,7 +228,8 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI return; } - if( outlines.size() > 1 && outlines.back()->IsCCW() && !outlines.back()->IsCircle() ) + if( outlines.size() > 1 && outlines.back()->IsCCW() && + !outlines.back()->IsCircle() ) { ERROR_IDF << "invalid IDF3 file (BOARD_OUTLINE)\n"; cerr << "* WARNING: final cutout does not have points in CW order\n"; @@ -244,6 +246,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI tstr << entry; tstr >> tmp; + if( tstr.fail() ) { if( outlineType == OTLN_COMPONENT && CompareToken( "PROP", entry ) ) @@ -252,10 +255,12 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI return; } - do{ + do + { ostringstream ostr; - ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << GetOutlineTypeString( outlineType ); + ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << + GetOutlineTypeString( outlineType ); ostr << " is not numeric\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* file position: " << pos; @@ -281,7 +286,8 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI { ostringstream ostr; - ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << GetOutlineTypeString( outlineType ); + ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << + GetOutlineTypeString( outlineType ); ostr << " is invalid\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* file position: " << pos; @@ -299,7 +305,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI { op = new IDF_OUTLINE; - if( op == NULL ) + if( op == nullptr ) { clearOutlines(); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, @@ -313,7 +319,8 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI { ostringstream ostr; - ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << GetOutlineTypeString( outlineType ); + ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << + GetOutlineTypeString( outlineType ); ostr << " is invalid (must be 0 or 1)\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* file position: " << pos; @@ -328,7 +335,8 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI { ostringstream ostr; - ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << GetOutlineTypeString( outlineType ); + ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << + GetOutlineTypeString( outlineType ); ostr << " is invalid (must be 0)\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* file position: " << pos; @@ -338,7 +346,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI op = new IDF_OUTLINE; - if( op == NULL ) + if( op == nullptr ) { clearOutlines(); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, @@ -348,7 +356,6 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI outlines.push_back( op ); loopidx = tmp; } - // end of block for first outline } else { @@ -384,7 +391,8 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI ostringstream ostr; ostr << "\n* invalid outline: " << GetOutlineTypeString( outlineType ) << "\n"; - ostr << "* violation of loop point order rules by Loop Index " << loopidx << "\n"; + ostr << "* violation of loop point order rules by Loop Index " << loopidx << + "\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* file position: " << pos; @@ -393,7 +401,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI op = new IDF_OUTLINE; - if( op == NULL ) + if( op == nullptr ) { clearOutlines(); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, @@ -408,11 +416,12 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI closed = false; } - if( op == NULL ) + if( op == nullptr ) { ostringstream ostr; - ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << GetOutlineTypeString( outlineType ); + ostr << "\n* invalid outline: RECORD 3, FIELD 1 of " << + GetOutlineTypeString( outlineType ); ostr << " is invalid\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* file position: " << pos; @@ -448,6 +457,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI tstr << entry; tstr >> x; + if( tstr.fail() ) { ostringstream ostr; @@ -488,6 +498,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI tstr << entry; tstr >> y; + if( tstr.fail() ) { ostringstream ostr; @@ -528,6 +539,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI tstr << entry; tstr >> ang; + if( tstr.fail() ) { ostringstream ostr; @@ -607,7 +619,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI sp = new IDF_SEGMENT( prePt, curPt, ang, false ); } - if( sp == NULL ) + if( sp == nullptr ) { clearOutlines(); throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, @@ -644,7 +656,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI prePt.x = x; prePt.y = y; } - } // while( aBoardFile.good() ) + } // NOTE: // 1. ideally we would ensure that there are no arcs with a radius of 0 @@ -655,6 +667,7 @@ void BOARD_OUTLINE::readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aI return; } + bool BOARD_OUTLINE::writeComments( std::ostream& aBoardFile ) { if( comments.empty() ) @@ -672,26 +685,28 @@ bool BOARD_OUTLINE::writeComments( std::ostream& aBoardFile ) return !aBoardFile.fail(); } + bool BOARD_OUTLINE::writeOwner( std::ostream& aBoardFile ) { switch( owner ) { - case ECAD: - aBoardFile << "ECAD\n"; - break; + case ECAD: + aBoardFile << "ECAD\n"; + break; - case MCAD: - aBoardFile << "MCAD\n"; - break; + case MCAD: + aBoardFile << "MCAD\n"; + break; - default: - aBoardFile << "UNOWNED\n"; - break; + default: + aBoardFile << "UNOWNED\n"; + break; } return !aBoardFile.fail(); } + void BOARD_OUTLINE::writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutline, size_t aIndex ) { std::list::iterator bo; @@ -699,7 +714,7 @@ void BOARD_OUTLINE::writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutlin if( !aOutline ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, - "\n* BUG: NULL outline pointer" ) ); + "\n* BUG: nullptr outline pointer" ) ); if( aOutline->size() == 1 ) { @@ -748,8 +763,7 @@ void BOARD_OUTLINE::writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutlin // check if we must reverse things - if( ( aOutline->IsCCW() && ( aIndex > 0 ) ) - || ( ( !aOutline->IsCCW() ) && ( aIndex == 0 ) ) ) + if( ( aOutline->IsCCW() && ( aIndex > 0 ) ) || ( ( !aOutline->IsCCW() ) && ( aIndex == 0 ) ) ) { eo = aOutline->begin(); bo = aOutline->end(); @@ -768,48 +782,48 @@ void BOARD_OUTLINE::writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutlin { if( aOutline->front()->angle < MIN_ANG && aOutline->front()->angle > -MIN_ANG ) { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << aOutline->front()->endPoint.x << " " - << aOutline->front()->endPoint.y << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << aOutline->front()->endPoint.x << " " << aOutline->front()->endPoint.y + << " 0\n"; - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << aOutline->front()->startPoint.x << " " - << aOutline->front()->startPoint.y << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << aOutline->front()->startPoint.x << " " + << aOutline->front()->startPoint.y << " 0\n"; } else { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << aOutline->front()->endPoint.x << " " - << aOutline->front()->endPoint.y << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << aOutline->front()->endPoint.x << " " << aOutline->front()->endPoint.y + << " 0\n"; - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << aOutline->front()->startPoint.x << " " - << aOutline->front()->startPoint.y << " " - << setprecision(3) << -aOutline->front()->angle << "\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << aOutline->front()->startPoint.x << " " + << aOutline->front()->startPoint.y << " " << setprecision( 3 ) + << -aOutline->front()->angle << "\n"; } } else { if( aOutline->front()->angle < MIN_ANG && aOutline->front()->angle > -MIN_ANG ) { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << (aOutline->front()->endPoint.x / IDF_THOU_TO_MM) << " " - << (aOutline->front()->endPoint.y / IDF_THOU_TO_MM) << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( aOutline->front()->endPoint.x / IDF_THOU_TO_MM ) << " " + << ( aOutline->front()->endPoint.y / IDF_THOU_TO_MM ) << " 0\n"; - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << (aOutline->front()->startPoint.x / IDF_THOU_TO_MM) << " " - << (aOutline->front()->startPoint.y / IDF_THOU_TO_MM) << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( aOutline->front()->startPoint.x / IDF_THOU_TO_MM ) << " " + << ( aOutline->front()->startPoint.y / IDF_THOU_TO_MM ) << " 0\n"; } else { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << (aOutline->front()->endPoint.x / IDF_THOU_TO_MM) << " " - << (aOutline->front()->endPoint.y / IDF_THOU_TO_MM) << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( aOutline->front()->endPoint.x / IDF_THOU_TO_MM ) << " " + << ( aOutline->front()->endPoint.y / IDF_THOU_TO_MM ) << " 0\n"; - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << (aOutline->front()->startPoint.x / IDF_THOU_TO_MM) << " " - << (aOutline->front()->startPoint.y / IDF_THOU_TO_MM) << " " - << setprecision(3) << -aOutline->front()->angle << "\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( aOutline->front()->startPoint.x / IDF_THOU_TO_MM ) << " " + << ( aOutline->front()->startPoint.y / IDF_THOU_TO_MM ) << " " + << setprecision( 3 ) << -aOutline->front()->angle << "\n"; } } @@ -818,34 +832,32 @@ void BOARD_OUTLINE::writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutlin { if( unit != UNIT_THOU ) { - if( (*bo)->angle < MIN_ANG && (*bo)->angle > -MIN_ANG ) + if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG ) { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << (*bo)->startPoint.x << " " - << (*bo)->startPoint.y << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << ( *bo )->startPoint.x << " " << ( *bo )->startPoint.y << " 0\n"; } else { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << (*bo)->startPoint.x << " " - << (*bo)->startPoint.y << " " - << setprecision(3) << -(*bo)->angle << "\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << ( *bo )->startPoint.x << " " << ( *bo )->startPoint.y << " " + << setprecision( 3 ) << -( *bo )->angle << "\n"; } } else { - if( (*bo)->angle < MIN_ANG && (*bo)->angle > -MIN_ANG ) + if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG ) { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << ((*bo)->startPoint.x / IDF_THOU_TO_MM) << " " - << ((*bo)->startPoint.y / IDF_THOU_TO_MM) << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( ( *bo )->startPoint.x / IDF_THOU_TO_MM ) << " " + << ( ( *bo )->startPoint.y / IDF_THOU_TO_MM ) << " 0\n"; } else { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << ((*bo)->startPoint.x / IDF_THOU_TO_MM) << " " - << ((*bo)->startPoint.y / IDF_THOU_TO_MM) << " " - << setprecision(3) << -(*bo)->angle << "\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( ( *bo )->startPoint.x / IDF_THOU_TO_MM ) << " " + << ( ( *bo )->startPoint.y / IDF_THOU_TO_MM ) << " " + << setprecision( 3 ) << -( *bo )->angle << "\n"; } } @@ -864,50 +876,46 @@ void BOARD_OUTLINE::writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutlin // for the first item we write out both points if( unit != UNIT_THOU ) { - if( (*bo)->angle < MIN_ANG && (*bo)->angle > -MIN_ANG ) + if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG ) { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << (*bo)->startPoint.x << " " - << (*bo)->startPoint.y << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << ( *bo )->startPoint.x << " " << ( *bo )->startPoint.y << " 0\n"; - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << (*bo)->endPoint.x << " " - << (*bo)->endPoint.y << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << ( *bo )->endPoint.x << " " << ( *bo )->endPoint.y << " 0\n"; } else { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << (*bo)->startPoint.x << " " - << (*bo)->startPoint.y << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << ( *bo )->startPoint.x << " " << ( *bo )->startPoint.y << " 0\n"; - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << (*bo)->endPoint.x << " " - << (*bo)->endPoint.y << " " - << setprecision(3) << (*bo)->angle << "\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << ( *bo )->endPoint.x << " " << ( *bo )->endPoint.y << " " + << setprecision( 3 ) << ( *bo )->angle << "\n"; } } else { - if( (*bo)->angle < MIN_ANG && (*bo)->angle > -MIN_ANG ) + if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG ) { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << ((*bo)->startPoint.x / IDF_THOU_TO_MM) << " " - << ((*bo)->startPoint.y / IDF_THOU_TO_MM) << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( ( *bo )->startPoint.x / IDF_THOU_TO_MM ) << " " + << ( ( *bo )->startPoint.y / IDF_THOU_TO_MM ) << " 0\n"; - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << ((*bo)->endPoint.x / IDF_THOU_TO_MM) << " " - << ((*bo)->endPoint.y / IDF_THOU_TO_MM) << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( ( *bo )->endPoint.x / IDF_THOU_TO_MM ) << " " + << ( ( *bo )->endPoint.y / IDF_THOU_TO_MM ) << " 0\n"; } else { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << ((*bo)->startPoint.x / IDF_THOU_TO_MM) << " " - << ((*bo)->startPoint.y / IDF_THOU_TO_MM) << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( ( *bo )->startPoint.x / IDF_THOU_TO_MM ) << " " + << ( ( *bo )->startPoint.y / IDF_THOU_TO_MM ) << " 0\n"; - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << ((*bo)->endPoint.x / IDF_THOU_TO_MM) << " " - << ((*bo)->endPoint.y / IDF_THOU_TO_MM) << " " - << setprecision(3) << (*bo)->angle << "\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( ( *bo )->endPoint.x / IDF_THOU_TO_MM ) << " " + << ( ( *bo )->endPoint.y / IDF_THOU_TO_MM ) << " " << setprecision( 3 ) + << ( *bo )->angle << "\n"; } } @@ -918,44 +926,41 @@ void BOARD_OUTLINE::writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutlin { if( unit != UNIT_THOU ) { - if( (*bo)->angle < MIN_ANG && (*bo)->angle > -MIN_ANG ) + if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG ) { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << (*bo)->endPoint.x << " " - << (*bo)->endPoint.y << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << ( *bo )->endPoint.x << " " << ( *bo )->endPoint.y << " 0\n"; } else { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(5) - << (*bo)->endPoint.x << " " - << (*bo)->endPoint.y << " " - << setprecision(3) << (*bo)->angle << "\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 5 ) + << ( *bo )->endPoint.x << " " << ( *bo )->endPoint.y << " " + << setprecision( 3 ) << ( *bo )->angle << "\n"; } } else { - if( (*bo)->angle < MIN_ANG && (*bo)->angle > -MIN_ANG ) + if( ( *bo )->angle < MIN_ANG && ( *bo )->angle > -MIN_ANG ) { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << ((*bo)->endPoint.x / IDF_THOU_TO_MM) << " " - << ((*bo)->endPoint.y / IDF_THOU_TO_MM) << " 0\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( ( *bo )->endPoint.x / IDF_THOU_TO_MM ) << " " + << ( ( *bo )->endPoint.y / IDF_THOU_TO_MM ) << " 0\n"; } else { - aBoardFile << aIndex << " " << setiosflags(ios::fixed) << setprecision(1) - << ((*bo)->endPoint.x / IDF_THOU_TO_MM) << " " - << ((*bo)->endPoint.y / IDF_THOU_TO_MM) << " " - << setprecision(3) << (*bo)->angle << "\n"; + aBoardFile << aIndex << " " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( ( *bo )->endPoint.x / IDF_THOU_TO_MM ) << " " + << ( ( *bo )->endPoint.y / IDF_THOU_TO_MM ) << " " + << setprecision( 3 ) << ( *bo )->angle << "\n"; } } ++bo; } } - - return; } + void BOARD_OUTLINE::writeOutlines( std::ostream& aBoardFile ) { if( outlines.empty() ) @@ -970,10 +975,9 @@ void BOARD_OUTLINE::writeOutlines( std::ostream& aBoardFile ) writeOutline( aBoardFile, *itS, idx++ ); ++itS; } - - return; } + bool BOARD_OUTLINE::SetUnit( IDF3::IDF_UNIT aUnit ) { // note: although UNIT_TNM is accepted here without reservation, @@ -993,11 +997,13 @@ bool BOARD_OUTLINE::SetUnit( IDF3::IDF_UNIT aUnit ) return true; } + IDF3::IDF_UNIT BOARD_OUTLINE::GetUnit( void ) { return unit; } + bool BOARD_OUTLINE::setThickness( double aThickness ) { if( aThickness < 0.0 ) @@ -1015,6 +1021,7 @@ bool BOARD_OUTLINE::setThickness( double aThickness ) return true; } + bool BOARD_OUTLINE::SetThickness( double aThickness ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1025,6 +1032,7 @@ bool BOARD_OUTLINE::SetThickness( double aThickness ) return setThickness( aThickness ); } + double BOARD_OUTLINE::GetThickness( void ) { return thickness; @@ -1047,7 +1055,8 @@ void BOARD_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead pos = aBoardFile.tellg(); if( !GetIDFString( aHeader, token, quoted, idx ) ) - throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid invocation: blank header line" ) ); + throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, + "invalid invocation: blank header line" ) ); if( quoted ) { @@ -1106,6 +1115,7 @@ void BOARD_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -1133,6 +1143,7 @@ void BOARD_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead teststr << token; teststr >> thickness; + if( teststr.fail() ) { ostringstream ostr; @@ -1197,6 +1208,7 @@ void BOARD_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -1219,8 +1231,6 @@ void BOARD_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } - - return; } @@ -1234,15 +1244,14 @@ void BOARD_OUTLINE::writeData( std::ostream& aBoardFile ) writeOwner( aBoardFile ); if( unit != UNIT_THOU ) - aBoardFile << setiosflags(ios::fixed) << setprecision(5) << thickness << "\n"; + aBoardFile << setiosflags( ios::fixed ) << setprecision( 5 ) << thickness << "\n"; else - aBoardFile << setiosflags(ios::fixed) << setprecision(1) << (thickness / IDF_THOU_TO_MM) << "\n"; + aBoardFile << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( thickness / IDF_THOU_TO_MM ) << "\n"; writeOutlines( aBoardFile ); aBoardFile << ".END_BOARD_OUTLINE\n\n"; - - return; } void BOARD_OUTLINE::clear( void ) @@ -1254,6 +1263,7 @@ void BOARD_OUTLINE::clear( void ) return; } + bool BOARD_OUTLINE::Clear( void ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1266,16 +1276,19 @@ bool BOARD_OUTLINE::Clear( void ) return true; } + void BOARD_OUTLINE::setParent( IDF3_BOARD* aParent ) { parent = aParent; } + IDF3_BOARD* BOARD_OUTLINE::GetParent( void ) { return parent; } + bool BOARD_OUTLINE::addOutline( IDF_OUTLINE* aOutline ) { std::list< IDF_OUTLINE* >::iterator itS = outlines.begin(); @@ -1305,6 +1318,7 @@ bool BOARD_OUTLINE::addOutline( IDF_OUTLINE* aOutline ) return true; } + bool BOARD_OUTLINE::AddOutline( IDF_OUTLINE* aOutline ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1315,6 +1329,7 @@ bool BOARD_OUTLINE::AddOutline( IDF_OUTLINE* aOutline ) return addOutline( aOutline ); } + bool BOARD_OUTLINE::DelOutline( IDF_OUTLINE* aOutline ) { std::list< IDF_OUTLINE* >::iterator itS = outlines.begin(); @@ -1324,7 +1339,7 @@ bool BOARD_OUTLINE::DelOutline( IDF_OUTLINE* aOutline ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; - ostr << "* BUG: NULL aOutline pointer\n"; + ostr << "* BUG: nullptr aOutline pointer\n"; ostr << "* outline type: " << GetOutlineTypeString( outlineType ); errormsg = ostr.str(); @@ -1425,16 +1440,19 @@ bool BOARD_OUTLINE::DelOutline( size_t aIndex ) return true; } + const std::list< IDF_OUTLINE* >*const BOARD_OUTLINE::GetOutlines( void ) { return &outlines; } + size_t BOARD_OUTLINE::OutlinesSize( void ) { return outlines.size(); } + IDF_OUTLINE* BOARD_OUTLINE::GetOutline( size_t aIndex ) { if( aIndex >= outlines.size() ) @@ -1444,7 +1462,7 @@ IDF_OUTLINE* BOARD_OUTLINE::GetOutline( size_t aIndex ) ostr << "* aIndex (" << aIndex << ") is out of range (" << outlines.size() << ")"; errormsg = ostr.str(); - return NULL; + return nullptr; } std::list< IDF_OUTLINE* >::iterator itS = outlines.begin(); @@ -1455,11 +1473,13 @@ IDF_OUTLINE* BOARD_OUTLINE::GetOutline( size_t aIndex ) return *itS; } + IDF3::KEY_OWNER BOARD_OUTLINE::GetOwner( void ) { return owner; } + bool BOARD_OUTLINE::SetOwner( IDF3::KEY_OWNER aOwner ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1471,11 +1491,13 @@ bool BOARD_OUTLINE::SetOwner( IDF3::KEY_OWNER aOwner ) return true; } + bool BOARD_OUTLINE::IsSingle( void ) { return single; } + void BOARD_OUTLINE::clearOutlines( void ) { std::list< IDF_OUTLINE* >::iterator itS = outlines.begin(); @@ -1488,32 +1510,34 @@ void BOARD_OUTLINE::clearOutlines( void ) } outlines.clear(); - return; } + void BOARD_OUTLINE::AddComment( const std::string& aComment ) { if( aComment.empty() ) return; comments.push_back( aComment ); - return; } + size_t BOARD_OUTLINE::CommentsSize( void ) { return comments.size(); } + std::list< std::string >* BOARD_OUTLINE::GetComments( void ) { return &comments; } + const std::string* BOARD_OUTLINE::GetComment( size_t aIndex ) { if( aIndex >= comments.size() ) - return NULL; + return nullptr; std::list< std::string >::iterator itS = comments.begin(); @@ -1523,6 +1547,7 @@ const std::string* BOARD_OUTLINE::GetComment( size_t aIndex ) return &(*itS); } + bool BOARD_OUTLINE::DeleteComment( size_t aIndex ) { if( aIndex >= comments.size() ) @@ -1537,26 +1562,22 @@ bool BOARD_OUTLINE::DeleteComment( size_t aIndex ) return true; } + void BOARD_OUTLINE::ClearComments( void ) { comments.clear(); - return; } -/* - * OTHER_OUTLINE - */ OTHER_OUTLINE::OTHER_OUTLINE( IDF3_BOARD* aParent ) { setParent( aParent ); outlineType = OTLN_OTHER; side = LYR_INVALID; single = false; - - return; } + bool OTHER_OUTLINE::SetOutlineIdentifier( const std::string& aUniqueID ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1569,11 +1590,13 @@ bool OTHER_OUTLINE::SetOutlineIdentifier( const std::string& aUniqueID ) return true; } + const std::string& OTHER_OUTLINE::GetOutlineIdentifier( void ) { return uniqueID; } + bool OTHER_OUTLINE::SetSide( IDF3::IDF_LAYER aSide ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1589,7 +1612,8 @@ bool OTHER_OUTLINE::SetSide( IDF3::IDF_LAYER aSide ) break; default: - do{ + do + { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; ostr << "* BUG: invalid side (" << aSide << "); must be one of TOP/BOTTOM\n"; @@ -1606,11 +1630,13 @@ bool OTHER_OUTLINE::SetSide( IDF3::IDF_LAYER aSide ) return true; } + IDF3::IDF_LAYER OTHER_OUTLINE::GetSide( void ) { return side; } + void OTHER_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHeader, IDF3::IDF_VERSION aIdfVersion ) { @@ -1749,6 +1775,7 @@ void OTHER_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead teststr << token; teststr >> thickness; + if( teststr.fail() ) { ostringstream ostr; @@ -1828,6 +1855,7 @@ void OTHER_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -1866,10 +1894,9 @@ void OTHER_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } } - - return; } + void OTHER_OUTLINE::writeData( std::ostream& aBoardFile ) { // this section is optional; do not write if not required @@ -1892,26 +1919,28 @@ void OTHER_OUTLINE::writeData( std::ostream& aBoardFile ) aBoardFile << "\"" << uniqueID << "\" "; if( unit != UNIT_THOU ) - aBoardFile << setiosflags(ios::fixed) << setprecision(5) << thickness << " "; + aBoardFile << setiosflags( ios::fixed ) << setprecision( 5 ) << thickness << " "; else - aBoardFile << setiosflags(ios::fixed) << setprecision(1) << (thickness / IDF_THOU_TO_MM) << " "; + aBoardFile << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( thickness / IDF_THOU_TO_MM ) << " "; switch( side ) { - case LYR_TOP: - case LYR_BOTTOM: - WriteLayersText( aBoardFile, side ); - break; + case LYR_TOP: + case LYR_BOTTOM: + WriteLayersText( aBoardFile, side ); + break; - default: - do{ - ostringstream ostr; - ostr << "\n* invalid OTHER_OUTLINE side (neither top nor bottom): "; - ostr << side; - throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); - } while( 0 ); + default: + do + { + ostringstream ostr; + ostr << "\n* invalid OTHER_OUTLINE side (neither top nor bottom): "; + ostr << side; + throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); + } while( 0 ); - break; + break; } } @@ -1923,8 +1952,6 @@ void OTHER_OUTLINE::writeData( std::ostream& aBoardFile ) aBoardFile << ".END_OTHER_OUTLINE\n\n"; else aBoardFile << ".END_VIA_KEEPOUT\n\n"; - - return; } @@ -1943,9 +1970,6 @@ bool OTHER_OUTLINE::Clear( void ) } -/* - * ROUTE_OUTLINE - */ ROUTE_OUTLINE::ROUTE_OUTLINE( IDF3_BOARD* aParent ) { setParent( aParent ); @@ -1954,6 +1978,7 @@ ROUTE_OUTLINE::ROUTE_OUTLINE( IDF3_BOARD* aParent ) layers = LYR_INVALID; } + bool ROUTE_OUTLINE::SetLayers( IDF3::IDF_LAYER aLayer ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1966,11 +1991,13 @@ bool ROUTE_OUTLINE::SetLayers( IDF3::IDF_LAYER aLayer ) return true; } + IDF3::IDF_LAYER ROUTE_OUTLINE::GetLayers( void ) { return layers; } + void ROUTE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHeader, IDF3::IDF_VERSION aIdfVersion ) { @@ -2053,6 +2080,7 @@ void ROUTE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -2116,8 +2144,7 @@ void ROUTE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } } - - } // RECORD 2, conditional > IDFv2 or ROUTE_KO_OUTLINE + } else { layers = LYR_ALL; @@ -2141,6 +2168,7 @@ void ROUTE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -2179,8 +2207,6 @@ void ROUTE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } } - - return; } @@ -2216,8 +2242,6 @@ void ROUTE_OUTLINE::writeData( std::ostream& aBoardFile ) aBoardFile << ".END_ROUTE_OUTLINE\n\n"; else aBoardFile << ".END_ROUTE_KEEPOUT\n\n"; - - return; } @@ -2235,9 +2259,6 @@ bool ROUTE_OUTLINE::Clear( void ) } -/* - * PLACE_OUTLINE - */ PLACE_OUTLINE::PLACE_OUTLINE( IDF3_BOARD* aParent ) { setParent( aParent ); @@ -2257,25 +2278,26 @@ bool PLACE_OUTLINE::SetSide( IDF3::IDF_LAYER aSide ) switch( aSide ) { - case LYR_TOP: - case LYR_BOTTOM: - case LYR_BOTH: - side = aSide; - break; + case LYR_TOP: + case LYR_BOTTOM: + case LYR_BOTH: + side = aSide; + break; - default: - do{ - side = LYR_INVALID; - ostringstream ostr; - ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; - ostr << "* BUG: invalid layer (" << aSide << "): must be one of TOP/BOTTOM/BOTH\n"; - ostr << "* outline type: " << GetOutlineTypeString( outlineType ); - errormsg = ostr.str(); + default: + do + { + side = LYR_INVALID; + ostringstream ostr; + ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; + ostr << "* BUG: invalid layer (" << aSide << "): must be one of TOP/BOTTOM/BOTH\n"; + ostr << "* outline type: " << GetOutlineTypeString( outlineType ); + errormsg = ostr.str(); - return false; - } while( 0 ); + return false; + } while( 0 ); - break; + break; } return true; @@ -2299,7 +2321,8 @@ bool PLACE_OUTLINE::SetMaxHeight( double aHeight ) { thickness = 0.0; - do{ + do + { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; ostr << "* BUG: invalid height (" << aHeight << "): must be >= 0.0"; @@ -2314,11 +2337,13 @@ bool PLACE_OUTLINE::SetMaxHeight( double aHeight ) return true; } + double PLACE_OUTLINE::GetMaxHeight( void ) { return thickness; } + void PLACE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHeader, IDF3::IDF_VERSION aIdfVersion ) { @@ -2399,6 +2424,7 @@ void PLACE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -2485,7 +2511,6 @@ void PLACE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead if( thickness < 0.0 ) thickness = 0.0; - } else { @@ -2529,6 +2554,7 @@ void PLACE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -2555,10 +2581,9 @@ void PLACE_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid .PLACE_KEEPOUT section: no .END_PLACE_KEEPOUT found" ) ); } - - return; } + void PLACE_OUTLINE::writeData( std::ostream& aBoardFile ) { // this section is optional; do not write if not required @@ -2578,26 +2603,26 @@ void PLACE_OUTLINE::writeData( std::ostream& aBoardFile ) // write RECORD 2 switch( side ) { - case LYR_TOP: - case LYR_BOTTOM: - case LYR_BOTH: - WriteLayersText( aBoardFile, side ); - break; + case LYR_TOP: + case LYR_BOTTOM: + case LYR_BOTH: + WriteLayersText( aBoardFile, side ); + break; - default: - do - { - ostringstream ostr; - ostr << "\n* invalid PLACE_OUTLINE/KEEPOUT side ("; - ostr << side << "); must be one of TOP/BOTTOM/BOTH"; - throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); - } while( 0 ); + default: + do + { + ostringstream ostr; + ostr << "\n* invalid PLACE_OUTLINE/KEEPOUT side ("; + ostr << side << "); must be one of TOP/BOTTOM/BOTH"; + throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); + } while( 0 ); - break; + break; } // thickness is optional for OTLN_PLACE, but mandatory for OTLN_PLACE_KEEPOUT - if( thickness < 0.0 && outlineType == OTLN_PLACE_KEEPOUT) + if( thickness < 0.0 && outlineType == OTLN_PLACE_KEEPOUT ) { aBoardFile << "\n"; } @@ -2606,9 +2631,10 @@ void PLACE_OUTLINE::writeData( std::ostream& aBoardFile ) aBoardFile << " "; if( unit != UNIT_THOU ) - aBoardFile << setiosflags(ios::fixed) << setprecision(5) << thickness << "\n"; + aBoardFile << setiosflags( ios::fixed ) << setprecision( 5 ) << thickness << "\n"; else - aBoardFile << setiosflags(ios::fixed) << setprecision(1) << (thickness / IDF_THOU_TO_MM) << "\n"; + aBoardFile << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( thickness / IDF_THOU_TO_MM ) << "\n"; } // write RECORD 3 @@ -2639,9 +2665,6 @@ bool PLACE_OUTLINE::Clear( void ) } -/* - * ROUTE_KEEPOUT - */ ROUTE_KO_OUTLINE::ROUTE_KO_OUTLINE( IDF3_BOARD* aParent ) : ROUTE_OUTLINE( aParent ) { @@ -2650,9 +2673,6 @@ ROUTE_KO_OUTLINE::ROUTE_KO_OUTLINE( IDF3_BOARD* aParent ) } -/* - * PLACE_KEEPOUT - */ PLACE_KO_OUTLINE::PLACE_KO_OUTLINE( IDF3_BOARD* aParent ) : PLACE_OUTLINE( aParent ) { @@ -2661,9 +2681,6 @@ PLACE_KO_OUTLINE::PLACE_KO_OUTLINE( IDF3_BOARD* aParent ) } -/* - * VIA_KEEPOUT - */ VIA_KO_OUTLINE::VIA_KO_OUTLINE( IDF3_BOARD* aParent ) : OTHER_OUTLINE( aParent ) { @@ -2672,9 +2689,6 @@ VIA_KO_OUTLINE::VIA_KO_OUTLINE( IDF3_BOARD* aParent ) } -/* - * PLACEMENT GROUP (PLACE_REGION) - */ GROUP_OUTLINE::GROUP_OUTLINE( IDF3_BOARD* aParent ) { setParent( aParent ); @@ -2695,23 +2709,24 @@ bool GROUP_OUTLINE::SetSide( IDF3::IDF_LAYER aSide ) switch( aSide ) { - case LYR_TOP: - case LYR_BOTTOM: - case LYR_BOTH: - side = aSide; - break; + case LYR_TOP: + case LYR_BOTTOM: + case LYR_BOTH: + side = aSide; + break; - default: - do{ - ostringstream ostr; - ostr << "invalid side (" << aSide << "); must be one of TOP/BOTTOM/BOTH\n"; - ostr << "* outline type: " << GetOutlineTypeString( outlineType ); - errormsg = ostr.str(); + default: + do + { + ostringstream ostr; + ostr << "invalid side (" << aSide << "); must be one of TOP/BOTTOM/BOTH\n"; + ostr << "* outline type: " << GetOutlineTypeString( outlineType ); + errormsg = ostr.str(); - return false; - } while( 0 ); + return false; + } while( 0 ); - break; + break; } return true; @@ -2731,7 +2746,7 @@ bool GROUP_OUTLINE::SetGroupName( std::string aGroupName ) return false; #endif - groupName = std::move(aGroupName); + groupName = std::move( aGroupName ); return true; } @@ -2774,8 +2789,7 @@ void GROUP_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } if( !CompareToken( ".PLACE_REGION", token ) ) - throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, - "\n* BUG: not a .PLACE_REGION" ) ); + throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "\n* BUG: not a .PLACE_REGION" ) ); if( !GetIDFString( aHeader, token, quoted, idx ) ) { @@ -2812,6 +2826,7 @@ void GROUP_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -2881,6 +2896,7 @@ void GROUP_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead } idx = 0; + if( comment ) { ostringstream ostr; @@ -2893,12 +2909,9 @@ void GROUP_OUTLINE::readData( std::istream& aBoardFile, const std::string& aHead throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } - if( !GetIDFString( iline, token, quoted, idx ) - || !CompareToken( ".END_PLACE_REGION", token ) ) + if( !GetIDFString( iline, token, quoted, idx ) || !CompareToken( ".END_PLACE_REGION", token ) ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "\n* invalid .PLACE_REGION section: no .END_PLACE_REGION found" ) ); - - return; } @@ -2918,22 +2931,23 @@ void GROUP_OUTLINE::writeData( std::ostream& aBoardFile ) // write RECORD 2 switch( side ) { - case LYR_TOP: - case LYR_BOTTOM: - case LYR_BOTH: - WriteLayersText( aBoardFile, side ); - break; + case LYR_TOP: + case LYR_BOTTOM: + case LYR_BOTH: + WriteLayersText( aBoardFile, side ); + break; - default: - do{ - ostringstream ostr; - ostr << "\n* invalid PLACE_REGION side (must be TOP/BOTTOM/BOTH): "; - ostr << side; + default: + do + { + ostringstream ostr; + ostr << "\n* invalid PLACE_REGION side (must be TOP/BOTTOM/BOTH): "; + ostr << side; - throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); - } while( 0 ); + throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); + } while( 0 ); - break; + break; } aBoardFile << " \"" << groupName << "\"\n"; @@ -2943,10 +2957,9 @@ void GROUP_OUTLINE::writeData( std::ostream& aBoardFile ) // write RECORD 4 aBoardFile << ".END_PLACE_REGION\n\n"; - - return; } + bool GROUP_OUTLINE::Clear( void ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -2962,9 +2975,7 @@ bool GROUP_OUTLINE::Clear( void ) return true; } -/* - * COMPONENT OUTLINE - */ + IDF3_COMP_OUTLINE::IDF3_COMP_OUTLINE( IDF3_BOARD* aParent ) { setParent( aParent ); @@ -2975,6 +2986,7 @@ IDF3_COMP_OUTLINE::IDF3_COMP_OUTLINE( IDF3_BOARD* aParent ) return; } + void IDF3_COMP_OUTLINE::readProperties( std::istream& aLibFile ) { bool quoted = false; @@ -3090,8 +3102,6 @@ void IDF3_COMP_OUTLINE::readProperties( std::istream& aLibFile ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } } - - return; } @@ -3099,6 +3109,7 @@ bool IDF3_COMP_OUTLINE::writeProperties( std::ostream& aLibFile ) { if( props.empty() ) return true; + std::map< std::string, std::string >::const_iterator itS = props.begin(); std::map< std::string, std::string >::const_iterator itE = props.end(); @@ -3112,6 +3123,7 @@ bool IDF3_COMP_OUTLINE::writeProperties( std::ostream& aLibFile ) return !aLibFile.fail(); } + void IDF3_COMP_OUTLINE::readData( std::istream& aLibFile, const std::string& aHeader, IDF3::IDF_VERSION aIdfVersion ) { @@ -3180,6 +3192,7 @@ void IDF3_COMP_OUTLINE::readData( std::istream& aLibFile, const std::string& aHe } idx = 0; + if( comment ) { ostringstream ostr; @@ -3333,6 +3346,7 @@ void IDF3_COMP_OUTLINE::readData( std::istream& aLibFile, const std::string& aHe } idx = 0; + if( comment ) { ostringstream ostr; @@ -3373,8 +3387,6 @@ void IDF3_COMP_OUTLINE::readData( std::istream& aLibFile, const std::string& aHe throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } } - - return; } @@ -3404,9 +3416,10 @@ void IDF3_COMP_OUTLINE::writeData( std::ostream& aLibFile ) aLibFile << "\"" << geometry << "\" \"" << part << "\" "; if( unit != UNIT_THOU ) - aLibFile << "MM " << setiosflags(ios::fixed) << setprecision(5) << thickness << "\n"; + aLibFile << "MM " << setiosflags( ios::fixed ) << setprecision( 5 ) << thickness << "\n"; else - aLibFile << "THOU " << setiosflags(ios::fixed) << setprecision(1) << (thickness / IDF_THOU_TO_MM) << "\n"; + aLibFile << "THOU " << setiosflags( ios::fixed ) << setprecision( 1 ) + << ( thickness / IDF_THOU_TO_MM ) << "\n"; writeOutlines( aLibFile ); @@ -3419,8 +3432,6 @@ void IDF3_COMP_OUTLINE::writeData( std::ostream& aLibFile ) { aLibFile << ".END_MECHANICAL\n\n"; } - - return; } @@ -3442,27 +3453,29 @@ bool IDF3_COMP_OUTLINE::Clear( void ) return true; } + bool IDF3_COMP_OUTLINE::SetComponentClass( IDF3::COMP_TYPE aCompClass ) { switch( aCompClass ) { - case COMP_ELEC: - case COMP_MECH: - compType = aCompClass; - break; + case COMP_ELEC: + case COMP_MECH: + compType = aCompClass; + break; - default: - do{ - ostringstream ostr; - ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; - ostr << "* BUG: invalid component class (must be ELECTRICAL or MECHANICAL): "; - ostr << aCompClass << "\n"; - errormsg = ostr.str(); + default: + do + { + ostringstream ostr; + ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; + ostr << "* BUG: invalid component class (must be ELECTRICAL or MECHANICAL): "; + ostr << aCompClass << "\n"; + errormsg = ostr.str(); - return false; - } while( 0 ); + return false; + } while( 0 ); - break; + break; } return true; @@ -3479,26 +3492,28 @@ void IDF3_COMP_OUTLINE::SetGeomName( const std::string& aGeomName ) { geometry = aGeomName; uid.clear(); - return; } + const std::string& IDF3_COMP_OUTLINE::GetGeomName( void ) { return geometry; } + void IDF3_COMP_OUTLINE::SetPartName( const std::string& aPartName ) { part = aPartName; uid.clear(); - return; } + const std::string& IDF3_COMP_OUTLINE::GetPartName( void ) { return part; } + const std::string& IDF3_COMP_OUTLINE::GetUID( void ) { if( !uid.empty() ) @@ -3518,6 +3533,7 @@ int IDF3_COMP_OUTLINE::incrementRef( void ) return ++refNum; } + int IDF3_COMP_OUTLINE::decrementRef( void ) { if( refNum == 0 ) @@ -3534,7 +3550,8 @@ int IDF3_COMP_OUTLINE::decrementRef( void ) return refNum; } -bool IDF3_COMP_OUTLINE::CreateDefaultOutline( const std::string &aGeom, const std::string &aPart ) + +bool IDF3_COMP_OUTLINE::CreateDefaultOutline( const std::string& aGeom, const std::string& aPart ) { Clear(); @@ -3567,7 +3584,7 @@ bool IDF3_COMP_OUTLINE::CreateDefaultOutline( const std::string &aGeom, const st p1.x = 1.5 * cos( a ); p1.y = 1.5 * sin( a ); - if( ol == NULL ) + if( ol == nullptr ) return false; for( int i = 0; i < 10; ++i ) @@ -3585,7 +3602,7 @@ bool IDF3_COMP_OUTLINE::CreateDefaultOutline( const std::string &aGeom, const st sp = new IDF_SEGMENT( p1, p2 ); - if( sp == NULL ) + if( sp == nullptr ) { Clear(); return false; @@ -3602,7 +3619,7 @@ bool IDF3_COMP_OUTLINE::CreateDefaultOutline( const std::string &aGeom, const st sp = new IDF_SEGMENT( p1, p2 ); - if( sp == NULL ) + if( sp == nullptr ) { Clear(); return false; diff --git a/utils/idftools/idf_outlines.h b/utils/idftools/idf_outlines.h index 63768dd263..00eecdd309 100644 --- a/utils/idftools/idf_outlines.h +++ b/utils/idftools/idf_outlines.h @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2017 Cirilo Bernardo + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -84,67 +85,10 @@ class IDF3_BOARD; /** - * BOARD_OUTLINE - * supports the IDFv3 BOARD OUTLINE data and is the basis of other IDFv3 outline classes + * IDFv3 BOARD OUTLINE data and is the basis of other IDFv3 outline objects. */ class BOARD_OUTLINE { -friend class IDF3_BOARD; -protected: - std::string errormsg; - std::list< IDF_OUTLINE* > outlines; - IDF3::KEY_OWNER owner; // indicates the owner of this outline (MCAD, ECAD, UNOWNED) - IDF3::OUTLINE_TYPE outlineType;// type of IDF outline - bool single; // true if only a single outline is accepted - std::list< std::string > comments; // associated comment list - IDF3::IDF_UNIT unit; // outline's native unit (MM or THOU) - IDF3_BOARD* parent; // BOARD which contains this outline - double thickness; // Board/Extrude Thickness or Height (IDF spec) - - // Read outline data from a BOARD or LIBRARY file's outline section - void readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aIdfVersion ); - // Write comments to a BOARD or LIBRARY file (must not be within a SECTION as per IDFv3 spec) - bool writeComments( std::ostream& aBoardFile ); - // Write the outline owner to a BOARD file - bool writeOwner( std::ostream& aBoardFile ); - // Write the data of a single outline object - void writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutline, size_t aIndex ); - // Iterate through the outlines and write out all data - void writeOutlines( std::ostream& aBoardFile ); // write outline data (no headers) - // Clear internal list of outlines - void clearOutlines( void ); - /** - * Function SetParent - * sets the parent IDF_BOARD object - */ - void setParent( IDF3_BOARD* aParent ); - - // Shadow routines used by friends to bypass ownership checks - bool addOutline( IDF_OUTLINE* aOutline ); - virtual bool setThickness( double aThickness ); - virtual void clear( void ); - - /** - * Function readData - * reads data from a .BOARD_OUTLINE section - * In case of an unrecoverable error an exception is thrown. On a successful - * return the file pointer will be at the line following .END_BOARD_OUTLINE - * - * @param aBoardFile is an IDFv3 file opened for reading - * @param aHeader is the ".BOARD_OUTLINE" header line as read by FetchIDFLine - */ - virtual void readData( std::istream& aBoardFile, const std::string& aHeader, - IDF3::IDF_VERSION aIdfVersion ); - - /** - * Function writeData - * writes the comments and .BOARD_OUTLINE section to an IDFv3 file. - * Throws exceptions. - * - * @param aBoardFile is an IDFv3 file opened for writing - */ - virtual void writeData( std::ostream& aBoardFile ); - public: BOARD_OUTLINE(); virtual ~BOARD_OUTLINE(); @@ -159,221 +103,233 @@ public: virtual bool SetUnit( IDF3::IDF_UNIT aUnit ); /** - * Function GetUnit - * returns the native unit type of the outline + * Return the native unit type of the outline. * - * @return IDF_UNIT is the native unit (UNIT_MM or UNIT_THOU) + * @return IDF_UNIT is the native unit (UNIT_MM or UNIT_THOU). */ virtual IDF3::IDF_UNIT GetUnit( void ); /** - * Function SetThickness - * sets the thickness or height of the outline (mm) + * Set the thickness or height of the outline (mm). * - * @param aThickness is the thickness or height of the outline in mm + * @param aThickness is the thickness or height of the outline in mm. */ virtual bool SetThickness( double aThickness ); /** - * Function GetThickness - * returns the thickness or height of an outline (mm) + * @return the thickness or height of an outline (mm). */ virtual double GetThickness( void ); /** - * Function Clear - * frees memory and reinitializes all internal data except for the parent pointer. + * Free memory and reinitializes all internal data except for the parent pointer. * - * @return bool: true if OK, false on ownership violations + * @return true if OK, false on ownership violations. */ virtual bool Clear( void ); /** - * Function GetOutlineType - * returns the type of outline according to the IDFv3 classification + * @return the type of outline according to the IDFv3 classification. */ IDF3::OUTLINE_TYPE GetOutlineType( void ); /** - * Function GetParent - * returns the parent IDF_BOARD object + * @return the parent IDF_BOARD object. */ IDF3_BOARD* GetParent( void ); /** - * Function AddOutline - * adds the specified outline to this object. + * Add the specified outline to this object. * - * @param aOutline is a valid IDF outline - * - * @return bool: true if the outline was added; false if the outline - * already existed or an ownership violation occurs. + * @param aOutline is a valid IDF outline. + * @return true if the outline was added; false if the outline already existed or an + * ownership violation occurs. */ bool AddOutline( IDF_OUTLINE* aOutline ); /** - * Function DelOutline( IDF_OUTLINE* aOutline ) - * removes the given outline, subject to IDF ownership rules, - * if it is owned by this object. The outline pointer remains - * valid and it is the user's responsibility to delete the object. - * The first outline in the list will never be deleted unless it - * is the sole remaining outline; this is to ensure that a board - * outline is not removed while the cutouts remain. + * Remove the given outline, subject to IDF ownership rules, + * if it is owned by this object. * - * @param aOutline is a pointer to the outline to remove from the list + * The outline pointer remains valid and it is the user's responsibility to delete the + * object. The first outline in the list will never be deleted unless it is the sole + * remaining outline; this is to ensure that a board outline is not removed while the + * cutouts remain. * - * @return bool: true if the outline was found and removed; false if - * the outline was not found or an ownership violation occurs. + * @param aOutline is a pointer to the outline to remove from the list. + * @return true if the outline was found and removed; false if the outline was not found + * or an ownership violation occurs. */ bool DelOutline( IDF_OUTLINE* aOutline ); /** - * Function DelOutline( IDF_OUTLINE* aOutline ) - * deletes the outline specified by the given index, subject to - * IDF ownership rules. The outline data is destroyed. - * The first outline in the list will never be deleted unless it - * is the sole remaining outline; this is to ensure that a board - * outline is not removed while the cutouts remain. + * Delete the outline specified by the given index, subject to IDF ownership rules. + * + * The outline data is destroyed. The first outline in the list will never be deleted + * unless it is the sole remaining outline; this is to ensure that a board outline is + * not removed while the cutouts remain. * * @param aIndex is an index to the outline to delete - * - * @return bool: true if the outline was found and deleted; false if - * the outline was not found or an ownership violation or indexation - * error occurs. + * @return true if the outline was found and deleted; false if the outline was not found + * or an ownership violation or indexation error occurs. */ bool DelOutline( size_t aIndex ); /** - * Function GetOutlines - * returns a pointer to the internal outlines list. It is up to the - * user to respect the IDFv3 specification and avoid changes to this - * list which are in violation of the specification. + * Return outlines list. + * + * It is up to the user to respect the IDFv3 specification and avoid changes to this + * list which are in violation of the specification. */ const std::list< IDF_OUTLINE* >*const GetOutlines( void ); /** - * Function OutlinesSize - * returns the number of items in the internal outline list + * @return the number of items in the internal outline list. */ size_t OutlinesSize( void ); /** - * Function GetOutline - * returns a pointer to the outline as specified by aIndex. - * If the index is out of bounds NULL is returned and the - * error message is set. It is the responsibility of the - * user to observe IDF ownership rules. + * Return a pointer to the outline as specified by aIndex. + * + * If the index is out of bounds NULL is returned and the error message is set. It is the + * responsibility of the user to observe IDF ownership rules. */ IDF_OUTLINE* GetOutline( size_t aIndex ); /** - * Function GetOwner - * returns the ownership status of the outline ( ECAD, MCAD, UNOWNED) + * @return the ownership status of the outline (ECAD, MCAD, UNOWNED). */ IDF3::KEY_OWNER GetOwner( void ); /** - * Function SetOwner - * sets the ownership status of the outline subject to IDF - * ownership rules. The return value is true if the ownership - * was changed and false if a specification violation occurred. + * Set the ownership status of the outline subject to IDF ownership rules. + * + * @return true if the ownership was changed and false if a specification violation occurred. */ bool SetOwner( IDF3::KEY_OWNER aOwner ); /** - * Function IsSingle - * return true if this type of outline only supports a single - * outline. All outlines except for BOARD_OUTLINE are single. + * @return true if this type of outline only supports a single outline. All outlines except + * for BOARD_OUTLINE are single. */ bool IsSingle( void ); /** - * Function ClearOutlines - * clears internal data except for the parent pointer + * Clear internal data except for the parent pointer. */ void ClearOutlines( void ); /** - * Function AddComment - * adds a comment to the outline data; this function is not - * subject to IDF ownership rules. + * Add a comment to the outline data. + * + * This function is not subject to IDF ownership rules. */ void AddComment( const std::string& aComment ); /** - * Function CommentSize - * returns the number of comments in the internal list + * @return the number of comments in the internal list. */ size_t CommentsSize( void ); /** - * Function GetComments - * returns a pointer to the internal list of comments + * @return the internal list of comments. */ std::list< std::string >* GetComments( void ); /** - * Function GetComment - * returns the string representing the indexed comment or - * NULL if the index is out of bounds + * @return indexed comment or NULL if the index is out of bounds. */ const std::string* GetComment( size_t aIndex ); /** - * Function DeleteComment - * deletes a comment based on the given index. + * Deletes a comment based on the given index. * - * @return bool: true if a comment was deleted, false if - * the index is out of bounds. + * @return true if a comment was deleted, false if the index is out of bounds. */ - bool DeleteComment( size_t aIndex ); + bool DeleteComment( size_t aIndex ); /** - * Function ClearComments - * deletes all comments + * Deletes all comments. */ - void ClearComments( void ); + void ClearComments( void ); const std::string& GetError( void ) { return errormsg; } + +protected: + // Read outline data from a BOARD or LIBRARY file's outline section + void readOutlines( std::istream& aBoardFile, IDF3::IDF_VERSION aIdfVersion ); + + // Write comments to a BOARD or LIBRARY file (must not be within a SECTION as per IDFv3 spec) + bool writeComments( std::ostream& aBoardFile ); + + // Write the outline owner to a BOARD file + bool writeOwner( std::ostream& aBoardFile ); + + // Write the data of a single outline object + void writeOutline( std::ostream& aBoardFile, IDF_OUTLINE* aOutline, size_t aIndex ); + + // Iterate through the outlines and write out all data + void writeOutlines( std::ostream& aBoardFile ); // write outline data (no headers) + + // Clear internal list of outlines + void clearOutlines( void ); + + /** + * Set the parent IDF_BOARD object. + */ + void setParent( IDF3_BOARD* aParent ); + + // Shadow routines used by friends to bypass ownership checks + bool addOutline( IDF_OUTLINE* aOutline ); + virtual bool setThickness( double aThickness ); + virtual void clear( void ); + + /** + * Read data from a .BOARD_OUTLINE section. + * + * In case of an unrecoverable error an exception is thrown. On a successful + * return the file pointer will be at the line following .END_BOARD_OUTLINE + * + * @param aBoardFile is an IDFv3 file opened for reading. + * @param aHeader is the ".BOARD_OUTLINE" header line as read by FetchIDFLine. + */ + virtual void readData( std::istream& aBoardFile, const std::string& aHeader, + IDF3::IDF_VERSION aIdfVersion ); + + /** + * Write the comments and .BOARD_OUTLINE section to an IDFv3 file. + * Throws exceptions. + * + * @param aBoardFile is an IDFv3 file opened for writing. + */ + virtual void writeData( std::ostream& aBoardFile ); + + std::string errormsg; + std::list< IDF_OUTLINE* > outlines; + + // indicates the owner of this outline (MCAD, ECAD, UNOWNED). + IDF3::KEY_OWNER owner; + IDF3::OUTLINE_TYPE outlineType; // type of IDF outline + bool single; // true if only a single outline is accepted + std::list< std::string > comments; // associated comment list + IDF3::IDF_UNIT unit; // outline's native unit (MM or THOU) + IDF3_BOARD* parent; // BOARD which contains this outline + double thickness; // Board/Extrude Thickness or Height (IDF spec) + +private: + friend class IDF3_BOARD; }; /** - * OTHER_OUTLINE - * describes miscellaneous extrusions on the board + * Miscellaneous extrusions on the board */ class OTHER_OUTLINE : public BOARD_OUTLINE { -friend class IDF3_BOARD; -private: - std::string uniqueID; // Outline Identifier (IDF spec) - IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM ONLY] (IDF spec) - - /** - * Function readData - * reads an OTHER_OUTLINE data from an IDFv3 file. - * If an unrecoverable error occurs an exception is thrown. - * - * @param aBoardFile is an IDFv3 file open for reading - * @param aHeader is the .OTHER_OUTLINE header as read via FetchIDFLine - */ - virtual void readData( std::istream& aBoardFile, const std::string& aHeader, - IDF3::IDF_VERSION aIdfVersion ) override; - - /** - * Function writeData - * writes the OTHER_OUTLINE data to an open IDFv3 file - * - * @param aBoardFile is an IDFv3 file open for writing - * - * @return bool: true if the data was successfully written, otherwise false. - */ - virtual void writeData( std::ostream& aBoardFile ) override; - public: OTHER_OUTLINE( IDF3_BOARD* aParent ); @@ -410,37 +366,38 @@ public: * deletes internal data except for the parent object */ virtual bool Clear( void ) override; -}; - -/** - * ROUTE_OUTLINE - * describes routing areas on the board - */ -class ROUTE_OUTLINE : public BOARD_OUTLINE -{ -friend class IDF3_BOARD; private: /** - * Function readData - * reads ROUTE_OUTLINE data from an IDFv3 file + * Read an OTHER_OUTLINE data from an IDFv3 file. * If an unrecoverable error occurs an exception is thrown. * - * @param aBoardFile is an open IDFv3 board file - * @param aHeader is the .ROUTE_OUTLINE header as returned by FetchIDFLine + * @param aBoardFile is an IDFv3 file open for reading. + * @param aHeader is the .OTHER_OUTLINE header as read via FetchIDFLine. */ virtual void readData( std::istream& aBoardFile, const std::string& aHeader, IDF3::IDF_VERSION aIdfVersion ) override; /** - * Function writeData - * writes the ROUTE_OUTLINE data to an open IDFv3 file + * Write the OTHER_OUTLINE data to an open IDFv3 file. + * + * @param aBoardFile is an IDFv3 file open for writing. + * @return true if the data was successfully written, otherwise false. */ virtual void writeData( std::ostream& aBoardFile ) override; -protected: - IDF3::IDF_LAYER layers; // Routing layers (IDF spec) + friend class IDF3_BOARD; + std::string uniqueID; // Outline Identifier (IDF spec) + IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM ONLY] (IDF spec) +}; + + +/** + * Routing areas on the board. + */ +class ROUTE_OUTLINE : public BOARD_OUTLINE +{ public: ROUTE_OUTLINE( IDF3_BOARD* aParent ); @@ -463,40 +420,35 @@ public: * deletes internal data except for the parent object */ virtual bool Clear( void ) override; -}; -/** - * PLACE_OUTLINE - * describes areas on the board for placing components - */ -class PLACE_OUTLINE : public BOARD_OUTLINE -{ -friend class IDF3_BOARD; private: + friend class IDF3_BOARD; + /** - * Function readData - * reads PLACE_OUTLINE data from an open IDFv3 file. + * Read ROUTE_OUTLINE data from an IDFv3 file. * If an unrecoverable error occurs an exception is thrown. * - * @param aBoardFile is an IDFv3 file opened for reading - * @param aHeader is the .PLACE_OUTLINE header as returned by FetchIDFLine + * @param aBoardFile is an open IDFv3 board file. + * @param aHeader is the .ROUTE_OUTLINE header as returned by FetchIDFLine. */ virtual void readData( std::istream& aBoardFile, const std::string& aHeader, IDF3::IDF_VERSION aIdfVersion ) override; /** - * Function writeData - * writes the PLACE_OUTLINE data to an open IDFv3 file - * - * @param aBoardFile is an IDFv3 file opened for writing - * - * @return bool: true if the data was successfully written, otherwise false + * Write the ROUTE_OUTLINE data to an open IDFv3 file. */ virtual void writeData( std::ostream& aBoardFile ) override; protected: - IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM/BOTH ONLY] (IDF spec) + IDF3::IDF_LAYER layers; // Routing layers (IDF spec) +}; + +/** + * Area on the board for placing components. + */ +class PLACE_OUTLINE : public BOARD_OUTLINE +{ public: PLACE_OUTLINE( IDF3_BOARD* aParent ); @@ -533,12 +485,36 @@ public: * deletes all internal data */ virtual bool Clear( void ) override; + +private: + friend class IDF3_BOARD; + + /** + * Read PLACE_OUTLINE data from an open IDFv3 file. + * + * If an unrecoverable error occurs an exception is thrown. + * + * @param aBoardFile is an IDFv3 file opened for reading. + * @param aHeader is the .PLACE_OUTLINE header as returned by FetchIDFLine. + */ + virtual void readData( std::istream& aBoardFile, const std::string& aHeader, + IDF3::IDF_VERSION aIdfVersion ) override; + + /** + * Write the PLACE_OUTLINE data to an open IDFv3 file. + * + * @param aBoardFile is an IDFv3 file opened for writing. + * @return true if the data was successfully written, otherwise false. + */ + virtual void writeData( std::ostream& aBoardFile ) override; + +protected: + IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM/BOTH ONLY] (IDF spec) }; /** - * ROUTE_KO_OUTLINE - * describes regions and layers where no electrical routing is permitted + * Regions and layers where no electrical routing is permitted. */ class ROUTE_KO_OUTLINE : public ROUTE_OUTLINE { @@ -546,11 +522,12 @@ public: ROUTE_KO_OUTLINE( IDF3_BOARD* aParent ); }; + /** - * VIA_KO_OUTLINE - * describes regions in which vias are prohibited. Note: IDFv3 only considers - * thru-hole vias and makes no statement regarding behavior with blind or buried - * vias. + * Region in which vias are prohibited. + * + * @note IDFv3 only considers thru-hole vias and makes no statement regarding behavior with + * blind or buried vias. */ class VIA_KO_OUTLINE : public OTHER_OUTLINE { @@ -560,9 +537,8 @@ public: /** - * PLACE_KO_OUTLINE - * represents regions and layers in which no component may - * be placed or on which a maximum component height is in effect. + * Regions and layers in which no component may be placed or on which a maximum component height + * is in effect. */ class PLACE_KO_OUTLINE : public PLACE_OUTLINE { @@ -570,87 +546,176 @@ public: PLACE_KO_OUTLINE( IDF3_BOARD* aParent ); }; + /** - * GROUP_OUTLINE - * represents regions and layers in which user-specified features or components - * may be placed. + * Regions and layers in which user-specified features or components may be placed. */ class GROUP_OUTLINE : public BOARD_OUTLINE { -friend class IDF3_BOARD; -private: - IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM/BOTH ONLY] (IDF spec) - std::string groupName; // non-unique string - - /** - * Function readData - * reads GROUP_OUTLINE data from an open IDFv3 file - * If an unrecoverable error occurs an exception is thrown. - * - * @param aBoardFile is an open IDFv3 file - * @param aHeader is the .PLACE_REGION header as returned by FetchIDFLine - */ - virtual void readData( std::istream& aBoardFile, const std::string& aHeader, - IDF3::IDF_VERSION aIdfVersion ) override; - - /** - * Function writeData - * writes the data to a .PLACE_REGION section of an IDFv3 file - * - * @param aBoardFile is an IDFv3 file open for writing - * - * @return bool: true if the data is successfully written, otherwise false - */ - virtual void writeData( std::ostream& aBoardFile ) override; - public: GROUP_OUTLINE( IDF3_BOARD* aParent ); /** - * Function SetSide - * sets the side which this outline applies to (TOP, BOTTOM, BOTH). + * Set the side which this outline applies to (TOP, BOTTOM, BOTH). + * * This function is subject to IDF ownership rules; true is returned * on success, otherwise false is returned and the error message is set. */ virtual bool SetSide( IDF3::IDF_LAYER aSide ); /** - * Function GetSide - * returns the side which this outline applies to + * @return the side which this outline applies to. */ virtual IDF3::IDF_LAYER GetSide( void ); /** - * Function SetGroupName - * sets the name of the group, subject to IDF ownership rules. + * Set the name of the group, subject to IDF ownership rules. + * * This function is subject to IDF ownership rules; true is returned * on success, otherwise false is returned and the error message is set. */ virtual bool SetGroupName( std::string aGroupName ); /** - * Function GetGroupName - * returns a reference to the (non-unique) group name + * Return a reference to the (non-unique) group name. */ virtual const std::string& GetGroupName( void ); /** - * Function Clear - * deletes internal data, subject to IDF ownership rules + * Delete internal data, subject to IDF ownership rules. */ virtual bool Clear( void ) override; + +private: + friend class IDF3_BOARD; + + /** + * Read GROUP_OUTLINE data from an open IDFv3 file. + * + * If an unrecoverable error occurs an exception is thrown. + * + * @param aBoardFile is an open IDFv3 file. + * @param aHeader is the .PLACE_REGION header as returned by FetchIDFLine. + */ + virtual void readData( std::istream& aBoardFile, const std::string& aHeader, + IDF3::IDF_VERSION aIdfVersion ) override; + + /** + * Write the data to a .PLACE_REGION section of an IDFv3 file. + * + * @param aBoardFile is an IDFv3 file open for writing. + * @return true if the data is successfully written, otherwise false. + */ + virtual void writeData( std::ostream& aBoardFile ) override; + + IDF3::IDF_LAYER side; // Board Side [TOP/BOTTOM/BOTH ONLY] (IDF spec) + std::string groupName; // non-unique string }; /** - * IDF3_COMP_OUTLINE - * represents a component's outline as stored in an IDF library file + * A component's outline as stored in an IDF library file. */ class IDF3_COMP_OUTLINE : public BOARD_OUTLINE { -friend class IDF3_BOARD; -friend class IDF3_COMP_OUTLINE_DATA; +public: + IDF3_COMP_OUTLINE( IDF3_BOARD* aParent ); + + /** + * Delete internal outline data. + */ + virtual bool Clear( void ) override; + + /** + * Set the type of component outline (.ELECTRICAL or .MECHANICAL). + * + * @return true on success, otherwise false and the error message is set. + */ + bool SetComponentClass( IDF3::COMP_TYPE aCompClass ); + + /** + * @return2 the class of component represented by this outline. + */ + IDF3::COMP_TYPE GetComponentClass( void ); + + /** + * Set the Geometry Name (Package Name, IDFv3 spec) of the component outline. + */ + void SetGeomName( const std::string& aGeomName ); + + /** + * @return the Geometry Name (Package Name) of the component outline. + */ + const std::string& GetGeomName( void ); + + /** + * Set the Part Name (Part Number, IDFv3 spec) of the component outline. + */ + void SetPartName( const std::string& aPartName ); + + /** + * Return the Part Name (Part Number) of the component outline. + */ + const std::string& GetPartName( void ); + + /** + * @return the unique identifier for this component outline, this is equal to + * GEOM_NAME + "_" + PART_NAME. + */ + const std::string& GetUID( void ); + + /** + * Create a default outline with the given Geometry and Part names. + * + * This outline is a star with outer radius 5mm and inner radius 2.5mm. + */ + bool CreateDefaultOutline( const std::string &aGeom, const std::string &aPart ); + + // XXX: property manipulators + private: + friend class IDF3_BOARD; + friend class IDF3_COMP_OUTLINE_DATA; + + void readProperties( std::istream& aLibFile ); + bool writeProperties( std::ostream& aLibFile ); + + /** + * Read a component outline from an open IDFv3 file. + * + * If an unrecoverable error occurs, an exception is thrown. + * + * @param aLibFile is an open IDFv3 Library file. + * @param aHeader is the .ELECTRICAL or .MECHANICAL header as returned by FetchIDFLine. + */ + virtual void readData( std::istream& aLibFile, const std::string& aHeader, + IDF3::IDF_VERSION aIdfVersion ) override; + + /** + * Write comments and component outline data to an IDFv3 Library file. + * + * @param aLibFile is an IDFv3 library file open for writing. + * @return true if the data was successfully written, otherwise false. + */ + virtual void writeData( std::ostream& aLibFile ) override; + + /** + * Increment the internal reference counter to keep track of the number of + * components referring to this outline. + * + * @return the number of current references to this component outline. + */ + int incrementRef( void ); + + /** + * Decrement the internal reference counter to keep track of the number of + * components referring to this outline. + * + * @return the number of remaining references or -1 if there were no references when the + * function was invoked, in which case the error message is also set. + */ + int decrementRef( void ); + std::string uid; // unique ID std::string geometry; // geometry name (IDF) std::string part; // part name (IDF) @@ -658,112 +723,6 @@ private: int refNum; // number of components referring to this outline std::map< std::string, std::string > props; // properties list - - void readProperties( std::istream& aLibFile ); - bool writeProperties( std::ostream& aLibFile ); - - /** - * Function readData - * reads a component outline from an open IDFv3 file - * If an unrecoverable error occurs, an exception is thrown. - * - * @param aLibFile is an open IDFv3 Library file - * @param aHeader is the .ELECTRICAL or .MECHANICAL header as returned by FetchIDFLine - */ - virtual void readData( std::istream& aLibFile, const std::string& aHeader, - IDF3::IDF_VERSION aIdfVersion ) override; - - /** - * Function writeData - * writes comments and component outline data to an IDFv3 Library file - * - * @param aLibFile is an IDFv3 library file open for writing - * - * @return bool: true if the data was successfully written, otherwise false - */ - virtual void writeData( std::ostream& aLibFile ) override; - - /** - * Function incrementRef - * increments the internal reference counter to keep track of the number of - * components referring to this outline. - * - * @return int: the number of current references to this component outline - */ - int incrementRef( void ); - - /** - * Function decrementRef - * decrements the internal reference counter to keep track of the number of - * components referring to this outline. - * - * @return int: the number of remaining references or -1 if there were no - * references when the function was invoked, in which case the error message - * is also set. - */ - int decrementRef( void ); - -public: - IDF3_COMP_OUTLINE( IDF3_BOARD* aParent ); - - /** - * Function Clear - * deletes internal outline data - */ - virtual bool Clear( void ) override; - - /** - * Function SetComponentClass - * sets the type of component outline (.ELECTRICAL or .MECHANICAL). - * Returns true on success, otherwise false and the error message is set - */ - bool SetComponentClass( IDF3::COMP_TYPE aCompClass ); - - /** - * Function GetComponentClass - * returns the class of component represented by this outline - */ - IDF3::COMP_TYPE GetComponentClass( void ); - - /** - * Function SetGeomName - * sets the Geometry Name (Package Name, IDFv3 spec) of the component outline - */ - void SetGeomName( const std::string& aGeomName ); - - /** - * Function GetGeomName - * returns the Geometry Name (Package Name) of the component outline - */ - const std::string& GetGeomName( void ); - - /** - * Function SetPartName - * sets the Part Name (Part Number, IDFv3 spec) of the component outline - */ - void SetPartName( const std::string& aPartName ); - - /** - * Function GetPartName - * returns the Part Name (Part Number) of the component outline - */ - const std::string& GetPartName( void ); - - /** - * Function GetUID - * returns the unique identifier for this component outline; - * this is equal to GEOM_NAME + "_" + PART_NAME - */ - const std::string& GetUID( void ); - - /** - * Function CreateDefaultOutline - * creates a default outline with the given Geometry and Part names. - * This outline is a star with outer radius 5mm and inner radius 2.5mm. - */ - bool CreateDefaultOutline( const std::string &aGeom, const std::string &aPart ); - - // XXX: property manipulators }; #endif // IDF_OUTLINES_H diff --git a/utils/idftools/idf_parser.cpp b/utils/idftools/idf_parser.cpp index bd5c274b3c..e211e07991 100644 --- a/utils/idftools/idf_parser.cpp +++ b/utils/idftools/idf_parser.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2017 Cirilo Bernardo + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -81,24 +82,17 @@ static bool MatchCompOutline( IDF3_COMP_OUTLINE* aOutlineA, IDF3_COMP_OUTLINE* a } -/* - * IDF3_COMP_OUTLINE_DATA - * This represents the outline placement - * information and other data specific to - * each component instance. - */ IDF3_COMP_OUTLINE_DATA::IDF3_COMP_OUTLINE_DATA() { - parent = NULL; - outline = NULL; + parent = nullptr; + outline = nullptr; xoff = 0.0; yoff = 0.0; zoff = 0.0; aoff = 0.0; - - return; } + IDF3_COMP_OUTLINE_DATA::IDF3_COMP_OUTLINE_DATA( IDF3_COMPONENT* aParent, IDF3_COMP_OUTLINE* aOutline ) { @@ -111,10 +105,9 @@ IDF3_COMP_OUTLINE_DATA::IDF3_COMP_OUTLINE_DATA( IDF3_COMPONENT* aParent, if( aOutline ) aOutline->incrementRef(); - - return; } + IDF3_COMP_OUTLINE_DATA::IDF3_COMP_OUTLINE_DATA( IDF3_COMPONENT* aParent, IDF3_COMP_OUTLINE* aOutline, double aXoff, double aYoff, @@ -126,17 +119,16 @@ IDF3_COMP_OUTLINE_DATA::IDF3_COMP_OUTLINE_DATA( IDF3_COMPONENT* aParent, yoff = aYoff; zoff = aZoff; aoff = aAngleOff; - return; } + IDF3_COMP_OUTLINE_DATA::~IDF3_COMP_OUTLINE_DATA() { if( outline ) outline->decrementRef(); - - return; } + #ifndef DISABLE_IDF_OWNERSHIP bool IDF3_COMP_OUTLINE_DATA::checkOwnership( int aSourceLine, const char* aSourceFunc ) { @@ -182,6 +174,7 @@ bool IDF3_COMP_OUTLINE_DATA::checkOwnership( int aSourceLine, const char* aSourc } #endif + bool IDF3_COMP_OUTLINE_DATA::SetOffsets( double aXoff, double aYoff, double aZoff, double aAngleOff ) { @@ -197,6 +190,7 @@ bool IDF3_COMP_OUTLINE_DATA::SetOffsets( double aXoff, double aYoff, return true; } + void IDF3_COMP_OUTLINE_DATA::GetOffsets( double& aXoff, double& aYoff, double& aZoff, double& aAngleOff ) { @@ -204,7 +198,6 @@ void IDF3_COMP_OUTLINE_DATA::GetOffsets( double& aXoff, double& aYoff, aYoff = yoff; aZoff = zoff; aAngleOff = aoff; - return; } @@ -213,6 +206,7 @@ void IDF3_COMP_OUTLINE_DATA::SetParent( IDF3_COMPONENT* aParent ) parent = aParent; } + bool IDF3_COMP_OUTLINE_DATA::SetOutline( IDF3_COMP_OUTLINE* aOutline ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -243,8 +237,8 @@ bool IDF3_COMP_OUTLINE_DATA::readPlaceData( std::istream &aBoardFile, "\n* BUG: invoked with no reference to the parent IDF_BOARD" ) ); // clear out data possibly left over from previous use of the object - outline = NULL; - parent = NULL; + outline = nullptr; + parent = nullptr; std::string iline; // the input line bool isComment; // true if a line just read in is a comment line @@ -599,14 +593,14 @@ bool IDF3_COMP_OUTLINE_DATA::readPlaceData( std::istream &aBoardFile, outline = aBoard->GetComponentOutline( uid ); - if( outline == NULL && !aNoSubstituteOutlines ) + if( outline == nullptr && !aNoSubstituteOutlines ) { ERROR_IDF << "MISSING OUTLINE\n"; cerr << "* GeomName( " << ngeom << " ), PartName( " << npart << " )\n"; cerr << "* Substituting default outline.\n"; outline = aBoard->GetInvalidOutline( ngeom, npart ); - if( outline == NULL ) + if( outline == nullptr ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "\n* missing outline: cannot create default" ) ); } @@ -620,13 +614,13 @@ bool IDF3_COMP_OUTLINE_DATA::readPlaceData( std::istream &aBoardFile, parent = aBoard->FindComponent( refdes ); - if( parent == NULL ) + if( parent == nullptr ) { IDF3_COMPONENT* cp = new IDF3_COMPONENT( aBoard ); - if( cp == NULL ) + if( cp == nullptr ) { - outline = NULL; + outline = nullptr; throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "cannot create component object" ) ); @@ -653,7 +647,7 @@ bool IDF3_COMP_OUTLINE_DATA::readPlaceData( std::istream &aBoardFile, { if( side != tL ) { - outline = NULL; + outline = nullptr; ostringstream ostr; ostr << "invalid IDF file\n"; @@ -682,7 +676,7 @@ bool IDF3_COMP_OUTLINE_DATA::readPlaceData( std::istream &aBoardFile, if( placement != parent->GetPlacement() ) { - outline = NULL; + outline = nullptr; ostringstream ostr; ostr << "invalid IDF file\n"; @@ -702,7 +696,7 @@ bool IDF3_COMP_OUTLINE_DATA::readPlaceData( std::istream &aBoardFile, IDF3_COMP_OUTLINE_DATA* cdp = new IDF3_COMP_OUTLINE_DATA; *cdp = *this; if( outline ) outline->incrementRef(); - outline = NULL; + outline = nullptr; if( !parent->AddOutlineData( cdp ) ) { @@ -713,7 +707,7 @@ bool IDF3_COMP_OUTLINE_DATA::readPlaceData( std::istream &aBoardFile, } return true; -} // IDF3_COMP_OUTLINE_DATA::readPlaceData +} void IDF3_COMP_OUTLINE_DATA::writePlaceData( std::ostream& aBoardFile, @@ -722,7 +716,7 @@ void IDF3_COMP_OUTLINE_DATA::writePlaceData( std::ostream& aBoardFile, IDF3::IDF_PLACEMENT aPlacement, IDF3::IDF_LAYER aSide ) { - if( outline == NULL ) + if( outline == nullptr ) return; if( outline->GetUID().empty() ) @@ -809,17 +803,9 @@ void IDF3_COMP_OUTLINE_DATA::writePlaceData( std::ostream& aBoardFile, aBoardFile << " ECAD\n"; break; } - - return; } -/* - * IDF3_COMPONENT - * - * This represents a component and its associated - * IDF outlines and ancillary data (position, etc) - */ IDF3_COMPONENT::IDF3_COMPONENT( IDF3_BOARD* aParent ) { xpos = 0.0; @@ -831,9 +817,9 @@ IDF3_COMPONENT::IDF3_COMPONENT( IDF3_BOARD* aParent ) layer = LYR_INVALID; parent = aParent; - return; } + IDF3_COMPONENT::~IDF3_COMPONENT() { std::list< IDF3_COMP_OUTLINE_DATA* >::iterator itcS = components.begin(); @@ -857,10 +843,9 @@ IDF3_COMPONENT::~IDF3_COMPONENT() } drills.clear(); - - return; } + #ifndef DISABLE_IDF_OWNERSHIP bool IDF3_COMPONENT::checkOwnership( int aSourceLine, const char* aSourceFunc ) { @@ -889,12 +874,14 @@ bool IDF3_COMPONENT::checkOwnership( int aSourceLine, const char* aSourceFunc ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; - ostr << "\n* ownership violation; internal CAD type (MCAD) conflicts with PLACEMENT ("; + ostr << "\n* ownership violation; internal CAD type (MCAD) conflicts with " + "PLACEMENT ("; ostr << GetPlacementString( placement ) << ")"; errormsg = ostr.str(); return false; } + break; case PS_ECAD: @@ -903,7 +890,8 @@ bool IDF3_COMPONENT::checkOwnership( int aSourceLine, const char* aSourceFunc ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; - ostr << "\n* ownership violation; internal CAD type (MCAD) conflicts with PLACEMENT ("; + ostr << "\n* ownership violation; internal CAD type (MCAD) conflicts with " + "PLACEMENT ("; ostr << GetPlacementString( placement ) << ")"; errormsg = ostr.str(); @@ -912,7 +900,8 @@ bool IDF3_COMPONENT::checkOwnership( int aSourceLine, const char* aSourceFunc ) break; default: - do{ + do + { ostringstream ostr; ostr << "\n* BUG: unhandled internal placement value (" << placement << ")"; errormsg = ostr.str(); @@ -986,6 +975,7 @@ const std::string& IDF3_COMPONENT::GetRefDes( void ) return refdes; } + IDF_DRILL_DATA* IDF3_COMPONENT::AddDrill( double aDia, double aXpos, double aYpos, IDF3::KEY_PLATING aPlating, const std::string& aHoleType, @@ -994,8 +984,8 @@ IDF_DRILL_DATA* IDF3_COMPONENT::AddDrill( double aDia, double aXpos, double aYpo IDF_DRILL_DATA* dp = new IDF_DRILL_DATA( aDia, aXpos, aYpos, aPlating, refdes, aHoleType, aOwner ); - if( dp == NULL ) - return NULL; + if( dp == nullptr ) + return nullptr; drills.push_back( dp ); @@ -1006,13 +996,13 @@ IDF_DRILL_DATA* IDF3_COMPONENT::AddDrill( double aDia, double aXpos, double aYpo IDF_DRILL_DATA* IDF3_COMPONENT::AddDrill( IDF_DRILL_DATA* aDrilledHole ) { if( !aDrilledHole ) - return NULL; + return nullptr; if( CompareToken( "PANEL", refdes ) ) { ERROR_IDF; cerr << "\n* BUG: PANEL drills not supported at component level\n"; - return NULL; + return nullptr; } if( refdes.compare( aDrilledHole->GetDrillRefDes() ) ) @@ -1020,7 +1010,7 @@ IDF_DRILL_DATA* IDF3_COMPONENT::AddDrill( IDF_DRILL_DATA* aDrilledHole ) ERROR_IDF; cerr << "\n* BUG: pushing an incorrect REFDES ('" << aDrilledHole->GetDrillRefDes(); cerr << "') to component ('" << refdes << "')\n"; - return NULL; + return nullptr; } drills.push_back( aDrilledHole ); @@ -1055,6 +1045,7 @@ bool IDF3_COMPONENT::DelDrill( double aDia, double aXpos, double aYpos ) itS = drills.erase( itS ); continue; } + ++itS; } @@ -1085,12 +1076,14 @@ bool IDF3_COMPONENT::DelDrill( IDF_DRILL_DATA* aDrill ) drills.erase( itS ); return true; } + ++itS; } return false; } + const std::list< IDF_DRILL_DATA* >*const IDF3_COMPONENT::GetDrills( void ) { return &drills; @@ -1098,10 +1091,11 @@ const std::list< IDF_DRILL_DATA* >*const IDF3_COMPONENT::GetDrills( void ) bool IDF3_COMPONENT::AddOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutline ) { - if( aComponentOutline == NULL ) + if( aComponentOutline == nullptr ) { ostringstream ostr; - ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): invalid aComponentOutline (NULL)"; + ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << + "(): invalid aComponentOutline (nullptr)"; errormsg = ostr.str(); return false; @@ -1113,6 +1107,7 @@ bool IDF3_COMPONENT::AddOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutline ) return true; } + bool IDF3_COMPONENT::DeleteOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutline ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1129,10 +1124,11 @@ bool IDF3_COMPONENT::DeleteOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutlin return false; } - if( aComponentOutline == NULL ) + if( aComponentOutline == nullptr ) { ostringstream ostr; - ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): invalid aComponentOutline (NULL)"; + ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << + "(): invalid aComponentOutline (nullptr)"; errormsg = ostr.str(); return false; @@ -1158,6 +1154,7 @@ bool IDF3_COMPONENT::DeleteOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutlin return false; } + bool IDF3_COMPONENT::DeleteOutlineData( size_t aIndex ) { #ifndef DISABLE_IDF_OWNERSHIP @@ -1195,16 +1192,19 @@ bool IDF3_COMPONENT::DeleteOutlineData( size_t aIndex ) return false; } + size_t IDF3_COMPONENT::GetOutlinesSize( void ) { return components.size(); } + const std::list< IDF3_COMP_OUTLINE_DATA* >*const IDF3_COMPONENT::GetOutlinesData( void ) { return &components; } + bool IDF3_COMPONENT::GetPosition( double& aXpos, double& aYpos, double& aAngle, IDF3::IDF_LAYER& aLayer ) { @@ -1226,7 +1226,9 @@ bool IDF3_COMPONENT::GetPosition( double& aXpos, double& aYpos, double& aAngle, return true; } -bool IDF3_COMPONENT::SetPosition( double aXpos, double aYpos, double aAngle, IDF3::IDF_LAYER aLayer ) + +bool IDF3_COMPONENT::SetPosition( double aXpos, double aYpos, double aAngle, + IDF3::IDF_LAYER aLayer ) { #ifndef DISABLE_IDF_OWNERSHIP if( !checkOwnership( __LINE__, __FUNCTION__ ) ) @@ -1242,14 +1244,17 @@ bool IDF3_COMPONENT::SetPosition( double aXpos, double aYpos, double aAngle, IDF break; default: - do{ + do + { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; - ostr << "\n* invalid side (must be TOP or BOTTOM only): " << GetLayerString( aLayer ); + ostr << "\n* invalid side (must be TOP or BOTTOM only): " << + GetLayerString( aLayer ); errormsg = ostr.str(); return false; } while( 0 ); + break; } @@ -1293,6 +1298,7 @@ bool IDF3_COMPONENT::SetPlacement( IDF3::IDF_PLACEMENT aPlacementValue ) return true; } + bool IDF3_COMPONENT::writeDrillData( std::ostream& aBoardFile ) { if( drills.empty() ) @@ -1351,6 +1357,7 @@ IDF3_BOARD::IDF3_BOARD( IDF3::CAD_TYPE aCadType ) return; } + IDF3_BOARD::~IDF3_BOARD() { Clear(); @@ -1378,7 +1385,7 @@ bool IDF3_BOARD::checkComponentOwnership( int aSourceLine, const char* aSourceFu { ostringstream ostr; ostr << __FILE__ << ":" << aSourceLine << ":" << aSourceFunc; - ostr << "(): Invalid component pointer (NULL)"; + ostr << "(): Invalid component pointer (nullptr)"; errormsg = ostr.str(); return false; @@ -1415,22 +1422,25 @@ bool IDF3_BOARD::checkComponentOwnership( int aSourceLine, const char* aSourceFu } #endif + IDF3::CAD_TYPE IDF3_BOARD::GetCadType( void ) { return cadType; } -void IDF3_BOARD::SetBoardName( std::string aBoardName ) + +void IDF3_BOARD::SetBoardName( const std::string& aBoardName ) { - boardName = std::move(aBoardName); - return; + boardName = std::move( aBoardName ); } + const std::string& IDF3_BOARD::GetBoardName( void ) { return boardName; } + bool IDF3_BOARD::setUnit( IDF3::IDF_UNIT aUnit, bool convert ) { switch( aUnit ) @@ -1592,7 +1602,7 @@ bool IDF3_BOARD::SetBoardThickness( double aBoardThickness ) return false; } - if(! olnBoard.SetThickness( aBoardThickness ) ) + if( !olnBoard.SetThickness( aBoardThickness ) ) { errormsg = olnBoard.GetError(); return false; @@ -1608,7 +1618,6 @@ double IDF3_BOARD::GetBoardThickness( void ) } -// read the DRILLED HOLES section void IDF3_BOARD::readBrdDrills( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ) { IDF_DRILL_DATA drill; @@ -1618,20 +1627,18 @@ void IDF3_BOARD::readBrdDrills( std::istream& aBoardFile, IDF3::FILE_STATE& aBoa IDF_DRILL_DATA *dp = new IDF_DRILL_DATA; *dp = drill; - if( AddDrill( dp ) == NULL ) + if( AddDrill( dp ) == nullptr ) { delete dp; throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, - "\n* BUG: could not add drill data; cannot continue reading the file" ) ); + "\n* BUG: could not add drill data; cannot continue reading the " + "file" ) ); } } - - return; } -// read the NOTES section void IDF3_BOARD::readBrdNotes( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ) { IDF_NOTE note; @@ -1642,23 +1649,18 @@ void IDF3_BOARD::readBrdNotes( std::istream& aBoardFile, IDF3::FILE_STATE& aBoar *np = note; notes.push_back( np ); } - - return; } -// read the component placement section -void IDF3_BOARD::readBrdPlacement( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState, bool aNoSubstituteOutlines ) +void IDF3_BOARD::readBrdPlacement( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState, + bool aNoSubstituteOutlines ) { IDF3_COMP_OUTLINE_DATA oldata; while( oldata.readPlaceData( aBoardFile, aBoardState, this, idfVer, aNoSubstituteOutlines ) ); - - return; } -// read the board HEADER void IDF3_BOARD::readBrdHeader( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ) { std::string iline; // the input line @@ -1737,9 +1739,13 @@ void IDF3_BOARD::readBrdHeader( std::istream& aBoardFile, IDF3::FILE_STATE& aBoa "* Violation of specification: IDF Version must not be in quotes" ) ); if( !token.compare( "3.0" ) || !token.compare( "3." ) || !token.compare( "3" ) ) + { idfVer = IDF_V3; + } else if( !token.compare( "2.0" ) || !token.compare( "2." ) || !token.compare( "2" ) ) + { idfVer = IDF_V2; + } else { ostringstream ostr; @@ -1788,7 +1794,8 @@ void IDF3_BOARD::readBrdHeader( std::istream& aBoardFile, IDF3::FILE_STATE& aBoa throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" "* Violation of specification:\n" - "* HEADER section, RECORD 2, FIELD 5: Board File Version must not be in quotes" ) ); + "* HEADER section, RECORD 2, FIELD 5: Board File Version must not be " + "in quotes" ) ); // RECORD 3: // Board Name [str]: stored @@ -1838,7 +1845,8 @@ void IDF3_BOARD::readBrdHeader( std::istream& aBoardFile, IDF3::FILE_STATE& aBoa ostringstream ostr; ostr << "invalid IDF file\n"; - ostr << "* HEADER section, RECORD 3, FIELD 2: expecting MM or THOU (got '" << token << "')\n"; + ostr << "* HEADER section, RECORD 3, FIELD 2: expecting MM or THOU (got '" << token << + "')\n"; throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } @@ -1870,11 +1878,9 @@ void IDF3_BOARD::readBrdHeader( std::istream& aBoardFile, IDF3::FILE_STATE& aBoa } aBoardState = IDF3::FILE_HEADER; - return; } -// read individual board sections; pay attention to IDFv3 section specifications void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState, bool aNoSubstituteOutlines ) { @@ -1907,10 +1913,12 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( !aBoardFile.good() ) { - if( aBoardFile.eof() && aBoardState >= IDF3::FILE_HEADER && aBoardState < IDF3::FILE_INVALID ) + if( aBoardFile.eof() && aBoardState >= IDF3::FILE_HEADER && + aBoardState < IDF3::FILE_INVALID ) { if( !comments.empty() ) - ERROR_IDF << "[warning]: trailing comments in IDF file (comments will be lost)\n"; + ERROR_IDF << "[warning]: trailing comments in IDF file (comments will be " + "lost)\n"; return; } @@ -1977,11 +1985,12 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .OTHER_OUTLINE" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".OTHER_OUTLINE" ) ); OTHER_OUTLINE* op = new OTHER_OUTLINE( this ); - if( op == NULL ) + if( op == nullptr ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "could not create OTHER_OUTLINE object" ) ); @@ -2000,7 +2009,8 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo } } - if( olnOther.insert( pair(op->GetOutlineIdentifier(), op) ).second == false ) + if( olnOther.insert( pair(op->GetOutlineIdentifier(), op ) ).second == false ) { ostringstream ostr; ostr << "invalid IDF file\n"; @@ -2021,11 +2031,12 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .ROUTE_OUTLINE" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".ROUTE_OUTLINE" ) ); ROUTE_OUTLINE* op = new ROUTE_OUTLINE( this ); - if( op == NULL ) + if( op == nullptr ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "could not create ROUTE_OUTLINE object" ) ); @@ -2054,11 +2065,12 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .PLACE_OUTLINE" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".PLACE_OUTLINE" ) ); PLACE_OUTLINE* op = new PLACE_OUTLINE( this ); - if( op == NULL ) + if( op == nullptr ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "could not create PLACE_OUTLINE object" ) ); @@ -2087,11 +2099,12 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .ROUTE_KEEPOUT" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".ROUTE_KEEPOUT" ) ); ROUTE_KO_OUTLINE* op = new ROUTE_KO_OUTLINE( this ); - if( op == NULL ) + if( op == nullptr ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "could not create ROUTE_KEEPOUT object" ) ); @@ -2120,11 +2133,12 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .VIA_KEEPOUT" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".VIA_KEEPOUT" ) ); VIA_KO_OUTLINE* op = new VIA_KO_OUTLINE( this ); - if( op == NULL ) + if( op == nullptr ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "could not create VIA_KEEPOUT object" ) ); @@ -2153,11 +2167,12 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .PLACE_KEEPOUT" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".PLACE_KEEPOUT" ) ); PLACE_KO_OUTLINE* op = new PLACE_KO_OUTLINE( this ); - if( op == NULL ) + if( op == nullptr ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "could not create PLACE_KEEPOUT object" ) ); @@ -2186,11 +2201,12 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .PLACE_REGION" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".PLACE_REGION" ) ); GROUP_OUTLINE* op = new GROUP_OUTLINE( this ); - if( op == NULL ) + if( op == nullptr ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "could not create PLACE_REGION object" ) ); @@ -2219,7 +2235,8 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .DRILLED_HOLES" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".DRILLED_HOLES" ) ); readBrdDrills( aBoardFile, aBoardState ); @@ -2243,12 +2260,14 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .NOTES" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".NOTES" ) ); if( idfVer < IDF_V3 ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDFv2 file\n" - "* Violation of specification: NOTES section not in specification" ) ); + "* Violation of specification: NOTES section not in " + "specification" ) ); readBrdNotes( aBoardFile, aBoardState ); @@ -2272,7 +2291,8 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo if( aBoardState != IDF3::FILE_OUTLINE ) throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: expecting .BOARD_OUTLINE, have .PLACEMENT" ) ); + "* Violation of specification: expecting .BOARD_OUTLINE, have " + ".PLACEMENT" ) ); readBrdPlacement( aBoardFile, aBoardState, aNoSubstituteOutlines ); @@ -2290,13 +2310,10 @@ void IDF3_BOARD::readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBo return; } - } // while( aBoardFile.good() - - return; -} // readBrdSection() + } +} -// read the board file data void IDF3_BOARD::readBoardFile( const std::string& aFileName, bool aNoSubstituteOutlines ) { OPEN_ISTREAM( brd, aFileName.c_str() ); @@ -2375,7 +2392,8 @@ void IDF3_BOARD::readBoardFile( const std::string& aFileName, bool aNoSubstitute throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF file\n" - "* Violation of specification: non-comment lines after PLACEMENT section" ) ); + "* Violation of specification: non-comment lines after " + "PLACEMENT section" ) ); } } } @@ -2389,16 +2407,16 @@ void IDF3_BOARD::readBoardFile( const std::string& aFileName, bool aNoSubstitute CLOSE_STREAM( brd ); return; -} // readBoardFile() +} -// read the library sections (outlines) -void IDF3_BOARD::readLibSection( std::istream& aLibFile, IDF3::FILE_STATE& aLibState, IDF3_BOARD* aBoard ) +void IDF3_BOARD::readLibSection( std::istream& aLibFile, IDF3::FILE_STATE& aLibState, + IDF3_BOARD* aBoard ) { - if( aBoard == NULL ) + if( aBoard == nullptr ) { throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, - "\n* BUG: invoked with NULL reference aBoard" ) ); + "\n* BUG: invoked with nullptr reference aBoard" ) ); } std::list< std::string > comments; // comments associated with a section @@ -2447,7 +2465,8 @@ void IDF3_BOARD::readLibSection( std::istream& aLibFile, IDF3::FILE_STATE& aLibS { ostringstream ostr; ostr << "invalid IDF library\n"; - ostr << "* Violation of specification: quoted string where .ELECTRICAL or .MECHANICAL expected\n"; + ostr << "* Violation of specification: quoted string where .ELECTRICAL or " + ".MECHANICAL expected\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* pos: " << pos; delete pout; @@ -2473,9 +2492,10 @@ void IDF3_BOARD::readLibSection( std::istream& aLibFile, IDF3::FILE_STATE& aLibS IDF3_COMP_OUTLINE* cop = aBoard->GetComponentOutline( pout->GetUID() ); - if( cop == NULL ) + if( cop == nullptr ) { - compOutlines.insert( pair( pout->GetUID(), pout ) ); + compOutlines.insert( pair( pout->GetUID(), pout ) ); } else { @@ -2489,7 +2509,8 @@ void IDF3_BOARD::readLibSection( std::istream& aLibFile, IDF3::FILE_STATE& aLibS ostringstream ostr; ostr << "invalid IDF library\n"; ostr << "duplicate Component Outline: '" << pout->GetUID() << "'\n"; - ostr << "* Violation of specification: multiple outlines have the same GEOM and PART name\n"; + ostr << "* Violation of specification: multiple outlines have the same GEOM and " + "PART name\n"; ostr << "* line: '" << iline << "'\n"; ostr << "* pos: " << pos; delete pout; @@ -2598,9 +2619,13 @@ void IDF3_BOARD::readLibHeader( std::istream& aLibFile, IDF3::FILE_STATE& aLibSt "* Violation of specification: IDF Version must not be in quotes" ) ); if( !token.compare( "3.0" ) || !token.compare( "3." ) || !token.compare( "3" ) ) + { idfVer = IDF_V3; + } else if( !token.compare( "2.0" ) || !token.compare( "2." ) || !token.compare( "2" ) ) + { idfVer = IDF_V2; + } else { ostringstream ostr; @@ -2649,7 +2674,8 @@ void IDF3_BOARD::readLibHeader( std::istream& aLibFile, IDF3::FILE_STATE& aLibSt throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, "invalid IDF library file\n" "* Violation of specification:\n" - "* HEADER section, RECORD 2, FIELD 5: Library File Version must not be in quotes" ) ); + "* HEADER section, RECORD 2, FIELD 5: Library File Version must not " + "be in quotes" ) ); // RECORD 3: // .END_HEADER @@ -2674,11 +2700,9 @@ void IDF3_BOARD::readLibHeader( std::istream& aLibFile, IDF3::FILE_STATE& aLibSt } aLibState = IDF3::FILE_HEADER; - return; } -// read the library file data void IDF3_BOARD::readLibFile( const std::string& aFileName ) { OPEN_ISTREAM( lib, aFileName.c_str() ); @@ -2710,7 +2734,6 @@ void IDF3_BOARD::readLibFile( const std::string& aFileName ) } CLOSE_STREAM( lib ); - return; } @@ -2817,7 +2840,6 @@ bool IDF3_BOARD::ReadFile( const wxString& aFullFileName, bool aNoSubstituteOutl } -// write the library file data bool IDF3_BOARD::writeLibFile( const std::string& aFileName ) { OPEN_OSTREAM( lib, aFileName.c_str() ); @@ -2835,7 +2857,7 @@ bool IDF3_BOARD::writeLibFile( const std::string& aFileName ) } lib.imbue( std::locale( "C" ) ); - wxDateTime tdate( time( NULL ) ); + wxDateTime tdate( time( nullptr ) ); if( idfSource.empty() ) idfSource = "KiCad-IDF Framework"; @@ -2872,7 +2894,7 @@ bool IDF3_BOARD::writeLibFile( const std::string& aFileName ) return true; } -// write the board file data + void IDF3_BOARD::writeBoardFile( const std::string& aFileName ) { OPEN_OSTREAM( brd, aFileName.c_str() ); @@ -2890,7 +2912,7 @@ void IDF3_BOARD::writeBoardFile( const std::string& aFileName ) } brd.imbue( std::locale( "C" ) ); - wxDateTime tdate( time( NULL ) ); + wxDateTime tdate( time( nullptr ) ); if( idfSource.empty() ) idfSource = "KiCad-IDF Framework"; @@ -3215,38 +3237,44 @@ const std::string& IDF3_BOARD::GetIDFSource( void ) } -void IDF3_BOARD::SetIDFSource( const std::string& aIDFSource ) +void IDF3_BOARD::SetIDFSource( const std::string& aIDFSource ) { idfSource = aIDFSource; return; } + const std::string& IDF3_BOARD::GetBoardSource( void ) { return brdSource; } + const std::string& IDF3_BOARD::GetLibrarySource( void ) { return libSource; } + const std::string& IDF3_BOARD::GetBoardDate( void ) { return brdDate; } + const std::string& IDF3_BOARD::GetLibraryDate( void ) { return libDate; } -int IDF3_BOARD::GetBoardVersion( void ) + +int IDF3_BOARD::GetBoardVersion( void ) { return brdFileVersion; } -bool IDF3_BOARD::SetBoardVersion( int aVersion ) + +bool IDF3_BOARD::SetBoardVersion( int aVersion ) { if( aVersion < 0 ) { @@ -3264,13 +3292,13 @@ bool IDF3_BOARD::SetBoardVersion( int aVersion ) } -int IDF3_BOARD::GetLibraryVersion( void ) +int IDF3_BOARD::GetLibraryVersion( void ) { return libFileVersion; } -bool IDF3_BOARD::SetLibraryVersion( int aVersion ) +bool IDF3_BOARD::SetLibraryVersion( int aVersion ) { if( aVersion < 0 ) { @@ -3310,11 +3338,13 @@ bool IDF3_BOARD::SetUserScale( double aScaleFactor ) return true; } + int IDF3_BOARD::GetUserPrecision( void ) { return userPrec; } + bool IDF3_BOARD::SetUserPrecision( int aPrecision ) { if( aPrecision < 1 || aPrecision > 8 ) @@ -3336,7 +3366,6 @@ void IDF3_BOARD::GetUserOffset( double& aXoff, double& aYoff ) { aXoff = userXoff; aYoff = userYoff; - return; } @@ -3344,7 +3373,6 @@ void IDF3_BOARD::SetUserOffset( double aXoff, double aYoff ) { userXoff = aXoff; userYoff = aYoff; - return; } @@ -3404,23 +3432,24 @@ const std::list< IDF_OUTLINE* >*const IDF3_BOARD::GetBoardOutlines( void ) IDF_DRILL_DATA* IDF3_BOARD::AddBoardDrill( double aDia, double aXpos, double aYpos, - IDF3::KEY_PLATING aPlating, - const std::string& aHoleType, - IDF3::KEY_OWNER aOwner ) + IDF3::KEY_PLATING aPlating, + const std::string& aHoleType, + IDF3::KEY_OWNER aOwner ) { IDF_DRILL_DATA* drill = new IDF_DRILL_DATA( aDia, aXpos, aYpos, aPlating, "BOARD", aHoleType, aOwner ); - if( drill != NULL ) + if( drill != nullptr ) board_drills.push_back( drill ); return drill; } + IDF_DRILL_DATA* IDF3_BOARD::AddDrill( IDF_DRILL_DATA* aDrilledHole ) { if( !aDrilledHole ) - return NULL; + return nullptr; // note: PANEL drills are essentially BOARD drills which // the panel requires to be present @@ -3506,10 +3535,6 @@ bool IDF3_BOARD::DelBoardDrill( double aDia, double aXpos, double aYpos ) } -// a slot is a deficient representation of a kicad slotted hole; -// it is usually associated with a component but IDFv3 does not -// provide for such an association. Note: this mechanism must bypass -// the BOARD_OUTLINE ownership rules bool IDF3_BOARD::AddSlot( double aWidth, double aLength, double aOrientation, double aX, double aY ) { if( aWidth < IDF_MIN_DIA_MM ) @@ -3564,7 +3589,7 @@ bool IDF3_BOARD::AddSlot( double aWidth, double aLength, double aOrientation, do IDF_OUTLINE* outline = new IDF_OUTLINE; - if( outline == NULL ) + if( outline == nullptr ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; @@ -3577,12 +3602,15 @@ bool IDF3_BOARD::AddSlot( double aWidth, double aLength, double aOrientation, do // first straight run IDF_SEGMENT* seg = new IDF_SEGMENT( pt[0], pt[1] ); outline->push( seg ); + // first 180 degree cap seg = new IDF_SEGMENT( c[1], pt[1], -180.0, true ); outline->push( seg ); + // final straight run seg = new IDF_SEGMENT( pt[2], pt[3] ); outline->push( seg ); + // final 180 degree cap seg = new IDF_SEGMENT( c[0], pt[3], -180.0, true ); outline->push( seg ); @@ -3598,10 +3626,10 @@ bool IDF3_BOARD::AddSlot( double aWidth, double aLength, double aOrientation, do IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( double aDia, double aXpos, double aYpos, - IDF3::KEY_PLATING aPlating, - const std::string& aHoleType, - IDF3::KEY_OWNER aOwner, - const std::string& aRefDes ) + IDF3::KEY_PLATING aPlating, + const std::string& aHoleType, + IDF3::KEY_OWNER aOwner, + const std::string& aRefDes ) { // first find the matching component; if it doesn't exist we must create it somehow - // question is, do we need a component outline at this stage or can those be added later? @@ -3630,7 +3658,7 @@ IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( double aDia, double aXpos, double aYpo ostr << "* PANEL data not supported"; errormsg = ostr.str(); - return NULL; + return nullptr; } std::map::iterator ref = components.find( refdes ); @@ -3640,19 +3668,20 @@ IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( double aDia, double aXpos, double aYpo // create the item IDF3_COMPONENT* comp = new IDF3_COMPONENT( this ); - if( comp == NULL ) + if( comp == nullptr ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; ostr << "* could not create new component object"; errormsg = ostr.str(); - return NULL; + return nullptr; } comp->SetParent( this ); comp->SetRefDes( refdes ); - ref = components.insert( std::pair< std::string, IDF3_COMPONENT*> ( comp->GetRefDes(), comp ) ).first; + ref = components.insert( std::pair< std::string, + IDF3_COMPONENT*> ( comp->GetRefDes(), comp ) ).first; } // add the drill @@ -3661,7 +3690,7 @@ IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( double aDia, double aXpos, double aYpo if( !dp ) { errormsg = ref->second->GetError(); - return NULL; + return nullptr; } return dp; @@ -3673,10 +3702,10 @@ IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( IDF_DRILL_DATA* aDrilledHole ) if( !aDrilledHole ) { ostringstream ostr; - ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): NULL pointer"; + ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): nullptr pointer"; errormsg = ostr.str(); - return NULL; + return nullptr; } if( CompareToken( "PANEL", aDrilledHole->GetDrillRefDes() ) ) @@ -3686,29 +3715,31 @@ IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( IDF_DRILL_DATA* aDrilledHole ) ostr << "* PANEL data not supported"; errormsg = ostr.str(); - return NULL; + return nullptr; } - std::map::iterator ref = components.find( aDrilledHole->GetDrillRefDes() ); + std::map::iterator ref = + components.find( aDrilledHole->GetDrillRefDes() ); if( ref == components.end() ) { // create the item IDF3_COMPONENT* comp = new IDF3_COMPONENT( this ); - if( comp == NULL ) + if( comp == nullptr ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "():\n"; ostr << "* could not create new component object"; errormsg = ostr.str(); - return NULL; + return nullptr; } comp->SetParent( this ); comp->SetRefDes( aDrilledHole->GetDrillRefDes() ); - ref = components.insert( std::pair< std::string, IDF3_COMPONENT*> ( comp->GetRefDes(), comp ) ).first; + ref = components.insert( std::pair< std::string, + IDF3_COMPONENT*> ( comp->GetRefDes(), comp ) ).first; } IDF_DRILL_DATA* dp = ref->second->AddDrill( aDrilledHole ); @@ -3716,7 +3747,7 @@ IDF_DRILL_DATA* IDF3_BOARD::addCompDrill( IDF_DRILL_DATA* aDrilledHole ) if( !dp ) { errormsg = ref->second->GetError(); - return NULL; + return nullptr; } return dp; @@ -3748,7 +3779,7 @@ bool IDF3_BOARD::AddComponent( IDF3_COMPONENT* aComponent ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__; - ostr << "(): Invalid component pointer (NULL)"; + ostr << "(): Invalid component pointer (nullptr)"; errormsg = ostr.str(); return false; @@ -3836,14 +3867,12 @@ IDF3_COMPONENT* IDF3_BOARD::FindComponent( const std::string& aRefDes ) std::map::iterator it = components.find( aRefDes ); if( it == components.end() ) - return NULL; + return nullptr; return it->second; } -// returns a pointer to a component outline object or NULL -// if the object doesn't exist IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileName ) { std::string fname = TO_UTF8( aFullFileName ); @@ -3856,7 +3885,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam cerr << "* invalid file name: '" << fname << "'"; errormsg = ostr.str(); - return NULL; + return nullptr; } if( !idflib.FileExists() ) @@ -3866,7 +3895,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam cerr << "* no such file: '" << fname << "'"; errormsg = ostr.str(); - return NULL; + return nullptr; } if( !idflib.IsFileReadable() ) @@ -3876,7 +3905,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam cerr << "* cannot read file: '" << fname << "'"; errormsg = ostr.str(); - return NULL; + return nullptr; } std::map< std::string, std::string >::iterator itm = uidFileList.find( fname ); @@ -3886,7 +3915,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam IDF3_COMP_OUTLINE* cp = new IDF3_COMP_OUTLINE( this ); - if( cp == NULL ) + if( cp == nullptr ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): \n"; @@ -3894,7 +3923,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam cerr << "* filename: '" << fname << "'"; errormsg = ostr.str(); - return NULL; + return nullptr; } OPEN_ISTREAM( model, fname.c_str() ); @@ -3911,13 +3940,11 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } - model.imbue( std::locale( "C" ) ); std::string iline; // the input line bool isComment; // true if a line just read in is a comment line std::streampos pos; - while( true ) { while( !FetchIDFLine( model, iline, isComment, pos ) && model.good() ); @@ -3950,7 +3977,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam throw( IDF_ERROR( __FILE__, __FUNCTION__, __LINE__, ostr.str() ) ); } - } // while( true ) + } } catch( const std::exception& e ) { @@ -3958,7 +3985,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam model.exceptions ( std::ios_base::goodbit ); CLOSE_STREAM( model ); errormsg = e.what(); - return NULL; + return nullptr; } CLOSE_STREAM( model ); @@ -3967,7 +3994,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam std::list< std::string >::iterator lsts = uidLibList.begin(); std::list< std::string >::iterator lste = uidLibList.end(); std::string uid = cp->GetUID(); - IDF3_COMP_OUTLINE* oldp = NULL; + IDF3_COMP_OUTLINE* oldp = nullptr; while( lsts != lste ) { @@ -3979,8 +4006,10 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam { // everything is fine; the outlines are genuine duplicates; delete the copy delete cp; + // make sure we can find the item via its filename uidFileList.insert( std::pair< std::string, std::string>( fname, uid ) ); + // return the pointer to the original return oldp; } @@ -3994,7 +4023,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam ostr << "* file: '" << fname << "'"; errormsg = ostr.str(); - return NULL; + return nullptr; } } @@ -4004,7 +4033,7 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam // if we got this far then any duplicates are from files previously read oldp = GetComponentOutline( uid ); - if( oldp == NULL ) + if( oldp == nullptr ) { // everything is fine, there are no existing entries uidFileList.insert( std::pair< std::string, std::string>( fname, uid ) ); @@ -4017,8 +4046,10 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam { // everything is fine; the outlines are genuine duplicates; delete the copy delete cp; + // make sure we can find the item via its other filename uidFileList.insert( std::pair< std::string, std::string>( fname, uid ) ); + // return the pointer to the original return oldp; } @@ -4048,12 +4079,10 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const wxString& aFullFileNam ostr << "* this file: '" << fname << "'"; errormsg = ostr.str(); - return NULL; + return nullptr; } -// returns a pointer to the component outline object with the -// unique ID aComponentID IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const std::string& aComponentID ) { std::map< std::string, IDF3_COMP_OUTLINE*>::iterator its = compOutlines.find( aComponentID ); @@ -4061,13 +4090,12 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetComponentOutline( const std::string& aComponen if( its != compOutlines.end() ) return its->second; - return NULL; + return nullptr; } -// returns a pointer to the outline which is substituted -// whenever a true outline cannot be found or is defective -IDF3_COMP_OUTLINE* IDF3_BOARD::GetInvalidOutline( const std::string& aGeomName, const std::string& aPartName ) +IDF3_COMP_OUTLINE* IDF3_BOARD::GetInvalidOutline( const std::string& aGeomName, + const std::string& aPartName ) { std::string uid; bool empty = false; @@ -4084,19 +4112,19 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetInvalidOutline( const std::string& aGeomName, IDF3_COMP_OUTLINE* cp = GetComponentOutline( uid ); - if( cp != NULL ) + if( cp != nullptr ) return cp; cp = new IDF3_COMP_OUTLINE( this ); - if( cp == NULL ) + if( cp == nullptr ) { ostringstream ostr; ostr << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "(): "; cerr << "could not create new outline"; errormsg = ostr.str(); - return NULL; + return nullptr; } if( empty ) @@ -4110,7 +4138,6 @@ IDF3_COMP_OUTLINE* IDF3_BOARD::GetInvalidOutline( const std::string& aGeomName, } -// clears all data void IDF3_BOARD::Clear( void ) { // preserve the board thickness @@ -4153,7 +4180,7 @@ void IDF3_BOARD::Clear( void ) } board_drills.clear(); - } while(0); + } while( 0 ); // delete components @@ -4169,7 +4196,7 @@ void IDF3_BOARD::Clear( void ) } components.clear(); - } while(0); + } while( 0 ); // delete component outlines @@ -4185,7 +4212,7 @@ void IDF3_BOARD::Clear( void ) } compOutlines.clear(); - } while(0); + } while( 0 ); // delete OTHER outlines @@ -4201,7 +4228,7 @@ void IDF3_BOARD::Clear( void ) } olnOther.clear(); - } while(0); + } while( 0 ); // delete ROUTE outlines @@ -4217,7 +4244,7 @@ void IDF3_BOARD::Clear( void ) } olnRoute.clear(); - } while(0); + } while( 0 ); // delete PLACE outlines @@ -4233,7 +4260,7 @@ void IDF3_BOARD::Clear( void ) } olnPlace.clear(); - } while(0); + } while( 0 ); // delete ROUTE KEEPOUT outlines @@ -4249,7 +4276,7 @@ void IDF3_BOARD::Clear( void ) } olnRouteKeepout.clear(); - } while(0); + } while( 0 ); // delete VIA KEEPOUT outlines @@ -4265,7 +4292,7 @@ void IDF3_BOARD::Clear( void ) } olnViaKeepout.clear(); - } while(0); + } while( 0 ); // delete PLACEMENT KEEPOUT outlines @@ -4281,7 +4308,7 @@ void IDF3_BOARD::Clear( void ) } olnPlaceKeepout.clear(); - } while(0); + } while( 0 ); // delete PLACEMENT GROUP outlines @@ -4297,7 +4324,7 @@ void IDF3_BOARD::Clear( void ) } olnGroup.clear(); - } while(0); + } while( 0 ); boardName.clear(); olnBoard.setThickness( thickness ); @@ -4306,13 +4333,10 @@ void IDF3_BOARD::Clear( void ) userScale = 1.0; userXoff = 0.0; userYoff = 0.0; - - return; } -const std::map*const -IDF3_BOARD::GetOtherOutlines( void ) +const std::map* const IDF3_BOARD::GetOtherOutlines( void ) { return &olnOther; } diff --git a/utils/idftools/idf_parser.h b/utils/idftools/idf_parser.h index 6761386793..657017f719 100644 --- a/utils/idftools/idf_parser.h +++ b/utils/idftools/idf_parser.h @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2017 Cirilo Bernardo + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -61,85 +62,29 @@ class IDF3_COMPONENT; class IDF3_COMP_OUTLINE_DATA { -friend class IDF3_BOARD; -friend class IDF3_COMPONENT; -private: - double xoff; // X offset from KiCad or X placement from IDF file - double yoff; // Y offset from KiCad or Y placement from IDF file - double zoff; // height offset (specified in IDFv3 spec, corresponds to KiCad Z offset) - double aoff; // angular offset from KiCad or Rotation Angle from IDF file - std::string errormsg; - - IDF3_COMP_OUTLINE* outline; // component outline to use - IDF3_COMPONENT* parent; // associated component - -#ifndef DISABLE_IDF_OWNERSHIP - bool checkOwnership( int aSourceLine, const char* aSourceFunc ); -#endif - - /** - * Function readPlaceData - * reads placement data from an open IDFv3 file - * - * @param aBoardFile is the open IDFv3 file - * @param aBoardState is the internal status flag of the IDF parser - * @param aIdfVersion is the version of the file currently being parsed - * @param aBoard is the IDF3_BOARD object which will store the data - * - * @return bool: true if placement data was successfully read. false if - * no placement data was read; this may happen if the end of the placement - * data was encountered or an error occurred. if an error occurred then - * an exception is thrown. - */ - bool readPlaceData( std::istream &aBoardFile, IDF3::FILE_STATE& aBoardState, - IDF3_BOARD *aBoard, IDF3::IDF_VERSION aIdfVersion, - bool aNoSubstituteOutlines ); - - /** - * Function writePlaceData - * writes RECORD 2 and RECORD 3 of a PLACEMENT section as per IDFv3 specification - * - * @param aBoardFile is the open IDFv3 file - * @param aXpos is the X location of the parent component - * @param aYpos is the Y location of the parent component - * @param aAngle is the rotation of the parent component - * @param aRefDes is the reference designator of the parent component - * @param aPlacement is the IDF Placement Status of the parent component - * @param aSide is the IDF Layer Designator (TOP or BOTTOM) - * - * @return bool: true if data was successfully written, otherwise false - */ - void writePlaceData( std::ostream& aBoardFile, double aXpos, double aYpos, double aAngle, - const std::string& aRefDes, IDF3::IDF_PLACEMENT aPlacement, - IDF3::IDF_LAYER aSide ); - public: /** - * Constructor - * creates an object with default settings and no parent or associated outline + * Create an object with default settings and no parent or associated outline. */ IDF3_COMP_OUTLINE_DATA(); /** - * Constructor - * creates an object with default settings and the specified parent and associated outline + * Create an object with default settings and the specified parent and associated outline. * - * @param aParent is the owning IDF3_COMPONENT object - * @param aOutline is the outline for this placed component + * @param aParent is the owning IDF3_COMPONENT object. + * @param aOutline is the outline for this placed component. */ IDF3_COMP_OUTLINE_DATA( IDF3_COMPONENT* aParent, IDF3_COMP_OUTLINE* aOutline ); /** - * Constructor - * creates an object the specified parent and associated outline and the specified - * data. + * Create an object the specified parent and associated outline and the specified data. * - * @param aParent is the owning IDF3_COMPONENT object - * @param aOutline is the outline for this placed component - * @param aXoff is the X offset of this outline in relation to its parent - * @param aYoff is the Y offset of this outline in relation to its parent - * @param aZoff is the board offset of this outline as per IDFv3 specification - * @param aAoff is the rotational offset of this outline in relation to its parent + * @param aParent is the owning IDF3_COMPONENT object. + * @param aOutline is the outline for this placed component. + * @param aXoff is the X offset of this outline in relation to its parent. + * @param aYoff is the Y offset of this outline in relation to its parent. + * @param aZoff is the board offset of this outline as per IDFv3 specification. + * @param aAoff is the rotational offset of this outline in relation to its parent. */ IDF3_COMP_OUTLINE_DATA( IDF3_COMPONENT* aParent, IDF3_COMP_OUTLINE* aOutline, double aXoff, double aYoff, double aZoff, double aAngleOff ); @@ -147,54 +92,46 @@ public: ~IDF3_COMP_OUTLINE_DATA(); /** - * Function SetOffsets - * sets the position and orientation of this outline item in relation to its parent + * Set the position and orientation of this outline item in relation to its parent. * - * @param aXoff is the X offset of this outline in relation to its parent - * @param aYoff is the Y offset of this outline in relation to its parent - * @param aZoff is the board offset of this outline as per IDFv3 specification - * @param aAoff is the rotational offset of this outline in relation to its parent + * @param aXoff is the X offset of this outline in relation to its parent. + * @param aYoff is the Y offset of this outline in relation to its parent. + * @param aZoff is the board offset of this outline as per IDFv3 specification. + * @param aAoff is the rotational offset of this outline in relation to its parent. * - * @return bool: true if the operation succeeded, false if an ownership - * violation occurred + * @return true if the operation succeeded, false if an ownership violation occurred. */ bool SetOffsets( double aXoff, double aYoff, double aZoff, double aAngleOff ); /** - * Function GetOffsets - * retrieves the position and orientation of this outline item in relation to its parent + * Retrieve the position and orientation of this outline item in relation to its parent. * - * @param aXoff is the X offset of this outline in relation to its parent - * @param aYoff is the Y offset of this outline in relation to its parent - * @param aZoff is the board offset of this outline as per IDFv3 specification - * @param aAoff is the rotational offset of this outline in relation to its parent + * @param aXoff is the X offset of this outline in relation to its parent. + * @param aYoff is the Y offset of this outline in relation to its parent. + * @param aZoff is the board offset of this outline as per IDFv3 specification. + * @param aAoff is the rotational offset of this outline in relation to its parent. */ void GetOffsets( double& aXoff, double& aYoff, double& aZoff, double& aAngleOff ); /** - * Function SetParent - * sets the parent object + * Set the parent object. * - * @param aParent is the owning IDF3_COMPONENT object + * @param aParent is the owning IDF3_COMPONENT object. */ void SetParent( IDF3_COMPONENT* aParent ); /** - * Function SetOutline - * sets the outline whose position is managed by this object + * Set the outline whose position is managed by this object. * - * @param aOutline is the outline for this component - * - * @return bool: true if the operation succeeded, false if an ownership - * violation occurred + * @param aOutline is the outline for this component. + * @return true if the operation succeeded, false if an ownership violation occurred. */ bool SetOutline( IDF3_COMP_OUTLINE* aOutline ); /** - * Function GetOutline - * retrieves the outline whose position is managed by this object + * Retrieve the outline whose position is managed by this object. * - * @return IDF3_COMP_OUTLINE*: the outline for this component + * @return the outline for this component. */ IDF3_COMP_OUTLINE* GetOutline( void ) { @@ -205,13 +142,267 @@ public: { return errormsg; } + +private: + +#ifndef DISABLE_IDF_OWNERSHIP + bool checkOwnership( int aSourceLine, const char* aSourceFunc ); +#endif + + /** + * Read placement data from an open IDFv3 file. + * + * @param aBoardFile is the open IDFv3 file + * @param aBoardState is the internal status flag of the IDF parser + * @param aIdfVersion is the version of the file currently being parsed + * @param aBoard is the IDF3_BOARD object which will store the data + * + * @return true if placement data was successfully read. false if + * no placement data was read; this may happen if the end of the placement + * data was encountered or an error occurred. if an error occurred then + * an exception is thrown. + */ + bool readPlaceData( std::istream &aBoardFile, IDF3::FILE_STATE& aBoardState, + IDF3_BOARD *aBoard, IDF3::IDF_VERSION aIdfVersion, + bool aNoSubstituteOutlines ); + + /** + * Write RECORD 2 and RECORD 3 of a PLACEMENT section as per IDFv3 specification. + * + * @param aBoardFile is the open IDFv3 file. + * @param aXpos is the X location of the parent component. + * @param aYpos is the Y location of the parent component. + * @param aAngle is the rotation of the parent component. + * @param aRefDes is the reference designator of the parent component. + * @param aPlacement is the IDF Placement Status of the parent component. + * @param aSide is the IDF Layer Designator (TOP or BOTTOM). + * @return true if data was successfully written, otherwise false. + */ + void writePlaceData( std::ostream& aBoardFile, double aXpos, double aYpos, double aAngle, + const std::string& aRefDes, IDF3::IDF_PLACEMENT aPlacement, + IDF3::IDF_LAYER aSide ); + + friend class IDF3_BOARD; + friend class IDF3_COMPONENT; + + double xoff; // X offset from KiCad or X placement from IDF file + double yoff; // Y offset from KiCad or Y placement from IDF file + double zoff; // height offset (specified in IDFv3 spec, corresponds to KiCad Z offset) + double aoff; // angular offset from KiCad or Rotation Angle from IDF file + std::string errormsg; + + IDF3_COMP_OUTLINE* outline; // component outline to use + IDF3_COMPONENT* parent; // associated component }; class IDF3_COMPONENT { -friend class IDF3_BOARD; +public: + /** + * Set the parent object and initializes other internal parameters to default values. + * + * @param aParent is the owning IDF3_BOARD object. + */ + IDF3_COMPONENT( IDF3_BOARD* aParent ); + + ~IDF3_COMPONENT(); + + /** + * Set the parent object. + * + * @param aParent is the owning IDF3_BOARD object. + */ + void SetParent( IDF3_BOARD* aParent ); + + /** + * @return the type of CAD (IDF3::CAD_ELEC, IDF3::CAD_MECH) which instantiated this object. + */ + IDF3::CAD_TYPE GetCadType( void ); + + /** + * @return the IDF UNIT type of the parent object or IDF3::UNIT_INVALID if the parent was + * not set. + */ + IDF3::IDF_UNIT GetUnit( void ); + + /** + * Set the Reference Designator (RefDes) of this component. + * + * The RefDes is shared by all outlines associated with this component. + * + * @return true if the RefDes was accepted, otherwise false. Prohibited values include empty + * strings and the word PANEL. + */ + bool SetRefDes( const std::string& aRefDes ); + + /** + * Retrieve the Reference Designator (RefDes) of this component. + * + * @return the Reference Designator. + */ + const std::string& GetRefDes( void ); + + /** + * Add a drill entry to the component and returns its pointer. + * + * @param aDia diameter of the drill (mm). + * @param aXpos X position of the drill (mm). + * @param aYpos Y position of the drill (mm). + * @param aPlating plating type (PTH, NPTH). + * @param aHoleType hole class (PIN, VIA, MTG, TOOL, etc). + * @param aOwner owning CAD system (ECAD, MCAD, UNOWNED). + * @return the newly created drill entry or NULL. + */ + IDF_DRILL_DATA* AddDrill( double aDia, double aXpos, double aYpos, + IDF3::KEY_PLATING aPlating, + const std::string& aHoleType, + IDF3::KEY_OWNER aOwner ); + + /** + * Add the given drill entry to the component and returns the pointer to indicate success. + * + * A return value of NULL indicates that the item was not added and it is the user's + * responsibility to delete the object if necessary. + * + * @param aDrilledHole pointer to a drill entry. + * @return aDrilledHole if the function succeeds, otherwise NULL. + */ + IDF_DRILL_DATA* AddDrill( IDF_DRILL_DATA* aDrilledHole ); + + /** + * Delete a drill entry based on its size and location. + * + * This operation is subject to IDF ownership rules. + * + * @param aDia diameter (mm) of the drilled hole to be deleted. + * @param aXpos X position (mm) of the hole to be deleted. + * @param aYpos X position (mm) of the hole to be deleted. + * @return true if a drill was found and deleted, otherwise false. + * @throw if an ownership violation occurs. + */ + bool DelDrill( double aDia, double aXpos, double aYpos ); + + /** + * Delete a drill entry based on pointer. + * + * This operation is subject to IDF ownership rules. + * + * @param aDrill the pointer associated with the drill entry to be deleted. + * @return true if a drill was found and deleted, otherwise false. + * @throw if an ownership violation occurs. + */ + bool DelDrill( IDF_DRILL_DATA* aDrill ); + + /** + * Return the internal list of drills. + * + * To avoid IDF violations, the user should not alter these entries. + */ + const std::list< IDF_DRILL_DATA* >* const GetDrills( void ); + + /** + * Add the given component outline data to this component. + * + * @param aComponentOutline is a pointer to the outline data to be added. + * @return true if the operation succeeds, otherwise false. + */ + bool AddOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutline ); + + /** + * Remove outline data based on the pointer provided. + * + * @param aComponentOutline is a pointer to be deleted from the internal list. + * @return true if the data was found and deleted, otherwise false. + */ + bool DeleteOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutline ); + + /** + * Remove outline data based on the provided index. + * + * @param aIndex is an index to the internal outline list. + * @return true if the data was deleted, false if the index was out of bounds. + */ + bool DeleteOutlineData( size_t aIndex ); + + /** + * @return the number of outlines in the internal list. + */ + size_t GetOutlinesSize( void ); + + + /** + * @return the internal list of outline data. + */ + const std::list< IDF3_COMP_OUTLINE_DATA* >*const GetOutlinesData( void ); + + /** + * Retrieve the internal position parameters and returns true if the + * position was previously set, otherwise false. + */ + bool GetPosition( double& aXpos, double& aYpos, double& aAngle, IDF3::IDF_LAYER& aLayer ); + + // NOTE: it may be possible to extend this so that internal drills and outlines + // are moved when the component is moved. However there is always a danger of + // position creep due to the relative position updates. + /** + * Set the internal position parameters and returns true if the position was set, false if + * the position was previously set. + * + * This object does not allow modification of the position once it is set since this may + * adversely affect the relationship with its internal objects. + * + * @param aXpos is the X position (mm) of the component. + * @param aYpos is the Y position (mm) of the component. + * @param aAngle is the rotation of the component (degrees). + * @param aLayer is the layer on which the component is places (TOP, BOTTOM). + * @return true if the position was set, otherwise false. + */ + bool SetPosition( double aXpos, double aYpos, double aAngle, IDF3::IDF_LAYER aLayer ); + + /** + * @return the IDF placement value of this component (UNPLACED, PLACED, ECAD, MCAD). + */ + IDF3::IDF_PLACEMENT GetPlacement( void ); + + /** + * Set the placement value of the component subject to ownership rules. + * + * An exception is thrown if aPlacementValue is invalid or an ownership + * violation occurs. + * + * @return true if the operation succeeded, otherwise false and the error message is set. + */ + bool SetPlacement( IDF3::IDF_PLACEMENT aPlacementValue ); + + const std::string& GetError( void ) + { + return errormsg; + } + private: + friend class IDF3_BOARD; + + /** + * Write the internal drill data to an IDFv3 .DRILLED_HOLES section. + * + * @param aBoardFile is an IDFv3 file opened for writing. + * @return true if the operation succeeded, otherwise false. + */ + bool writeDrillData( std::ostream& aBoardFile ); + + /** + * Write the component placement data to an IDFv3 .PLACEMENT section. + * + * @param aBoardFile is an IDFv3 file opened for writing. + * @return true if the operation succeeded, otherwise false. + */ + bool writePlaceData( std::ostream& aBoardFile ); + +#ifndef DISABLE_IDF_OWNERSHIP + bool checkOwnership( int aSourceLine, const char* aSourceFunc ); +#endif + std::list< IDF3_COMP_OUTLINE_DATA* > components; std::list< IDF_DRILL_DATA* > drills; @@ -224,341 +415,11 @@ private: std::string refdes; ///< Reference Description (MUST BE UNIQUE) IDF3_BOARD* parent; std::string errormsg; - - /** - * Function WriteDrillData - * writes the internal drill data to an IDFv3 .DRILLED_HOLES section - * - * @param aBoardFile is an IDFv3 file opened for writing - * - * @return bool: true if the operation succeeded, otherwise false - */ - bool writeDrillData( std::ostream& aBoardFile ); - - /** - * Function WritePlaceData - * writes the component placement data to an IDFv3 .PLACEMENT section - * - * @param aBoardFile is an IDFv3 file opened for writing - * - * @return bool: true if the operation succeeded, otherwise false - */ - bool writePlaceData( std::ostream& aBoardFile ); - -#ifndef DISABLE_IDF_OWNERSHIP - bool checkOwnership( int aSourceLine, const char* aSourceFunc ); -#endif - -public: - /** - * Constructor - * sets the parent object and initializes other internal parameters to default values - * - * @param aParent is the owning IDF3_BOARD object - */ - IDF3_COMPONENT( IDF3_BOARD* aParent ); - - ~IDF3_COMPONENT(); - - /** - * Function SetParent - * sets the parent object - * - * @param aParent is the owning IDF3_BOARD object - */ - void SetParent( IDF3_BOARD* aParent ); - - /** - * Function GetCadType - * returns the type of CAD (IDF3::CAD_ELEC, IDF3::CAD_MECH) which instantiated this object - * - * @return IDF3::CAD_TYPE - */ - IDF3::CAD_TYPE GetCadType( void ); - - /** - * Function GetCadType - * returns the IDF UNIT type of the parent object or IDF3::UNIT_INVALID if - * the parent was not set - * - * @return IDF3::IDF_UNIT - */ - IDF3::IDF_UNIT GetUnit( void ); - - /** - * Function SetRefDes - * sets the Reference Designator (RefDes) of this component; the RefDes is shared - * by all outlines associated with this component. - * - * @return bool: true if the RefDes was accepted, otherwise false. Prohibited - * values include empty strings and the word PANEL. - */ - bool SetRefDes( const std::string& aRefDes ); - - /** - * Function GetRefDes - * Retrieves the Reference Designator (RefDes) of this component - * - * @return string: the Reference Designator - */ - const std::string& GetRefDes( void ); - - /** - * Function AddDrill - * adds a drill entry to the component and returns its pointer - * - * @param aDia diameter of the drill (mm) - * @param aXpos X position of the drill (mm) - * @param aYpos Y position of the drill (mm) - * @param aPlating plating type (PTH, NPTH) - * @param aHoleType hole class (PIN, VIA, MTG, TOOL, etc) - * @param aOwner owning CAD system (ECAD, MCAD, UNOWNED) - * - * @return pointer: a pointer to the newly created drill entry or NULL - */ - IDF_DRILL_DATA* AddDrill( double aDia, double aXpos, double aYpos, - IDF3::KEY_PLATING aPlating, - const std::string& aHoleType, - IDF3::KEY_OWNER aOwner ); - - /** - * Function AddDrill - * adds the given drill entry to the component and returns the pointer - * to indicate success. A return value of NULL indicates that the item - * was not added and it is the user's responsibility to delete the - * object if necessary. - * - * @param aDrilledHole pointer to a drill entry - * - * @return pointer: aDrilledHole if the function succeeds, otherwise NULL - */ - IDF_DRILL_DATA* AddDrill( IDF_DRILL_DATA* aDrilledHole ); - - /** - * Function DelDrill( double aDia, double aXpos, double aYpos ) - * deletes a drill entry based on its size and location. This operation is - * subject to IDF ownership rules. - * - * @param aDia diameter (mm) of the drilled hole to be deleted - * @param aXpos X position (mm) of the hole to be deleted - * @param aYpos X position (mm) of the hole to be deleted - * - * @return bool: true if a drill was found and deleted, otherwise false. - * If an ownership violation occurs an exception is thrown. - */ - bool DelDrill( double aDia, double aXpos, double aYpos ); - - /** - * Function DelDrill( IDF_DRILL_DATA* aDrill ) - * deletes a drill entry based on pointer. This operation is - * subject to IDF ownership rules. - * - * @param aDrill the pointer associated with the drill entry to be deleted - * - * @return bool: true if a drill was found and deleted, otherwise false. - * If an ownership violation occurs an exception is thrown. - */ - bool DelDrill( IDF_DRILL_DATA* aDrill ); - - /** - * Function GetDrills - * returns a pointer to the internal list of drills. To avoid IDF - * violations, the user should not alter these entries. - */ - const std::list< IDF_DRILL_DATA* >*const GetDrills( void ); - - /** - * Function AddOutlineData - * adds the given component outline data to this component - * - * @param aComponentOutline is a pointer to the outline data to be added - * - * @return true if the operation succeeds, otherwise false - */ - bool AddOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutline ); - - /** - * Function DeleteOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutline ) - * removes outline data based on the pointer provided. - * - * @param aComponentOutline is a pointer to be deleted from the internal list - * - * @return bool: true if the data was found and deleted, otherwise false - */ - bool DeleteOutlineData( IDF3_COMP_OUTLINE_DATA* aComponentOutline ); - - /** - * Function DeleteOutlineData( size_t aIndex ) - * removes outline data based on the provided index. - * - * @param aIndex is an index to the internal outline list - * - * @return bool: true if the data was deleted, false if the - * index was out of bounds. - */ - bool DeleteOutlineData( size_t aIndex ); - - /** - * Function GetOutlineSize - * returns the number of outlines in the internal list - */ - size_t GetOutlinesSize( void ); - - - /** - * Function GetOutlinesData - * returns a pointer to the internal list of outline data - */ - const std::list< IDF3_COMP_OUTLINE_DATA* >*const GetOutlinesData( void ); - - /** - * Function GetPosition - * retrieves the internal position parameters and returns true if the - * position was previously set, otherwise false. - */ - bool GetPosition( double& aXpos, double& aYpos, double& aAngle, IDF3::IDF_LAYER& aLayer ); - - // NOTE: it may be possible to extend this so that internal drills and outlines - // are moved when the component is moved. However there is always a danger of - // position creep due to the relative position updates. - /** - * Function SetPosition - * sets the internal position parameters and returns true if the - * position was set, false if the position was previously set. This object - * does not allow modification of the position once it is set since this may - * adversely affect the relationship with its internal objects. - * - * @param aXpos is the X position (mm) of the component - * @param aYpos is the Y position (mm) of the component - * @param aAngle is the rotation of the component (degrees) - * @param aLayer is the layer on which the component is places (TOP, BOTTOM) - * - * @return bool: true if the position was set, otherwise false - */ - bool SetPosition( double aXpos, double aYpos, double aAngle, IDF3::IDF_LAYER aLayer ); - - /** - * Function GetPlacement - * returns the IDF placement value of this component (UNPLACED, PLACED, ECAD, MCAD) - */ - IDF3::IDF_PLACEMENT GetPlacement( void ); - - /** - * Function SetPlacement - * sets the placement value of the component subject to ownership rules. - * An exception is thrown if aPlacementValue is invalid or an ownership - * violation occurs. - * - * @return bool: true if the operation succeeded, otherwise false and the - * error message is set. - */ - bool SetPlacement( IDF3::IDF_PLACEMENT aPlacementValue ); - - const std::string& GetError( void ) - { - return errormsg; - } }; + class IDF3_BOARD { -private: - std::map< std::string, std::string > uidFileList; // map of files opened and UIDs - std::list< std::string > uidLibList; // list of UIDs read from a library file - std::string errormsg; // string for passing error messages to user - std::list< IDF_NOTE* > notes; // IDF notes - std::list< std::string > noteComments; // comment list for NOTES section - std::list< std::string > drillComments; // comment list for DRILL section - std::list< std::string > placeComments; // comment list for PLACEMENT section - std::list board_drills; - std::map< std::string, IDF3_COMPONENT*> components; // drill and placement data for components - std::map< std::string, IDF3_COMP_OUTLINE*> compOutlines; // component outlines (data for library file) - std::string boardName; - IDF3::CAD_TYPE cadType; - IDF3::IDF_UNIT unit; - IDF3::IDF_VERSION idfVer; // IDF version of Board or Library - int iRefDes; // counter for automatically numbered NOREFDES items - std::string sRefDes; - - std::string idfSource; // SOURCE string to use when writing BOARD and LIBRARY headers - std::string brdSource; // SOURCE string as retrieved from a BOARD file - std::string libSource; // SOURCE string as retrieved from a LIBRARY file - std::string brdDate; // DATE string from BOARD file - std::string libDate; // DATE string from LIBRARY file - int brdFileVersion; // File Version from BOARD file - int libFileVersion; // File Version from LIBRARY file - - int userPrec; // user may store any integer here - double userScale; // user may store a scale for translating to arbitrary units - double userXoff; // user may specify an arbitrary X/Y offset - double userYoff; - - // main board outline and cutouts - BOARD_OUTLINE olnBoard; - // OTHER outlines - std::map olnOther; - // ROUTE outlines - std::list olnRoute; - // PLACEMENT outlines - std::list olnPlace; - // ROUTE KEEPOUT outlines - std::list olnRouteKeepout; - // VIA KEEPOUT outlines - std::list olnViaKeepout; - // PLACE KEEPOUT outlines - std::list olnPlaceKeepout; - // PLACEMENT GROUP outlines - std::multimap olnGroup; - - // Set the unit; this can only be done internally upon - // reading a file or saving - bool setUnit( IDF3::IDF_UNIT aUnit, bool convert = false ); - - IDF_DRILL_DATA* addCompDrill( double aDia, double aXpos, double aYpos, - IDF3::KEY_PLATING aPlating, - const std::string& aHoleType, - IDF3::KEY_OWNER aOwner, - const std::string& aRefDes ); - - IDF_DRILL_DATA* addCompDrill( IDF_DRILL_DATA* aDrilledHole ); - - bool delCompDrill( double aDia, double aXpos, double aYpos, const std::string& aRefDes ); - - // read the DRILLED HOLES section - void readBrdDrills( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ); - // read the NOTES section - void readBrdNotes( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ); - // read the component placement section - void readBrdPlacement( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState, - bool aNoSubstituteOutlines ); - // read the board HEADER - void readBrdHeader( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ); - // read individual board sections; pay attention to IDFv3 section specifications - // exception thrown on unrecoverable errors. state flag set to FILE_PLACEMENT - // upon reading the PLACEMENT file; according to IDFv3 this is the final section - void readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState, - bool aNoSubstituteOutlines ); - // read the board file data - void readBoardFile( const std::string& aFileName, bool aNoSubstituteOutlines ); - - // write the board file data - void writeBoardFile( const std::string& aFileName ); - - // read the library sections (outlines) - void readLibSection( std::istream& aLibFile, IDF3::FILE_STATE& aLibState, IDF3_BOARD* aBoard ); - // read the library HEADER - void readLibHeader( std::istream& aLibFile, IDF3::FILE_STATE& aLibState ); - // read the library file data - void readLibFile( const std::string& aFileName ); - - // write the library file data - bool writeLibFile( const std::string& aFileName ); - -#ifndef DISABLE_IDF_OWNERSHIP - bool checkComponentOwnership( int aSourceLine, const char* aSourceFunc, - IDF3_COMPONENT* aComponent ); -#endif - public: IDF3_BOARD( IDF3::CAD_TYPE aCadType ); virtual ~IDF3_BOARD(); @@ -574,14 +435,15 @@ public: const std::string& GetNewRefDes( void ); - void SetBoardName( std::string aBoardName ); + void SetBoardName( const std::string& aBoardName ); const std::string& GetBoardName( void ); bool SetBoardThickness( double aBoardThickness ); double GetBoardThickness( void ); bool ReadFile( const wxString& aFullFileName, bool aNoSubstituteOutlines = false ); - bool WriteFile( const wxString& aFullFileName, bool aUnitMM = true, bool aForceUnitFlag = false ); + bool WriteFile( const wxString& aFullFileName, bool aUnitMM = true, + bool aForceUnitFlag = false ); const std::string& GetIDFSource( void ); void SetIDFSource( const std::string& aIDFSource); @@ -695,8 +557,7 @@ public: std::map< std::string, IDF3_COMPONENT* >*const GetComponents( void ); IDF3_COMPONENT* FindComponent( const std::string& aRefDes ); - // returns a pointer to a component outline object or NULL - // if the object doesn't exist + // Return a pointer to a component outline object or NULL if the object doesn't exist. IDF3_COMP_OUTLINE* GetComponentOutline( const wxString& aFullFileName ); // returns a pointer to the component outline object with the @@ -705,7 +566,8 @@ public: // returns a pointer to the outline "NOGEOM NOPART" which is substituted // whenever a true outline cannot be found or is defective - IDF3_COMP_OUTLINE* GetInvalidOutline( const std::string& aGeomName, const std::string& aPartName ); + IDF3_COMP_OUTLINE* GetInvalidOutline( const std::string& aGeomName, + const std::string& aPartName ); // clears all data void Clear( void ); @@ -715,6 +577,121 @@ public: { return errormsg; } + +private: + // Set the unit; this can only be done internally upon reading a file or saving. + bool setUnit( IDF3::IDF_UNIT aUnit, bool convert = false ); + + IDF_DRILL_DATA* addCompDrill( double aDia, double aXpos, double aYpos, + IDF3::KEY_PLATING aPlating, + const std::string& aHoleType, + IDF3::KEY_OWNER aOwner, + const std::string& aRefDes ); + + IDF_DRILL_DATA* addCompDrill( IDF_DRILL_DATA* aDrilledHole ); + + bool delCompDrill( double aDia, double aXpos, double aYpos, const std::string& aRefDes ); + + // read the DRILLED HOLES section + void readBrdDrills( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ); + + // read the NOTES section + void readBrdNotes( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ); + + // read the component placement section + void readBrdPlacement( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState, + bool aNoSubstituteOutlines ); + + // read the board HEADER + void readBrdHeader( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState ); + + // read individual board sections; pay attention to IDFv3 section specifications + // exception thrown on unrecoverable errors. state flag set to FILE_PLACEMENT + // upon reading the PLACEMENT file; according to IDFv3 this is the final section + void readBrdSection( std::istream& aBoardFile, IDF3::FILE_STATE& aBoardState, + bool aNoSubstituteOutlines ); + // read the board file data + void readBoardFile( const std::string& aFileName, bool aNoSubstituteOutlines ); + + // write the board file data + void writeBoardFile( const std::string& aFileName ); + + // read the library sections (outlines) + void readLibSection( std::istream& aLibFile, IDF3::FILE_STATE& aLibState, IDF3_BOARD* aBoard ); + + // read the library HEADER + void readLibHeader( std::istream& aLibFile, IDF3::FILE_STATE& aLibState ); + + // read the library file data + void readLibFile( const std::string& aFileName ); + + // write the library file data + bool writeLibFile( const std::string& aFileName ); + +#ifndef DISABLE_IDF_OWNERSHIP + bool checkComponentOwnership( int aSourceLine, const char* aSourceFunc, + IDF3_COMPONENT* aComponent ); +#endif + + std::map< std::string, std::string > uidFileList; // map of files opened and UIDs + std::list< std::string > uidLibList; // list of UIDs read from a library file + + // string for passing error messages to user + std::string errormsg; + std::list< IDF_NOTE* > notes; // IDF notes + std::list< std::string > noteComments; // comment list for NOTES section + std::list< std::string > drillComments; // comment list for DRILL section + std::list< std::string > placeComments; // comment list for PLACEMENT section + std::list board_drills; + std::map< std::string, IDF3_COMPONENT*> components; // drill and placement data for components + + // component outlines (data for library file). + std::map< std::string, IDF3_COMP_OUTLINE*> compOutlines; + std::string boardName; + IDF3::CAD_TYPE cadType; + IDF3::IDF_UNIT unit; + IDF3::IDF_VERSION idfVer; // IDF version of Board or Library + + // counter for automatically numbered NOREFDES items + int iRefDes; + std::string sRefDes; + + std::string idfSource; // SOURCE string to use when writing BOARD and LIBRARY headers + std::string brdSource; // SOURCE string as retrieved from a BOARD file + std::string libSource; // SOURCE string as retrieved from a LIBRARY file + std::string brdDate; // DATE string from BOARD file + std::string libDate; // DATE string from LIBRARY file + int brdFileVersion; // File Version from BOARD file + int libFileVersion; // File Version from LIBRARY file + + int userPrec; // user may store any integer here + double userScale; // user may store a scale for translating to arbitrary units + double userXoff; // user may specify an arbitrary X/Y offset + double userYoff; + + // main board outline and cutouts + BOARD_OUTLINE olnBoard; + + // OTHER outlines + std::map olnOther; + + // ROUTE outlines + std::list olnRoute; + + // PLACEMENT outlines + std::list olnPlace; + + // ROUTE KEEPOUT outlines + std::list olnRouteKeepout; + + // VIA KEEPOUT outlines + std::list olnViaKeepout; + + // PLACE KEEPOUT outlines + std::list olnPlaceKeepout; + + // PLACEMENT GROUP outlines + std::multimap olnGroup; }; #endif // IDF_PARSER_H