Gerbview, Aperture macros handling: use accessors for some internal data

and add comments. No actual code change.
This commit is contained in:
jean-pierre charras 2023-01-28 16:39:48 +01:00
parent d4a5e2caad
commit be420a0cf5
6 changed files with 70 additions and 26 deletions

View File

@ -172,7 +172,7 @@ void AM_PARAM::PushOperator( parm_item_type aType, int aValue )
* @param aText = pointer to the parameter to read. Will be modified to point to the next field
* @return true if a param is read, or false
*/
bool AM_PARAM::ReadParam( char*& aText )
bool AM_PARAM::ReadParamFromAmDef( char*& aText )
{
bool found = false;
int ivalue;

View File

@ -329,14 +329,22 @@ public:
* @param aText = pointer to the parameter to read. Will be modified to point to the next field
* @return true if a param is read, or false
*/
bool ReadParam( char*& aText );
bool ReadParamFromAmDef( char*& aText );
private:
int m_index; ///< has meaning to define parameter local to an aperture macro
std::vector<AM_PARAM_ITEM> m_paramStack; ///< List of operands/operators to evaluate the
///< actual value if a par def is $3/2, there are
///< 3 items in stack: 3 (type PUSHPARM) , / (type
///< DIV), 2 (type PUSHVALUE).
/**
* has meaning to define parameter local to an aperture macro
* this is the id of a parameter defined like
* $n = ....
* n is the index
*/
int m_index;
/**
* List of operands/operators to evaluate the actual value if a par def is $3/2,
* there are 3 items in stack: 3 (type PUSHPARM) , / (type DIV), 2 (type PUSHVALUE).
*/
std::vector<AM_PARAM_ITEM> m_paramStack;
};

View File

@ -86,8 +86,8 @@ enum AM_PRIMITIVE_ID {
/**
* An aperture macro primitive as given in Table 3 of
* http://gerbv.sourceforge.net/docs/rs274xrevd_e.pdf
* An aperture macro primitive as given in gerber layer format doc. See
* https://www.ucamco.com/en/news/gerber-layer-format-specification-revision-????
*/
class AM_PRIMITIVE
{
@ -96,11 +96,16 @@ public:
AM_PARAMS m_Params; ///< A sequence of parameters used by the primitive
bool m_GerbMetric; // units for this primitive:
// false = Inches, true = metric
int m_LocalParamLevel; // count of local param defined inside a aperture macro
// local param stack when this primitive is put in
// aperture macro primitive stack list
// not used outside a aperture macro
AM_PRIMITIVE( bool aGerbMetric, AM_PRIMITIVE_ID aId = AMP_UNKNOWN )
{
m_Primitive_id = aId;
m_GerbMetric = aGerbMetric;
m_LocalParamLevel = 0;
}

View File

@ -32,6 +32,24 @@
#include <aperture_macro.h>
void APERTURE_MACRO::AddPrimitiveToList( AM_PRIMITIVE& aPrimitive )
{
m_primitivesList.push_back( aPrimitive );
m_primitivesList.back().m_LocalParamLevel = m_localParamStack.size();
}
void APERTURE_MACRO::AddLocalParamDefToStack()
{
m_localParamStack.push_back( AM_PARAM() );
}
AM_PARAM& APERTURE_MACRO::GetLastLocalParamDefFromStack()
{
return m_localParamStack.back();
}
SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* aParent,
const VECTOR2I& aShapePos )
{
@ -39,7 +57,7 @@ SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* a
m_shape.RemoveAllContours();
for( AM_PRIMITIVE& prim_macro : m_PrimitivesList )
for( AM_PRIMITIVE& prim_macro : m_primitivesList )
{
if( prim_macro.m_Primitive_id == AMP_COMMENT )
continue;
@ -77,11 +95,11 @@ double APERTURE_MACRO::GetLocalParam( const D_CODE* aDcode, unsigned aParamId )
// find parameter descr.
const AM_PARAM * param = nullptr;
for( unsigned ii = 0; ii < m_LocalParamStack.size(); ii ++ )
for( unsigned ii = 0; ii < m_localParamStack.size(); ii ++ )
{
if( m_LocalParamStack[ii].GetIndex() == aParamId )
if( m_localParamStack[ii].GetIndex() == aParamId )
{
param = &m_LocalParamStack[ii];
param = &m_localParamStack[ii];
break;
}
}

View File

@ -100,19 +100,31 @@ public:
wxString m_AmName;
/**
* A sequence of AM_PRIMITIVEs
* Add a new ptimitive ( AMP_CIRCLE, AMP_LINE2 ...) to the list of primitives
* to define the full shape of the aperture macro
*/
std::vector<AM_PRIMITIVE> m_PrimitivesList;
void AddPrimitiveToList( AM_PRIMITIVE& aPrimitive );
/* A deferred parameter can be defined in aperture macro,
* but outside aperture primitives. Example
/**
* A deferred parameter can be defined in aperture macro,
* but outside aperture primitives. Example
* %AMRECTHERM*
* $4=$3/2* parameter $4 is half value of parameter $3
* m_localparamStack handle a list of local deferred parameters
*/
AM_PARAMS m_LocalParamStack;
void AddLocalParamDefToStack();
AM_PARAM& GetLastLocalParamDefFromStack();
private:
/**
* A list of AM_PRIMITIVEs to define the shape of the aperture macro
*/
std::vector<AM_PRIMITIVE> m_primitivesList;
/**
* m_localparamStack handle a list of local deferred parameters
*/
AM_PARAMS m_localParamStack;
SHAPE_POLY_SET m_shape; ///< The shape of the item, calculated by GetApertureMacroShape
};

View File

@ -1020,14 +1020,14 @@ bool GERBER_FILE_IMAGE::ReadApertureMacro( char *aBuff, unsigned int aBuffSize,
// all other symbols are illegal.
if( *aText == '$' ) // local parameter declaration, inside the aperture macro
{
am.m_LocalParamStack.push_back( AM_PARAM() );
AM_PARAM& param = am.m_LocalParamStack.back();
am.AddLocalParamDefToStack();
AM_PARAM& param = am.GetLastLocalParamDefFromStack();
aText = GetNextLine( aBuff, aBuffSize, aText, gerber_file );
if( aText == nullptr) // End of File
return false;
param.ReadParam( aText );
param.ReadParamFromAmDef( aText );
continue;
}
else if( !isdigit(*aText) ) // Ill. symbol
@ -1114,7 +1114,7 @@ bool GERBER_FILE_IMAGE::ReadApertureMacro( char *aBuff, unsigned int aBuffSize,
if( aText == nullptr) // End of File
return false;
param.ReadParam( aText );
param.ReadParamFromAmDef( aText );
}
if( ii < paramCount )
@ -1149,7 +1149,7 @@ bool GERBER_FILE_IMAGE::ReadApertureMacro( char *aBuff, unsigned int aBuffSize,
if( aText == nullptr ) // End of File
return false;
param.ReadParam( aText );
param.ReadParamFromAmDef( aText );
}
}
@ -1158,10 +1158,11 @@ bool GERBER_FILE_IMAGE::ReadApertureMacro( char *aBuff, unsigned int aBuffSize,
{
prim.m_Params.push_back( AM_PARAM() );
AM_PARAM& param = prim.m_Params.back();
param.ReadParam( aText );
param.ReadParamFromAmDef( aText );
}
am.m_PrimitivesList.push_back( prim );
// The primitive description is now parsed: push it to the current aperture macro
am.AddPrimitiveToList( prim );
}
m_aperture_macros.insert( am );