CADSTAR PCB Archive Importer: Load correct pad information for pads with PADEXCEPTION

Overwrites pad definitions for pads that have PADEXCEPTION
This commit is contained in:
Roberto Fernandez Bautista 2020-10-24 18:02:44 +01:00 committed by Wayne Stambaugh
parent 7a1777e9b9
commit 0dc153fe58
2 changed files with 185 additions and 144 deletions

View File

@ -681,15 +681,21 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryPads( const SYMDEF_PCB& aComponent,
{
for( std::pair<PAD_ID, PAD> padPair : aComponent.Pads )
{
PAD& csPad = padPair.second; //Cadstar pad
PADCODE csPadcode = getPadCode( csPad.PadCodeID );
D_PAD* pad = new D_PAD( aModule );
D_PAD* pad = getKiCadPad( padPair.second, aModule );
aModule->Add( pad,
ADD_MODE::INSERT ); // insert so that we get correct behaviour when finding pads
// in the module by PAD_ID - see loadNets()
}
}
switch( csPad.Side )
D_PAD* CADSTAR_PCB_ARCHIVE_LOADER::getKiCadPad( const PAD& aCadstarPad, MODULE* aParent )
{
PADCODE csPadcode = getPadCode( aCadstarPad.PadCodeID );
D_PAD* pad = new D_PAD( aParent );
switch( aCadstarPad.Side )
{
case PAD_SIDE::MAXIMUM: //Bottom side
pad->SetAttribute( PAD_ATTR_T::PAD_ATTRIB_SMD );
@ -716,11 +722,12 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryPads( const SYMDEF_PCB& aComponent,
wxFAIL_MSG( "Unknown Pad type" );
}
pad->SetName( csPad.Identifier.IsEmpty() ? wxString::Format( wxT( "%ld" ), csPad.ID ) :
csPad.Identifier );
pad->SetName( aCadstarPad.Identifier.IsEmpty() ?
wxString::Format( wxT( "%ld" ), aCadstarPad.ID ) :
aCadstarPad.Identifier );
pad->SetPos0( getKiCadPoint( csPad.Position ) - aModule->GetPosition() );
pad->SetOrientation( getAngleTenthDegree( csPad.OrientAngle ) );
pad->SetPos0( getKiCadPoint( aCadstarPad.Position ) - aParent->GetPosition() );
pad->SetOrientation( getAngleTenthDegree( aCadstarPad.OrientAngle ) );
if( csPadcode.Shape.Size == 0 )
// zero sized pads seems to break KiCad so lets make it very small instead
@ -828,7 +835,8 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryPads( const SYMDEF_PCB& aComponent,
}
}
//TODO handle csPadcode.Reassigns when KiCad supports full padstacks
}
return pad;
}
@ -1075,6 +1083,38 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadComponents()
mBoard->Add( m, ADD_MODE::APPEND );
//Override pads with pad exceptions
if( comp.PadExceptions.size() > 0 )
{
SYMDEF_PCB fpLibEntry = Library.ComponentDefinitions.at( comp.SymdefID );
for( std::pair<PAD_ID, PADEXCEPTION> padPair : comp.PadExceptions )
{
PADEXCEPTION& padEx = padPair.second;
PAD csPad = fpLibEntry.Pads.at( padPair.first );
if( !padEx.PadCode.IsEmpty() )
csPad.PadCodeID = padEx.PadCode;
if( padEx.OverrideExits )
csPad.Exits = padEx.Exits;
if( padEx.OverrideOrientation )
csPad.OrientAngle = padEx.OrientAngle;
if( padEx.OverrideSide )
csPad.Side = padEx.Side;
//Find the pad in the module definition
D_PAD* kiPad = m->Pads().at( padEx.ID - (long) 1 );
if( kiPad )
delete kiPad;
m->Pads().at( padEx.ID - (long) 1 ) = getKiCadPad( csPad, m );
}
}
//set to empty string to avoid duplication when loading attributes:
m->SetValue( wxEmptyString );

View File

@ -336,6 +336,7 @@ private:
// Helper Functions for obtaining individual elements as KiCad elements:
double getHatchCodeAngleDegrees( const HATCHCODE_ID& aCadstarHatchcodeID );
D_PAD* getKiCadPad( const PAD& aCadstarPad, MODULE* aParent );
MODULE* getModuleFromCadstarID( const COMPONENT_ID& aCadstarComponentID );
int getKiCadHatchCodeThickness( const HATCHCODE_ID& aCadstarHatchcodeID );
int getKiCadHatchCodeGap( const HATCHCODE_ID& aCadstarHatchcodeID );