2014-11-22 11:52:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
|
2021-07-16 20:13:26 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-11-22 11:52:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-01-29 12:26:58 +00:00
|
|
|
* @file X2_gerber_attributes.cpp
|
2014-11-22 11:52:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manage the gerber extensions (attributes) in the new X2 version
|
|
|
|
* only few extensions are handled
|
|
|
|
* See http://www.ucamco.com/files/downloads/file/81/the_gerber_file_format_specification.pdf
|
|
|
|
*
|
|
|
|
* gerber attributes in the new X2 version look like:
|
|
|
|
* %TF.FileFunction,Copper,L1,Top*%
|
|
|
|
*
|
|
|
|
* Currently:
|
2016-05-25 09:45:55 +00:00
|
|
|
* .FileFunction .FileFunction Identifies the file's function in the PCB.
|
|
|
|
* Other Standard Attributes, not yet used in Gerbview:
|
|
|
|
* .Part Identifies the part the file represents, e.g. a single PCB
|
|
|
|
* .MD5 Sets the MD5 file signature or checksum.
|
2014-11-22 11:52:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/log.h>
|
2018-01-29 12:26:58 +00:00
|
|
|
#include <X2_gerber_attributes.h>
|
2023-09-09 04:10:57 +00:00
|
|
|
#include <string_utils.h>
|
2014-11-22 11:52:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
X2_ATTRIBUTE::X2_ATTRIBUTE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
X2_ATTRIBUTE::~X2_ATTRIBUTE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
const wxString& X2_ATTRIBUTE::GetAttribute()
|
|
|
|
{
|
|
|
|
return m_Prms.Item( 0 );
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
|
|
|
const wxString& X2_ATTRIBUTE::GetPrm( int aIdx )
|
2014-11-22 11:52:57 +00:00
|
|
|
{
|
|
|
|
static const wxString dummy;
|
|
|
|
|
2016-07-27 13:27:19 +00:00
|
|
|
if( GetPrmCount() > aIdx && aIdx >= 0 )
|
2014-11-22 11:52:57 +00:00
|
|
|
return m_Prms.Item( aIdx );
|
|
|
|
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
void X2_ATTRIBUTE::DbgListPrms()
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxLogMessage( wxT( "prms count %d" ), GetPrmCount() );
|
2014-11-22 11:52:57 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < GetPrmCount(); ii++ )
|
|
|
|
wxLogMessage( m_Prms.Item( ii ) );
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2017-09-28 22:38:36 +00:00
|
|
|
bool X2_ATTRIBUTE::ParseAttribCmd( FILE* aFile, char *aBuffer, int aBuffSize, char* &aText,
|
2017-09-29 05:58:15 +00:00
|
|
|
int& aLineNum )
|
2014-11-22 11:52:57 +00:00
|
|
|
{
|
2019-10-24 16:50:51 +00:00
|
|
|
// parse a TF, TA, TO ... command and fill m_Prms by the parameters found.
|
2017-09-29 05:58:15 +00:00
|
|
|
// the "%TF" (start of command) is already read by the caller
|
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
bool ok = true;
|
2019-10-24 16:50:51 +00:00
|
|
|
std::string data;
|
2014-11-22 11:52:57 +00:00
|
|
|
|
|
|
|
for( ; ; )
|
|
|
|
{
|
|
|
|
while( *aText )
|
|
|
|
{
|
|
|
|
switch( *aText )
|
|
|
|
{
|
|
|
|
case '%': // end of command
|
|
|
|
return ok; // success completion
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
aText++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '*': // End of block
|
2023-09-09 04:10:57 +00:00
|
|
|
m_Prms.Add( From_UTF8( data.c_str() ) );
|
2019-10-24 16:50:51 +00:00
|
|
|
data.clear();
|
2014-11-22 11:52:57 +00:00
|
|
|
aText++;
|
|
|
|
break;
|
|
|
|
|
2017-09-29 05:58:15 +00:00
|
|
|
case ',': // End of parameter (separator)
|
2014-11-22 11:52:57 +00:00
|
|
|
aText++;
|
2023-09-09 04:10:57 +00:00
|
|
|
m_Prms.Add( From_UTF8( data.c_str() ) );
|
2019-10-24 16:50:51 +00:00
|
|
|
data.clear();
|
2014-11-22 11:52:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-10-24 16:50:51 +00:00
|
|
|
data += *aText;
|
2014-11-22 11:52:57 +00:00
|
|
|
aText++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// end of current line, read another one.
|
2018-05-13 16:44:26 +00:00
|
|
|
if( aBuffer && aFile )
|
2014-11-22 11:52:57 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
if( fgets( aBuffer, aBuffSize, aFile ) == nullptr )
|
2014-11-22 11:52:57 +00:00
|
|
|
{
|
|
|
|
// end of file
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-28 22:38:36 +00:00
|
|
|
aLineNum++;
|
2014-11-22 11:52:57 +00:00
|
|
|
aText = aBuffer;
|
|
|
|
}
|
|
|
|
else
|
2021-07-16 20:13:26 +00:00
|
|
|
{
|
2014-11-22 11:52:57 +00:00
|
|
|
return ok;
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
2014-11-22 11:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
X2_ATTRIBUTE_FILEFUNCTION::X2_ATTRIBUTE_FILEFUNCTION( X2_ATTRIBUTE& aAttributeBase )
|
|
|
|
: X2_ATTRIBUTE()
|
|
|
|
{
|
|
|
|
m_Prms = aAttributeBase.GetPrms();
|
|
|
|
m_z_order = 0;
|
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
// ensure at least 7 parameters exist.
|
|
|
|
while( GetPrmCount() < 7 )
|
2014-11-22 11:52:57 +00:00
|
|
|
m_Prms.Add( wxEmptyString );
|
|
|
|
|
|
|
|
set_Z_Order();
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetFileType()
|
|
|
|
{
|
2017-04-28 10:53:30 +00:00
|
|
|
// the type of layer (Copper, Soldermask ... )
|
2014-11-22 11:52:57 +00:00
|
|
|
return m_Prms.Item( 1 );
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetBrdLayerId()
|
|
|
|
{
|
2015-04-09 18:53:36 +00:00
|
|
|
// the brd layer identifier: Ln (for Copper type) or Top, Bot
|
2014-11-22 11:52:57 +00:00
|
|
|
return m_Prms.Item( 2 );
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
const wxString X2_ATTRIBUTE_FILEFUNCTION::GetDrillLayerPair()
|
|
|
|
{
|
|
|
|
// the layer pair identifiers, for drill files, i.e.
|
|
|
|
// with m_Prms.Item( 1 ) = "Plated" or "NonPlated"
|
|
|
|
wxString lpair = m_Prms.Item( 2 ) + ',' + m_Prms.Item( 3 );
|
|
|
|
return lpair;
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2015-04-09 18:53:36 +00:00
|
|
|
const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetBrdLayerSide()
|
|
|
|
{
|
|
|
|
if( IsCopper() )
|
|
|
|
// the brd layer identifier: Top, Bot, Inr
|
|
|
|
return m_Prms.Item( 3 );
|
|
|
|
else
|
|
|
|
// the brd layer identifier: Top, Bot ( same as GetBrdLayerId() )
|
|
|
|
return m_Prms.Item( 2 );
|
|
|
|
}
|
2014-11-22 11:52:57 +00:00
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetLabel()
|
|
|
|
{
|
2015-04-09 18:53:36 +00:00
|
|
|
if( IsCopper() )
|
|
|
|
return m_Prms.Item( 4 );
|
|
|
|
else
|
|
|
|
return m_Prms.Item( 3 );
|
2014-11-22 11:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetLPType()
|
|
|
|
{
|
|
|
|
// Only for drill files: the Layer Pair type (PTH, NPTH, Blind or Buried)
|
|
|
|
return m_Prms.Item( 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString& X2_ATTRIBUTE_FILEFUNCTION::GetRouteType()
|
|
|
|
{
|
|
|
|
// Only for drill files: the drill/routing type(Drill, Route, Mixed)
|
|
|
|
return m_Prms.Item( 5 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 18:53:36 +00:00
|
|
|
bool X2_ATTRIBUTE_FILEFUNCTION::IsCopper()
|
|
|
|
{
|
|
|
|
// the filefunction label, if any
|
|
|
|
return GetFileType().IsSameAs( wxT( "Copper" ), false );
|
|
|
|
}
|
|
|
|
|
2017-04-28 10:53:30 +00:00
|
|
|
|
|
|
|
bool X2_ATTRIBUTE_FILEFUNCTION::IsDrillFile()
|
|
|
|
{
|
|
|
|
// the filefunction label, if any
|
|
|
|
return GetFileType().IsSameAs( wxT( "Plated" ), false )
|
|
|
|
|| GetFileType().IsSameAs( wxT( "NonPlated" ), false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
void X2_ATTRIBUTE_FILEFUNCTION::set_Z_Order()
|
|
|
|
{
|
2022-07-25 19:23:23 +00:00
|
|
|
m_z_order = 100; // high level
|
2014-11-22 11:52:57 +00:00
|
|
|
m_z_sub_order = 0;
|
|
|
|
|
2015-04-09 18:53:36 +00:00
|
|
|
if( IsCopper() )
|
2014-11-22 11:52:57 +00:00
|
|
|
{
|
|
|
|
// Copper layer: the priority is the layer Id
|
|
|
|
m_z_order = 0;
|
|
|
|
wxString num = GetBrdLayerId().Mid( 1 );
|
|
|
|
long lnum;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2014-11-22 11:52:57 +00:00
|
|
|
if( num.ToLong( &lnum ) )
|
|
|
|
m_z_sub_order = -lnum;
|
|
|
|
}
|
|
|
|
|
2022-07-25 19:35:01 +00:00
|
|
|
if( GetFileType().IsSameAs( wxT( "Soldermask" ), false ) )
|
2014-11-22 11:52:57 +00:00
|
|
|
{
|
2022-07-25 19:35:01 +00:00
|
|
|
// solder mask layer: the priority is top then bottom
|
2014-11-22 11:52:57 +00:00
|
|
|
m_z_order = 1; // for top
|
|
|
|
|
|
|
|
if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
|
|
|
|
m_z_order = -m_z_order;
|
|
|
|
}
|
|
|
|
|
2022-07-25 19:35:01 +00:00
|
|
|
if( GetFileType().IsSameAs( wxT( "Legend" ), false ) )
|
2014-11-22 11:52:57 +00:00
|
|
|
{
|
2022-07-25 19:35:01 +00:00
|
|
|
// Silk screen layer: the priority is top then bottom
|
2014-11-22 11:52:57 +00:00
|
|
|
m_z_order = 2; // for top
|
|
|
|
|
|
|
|
if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
|
|
|
|
m_z_order = -m_z_order;
|
|
|
|
}
|
|
|
|
|
2022-07-25 19:35:01 +00:00
|
|
|
if( GetFileType().IsSameAs( wxT( "Paste" ), false ) )
|
2014-11-22 11:52:57 +00:00
|
|
|
{
|
2022-07-25 19:35:01 +00:00
|
|
|
// solder paste layer: the priority is top then bottom
|
2014-11-22 11:52:57 +00:00
|
|
|
m_z_order = 3; // for top
|
|
|
|
|
2018-03-18 15:04:01 +00:00
|
|
|
if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
|
|
|
|
m_z_order = -m_z_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( GetFileType().IsSameAs( wxT( "Glue" ), false ) )
|
|
|
|
{
|
|
|
|
// Glue spots used to fix components to the board prior to soldering:
|
|
|
|
// the priority is top then bottom
|
|
|
|
m_z_order = 4; // for top
|
2014-11-22 11:52:57 +00:00
|
|
|
|
|
|
|
if( GetBrdLayerId().IsSameAs( wxT( "Bot" ), false ) )
|
|
|
|
m_z_order = -m_z_order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|