CADSTAR Schematic: Cleanup pins in symbols

In CADSTAR pins are single points. We can replicate the original look
of the schematic in most cases by searching the symbol for straight
segments that are coincident with the pin and use those to calculate
a suitable pin length and angle.
This commit is contained in:
Roberto Fernandez Bautista 2021-05-28 19:39:08 +01:00
parent 29d1b84939
commit 9a9c9d38e8
2 changed files with 93 additions and 11 deletions

View File

@ -1265,17 +1265,6 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
pin->SetNumber( pinNum );
pin->SetName( pinName );
int oDeg = (int) NormalizeAngle180( getAngleTenthDegree( term.OrientAngle ) );
if( oDeg >= -450 && oDeg <= 450 )
pin->SetOrientation( 'R' ); // 0 degrees
else if( oDeg >= 450 && oDeg <= 1350 )
pin->SetOrientation( 'U' ); // 90 degrees
else if( oDeg >= 1350 || oDeg <= -1350 )
pin->SetOrientation( 'L' ); // 180 degrees
else
pin->SetOrientation( 'D' ); // -90 degrees
if( aPart->IsPower() )
{
pin->SetVisible( false );
@ -1286,6 +1275,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
aPart->AddDrawItem( pin );
}
fixUpLibraryPins( aPart, gateNumber );
if(aCadstarPart)
m_pinNumsMap.insert( { aCadstarPart->ID + aGateID, pinNumMap } );
@ -2715,6 +2706,95 @@ LIB_PART* CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart( const LIB_PART* aPart,
return retval;
}
void CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins( LIB_PART* aPartToFix, int aGateNumber )
{
// Store a list of segments that are not connected to other segments and are vertical or horizontal
std::map<wxPoint, LIB_POLYLINE*> twoPointUniqueSegments;
LIB_ITEMS_CONTAINER::ITERATOR polylineiter = aPartToFix->GetDrawItems().begin( LIB_POLYLINE_T );
for( ; polylineiter != aPartToFix->GetDrawItems().end( LIB_POLYLINE_T ); ++polylineiter )
{
LIB_POLYLINE& polyline = static_cast<LIB_POLYLINE&>( *polylineiter );
if( aGateNumber > 0 && polyline.GetUnit() != aGateNumber )
continue;
const std::vector<wxPoint>& pts = polyline.GetPolyPoints();
bool isUnique = true;
auto removeSegment =
[&]( LIB_POLYLINE* aLineToRemove )
{
twoPointUniqueSegments.erase( aLineToRemove->GetPolyPoints().at( 0 ) );
twoPointUniqueSegments.erase( aLineToRemove->GetPolyPoints().at( 1 ) );
isUnique = false;
};
if( pts.size() == 2 )
{
const wxPoint& pt0 = pts.at( 0 );
const wxPoint& pt1 = pts.at( 1 );
if( twoPointUniqueSegments.count( pt0 ) )
removeSegment( twoPointUniqueSegments.at( pt0 ) );
if( twoPointUniqueSegments.count( pt1 ) )
removeSegment( twoPointUniqueSegments.at( pt1 ) );
if( isUnique && pt0 != pt1 )
{
if( pt0.x == pt1.x || pt0.y == pt1.y )
{
twoPointUniqueSegments.insert( { pts.at( 0 ), &polyline } );
twoPointUniqueSegments.insert( { pts.at( 1 ), &polyline } );
}
}
}
}
LIB_PINS pins;
aPartToFix->GetPins( pins, aGateNumber );
for( auto& pin : pins )
{
auto setPinOrientation =
[&]( double aAngleRad )
{
int oDeg = (int) NormalizeAngle180( wxRadToDeg( aAngleRad ) );
if( oDeg >= -45 && oDeg <= 45 )
pin->SetOrientation( 'R' ); // 0 degrees
else if( oDeg >= 45 && oDeg <= 135 )
pin->SetOrientation( 'U' ); // 90 degrees
else if( oDeg >= 135 || oDeg <= -135 )
pin->SetOrientation( 'L' ); // 180 degrees
else
pin->SetOrientation( 'D' ); // -90 degrees
};
if( twoPointUniqueSegments.count( pin->GetPosition() ) )
{
LIB_POLYLINE* poly = twoPointUniqueSegments.at( pin->GetPosition() );
wxPoint otherPt = poly->GetPolyPoints().at( 0 );
if( otherPt == pin->GetPosition() )
otherPt = poly->GetPolyPoints().at( 1 );
VECTOR2I vec( otherPt - pin->GetPosition() );
pin->SetLength( vec.EuclideanNorm() );
setPinOrientation( vec.Angle() );
int i = 0;
}
}
}
std::pair<wxPoint, wxSize>
CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad(
const FIGURE& aCadstarFigure )

View File

@ -214,6 +214,8 @@ private:
LIB_PART* getScaledLibPart( const LIB_PART* aPart, long long aScalingFactorNumerator,
long long aScalingFactorDenominator );
void fixUpLibraryPins( LIB_PART* aPartToFix, int aGateNumber );
std::pair<wxPoint, wxSize> getFigureExtentsKiCad( const FIGURE& aCadstarFigure );
wxPoint getKiCadPoint( wxPoint aCadstarPoint );