Snap arc center *by* the grid, not *to* the grid.
Also fixes a bug with editing an arc endpoint because the cursor pos was being forced before the arc constraints stuff had been run (in updateItem()).
This commit is contained in:
parent
91c551f4ab
commit
12fe44d4b3
|
@ -61,7 +61,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSnap( bool aSnap ) { m_enableSnap = aSnap; }
|
void SetSnap( bool aSnap ) { m_enableSnap = aSnap; }
|
||||||
|
bool GetSnap() const { return m_enableSnap; }
|
||||||
|
|
||||||
void SetUseGrid( bool aSnapToGrid ) { m_enableGrid = aSnapToGrid; }
|
void SetUseGrid( bool aSnapToGrid ) { m_enableGrid = aSnapToGrid; }
|
||||||
|
bool GetUseGrid() const { return m_enableGrid; }
|
||||||
|
|
||||||
void SetSnapLine( bool aSnap ) { m_enableSnapLine = aSnap; }
|
void SetSnapLine( bool aSnap ) { m_enableSnapLine = aSnap; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -219,6 +219,9 @@ std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
|
||||||
points->Point( ARC_CENTER ) ) );
|
points->Point( ARC_CENTER ) ) );
|
||||||
|
|
||||||
points->Point( ARC_MID ).SetGridConstraint( IGNORE_GRID );
|
points->Point( ARC_MID ).SetGridConstraint( IGNORE_GRID );
|
||||||
|
points->Point( ARC_START ).SetGridConstraint( SNAP_TO_GRID );
|
||||||
|
points->Point( ARC_CENTER ).SetGridConstraint( SNAP_BY_GRID );
|
||||||
|
points->Point( ARC_END ).SetGridConstraint( SNAP_TO_GRID );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_CIRCLE:
|
case S_CIRCLE:
|
||||||
|
@ -465,50 +468,49 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
|
||||||
m_original = *m_editedPoint; // Save the original position
|
m_original = *m_editedPoint; // Save the original position
|
||||||
controls->SetAutoPan( true );
|
controls->SetAutoPan( true );
|
||||||
inDrag = true;
|
inDrag = true;
|
||||||
grid.SetAuxAxes( true, m_original.GetPosition() );
|
|
||||||
|
if( m_editedPoint->GetGridConstraint() != SNAP_BY_GRID )
|
||||||
|
grid.SetAuxAxes( true, m_original.GetPosition() );
|
||||||
|
|
||||||
setAltConstraint( true );
|
setAltConstraint( true );
|
||||||
m_editedPoint->SetActive();
|
m_editedPoint->SetActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VECTOR2I pos = evt->Position();
|
||||||
|
|
||||||
//TODO: unify the constraints to solve simultaneously instead of sequentially
|
//TODO: unify the constraints to solve simultaneously instead of sequentially
|
||||||
switch( m_editedPoint->GetGridConstraint() )
|
switch( m_editedPoint->GetGridConstraint() )
|
||||||
{
|
{
|
||||||
case IGNORE_GRID:
|
case IGNORE_GRID:
|
||||||
m_editedPoint->SetPosition( evt->Position() );
|
m_editedPoint->SetPosition( pos );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SNAP_TO_GRID:
|
case SNAP_TO_GRID:
|
||||||
m_editedPoint->SetPosition( grid.BestSnapAnchor( evt->Position(), snapLayers,
|
m_editedPoint->SetPosition( grid.BestSnapAnchor( pos, snapLayers, { item } ) );
|
||||||
{ item } ) );
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SNAP_BY_GRID:
|
case SNAP_BY_GRID:
|
||||||
{
|
{
|
||||||
VECTOR2I start = m_editedPoint->GetPosition();
|
if( grid.GetUseGrid() )
|
||||||
VECTOR2I startGrid = grid.BestSnapAnchor( start, snapLayers, { item } );
|
|
||||||
VECTOR2I end = evt->Position();
|
|
||||||
VECTOR2I endGrid = grid.BestSnapAnchor( end, snapLayers, { item } );
|
|
||||||
|
|
||||||
if( start == startGrid )
|
|
||||||
{
|
{
|
||||||
end = endGrid;
|
VECTOR2I gridPt = grid.BestSnapAnchor( pos, {}, { item } );
|
||||||
}
|
|
||||||
else if( start.x == startGrid.x )
|
|
||||||
{
|
|
||||||
end.x = endGrid.x;
|
|
||||||
|
|
||||||
if( abs( end.y - start.y ) < grid.GetGrid().y )
|
VECTOR2I last = m_editedPoint->GetPosition();
|
||||||
end.y = start.y;
|
VECTOR2I delta = pos - last;
|
||||||
}
|
VECTOR2I deltaGrid = gridPt - grid.BestSnapAnchor( last, {}, { item } );
|
||||||
else if( start.y == startGrid.y )
|
|
||||||
{
|
|
||||||
end.y = endGrid.y;
|
|
||||||
|
|
||||||
if( abs( end.x - start.x ) < grid.GetGrid().x )
|
if( abs( delta.x ) > grid.GetGrid().x / 2 )
|
||||||
end.x = start.x;
|
pos.x = last.x + deltaGrid.x;
|
||||||
|
else
|
||||||
|
pos.x = last.x;
|
||||||
|
|
||||||
|
if( abs( delta.y ) > grid.GetGrid().x / 2 )
|
||||||
|
pos.y = last.y + deltaGrid.y;
|
||||||
|
else
|
||||||
|
pos.y = last.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_editedPoint->SetPosition( end );
|
m_editedPoint->SetPosition( pos );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -522,13 +524,10 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
|
||||||
m_editedPoint->ApplyConstraint();
|
m_editedPoint->ApplyConstraint();
|
||||||
|
|
||||||
if( m_editedPoint->GetGridConstraint() == SNAP_TO_GRID )
|
if( m_editedPoint->GetGridConstraint() == SNAP_TO_GRID )
|
||||||
{
|
m_editedPoint->SetPosition( grid.BestSnapAnchor( pos, snapLayers, { item } ) );
|
||||||
m_editedPoint->SetPosition( grid.BestSnapAnchor( m_editedPoint->GetPosition(),
|
|
||||||
snapLayers, { item } ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
controls->ForceCursorPosition( true, m_editedPoint->GetPosition() );
|
|
||||||
updateItem();
|
updateItem();
|
||||||
|
controls->ForceCursorPosition( true, m_editedPoint->GetPosition() );
|
||||||
updatePoints();
|
updatePoints();
|
||||||
}
|
}
|
||||||
else if( m_editedPoint && evt->Action() == TA_MOUSE_DOWN && evt->Buttons() == BUT_LEFT )
|
else if( m_editedPoint && evt->Action() == TA_MOUSE_DOWN && evt->Buttons() == BUT_LEFT )
|
||||||
|
@ -863,9 +862,9 @@ static void pinEditedCorner( int aEditedPointIndex, int aMinWidth, int aMinHeigh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PCB_POINT_EDITOR::editArcEndpointKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
void PCB_POINT_EDITOR::editArcEndpointKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter,
|
||||||
VECTOR2I aMid, VECTOR2I aEnd,
|
VECTOR2I aStart, VECTOR2I aMid, VECTOR2I aEnd,
|
||||||
const VECTOR2I aCursor ) const
|
const VECTOR2I aCursor ) const
|
||||||
{
|
{
|
||||||
bool clockwise;
|
bool clockwise;
|
||||||
bool movingStart;
|
bool movingStart;
|
||||||
|
@ -999,8 +998,9 @@ void PCB_POINT_EDITOR::editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PCB_POINT_EDITOR::editArcMidKeepEnpoints( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
void PCB_POINT_EDITOR::editArcMidKeepEndpoints( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
||||||
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const
|
VECTOR2I aMid, VECTOR2I aEnd,
|
||||||
|
const VECTOR2I aCursor ) const
|
||||||
{
|
{
|
||||||
bool clockwise;
|
bool clockwise;
|
||||||
VECTOR2I oldCenter = aArc->GetCenter();
|
VECTOR2I oldCenter = aArc->GetCenter();
|
||||||
|
@ -1169,7 +1169,7 @@ void PCB_POINT_EDITOR::updateItem() const
|
||||||
if( m_altEditMethod )
|
if( m_altEditMethod )
|
||||||
editArcMidKeepCenter( shape, center, start, mid, end, cursorPos );
|
editArcMidKeepCenter( shape, center, start, mid, end, cursorPos );
|
||||||
else
|
else
|
||||||
editArcMidKeepEnpoints( shape, center, start, mid, end, cursorPos );
|
editArcMidKeepEndpoints( shape, center, start, mid, end, cursorPos );
|
||||||
}
|
}
|
||||||
else if( isModified( m_editPoints->Point( ARC_START ) )
|
else if( isModified( m_editPoints->Point( ARC_START ) )
|
||||||
|| isModified( m_editPoints->Point( ARC_END ) ) )
|
|| isModified( m_editPoints->Point( ARC_END ) ) )
|
||||||
|
|
|
@ -131,26 +131,26 @@ private:
|
||||||
int removeCorner( const TOOL_EVENT& aEvent );
|
int removeCorner( const TOOL_EVENT& aEvent );
|
||||||
int modifiedSelection( const TOOL_EVENT& aEvent );
|
int modifiedSelection( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
/** Move an end point of the arc, while keeping the tangent at the other endpoint.
|
/**
|
||||||
*
|
* Move an end point of the arc, while keeping the tangent at the other endpoint.
|
||||||
*/
|
*/
|
||||||
void editArcEndpointKeepTangent( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
void editArcEndpointKeepTangent( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
||||||
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const;
|
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const;
|
||||||
|
|
||||||
/** Move an end point of the arc, while keeping radius, and the other point position.
|
/**
|
||||||
*
|
* Move an end point of the arc around the circumference.
|
||||||
*/
|
*/
|
||||||
void editArcEndpointKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
void editArcEndpointKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
||||||
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const;
|
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const;
|
||||||
|
|
||||||
/** Move the mid point of the arc, while keeping the two endpoints.
|
/**
|
||||||
*
|
* Move the mid point of the arc, while keeping the two endpoints.
|
||||||
*/
|
*/
|
||||||
void editArcMidKeepEnpoints( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
void editArcMidKeepEndpoints( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
||||||
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const;
|
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const;
|
||||||
|
|
||||||
/** Move the mid point of the arc, while keeping the angle.
|
/**
|
||||||
*
|
* Move the mid point of the arc, while keeping the angle.
|
||||||
*/
|
*/
|
||||||
void editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart, VECTOR2I aMid,
|
void editArcMidKeepCenter( PCB_SHAPE* aArc, VECTOR2I aCenter, VECTOR2I aStart, VECTOR2I aMid,
|
||||||
VECTOR2I aEnd, const VECTOR2I aCursor ) const;
|
VECTOR2I aEnd, const VECTOR2I aCursor ) const;
|
||||||
|
|
Loading…
Reference in New Issue