2012-12-29 09:54:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
|
2013-03-09 19:36:31 +00:00
|
|
|
* Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
|
2023-03-02 14:04:37 +00:00
|
|
|
* Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-12-29 09:54:25 +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
|
|
|
|
*/
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcad/pcad_arc.h>
|
2023-04-01 20:05:58 +00:00
|
|
|
#include <pcad/pcad_copper_pour.h>
|
|
|
|
#include <pcad/pcad_cutout.h>
|
|
|
|
#include <pcad/pcad_plane.h>
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcad/pcad_line.h>
|
|
|
|
#include <pcad/pcad_footprint.h>
|
|
|
|
#include <pcad/pcad_pad.h>
|
|
|
|
#include <pcad/pcad_polygon.h>
|
|
|
|
#include <pcad/pcad_text.h>
|
|
|
|
#include <pcad/pcad_via.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcb_text.h>
|
2016-02-24 11:56:40 +00:00
|
|
|
#include <trigo.h>
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <xnode.h>
|
|
|
|
|
|
|
|
#include <wx/string.h>
|
2016-02-24 11:56:40 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
namespace PCAD2KICAD {
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
PCAD_FOOTPRINT::PCAD_FOOTPRINT( PCAD_CALLBACKS* aCallbacks, BOARD* aBoard ) :
|
2023-03-30 11:49:23 +00:00
|
|
|
PCAD_PCB_COMPONENT( aCallbacks, aBoard )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
InitTTextValue( &m_Value );
|
|
|
|
m_Mirror = 0;
|
2023-04-01 20:05:58 +00:00
|
|
|
m_ObjType = wxT( 'M' ); // FOOTPRINT
|
2014-06-24 16:17:18 +00:00
|
|
|
m_KiCadLayer = F_SilkS; // default
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
PCAD_FOOTPRINT::~PCAD_FOOTPRINT()
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
delete m_FootprintItems[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
XNODE* PCAD_FOOTPRINT::FindModulePatternDefName( XNODE* aNode, const wxString& aName )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
XNODE* result, * lNode;
|
|
|
|
wxString propValue1, propValue2;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
result = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
lNode = FindNode( aNode, wxT( "patternDef" ) );
|
|
|
|
|
|
|
|
while( lNode )
|
|
|
|
{
|
|
|
|
if( lNode->GetName() == wxT( "patternDef" ) )
|
|
|
|
{
|
|
|
|
lNode->GetAttribute( wxT( "Name" ), &propValue1 );
|
|
|
|
FindNode( lNode,
|
|
|
|
wxT( "originalName" ) )->GetAttribute( wxT( "Name" ), &propValue2 );
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( ValidateName( propValue1 ) == aName || ValidateName( propValue2 ) == aName )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
result = lNode;
|
2021-07-19 23:56:05 +00:00
|
|
|
lNode = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lNode )
|
|
|
|
lNode = lNode->GetNext();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( result == nullptr )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
lNode = FindNode( aNode, wxT( "patternDefExtended" ) ); // New file format
|
|
|
|
|
|
|
|
while( lNode )
|
|
|
|
{
|
|
|
|
if( lNode->GetName() == wxT( "patternDefExtended" ) )
|
|
|
|
{
|
|
|
|
lNode->GetAttribute( wxT( "Name" ), &propValue1 );
|
|
|
|
|
|
|
|
if( ValidateName( propValue1 ) == aName )
|
|
|
|
{
|
|
|
|
result = lNode;
|
2021-07-19 23:56:05 +00:00
|
|
|
lNode = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lNode )
|
|
|
|
lNode = lNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
XNODE* PCAD_FOOTPRINT::FindPatternMultilayerSection( XNODE* aNode, wxString* aPatGraphRefName )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
XNODE* result, * pNode, * lNode;
|
|
|
|
wxString propValue, patName;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
result = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
pNode = aNode; // pattern;
|
|
|
|
lNode = aNode;
|
|
|
|
|
|
|
|
// calling from library conversion we need to find pattern
|
|
|
|
if( lNode->GetName() == wxT( "compDef" ) )
|
|
|
|
{
|
|
|
|
lNode->GetAttribute( wxT( "Name" ), &propValue );
|
|
|
|
propValue.Trim( false );
|
|
|
|
patName = ValidateName( propValue );
|
|
|
|
|
|
|
|
if( FindNode( lNode, wxT( "attachedPattern" ) ) )
|
|
|
|
{
|
|
|
|
FindNode( FindNode( lNode, wxT( "attachedPattern" ) ),
|
|
|
|
wxT( "patternName" ) )->GetAttribute( wxT( "Name" ), &propValue );
|
|
|
|
propValue.Trim( false );
|
|
|
|
propValue.Trim( true );
|
|
|
|
patName = ValidateName( propValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
lNode = FindModulePatternDefName( lNode->GetParent(), patName );
|
|
|
|
pNode = lNode; // pattern;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
lNode = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( pNode )
|
|
|
|
lNode = FindNode( pNode, wxT( "multiLayer" ) ); // Old file format
|
|
|
|
|
|
|
|
if( lNode )
|
2013-03-09 19:36:31 +00:00
|
|
|
{
|
|
|
|
*aPatGraphRefName = wxEmptyString; // default
|
2012-12-29 09:54:25 +00:00
|
|
|
result = lNode;
|
2013-03-09 19:36:31 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// New file format
|
2013-03-09 19:36:31 +00:00
|
|
|
|
|
|
|
if( *aPatGraphRefName == wxEmptyString ) // default
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2013-03-09 19:36:31 +00:00
|
|
|
if( FindNode( aNode, wxT( "patternGraphicsNameRef" ) ) )
|
|
|
|
{
|
|
|
|
FindNode( aNode,
|
|
|
|
wxT( "patternGraphicsNameRef" ) )->GetAttribute( wxT( "Name" ),
|
|
|
|
aPatGraphRefName );
|
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( FindNode( aNode, wxT( "patternGraphicsDef" ) ) )
|
|
|
|
lNode = FindNode( aNode, wxT( "patternGraphicsDef" ) );
|
2017-03-11 21:18:45 +00:00
|
|
|
else if( pNode )
|
2012-12-29 09:54:25 +00:00
|
|
|
lNode = FindNode( pNode, wxT( "patternGraphicsDef" ) );
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
if( *aPatGraphRefName == wxEmptyString ) // no pattern detection, the first is actual...
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
if( lNode )
|
|
|
|
{
|
|
|
|
result = FindNode( lNode, wxT( "multiLayer" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
lNode = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while( lNode ) // selected by name
|
|
|
|
{
|
|
|
|
if( lNode->GetName() == wxT( "patternGraphicsDef" ) )
|
|
|
|
{
|
|
|
|
FindNode( lNode,
|
|
|
|
wxT( "patternGraphicsNameDef" ) )->GetAttribute( wxT( "Name" ),
|
|
|
|
&propValue );
|
|
|
|
|
|
|
|
if( propValue == *aPatGraphRefName )
|
|
|
|
{
|
|
|
|
result = FindNode( lNode, wxT( "multiLayer" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
lNode = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-12-29 09:54:25 +00:00
|
|
|
lNode = lNode->GetNext();
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-12-29 09:54:25 +00:00
|
|
|
lNode = lNode->GetNext();
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void PCAD_FOOTPRINT::DoLayerContentsObjects( XNODE* aNode, PCAD_FOOTPRINT* aFootprint,
|
2023-04-01 20:05:58 +00:00
|
|
|
PCAD_COMPONENTS_ARRAY* aList, wxStatusBar* aStatusBar,
|
|
|
|
const wxString& aDefaultMeasurementUnit,
|
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
PCAD_ARC* arc;
|
|
|
|
PCAD_POLYGON* polygon;
|
|
|
|
PCAD_POLYGON* plane_layer = nullptr;
|
|
|
|
PCAD_COPPER_POUR* copperPour;
|
|
|
|
PCAD_CUTOUT* cutout;
|
|
|
|
PCAD_PLANE* plane;
|
|
|
|
VERTICES_ARRAY* plane_layer_polygon;
|
|
|
|
PCAD_LINE* line;
|
|
|
|
PCAD_TEXT* text;
|
|
|
|
XNODE* lNode;
|
|
|
|
XNODE* tNode;
|
|
|
|
wxString propValue;
|
|
|
|
long long i;
|
|
|
|
int PCadLayer;
|
|
|
|
long num = 0;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
i = 0;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
// aStatusBar->SetStatusText( wxT( "Processing LAYER CONTENT OBJECTS " ) );
|
|
|
|
if( FindNode( aNode, wxT( "layerNumRef" ) ) )
|
|
|
|
FindNode( aNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &num );
|
|
|
|
|
|
|
|
PCadLayer = (int) num;
|
|
|
|
|
|
|
|
if( m_callbacks->GetLayerType( PCadLayer ) == LAYER_TYPE_PLANE )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
plane_layer = new PCAD_POLYGON( m_callbacks, m_board, PCadLayer );
|
2012-12-29 09:54:25 +00:00
|
|
|
plane_layer->AssignNet( m_callbacks->GetLayerNetNameRef( PCadLayer ) );
|
2020-11-14 21:21:54 +00:00
|
|
|
plane_layer->SetOutline( &m_BoardOutline );
|
2012-12-29 09:54:25 +00:00
|
|
|
aList->Add( plane_layer );
|
|
|
|
|
|
|
|
// fill the polygon with the same contour as its outline is
|
|
|
|
//plane_layer->AddIsland( &m_boardOutline );
|
|
|
|
}
|
|
|
|
|
|
|
|
lNode = aNode->GetChildren();
|
|
|
|
|
|
|
|
while( lNode )
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
// aStatusBar->SetStatusText( wxString::Format( "Processing LAYER CONTENT OBJECTS :%lld",
|
|
|
|
// i ) );
|
|
|
|
|
|
|
|
if( lNode->GetName() == wxT( "line" ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
line = new PCAD_LINE( m_callbacks, m_board );
|
2012-12-29 09:54:25 +00:00
|
|
|
line->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
|
|
|
|
aList->Add( line );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lNode->GetName() == wxT( "text" ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
text = new PCAD_TEXT( m_callbacks, m_board );
|
2012-12-29 09:54:25 +00:00
|
|
|
text->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
|
|
|
|
aList->Add( text );
|
|
|
|
}
|
|
|
|
|
|
|
|
// added as Sergeys request 02/2008
|
|
|
|
if( lNode->GetName() == wxT( "attr" ) )
|
|
|
|
{
|
|
|
|
// assign fonts to Module Name,Value,Type,....s
|
|
|
|
lNode->GetAttribute( wxT( "Name" ), &propValue );
|
|
|
|
propValue.Trim( false );
|
|
|
|
propValue.Trim( true );
|
|
|
|
|
2016-02-24 11:56:40 +00:00
|
|
|
if( propValue == wxT( "RefDes" ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
tNode = FindNode( lNode, wxT( "textStyleRef" ) );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( tNode && aFootprint )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
// TODO: to understand and may be repair
|
|
|
|
// Alexander Lunev: originally in Delphi version of the project there was
|
2023-04-01 20:05:58 +00:00
|
|
|
// a strange access to pcbModule->m_Name (it was global variable). This access
|
2012-12-29 09:54:25 +00:00
|
|
|
// is necessary when the function DoLayerContentsObjects() is called from
|
|
|
|
// function CreatePCBModule(). However it is not clear whether the access is
|
|
|
|
// required when the function DoLayerContentsObjects() is called from
|
|
|
|
// function ProcessXMLtoPCBLib().
|
2023-04-01 20:05:58 +00:00
|
|
|
SetFontProperty( tNode, &aFootprint->m_Name, aDefaultMeasurementUnit,
|
2012-12-29 09:54:25 +00:00
|
|
|
aActualConversion );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// added as Sergeys request 02/2008
|
|
|
|
if( lNode->GetName() == wxT( "arc" ) || lNode->GetName() == wxT( "triplePointArc" ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
arc = new PCAD_ARC( m_callbacks, m_board );
|
2012-12-29 09:54:25 +00:00
|
|
|
arc->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
|
|
|
|
aList->Add( arc );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lNode->GetName() == wxT( "pcbPoly" ) )
|
|
|
|
{
|
|
|
|
if( m_callbacks->GetLayerType( PCadLayer ) == LAYER_TYPE_PLANE )
|
|
|
|
{
|
|
|
|
plane_layer_polygon = new VERTICES_ARRAY;
|
2021-07-19 23:56:05 +00:00
|
|
|
plane_layer->FormPolygon( lNode, plane_layer_polygon, aDefaultMeasurementUnit,
|
|
|
|
aActualConversion );
|
2023-04-01 20:05:58 +00:00
|
|
|
plane_layer->m_Cutouts.Add( plane_layer_polygon );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
polygon = new PCAD_POLYGON( m_callbacks, m_board, PCadLayer );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
if( polygon->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
aList->Add( polygon );
|
|
|
|
else
|
|
|
|
delete polygon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lNode->GetName() == wxT( "copperPour95" ) )
|
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
copperPour = new PCAD_COPPER_POUR( m_callbacks, m_board, PCadLayer );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2017-12-14 15:09:04 +00:00
|
|
|
if( copperPour->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
aList->Add( copperPour );
|
|
|
|
else
|
|
|
|
delete copperPour;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lNode->GetName() == wxT( "polyCutOut" ) )
|
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
cutout = new PCAD_CUTOUT( m_callbacks, m_board, PCadLayer );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( cutout->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
|
|
|
|
aList->Add( cutout );
|
|
|
|
else
|
|
|
|
delete cutout;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( lNode->GetName() == wxT( "planeObj" ) )
|
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
plane = new PCAD_PLANE( m_callbacks, m_board, PCadLayer );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2017-12-14 15:09:04 +00:00
|
|
|
if( plane->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
aList->Add( plane );
|
|
|
|
else
|
|
|
|
delete plane;
|
|
|
|
}
|
|
|
|
|
|
|
|
lNode = lNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void PCAD_FOOTPRINT::SetName( const wxString& aPin, const wxString& aName )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
long num;
|
|
|
|
|
|
|
|
aPin.ToLong( &num );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_FootprintItems[i]->m_ObjType == wxT( 'P' ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
if( ( (PCAD_PAD*) m_FootprintItems[i] )->m_Number == num )
|
2023-04-01 20:05:58 +00:00
|
|
|
( (PCAD_PAD*) m_FootprintItems[i] )->m_Name.text = aName;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void PCAD_FOOTPRINT::Parse( XNODE* aNode, wxStatusBar* aStatusBar,
|
2020-11-14 21:21:54 +00:00
|
|
|
const wxString& aDefaultMeasurementUnit,
|
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
XNODE* lNode, * tNode, * mNode;
|
2023-03-30 11:49:23 +00:00
|
|
|
PCAD_PAD* pad;
|
|
|
|
PCAD_VIA* via;
|
2012-12-29 09:54:25 +00:00
|
|
|
wxString propValue, str;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
FindNode( aNode, wxT( "originalName" ) )->GetAttribute( wxT( "Name" ), &propValue );
|
2012-12-29 09:54:25 +00:00
|
|
|
propValue.Trim( false );
|
2023-04-01 20:05:58 +00:00
|
|
|
m_Name.text = propValue;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
// aStatusBar->SetStatusText( wxT( "Creating Component : " ) + m_Name.text );
|
2012-12-29 09:54:25 +00:00
|
|
|
lNode = aNode;
|
2023-04-01 20:05:58 +00:00
|
|
|
lNode = FindPatternMultilayerSection( lNode, &m_PatGraphRefName );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( lNode )
|
|
|
|
{
|
|
|
|
tNode = lNode;
|
|
|
|
tNode = tNode->GetChildren();
|
|
|
|
|
|
|
|
while( tNode )
|
|
|
|
{
|
|
|
|
if( tNode->GetName() == wxT( "pad" ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
pad = new PCAD_PAD( m_callbacks, m_board );
|
2012-12-29 09:54:25 +00:00
|
|
|
pad->Parse( tNode, aDefaultMeasurementUnit, aActualConversion );
|
2020-11-14 21:21:54 +00:00
|
|
|
m_FootprintItems.Add( pad );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( tNode->GetName() == wxT( "via" ) )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
via = new PCAD_VIA( m_callbacks, m_board );
|
2012-12-29 09:54:25 +00:00
|
|
|
via->Parse( tNode, aDefaultMeasurementUnit, aActualConversion );
|
2020-11-14 21:21:54 +00:00
|
|
|
m_FootprintItems.Add( via );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tNode = tNode->GetNext();
|
|
|
|
}
|
|
|
|
|
2020-10-30 19:31:23 +00:00
|
|
|
lNode = lNode->GetParent();
|
|
|
|
}
|
2015-03-28 16:16:40 +00:00
|
|
|
|
|
|
|
if( lNode )
|
|
|
|
lNode = FindNode( lNode, wxT( "layerContents" ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
while( lNode )
|
|
|
|
{
|
|
|
|
if( lNode->GetName() == wxT( "layerContents" ) )
|
2020-11-14 21:21:54 +00:00
|
|
|
DoLayerContentsObjects( lNode, this, &m_FootprintItems, aStatusBar,
|
2012-12-29 09:54:25 +00:00
|
|
|
aDefaultMeasurementUnit, aActualConversion );
|
|
|
|
|
|
|
|
lNode = lNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// map pins
|
|
|
|
lNode = FindPinMap( aNode );
|
|
|
|
|
|
|
|
if( lNode )
|
|
|
|
{
|
|
|
|
mNode = lNode->GetChildren();
|
|
|
|
|
|
|
|
while( mNode )
|
|
|
|
{
|
|
|
|
if( mNode->GetName() == wxT( "padNum" ) )
|
|
|
|
{
|
|
|
|
str = mNode->GetNodeContent();
|
|
|
|
mNode = mNode->GetNext();
|
|
|
|
|
|
|
|
if( !mNode )
|
|
|
|
break;
|
|
|
|
|
|
|
|
mNode->GetAttribute( wxT( "Name" ), &propValue );
|
2017-08-11 09:22:13 +00:00
|
|
|
SetName( str, propValue );
|
2012-12-29 09:54:25 +00:00
|
|
|
mNode = mNode->GetNext();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mNode = mNode->GetNext();
|
|
|
|
|
|
|
|
if( !mNode )
|
|
|
|
break;
|
|
|
|
|
|
|
|
mNode = mNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void PCAD_FOOTPRINT::AddToBoard( FOOTPRINT* aFootprint )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
// No nested footprints....
|
|
|
|
wxCHECK( aFootprint == nullptr, /* void */ );
|
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
int i;
|
2022-01-18 02:05:59 +00:00
|
|
|
EDA_ANGLE r;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
// transform text positions
|
2023-04-01 20:05:58 +00:00
|
|
|
CorrectTextPosition( &m_Name );
|
|
|
|
RotatePoint( &m_Name.correctedPositionX, &m_Name.correctedPositionY, -m_Rotation );
|
2016-02-24 11:56:40 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
CorrectTextPosition( &m_Value );
|
2023-04-01 20:05:58 +00:00
|
|
|
RotatePoint( &m_Value.correctedPositionX, &m_Value.correctedPositionY, -m_Rotation );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
FOOTPRINT* footprint = new FOOTPRINT( m_board );
|
|
|
|
m_board->Add( footprint, ADD_MODE::APPEND );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
footprint->SetPosition( VECTOR2I( m_PositionX, m_PositionY ) );
|
2020-11-14 21:21:54 +00:00
|
|
|
footprint->SetLayer( m_Mirror ? B_Cu : F_Cu );
|
2023-04-01 20:05:58 +00:00
|
|
|
footprint->SetOrientation( m_Rotation );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2018-07-26 14:38:30 +00:00
|
|
|
LIB_ID fpID;
|
2023-04-01 20:05:58 +00:00
|
|
|
fpID.Parse( m_CompRef, true );
|
2020-11-14 21:21:54 +00:00
|
|
|
footprint->SetFPID( fpID );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
// reference text
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_TEXT* ref_text = &footprint->Reference();
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
ref_text->SetText( ValidateReference( m_Name.text ) );
|
2023-03-30 11:49:23 +00:00
|
|
|
ref_text->SetType( PCB_TEXT::TEXT_is_REFERENCE );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
ref_text->SetFPRelativePosition( VECTOR2I( m_Name.correctedPositionX,
|
|
|
|
m_Name.correctedPositionY ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_Name.isTrueType )
|
|
|
|
SetTextSizeFromTrueTypeFontHeight( ref_text, m_Name.textHeight );
|
2017-12-12 18:21:44 +00:00
|
|
|
else
|
2023-04-01 20:05:58 +00:00
|
|
|
SetTextSizeFromStrokeFontHeight( ref_text, m_Name.textHeight );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
r = m_Name.textRotation - m_Rotation;
|
2022-01-18 02:05:59 +00:00
|
|
|
ref_text->SetTextAngle( r );
|
2018-04-28 15:22:25 +00:00
|
|
|
ref_text->SetKeepUpright( false );
|
2016-02-24 11:56:40 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
ref_text->SetItalic( m_Name.isItalic );
|
|
|
|
ref_text->SetTextThickness( m_Name.textstrokeWidth );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
ref_text->SetMirrored( m_Name.mirror );
|
|
|
|
ref_text->SetVisible( m_Name.textIsVisible );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2022-05-31 20:01:48 +00:00
|
|
|
ref_text->SetLayer( m_Mirror ? FlipLayer( m_KiCadLayer ) : m_KiCadLayer );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
// value text
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_TEXT* val_text = &footprint->Value();
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
val_text->SetText( m_Value.text );
|
2023-03-30 11:49:23 +00:00
|
|
|
val_text->SetType( PCB_TEXT::TEXT_is_VALUE );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
val_text->SetFPRelativePosition( VECTOR2I( m_Value.correctedPositionX,
|
|
|
|
m_Value.correctedPositionY ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( m_Value.isTrueType )
|
|
|
|
SetTextSizeFromTrueTypeFontHeight( val_text, m_Value.textHeight );
|
2017-12-12 18:21:44 +00:00
|
|
|
else
|
2020-11-14 21:21:54 +00:00
|
|
|
SetTextSizeFromStrokeFontHeight( val_text, m_Value.textHeight );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2023-04-01 20:05:58 +00:00
|
|
|
r = m_Value.textRotation - m_Rotation;
|
2022-01-18 02:05:59 +00:00
|
|
|
val_text->SetTextAngle( r );
|
2018-04-28 15:22:25 +00:00
|
|
|
val_text->SetKeepUpright( false );
|
2016-02-24 11:56:40 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
val_text->SetItalic( m_Value.isItalic );
|
|
|
|
val_text->SetTextThickness( m_Value.textstrokeWidth );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
val_text->SetMirrored( m_Value.mirror );
|
|
|
|
val_text->SetVisible( m_Value.textIsVisible );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
val_text->SetLayer( m_Value.mirror ? FlipLayer( m_KiCadLayer ) : m_KiCadLayer );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
// TEXTS
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_FootprintItems[i]->m_ObjType == wxT( 'T' ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_FootprintItems[ i ]->AddToBoard( footprint );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 21:07:01 +00:00
|
|
|
// FOOTPRINT LINES
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_FootprintItems[i]->m_ObjType == wxT( 'L' ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_FootprintItems[ i ]->AddToBoard( footprint );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 21:07:01 +00:00
|
|
|
// FOOTPRINT ARCS
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_FootprintItems[i]->m_ObjType == wxT( 'A' ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_FootprintItems[ i ]->AddToBoard( footprint );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 21:07:01 +00:00
|
|
|
// FOOTPRINT POLYGONS
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2017-12-13 19:14:23 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_FootprintItems[i]->m_ObjType == wxT( 'Z' ) )
|
2023-03-30 11:49:23 +00:00
|
|
|
m_FootprintItems[ i ]->AddToBoard( footprint );
|
2017-12-13 19:14:23 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
// PADS
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_FootprintItems[i]->m_ObjType == wxT( 'P' ) )
|
|
|
|
((PCAD_PAD*) m_FootprintItems[ i ] )->AddToFootprint( footprint, m_Rotation, false );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// VIAS
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_FootprintItems[i]->m_ObjType == wxT( 'V' ) )
|
|
|
|
((PCAD_VIA*) m_FootprintItems[ i ] )->AddToFootprint( footprint, m_Rotation, false );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void PCAD_FOOTPRINT::Flip()
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2013-03-09 19:36:31 +00:00
|
|
|
int i;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( m_Mirror == 1 )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
m_Rotation = -m_Rotation;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_FootprintItems.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2023-04-01 20:05:58 +00:00
|
|
|
if( m_FootprintItems[i]->m_ObjType == wxT( 'L' ) || // lines
|
|
|
|
m_FootprintItems[i]->m_ObjType == wxT( 'A' ) || // arcs
|
|
|
|
m_FootprintItems[i]->m_ObjType == wxT( 'Z' ) || // polygons
|
|
|
|
m_FootprintItems[i]->m_ObjType == wxT( 'P' ) || // pads
|
|
|
|
m_FootprintItems[i]->m_ObjType == wxT( 'V' ) ) // vias
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
m_FootprintItems[i]->Flip();
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace PCAD2KICAD
|