Gerbview: minor code cleanup

This commit is contained in:
jean-pierre charras 2018-05-13 18:44:26 +02:00
parent 8da242c593
commit d8687e4eaf
5 changed files with 48 additions and 54 deletions

View File

@ -133,7 +133,7 @@ bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, ch
} }
// end of current line, read another one. // end of current line, read another one.
if( aBuffer ) if( aBuffer && aFile )
{ {
if( fgets( aBuffer, aBuffSize, aFile ) == NULL ) if( fgets( aBuffer, aBuffSize, aFile ) == NULL )
{ {

View File

@ -104,10 +104,10 @@ void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
wxSize aPenSize, wxSize aPenSize,
bool aLayerNegative ); bool aLayerNegative );
// Getber X2 files have a file attribute which specify the type of image // Gerber X2 files have a file attribute which specify the type of image
// (copper, solder paste ... and sides tpo, bottom or inner copper layers) // (copper, solder paste ... and sides tpo, bottom or inner copper layers)
// Excellon drill files do not have attributes, so, just to identify the image // Excellon drill files do not have attributes, so, just to identify the image
// In gerbview, we add this attribute, like a Gerber drill file // In gerbview, we add this attribute, similat to a Gerber drill file
static const char file_attribute[] = ".FileFunction,Other,Drill*"; static const char file_attribute[] = ".FileFunction,Other,Drill*";
static EXCELLON_CMD excellonHeaderCmdList[] = static EXCELLON_CMD excellonHeaderCmdList[] =
@ -314,7 +314,7 @@ bool EXCELLON_IMAGE::LoadFile( const wxString & aFullFileName )
X2_ATTRIBUTE dummy; X2_ATTRIBUTE dummy;
char* text = (char*)file_attribute; char* text = (char*)file_attribute;
int dummyline = 0; int dummyline = 0;
dummy.ParseAttribCmd( m_Current_File, NULL, 0, text, dummyline ); dummy.ParseAttribCmd( NULL, NULL, 0, text, dummyline );
delete m_FileFunction; delete m_FileFunction;
m_FileFunction = new X2_ATTRIBUTE_FILEFUNCTION( dummy ); m_FileFunction = new X2_ATTRIBUTE_FILEFUNCTION( dummy );

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2010-2016 Jean-Pierre Charras jp.charras at wanadoo.fr * Copyright (C) 2010-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -175,9 +175,8 @@ private:
// 0 = no negative items found // 0 = no negative items found
// 1 = have negative items found // 1 = have negative items found
/** /**
* Function GetNextLine
* test for an end of line * test for an end of line
* if an end of line is found: * if a end of line is found:
* read a new line * read a new line
* @param aBuff = buffer (size = GERBER_BUFZ) to fill with a new line * @param aBuff = buffer (size = GERBER_BUFZ) to fill with a new line
* @param aText = pointer to the last useful char in aBuff * @param aText = pointer to the last useful char in aBuff
@ -190,6 +189,44 @@ private:
bool GetEndOfBlock( char* aBuff, unsigned int aBuffSize, char*& aText, FILE* aGerberFile ); bool GetEndOfBlock( char* aBuff, unsigned int aBuffSize, char*& aText, FILE* aGerberFile );
/**
* reads a single RS274X command terminated with a %
*/
bool ReadRS274XCommand( char *aBuff, unsigned int aBuffSize, char*& aText );
/**
* executes a RS274X command
*/
bool ExecuteRS274XCommand( int aCommand, char* aBuff,
unsigned int aBuffSize, char*& aText );
/**
* reads two bytes of data and assembles them into an int with the first
* byte in the sequence put into the most significant part of a 16 bit value
* to build a RS274X command identifier.
* @param text A reference to a pointer to read bytes from and to advance as
* they are read.
* @return a RS274X command identifier.
*/
int ReadXCommandID( char*& text );
/**
* reads in an aperture macro and saves it in m_aperture_macros.
* @param aBuff a character buffer at least GERBER_BUFZ long that can be
* used to read successive lines from the gerber file.
* @param text A reference to a character pointer which gives the initial
* text to read from.
* @param aBuffSize is the size of aBuff
* @param gerber_file Which file to read from for continuation.
* @return bool - true if a macro was read in successfully, else false.
*/
bool ReadApertureMacro( char *aBuff, unsigned int aBuffSize,
char* & text, FILE * gerber_file );
// functions to execute G commands or D basic commands:
bool Execute_G_Command( char*& text, int G_command );
bool Execute_DCODE_Command( char*& text, int D_command );
public: public:
GERBER_FILE_IMAGE( int layer ); GERBER_FILE_IMAGE( int layer );
virtual ~GERBER_FILE_IMAGE(); virtual ~GERBER_FILE_IMAGE();
@ -275,7 +312,6 @@ public:
wxPoint ReadXYCoord( char*& Text ); wxPoint ReadXYCoord( char*& Text );
/** /**
* Function ReadIJCoord
* Returns the current coordinate type pointed to by InnJnn Text (InnnnJmmmm) * Returns the current coordinate type pointed to by InnJnn Text (InnnnJmmmm)
* These coordinates are relative, so if coordinate is absent, it's value * These coordinates are relative, so if coordinate is absent, it's value
* defaults to 0 * defaults to 0
@ -286,48 +322,6 @@ public:
int GCodeNumber( char*& Text ); int GCodeNumber( char*& Text );
int DCodeNumber( char*& Text ); int DCodeNumber( char*& Text );
// functions to execute G commands or D commands:
bool Execute_G_Command( char*& text, int G_command );
bool Execute_DCODE_Command( char*& text, int D_command );
/**
* Function ReadRS274XCommand
* reads a single RS274X command terminated with a %
*/
bool ReadRS274XCommand( char *aBuff, unsigned int aBuffSize, char*& aText );
/**
* Function ExecuteRS274XCommand
* executes a RS274X command
*/
bool ExecuteRS274XCommand( int aCommand, char* aBuff,
unsigned int aBuffSize, char*& aText );
/**
* reads two bytes of data and assembles them into an int with the first
* byte in the sequence put into the most significant part of a 16 bit value
* to build a RS274X command identifier.
* @param text A reference to a pointer to read bytes from and to advance as
* they are read.
* @return a RS274X command identifier.
*/
int ReadXCommandID( char*& text );
/**
* Function ReadApertureMacro
* reads in an aperture macro and saves it in m_aperture_macros.
* @param aBuff a character buffer at least GERBER_BUFZ long that can be
* used to read successive lines from the gerber file.
* @param text A reference to a character pointer which gives the initial
* text to read from.
* @param aBuffSize is the size of aBuff
* @param gerber_file Which file to read from for continuation.
* @return bool - true if a macro was read in successfully, else false.
*/
bool ReadApertureMacro( char *aBuff, unsigned int aBuffSize,
char* & text, FILE * gerber_file );
/** /**
* Function GetDCODEOrCreate * Function GetDCODEOrCreate
* returns a pointer to the D_CODE within this GERBER for the given * returns a pointer to the D_CODE within this GERBER for the given

View File

@ -6,7 +6,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2007-2016 Jean-Pierre Charras jp.charras at wanadoo.fr * Copyright (C) 2007-2018 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License