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>
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2012-2021 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
|
|
|
|
*/
|
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <pcad/pcb.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <pcad/pcb_keepout.h>
|
|
|
|
#include <pcad/pcb_footprint.h>
|
|
|
|
#include <pcad/pcb_net.h>
|
|
|
|
#include <pcad/pcb_pad.h>
|
|
|
|
#include <pcad/pcb_text.h>
|
|
|
|
#include <pcad/pcb_via.h>
|
|
|
|
#include <pcad/s_expr_loader.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <board.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
#include <common.h>
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <xnode.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/string.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
namespace PCAD2KICAD {
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
PCB_LAYER_ID PCB::GetKiCadLayer( int aPCadLayer ) const
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
auto it = m_LayersMap.find( aPCadLayer );
|
2020-02-28 19:43:37 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( it == m_LayersMap.end() )
|
2020-02-28 19:43:37 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
|
|
|
|
|
|
|
|
return it->second.KiCadLayer;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
LAYER_TYPE_T PCB::GetLayerType( int aPCadLayer ) const
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
auto it = m_LayersMap.find( aPCadLayer );
|
2020-02-28 19:43:37 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( it == m_LayersMap.end() )
|
2020-02-28 19:43:37 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
|
|
|
|
|
|
|
|
return it->second.layerType;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
wxString PCB::GetLayerNetNameRef( int aPCadLayer ) const
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
auto it = m_LayersMap.find( aPCadLayer );
|
2020-02-28 19:43:37 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( it == m_LayersMap.end() )
|
2020-02-28 19:43:37 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Unknown PCad layer %u" ), unsigned( aPCadLayer ) ) );
|
|
|
|
|
|
|
|
return it->second.netNameRef;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
PCB::PCB( BOARD* aBoard ) :
|
|
|
|
PCB_FOOTPRINT( this, aBoard )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
m_DefaultMeasurementUnit = wxT( "mil" );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-02-28 19:43:37 +00:00
|
|
|
for( size_t i = 0; i < 8; ++i )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-02-28 19:43:37 +00:00
|
|
|
TLAYER layer;
|
|
|
|
layer.KiCadLayer = F_Mask; // default
|
|
|
|
layer.layerType = LAYER_TYPE_NONSIGNAL; // default
|
2022-02-09 18:33:52 +00:00
|
|
|
layer.netNameRef = wxEmptyString; // default
|
2020-02-28 19:43:37 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_LayersMap.insert( std::make_pair( i, layer ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_SizeX = 0;
|
|
|
|
m_SizeY = 0;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_LayersMap[1].KiCadLayer = F_Cu;
|
|
|
|
m_LayersMap[1].layerType = LAYER_TYPE_SIGNAL;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_LayersMap[2].KiCadLayer = B_Cu;
|
|
|
|
m_LayersMap[2].layerType = LAYER_TYPE_SIGNAL;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_LayersMap[3].KiCadLayer = Eco2_User;
|
|
|
|
m_LayersMap[6].KiCadLayer = F_SilkS;
|
|
|
|
m_LayersMap[7].KiCadLayer = B_SilkS;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PCB::~PCB()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
delete m_PcbComponents[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbNetlist.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
delete m_PcbNetlist[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
int PCB::GetNetCode( const wxString& aNetName ) const
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-18 19:50:36 +00:00
|
|
|
const PCB_NET* net;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( int i = 0; i < (int) m_PcbNetlist.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
net = m_PcbNetlist[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( net->m_Name == aNetName )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
return net->m_NetCode;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
XNODE* PCB::FindCompDefName( XNODE* aNode, const wxString& aName ) const
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
XNODE* result = nullptr, * lNode;
|
2012-12-29 09:54:25 +00:00
|
|
|
wxString propValue;
|
|
|
|
|
|
|
|
lNode = FindNode( aNode, wxT( "compDef" ) );
|
|
|
|
|
|
|
|
while( lNode )
|
|
|
|
{
|
2022-05-27 17:08:27 +00:00
|
|
|
if( lNode->GetName().IsSameAs( wxT( "compDef" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
lNode->GetAttribute( wxT( "Name" ), &propValue );
|
|
|
|
|
|
|
|
if( propValue == 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue, const wxString& aPatGraphRefName,
|
|
|
|
const wxString& aXmlName, const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
XNODE* tNode, * t1Node;
|
2016-02-24 11:56:40 +00:00
|
|
|
wxString n, nnew, pn, propValue, str;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
// aNode is pattern now
|
|
|
|
tNode = aNode;
|
|
|
|
t1Node = aNode;
|
|
|
|
n = aXmlName;
|
|
|
|
|
2013-03-09 19:36:31 +00:00
|
|
|
// new file format version
|
2012-12-29 09:54:25 +00:00
|
|
|
if( FindNode( tNode, wxT( "patternGraphicsNameRef" ) ) )
|
|
|
|
{
|
|
|
|
FindNode( tNode,
|
|
|
|
wxT( "patternGraphicsNameRef" ) )->GetAttribute( wxT( "Name" ),
|
|
|
|
&pn );
|
|
|
|
pn.Trim( false );
|
|
|
|
pn.Trim( true );
|
|
|
|
tNode = FindNode( tNode, wxT( "patternGraphicsRef" ) );
|
|
|
|
|
|
|
|
while( tNode )
|
|
|
|
{
|
2022-05-27 17:08:27 +00:00
|
|
|
if( tNode->GetName().IsSameAs( wxT( "patternGraphicsRef" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
if( FindNode( tNode, wxT( "patternGraphicsNameRef" ) ) )
|
|
|
|
{
|
|
|
|
FindNode( tNode,
|
|
|
|
wxT( "patternGraphicsNameRef" ) )->GetAttribute( wxT( "Name" ),
|
|
|
|
&propValue );
|
|
|
|
|
|
|
|
if( propValue == pn )
|
|
|
|
{
|
|
|
|
t1Node = tNode; // find correct section with same name.
|
|
|
|
str = aTextValue->text;
|
|
|
|
str.Trim( false );
|
|
|
|
str.Trim( true );
|
2016-02-24 11:56:40 +00:00
|
|
|
nnew = n; // new file version
|
|
|
|
n = n + wxT( ' ' ) + str; // old file version
|
2021-07-19 23:56:05 +00:00
|
|
|
tNode = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
tNode = tNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// old version and compatible for both from this point
|
2012-12-29 09:54:25 +00:00
|
|
|
tNode = FindNode( t1Node, wxT( "attr" ) );
|
|
|
|
|
|
|
|
while( tNode )
|
|
|
|
{
|
|
|
|
tNode->GetAttribute( wxT( "Name" ), &propValue );
|
|
|
|
propValue.Trim( false );
|
|
|
|
propValue.Trim( true );
|
|
|
|
|
2016-02-24 11:56:40 +00:00
|
|
|
if( propValue == n || propValue == nnew )
|
2012-12-29 09:54:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
tNode = tNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( tNode )
|
2020-11-14 21:21:54 +00:00
|
|
|
SetTextParameters( tNode, aTextValue, m_DefaultMeasurementUnit, aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
void PCB::DoPCBComponents( XNODE* aNode, wxXmlDocument* aXmlDoc, const wxString& aActualConversion,
|
|
|
|
wxStatusBar* aStatusBar )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
XNODE* lNode, * tNode, * mNode;
|
|
|
|
PCB_FOOTPRINT* fp;
|
|
|
|
PCB_PAD* pad;
|
|
|
|
PCB_VIA* via;
|
|
|
|
PCB_KEEPOUT* keepOut;
|
|
|
|
wxString cn, str, propValue;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
lNode = aNode->GetChildren();
|
|
|
|
|
|
|
|
while( lNode )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
fp = nullptr;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( lNode->GetName().IsSameAs( wxT( "pattern" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
FindNode( lNode, wxT( "patternRef" ) )->GetAttribute( wxT( "Name" ),
|
|
|
|
&cn );
|
|
|
|
cn = ValidateName( cn );
|
|
|
|
tNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
|
|
|
|
|
|
|
|
if( tNode && cn.Len() > 0 )
|
|
|
|
{
|
|
|
|
tNode = FindModulePatternDefName( tNode, cn );
|
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
fp = new PCB_FOOTPRINT( this, m_board );
|
2013-03-09 19:36:31 +00:00
|
|
|
|
|
|
|
mNode = FindNode( lNode, wxT( "patternGraphicsNameRef" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2013-03-09 19:36:31 +00:00
|
|
|
if( mNode )
|
2020-11-14 21:21:54 +00:00
|
|
|
mNode->GetAttribute( wxT( "Name" ), &fp->m_patGraphRefName );
|
2013-03-09 19:36:31 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
fp->Parse( tNode, aStatusBar, m_DefaultMeasurementUnit, aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( fp )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
fp->m_compRef = cn; // default - in new version of file it is updated later....
|
2012-12-29 09:54:25 +00:00
|
|
|
tNode = FindNode( lNode, wxT( "refDesRef" ) );
|
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
tNode->GetAttribute( wxT( "Name" ), &fp->m_name.text );
|
|
|
|
SetTextProperty( lNode, &fp->m_name, fp->m_patGraphRefName, wxT( "RefDes" ),
|
|
|
|
aActualConversion );
|
|
|
|
SetTextProperty( lNode, &fp->m_Value, fp->m_patGraphRefName, wxT( "Value" ),
|
|
|
|
aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tNode = FindNode( lNode, wxT( "pt" ) );
|
|
|
|
|
|
|
|
if( tNode )
|
2020-11-14 21:21:54 +00:00
|
|
|
{
|
|
|
|
SetPosition( tNode->GetNodeContent(), m_DefaultMeasurementUnit,
|
|
|
|
&fp->m_positionX, &fp->m_positionY, aActualConversion );
|
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
tNode = FindNode( lNode, wxT( "rotation" ) );
|
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
{
|
|
|
|
str = tNode->GetNodeContent();
|
|
|
|
str.Trim( false );
|
2020-11-14 21:21:54 +00:00
|
|
|
fp->m_rotation = StrToInt1Units( str );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
str = FindNodeGetContent( lNode, wxT( "isFlipped" ) );
|
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( str.IsSameAs( wxT( "True" ), false ) )
|
2020-11-14 21:21:54 +00:00
|
|
|
fp->m_Mirror = 1;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
tNode = aNode;
|
|
|
|
|
|
|
|
while( tNode->GetName() != wxT( "www.lura.sk" ) )
|
|
|
|
tNode = tNode->GetParent();
|
|
|
|
|
|
|
|
tNode = FindNode( tNode, wxT( "netlist" ) );
|
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
{
|
|
|
|
tNode = FindNode( tNode, wxT( "compInst" ) );
|
|
|
|
|
|
|
|
while( tNode )
|
|
|
|
{
|
|
|
|
tNode->GetAttribute( wxT( "Name" ), &propValue );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( propValue == fp->m_name.text )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
if( FindNode( tNode, wxT( "compValue" ) ) )
|
|
|
|
{
|
|
|
|
FindNode( tNode,
|
|
|
|
wxT( "compValue" ) )->GetAttribute( wxT( "Name" ),
|
2020-11-14 21:21:54 +00:00
|
|
|
&fp->m_Value.text );
|
|
|
|
fp->m_Value.text.Trim( false );
|
|
|
|
fp->m_Value.text.Trim( true );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( FindNode( tNode, wxT( "compRef" ) ) )
|
|
|
|
{
|
|
|
|
FindNode( tNode,
|
|
|
|
wxT( "compRef" ) )->GetAttribute( wxT( "Name" ),
|
2020-11-14 21:21:54 +00:00
|
|
|
&fp->m_compRef );
|
|
|
|
fp->m_compRef.Trim( false );
|
|
|
|
fp->m_compRef.Trim( true );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
tNode = 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
|
|
|
tNode = tNode->GetNext();
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// map pins
|
|
|
|
tNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
|
2020-11-14 21:21:54 +00:00
|
|
|
tNode = FindCompDefName( tNode, fp->m_compRef );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
{
|
|
|
|
tNode = FindPinMap( tNode );
|
|
|
|
|
|
|
|
if( tNode )
|
|
|
|
{
|
|
|
|
mNode = tNode->GetChildren();
|
|
|
|
|
|
|
|
while( mNode )
|
|
|
|
{
|
2022-05-27 17:08:27 +00:00
|
|
|
if( mNode->GetName().IsSameAs( wxT( "padNum" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
str = mNode->GetNodeContent();
|
|
|
|
mNode = mNode->GetNext();
|
|
|
|
|
|
|
|
if( !mNode )
|
|
|
|
break;
|
|
|
|
|
|
|
|
mNode->GetAttribute( wxT( "Name" ), &propValue );
|
2020-11-14 21:21:54 +00:00
|
|
|
fp->SetName( str, propValue );
|
2012-12-29 09:54:25 +00:00
|
|
|
mNode = mNode->GetNext();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mNode = mNode->GetNext();
|
|
|
|
|
|
|
|
if( !mNode )
|
|
|
|
break;
|
|
|
|
|
|
|
|
mNode = mNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_PcbComponents.Add( fp );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( lNode->GetName().IsSameAs( wxT( "pad" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
pad = new PCB_PAD( this, m_board );
|
2020-11-14 21:21:54 +00:00
|
|
|
pad->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion );
|
|
|
|
m_PcbComponents.Add( pad );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( lNode->GetName().IsSameAs( wxT( "via" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
via = new PCB_VIA( this, m_board );
|
2020-11-14 21:21:54 +00:00
|
|
|
via->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion );
|
|
|
|
m_PcbComponents.Add( via );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
2022-05-27 17:08:27 +00:00
|
|
|
else if( lNode->GetName().IsSameAs( wxT( "polyKeepOut" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
keepOut = new PCB_KEEPOUT( m_callbacks, m_board, 0 );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( keepOut->Parse( lNode, m_DefaultMeasurementUnit, aActualConversion ) )
|
|
|
|
m_PcbComponents.Add( keepOut );
|
2012-12-29 09:54:25 +00:00
|
|
|
else
|
|
|
|
delete keepOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
lNode = lNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
void PCB::ConnectPinToNet( const wxString& aCompRef, const wxString& aPinRef,
|
2017-09-23 09:20:10 +00:00
|
|
|
const wxString& aNetName )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
PCB_FOOTPRINT* footprint;
|
|
|
|
PCB_PAD* cp;
|
|
|
|
int i, j;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
footprint = (PCB_FOOTPRINT*) m_PcbComponents[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( footprint->m_objType == wxT( 'M' ) && footprint->m_name.text == aCompRef )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
for( j = 0; j < (int) footprint->m_FootprintItems.GetCount(); j++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
if( footprint->m_FootprintItems[j]->m_objType == wxT( 'P' ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
cp = (PCB_PAD*) footprint->m_FootprintItems[j];
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( cp->m_name.text == aPinRef )
|
|
|
|
cp->m_net = aNetName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
int PCB::FindLayer( const wxString& aLayerName ) const
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2022-06-09 00:16:48 +00:00
|
|
|
for( LAYER_NUM i = 0; i < (int)m_layersStackup.size(); ++i )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2022-06-09 18:08:49 +00:00
|
|
|
if( m_layersStackup[i].first == aLayerName )
|
2012-12-29 09:54:25 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
void PCB::MapLayer( XNODE* aNode )
|
|
|
|
{
|
2017-03-13 03:19:33 +00:00
|
|
|
wxString lName, layerType;
|
|
|
|
PCB_LAYER_ID KiCadLayer;
|
|
|
|
long num = 0;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
aNode->GetAttribute( wxT( "Name" ), &lName );
|
|
|
|
lName = lName.MakeUpper();
|
|
|
|
|
|
|
|
if( lName == wxT( "TOP ASSY" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2017-12-13 17:47:03 +00:00
|
|
|
KiCadLayer = F_Fab;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "TOP SILK" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = F_SilkS;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "TOP PASTE" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = F_Paste;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "TOP MASK" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = F_Mask;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "TOP" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = F_Cu;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "BOTTOM" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = B_Cu;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "BOT MASK" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = B_Mask;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "BOT PASTE" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = B_Paste;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "BOT SILK" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = B_SilkS;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "BOT ASSY" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2017-12-13 17:47:03 +00:00
|
|
|
KiCadLayer = B_Fab;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else if( lName == wxT( "BOARD" ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = Edge_Cuts;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
else
|
|
|
|
{
|
2013-03-31 13:27:46 +00:00
|
|
|
int layernum = FindLayer( lName );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
if( layernum == -1 )
|
2014-06-24 16:17:18 +00:00
|
|
|
KiCadLayer = Dwgs_User; // default
|
2012-12-29 09:54:25 +00:00
|
|
|
else
|
2014-06-29 13:05:51 +00:00
|
|
|
KiCadLayer = ToLAYER_ID( layernum );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( FindNode( aNode, wxT( "layerNum" ) ) )
|
|
|
|
FindNode( aNode, wxT( "layerNum" ) )->GetNodeContent().ToLong( &num );
|
|
|
|
|
2020-02-28 19:43:37 +00:00
|
|
|
if( num < 0 )
|
2013-03-09 19:36:31 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( wxT( "layerNum = %ld is out of range" ), num ) );
|
|
|
|
|
2020-02-28 19:43:37 +00:00
|
|
|
TLAYER newlayer;
|
|
|
|
newlayer.KiCadLayer = KiCadLayer;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( FindNode( aNode, wxT( "layerType" ) ) )
|
|
|
|
{
|
|
|
|
layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim( false );
|
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( layerType.IsSameAs( wxT( "NonSignal" ), false ) )
|
2020-02-28 19:43:37 +00:00
|
|
|
newlayer.layerType = LAYER_TYPE_NONSIGNAL;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( layerType.IsSameAs( wxT( "Signal" ), false ) )
|
2020-02-28 19:43:37 +00:00
|
|
|
newlayer.layerType = LAYER_TYPE_SIGNAL;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( layerType.IsSameAs( wxT( "Plane" ), false ) )
|
2020-02-28 19:43:37 +00:00
|
|
|
newlayer.layerType = LAYER_TYPE_PLANE;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_LayersMap.insert( std::make_pair( num, newlayer ) );
|
2020-02-28 19:43:37 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
if( FindNode( aNode, wxT( "netNameRef" ) ) )
|
|
|
|
{
|
|
|
|
FindNode( aNode, wxT( "netNameRef" ) )->GetAttribute( wxT( "Name" ),
|
2020-11-14 21:21:54 +00:00
|
|
|
&m_LayersMap[(int) num].netNameRef );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
int PCB::FindOutlinePoint( const VERTICES_ARRAY* aOutline, wxRealPoint aPoint ) const
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i = 0; i < (int) aOutline->GetCount(); i++ )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2012-12-29 09:54:25 +00:00
|
|
|
if( *((*aOutline)[i]) == aPoint )
|
|
|
|
return i;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
double PCB::GetDistance( const wxRealPoint* aPoint1, const wxRealPoint* aPoint2 ) const
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
return sqrt( ( aPoint1->x - aPoint2->x ) * ( aPoint1->x - aPoint2->x ) +
|
|
|
|
( aPoint1->y - aPoint2->y ) * ( aPoint1->y - aPoint2->y ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
XNODE* iNode, *lNode, *pNode;
|
|
|
|
long PCadLayer = 0;
|
|
|
|
int x, y, i, j, targetInd;
|
|
|
|
wxRealPoint* xchgPoint;
|
|
|
|
double minDistance, distance;
|
|
|
|
|
|
|
|
iNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
|
|
|
|
|
|
|
|
if( iNode )
|
|
|
|
{
|
|
|
|
// COMPONENTS AND OBJECTS
|
|
|
|
iNode = iNode->GetChildren();
|
|
|
|
|
|
|
|
while( iNode )
|
|
|
|
{
|
|
|
|
// objects
|
2022-05-27 17:08:27 +00:00
|
|
|
if( iNode->GetName().IsSameAs( wxT( "layerContents" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
if( FindNode( iNode, wxT( "layerNumRef" ) ) )
|
|
|
|
FindNode( iNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &PCadLayer );
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
if( GetKiCadLayer( PCadLayer ) == Edge_Cuts )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
lNode = iNode->GetChildren();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
while( lNode )
|
|
|
|
{
|
2022-05-27 17:08:27 +00:00
|
|
|
if( lNode->GetName().IsSameAs( wxT( "line" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
pNode = FindNode( lNode, wxT( "pt" ) );
|
|
|
|
|
|
|
|
if( pNode )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
SetPosition( pNode->GetNodeContent(), m_DefaultMeasurementUnit,
|
2012-12-29 09:54:25 +00:00
|
|
|
&x, &y, aActualConversion );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( FindOutlinePoint( &m_BoardOutline, wxRealPoint( x, y) ) == -1 )
|
|
|
|
m_BoardOutline.Add( new wxRealPoint( x, y ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 16:48:42 +00:00
|
|
|
if( pNode )
|
|
|
|
pNode = pNode->GetNext();
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( pNode )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
SetPosition( pNode->GetNodeContent(), m_DefaultMeasurementUnit,
|
2012-12-29 09:54:25 +00:00
|
|
|
&x, &y, aActualConversion );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( FindOutlinePoint( &m_BoardOutline, wxRealPoint( x, y) ) == -1 )
|
|
|
|
m_BoardOutline.Add( new wxRealPoint( x, y ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lNode = lNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
//m_boardOutline.Sort( cmpFunc );
|
|
|
|
// sort vertices according to the distances between them
|
2020-11-14 21:21:54 +00:00
|
|
|
if( m_BoardOutline.GetCount() > 3 )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_BoardOutline.GetCount() - 1; i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
minDistance = GetDistance( m_BoardOutline[i], m_BoardOutline[ i + 1] );
|
2012-12-29 09:54:25 +00:00
|
|
|
targetInd = i + 1;
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( j = i + 2; j < (int) m_BoardOutline.GetCount(); j++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
distance = GetDistance( m_BoardOutline[i], m_BoardOutline[j] );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
if( distance < minDistance )
|
|
|
|
{
|
|
|
|
minDistance = distance;
|
|
|
|
targetInd = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
xchgPoint = m_BoardOutline[ i + 1];
|
|
|
|
m_BoardOutline[ i + 1] = m_BoardOutline[targetInd];
|
|
|
|
m_BoardOutline[targetInd] = xchgPoint;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iNode = iNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
void PCB::ParseBoard( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc,
|
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
XNODE* aNode;//, *aaNode;
|
|
|
|
PCB_NET* net;
|
|
|
|
PCB_COMPONENT* comp;
|
2020-11-14 21:21:54 +00:00
|
|
|
PCB_FOOTPRINT* footprint;
|
2012-12-29 09:54:25 +00:00
|
|
|
wxString compRef, pinRef, layerName, layerType;
|
|
|
|
int i, j, netCode;
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Default measurement units
|
2012-12-29 09:54:25 +00:00
|
|
|
aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "asciiHeader" ) );
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
aNode = FindNode( aNode, wxT( "fileUnits" ) );
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
m_DefaultMeasurementUnit = aNode->GetNodeContent().Lower();
|
|
|
|
m_DefaultMeasurementUnit.Trim( true );
|
|
|
|
m_DefaultMeasurementUnit.Trim( false );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine layers stackup
|
|
|
|
aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
|
|
|
|
|
|
|
|
/*if( aNode )
|
|
|
|
{
|
|
|
|
aNode = FindNode( aNode, wxT( "layersStackup" ) );
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
aNode = FindNode( aNode, wxT( "layerStackupData" ) );
|
|
|
|
|
|
|
|
while( aNode )
|
|
|
|
{
|
|
|
|
if( aNode->GetName() == wxT( "layerStackupData" ) )
|
|
|
|
{
|
|
|
|
aaNode = FindNode( aNode, wxT( "layerStackupName" ) );
|
|
|
|
|
|
|
|
if( aaNode ) {
|
|
|
|
aaNode->GetAttribute( wxT( "Name" ), &layerName );
|
|
|
|
layerName = layerName.MakeUpper();
|
|
|
|
m_layersStackup.Add( layerName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aNode = aNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
aNode = FindNode( aNode, wxT( "layerDef" ) );
|
|
|
|
|
|
|
|
while( aNode )
|
|
|
|
{
|
2022-05-27 17:08:27 +00:00
|
|
|
if( aNode->GetName().IsSameAs( wxT( "layerDef" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
if( FindNode( aNode, wxT( "layerType" ) ) )
|
|
|
|
{
|
2022-06-09 18:08:49 +00:00
|
|
|
long num = -1;
|
|
|
|
|
|
|
|
if( FindNode( aNode, wxT( "layerNum" ) ) )
|
|
|
|
FindNode( aNode, wxT( "layerNum" ) )->GetNodeContent().ToLong( &num );
|
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim(
|
|
|
|
false );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2022-06-09 18:08:49 +00:00
|
|
|
if( num > 0 && ( layerType.IsSameAs( wxT( "Signal" ), false )
|
|
|
|
|| layerType.IsSameAs( wxT( "Plane" ), false ) ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
aNode->GetAttribute( wxT( "Name" ), &layerName );
|
|
|
|
layerName = layerName.MakeUpper();
|
2022-06-09 18:08:49 +00:00
|
|
|
m_layersStackup.emplace_back( layerName, num );
|
2020-02-28 19:43:37 +00:00
|
|
|
|
|
|
|
if( m_layersStackup.size() > 32 )
|
2021-06-27 23:26:54 +00:00
|
|
|
THROW_IO_ERROR( _( "KiCad only supports 32 signal layers." ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aNode = aNode->GetNext();
|
|
|
|
}
|
2022-06-09 18:08:49 +00:00
|
|
|
|
|
|
|
// Ensure that the layers are properly mapped to their order with the bottom
|
|
|
|
// copper (layer 2 in PCAD) at the end
|
|
|
|
std::sort( m_layersStackup.begin(), m_layersStackup.end(),
|
|
|
|
[&]( const std::pair<wxString, long>& a, const std::pair<wxString, long>& b ) {
|
|
|
|
long lhs = a.second == 2 ? std::numeric_limits<long>::max() : a.second;
|
|
|
|
long rhs = b.second == 2 ? std::numeric_limits<long>::max() : b.second;
|
|
|
|
|
|
|
|
return lhs < rhs;
|
|
|
|
} );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Layers mapping
|
|
|
|
aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
aNode = FindNode( aNode, wxT( "layerDef" ) );
|
|
|
|
|
|
|
|
while( aNode )
|
|
|
|
{
|
2022-05-27 17:08:27 +00:00
|
|
|
if( aNode->GetName().IsSameAs( wxT( "layerDef" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
MapLayer( aNode );
|
|
|
|
|
|
|
|
aNode = aNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GetBoardOutline( aXmlDoc, aActualConversion );
|
|
|
|
|
|
|
|
// NETLIST
|
|
|
|
// aStatusBar->SetStatusText( wxT( "Loading NETLIST " ) );
|
|
|
|
|
|
|
|
aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "netlist" ) );
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
aNode = FindNode( aNode, wxT( "net" ) );
|
|
|
|
|
|
|
|
netCode = 1;
|
|
|
|
|
|
|
|
while( aNode )
|
|
|
|
{
|
|
|
|
net = new PCB_NET( netCode++ );
|
|
|
|
net->Parse( aNode );
|
2020-11-14 21:21:54 +00:00
|
|
|
m_PcbNetlist.Add( net );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
aNode = aNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOARD FILE
|
|
|
|
// aStatusBar->SetStatusText( wxT( "Loading BOARD DEFINITION " ) );
|
|
|
|
|
|
|
|
aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
// COMPONENTS AND OBJECTS
|
|
|
|
aNode = aNode->GetChildren();
|
|
|
|
|
|
|
|
while( aNode )
|
|
|
|
{
|
2020-10-21 03:48:06 +00:00
|
|
|
// Components/footprints
|
2022-05-27 17:08:27 +00:00
|
|
|
if( aNode->GetName().IsSameAs( wxT( "multiLayer" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
DoPCBComponents( aNode, aXmlDoc, aActualConversion, aStatusBar );
|
|
|
|
|
|
|
|
// objects
|
2022-05-27 17:08:27 +00:00
|
|
|
if( aNode->GetName().IsSameAs( wxT( "layerContents" ), false ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
DoLayerContentsObjects( aNode, nullptr, &m_PcbComponents, aStatusBar,
|
2020-11-14 21:21:54 +00:00
|
|
|
m_DefaultMeasurementUnit, aActualConversion );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
aNode = aNode->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// POSTPROCESS -- SET NETLIST REFERENCES
|
|
|
|
// aStatusBar->SetStatusText( wxT( "Processing NETLIST " ) );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbNetlist.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
net = m_PcbNetlist[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( j = 0; j < (int) net->m_NetNodes.GetCount(); j++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
compRef = net->m_NetNodes[j]->m_CompRef;
|
2012-12-29 09:54:25 +00:00
|
|
|
compRef.Trim( false );
|
|
|
|
compRef.Trim( true );
|
2020-11-14 21:21:54 +00:00
|
|
|
pinRef = net->m_NetNodes[j]->m_PinRef;
|
2012-12-29 09:54:25 +00:00
|
|
|
pinRef.Trim( false );
|
|
|
|
pinRef.Trim( true );
|
2020-11-14 21:21:54 +00:00
|
|
|
ConnectPinToNet( compRef, pinRef, net->m_Name );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// POSTPROCESS -- FLIP COMPONENTS
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
if( m_PcbComponents[i]->m_objType == wxT( 'M' ) )
|
|
|
|
( (PCB_FOOTPRINT*) m_PcbComponents[i] )->Flip();
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// POSTPROCESS -- SET/OPTIMIZE NEW PCB POSITION
|
|
|
|
// aStatusBar->SetStatusText( wxT( "Optimizing BOARD POSITION " ) );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_SizeX = 10000000;
|
|
|
|
m_SizeY = 0;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
comp = m_PcbComponents[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( comp->m_positionY < m_SizeY )
|
|
|
|
m_SizeY = comp->m_positionY; // max Y
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( comp->m_positionX < m_SizeX && comp->m_positionX > 0 )
|
|
|
|
m_SizeX = comp->m_positionX; // Min X
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_SizeY -= 10000;
|
|
|
|
m_SizeX -= 10000;
|
2012-12-29 09:54:25 +00:00
|
|
|
// aStatusBar->SetStatusText( wxT( " POSITIONING POSTPROCESS " ) );
|
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
|
|
|
|
m_PcbComponents[i]->SetPosOffset( -m_SizeX, -m_SizeY );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_SizeX = 0;
|
|
|
|
m_SizeY = 0;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
comp = m_PcbComponents[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( comp->m_positionY < m_SizeY )
|
|
|
|
m_SizeY = comp->m_positionY; // max Y
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( comp->m_positionX > m_SizeX )
|
|
|
|
m_SizeX = comp->m_positionX; // Min X
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SHEET SIZE CALCULATION
|
2020-11-14 21:21:54 +00:00
|
|
|
m_SizeY = -m_SizeY; // it is in absolute units
|
|
|
|
m_SizeX += 10000;
|
|
|
|
m_SizeY += 10000;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
// A4 is minimum $Descr A4 11700 8267
|
2020-11-14 21:21:54 +00:00
|
|
|
if( m_SizeX < 11700 )
|
|
|
|
m_SizeX = 11700;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
if( m_SizeY < 8267 )
|
|
|
|
m_SizeY = 8267;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// LIBRARY FILE
|
|
|
|
// aStatusBar->SetStatusText( wxT( "Processing LIBRARY FILE " ) );
|
|
|
|
|
|
|
|
aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
|
|
|
|
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
aNode = FindNode( aNode, wxT( "compDef" ) );
|
|
|
|
|
|
|
|
while( aNode )
|
|
|
|
{
|
|
|
|
// aStatusBar->SetStatusText( wxT( "Processing COMPONENTS " ) );
|
|
|
|
|
2022-05-27 17:08:27 +00:00
|
|
|
if( aNode->GetName().IsSameAs( wxT( "compDef" ), false ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
footprint = new PCB_FOOTPRINT( this, m_board );
|
|
|
|
footprint->Parse( aNode, aStatusBar, m_DefaultMeasurementUnit,
|
|
|
|
aActualConversion );
|
|
|
|
m_PcbComponents.Add( footprint );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aNode = aNode->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB::AddToBoard()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
PCB_NET* net;
|
|
|
|
|
2022-06-09 00:16:48 +00:00
|
|
|
m_board->SetCopperLayerCount( m_layersStackup.size() );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbNetlist.GetCount(); i++ )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
net = m_PcbNetlist[i];
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
m_board->Add( new NETINFO_ITEM( m_board, net->m_Name, net->m_NetCode ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
Removed D_PAD::SetNetname() function and D_PAD::m_Netname, D_PAD::m_ShortNetname fields.
D_PAD::GetNetname() and D_PAD::GetShortNetname() were moved to BOARD_CONNECTED_ITEM. Now they use the net name stored in NETINFO_ITEM.
Moved some one-line functions from class_board_connected_item.cpp to class_board_connected_item.h.
Added a copyright notice, moved Doxygen comments from class_board_connected_item.cpp to class_board_connected_item.h.
I have some doubts if changes introduced pcbnew/dialogs/dialog_pad_properties.cpp do not break anything, but I could not find a test case that breaks the pcbnew.
Performed tests:
- changed pad's net name from empty to existent - ok, name was changed
- changed pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty
- changed pad's net name from existent to empty - ok, net name became empty
- changed pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed
- (re)reading netlists, including net changes - fine, changes are applied, but empty nets are still kept
- loaded pcbnew/pcad2kicadpcb_plugin/examples/CK1202_V1.pcb to test P-CAD import plugin - ok, net names are correct
- imported an Eagle 6.0 board (Arduino Uno; http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip) then saved in .kicad_pcb format and reloaded - ok, net names are correct
- saved demos/video/video.kicad_pcb in legacy format and then loaded it again - ok, net names are correct
2014-01-14 09:41:52 +00:00
|
|
|
|
2020-11-14 21:21:54 +00:00
|
|
|
for( i = 0; i < (int) m_PcbComponents.GetCount(); i++ )
|
Removed D_PAD::SetNetname() function and D_PAD::m_Netname, D_PAD::m_ShortNetname fields.
D_PAD::GetNetname() and D_PAD::GetShortNetname() were moved to BOARD_CONNECTED_ITEM. Now they use the net name stored in NETINFO_ITEM.
Moved some one-line functions from class_board_connected_item.cpp to class_board_connected_item.h.
Added a copyright notice, moved Doxygen comments from class_board_connected_item.cpp to class_board_connected_item.h.
I have some doubts if changes introduced pcbnew/dialogs/dialog_pad_properties.cpp do not break anything, but I could not find a test case that breaks the pcbnew.
Performed tests:
- changed pad's net name from empty to existent - ok, name was changed
- changed pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty
- changed pad's net name from existent to empty - ok, net name became empty
- changed pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed
- (re)reading netlists, including net changes - fine, changes are applied, but empty nets are still kept
- loaded pcbnew/pcad2kicadpcb_plugin/examples/CK1202_V1.pcb to test P-CAD import plugin - ok, net names are correct
- imported an Eagle 6.0 board (Arduino Uno; http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip) then saved in .kicad_pcb format and reloaded - ok, net names are correct
- saved demos/video/video.kicad_pcb in legacy format and then loaded it again - ok, net names are correct
2014-01-14 09:41:52 +00:00
|
|
|
{
|
2020-11-14 21:21:54 +00:00
|
|
|
m_PcbComponents[i]->AddToBoard();
|
Removed D_PAD::SetNetname() function and D_PAD::m_Netname, D_PAD::m_ShortNetname fields.
D_PAD::GetNetname() and D_PAD::GetShortNetname() were moved to BOARD_CONNECTED_ITEM. Now they use the net name stored in NETINFO_ITEM.
Moved some one-line functions from class_board_connected_item.cpp to class_board_connected_item.h.
Added a copyright notice, moved Doxygen comments from class_board_connected_item.cpp to class_board_connected_item.h.
I have some doubts if changes introduced pcbnew/dialogs/dialog_pad_properties.cpp do not break anything, but I could not find a test case that breaks the pcbnew.
Performed tests:
- changed pad's net name from empty to existent - ok, name was changed
- changed pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty
- changed pad's net name from existent to empty - ok, net name became empty
- changed pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed
- (re)reading netlists, including net changes - fine, changes are applied, but empty nets are still kept
- loaded pcbnew/pcad2kicadpcb_plugin/examples/CK1202_V1.pcb to test P-CAD import plugin - ok, net names are correct
- imported an Eagle 6.0 board (Arduino Uno; http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip) then saved in .kicad_pcb format and reloaded - ok, net names are correct
- saved demos/video/video.kicad_pcb in legacy format and then loaded it again - ok, net names are correct
2014-01-14 09:41:52 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace PCAD2KICAD
|