Properly align imported dimensions

The height depends on which direction the dimension is being pulled.

Also try to mimic Altium's automatic arrow in/out style

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21329
This commit is contained in:
Seth Hillbrand 2025-07-17 10:33:03 -07:00
parent 5fb40f152c
commit e8219c4300

View File

@ -1600,7 +1600,8 @@ void ALTIUM_PCB::HelperParseDimensions6Linear( const ADIMENSION6& aElem )
* This should give us a valid measurement point where we can place the drawsegment. * This should give us a valid measurement point where we can place the drawsegment.
*/ */
VECTOR2I direction = aElem.xy1 - referencePoint0; VECTOR2I direction = aElem.xy1 - referencePoint0;
VECTOR2I directionNormalVector = VECTOR2I( -direction.y, direction.x ); VECTOR2I referenceDiff = referencePoint1 - referencePoint0;
VECTOR2I directionNormalVector = direction.Perpendicular();
SEG segm1( referencePoint0, referencePoint0 + directionNormalVector ); SEG segm1( referencePoint0, referencePoint0 + directionNormalVector );
SEG segm2( referencePoint1, referencePoint1 + direction ); SEG segm2( referencePoint1, referencePoint1 + direction );
OPT_VECTOR2I intersection( segm1.Intersect( segm2, true, true ) ); OPT_VECTOR2I intersection( segm1.Intersect( segm2, true, true ) );
@ -1612,7 +1613,7 @@ void ALTIUM_PCB::HelperParseDimensions6Linear( const ADIMENSION6& aElem )
int height = direction.EuclideanNorm(); int height = direction.EuclideanNorm();
if( ( direction.x > 0 || direction.y < 0 ) != ( aElem.angle >= 180.0 ) ) if( direction.Cross( referenceDiff ) > 0 )
height = -height; height = -height;
dimension->SetHeight( height ); dimension->SetHeight( height );
@ -1627,6 +1628,12 @@ void ALTIUM_PCB::HelperParseDimensions6Linear( const ADIMENSION6& aElem )
dimension->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX ); dimension->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX );
dimension->SetPrefix( aElem.textprefix ); dimension->SetPrefix( aElem.textprefix );
int dist = ( dimension->GetEnd() - dimension->GetStart() ).EuclideanNorm();
if( dist < 3 * dimension->GetArrowLength() )
dimension->SetArrowDirection( DIM_ARROW_DIRECTION::INWARD );
// Suffix normally (but not always) holds the units // Suffix normally (but not always) holds the units
wxRegEx units( wxS( "(mm)|(in)|(mils)|(thou)|(')|(\")" ), wxRE_ADVANCED ); wxRegEx units( wxS( "(mm)|(in)|(mils)|(thou)|(')|(\")" ), wxRE_ADVANCED );