Altium SCH Lib updates
- Use pin-compatible line widths for symbols - Handle circular arcs as circles, not elliptical arcs
This commit is contained in:
parent
de2fbbd11a
commit
1325701956
|
@ -482,7 +482,9 @@ ASCH_ELLIPSE::ASCH_ELLIPSE( const std::map<wxString, wxString>& aProps ) :
|
|||
ASCH_FILL_INTERFACE( aProps ),
|
||||
ASCH_BORDER_INTERFACE( aProps )
|
||||
{
|
||||
wxASSERT( ReadRecord( aProps ) == ALTIUM_SCH_RECORD::ELLIPSE );
|
||||
ALTIUM_SCH_RECORD record = ReadRecord( aProps );
|
||||
|
||||
wxASSERT( record == ALTIUM_SCH_RECORD::ELLIPSE || record == ALTIUM_SCH_RECORD::ELLIPTICAL_ARC );
|
||||
|
||||
Center = VECTOR2I( ReadKiCadUnitFrac( aProps, "LOCATION.X" ),
|
||||
-ReadKiCadUnitFrac( aProps, "LOCATION.Y" ) );
|
||||
|
|
|
@ -133,18 +133,26 @@ static void SetSchShapeFillAndColor( const ASCH_FILL_INTERFACE& elem, SCH_SHAPE*
|
|||
shape->SetFillMode( FILL_T::FILLED_WITH_COLOR );
|
||||
shape->SetFillColor( GetColorFromInt( elem.AreaColor ) );
|
||||
}
|
||||
|
||||
// Fixup small circles that had their widths set to 0
|
||||
if( shape->GetShape() == SHAPE_T::CIRCLE && shape->GetStroke().GetWidth() == 0
|
||||
&& shape->GetRadius() <= schIUScale.MilsToIU( 10 ) )
|
||||
{
|
||||
shape->SetFillMode( FILL_T::FILLED_SHAPE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void SetLibShapeLine( const ASCH_BORDER_INTERFACE& elem, SCH_SHAPE* shape,
|
||||
ALTIUM_SCH_RECORD aType )
|
||||
{
|
||||
COLOR4D color = GetColorFromInt( elem.Color );
|
||||
COLOR4D default_color;
|
||||
COLOR4D alt_default_color = COLOR4D( PUREBLUE ); // PUREBLUE is used for many objects, so if
|
||||
// it is used, we will assume that it should
|
||||
// blend with the others
|
||||
STROKE_PARAMS stroke;
|
||||
stroke.SetColor( GetColorFromInt( elem.Color ) );
|
||||
stroke.SetLineStyle( LINE_STYLE::SOLID );
|
||||
|
||||
switch( aType )
|
||||
{
|
||||
|
@ -160,10 +168,18 @@ static void SetLibShapeLine( const ASCH_BORDER_INTERFACE& elem, SCH_SHAPE* shape
|
|||
default: default_color = COLOR4D( PUREBLUE ); break;
|
||||
}
|
||||
|
||||
if( color == default_color || color == alt_default_color )
|
||||
color = COLOR4D::UNSPECIFIED;
|
||||
if( stroke.GetColor() == default_color || stroke.GetColor() == alt_default_color )
|
||||
stroke.SetColor( COLOR4D::UNSPECIFIED );
|
||||
|
||||
shape->SetStroke( STROKE_PARAMS( elem.LineWidth, LINE_STYLE::SOLID, color ) );
|
||||
// In Altium libraries, you cannot change the width of the pins. So, to match pin width,
|
||||
// if the line width of other elements is the default pin width (10 mil), we set the width
|
||||
// to the KiCad default pin width ( represented by 0 )
|
||||
if( elem.LineWidth == 2540 )
|
||||
stroke.SetWidth( 0 );
|
||||
else
|
||||
stroke.SetWidth( elem.LineWidth );
|
||||
|
||||
shape->SetStroke( stroke );
|
||||
}
|
||||
|
||||
static void SetLibShapeFillAndColor( const ASCH_FILL_INTERFACE& elem, SCH_SHAPE* shape,
|
||||
|
@ -213,6 +229,13 @@ static void SetLibShapeFillAndColor( const ASCH_FILL_INTERFACE& elem, SCH_SHAPE*
|
|||
stroke.SetWidth( -1 );
|
||||
shape->SetStroke( stroke );
|
||||
}
|
||||
|
||||
// Fixup small circles that had their widths set to 0
|
||||
if( shape->GetShape() == SHAPE_T::CIRCLE && shape->GetStroke().GetWidth() == 0
|
||||
&& shape->GetRadius() <= schIUScale.MilsToIU( 10 ) )
|
||||
{
|
||||
shape->SetFillMode( FILL_T::FILLED_SHAPE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -283,6 +306,47 @@ bool SCH_IO_ALTIUM::CanReadLibrary( const wxString& aFileName ) const
|
|||
}
|
||||
|
||||
|
||||
void SCH_IO_ALTIUM::fixupSymbolPinNameNumbers( SYMBOL* aSymbol )
|
||||
{
|
||||
std::vector<SCH_PIN*> pins;
|
||||
|
||||
if( LIB_SYMBOL* lib_sym = dyn_cast<LIB_SYMBOL*>( aSymbol ) )
|
||||
pins = lib_sym->GetAllLibPins();
|
||||
|
||||
if( SCH_SYMBOL* sch_sym = dyn_cast<SCH_SYMBOL*>( aSymbol ) )
|
||||
pins = sch_sym->GetPins();
|
||||
|
||||
|
||||
bool names_visible = false;
|
||||
bool numbers_visible = false;
|
||||
|
||||
for( SCH_PIN* pin : pins )
|
||||
{
|
||||
if( pin->GetNameTextSize() > 0 && !pin->GetName().empty() )
|
||||
names_visible = true;
|
||||
|
||||
if( pin->GetNumberTextSize() > 0 && !pin->GetNumber().empty() )
|
||||
numbers_visible = true;
|
||||
}
|
||||
|
||||
if( !names_visible )
|
||||
{
|
||||
for( SCH_PIN* pin : pins )
|
||||
pin->SetNameTextSize( schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE ) );
|
||||
|
||||
aSymbol->SetShowPinNames( false );
|
||||
}
|
||||
|
||||
if( !numbers_visible )
|
||||
{
|
||||
for( SCH_PIN* pin : pins )
|
||||
pin->SetNumberTextSize( schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE ) );
|
||||
|
||||
aSymbol->SetShowPinNumbers( false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wxString SCH_IO_ALTIUM::getLibName()
|
||||
{
|
||||
if( m_libName.IsEmpty() )
|
||||
|
@ -703,6 +767,9 @@ void SCH_IO_ALTIUM::ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile
|
|||
if( libSymbolIt == m_libSymbols.end() )
|
||||
THROW_IO_ERROR( "every symbol should have a symbol attached" );
|
||||
|
||||
fixupSymbolPinNameNumbers( symbol.second );
|
||||
fixupSymbolPinNameNumbers( libSymbolIt->second );
|
||||
|
||||
m_pi->SaveSymbol( getLibFileName().GetFullPath(),
|
||||
new LIB_SYMBOL( *( libSymbolIt->second ) ), m_properties.get() );
|
||||
|
||||
|
@ -810,6 +877,9 @@ void SCH_IO_ALTIUM::ParseASCIISchematic( const wxString& aFileName )
|
|||
if( libSymbolIt == m_libSymbols.end() )
|
||||
THROW_IO_ERROR( "every symbol should have a symbol attached" );
|
||||
|
||||
fixupSymbolPinNameNumbers( symbol.second );
|
||||
fixupSymbolPinNameNumbers( libSymbolIt->second );
|
||||
|
||||
m_pi->SaveSymbol( getLibFileName().GetFullPath(),
|
||||
new LIB_SYMBOL( *( libSymbolIt->second ) ), m_properties.get() );
|
||||
|
||||
|
@ -2251,6 +2321,13 @@ void SCH_IO_ALTIUM::ParseEllipticalArc( const std::map<wxString, wxString>& aPro
|
|||
{
|
||||
ASCH_ARC elem( aProperties );
|
||||
|
||||
if( elem.m_Radius == elem.m_SecondaryRadius && elem.m_StartAngle == 0
|
||||
&& ( elem.m_EndAngle == 0 || elem.m_EndAngle == 360 ) )
|
||||
{
|
||||
ParseCircle( aProperties, aSymbol );
|
||||
return;
|
||||
}
|
||||
|
||||
if( aSymbol.empty() && ShouldPutItemOnSheet( elem.ownerindex ) )
|
||||
{
|
||||
SCH_SCREEN* currentScreen = getCurrentScreen();
|
||||
|
@ -4084,6 +4161,12 @@ void SCH_IO_ALTIUM::ParseLibParameter( const std::map<wxString, wxString>& aProp
|
|||
int size = aFontSizes[elem.fontId - 1];
|
||||
field->SetTextSize( { size, size } );
|
||||
}
|
||||
else
|
||||
{
|
||||
int size = schIUScale.MilsToIU( DEFAULT_TEXT_SIZE );
|
||||
field->SetTextSize( { size, size } );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4344,6 +4427,7 @@ std::map<wxString,LIB_SYMBOL*> SCH_IO_ALTIUM::ParseLibFile( const ALTIUM_COMPOUN
|
|||
{
|
||||
LIB_SYMBOL* symbol = symbols[ii];
|
||||
symbol->FixupDrawItems();
|
||||
fixupSymbolPinNameNumbers( symbol );
|
||||
|
||||
SCH_FIELD& valField = symbol->GetValueField();
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include "altium_parser_sch.h"
|
||||
|
||||
|
||||
class SYMBOL;
|
||||
class SCH_SYMBOL;
|
||||
class SCH_SHEET;
|
||||
class TITLE_BLOCK;
|
||||
|
@ -183,6 +183,8 @@ private:
|
|||
void doEnumerateSymbolLib( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties,
|
||||
std::function<void(const wxString&, LIB_SYMBOL*)> aInserter );
|
||||
|
||||
void fixupSymbolPinNameNumbers( SYMBOL* aSymbol );
|
||||
|
||||
private:
|
||||
SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded..
|
||||
SCH_SHEET_PATH m_sheetPath;
|
||||
|
|
Loading…
Reference in New Issue