Pcbnew, read DIMENSION from file: fix some issues related to the dim style.
Until not, when reading a DIMENSION item, the dim text was read before the style to apply is read, thus creating some style errors if the style is not the default Now the dim text is stored after the style data, and for old files, the style used when reading the text is the minimal text constraints Fixes https://gitlab.com/kicad/code/kicad/-/issues/18911
This commit is contained in:
@@ -931,8 +931,6 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_DIMENSION_BASE* aDimension, int aNest
|
||||
|
||||
if( !center )
|
||||
{
|
||||
format( static_cast<const PCB_TEXT*>( aDimension ), aNestLevel + 1 );
|
||||
|
||||
m_out->Print( aNestLevel + 1, "(format (prefix %s) (suffix %s) (units %d) (units_format %d) (precision %d)",
|
||||
m_out->Quotew( aDimension->GetPrefix() ).c_str(),
|
||||
m_out->Quotew( aDimension->GetSuffix() ).c_str(),
|
||||
@@ -974,6 +972,11 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_DIMENSION_BASE* aDimension, int aNest
|
||||
|
||||
m_out->Print( 0, ")\n" );
|
||||
|
||||
// Write dimension text after all other options to be sure the
|
||||
// text options are known when reading the file
|
||||
if( !center )
|
||||
format( static_cast<const PCB_TEXT*>( aDimension ), aNestLevel + 1 );
|
||||
|
||||
m_out->Print( aNestLevel, ")\n" );
|
||||
}
|
||||
|
||||
@@ -1533,11 +1536,11 @@ void PCB_IO_KICAD_SEXPR::format( const PAD* aPad, int aNestLevel ) const
|
||||
case PAD_SHAPE::CHAMFERED_RECT:
|
||||
case PAD_SHAPE::ROUNDRECT: return "roundrect";
|
||||
case PAD_SHAPE::CUSTOM: return "custom";
|
||||
|
||||
|
||||
default:
|
||||
THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"),
|
||||
aPad->GetShape( aLayer ) ) );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const char* type;
|
||||
@@ -1689,7 +1692,7 @@ void PCB_IO_KICAD_SEXPR::format( const PAD* aPad, int aNestLevel ) const
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// For normal padstacks, this is the one and only set of properties. For complex ones, this
|
||||
// will represent the front layer properties, and other layers will be formatted below
|
||||
formatCornerProperties( PADSTACK::ALL_LAYERS );
|
||||
@@ -2571,7 +2574,7 @@ void PCB_IO_KICAD_SEXPR::format( const PCB_TRACK* aTrack, int aNestLevel ) const
|
||||
else
|
||||
formatLayer( aTrack->GetLayer() );
|
||||
|
||||
if( aTrack->HasSolderMask()
|
||||
if( aTrack->HasSolderMask()
|
||||
&& aTrack->GetLocalSolderMaskMargin().has_value()
|
||||
&& ( aTrack->IsOnLayer( F_Cu ) || aTrack->IsOnLayer( B_Cu ) ) )
|
||||
{
|
||||
|
||||
@@ -3886,6 +3886,7 @@ PCB_DIMENSION_BASE* PCB_IO_KICAD_SEXPR_PARSER::parseDIMENSION( BOARD_ITEM* aPare
|
||||
token = NextTok();
|
||||
|
||||
bool isLegacyDimension = false;
|
||||
bool isStyleKnown = false;
|
||||
|
||||
// Old format
|
||||
if( token == T_width )
|
||||
@@ -3937,12 +3938,20 @@ PCB_DIMENSION_BASE* PCB_IO_KICAD_SEXPR_PARSER::parseDIMENSION( BOARD_ITEM* aPare
|
||||
|
||||
case T_gr_text:
|
||||
{
|
||||
// when parsing the text we do not yet know if the text is kept aligned
|
||||
// or not.
|
||||
// Leave the text not aligned for now to read the text angle.
|
||||
// In old pcb files, when parsing the text we do not yet know
|
||||
// if the text is kept aligned or not, and its DIM_TEXT_POSITION option.
|
||||
// Leave the text not aligned for now to read the text angle, and no
|
||||
// constraint for DIM_TEXT_POSITION in this case.
|
||||
// It will be set aligned (or not) later
|
||||
bool is_aligned = dim->GetKeepTextAligned();
|
||||
dim->SetKeepTextAligned( false );
|
||||
DIM_TEXT_POSITION t_dim_pos = dim->GetTextPositionMode();
|
||||
|
||||
if( !isStyleKnown )
|
||||
{
|
||||
dim->SetTextPositionMode( DIM_TEXT_POSITION::MANUAL );
|
||||
dim->SetKeepTextAligned( false );
|
||||
}
|
||||
|
||||
parsePCB_TEXT( m_board, dim.get() );
|
||||
|
||||
if( isLegacyDimension )
|
||||
@@ -3955,7 +3964,11 @@ PCB_DIMENSION_BASE* PCB_IO_KICAD_SEXPR_PARSER::parseDIMENSION( BOARD_ITEM* aPare
|
||||
dim->SetUnits( units );
|
||||
}
|
||||
|
||||
dim->SetKeepTextAligned( is_aligned );
|
||||
if( !isStyleKnown )
|
||||
{
|
||||
dim->SetKeepTextAligned( is_aligned );
|
||||
dim->SetTextPositionMode( t_dim_pos );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4081,6 +4094,8 @@ PCB_DIMENSION_BASE* PCB_IO_KICAD_SEXPR_PARSER::parseDIMENSION( BOARD_ITEM* aPare
|
||||
|
||||
case T_style:
|
||||
{
|
||||
isStyleKnown = true;
|
||||
|
||||
// new format: default to keep text aligned off unless token is present
|
||||
dim->SetKeepTextAligned( false );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user