Pass std::string by reference instead of on the stack where applicable.

This commit is contained in:
Wayne Stambaugh 2021-07-27 13:29:35 -04:00
parent 1f2e7a94ca
commit 369d813a32
9 changed files with 1306 additions and 1325 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Mark Roszko <mark.roszko@gmail.com>
* 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;

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2016 Mark Roszko <mark.roszko@gmail.com>
* 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;
};

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Mark Roszko <mark.roszko@gmail.com>
* 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<SEXPR> Parse( const std::string& aString );
std::unique_ptr<SEXPR> 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<SEXPR> parseString(

View File

@ -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 <hillbrand@kipro-pcb.com>
*
* 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() );

View File

@ -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 <seth@kipro-pcb.com>
*
* 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

File diff suppressed because it is too large Load Diff

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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<IDF_DRILL_DATA*> 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<std::string, OTHER_OUTLINE*> olnOther;
// ROUTE outlines
std::list<ROUTE_OUTLINE*> olnRoute;
// PLACEMENT outlines
std::list<PLACE_OUTLINE*> olnPlace;
// ROUTE KEEPOUT outlines
std::list<ROUTE_KO_OUTLINE*> olnRouteKeepout;
// VIA KEEPOUT outlines
std::list<VIA_KO_OUTLINE*> olnViaKeepout;
// PLACE KEEPOUT outlines
std::list<PLACE_KO_OUTLINE*> olnPlaceKeepout;
// PLACEMENT GROUP outlines
std::multimap<std::string, GROUP_OUTLINE*> 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<IDF_DRILL_DATA*> 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<std::string, OTHER_OUTLINE*> olnOther;
// ROUTE outlines
std::list<ROUTE_OUTLINE*> olnRoute;
// PLACEMENT outlines
std::list<PLACE_OUTLINE*> olnPlace;
// ROUTE KEEPOUT outlines
std::list<ROUTE_KO_OUTLINE*> olnRouteKeepout;
// VIA KEEPOUT outlines
std::list<VIA_KO_OUTLINE*> olnViaKeepout;
// PLACE KEEPOUT outlines
std::list<PLACE_KO_OUTLINE*> olnPlaceKeepout;
// PLACEMENT GROUP outlines
std::multimap<std::string, GROUP_OUTLINE*> olnGroup;
};
#endif // IDF_PARSER_H