diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 265cd878b9..88d7acdce4 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -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 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( *polylineiter ); + + if( aGateNumber > 0 && polyline.GetUnit() != aGateNumber ) + continue; + + const std::vector& 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 CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad( const FIGURE& aCadstarFigure ) diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index d00213dd7c..8da7d6bdf1 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -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 getFigureExtentsKiCad( const FIGURE& aCadstarFigure ); wxPoint getKiCadPoint( wxPoint aCadstarPoint );