Fix orientation of orthogonal dimensions

When drawing and editing orthogonal dimensions, take distance and
relative position to the end points into account.

Fixes https://gitlab.com/kicad/code/kicad/issues/7243

Fixes https://gitlab.com/kicad/code/kicad/issues/7189
This commit is contained in:
Jonathan Haas 2021-03-05 15:40:02 +01:00 committed by Seth Hillbrand
parent 0f22b54cd8
commit 274d4e2eb4
2 changed files with 84 additions and 18 deletions

View File

@ -913,6 +913,21 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
{
case SET_END:
dimension->SetEnd( (wxPoint) cursorPos );
if( dimension->Type() == PCB_DIM_ORTHOGONAL_T )
{
ORTHOGONAL_DIMENSION* ortho = static_cast<ORTHOGONAL_DIMENSION*>( dimension );
BOX2I bounds( dimension->GetStart(),
dimension->GetEnd() - dimension->GetStart() );
// Create a nice preview by measuring the longer dimension
bool vert = bounds.GetWidth() < bounds.GetHeight();
ortho->SetOrientation( vert ? ORTHOGONAL_DIMENSION::DIR::VERTICAL
: ORTHOGONAL_DIMENSION::DIR::HORIZONTAL );
}
dimension->Update();
if( !!evt->Modifier( MD_CTRL ) || dimension->Type() == PCB_DIM_CENTER_T )
@ -938,16 +953,38 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
{
ORTHOGONAL_DIMENSION* ortho = static_cast<ORTHOGONAL_DIMENSION*>( dimension );
BOX2I bounds( dimension->GetStart(),
BOX2I bounds( dimension->GetStart(),
dimension->GetEnd() - dimension->GetStart() );
VECTOR2I direction( cursorPos - bounds.Centre() );
bool vert = std::abs( direction.y ) < std::abs( direction.x );
bool vert;
// Only change the orientation when we move outside the bounds
if( !bounds.Contains( cursorPos ) )
{
ortho->SetOrientation( vert ? ORTHOGONAL_DIMENSION::DIR::VERTICAL :
ORTHOGONAL_DIMENSION::DIR::HORIZONTAL );
// If the dimension is horizontal or vertical, set correct orientation
// otherwise, test if we're left/right of the bounding box or above/below it
if( bounds.GetWidth() == 0 )
{
vert = true;
}
else if( bounds.GetHeight() == 0 )
{
vert = false;
}
else if( cursorPos.x > bounds.GetLeft() && cursorPos.x < bounds.GetRight() )
{
vert = false;
}
else if( cursorPos.y > bounds.GetTop() && cursorPos.y < bounds.GetBottom() )
{
vert = true;
}
else
{
vert = std::abs( direction.y ) < std::abs( direction.x );
}
ortho->SetOrientation( vert ? ORTHOGONAL_DIMENSION::DIR::VERTICAL
: ORTHOGONAL_DIMENSION::DIR::HORIZONTAL );
}
else
{

View File

@ -1375,24 +1375,53 @@ void PCB_POINT_EDITOR::updateItem() const
{
ORTHOGONAL_DIMENSION* dimension = static_cast<ORTHOGONAL_DIMENSION*>( item );
BOX2I bounds( dimension->GetStart(),
dimension->GetEnd() - dimension->GetStart() );
VECTOR2I direction( m_editedPoint->GetPosition() - bounds.Centre() );
bool vert = std::abs( direction.y ) < std::abs( direction.x );
VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetStart() );
if( isModified( m_editPoints->Point( DIM_CROSSBARSTART ) ) ||
isModified( m_editPoints->Point( DIM_CROSSBAREND ) ) )
{
// Only change the orientation when we move outside the bounds
if( !bounds.Contains( m_editedPoint->GetPosition() ) )
{
dimension->SetOrientation( vert ? ORTHOGONAL_DIMENSION::DIR::VERTICAL :
ORTHOGONAL_DIMENSION::DIR::HORIZONTAL );
}
BOX2I bounds( dimension->GetStart(), dimension->GetEnd() - dimension->GetStart() );
vert = dimension->GetOrientation() == ORTHOGONAL_DIMENSION::DIR::VERTICAL;
const VECTOR2I& cursorPos = m_editedPoint->GetPosition();
// Find vector from nearest dimension point to edit position
VECTOR2I directionA( cursorPos - dimension->GetStart() );
VECTOR2I directionB( cursorPos - dimension->GetEnd() );
VECTOR2I direction = ( directionA < directionB ) ? directionA : directionB;
bool vert;
VECTOR2D featureLine( cursorPos - dimension->GetStart() );
// Only change the orientation when we move outside the bounds
if( !bounds.Contains( cursorPos ) )
{
// If the dimension is horizontal or vertical, set correct orientation
// otherwise, test if we're left/right of the bounding box or above/below it
if( bounds.GetWidth() == 0 )
{
vert = true;
}
else if( bounds.GetHeight() == 0 )
{
vert = false;
}
else if( cursorPos.x > bounds.GetLeft() && cursorPos.x < bounds.GetRight() )
{
vert = false;
}
else if( cursorPos.y > bounds.GetTop() && cursorPos.y < bounds.GetBottom() )
{
vert = true;
}
else
{
vert = std::abs( direction.y ) < std::abs( direction.x );
}
dimension->SetOrientation( vert ? ORTHOGONAL_DIMENSION::DIR::VERTICAL
: ORTHOGONAL_DIMENSION::DIR::HORIZONTAL );
}
else
{
vert = dimension->GetOrientation() == ORTHOGONAL_DIMENSION::DIR::VERTICAL;
}
dimension->SetHeight( vert ? featureLine.x : featureLine.y );
}