From 79aafd1bd313189036dedab7c799d85d862b1858 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Fri, 11 Mar 2022 19:15:34 +0100 Subject: [PATCH] altium: support keepout restrictions in Arcs, Fills and Regions --- pcbnew/plugins/altium/altium_parser.ksy | 42 +++++++++++++++++++-- pcbnew/plugins/altium/altium_parser_pcb.cpp | 22 +++++++++++ pcbnew/plugins/altium/altium_parser_pcb.h | 3 ++ pcbnew/plugins/altium/altium_pcb.cpp | 29 ++++++-------- pcbnew/plugins/altium/altium_pcb.h | 4 +- 5 files changed, 77 insertions(+), 23 deletions(-) diff --git a/pcbnew/plugins/altium/altium_parser.ksy b/pcbnew/plugins/altium/altium_parser.ksy index 0fb4342a3c..0f2ca6823c 100644 --- a/pcbnew/plugins/altium/altium_parser.ksy +++ b/pcbnew/plugins/altium/altium_parser.ksy @@ -60,10 +60,13 @@ types: - id: sub1_len type: u4 - id: data - type: arc_sub1 + type: arc_sub1(sub1_len) size: sub1_len arc_sub1: + params: + - id: sub1_len + type: u4 seq: - id: layer type: u1 @@ -102,6 +105,10 @@ types: type: f8 - id: width type: u4 + - size: 11 + - id: keepout_restrictions + type: keepout_restrictions + if: sub1_len >= 57 pad: seq: @@ -366,10 +373,13 @@ types: - id: sub1_len type: u4 - id: data - type: track_sub1 + type: track_sub1(sub1_len) size: sub1_len track_sub1: + params: + - id: sub1_len + type: u4 seq: - id: layer type: u1 @@ -405,6 +415,10 @@ types: type: xy - id: width # 29 type: s4 + - size: 12 + - id: keepout_restrictions + type: keepout_restrictions + if: sub1_len >= 46 text: seq: @@ -527,10 +541,13 @@ types: - id: sub1_len type: u4 - id: data - type: fill_sub1 + type: fill_sub1(sub1_len) size: sub1_len fill_sub1: + params: + - id: sub1_len + type: u4 seq: - id: layer type: u1 @@ -564,6 +581,10 @@ types: type: xy - id: rotation type: f8 + - size: 9 + - id: keepout_restrictions + type: keepout_restrictions + if: sub1_len >= 47 region: seq: @@ -654,6 +675,21 @@ types: size: propterties_len type: str + keepout_restrictions: + seq: + - id: keepout_restriction_unknown # not used + type: b3 + - id: keepout_restriction_pth + type: b1 + - id: keepout_restriction_smd + type: b1 + - id: keepout_restriction_copper + type: b1 + - id: keepout_restriction_track + type: b1 + - id: keepout_restriction_via + type: b1 + xy: seq: - id: x diff --git a/pcbnew/plugins/altium/altium_parser_pcb.cpp b/pcbnew/plugins/altium/altium_parser_pcb.cpp index 024df9fc10..7f838fcc61 100644 --- a/pcbnew/plugins/altium/altium_parser_pcb.cpp +++ b/pcbnew/plugins/altium/altium_parser_pcb.cpp @@ -592,6 +592,16 @@ AARC6::AARC6( ALTIUM_PARSER& aReader ) endangle = aReader.Read(); width = aReader.ReadKicadUnit(); + if( aReader.GetRemainingSubrecordBytes() >= 12 ) + { + aReader.Skip( 11 ); + keepoutrestrictions = aReader.Read(); + } + else + { + keepoutrestrictions = is_keepout ? 0x1F : 0; + } + aReader.SkipSubrecord(); if( aReader.HasParsingError() ) @@ -957,6 +967,16 @@ AFILL6::AFILL6( ALTIUM_PARSER& aReader ) pos2 = aReader.ReadVector2I(); rotation = aReader.Read(); + if( aReader.GetRemainingSubrecordBytes() >= 10 ) + { + aReader.Skip( 9 ); + keepoutrestrictions = aReader.Read(); + } + else + { + keepoutrestrictions = is_keepout ? 0x1F : 0; + } + aReader.SkipSubrecord(); if( aReader.HasParsingError() ) @@ -997,6 +1017,8 @@ AREGION6::AREGION6( ALTIUM_PARSER& aReader, bool aExtendedVertices ) bool is_cutout = ALTIUM_PARSER::ReadBool( properties, wxT( "ISBOARDCUTOUT" ), false ); is_shapebased = ALTIUM_PARSER::ReadBool( properties, wxT( "ISSHAPEBASED" ), false ); + keepoutrestrictions = static_cast( + ALTIUM_PARSER::ReadInt( properties, wxT( "KEEPOUTRESTRIC" ), 0x1F ) ); // TODO: this can differ from the other subpolyindex?! //subpolyindex = static_cast( diff --git a/pcbnew/plugins/altium/altium_parser_pcb.h b/pcbnew/plugins/altium/altium_parser_pcb.h index 04562af741..59a06a214e 100644 --- a/pcbnew/plugins/altium/altium_parser_pcb.h +++ b/pcbnew/plugins/altium/altium_parser_pcb.h @@ -524,6 +524,7 @@ struct AREGION6 uint16_t net; uint16_t component; uint16_t subpolyindex; + uint8_t keepoutrestrictions; uint16_t holecount; ALTIUM_REGION_KIND kind; // I assume this means if normal or keepout? @@ -544,6 +545,7 @@ struct AARC6 uint16_t net; uint16_t component; uint16_t subpolyindex; + uint8_t keepoutrestrictions; VECTOR2I center; uint32_t radius; @@ -699,6 +701,7 @@ struct AFILL6 ALTIUM_LAYER layer; uint16_t component; uint16_t net; + uint8_t keepoutrestrictions; VECTOR2I pos1; VECTOR2I pos2; diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp index 4f55138ef8..02ffa73217 100644 --- a/pcbnew/plugins/altium/altium_pcb.cpp +++ b/pcbnew/plugins/altium/altium_pcb.cpp @@ -1931,11 +1931,8 @@ void ALTIUM_PCB::ConvertShapeBasedRegions6ToBoardItem( const AREGION6& aElem ) m_board->Add( zone, ADD_MODE::APPEND ); zone->SetIsRuleArea( true ); - zone->SetDoNotAllowTracks( false ); - zone->SetDoNotAllowVias( false ); - zone->SetDoNotAllowPads( false ); - zone->SetDoNotAllowFootprints( false ); - zone->SetDoNotAllowCopperPour( true ); + + HelperSetZoneKeepoutRestrictions( zone, aElem.keepoutrestrictions ); zone->SetPosition( aElem.outline.at( 0 ).position ); zone->Outline()->AddOutline( linechain ); @@ -1982,11 +1979,8 @@ void ALTIUM_PCB::ConvertShapeBasedRegions6ToFootprintItem( FOOTPRINT* aFoot aFootprint->Add( zone, ADD_MODE::APPEND ); zone->SetIsRuleArea( true ); - zone->SetDoNotAllowTracks( false ); - zone->SetDoNotAllowVias( false ); - zone->SetDoNotAllowPads( false ); - zone->SetDoNotAllowFootprints( false ); - zone->SetDoNotAllowCopperPour( true ); + + HelperSetZoneKeepoutRestrictions( zone, aElem.keepoutrestrictions ); zone->SetPosition( aElem.outline.at( 0 ).position ); zone->Outline()->AddOutline( linechain ); @@ -2218,7 +2212,7 @@ void ALTIUM_PCB::ConvertArcs6ToBoardItem( const AARC6& aElem, const int aPrimiti ConvertArcs6ToPcbShape( aElem, &shape ); shape.SetStroke( STROKE_PARAMS( aElem.width, PLOT_DASH_TYPE::SOLID ) ); - HelperPcpShapeAsBoardKeepoutRegion( shape, aElem.layer ); + HelperPcpShapeAsBoardKeepoutRegion( shape, aElem.layer, aElem.keepoutrestrictions ); } else { @@ -2260,7 +2254,8 @@ void ALTIUM_PCB::ConvertArcs6ToFootprintItem( FOOTPRINT* aFootprint, const AARC6 ConvertArcs6ToPcbShape( aElem, &shape ); shape.SetStroke( STROKE_PARAMS( aElem.width, PLOT_DASH_TYPE::SOLID ) ); - HelperPcpShapeAsFootprintKeepoutRegion( aFootprint, shape, aElem.layer ); + HelperPcpShapeAsFootprintKeepoutRegion( aFootprint, shape, aElem.layer, + aElem.keepoutrestrictions ); } else { @@ -3315,7 +3310,8 @@ void ALTIUM_PCB::ConvertFills6ToFootprintItem( FOOTPRINT* aFootprint, const AFIL shape.Rotate( center, EDA_ANGLE( aElem.rotation, DEGREES_T ) ); } - HelperPcpShapeAsFootprintKeepoutRegion( aFootprint, shape, aElem.layer ); + HelperPcpShapeAsFootprintKeepoutRegion( aFootprint, shape, aElem.layer, + aElem.keepoutrestrictions ); } else if( aIsBoardImport && IsAltiumLayerCopper( aElem.layer ) && aElem.net != ALTIUM_NET_UNCONNECTED ) @@ -3365,11 +3361,8 @@ void ALTIUM_PCB::ConvertFills6ToBoardItemWithNet( const AFILL6& aElem ) if( aElem.is_keepout ) { zone->SetIsRuleArea( true ); - zone->SetDoNotAllowTracks( false ); - zone->SetDoNotAllowVias( false ); - zone->SetDoNotAllowPads( false ); - zone->SetDoNotAllowFootprints( false ); - zone->SetDoNotAllowCopperPour( true ); + + HelperSetZoneKeepoutRestrictions( zone, aElem.keepoutrestrictions ); } if( aElem.rotation != 0. ) diff --git a/pcbnew/plugins/altium/altium_pcb.h b/pcbnew/plugins/altium/altium_pcb.h index 6a868cfb7e..65cb94c5e8 100644 --- a/pcbnew/plugins/altium/altium_pcb.h +++ b/pcbnew/plugins/altium/altium_pcb.h @@ -223,10 +223,10 @@ private: void HelperSetZoneKeepoutRestrictions( ZONE* aZone, const uint8_t aKeepoutRestrictions ); void HelperPcpShapeAsBoardKeepoutRegion( const PCB_SHAPE& aShape, const ALTIUM_LAYER aAltiumLayer, - const uint8_t aKeepoutRestrictions = 0x1F ); + const uint8_t aKeepoutRestrictions ); void HelperPcpShapeAsFootprintKeepoutRegion( FOOTPRINT* aFootprint, const PCB_SHAPE& aShape, const ALTIUM_LAYER aAltiumLayer, - const uint8_t aKeepoutRestrictions = 0x1F ); + const uint8_t aKeepoutRestrictions ); std::vector> HelperGetSolderAndPasteMaskExpansions( const ALTIUM_RECORD aType, const int aPrimitiveIndex,